]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.8.2-201303102007.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.8.2-201303102007.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..9551bb8 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,82 @@ 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 + current->mm->aslr_gap = 0UL;
47934 +#endif
47935 +
47936 + current->mm->def_flags = 0;
47937 +
47938 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
47939 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
47940 + send_sig(SIGKILL, current, 0);
47941 + goto out_free_dentry;
47942 + }
47943 +#endif
47944 +
47945 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
47946 + pax_set_initial_flags(bprm);
47947 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
47948 + if (pax_set_initial_flags_func)
47949 + (pax_set_initial_flags_func)(bprm);
47950 +#endif
47951 +
47952 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
47953 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
47954 + current->mm->context.user_cs_limit = PAGE_SIZE;
47955 + current->mm->def_flags |= VM_PAGEEXEC;
47956 + }
47957 +#endif
47958 +
47959 +#ifdef CONFIG_PAX_SEGMEXEC
47960 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
47961 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
47962 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
47963 + pax_task_size = SEGMEXEC_TASK_SIZE;
47964 + current->mm->def_flags |= VM_NOHUGEPAGE;
47965 + }
47966 +#endif
47967 +
47968 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
47969 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47970 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
47971 + put_cpu();
47972 + }
47973 +#endif
47974
47975 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
47976 may depend on the personality. */
47977 SET_PERSONALITY(loc->elf_ex);
47978 +
47979 +#ifdef CONFIG_PAX_ASLR
47980 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
47981 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
47982 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
47983 + }
47984 +#endif
47985 +
47986 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
47987 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
47988 + executable_stack = EXSTACK_DISABLE_X;
47989 + current->personality &= ~READ_IMPLIES_EXEC;
47990 + } else
47991 +#endif
47992 +
47993 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
47994 current->personality |= READ_IMPLIES_EXEC;
47995
47996 @@ -810,6 +1216,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
47997 #else
47998 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
47999 #endif
48000 +
48001 +#ifdef CONFIG_PAX_RANDMMAP
48002 + /* PaX: randomize base address at the default exe base if requested */
48003 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
48004 +#ifdef CONFIG_SPARC64
48005 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
48006 +#else
48007 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
48008 +#endif
48009 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
48010 + elf_flags |= MAP_FIXED;
48011 + }
48012 +#endif
48013 +
48014 }
48015
48016 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
48017 @@ -842,9 +1262,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
48018 * allowed task size. Note that p_filesz must always be
48019 * <= p_memsz so it is only necessary to check p_memsz.
48020 */
48021 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48022 - elf_ppnt->p_memsz > TASK_SIZE ||
48023 - TASK_SIZE - elf_ppnt->p_memsz < k) {
48024 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
48025 + elf_ppnt->p_memsz > pax_task_size ||
48026 + pax_task_size - elf_ppnt->p_memsz < k) {
48027 /* set_brk can never work. Avoid overflows. */
48028 send_sig(SIGKILL, current, 0);
48029 retval = -EINVAL;
48030 @@ -883,17 +1303,44 @@ static int load_elf_binary(struct linux_binprm *bprm)
48031 goto out_free_dentry;
48032 }
48033 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
48034 - send_sig(SIGSEGV, current, 0);
48035 - retval = -EFAULT; /* Nobody gets to see this, but.. */
48036 - goto out_free_dentry;
48037 + /*
48038 + * This bss-zeroing can fail if the ELF
48039 + * file specifies odd protections. So
48040 + * we don't check the return value
48041 + */
48042 }
48043
48044 +#ifdef CONFIG_PAX_RANDMMAP
48045 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
48046 + unsigned long start, size;
48047 +
48048 + start = ELF_PAGEALIGN(elf_brk);
48049 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
48050 + down_read(&current->mm->mmap_sem);
48051 + retval = -ENOMEM;
48052 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
48053 + unsigned long prot = PROT_NONE;
48054 +
48055 + up_read(&current->mm->mmap_sem);
48056 + current->mm->aslr_gap += PAGE_ALIGN(size) >> PAGE_SHIFT;
48057 +// if (current->personality & ADDR_NO_RANDOMIZE)
48058 +// prot = PROT_READ;
48059 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
48060 + retval = IS_ERR_VALUE(start) ? start : 0;
48061 + } else
48062 + up_read(&current->mm->mmap_sem);
48063 + if (retval == 0)
48064 + retval = set_brk(start + size, start + size + PAGE_SIZE);
48065 + if (retval < 0) {
48066 + send_sig(SIGKILL, current, 0);
48067 + goto out_free_dentry;
48068 + }
48069 + }
48070 +#endif
48071 +
48072 if (elf_interpreter) {
48073 - unsigned long interp_map_addr = 0;
48074 -
48075 elf_entry = load_elf_interp(&loc->interp_elf_ex,
48076 interpreter,
48077 - &interp_map_addr,
48078 load_bias);
48079 if (!IS_ERR((void *)elf_entry)) {
48080 /*
48081 @@ -1115,7 +1562,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
48082 * Decide what to dump of a segment, part, all or none.
48083 */
48084 static unsigned long vma_dump_size(struct vm_area_struct *vma,
48085 - unsigned long mm_flags)
48086 + unsigned long mm_flags, long signr)
48087 {
48088 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
48089
48090 @@ -1152,7 +1599,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
48091 if (vma->vm_file == NULL)
48092 return 0;
48093
48094 - if (FILTER(MAPPED_PRIVATE))
48095 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
48096 goto whole;
48097
48098 /*
48099 @@ -1374,9 +1821,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
48100 {
48101 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
48102 int i = 0;
48103 - do
48104 + do {
48105 i += 2;
48106 - while (auxv[i - 2] != AT_NULL);
48107 + } while (auxv[i - 2] != AT_NULL);
48108 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
48109 }
48110
48111 @@ -2006,14 +2453,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
48112 }
48113
48114 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
48115 - unsigned long mm_flags)
48116 + struct coredump_params *cprm)
48117 {
48118 struct vm_area_struct *vma;
48119 size_t size = 0;
48120
48121 for (vma = first_vma(current, gate_vma); vma != NULL;
48122 vma = next_vma(vma, gate_vma))
48123 - size += vma_dump_size(vma, mm_flags);
48124 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48125 return size;
48126 }
48127
48128 @@ -2107,7 +2554,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48129
48130 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
48131
48132 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
48133 + offset += elf_core_vma_data_size(gate_vma, cprm);
48134 offset += elf_core_extra_data_size();
48135 e_shoff = offset;
48136
48137 @@ -2121,10 +2568,12 @@ static int elf_core_dump(struct coredump_params *cprm)
48138 offset = dataoff;
48139
48140 size += sizeof(*elf);
48141 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48142 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
48143 goto end_coredump;
48144
48145 size += sizeof(*phdr4note);
48146 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48147 if (size > cprm->limit
48148 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
48149 goto end_coredump;
48150 @@ -2138,7 +2587,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48151 phdr.p_offset = offset;
48152 phdr.p_vaddr = vma->vm_start;
48153 phdr.p_paddr = 0;
48154 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
48155 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48156 phdr.p_memsz = vma->vm_end - vma->vm_start;
48157 offset += phdr.p_filesz;
48158 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
48159 @@ -2149,6 +2598,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48160 phdr.p_align = ELF_EXEC_PAGESIZE;
48161
48162 size += sizeof(phdr);
48163 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48164 if (size > cprm->limit
48165 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
48166 goto end_coredump;
48167 @@ -2173,7 +2623,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48168 unsigned long addr;
48169 unsigned long end;
48170
48171 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
48172 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
48173
48174 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
48175 struct page *page;
48176 @@ -2182,6 +2632,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48177 page = get_dump_page(addr);
48178 if (page) {
48179 void *kaddr = kmap(page);
48180 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
48181 stop = ((size += PAGE_SIZE) > cprm->limit) ||
48182 !dump_write(cprm->file, kaddr,
48183 PAGE_SIZE);
48184 @@ -2199,6 +2650,7 @@ static int elf_core_dump(struct coredump_params *cprm)
48185
48186 if (e_phnum == PN_XNUM) {
48187 size += sizeof(*shdr4extnum);
48188 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
48189 if (size > cprm->limit
48190 || !dump_write(cprm->file, shdr4extnum,
48191 sizeof(*shdr4extnum)))
48192 @@ -2219,6 +2671,97 @@ out:
48193
48194 #endif /* CONFIG_ELF_CORE */
48195
48196 +#ifdef CONFIG_PAX_MPROTECT
48197 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
48198 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
48199 + * we'll remove VM_MAYWRITE for good on RELRO segments.
48200 + *
48201 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
48202 + * basis because we want to allow the common case and not the special ones.
48203 + */
48204 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
48205 +{
48206 + struct elfhdr elf_h;
48207 + struct elf_phdr elf_p;
48208 + unsigned long i;
48209 + unsigned long oldflags;
48210 + bool is_textrel_rw, is_textrel_rx, is_relro;
48211 +
48212 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
48213 + return;
48214 +
48215 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
48216 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
48217 +
48218 +#ifdef CONFIG_PAX_ELFRELOCS
48219 + /* possible TEXTREL */
48220 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
48221 + 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);
48222 +#else
48223 + is_textrel_rw = false;
48224 + is_textrel_rx = false;
48225 +#endif
48226 +
48227 + /* possible RELRO */
48228 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
48229 +
48230 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
48231 + return;
48232 +
48233 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
48234 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
48235 +
48236 +#ifdef CONFIG_PAX_ETEXECRELOCS
48237 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48238 +#else
48239 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
48240 +#endif
48241 +
48242 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
48243 + !elf_check_arch(&elf_h) ||
48244 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
48245 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
48246 + return;
48247 +
48248 + for (i = 0UL; i < elf_h.e_phnum; i++) {
48249 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
48250 + return;
48251 + switch (elf_p.p_type) {
48252 + case PT_DYNAMIC:
48253 + if (!is_textrel_rw && !is_textrel_rx)
48254 + continue;
48255 + i = 0UL;
48256 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
48257 + elf_dyn dyn;
48258 +
48259 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
48260 + return;
48261 + if (dyn.d_tag == DT_NULL)
48262 + return;
48263 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
48264 + gr_log_textrel(vma);
48265 + if (is_textrel_rw)
48266 + vma->vm_flags |= VM_MAYWRITE;
48267 + else
48268 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
48269 + vma->vm_flags &= ~VM_MAYWRITE;
48270 + return;
48271 + }
48272 + i++;
48273 + }
48274 + return;
48275 +
48276 + case PT_GNU_RELRO:
48277 + if (!is_relro)
48278 + continue;
48279 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
48280 + vma->vm_flags &= ~VM_MAYWRITE;
48281 + return;
48282 + }
48283 + }
48284 +}
48285 +#endif
48286 +
48287 static int __init init_elf_binfmt(void)
48288 {
48289 register_binfmt(&elf_format);
48290 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
48291 index b563719..3868998 100644
48292 --- a/fs/binfmt_flat.c
48293 +++ b/fs/binfmt_flat.c
48294 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
48295 realdatastart = (unsigned long) -ENOMEM;
48296 printk("Unable to allocate RAM for process data, errno %d\n",
48297 (int)-realdatastart);
48298 + down_write(&current->mm->mmap_sem);
48299 vm_munmap(textpos, text_len);
48300 + up_write(&current->mm->mmap_sem);
48301 ret = realdatastart;
48302 goto err;
48303 }
48304 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48305 }
48306 if (IS_ERR_VALUE(result)) {
48307 printk("Unable to read data+bss, errno %d\n", (int)-result);
48308 + down_write(&current->mm->mmap_sem);
48309 vm_munmap(textpos, text_len);
48310 vm_munmap(realdatastart, len);
48311 + up_write(&current->mm->mmap_sem);
48312 ret = result;
48313 goto err;
48314 }
48315 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
48316 }
48317 if (IS_ERR_VALUE(result)) {
48318 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
48319 + down_write(&current->mm->mmap_sem);
48320 vm_munmap(textpos, text_len + data_len + extra +
48321 MAX_SHARED_LIBS * sizeof(unsigned long));
48322 + up_write(&current->mm->mmap_sem);
48323 ret = result;
48324 goto err;
48325 }
48326 diff --git a/fs/bio.c b/fs/bio.c
48327 index b96fc6c..431d628 100644
48328 --- a/fs/bio.c
48329 +++ b/fs/bio.c
48330 @@ -818,7 +818,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
48331 /*
48332 * Overflow, abort
48333 */
48334 - if (end < start)
48335 + if (end < start || end - start > INT_MAX - nr_pages)
48336 return ERR_PTR(-EINVAL);
48337
48338 nr_pages += end - start;
48339 @@ -952,7 +952,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
48340 /*
48341 * Overflow, abort
48342 */
48343 - if (end < start)
48344 + if (end < start || end - start > INT_MAX - nr_pages)
48345 return ERR_PTR(-EINVAL);
48346
48347 nr_pages += end - start;
48348 @@ -1214,7 +1214,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
48349 const int read = bio_data_dir(bio) == READ;
48350 struct bio_map_data *bmd = bio->bi_private;
48351 int i;
48352 - char *p = bmd->sgvecs[0].iov_base;
48353 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
48354
48355 __bio_for_each_segment(bvec, bio, i, 0) {
48356 char *addr = page_address(bvec->bv_page);
48357 diff --git a/fs/block_dev.c b/fs/block_dev.c
48358 index 78333a3..23dcb4d 100644
48359 --- a/fs/block_dev.c
48360 +++ b/fs/block_dev.c
48361 @@ -651,7 +651,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
48362 else if (bdev->bd_contains == bdev)
48363 return true; /* is a whole device which isn't held */
48364
48365 - else if (whole->bd_holder == bd_may_claim)
48366 + else if (whole->bd_holder == (void *)bd_may_claim)
48367 return true; /* is a partition of a device that is being partitioned */
48368 else if (whole->bd_holder != NULL)
48369 return false; /* is a partition of a held device */
48370 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
48371 index eea5da7..88fead70 100644
48372 --- a/fs/btrfs/ctree.c
48373 +++ b/fs/btrfs/ctree.c
48374 @@ -1033,9 +1033,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
48375 free_extent_buffer(buf);
48376 add_root_to_dirty_list(root);
48377 } else {
48378 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
48379 - parent_start = parent->start;
48380 - else
48381 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
48382 + if (parent)
48383 + parent_start = parent->start;
48384 + else
48385 + parent_start = 0;
48386 + } else
48387 parent_start = 0;
48388
48389 WARN_ON(trans->transid != btrfs_header_generation(parent));
48390 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
48391 index cc93b23..f3c42bf 100644
48392 --- a/fs/btrfs/inode.c
48393 +++ b/fs/btrfs/inode.c
48394 @@ -7296,7 +7296,7 @@ fail:
48395 return -ENOMEM;
48396 }
48397
48398 -static int btrfs_getattr(struct vfsmount *mnt,
48399 +int btrfs_getattr(struct vfsmount *mnt,
48400 struct dentry *dentry, struct kstat *stat)
48401 {
48402 struct inode *inode = dentry->d_inode;
48403 @@ -7310,6 +7310,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
48404 return 0;
48405 }
48406
48407 +EXPORT_SYMBOL(btrfs_getattr);
48408 +
48409 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
48410 +{
48411 + return BTRFS_I(inode)->root->anon_dev;
48412 +}
48413 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
48414 +
48415 /*
48416 * If a file is moved, it will inherit the cow and compression flags of the new
48417 * directory.
48418 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
48419 index 338f259..b657640 100644
48420 --- a/fs/btrfs/ioctl.c
48421 +++ b/fs/btrfs/ioctl.c
48422 @@ -3033,9 +3033,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48423 for (i = 0; i < num_types; i++) {
48424 struct btrfs_space_info *tmp;
48425
48426 + /* Don't copy in more than we allocated */
48427 if (!slot_count)
48428 break;
48429
48430 + slot_count--;
48431 +
48432 info = NULL;
48433 rcu_read_lock();
48434 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
48435 @@ -3057,10 +3060,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
48436 memcpy(dest, &space, sizeof(space));
48437 dest++;
48438 space_args.total_spaces++;
48439 - slot_count--;
48440 }
48441 - if (!slot_count)
48442 - break;
48443 }
48444 up_read(&info->groups_sem);
48445 }
48446 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
48447 index 300e09a..9fe4539 100644
48448 --- a/fs/btrfs/relocation.c
48449 +++ b/fs/btrfs/relocation.c
48450 @@ -1269,7 +1269,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
48451 }
48452 spin_unlock(&rc->reloc_root_tree.lock);
48453
48454 - BUG_ON((struct btrfs_root *)node->data != root);
48455 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
48456
48457 if (!del) {
48458 spin_lock(&rc->reloc_root_tree.lock);
48459 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
48460 index d8982e9..29a85fa 100644
48461 --- a/fs/btrfs/super.c
48462 +++ b/fs/btrfs/super.c
48463 @@ -267,7 +267,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
48464 function, line, errstr);
48465 return;
48466 }
48467 - ACCESS_ONCE(trans->transaction->aborted) = errno;
48468 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
48469 __btrfs_std_error(root->fs_info, function, line, errno, NULL);
48470 }
48471 /*
48472 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
48473 index 622f469..e8d2d55 100644
48474 --- a/fs/cachefiles/bind.c
48475 +++ b/fs/cachefiles/bind.c
48476 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
48477 args);
48478
48479 /* start by checking things over */
48480 - ASSERT(cache->fstop_percent >= 0 &&
48481 - cache->fstop_percent < cache->fcull_percent &&
48482 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
48483 cache->fcull_percent < cache->frun_percent &&
48484 cache->frun_percent < 100);
48485
48486 - ASSERT(cache->bstop_percent >= 0 &&
48487 - cache->bstop_percent < cache->bcull_percent &&
48488 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
48489 cache->bcull_percent < cache->brun_percent &&
48490 cache->brun_percent < 100);
48491
48492 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
48493 index 0a1467b..6a53245 100644
48494 --- a/fs/cachefiles/daemon.c
48495 +++ b/fs/cachefiles/daemon.c
48496 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
48497 if (n > buflen)
48498 return -EMSGSIZE;
48499
48500 - if (copy_to_user(_buffer, buffer, n) != 0)
48501 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
48502 return -EFAULT;
48503
48504 return n;
48505 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
48506 if (test_bit(CACHEFILES_DEAD, &cache->flags))
48507 return -EIO;
48508
48509 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
48510 + if (datalen > PAGE_SIZE - 1)
48511 return -EOPNOTSUPP;
48512
48513 /* drag the command string into the kernel so we can parse it */
48514 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
48515 if (args[0] != '%' || args[1] != '\0')
48516 return -EINVAL;
48517
48518 - if (fstop < 0 || fstop >= cache->fcull_percent)
48519 + if (fstop >= cache->fcull_percent)
48520 return cachefiles_daemon_range_error(cache, args);
48521
48522 cache->fstop_percent = fstop;
48523 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
48524 if (args[0] != '%' || args[1] != '\0')
48525 return -EINVAL;
48526
48527 - if (bstop < 0 || bstop >= cache->bcull_percent)
48528 + if (bstop >= cache->bcull_percent)
48529 return cachefiles_daemon_range_error(cache, args);
48530
48531 cache->bstop_percent = bstop;
48532 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
48533 index 4938251..7e01445 100644
48534 --- a/fs/cachefiles/internal.h
48535 +++ b/fs/cachefiles/internal.h
48536 @@ -59,7 +59,7 @@ struct cachefiles_cache {
48537 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
48538 struct rb_root active_nodes; /* active nodes (can't be culled) */
48539 rwlock_t active_lock; /* lock for active_nodes */
48540 - atomic_t gravecounter; /* graveyard uniquifier */
48541 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
48542 unsigned frun_percent; /* when to stop culling (% files) */
48543 unsigned fcull_percent; /* when to start culling (% files) */
48544 unsigned fstop_percent; /* when to stop allocating (% files) */
48545 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
48546 * proc.c
48547 */
48548 #ifdef CONFIG_CACHEFILES_HISTOGRAM
48549 -extern atomic_t cachefiles_lookup_histogram[HZ];
48550 -extern atomic_t cachefiles_mkdir_histogram[HZ];
48551 -extern atomic_t cachefiles_create_histogram[HZ];
48552 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48553 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48554 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
48555
48556 extern int __init cachefiles_proc_init(void);
48557 extern void cachefiles_proc_cleanup(void);
48558 static inline
48559 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
48560 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
48561 {
48562 unsigned long jif = jiffies - start_jif;
48563 if (jif >= HZ)
48564 jif = HZ - 1;
48565 - atomic_inc(&histogram[jif]);
48566 + atomic_inc_unchecked(&histogram[jif]);
48567 }
48568
48569 #else
48570 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
48571 index 8c01c5fc..15f982e 100644
48572 --- a/fs/cachefiles/namei.c
48573 +++ b/fs/cachefiles/namei.c
48574 @@ -317,7 +317,7 @@ try_again:
48575 /* first step is to make up a grave dentry in the graveyard */
48576 sprintf(nbuffer, "%08x%08x",
48577 (uint32_t) get_seconds(),
48578 - (uint32_t) atomic_inc_return(&cache->gravecounter));
48579 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
48580
48581 /* do the multiway lock magic */
48582 trap = lock_rename(cache->graveyard, dir);
48583 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
48584 index eccd339..4c1d995 100644
48585 --- a/fs/cachefiles/proc.c
48586 +++ b/fs/cachefiles/proc.c
48587 @@ -14,9 +14,9 @@
48588 #include <linux/seq_file.h>
48589 #include "internal.h"
48590
48591 -atomic_t cachefiles_lookup_histogram[HZ];
48592 -atomic_t cachefiles_mkdir_histogram[HZ];
48593 -atomic_t cachefiles_create_histogram[HZ];
48594 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
48595 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
48596 +atomic_unchecked_t cachefiles_create_histogram[HZ];
48597
48598 /*
48599 * display the latency histogram
48600 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
48601 return 0;
48602 default:
48603 index = (unsigned long) v - 3;
48604 - x = atomic_read(&cachefiles_lookup_histogram[index]);
48605 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
48606 - z = atomic_read(&cachefiles_create_histogram[index]);
48607 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
48608 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
48609 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
48610 if (x == 0 && y == 0 && z == 0)
48611 return 0;
48612
48613 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
48614 index 4809922..aab2c39 100644
48615 --- a/fs/cachefiles/rdwr.c
48616 +++ b/fs/cachefiles/rdwr.c
48617 @@ -965,7 +965,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
48618 old_fs = get_fs();
48619 set_fs(KERNEL_DS);
48620 ret = file->f_op->write(
48621 - file, (const void __user *) data, len, &pos);
48622 + file, (const void __force_user *) data, len, &pos);
48623 set_fs(old_fs);
48624 kunmap(page);
48625 if (ret != len)
48626 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
48627 index 8c1aabe..bbf856a 100644
48628 --- a/fs/ceph/dir.c
48629 +++ b/fs/ceph/dir.c
48630 @@ -243,7 +243,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
48631 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
48632 struct ceph_mds_client *mdsc = fsc->mdsc;
48633 unsigned frag = fpos_frag(filp->f_pos);
48634 - int off = fpos_off(filp->f_pos);
48635 + unsigned int off = fpos_off(filp->f_pos);
48636 int err;
48637 u32 ftype;
48638 struct ceph_mds_reply_info_parsed *rinfo;
48639 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
48640 index d9ea6ed..1e6c8ac 100644
48641 --- a/fs/cifs/cifs_debug.c
48642 +++ b/fs/cifs/cifs_debug.c
48643 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48644
48645 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
48646 #ifdef CONFIG_CIFS_STATS2
48647 - atomic_set(&totBufAllocCount, 0);
48648 - atomic_set(&totSmBufAllocCount, 0);
48649 + atomic_set_unchecked(&totBufAllocCount, 0);
48650 + atomic_set_unchecked(&totSmBufAllocCount, 0);
48651 #endif /* CONFIG_CIFS_STATS2 */
48652 spin_lock(&cifs_tcp_ses_lock);
48653 list_for_each(tmp1, &cifs_tcp_ses_list) {
48654 @@ -281,7 +281,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
48655 tcon = list_entry(tmp3,
48656 struct cifs_tcon,
48657 tcon_list);
48658 - atomic_set(&tcon->num_smbs_sent, 0);
48659 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
48660 if (server->ops->clear_stats)
48661 server->ops->clear_stats(tcon);
48662 }
48663 @@ -313,8 +313,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
48664 smBufAllocCount.counter, cifs_min_small);
48665 #ifdef CONFIG_CIFS_STATS2
48666 seq_printf(m, "Total Large %d Small %d Allocations\n",
48667 - atomic_read(&totBufAllocCount),
48668 - atomic_read(&totSmBufAllocCount));
48669 + atomic_read_unchecked(&totBufAllocCount),
48670 + atomic_read_unchecked(&totSmBufAllocCount));
48671 #endif /* CONFIG_CIFS_STATS2 */
48672
48673 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
48674 @@ -343,7 +343,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
48675 if (tcon->need_reconnect)
48676 seq_puts(m, "\tDISCONNECTED ");
48677 seq_printf(m, "\nSMBs: %d",
48678 - atomic_read(&tcon->num_smbs_sent));
48679 + atomic_read_unchecked(&tcon->num_smbs_sent));
48680 if (server->ops->print_stats)
48681 server->ops->print_stats(m, tcon);
48682 }
48683 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
48684 index de7f916..6cb22a9 100644
48685 --- a/fs/cifs/cifsfs.c
48686 +++ b/fs/cifs/cifsfs.c
48687 @@ -997,7 +997,7 @@ cifs_init_request_bufs(void)
48688 /* cERROR(1, "CIFSMaxBufSize %d 0x%x",CIFSMaxBufSize,CIFSMaxBufSize); */
48689 cifs_req_cachep = kmem_cache_create("cifs_request",
48690 CIFSMaxBufSize + max_hdr_size, 0,
48691 - SLAB_HWCACHE_ALIGN, NULL);
48692 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
48693 if (cifs_req_cachep == NULL)
48694 return -ENOMEM;
48695
48696 @@ -1024,7 +1024,7 @@ cifs_init_request_bufs(void)
48697 efficient to alloc 1 per page off the slab compared to 17K (5page)
48698 alloc of large cifs buffers even when page debugging is on */
48699 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
48700 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
48701 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
48702 NULL);
48703 if (cifs_sm_req_cachep == NULL) {
48704 mempool_destroy(cifs_req_poolp);
48705 @@ -1109,8 +1109,8 @@ init_cifs(void)
48706 atomic_set(&bufAllocCount, 0);
48707 atomic_set(&smBufAllocCount, 0);
48708 #ifdef CONFIG_CIFS_STATS2
48709 - atomic_set(&totBufAllocCount, 0);
48710 - atomic_set(&totSmBufAllocCount, 0);
48711 + atomic_set_unchecked(&totBufAllocCount, 0);
48712 + atomic_set_unchecked(&totSmBufAllocCount, 0);
48713 #endif /* CONFIG_CIFS_STATS2 */
48714
48715 atomic_set(&midCount, 0);
48716 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
48717 index e6899ce..d6b2920 100644
48718 --- a/fs/cifs/cifsglob.h
48719 +++ b/fs/cifs/cifsglob.h
48720 @@ -751,35 +751,35 @@ struct cifs_tcon {
48721 __u16 Flags; /* optional support bits */
48722 enum statusEnum tidStatus;
48723 #ifdef CONFIG_CIFS_STATS
48724 - atomic_t num_smbs_sent;
48725 + atomic_unchecked_t num_smbs_sent;
48726 union {
48727 struct {
48728 - atomic_t num_writes;
48729 - atomic_t num_reads;
48730 - atomic_t num_flushes;
48731 - atomic_t num_oplock_brks;
48732 - atomic_t num_opens;
48733 - atomic_t num_closes;
48734 - atomic_t num_deletes;
48735 - atomic_t num_mkdirs;
48736 - atomic_t num_posixopens;
48737 - atomic_t num_posixmkdirs;
48738 - atomic_t num_rmdirs;
48739 - atomic_t num_renames;
48740 - atomic_t num_t2renames;
48741 - atomic_t num_ffirst;
48742 - atomic_t num_fnext;
48743 - atomic_t num_fclose;
48744 - atomic_t num_hardlinks;
48745 - atomic_t num_symlinks;
48746 - atomic_t num_locks;
48747 - atomic_t num_acl_get;
48748 - atomic_t num_acl_set;
48749 + atomic_unchecked_t num_writes;
48750 + atomic_unchecked_t num_reads;
48751 + atomic_unchecked_t num_flushes;
48752 + atomic_unchecked_t num_oplock_brks;
48753 + atomic_unchecked_t num_opens;
48754 + atomic_unchecked_t num_closes;
48755 + atomic_unchecked_t num_deletes;
48756 + atomic_unchecked_t num_mkdirs;
48757 + atomic_unchecked_t num_posixopens;
48758 + atomic_unchecked_t num_posixmkdirs;
48759 + atomic_unchecked_t num_rmdirs;
48760 + atomic_unchecked_t num_renames;
48761 + atomic_unchecked_t num_t2renames;
48762 + atomic_unchecked_t num_ffirst;
48763 + atomic_unchecked_t num_fnext;
48764 + atomic_unchecked_t num_fclose;
48765 + atomic_unchecked_t num_hardlinks;
48766 + atomic_unchecked_t num_symlinks;
48767 + atomic_unchecked_t num_locks;
48768 + atomic_unchecked_t num_acl_get;
48769 + atomic_unchecked_t num_acl_set;
48770 } cifs_stats;
48771 #ifdef CONFIG_CIFS_SMB2
48772 struct {
48773 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
48774 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
48775 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
48776 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
48777 } smb2_stats;
48778 #endif /* CONFIG_CIFS_SMB2 */
48779 } stats;
48780 @@ -1080,7 +1080,7 @@ convert_delimiter(char *path, char delim)
48781 }
48782
48783 #ifdef CONFIG_CIFS_STATS
48784 -#define cifs_stats_inc atomic_inc
48785 +#define cifs_stats_inc atomic_inc_unchecked
48786
48787 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
48788 unsigned int bytes)
48789 @@ -1445,8 +1445,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
48790 /* Various Debug counters */
48791 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
48792 #ifdef CONFIG_CIFS_STATS2
48793 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
48794 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
48795 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
48796 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
48797 #endif
48798 GLOBAL_EXTERN atomic_t smBufAllocCount;
48799 GLOBAL_EXTERN atomic_t midCount;
48800 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
48801 index 51dc2fb..1e12a33 100644
48802 --- a/fs/cifs/link.c
48803 +++ b/fs/cifs/link.c
48804 @@ -616,7 +616,7 @@ symlink_exit:
48805
48806 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
48807 {
48808 - char *p = nd_get_link(nd);
48809 + const char *p = nd_get_link(nd);
48810 if (!IS_ERR(p))
48811 kfree(p);
48812 }
48813 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
48814 index 3a00c0d..42d901c 100644
48815 --- a/fs/cifs/misc.c
48816 +++ b/fs/cifs/misc.c
48817 @@ -169,7 +169,7 @@ cifs_buf_get(void)
48818 memset(ret_buf, 0, buf_size + 3);
48819 atomic_inc(&bufAllocCount);
48820 #ifdef CONFIG_CIFS_STATS2
48821 - atomic_inc(&totBufAllocCount);
48822 + atomic_inc_unchecked(&totBufAllocCount);
48823 #endif /* CONFIG_CIFS_STATS2 */
48824 }
48825
48826 @@ -204,7 +204,7 @@ cifs_small_buf_get(void)
48827 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
48828 atomic_inc(&smBufAllocCount);
48829 #ifdef CONFIG_CIFS_STATS2
48830 - atomic_inc(&totSmBufAllocCount);
48831 + atomic_inc_unchecked(&totSmBufAllocCount);
48832 #endif /* CONFIG_CIFS_STATS2 */
48833
48834 }
48835 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
48836 index 47bc5a8..10decbe 100644
48837 --- a/fs/cifs/smb1ops.c
48838 +++ b/fs/cifs/smb1ops.c
48839 @@ -586,27 +586,27 @@ static void
48840 cifs_clear_stats(struct cifs_tcon *tcon)
48841 {
48842 #ifdef CONFIG_CIFS_STATS
48843 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
48844 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
48845 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
48846 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
48847 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
48848 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
48849 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
48850 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
48851 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
48852 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
48853 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
48854 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
48855 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
48856 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
48857 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
48858 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
48859 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
48860 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
48861 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
48862 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
48863 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
48864 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
48865 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
48866 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
48867 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
48868 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
48869 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
48870 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
48871 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
48872 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
48873 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
48874 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
48875 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
48876 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
48877 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
48878 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
48879 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
48880 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
48881 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
48882 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
48883 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
48884 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
48885 #endif
48886 }
48887
48888 @@ -615,36 +615,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
48889 {
48890 #ifdef CONFIG_CIFS_STATS
48891 seq_printf(m, " Oplocks breaks: %d",
48892 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
48893 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
48894 seq_printf(m, "\nReads: %d Bytes: %llu",
48895 - atomic_read(&tcon->stats.cifs_stats.num_reads),
48896 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
48897 (long long)(tcon->bytes_read));
48898 seq_printf(m, "\nWrites: %d Bytes: %llu",
48899 - atomic_read(&tcon->stats.cifs_stats.num_writes),
48900 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
48901 (long long)(tcon->bytes_written));
48902 seq_printf(m, "\nFlushes: %d",
48903 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
48904 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
48905 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
48906 - atomic_read(&tcon->stats.cifs_stats.num_locks),
48907 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
48908 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
48909 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
48910 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
48911 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
48912 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
48913 - atomic_read(&tcon->stats.cifs_stats.num_opens),
48914 - atomic_read(&tcon->stats.cifs_stats.num_closes),
48915 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
48916 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
48917 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
48918 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
48919 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
48920 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
48921 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
48922 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
48923 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
48924 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
48925 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
48926 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
48927 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
48928 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
48929 seq_printf(m, "\nRenames: %d T2 Renames %d",
48930 - atomic_read(&tcon->stats.cifs_stats.num_renames),
48931 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
48932 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
48933 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
48934 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
48935 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
48936 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
48937 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
48938 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
48939 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
48940 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
48941 #endif
48942 }
48943
48944 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
48945 index c9c7aa7..065056a 100644
48946 --- a/fs/cifs/smb2ops.c
48947 +++ b/fs/cifs/smb2ops.c
48948 @@ -274,8 +274,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
48949 #ifdef CONFIG_CIFS_STATS
48950 int i;
48951 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
48952 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
48953 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
48954 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
48955 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
48956 }
48957 #endif
48958 }
48959 @@ -284,66 +284,66 @@ static void
48960 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
48961 {
48962 #ifdef CONFIG_CIFS_STATS
48963 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
48964 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
48965 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
48966 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
48967 seq_printf(m, "\nNegotiates: %d sent %d failed",
48968 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
48969 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
48970 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
48971 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
48972 seq_printf(m, "\nSessionSetups: %d sent %d failed",
48973 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
48974 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
48975 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
48976 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
48977 #define SMB2LOGOFF 0x0002 /* trivial request/resp */
48978 seq_printf(m, "\nLogoffs: %d sent %d failed",
48979 - atomic_read(&sent[SMB2_LOGOFF_HE]),
48980 - atomic_read(&failed[SMB2_LOGOFF_HE]));
48981 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
48982 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
48983 seq_printf(m, "\nTreeConnects: %d sent %d failed",
48984 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
48985 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
48986 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
48987 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
48988 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
48989 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
48990 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
48991 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
48992 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
48993 seq_printf(m, "\nCreates: %d sent %d failed",
48994 - atomic_read(&sent[SMB2_CREATE_HE]),
48995 - atomic_read(&failed[SMB2_CREATE_HE]));
48996 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
48997 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
48998 seq_printf(m, "\nCloses: %d sent %d failed",
48999 - atomic_read(&sent[SMB2_CLOSE_HE]),
49000 - atomic_read(&failed[SMB2_CLOSE_HE]));
49001 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
49002 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
49003 seq_printf(m, "\nFlushes: %d sent %d failed",
49004 - atomic_read(&sent[SMB2_FLUSH_HE]),
49005 - atomic_read(&failed[SMB2_FLUSH_HE]));
49006 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
49007 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
49008 seq_printf(m, "\nReads: %d sent %d failed",
49009 - atomic_read(&sent[SMB2_READ_HE]),
49010 - atomic_read(&failed[SMB2_READ_HE]));
49011 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
49012 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
49013 seq_printf(m, "\nWrites: %d sent %d failed",
49014 - atomic_read(&sent[SMB2_WRITE_HE]),
49015 - atomic_read(&failed[SMB2_WRITE_HE]));
49016 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
49017 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
49018 seq_printf(m, "\nLocks: %d sent %d failed",
49019 - atomic_read(&sent[SMB2_LOCK_HE]),
49020 - atomic_read(&failed[SMB2_LOCK_HE]));
49021 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
49022 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
49023 seq_printf(m, "\nIOCTLs: %d sent %d failed",
49024 - atomic_read(&sent[SMB2_IOCTL_HE]),
49025 - atomic_read(&failed[SMB2_IOCTL_HE]));
49026 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
49027 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
49028 seq_printf(m, "\nCancels: %d sent %d failed",
49029 - atomic_read(&sent[SMB2_CANCEL_HE]),
49030 - atomic_read(&failed[SMB2_CANCEL_HE]));
49031 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
49032 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
49033 seq_printf(m, "\nEchos: %d sent %d failed",
49034 - atomic_read(&sent[SMB2_ECHO_HE]),
49035 - atomic_read(&failed[SMB2_ECHO_HE]));
49036 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
49037 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
49038 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
49039 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
49040 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
49041 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
49042 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
49043 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
49044 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
49045 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
49046 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
49047 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
49048 seq_printf(m, "\nQueryInfos: %d sent %d failed",
49049 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
49050 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
49051 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
49052 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
49053 seq_printf(m, "\nSetInfos: %d sent %d failed",
49054 - atomic_read(&sent[SMB2_SET_INFO_HE]),
49055 - atomic_read(&failed[SMB2_SET_INFO_HE]));
49056 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
49057 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
49058 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
49059 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
49060 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
49061 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
49062 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
49063 #endif
49064 }
49065
49066 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
49067 index 41d9d07..dbb4772 100644
49068 --- a/fs/cifs/smb2pdu.c
49069 +++ b/fs/cifs/smb2pdu.c
49070 @@ -1761,8 +1761,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
49071 default:
49072 cERROR(1, "info level %u isn't supported",
49073 srch_inf->info_level);
49074 - rc = -EINVAL;
49075 - goto qdir_exit;
49076 + return -EINVAL;
49077 }
49078
49079 req->FileIndex = cpu_to_le32(index);
49080 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
49081 index 958ae0e..505c9d0 100644
49082 --- a/fs/coda/cache.c
49083 +++ b/fs/coda/cache.c
49084 @@ -24,7 +24,7 @@
49085 #include "coda_linux.h"
49086 #include "coda_cache.h"
49087
49088 -static atomic_t permission_epoch = ATOMIC_INIT(0);
49089 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
49090
49091 /* replace or extend an acl cache hit */
49092 void coda_cache_enter(struct inode *inode, int mask)
49093 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
49094 struct coda_inode_info *cii = ITOC(inode);
49095
49096 spin_lock(&cii->c_lock);
49097 - cii->c_cached_epoch = atomic_read(&permission_epoch);
49098 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
49099 if (cii->c_uid != current_fsuid()) {
49100 cii->c_uid = current_fsuid();
49101 cii->c_cached_perm = mask;
49102 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
49103 {
49104 struct coda_inode_info *cii = ITOC(inode);
49105 spin_lock(&cii->c_lock);
49106 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
49107 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
49108 spin_unlock(&cii->c_lock);
49109 }
49110
49111 /* remove all acl caches */
49112 void coda_cache_clear_all(struct super_block *sb)
49113 {
49114 - atomic_inc(&permission_epoch);
49115 + atomic_inc_unchecked(&permission_epoch);
49116 }
49117
49118
49119 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
49120 spin_lock(&cii->c_lock);
49121 hit = (mask & cii->c_cached_perm) == mask &&
49122 cii->c_uid == current_fsuid() &&
49123 - cii->c_cached_epoch == atomic_read(&permission_epoch);
49124 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
49125 spin_unlock(&cii->c_lock);
49126
49127 return hit;
49128 diff --git a/fs/compat.c b/fs/compat.c
49129 index 015e1e1..b8966ac 100644
49130 --- a/fs/compat.c
49131 +++ b/fs/compat.c
49132 @@ -54,7 +54,7 @@
49133 #include <asm/ioctls.h>
49134 #include "internal.h"
49135
49136 -int compat_log = 1;
49137 +int compat_log = 0;
49138
49139 int compat_printk(const char *fmt, ...)
49140 {
49141 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
49142
49143 set_fs(KERNEL_DS);
49144 /* The __user pointer cast is valid because of the set_fs() */
49145 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
49146 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
49147 set_fs(oldfs);
49148 /* truncating is ok because it's a user address */
49149 if (!ret)
49150 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
49151 goto out;
49152
49153 ret = -EINVAL;
49154 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
49155 + if (nr_segs > UIO_MAXIOV)
49156 goto out;
49157 if (nr_segs > fast_segs) {
49158 ret = -ENOMEM;
49159 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
49160
49161 struct compat_readdir_callback {
49162 struct compat_old_linux_dirent __user *dirent;
49163 + struct file * file;
49164 int result;
49165 };
49166
49167 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
49168 buf->result = -EOVERFLOW;
49169 return -EOVERFLOW;
49170 }
49171 +
49172 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49173 + return 0;
49174 +
49175 buf->result++;
49176 dirent = buf->dirent;
49177 if (!access_ok(VERIFY_WRITE, dirent,
49178 @@ -878,6 +883,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
49179
49180 buf.result = 0;
49181 buf.dirent = dirent;
49182 + buf.file = f.file;
49183
49184 error = vfs_readdir(f.file, compat_fillonedir, &buf);
49185 if (buf.result)
49186 @@ -897,6 +903,7 @@ struct compat_linux_dirent {
49187 struct compat_getdents_callback {
49188 struct compat_linux_dirent __user *current_dir;
49189 struct compat_linux_dirent __user *previous;
49190 + struct file * file;
49191 int count;
49192 int error;
49193 };
49194 @@ -918,6 +925,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
49195 buf->error = -EOVERFLOW;
49196 return -EOVERFLOW;
49197 }
49198 +
49199 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49200 + return 0;
49201 +
49202 dirent = buf->previous;
49203 if (dirent) {
49204 if (__put_user(offset, &dirent->d_off))
49205 @@ -963,6 +974,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49206 buf.previous = NULL;
49207 buf.count = count;
49208 buf.error = 0;
49209 + buf.file = f.file;
49210
49211 error = vfs_readdir(f.file, compat_filldir, &buf);
49212 if (error >= 0)
49213 @@ -983,6 +995,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
49214 struct compat_getdents_callback64 {
49215 struct linux_dirent64 __user *current_dir;
49216 struct linux_dirent64 __user *previous;
49217 + struct file * file;
49218 int count;
49219 int error;
49220 };
49221 @@ -999,6 +1012,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
49222 buf->error = -EINVAL; /* only used if we fail.. */
49223 if (reclen > buf->count)
49224 return -EINVAL;
49225 +
49226 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
49227 + return 0;
49228 +
49229 dirent = buf->previous;
49230
49231 if (dirent) {
49232 @@ -1048,13 +1065,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
49233 buf.previous = NULL;
49234 buf.count = count;
49235 buf.error = 0;
49236 + buf.file = f.file;
49237
49238 error = vfs_readdir(f.file, compat_filldir64, &buf);
49239 if (error >= 0)
49240 error = buf.error;
49241 lastdirent = buf.previous;
49242 if (lastdirent) {
49243 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
49244 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
49245 if (__put_user_unaligned(d_off, &lastdirent->d_off))
49246 error = -EFAULT;
49247 else
49248 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
49249 index a81147e..20bf2b5 100644
49250 --- a/fs/compat_binfmt_elf.c
49251 +++ b/fs/compat_binfmt_elf.c
49252 @@ -30,11 +30,13 @@
49253 #undef elf_phdr
49254 #undef elf_shdr
49255 #undef elf_note
49256 +#undef elf_dyn
49257 #undef elf_addr_t
49258 #define elfhdr elf32_hdr
49259 #define elf_phdr elf32_phdr
49260 #define elf_shdr elf32_shdr
49261 #define elf_note elf32_note
49262 +#define elf_dyn Elf32_Dyn
49263 #define elf_addr_t Elf32_Addr
49264
49265 /*
49266 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
49267 index e2f57a0..3c78771 100644
49268 --- a/fs/compat_ioctl.c
49269 +++ b/fs/compat_ioctl.c
49270 @@ -623,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
49271 return -EFAULT;
49272 if (__get_user(udata, &ss32->iomem_base))
49273 return -EFAULT;
49274 - ss.iomem_base = compat_ptr(udata);
49275 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
49276 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
49277 __get_user(ss.port_high, &ss32->port_high))
49278 return -EFAULT;
49279 @@ -798,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
49280 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
49281 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
49282 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
49283 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49284 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
49285 return -EFAULT;
49286
49287 return ioctl_preallocate(file, p);
49288 @@ -1620,8 +1620,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
49289 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
49290 {
49291 unsigned int a, b;
49292 - a = *(unsigned int *)p;
49293 - b = *(unsigned int *)q;
49294 + a = *(const unsigned int *)p;
49295 + b = *(const unsigned int *)q;
49296 if (a > b)
49297 return 1;
49298 if (a < b)
49299 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
49300 index 712b10f..c33c4ca 100644
49301 --- a/fs/configfs/dir.c
49302 +++ b/fs/configfs/dir.c
49303 @@ -1037,10 +1037,11 @@ static int configfs_dump(struct configfs_dirent *sd, int level)
49304 static int configfs_depend_prep(struct dentry *origin,
49305 struct config_item *target)
49306 {
49307 - struct configfs_dirent *child_sd, *sd = origin->d_fsdata;
49308 + struct configfs_dirent *child_sd, *sd;
49309 int ret = 0;
49310
49311 - BUG_ON(!origin || !sd);
49312 + BUG_ON(!origin || !origin->d_fsdata);
49313 + sd = origin->d_fsdata;
49314
49315 if (sd->s_element == target) /* Boo-yah */
49316 goto out;
49317 @@ -1564,7 +1565,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49318 }
49319 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
49320 struct configfs_dirent *next;
49321 - const char * name;
49322 + const unsigned char * name;
49323 + char d_name[sizeof(next->s_dentry->d_iname)];
49324 int len;
49325 struct inode *inode = NULL;
49326
49327 @@ -1574,7 +1576,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
49328 continue;
49329
49330 name = configfs_get_name(next);
49331 - len = strlen(name);
49332 + if (next->s_dentry && name == next->s_dentry->d_iname) {
49333 + len = next->s_dentry->d_name.len;
49334 + memcpy(d_name, name, len);
49335 + name = d_name;
49336 + } else
49337 + len = strlen(name);
49338
49339 /*
49340 * We'll have a dentry and an inode for
49341 diff --git a/fs/coredump.c b/fs/coredump.c
49342 index 1774932..5812106 100644
49343 --- a/fs/coredump.c
49344 +++ b/fs/coredump.c
49345 @@ -52,7 +52,7 @@ struct core_name {
49346 char *corename;
49347 int used, size;
49348 };
49349 -static atomic_t call_count = ATOMIC_INIT(1);
49350 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
49351
49352 /* The maximal length of core_pattern is also specified in sysctl.c */
49353
49354 @@ -60,7 +60,7 @@ static int expand_corename(struct core_name *cn)
49355 {
49356 char *old_corename = cn->corename;
49357
49358 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
49359 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
49360 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
49361
49362 if (!cn->corename) {
49363 @@ -157,7 +157,7 @@ static int format_corename(struct core_name *cn, struct coredump_params *cprm)
49364 int pid_in_pattern = 0;
49365 int err = 0;
49366
49367 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
49368 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
49369 cn->corename = kmalloc(cn->size, GFP_KERNEL);
49370 cn->used = 0;
49371
49372 @@ -414,17 +414,17 @@ static void wait_for_dump_helpers(struct file *file)
49373 pipe = file->f_path.dentry->d_inode->i_pipe;
49374
49375 pipe_lock(pipe);
49376 - pipe->readers++;
49377 - pipe->writers--;
49378 + atomic_inc(&pipe->readers);
49379 + atomic_dec(&pipe->writers);
49380
49381 - while ((pipe->readers > 1) && (!signal_pending(current))) {
49382 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
49383 wake_up_interruptible_sync(&pipe->wait);
49384 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
49385 pipe_wait(pipe);
49386 }
49387
49388 - pipe->readers--;
49389 - pipe->writers++;
49390 + atomic_dec(&pipe->readers);
49391 + atomic_inc(&pipe->writers);
49392 pipe_unlock(pipe);
49393
49394 }
49395 @@ -471,7 +471,8 @@ void do_coredump(siginfo_t *siginfo)
49396 int ispipe;
49397 struct files_struct *displaced;
49398 bool need_nonrelative = false;
49399 - static atomic_t core_dump_count = ATOMIC_INIT(0);
49400 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
49401 + long signr = siginfo->si_signo;
49402 struct coredump_params cprm = {
49403 .siginfo = siginfo,
49404 .regs = signal_pt_regs(),
49405 @@ -484,7 +485,10 @@ void do_coredump(siginfo_t *siginfo)
49406 .mm_flags = mm->flags,
49407 };
49408
49409 - audit_core_dumps(siginfo->si_signo);
49410 + audit_core_dumps(signr);
49411 +
49412 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
49413 + gr_handle_brute_attach(cprm.mm_flags);
49414
49415 binfmt = mm->binfmt;
49416 if (!binfmt || !binfmt->core_dump)
49417 @@ -508,7 +512,7 @@ void do_coredump(siginfo_t *siginfo)
49418 need_nonrelative = true;
49419 }
49420
49421 - retval = coredump_wait(siginfo->si_signo, &core_state);
49422 + retval = coredump_wait(signr, &core_state);
49423 if (retval < 0)
49424 goto fail_creds;
49425
49426 @@ -556,7 +560,7 @@ void do_coredump(siginfo_t *siginfo)
49427 }
49428 cprm.limit = RLIM_INFINITY;
49429
49430 - dump_count = atomic_inc_return(&core_dump_count);
49431 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
49432 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
49433 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
49434 task_tgid_vnr(current), current->comm);
49435 @@ -583,6 +587,8 @@ void do_coredump(siginfo_t *siginfo)
49436 } else {
49437 struct inode *inode;
49438
49439 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
49440 +
49441 if (cprm.limit < binfmt->min_coredump)
49442 goto fail_unlock;
49443
49444 @@ -640,7 +646,7 @@ close_fail:
49445 filp_close(cprm.file, NULL);
49446 fail_dropcount:
49447 if (ispipe)
49448 - atomic_dec(&core_dump_count);
49449 + atomic_dec_unchecked(&core_dump_count);
49450 fail_unlock:
49451 kfree(cn.corename);
49452 fail_corename:
49453 @@ -659,7 +665,7 @@ fail:
49454 */
49455 int dump_write(struct file *file, const void *addr, int nr)
49456 {
49457 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
49458 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
49459 }
49460 EXPORT_SYMBOL(dump_write);
49461
49462 diff --git a/fs/dcache.c b/fs/dcache.c
49463 index 19153a0..428c2f5 100644
49464 --- a/fs/dcache.c
49465 +++ b/fs/dcache.c
49466 @@ -3133,7 +3133,7 @@ void __init vfs_caches_init(unsigned long mempages)
49467 mempages -= reserve;
49468
49469 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
49470 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
49471 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
49472
49473 dcache_init();
49474 inode_init();
49475 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
49476 index a5f12b7..4ee8a6f 100644
49477 --- a/fs/debugfs/inode.c
49478 +++ b/fs/debugfs/inode.c
49479 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
49480 */
49481 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
49482 {
49483 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
49484 + return __create_file(name, S_IFDIR | S_IRWXU,
49485 +#else
49486 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
49487 +#endif
49488 parent, NULL, NULL);
49489 }
49490 EXPORT_SYMBOL_GPL(debugfs_create_dir);
49491 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
49492 index cc7709e..7e7211f 100644
49493 --- a/fs/ecryptfs/inode.c
49494 +++ b/fs/ecryptfs/inode.c
49495 @@ -674,7 +674,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
49496 old_fs = get_fs();
49497 set_fs(get_ds());
49498 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
49499 - (char __user *)lower_buf,
49500 + (char __force_user *)lower_buf,
49501 PATH_MAX);
49502 set_fs(old_fs);
49503 if (rc < 0)
49504 @@ -706,7 +706,7 @@ out:
49505 static void
49506 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
49507 {
49508 - char *buf = nd_get_link(nd);
49509 + const char *buf = nd_get_link(nd);
49510 if (!IS_ERR(buf)) {
49511 /* Free the char* */
49512 kfree(buf);
49513 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
49514 index 412e6ed..4292d22 100644
49515 --- a/fs/ecryptfs/miscdev.c
49516 +++ b/fs/ecryptfs/miscdev.c
49517 @@ -315,7 +315,7 @@ check_list:
49518 goto out_unlock_msg_ctx;
49519 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
49520 if (msg_ctx->msg) {
49521 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
49522 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
49523 goto out_unlock_msg_ctx;
49524 i += packet_length_size;
49525 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
49526 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
49527 index b2a34a1..162fa69 100644
49528 --- a/fs/ecryptfs/read_write.c
49529 +++ b/fs/ecryptfs/read_write.c
49530 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
49531 return -EIO;
49532 fs_save = get_fs();
49533 set_fs(get_ds());
49534 - rc = vfs_write(lower_file, data, size, &offset);
49535 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
49536 set_fs(fs_save);
49537 mark_inode_dirty_sync(ecryptfs_inode);
49538 return rc;
49539 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
49540 return -EIO;
49541 fs_save = get_fs();
49542 set_fs(get_ds());
49543 - rc = vfs_read(lower_file, data, size, &offset);
49544 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
49545 set_fs(fs_save);
49546 return rc;
49547 }
49548 diff --git a/fs/exec.c b/fs/exec.c
49549 index 20df02c..81c9e78 100644
49550 --- a/fs/exec.c
49551 +++ b/fs/exec.c
49552 @@ -55,6 +55,17 @@
49553 #include <linux/pipe_fs_i.h>
49554 #include <linux/oom.h>
49555 #include <linux/compat.h>
49556 +#include <linux/random.h>
49557 +#include <linux/seq_file.h>
49558 +#include <linux/coredump.h>
49559 +#include <linux/mman.h>
49560 +
49561 +#ifdef CONFIG_PAX_REFCOUNT
49562 +#include <linux/kallsyms.h>
49563 +#include <linux/kdebug.h>
49564 +#endif
49565 +
49566 +#include <trace/events/fs.h>
49567
49568 #include <asm/uaccess.h>
49569 #include <asm/mmu_context.h>
49570 @@ -66,6 +77,18 @@
49571
49572 #include <trace/events/sched.h>
49573
49574 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
49575 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
49576 +{
49577 + 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");
49578 +}
49579 +#endif
49580 +
49581 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
49582 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
49583 +EXPORT_SYMBOL(pax_set_initial_flags_func);
49584 +#endif
49585 +
49586 int suid_dumpable = 0;
49587
49588 static LIST_HEAD(formats);
49589 @@ -75,8 +98,8 @@ void __register_binfmt(struct linux_binfmt * fmt, int insert)
49590 {
49591 BUG_ON(!fmt);
49592 write_lock(&binfmt_lock);
49593 - insert ? list_add(&fmt->lh, &formats) :
49594 - list_add_tail(&fmt->lh, &formats);
49595 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
49596 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
49597 write_unlock(&binfmt_lock);
49598 }
49599
49600 @@ -85,7 +108,7 @@ EXPORT_SYMBOL(__register_binfmt);
49601 void unregister_binfmt(struct linux_binfmt * fmt)
49602 {
49603 write_lock(&binfmt_lock);
49604 - list_del(&fmt->lh);
49605 + pax_list_del((struct list_head *)&fmt->lh);
49606 write_unlock(&binfmt_lock);
49607 }
49608
49609 @@ -180,18 +203,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49610 int write)
49611 {
49612 struct page *page;
49613 - int ret;
49614
49615 -#ifdef CONFIG_STACK_GROWSUP
49616 - if (write) {
49617 - ret = expand_downwards(bprm->vma, pos);
49618 - if (ret < 0)
49619 - return NULL;
49620 - }
49621 -#endif
49622 - ret = get_user_pages(current, bprm->mm, pos,
49623 - 1, write, 1, &page, NULL);
49624 - if (ret <= 0)
49625 + if (0 > expand_downwards(bprm->vma, pos))
49626 + return NULL;
49627 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
49628 return NULL;
49629
49630 if (write) {
49631 @@ -207,6 +222,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
49632 if (size <= ARG_MAX)
49633 return page;
49634
49635 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49636 + // only allow 512KB for argv+env on suid/sgid binaries
49637 + // to prevent easy ASLR exhaustion
49638 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
49639 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
49640 + (size > (512 * 1024))) {
49641 + put_page(page);
49642 + return NULL;
49643 + }
49644 +#endif
49645 +
49646 /*
49647 * Limit to 1/4-th the stack size for the argv+env strings.
49648 * This ensures that:
49649 @@ -266,6 +292,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
49650 vma->vm_end = STACK_TOP_MAX;
49651 vma->vm_start = vma->vm_end - PAGE_SIZE;
49652 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
49653 +
49654 +#ifdef CONFIG_PAX_SEGMEXEC
49655 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
49656 +#endif
49657 +
49658 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
49659 INIT_LIST_HEAD(&vma->anon_vma_chain);
49660
49661 @@ -276,6 +307,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
49662 mm->stack_vm = mm->total_vm = 1;
49663 up_write(&mm->mmap_sem);
49664 bprm->p = vma->vm_end - sizeof(void *);
49665 +
49666 +#ifdef CONFIG_PAX_RANDUSTACK
49667 + if (randomize_va_space)
49668 + bprm->p ^= random32() & ~PAGE_MASK;
49669 +#endif
49670 +
49671 return 0;
49672 err:
49673 up_write(&mm->mmap_sem);
49674 @@ -384,19 +421,7 @@ err:
49675 return err;
49676 }
49677
49678 -struct user_arg_ptr {
49679 -#ifdef CONFIG_COMPAT
49680 - bool is_compat;
49681 -#endif
49682 - union {
49683 - const char __user *const __user *native;
49684 -#ifdef CONFIG_COMPAT
49685 - const compat_uptr_t __user *compat;
49686 -#endif
49687 - } ptr;
49688 -};
49689 -
49690 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49691 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49692 {
49693 const char __user *native;
49694
49695 @@ -405,14 +430,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
49696 compat_uptr_t compat;
49697
49698 if (get_user(compat, argv.ptr.compat + nr))
49699 - return ERR_PTR(-EFAULT);
49700 + return (const char __force_user *)ERR_PTR(-EFAULT);
49701
49702 return compat_ptr(compat);
49703 }
49704 #endif
49705
49706 if (get_user(native, argv.ptr.native + nr))
49707 - return ERR_PTR(-EFAULT);
49708 + return (const char __force_user *)ERR_PTR(-EFAULT);
49709
49710 return native;
49711 }
49712 @@ -431,7 +456,7 @@ static int count(struct user_arg_ptr argv, int max)
49713 if (!p)
49714 break;
49715
49716 - if (IS_ERR(p))
49717 + if (IS_ERR((const char __force_kernel *)p))
49718 return -EFAULT;
49719
49720 if (i >= max)
49721 @@ -466,7 +491,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
49722
49723 ret = -EFAULT;
49724 str = get_user_arg_ptr(argv, argc);
49725 - if (IS_ERR(str))
49726 + if (IS_ERR((const char __force_kernel *)str))
49727 goto out;
49728
49729 len = strnlen_user(str, MAX_ARG_STRLEN);
49730 @@ -548,7 +573,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
49731 int r;
49732 mm_segment_t oldfs = get_fs();
49733 struct user_arg_ptr argv = {
49734 - .ptr.native = (const char __user *const __user *)__argv,
49735 + .ptr.native = (const char __force_user *const __force_user *)__argv,
49736 };
49737
49738 set_fs(KERNEL_DS);
49739 @@ -583,7 +608,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
49740 unsigned long new_end = old_end - shift;
49741 struct mmu_gather tlb;
49742
49743 - BUG_ON(new_start > new_end);
49744 + if (new_start >= new_end || new_start < mmap_min_addr)
49745 + return -ENOMEM;
49746
49747 /*
49748 * ensure there are no vmas between where we want to go
49749 @@ -592,6 +618,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
49750 if (vma != find_vma(mm, new_start))
49751 return -EFAULT;
49752
49753 +#ifdef CONFIG_PAX_SEGMEXEC
49754 + BUG_ON(pax_find_mirror_vma(vma));
49755 +#endif
49756 +
49757 /*
49758 * cover the whole range: [new_start, old_end)
49759 */
49760 @@ -672,10 +702,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
49761 stack_top = arch_align_stack(stack_top);
49762 stack_top = PAGE_ALIGN(stack_top);
49763
49764 - if (unlikely(stack_top < mmap_min_addr) ||
49765 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
49766 - return -ENOMEM;
49767 -
49768 stack_shift = vma->vm_end - stack_top;
49769
49770 bprm->p -= stack_shift;
49771 @@ -687,8 +713,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
49772 bprm->exec -= stack_shift;
49773
49774 down_write(&mm->mmap_sem);
49775 +
49776 + /* Move stack pages down in memory. */
49777 + if (stack_shift) {
49778 + ret = shift_arg_pages(vma, stack_shift);
49779 + if (ret)
49780 + goto out_unlock;
49781 + }
49782 +
49783 vm_flags = VM_STACK_FLAGS;
49784
49785 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
49786 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
49787 + vm_flags &= ~VM_EXEC;
49788 +
49789 +#ifdef CONFIG_PAX_MPROTECT
49790 + if (mm->pax_flags & MF_PAX_MPROTECT)
49791 + vm_flags &= ~VM_MAYEXEC;
49792 +#endif
49793 +
49794 + }
49795 +#endif
49796 +
49797 /*
49798 * Adjust stack execute permissions; explicitly enable for
49799 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
49800 @@ -707,13 +753,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
49801 goto out_unlock;
49802 BUG_ON(prev != vma);
49803
49804 - /* Move stack pages down in memory. */
49805 - if (stack_shift) {
49806 - ret = shift_arg_pages(vma, stack_shift);
49807 - if (ret)
49808 - goto out_unlock;
49809 - }
49810 -
49811 /* mprotect_fixup is overkill to remove the temporary stack flags */
49812 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
49813
49814 @@ -737,6 +776,30 @@ int setup_arg_pages(struct linux_binprm *bprm,
49815 #endif
49816 current->mm->start_stack = bprm->p;
49817 ret = expand_stack(vma, stack_base);
49818 +
49819 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_ASLR)
49820 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
49821 + unsigned long size, flags, vm_flags;
49822 +
49823 + size = STACK_TOP - vma->vm_end;
49824 + flags = MAP_FIXED | MAP_PRIVATE;
49825 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
49826 +
49827 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, flags, vm_flags, 0);
49828 +
49829 +#ifdef CONFIG_X86
49830 + if (!ret) {
49831 + current->mm->aslr_gap += size >> PAGE_SHIFT;
49832 + size = mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
49833 + ret = 0 != mmap_region(NULL, 0, size, flags, vm_flags, 0);
49834 + if (!ret)
49835 + current->mm->aslr_gap += size >> PAGE_SHIFT;
49836 + }
49837 +#endif
49838 +
49839 + }
49840 +#endif
49841 +
49842 if (ret)
49843 ret = -EFAULT;
49844
49845 @@ -772,6 +835,8 @@ struct file *open_exec(const char *name)
49846
49847 fsnotify_open(file);
49848
49849 + trace_open_exec(name);
49850 +
49851 err = deny_write_access(file);
49852 if (err)
49853 goto exit;
49854 @@ -795,7 +860,7 @@ int kernel_read(struct file *file, loff_t offset,
49855 old_fs = get_fs();
49856 set_fs(get_ds());
49857 /* The cast to a user pointer is valid due to the set_fs() */
49858 - result = vfs_read(file, (void __user *)addr, count, &pos);
49859 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
49860 set_fs(old_fs);
49861 return result;
49862 }
49863 @@ -1247,7 +1312,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
49864 }
49865 rcu_read_unlock();
49866
49867 - if (p->fs->users > n_fs) {
49868 + if (atomic_read(&p->fs->users) > n_fs) {
49869 bprm->unsafe |= LSM_UNSAFE_SHARE;
49870 } else {
49871 res = -EAGAIN;
49872 @@ -1447,6 +1512,28 @@ int search_binary_handler(struct linux_binprm *bprm)
49873
49874 EXPORT_SYMBOL(search_binary_handler);
49875
49876 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49877 +static DEFINE_PER_CPU(u64, exec_counter);
49878 +static int __init init_exec_counters(void)
49879 +{
49880 + unsigned int cpu;
49881 +
49882 + for_each_possible_cpu(cpu) {
49883 + per_cpu(exec_counter, cpu) = (u64)cpu;
49884 + }
49885 +
49886 + return 0;
49887 +}
49888 +early_initcall(init_exec_counters);
49889 +static inline void increment_exec_counter(void)
49890 +{
49891 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
49892 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
49893 +}
49894 +#else
49895 +static inline void increment_exec_counter(void) {}
49896 +#endif
49897 +
49898 /*
49899 * sys_execve() executes a new program.
49900 */
49901 @@ -1454,6 +1541,11 @@ static int do_execve_common(const char *filename,
49902 struct user_arg_ptr argv,
49903 struct user_arg_ptr envp)
49904 {
49905 +#ifdef CONFIG_GRKERNSEC
49906 + struct file *old_exec_file;
49907 + struct acl_subject_label *old_acl;
49908 + struct rlimit old_rlim[RLIM_NLIMITS];
49909 +#endif
49910 struct linux_binprm *bprm;
49911 struct file *file;
49912 struct files_struct *displaced;
49913 @@ -1461,6 +1553,8 @@ static int do_execve_common(const char *filename,
49914 int retval;
49915 const struct cred *cred = current_cred();
49916
49917 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
49918 +
49919 /*
49920 * We move the actual failure in case of RLIMIT_NPROC excess from
49921 * set*uid() to execve() because too many poorly written programs
49922 @@ -1501,12 +1595,27 @@ static int do_execve_common(const char *filename,
49923 if (IS_ERR(file))
49924 goto out_unmark;
49925
49926 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
49927 + retval = -EPERM;
49928 + goto out_file;
49929 + }
49930 +
49931 sched_exec();
49932
49933 bprm->file = file;
49934 bprm->filename = filename;
49935 bprm->interp = filename;
49936
49937 + if (gr_process_user_ban()) {
49938 + retval = -EPERM;
49939 + goto out_file;
49940 + }
49941 +
49942 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
49943 + retval = -EACCES;
49944 + goto out_file;
49945 + }
49946 +
49947 retval = bprm_mm_init(bprm);
49948 if (retval)
49949 goto out_file;
49950 @@ -1523,24 +1632,65 @@ static int do_execve_common(const char *filename,
49951 if (retval < 0)
49952 goto out;
49953
49954 +#ifdef CONFIG_GRKERNSEC
49955 + old_acl = current->acl;
49956 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
49957 + old_exec_file = current->exec_file;
49958 + get_file(file);
49959 + current->exec_file = file;
49960 +#endif
49961 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49962 + /* limit suid stack to 8MB
49963 + * we saved the old limits above and will restore them if this exec fails
49964 + */
49965 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
49966 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
49967 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
49968 +#endif
49969 +
49970 + if (!gr_tpe_allow(file)) {
49971 + retval = -EACCES;
49972 + goto out_fail;
49973 + }
49974 +
49975 + if (gr_check_crash_exec(file)) {
49976 + retval = -EACCES;
49977 + goto out_fail;
49978 + }
49979 +
49980 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
49981 + bprm->unsafe);
49982 + if (retval < 0)
49983 + goto out_fail;
49984 +
49985 retval = copy_strings_kernel(1, &bprm->filename, bprm);
49986 if (retval < 0)
49987 - goto out;
49988 + goto out_fail;
49989
49990 bprm->exec = bprm->p;
49991 retval = copy_strings(bprm->envc, envp, bprm);
49992 if (retval < 0)
49993 - goto out;
49994 + goto out_fail;
49995
49996 retval = copy_strings(bprm->argc, argv, bprm);
49997 if (retval < 0)
49998 - goto out;
49999 + goto out_fail;
50000 +
50001 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
50002 +
50003 + gr_handle_exec_args(bprm, argv);
50004
50005 retval = search_binary_handler(bprm);
50006 if (retval < 0)
50007 - goto out;
50008 + goto out_fail;
50009 +#ifdef CONFIG_GRKERNSEC
50010 + if (old_exec_file)
50011 + fput(old_exec_file);
50012 +#endif
50013
50014 /* execve succeeded */
50015 +
50016 + increment_exec_counter();
50017 current->fs->in_exec = 0;
50018 current->in_execve = 0;
50019 acct_update_integrals(current);
50020 @@ -1549,6 +1699,14 @@ static int do_execve_common(const char *filename,
50021 put_files_struct(displaced);
50022 return retval;
50023
50024 +out_fail:
50025 +#ifdef CONFIG_GRKERNSEC
50026 + current->acl = old_acl;
50027 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
50028 + fput(current->exec_file);
50029 + current->exec_file = old_exec_file;
50030 +#endif
50031 +
50032 out:
50033 if (bprm->mm) {
50034 acct_arg_size(bprm, 0);
50035 @@ -1697,3 +1855,253 @@ asmlinkage long compat_sys_execve(const char __user * filename,
50036 return error;
50037 }
50038 #endif
50039 +
50040 +int pax_check_flags(unsigned long *flags)
50041 +{
50042 + int retval = 0;
50043 +
50044 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
50045 + if (*flags & MF_PAX_SEGMEXEC)
50046 + {
50047 + *flags &= ~MF_PAX_SEGMEXEC;
50048 + retval = -EINVAL;
50049 + }
50050 +#endif
50051 +
50052 + if ((*flags & MF_PAX_PAGEEXEC)
50053 +
50054 +#ifdef CONFIG_PAX_PAGEEXEC
50055 + && (*flags & MF_PAX_SEGMEXEC)
50056 +#endif
50057 +
50058 + )
50059 + {
50060 + *flags &= ~MF_PAX_PAGEEXEC;
50061 + retval = -EINVAL;
50062 + }
50063 +
50064 + if ((*flags & MF_PAX_MPROTECT)
50065 +
50066 +#ifdef CONFIG_PAX_MPROTECT
50067 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50068 +#endif
50069 +
50070 + )
50071 + {
50072 + *flags &= ~MF_PAX_MPROTECT;
50073 + retval = -EINVAL;
50074 + }
50075 +
50076 + if ((*flags & MF_PAX_EMUTRAMP)
50077 +
50078 +#ifdef CONFIG_PAX_EMUTRAMP
50079 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
50080 +#endif
50081 +
50082 + )
50083 + {
50084 + *flags &= ~MF_PAX_EMUTRAMP;
50085 + retval = -EINVAL;
50086 + }
50087 +
50088 + return retval;
50089 +}
50090 +
50091 +EXPORT_SYMBOL(pax_check_flags);
50092 +
50093 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
50094 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
50095 +{
50096 + struct task_struct *tsk = current;
50097 + struct mm_struct *mm = current->mm;
50098 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
50099 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
50100 + char *path_exec = NULL;
50101 + char *path_fault = NULL;
50102 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
50103 + siginfo_t info = { };
50104 +
50105 + if (buffer_exec && buffer_fault) {
50106 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
50107 +
50108 + down_read(&mm->mmap_sem);
50109 + vma = mm->mmap;
50110 + while (vma && (!vma_exec || !vma_fault)) {
50111 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
50112 + vma_exec = vma;
50113 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
50114 + vma_fault = vma;
50115 + vma = vma->vm_next;
50116 + }
50117 + if (vma_exec) {
50118 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
50119 + if (IS_ERR(path_exec))
50120 + path_exec = "<path too long>";
50121 + else {
50122 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
50123 + if (path_exec) {
50124 + *path_exec = 0;
50125 + path_exec = buffer_exec;
50126 + } else
50127 + path_exec = "<path too long>";
50128 + }
50129 + }
50130 + if (vma_fault) {
50131 + start = vma_fault->vm_start;
50132 + end = vma_fault->vm_end;
50133 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
50134 + if (vma_fault->vm_file) {
50135 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
50136 + if (IS_ERR(path_fault))
50137 + path_fault = "<path too long>";
50138 + else {
50139 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
50140 + if (path_fault) {
50141 + *path_fault = 0;
50142 + path_fault = buffer_fault;
50143 + } else
50144 + path_fault = "<path too long>";
50145 + }
50146 + } else
50147 + path_fault = "<anonymous mapping>";
50148 + }
50149 + up_read(&mm->mmap_sem);
50150 + }
50151 + if (tsk->signal->curr_ip)
50152 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
50153 + else
50154 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
50155 + 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),
50156 + from_kuid(&init_user_ns, task_uid(tsk)), from_kuid(&init_user_ns, task_euid(tsk)), pc, sp);
50157 + free_page((unsigned long)buffer_exec);
50158 + free_page((unsigned long)buffer_fault);
50159 + pax_report_insns(regs, pc, sp);
50160 + info.si_signo = SIGKILL;
50161 + info.si_errno = 0;
50162 + info.si_code = SI_KERNEL;
50163 + info.si_pid = 0;
50164 + info.si_uid = 0;
50165 + do_coredump(&info);
50166 +}
50167 +#endif
50168 +
50169 +#ifdef CONFIG_PAX_REFCOUNT
50170 +void pax_report_refcount_overflow(struct pt_regs *regs)
50171 +{
50172 + if (current->signal->curr_ip)
50173 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
50174 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
50175 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
50176 + else
50177 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
50178 + from_kuid(&init_user_ns, current_uid()), from_kuid(&init_user_ns, current_euid()));
50179 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
50180 + show_regs(regs);
50181 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
50182 +}
50183 +#endif
50184 +
50185 +#ifdef CONFIG_PAX_USERCOPY
50186 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
50187 +static noinline int check_stack_object(const void *obj, unsigned long len)
50188 +{
50189 + const void * const stack = task_stack_page(current);
50190 + const void * const stackend = stack + THREAD_SIZE;
50191 +
50192 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50193 + const void *frame = NULL;
50194 + const void *oldframe;
50195 +#endif
50196 +
50197 + if (obj + len < obj)
50198 + return -1;
50199 +
50200 + if (obj + len <= stack || stackend <= obj)
50201 + return 0;
50202 +
50203 + if (obj < stack || stackend < obj + len)
50204 + return -1;
50205 +
50206 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
50207 + oldframe = __builtin_frame_address(1);
50208 + if (oldframe)
50209 + frame = __builtin_frame_address(2);
50210 + /*
50211 + low ----------------------------------------------> high
50212 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
50213 + ^----------------^
50214 + allow copies only within here
50215 + */
50216 + while (stack <= frame && frame < stackend) {
50217 + /* if obj + len extends past the last frame, this
50218 + check won't pass and the next frame will be 0,
50219 + causing us to bail out and correctly report
50220 + the copy as invalid
50221 + */
50222 + if (obj + len <= frame)
50223 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
50224 + oldframe = frame;
50225 + frame = *(const void * const *)frame;
50226 + }
50227 + return -1;
50228 +#else
50229 + return 1;
50230 +#endif
50231 +}
50232 +
50233 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
50234 +{
50235 + if (current->signal->curr_ip)
50236 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50237 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50238 + else
50239 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
50240 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
50241 + dump_stack();
50242 + gr_handle_kernel_exploit();
50243 + do_group_exit(SIGKILL);
50244 +}
50245 +#endif
50246 +
50247 +void __check_object_size(const void *ptr, unsigned long n, bool to)
50248 +{
50249 +
50250 +#ifdef CONFIG_PAX_USERCOPY
50251 + const char *type;
50252 +
50253 + if (!n)
50254 + return;
50255 +
50256 + type = check_heap_object(ptr, n);
50257 + if (!type) {
50258 + if (check_stack_object(ptr, n) != -1)
50259 + return;
50260 + type = "<process stack>";
50261 + }
50262 +
50263 + pax_report_usercopy(ptr, n, to, type);
50264 +#endif
50265 +
50266 +}
50267 +EXPORT_SYMBOL(__check_object_size);
50268 +
50269 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
50270 +void pax_track_stack(void)
50271 +{
50272 + unsigned long sp = (unsigned long)&sp;
50273 + if (sp < current_thread_info()->lowest_stack &&
50274 + sp > (unsigned long)task_stack_page(current))
50275 + current_thread_info()->lowest_stack = sp;
50276 +}
50277 +EXPORT_SYMBOL(pax_track_stack);
50278 +#endif
50279 +
50280 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
50281 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
50282 +{
50283 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
50284 + dump_stack();
50285 + do_group_exit(SIGKILL);
50286 +}
50287 +EXPORT_SYMBOL(report_size_overflow);
50288 +#endif
50289 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
50290 index 2616d0e..2ffdec9 100644
50291 --- a/fs/ext2/balloc.c
50292 +++ b/fs/ext2/balloc.c
50293 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
50294
50295 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50296 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50297 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50298 + if (free_blocks < root_blocks + 1 &&
50299 !uid_eq(sbi->s_resuid, current_fsuid()) &&
50300 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50301 - !in_group_p (sbi->s_resgid))) {
50302 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50303 return 0;
50304 }
50305 return 1;
50306 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
50307 index 22548f5..41521d8 100644
50308 --- a/fs/ext3/balloc.c
50309 +++ b/fs/ext3/balloc.c
50310 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
50311
50312 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
50313 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
50314 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
50315 + if (free_blocks < root_blocks + 1 &&
50316 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
50317 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
50318 - !in_group_p (sbi->s_resgid))) {
50319 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
50320 return 0;
50321 }
50322 return 1;
50323 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
50324 index 2f2e0da..89b113a 100644
50325 --- a/fs/ext4/balloc.c
50326 +++ b/fs/ext4/balloc.c
50327 @@ -505,8 +505,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
50328 /* Hm, nope. Are (enough) root reserved clusters available? */
50329 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
50330 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
50331 - capable(CAP_SYS_RESOURCE) ||
50332 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
50333 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
50334 + capable_nolog(CAP_SYS_RESOURCE)) {
50335
50336 if (free_clusters >= (nclusters + dirty_clusters))
50337 return 1;
50338 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
50339 index 8462eb3..4a71af6 100644
50340 --- a/fs/ext4/ext4.h
50341 +++ b/fs/ext4/ext4.h
50342 @@ -1265,19 +1265,19 @@ struct ext4_sb_info {
50343 unsigned long s_mb_last_start;
50344
50345 /* stats for buddy allocator */
50346 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
50347 - atomic_t s_bal_success; /* we found long enough chunks */
50348 - atomic_t s_bal_allocated; /* in blocks */
50349 - atomic_t s_bal_ex_scanned; /* total extents scanned */
50350 - atomic_t s_bal_goals; /* goal hits */
50351 - atomic_t s_bal_breaks; /* too long searches */
50352 - atomic_t s_bal_2orders; /* 2^order hits */
50353 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
50354 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
50355 + atomic_unchecked_t s_bal_allocated; /* in blocks */
50356 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
50357 + atomic_unchecked_t s_bal_goals; /* goal hits */
50358 + atomic_unchecked_t s_bal_breaks; /* too long searches */
50359 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
50360 spinlock_t s_bal_lock;
50361 unsigned long s_mb_buddies_generated;
50362 unsigned long long s_mb_generation_time;
50363 - atomic_t s_mb_lost_chunks;
50364 - atomic_t s_mb_preallocated;
50365 - atomic_t s_mb_discarded;
50366 + atomic_unchecked_t s_mb_lost_chunks;
50367 + atomic_unchecked_t s_mb_preallocated;
50368 + atomic_unchecked_t s_mb_discarded;
50369 atomic_t s_lock_busy;
50370
50371 /* locality groups */
50372 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
50373 index 061727a..7622abf 100644
50374 --- a/fs/ext4/mballoc.c
50375 +++ b/fs/ext4/mballoc.c
50376 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
50377 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
50378
50379 if (EXT4_SB(sb)->s_mb_stats)
50380 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
50381 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
50382
50383 break;
50384 }
50385 @@ -2044,7 +2044,7 @@ repeat:
50386 ac->ac_status = AC_STATUS_CONTINUE;
50387 ac->ac_flags |= EXT4_MB_HINT_FIRST;
50388 cr = 3;
50389 - atomic_inc(&sbi->s_mb_lost_chunks);
50390 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
50391 goto repeat;
50392 }
50393 }
50394 @@ -2552,25 +2552,25 @@ int ext4_mb_release(struct super_block *sb)
50395 if (sbi->s_mb_stats) {
50396 ext4_msg(sb, KERN_INFO,
50397 "mballoc: %u blocks %u reqs (%u success)",
50398 - atomic_read(&sbi->s_bal_allocated),
50399 - atomic_read(&sbi->s_bal_reqs),
50400 - atomic_read(&sbi->s_bal_success));
50401 + atomic_read_unchecked(&sbi->s_bal_allocated),
50402 + atomic_read_unchecked(&sbi->s_bal_reqs),
50403 + atomic_read_unchecked(&sbi->s_bal_success));
50404 ext4_msg(sb, KERN_INFO,
50405 "mballoc: %u extents scanned, %u goal hits, "
50406 "%u 2^N hits, %u breaks, %u lost",
50407 - atomic_read(&sbi->s_bal_ex_scanned),
50408 - atomic_read(&sbi->s_bal_goals),
50409 - atomic_read(&sbi->s_bal_2orders),
50410 - atomic_read(&sbi->s_bal_breaks),
50411 - atomic_read(&sbi->s_mb_lost_chunks));
50412 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
50413 + atomic_read_unchecked(&sbi->s_bal_goals),
50414 + atomic_read_unchecked(&sbi->s_bal_2orders),
50415 + atomic_read_unchecked(&sbi->s_bal_breaks),
50416 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
50417 ext4_msg(sb, KERN_INFO,
50418 "mballoc: %lu generated and it took %Lu",
50419 sbi->s_mb_buddies_generated,
50420 sbi->s_mb_generation_time);
50421 ext4_msg(sb, KERN_INFO,
50422 "mballoc: %u preallocated, %u discarded",
50423 - atomic_read(&sbi->s_mb_preallocated),
50424 - atomic_read(&sbi->s_mb_discarded));
50425 + atomic_read_unchecked(&sbi->s_mb_preallocated),
50426 + atomic_read_unchecked(&sbi->s_mb_discarded));
50427 }
50428
50429 free_percpu(sbi->s_locality_groups);
50430 @@ -3060,16 +3060,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
50431 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
50432
50433 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
50434 - atomic_inc(&sbi->s_bal_reqs);
50435 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50436 + atomic_inc_unchecked(&sbi->s_bal_reqs);
50437 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
50438 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
50439 - atomic_inc(&sbi->s_bal_success);
50440 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
50441 + atomic_inc_unchecked(&sbi->s_bal_success);
50442 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
50443 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
50444 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
50445 - atomic_inc(&sbi->s_bal_goals);
50446 + atomic_inc_unchecked(&sbi->s_bal_goals);
50447 if (ac->ac_found > sbi->s_mb_max_to_scan)
50448 - atomic_inc(&sbi->s_bal_breaks);
50449 + atomic_inc_unchecked(&sbi->s_bal_breaks);
50450 }
50451
50452 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
50453 @@ -3469,7 +3469,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
50454 trace_ext4_mb_new_inode_pa(ac, pa);
50455
50456 ext4_mb_use_inode_pa(ac, pa);
50457 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
50458 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
50459
50460 ei = EXT4_I(ac->ac_inode);
50461 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50462 @@ -3529,7 +3529,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
50463 trace_ext4_mb_new_group_pa(ac, pa);
50464
50465 ext4_mb_use_group_pa(ac, pa);
50466 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50467 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
50468
50469 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
50470 lg = ac->ac_lg;
50471 @@ -3618,7 +3618,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
50472 * from the bitmap and continue.
50473 */
50474 }
50475 - atomic_add(free, &sbi->s_mb_discarded);
50476 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
50477
50478 return err;
50479 }
50480 @@ -3636,7 +3636,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
50481 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
50482 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
50483 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
50484 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50485 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
50486 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
50487
50488 return 0;
50489 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
50490 index 0465f36..99a003a 100644
50491 --- a/fs/ext4/super.c
50492 +++ b/fs/ext4/super.c
50493 @@ -2429,7 +2429,7 @@ struct ext4_attr {
50494 ssize_t (*store)(struct ext4_attr *, struct ext4_sb_info *,
50495 const char *, size_t);
50496 int offset;
50497 -};
50498 +} __do_const;
50499
50500 static int parse_strtoul(const char *buf,
50501 unsigned long max, unsigned long *value)
50502 diff --git a/fs/fcntl.c b/fs/fcntl.c
50503 index 71a600a..20d87b1 100644
50504 --- a/fs/fcntl.c
50505 +++ b/fs/fcntl.c
50506 @@ -107,6 +107,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
50507 if (err)
50508 return err;
50509
50510 + if (gr_handle_chroot_fowner(pid, type))
50511 + return -ENOENT;
50512 + if (gr_check_protected_task_fowner(pid, type))
50513 + return -EACCES;
50514 +
50515 f_modown(filp, pid, type, force);
50516 return 0;
50517 }
50518 diff --git a/fs/fhandle.c b/fs/fhandle.c
50519 index 999ff5c..41f4109 100644
50520 --- a/fs/fhandle.c
50521 +++ b/fs/fhandle.c
50522 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
50523 } else
50524 retval = 0;
50525 /* copy the mount id */
50526 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
50527 - sizeof(*mnt_id)) ||
50528 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
50529 copy_to_user(ufh, handle,
50530 sizeof(struct file_handle) + handle_bytes))
50531 retval = -EFAULT;
50532 diff --git a/fs/fifo.c b/fs/fifo.c
50533 index cf6f434..3d7942c 100644
50534 --- a/fs/fifo.c
50535 +++ b/fs/fifo.c
50536 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
50537 */
50538 filp->f_op = &read_pipefifo_fops;
50539 pipe->r_counter++;
50540 - if (pipe->readers++ == 0)
50541 + if (atomic_inc_return(&pipe->readers) == 1)
50542 wake_up_partner(inode);
50543
50544 - if (!pipe->writers) {
50545 + if (!atomic_read(&pipe->writers)) {
50546 if ((filp->f_flags & O_NONBLOCK)) {
50547 /* suppress POLLHUP until we have
50548 * seen a writer */
50549 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
50550 * errno=ENXIO when there is no process reading the FIFO.
50551 */
50552 ret = -ENXIO;
50553 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
50554 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
50555 goto err;
50556
50557 filp->f_op = &write_pipefifo_fops;
50558 pipe->w_counter++;
50559 - if (!pipe->writers++)
50560 + if (atomic_inc_return(&pipe->writers) == 1)
50561 wake_up_partner(inode);
50562
50563 - if (!pipe->readers) {
50564 + if (!atomic_read(&pipe->readers)) {
50565 if (wait_for_partner(inode, &pipe->r_counter))
50566 goto err_wr;
50567 }
50568 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
50569 */
50570 filp->f_op = &rdwr_pipefifo_fops;
50571
50572 - pipe->readers++;
50573 - pipe->writers++;
50574 + atomic_inc(&pipe->readers);
50575 + atomic_inc(&pipe->writers);
50576 pipe->r_counter++;
50577 pipe->w_counter++;
50578 - if (pipe->readers == 1 || pipe->writers == 1)
50579 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
50580 wake_up_partner(inode);
50581 break;
50582
50583 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
50584 return 0;
50585
50586 err_rd:
50587 - if (!--pipe->readers)
50588 + if (atomic_dec_and_test(&pipe->readers))
50589 wake_up_interruptible(&pipe->wait);
50590 ret = -ERESTARTSYS;
50591 goto err;
50592
50593 err_wr:
50594 - if (!--pipe->writers)
50595 + if (atomic_dec_and_test(&pipe->writers))
50596 wake_up_interruptible(&pipe->wait);
50597 ret = -ERESTARTSYS;
50598 goto err;
50599
50600 err:
50601 - if (!pipe->readers && !pipe->writers)
50602 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
50603 free_pipe_info(inode);
50604
50605 err_nocleanup:
50606 diff --git a/fs/file.c b/fs/file.c
50607 index 2b3570b..c57924b 100644
50608 --- a/fs/file.c
50609 +++ b/fs/file.c
50610 @@ -16,6 +16,7 @@
50611 #include <linux/slab.h>
50612 #include <linux/vmalloc.h>
50613 #include <linux/file.h>
50614 +#include <linux/security.h>
50615 #include <linux/fdtable.h>
50616 #include <linux/bitops.h>
50617 #include <linux/interrupt.h>
50618 @@ -892,6 +893,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
50619 if (!file)
50620 return __close_fd(files, fd);
50621
50622 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
50623 if (fd >= rlimit(RLIMIT_NOFILE))
50624 return -EBADF;
50625
50626 @@ -918,6 +920,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
50627 if (unlikely(oldfd == newfd))
50628 return -EINVAL;
50629
50630 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
50631 if (newfd >= rlimit(RLIMIT_NOFILE))
50632 return -EBADF;
50633
50634 @@ -973,6 +976,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
50635 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
50636 {
50637 int err;
50638 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
50639 if (from >= rlimit(RLIMIT_NOFILE))
50640 return -EINVAL;
50641 err = alloc_fd(from, flags);
50642 diff --git a/fs/filesystems.c b/fs/filesystems.c
50643 index da165f6..3671bdb 100644
50644 --- a/fs/filesystems.c
50645 +++ b/fs/filesystems.c
50646 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
50647 int len = dot ? dot - name : strlen(name);
50648
50649 fs = __get_fs_type(name, len);
50650 +
50651 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
50652 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
50653 +#else
50654 if (!fs && (request_module("%.*s", len, name) == 0))
50655 +#endif
50656 fs = __get_fs_type(name, len);
50657
50658 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
50659 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
50660 index fe6ca58..65318cf 100644
50661 --- a/fs/fs_struct.c
50662 +++ b/fs/fs_struct.c
50663 @@ -4,6 +4,7 @@
50664 #include <linux/path.h>
50665 #include <linux/slab.h>
50666 #include <linux/fs_struct.h>
50667 +#include <linux/grsecurity.h>
50668 #include "internal.h"
50669
50670 /*
50671 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
50672 write_seqcount_begin(&fs->seq);
50673 old_root = fs->root;
50674 fs->root = *path;
50675 + gr_set_chroot_entries(current, path);
50676 write_seqcount_end(&fs->seq);
50677 spin_unlock(&fs->lock);
50678 if (old_root.dentry)
50679 @@ -53,6 +55,21 @@ static inline int replace_path(struct path *p, const struct path *old, const str
50680 return 1;
50681 }
50682
50683 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
50684 +{
50685 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
50686 + return 0;
50687 + *p = *new;
50688 +
50689 + /* This function is only called from pivot_root(). Leave our
50690 + gr_chroot_dentry and is_chrooted flags as-is, so that a
50691 + pivoted root isn't treated as a chroot
50692 + */
50693 + //gr_set_chroot_entries(task, new);
50694 +
50695 + return 1;
50696 +}
50697 +
50698 void chroot_fs_refs(struct path *old_root, struct path *new_root)
50699 {
50700 struct task_struct *g, *p;
50701 @@ -67,7 +84,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
50702 int hits = 0;
50703 spin_lock(&fs->lock);
50704 write_seqcount_begin(&fs->seq);
50705 - hits += replace_path(&fs->root, old_root, new_root);
50706 + hits += replace_root_path(p, &fs->root, old_root, new_root);
50707 hits += replace_path(&fs->pwd, old_root, new_root);
50708 write_seqcount_end(&fs->seq);
50709 while (hits--) {
50710 @@ -99,7 +116,8 @@ void exit_fs(struct task_struct *tsk)
50711 task_lock(tsk);
50712 spin_lock(&fs->lock);
50713 tsk->fs = NULL;
50714 - kill = !--fs->users;
50715 + gr_clear_chroot_entries(tsk);
50716 + kill = !atomic_dec_return(&fs->users);
50717 spin_unlock(&fs->lock);
50718 task_unlock(tsk);
50719 if (kill)
50720 @@ -112,7 +130,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
50721 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
50722 /* We don't need to lock fs - think why ;-) */
50723 if (fs) {
50724 - fs->users = 1;
50725 + atomic_set(&fs->users, 1);
50726 fs->in_exec = 0;
50727 spin_lock_init(&fs->lock);
50728 seqcount_init(&fs->seq);
50729 @@ -121,6 +139,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
50730 spin_lock(&old->lock);
50731 fs->root = old->root;
50732 path_get(&fs->root);
50733 + /* instead of calling gr_set_chroot_entries here,
50734 + we call it from every caller of this function
50735 + */
50736 fs->pwd = old->pwd;
50737 path_get(&fs->pwd);
50738 spin_unlock(&old->lock);
50739 @@ -139,8 +160,9 @@ int unshare_fs_struct(void)
50740
50741 task_lock(current);
50742 spin_lock(&fs->lock);
50743 - kill = !--fs->users;
50744 + kill = !atomic_dec_return(&fs->users);
50745 current->fs = new_fs;
50746 + gr_set_chroot_entries(current, &new_fs->root);
50747 spin_unlock(&fs->lock);
50748 task_unlock(current);
50749
50750 @@ -153,13 +175,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
50751
50752 int current_umask(void)
50753 {
50754 - return current->fs->umask;
50755 + return current->fs->umask | gr_acl_umask();
50756 }
50757 EXPORT_SYMBOL(current_umask);
50758
50759 /* to be mentioned only in INIT_TASK */
50760 struct fs_struct init_fs = {
50761 - .users = 1,
50762 + .users = ATOMIC_INIT(1),
50763 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
50764 .seq = SEQCNT_ZERO,
50765 .umask = 0022,
50766 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
50767 index 8dcb114..b1072e2 100644
50768 --- a/fs/fscache/cookie.c
50769 +++ b/fs/fscache/cookie.c
50770 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
50771 parent ? (char *) parent->def->name : "<no-parent>",
50772 def->name, netfs_data);
50773
50774 - fscache_stat(&fscache_n_acquires);
50775 + fscache_stat_unchecked(&fscache_n_acquires);
50776
50777 /* if there's no parent cookie, then we don't create one here either */
50778 if (!parent) {
50779 - fscache_stat(&fscache_n_acquires_null);
50780 + fscache_stat_unchecked(&fscache_n_acquires_null);
50781 _leave(" [no parent]");
50782 return NULL;
50783 }
50784 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
50785 /* allocate and initialise a cookie */
50786 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
50787 if (!cookie) {
50788 - fscache_stat(&fscache_n_acquires_oom);
50789 + fscache_stat_unchecked(&fscache_n_acquires_oom);
50790 _leave(" [ENOMEM]");
50791 return NULL;
50792 }
50793 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
50794
50795 switch (cookie->def->type) {
50796 case FSCACHE_COOKIE_TYPE_INDEX:
50797 - fscache_stat(&fscache_n_cookie_index);
50798 + fscache_stat_unchecked(&fscache_n_cookie_index);
50799 break;
50800 case FSCACHE_COOKIE_TYPE_DATAFILE:
50801 - fscache_stat(&fscache_n_cookie_data);
50802 + fscache_stat_unchecked(&fscache_n_cookie_data);
50803 break;
50804 default:
50805 - fscache_stat(&fscache_n_cookie_special);
50806 + fscache_stat_unchecked(&fscache_n_cookie_special);
50807 break;
50808 }
50809
50810 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
50811 if (fscache_acquire_non_index_cookie(cookie) < 0) {
50812 atomic_dec(&parent->n_children);
50813 __fscache_cookie_put(cookie);
50814 - fscache_stat(&fscache_n_acquires_nobufs);
50815 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
50816 _leave(" = NULL");
50817 return NULL;
50818 }
50819 }
50820
50821 - fscache_stat(&fscache_n_acquires_ok);
50822 + fscache_stat_unchecked(&fscache_n_acquires_ok);
50823 _leave(" = %p", cookie);
50824 return cookie;
50825 }
50826 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
50827 cache = fscache_select_cache_for_object(cookie->parent);
50828 if (!cache) {
50829 up_read(&fscache_addremove_sem);
50830 - fscache_stat(&fscache_n_acquires_no_cache);
50831 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
50832 _leave(" = -ENOMEDIUM [no cache]");
50833 return -ENOMEDIUM;
50834 }
50835 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
50836 object = cache->ops->alloc_object(cache, cookie);
50837 fscache_stat_d(&fscache_n_cop_alloc_object);
50838 if (IS_ERR(object)) {
50839 - fscache_stat(&fscache_n_object_no_alloc);
50840 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
50841 ret = PTR_ERR(object);
50842 goto error;
50843 }
50844
50845 - fscache_stat(&fscache_n_object_alloc);
50846 + fscache_stat_unchecked(&fscache_n_object_alloc);
50847
50848 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
50849
50850 @@ -378,7 +378,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
50851
50852 _enter("{%s}", cookie->def->name);
50853
50854 - fscache_stat(&fscache_n_invalidates);
50855 + fscache_stat_unchecked(&fscache_n_invalidates);
50856
50857 /* Only permit invalidation of data files. Invalidating an index will
50858 * require the caller to release all its attachments to the tree rooted
50859 @@ -437,10 +437,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
50860 struct fscache_object *object;
50861 struct hlist_node *_p;
50862
50863 - fscache_stat(&fscache_n_updates);
50864 + fscache_stat_unchecked(&fscache_n_updates);
50865
50866 if (!cookie) {
50867 - fscache_stat(&fscache_n_updates_null);
50868 + fscache_stat_unchecked(&fscache_n_updates_null);
50869 _leave(" [no cookie]");
50870 return;
50871 }
50872 @@ -474,12 +474,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
50873 struct fscache_object *object;
50874 unsigned long event;
50875
50876 - fscache_stat(&fscache_n_relinquishes);
50877 + fscache_stat_unchecked(&fscache_n_relinquishes);
50878 if (retire)
50879 - fscache_stat(&fscache_n_relinquishes_retire);
50880 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
50881
50882 if (!cookie) {
50883 - fscache_stat(&fscache_n_relinquishes_null);
50884 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
50885 _leave(" [no cookie]");
50886 return;
50887 }
50888 @@ -495,7 +495,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
50889
50890 /* wait for the cookie to finish being instantiated (or to fail) */
50891 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
50892 - fscache_stat(&fscache_n_relinquishes_waitcrt);
50893 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
50894 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
50895 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
50896 }
50897 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
50898 index ee38fef..0a326d4 100644
50899 --- a/fs/fscache/internal.h
50900 +++ b/fs/fscache/internal.h
50901 @@ -148,101 +148,101 @@ extern void fscache_proc_cleanup(void);
50902 * stats.c
50903 */
50904 #ifdef CONFIG_FSCACHE_STATS
50905 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
50906 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
50907 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
50908 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
50909
50910 -extern atomic_t fscache_n_op_pend;
50911 -extern atomic_t fscache_n_op_run;
50912 -extern atomic_t fscache_n_op_enqueue;
50913 -extern atomic_t fscache_n_op_deferred_release;
50914 -extern atomic_t fscache_n_op_release;
50915 -extern atomic_t fscache_n_op_gc;
50916 -extern atomic_t fscache_n_op_cancelled;
50917 -extern atomic_t fscache_n_op_rejected;
50918 +extern atomic_unchecked_t fscache_n_op_pend;
50919 +extern atomic_unchecked_t fscache_n_op_run;
50920 +extern atomic_unchecked_t fscache_n_op_enqueue;
50921 +extern atomic_unchecked_t fscache_n_op_deferred_release;
50922 +extern atomic_unchecked_t fscache_n_op_release;
50923 +extern atomic_unchecked_t fscache_n_op_gc;
50924 +extern atomic_unchecked_t fscache_n_op_cancelled;
50925 +extern atomic_unchecked_t fscache_n_op_rejected;
50926
50927 -extern atomic_t fscache_n_attr_changed;
50928 -extern atomic_t fscache_n_attr_changed_ok;
50929 -extern atomic_t fscache_n_attr_changed_nobufs;
50930 -extern atomic_t fscache_n_attr_changed_nomem;
50931 -extern atomic_t fscache_n_attr_changed_calls;
50932 +extern atomic_unchecked_t fscache_n_attr_changed;
50933 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
50934 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
50935 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
50936 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
50937
50938 -extern atomic_t fscache_n_allocs;
50939 -extern atomic_t fscache_n_allocs_ok;
50940 -extern atomic_t fscache_n_allocs_wait;
50941 -extern atomic_t fscache_n_allocs_nobufs;
50942 -extern atomic_t fscache_n_allocs_intr;
50943 -extern atomic_t fscache_n_allocs_object_dead;
50944 -extern atomic_t fscache_n_alloc_ops;
50945 -extern atomic_t fscache_n_alloc_op_waits;
50946 +extern atomic_unchecked_t fscache_n_allocs;
50947 +extern atomic_unchecked_t fscache_n_allocs_ok;
50948 +extern atomic_unchecked_t fscache_n_allocs_wait;
50949 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
50950 +extern atomic_unchecked_t fscache_n_allocs_intr;
50951 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
50952 +extern atomic_unchecked_t fscache_n_alloc_ops;
50953 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
50954
50955 -extern atomic_t fscache_n_retrievals;
50956 -extern atomic_t fscache_n_retrievals_ok;
50957 -extern atomic_t fscache_n_retrievals_wait;
50958 -extern atomic_t fscache_n_retrievals_nodata;
50959 -extern atomic_t fscache_n_retrievals_nobufs;
50960 -extern atomic_t fscache_n_retrievals_intr;
50961 -extern atomic_t fscache_n_retrievals_nomem;
50962 -extern atomic_t fscache_n_retrievals_object_dead;
50963 -extern atomic_t fscache_n_retrieval_ops;
50964 -extern atomic_t fscache_n_retrieval_op_waits;
50965 +extern atomic_unchecked_t fscache_n_retrievals;
50966 +extern atomic_unchecked_t fscache_n_retrievals_ok;
50967 +extern atomic_unchecked_t fscache_n_retrievals_wait;
50968 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
50969 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
50970 +extern atomic_unchecked_t fscache_n_retrievals_intr;
50971 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
50972 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
50973 +extern atomic_unchecked_t fscache_n_retrieval_ops;
50974 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
50975
50976 -extern atomic_t fscache_n_stores;
50977 -extern atomic_t fscache_n_stores_ok;
50978 -extern atomic_t fscache_n_stores_again;
50979 -extern atomic_t fscache_n_stores_nobufs;
50980 -extern atomic_t fscache_n_stores_oom;
50981 -extern atomic_t fscache_n_store_ops;
50982 -extern atomic_t fscache_n_store_calls;
50983 -extern atomic_t fscache_n_store_pages;
50984 -extern atomic_t fscache_n_store_radix_deletes;
50985 -extern atomic_t fscache_n_store_pages_over_limit;
50986 +extern atomic_unchecked_t fscache_n_stores;
50987 +extern atomic_unchecked_t fscache_n_stores_ok;
50988 +extern atomic_unchecked_t fscache_n_stores_again;
50989 +extern atomic_unchecked_t fscache_n_stores_nobufs;
50990 +extern atomic_unchecked_t fscache_n_stores_oom;
50991 +extern atomic_unchecked_t fscache_n_store_ops;
50992 +extern atomic_unchecked_t fscache_n_store_calls;
50993 +extern atomic_unchecked_t fscache_n_store_pages;
50994 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
50995 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
50996
50997 -extern atomic_t fscache_n_store_vmscan_not_storing;
50998 -extern atomic_t fscache_n_store_vmscan_gone;
50999 -extern atomic_t fscache_n_store_vmscan_busy;
51000 -extern atomic_t fscache_n_store_vmscan_cancelled;
51001 -extern atomic_t fscache_n_store_vmscan_wait;
51002 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51003 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
51004 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
51005 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51006 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
51007
51008 -extern atomic_t fscache_n_marks;
51009 -extern atomic_t fscache_n_uncaches;
51010 +extern atomic_unchecked_t fscache_n_marks;
51011 +extern atomic_unchecked_t fscache_n_uncaches;
51012
51013 -extern atomic_t fscache_n_acquires;
51014 -extern atomic_t fscache_n_acquires_null;
51015 -extern atomic_t fscache_n_acquires_no_cache;
51016 -extern atomic_t fscache_n_acquires_ok;
51017 -extern atomic_t fscache_n_acquires_nobufs;
51018 -extern atomic_t fscache_n_acquires_oom;
51019 +extern atomic_unchecked_t fscache_n_acquires;
51020 +extern atomic_unchecked_t fscache_n_acquires_null;
51021 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
51022 +extern atomic_unchecked_t fscache_n_acquires_ok;
51023 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
51024 +extern atomic_unchecked_t fscache_n_acquires_oom;
51025
51026 -extern atomic_t fscache_n_invalidates;
51027 -extern atomic_t fscache_n_invalidates_run;
51028 +extern atomic_unchecked_t fscache_n_invalidates;
51029 +extern atomic_unchecked_t fscache_n_invalidates_run;
51030
51031 -extern atomic_t fscache_n_updates;
51032 -extern atomic_t fscache_n_updates_null;
51033 -extern atomic_t fscache_n_updates_run;
51034 +extern atomic_unchecked_t fscache_n_updates;
51035 +extern atomic_unchecked_t fscache_n_updates_null;
51036 +extern atomic_unchecked_t fscache_n_updates_run;
51037
51038 -extern atomic_t fscache_n_relinquishes;
51039 -extern atomic_t fscache_n_relinquishes_null;
51040 -extern atomic_t fscache_n_relinquishes_waitcrt;
51041 -extern atomic_t fscache_n_relinquishes_retire;
51042 +extern atomic_unchecked_t fscache_n_relinquishes;
51043 +extern atomic_unchecked_t fscache_n_relinquishes_null;
51044 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51045 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
51046
51047 -extern atomic_t fscache_n_cookie_index;
51048 -extern atomic_t fscache_n_cookie_data;
51049 -extern atomic_t fscache_n_cookie_special;
51050 +extern atomic_unchecked_t fscache_n_cookie_index;
51051 +extern atomic_unchecked_t fscache_n_cookie_data;
51052 +extern atomic_unchecked_t fscache_n_cookie_special;
51053
51054 -extern atomic_t fscache_n_object_alloc;
51055 -extern atomic_t fscache_n_object_no_alloc;
51056 -extern atomic_t fscache_n_object_lookups;
51057 -extern atomic_t fscache_n_object_lookups_negative;
51058 -extern atomic_t fscache_n_object_lookups_positive;
51059 -extern atomic_t fscache_n_object_lookups_timed_out;
51060 -extern atomic_t fscache_n_object_created;
51061 -extern atomic_t fscache_n_object_avail;
51062 -extern atomic_t fscache_n_object_dead;
51063 +extern atomic_unchecked_t fscache_n_object_alloc;
51064 +extern atomic_unchecked_t fscache_n_object_no_alloc;
51065 +extern atomic_unchecked_t fscache_n_object_lookups;
51066 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
51067 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
51068 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
51069 +extern atomic_unchecked_t fscache_n_object_created;
51070 +extern atomic_unchecked_t fscache_n_object_avail;
51071 +extern atomic_unchecked_t fscache_n_object_dead;
51072
51073 -extern atomic_t fscache_n_checkaux_none;
51074 -extern atomic_t fscache_n_checkaux_okay;
51075 -extern atomic_t fscache_n_checkaux_update;
51076 -extern atomic_t fscache_n_checkaux_obsolete;
51077 +extern atomic_unchecked_t fscache_n_checkaux_none;
51078 +extern atomic_unchecked_t fscache_n_checkaux_okay;
51079 +extern atomic_unchecked_t fscache_n_checkaux_update;
51080 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
51081
51082 extern atomic_t fscache_n_cop_alloc_object;
51083 extern atomic_t fscache_n_cop_lookup_object;
51084 @@ -267,6 +267,11 @@ static inline void fscache_stat(atomic_t *stat)
51085 atomic_inc(stat);
51086 }
51087
51088 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
51089 +{
51090 + atomic_inc_unchecked(stat);
51091 +}
51092 +
51093 static inline void fscache_stat_d(atomic_t *stat)
51094 {
51095 atomic_dec(stat);
51096 @@ -279,6 +284,7 @@ extern const struct file_operations fscache_stats_fops;
51097
51098 #define __fscache_stat(stat) (NULL)
51099 #define fscache_stat(stat) do {} while (0)
51100 +#define fscache_stat_unchecked(stat) do {} while (0)
51101 #define fscache_stat_d(stat) do {} while (0)
51102 #endif
51103
51104 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
51105 index 50d41c1..10ee117 100644
51106 --- a/fs/fscache/object.c
51107 +++ b/fs/fscache/object.c
51108 @@ -143,7 +143,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51109 /* Invalidate an object on disk */
51110 case FSCACHE_OBJECT_INVALIDATING:
51111 clear_bit(FSCACHE_OBJECT_EV_INVALIDATE, &object->events);
51112 - fscache_stat(&fscache_n_invalidates_run);
51113 + fscache_stat_unchecked(&fscache_n_invalidates_run);
51114 fscache_stat(&fscache_n_cop_invalidate_object);
51115 fscache_invalidate_object(object);
51116 fscache_stat_d(&fscache_n_cop_invalidate_object);
51117 @@ -153,7 +153,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51118 /* update the object metadata on disk */
51119 case FSCACHE_OBJECT_UPDATING:
51120 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
51121 - fscache_stat(&fscache_n_updates_run);
51122 + fscache_stat_unchecked(&fscache_n_updates_run);
51123 fscache_stat(&fscache_n_cop_update_object);
51124 object->cache->ops->update_object(object);
51125 fscache_stat_d(&fscache_n_cop_update_object);
51126 @@ -242,7 +242,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51127 spin_lock(&object->lock);
51128 object->state = FSCACHE_OBJECT_DEAD;
51129 spin_unlock(&object->lock);
51130 - fscache_stat(&fscache_n_object_dead);
51131 + fscache_stat_unchecked(&fscache_n_object_dead);
51132 goto terminal_transit;
51133
51134 /* handle the parent cache of this object being withdrawn from
51135 @@ -257,7 +257,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
51136 spin_lock(&object->lock);
51137 object->state = FSCACHE_OBJECT_DEAD;
51138 spin_unlock(&object->lock);
51139 - fscache_stat(&fscache_n_object_dead);
51140 + fscache_stat_unchecked(&fscache_n_object_dead);
51141 goto terminal_transit;
51142
51143 /* complain about the object being woken up once it is
51144 @@ -495,7 +495,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51145 parent->cookie->def->name, cookie->def->name,
51146 object->cache->tag->name);
51147
51148 - fscache_stat(&fscache_n_object_lookups);
51149 + fscache_stat_unchecked(&fscache_n_object_lookups);
51150 fscache_stat(&fscache_n_cop_lookup_object);
51151 ret = object->cache->ops->lookup_object(object);
51152 fscache_stat_d(&fscache_n_cop_lookup_object);
51153 @@ -506,7 +506,7 @@ static void fscache_lookup_object(struct fscache_object *object)
51154 if (ret == -ETIMEDOUT) {
51155 /* probably stuck behind another object, so move this one to
51156 * the back of the queue */
51157 - fscache_stat(&fscache_n_object_lookups_timed_out);
51158 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
51159 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51160 }
51161
51162 @@ -529,7 +529,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
51163
51164 spin_lock(&object->lock);
51165 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51166 - fscache_stat(&fscache_n_object_lookups_negative);
51167 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
51168
51169 /* transit here to allow write requests to begin stacking up
51170 * and read requests to begin returning ENODATA */
51171 @@ -575,7 +575,7 @@ void fscache_obtained_object(struct fscache_object *object)
51172 * result, in which case there may be data available */
51173 spin_lock(&object->lock);
51174 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
51175 - fscache_stat(&fscache_n_object_lookups_positive);
51176 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
51177
51178 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
51179
51180 @@ -589,7 +589,7 @@ void fscache_obtained_object(struct fscache_object *object)
51181 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
51182 } else {
51183 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
51184 - fscache_stat(&fscache_n_object_created);
51185 + fscache_stat_unchecked(&fscache_n_object_created);
51186
51187 object->state = FSCACHE_OBJECT_AVAILABLE;
51188 spin_unlock(&object->lock);
51189 @@ -634,7 +634,7 @@ static void fscache_object_available(struct fscache_object *object)
51190 fscache_enqueue_dependents(object);
51191
51192 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
51193 - fscache_stat(&fscache_n_object_avail);
51194 + fscache_stat_unchecked(&fscache_n_object_avail);
51195
51196 _leave("");
51197 }
51198 @@ -894,7 +894,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51199 enum fscache_checkaux result;
51200
51201 if (!object->cookie->def->check_aux) {
51202 - fscache_stat(&fscache_n_checkaux_none);
51203 + fscache_stat_unchecked(&fscache_n_checkaux_none);
51204 return FSCACHE_CHECKAUX_OKAY;
51205 }
51206
51207 @@ -903,17 +903,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
51208 switch (result) {
51209 /* entry okay as is */
51210 case FSCACHE_CHECKAUX_OKAY:
51211 - fscache_stat(&fscache_n_checkaux_okay);
51212 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
51213 break;
51214
51215 /* entry requires update */
51216 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
51217 - fscache_stat(&fscache_n_checkaux_update);
51218 + fscache_stat_unchecked(&fscache_n_checkaux_update);
51219 break;
51220
51221 /* entry requires deletion */
51222 case FSCACHE_CHECKAUX_OBSOLETE:
51223 - fscache_stat(&fscache_n_checkaux_obsolete);
51224 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
51225 break;
51226
51227 default:
51228 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
51229 index 762a9ec..2023284 100644
51230 --- a/fs/fscache/operation.c
51231 +++ b/fs/fscache/operation.c
51232 @@ -17,7 +17,7 @@
51233 #include <linux/slab.h>
51234 #include "internal.h"
51235
51236 -atomic_t fscache_op_debug_id;
51237 +atomic_unchecked_t fscache_op_debug_id;
51238 EXPORT_SYMBOL(fscache_op_debug_id);
51239
51240 /**
51241 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
51242 ASSERTCMP(atomic_read(&op->usage), >, 0);
51243 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
51244
51245 - fscache_stat(&fscache_n_op_enqueue);
51246 + fscache_stat_unchecked(&fscache_n_op_enqueue);
51247 switch (op->flags & FSCACHE_OP_TYPE) {
51248 case FSCACHE_OP_ASYNC:
51249 _debug("queue async");
51250 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
51251 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
51252 if (op->processor)
51253 fscache_enqueue_operation(op);
51254 - fscache_stat(&fscache_n_op_run);
51255 + fscache_stat_unchecked(&fscache_n_op_run);
51256 }
51257
51258 /*
51259 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51260 if (object->n_in_progress > 0) {
51261 atomic_inc(&op->usage);
51262 list_add_tail(&op->pend_link, &object->pending_ops);
51263 - fscache_stat(&fscache_n_op_pend);
51264 + fscache_stat_unchecked(&fscache_n_op_pend);
51265 } else if (!list_empty(&object->pending_ops)) {
51266 atomic_inc(&op->usage);
51267 list_add_tail(&op->pend_link, &object->pending_ops);
51268 - fscache_stat(&fscache_n_op_pend);
51269 + fscache_stat_unchecked(&fscache_n_op_pend);
51270 fscache_start_operations(object);
51271 } else {
51272 ASSERTCMP(object->n_in_progress, ==, 0);
51273 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
51274 object->n_exclusive++; /* reads and writes must wait */
51275 atomic_inc(&op->usage);
51276 list_add_tail(&op->pend_link, &object->pending_ops);
51277 - fscache_stat(&fscache_n_op_pend);
51278 + fscache_stat_unchecked(&fscache_n_op_pend);
51279 ret = 0;
51280 } else {
51281 /* If we're in any other state, there must have been an I/O
51282 @@ -215,11 +215,11 @@ int fscache_submit_op(struct fscache_object *object,
51283 if (object->n_exclusive > 0) {
51284 atomic_inc(&op->usage);
51285 list_add_tail(&op->pend_link, &object->pending_ops);
51286 - fscache_stat(&fscache_n_op_pend);
51287 + fscache_stat_unchecked(&fscache_n_op_pend);
51288 } else if (!list_empty(&object->pending_ops)) {
51289 atomic_inc(&op->usage);
51290 list_add_tail(&op->pend_link, &object->pending_ops);
51291 - fscache_stat(&fscache_n_op_pend);
51292 + fscache_stat_unchecked(&fscache_n_op_pend);
51293 fscache_start_operations(object);
51294 } else {
51295 ASSERTCMP(object->n_exclusive, ==, 0);
51296 @@ -231,12 +231,12 @@ int fscache_submit_op(struct fscache_object *object,
51297 object->n_ops++;
51298 atomic_inc(&op->usage);
51299 list_add_tail(&op->pend_link, &object->pending_ops);
51300 - fscache_stat(&fscache_n_op_pend);
51301 + fscache_stat_unchecked(&fscache_n_op_pend);
51302 ret = 0;
51303 } else if (object->state == FSCACHE_OBJECT_DYING ||
51304 object->state == FSCACHE_OBJECT_LC_DYING ||
51305 object->state == FSCACHE_OBJECT_WITHDRAWING) {
51306 - fscache_stat(&fscache_n_op_rejected);
51307 + fscache_stat_unchecked(&fscache_n_op_rejected);
51308 op->state = FSCACHE_OP_ST_CANCELLED;
51309 ret = -ENOBUFS;
51310 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
51311 @@ -315,7 +315,7 @@ int fscache_cancel_op(struct fscache_operation *op,
51312 ret = -EBUSY;
51313 if (op->state == FSCACHE_OP_ST_PENDING) {
51314 ASSERT(!list_empty(&op->pend_link));
51315 - fscache_stat(&fscache_n_op_cancelled);
51316 + fscache_stat_unchecked(&fscache_n_op_cancelled);
51317 list_del_init(&op->pend_link);
51318 if (do_cancel)
51319 do_cancel(op);
51320 @@ -347,7 +347,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
51321 while (!list_empty(&object->pending_ops)) {
51322 op = list_entry(object->pending_ops.next,
51323 struct fscache_operation, pend_link);
51324 - fscache_stat(&fscache_n_op_cancelled);
51325 + fscache_stat_unchecked(&fscache_n_op_cancelled);
51326 list_del_init(&op->pend_link);
51327
51328 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
51329 @@ -419,7 +419,7 @@ void fscache_put_operation(struct fscache_operation *op)
51330 op->state, ==, FSCACHE_OP_ST_CANCELLED);
51331 op->state = FSCACHE_OP_ST_DEAD;
51332
51333 - fscache_stat(&fscache_n_op_release);
51334 + fscache_stat_unchecked(&fscache_n_op_release);
51335
51336 if (op->release) {
51337 op->release(op);
51338 @@ -442,7 +442,7 @@ void fscache_put_operation(struct fscache_operation *op)
51339 * lock, and defer it otherwise */
51340 if (!spin_trylock(&object->lock)) {
51341 _debug("defer put");
51342 - fscache_stat(&fscache_n_op_deferred_release);
51343 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
51344
51345 cache = object->cache;
51346 spin_lock(&cache->op_gc_list_lock);
51347 @@ -495,7 +495,7 @@ void fscache_operation_gc(struct work_struct *work)
51348
51349 _debug("GC DEFERRED REL OBJ%x OP%x",
51350 object->debug_id, op->debug_id);
51351 - fscache_stat(&fscache_n_op_gc);
51352 + fscache_stat_unchecked(&fscache_n_op_gc);
51353
51354 ASSERTCMP(atomic_read(&op->usage), ==, 0);
51355 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
51356 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
51357 index ff000e5..c44ec6d 100644
51358 --- a/fs/fscache/page.c
51359 +++ b/fs/fscache/page.c
51360 @@ -61,7 +61,7 @@ try_again:
51361 val = radix_tree_lookup(&cookie->stores, page->index);
51362 if (!val) {
51363 rcu_read_unlock();
51364 - fscache_stat(&fscache_n_store_vmscan_not_storing);
51365 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
51366 __fscache_uncache_page(cookie, page);
51367 return true;
51368 }
51369 @@ -91,11 +91,11 @@ try_again:
51370 spin_unlock(&cookie->stores_lock);
51371
51372 if (xpage) {
51373 - fscache_stat(&fscache_n_store_vmscan_cancelled);
51374 - fscache_stat(&fscache_n_store_radix_deletes);
51375 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
51376 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51377 ASSERTCMP(xpage, ==, page);
51378 } else {
51379 - fscache_stat(&fscache_n_store_vmscan_gone);
51380 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
51381 }
51382
51383 wake_up_bit(&cookie->flags, 0);
51384 @@ -110,11 +110,11 @@ page_busy:
51385 * sleeping on memory allocation, so we may need to impose a timeout
51386 * too. */
51387 if (!(gfp & __GFP_WAIT)) {
51388 - fscache_stat(&fscache_n_store_vmscan_busy);
51389 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
51390 return false;
51391 }
51392
51393 - fscache_stat(&fscache_n_store_vmscan_wait);
51394 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
51395 __fscache_wait_on_page_write(cookie, page);
51396 gfp &= ~__GFP_WAIT;
51397 goto try_again;
51398 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
51399 FSCACHE_COOKIE_STORING_TAG);
51400 if (!radix_tree_tag_get(&cookie->stores, page->index,
51401 FSCACHE_COOKIE_PENDING_TAG)) {
51402 - fscache_stat(&fscache_n_store_radix_deletes);
51403 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
51404 xpage = radix_tree_delete(&cookie->stores, page->index);
51405 }
51406 spin_unlock(&cookie->stores_lock);
51407 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
51408
51409 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
51410
51411 - fscache_stat(&fscache_n_attr_changed_calls);
51412 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
51413
51414 if (fscache_object_is_active(object)) {
51415 fscache_stat(&fscache_n_cop_attr_changed);
51416 @@ -187,11 +187,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51417
51418 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51419
51420 - fscache_stat(&fscache_n_attr_changed);
51421 + fscache_stat_unchecked(&fscache_n_attr_changed);
51422
51423 op = kzalloc(sizeof(*op), GFP_KERNEL);
51424 if (!op) {
51425 - fscache_stat(&fscache_n_attr_changed_nomem);
51426 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
51427 _leave(" = -ENOMEM");
51428 return -ENOMEM;
51429 }
51430 @@ -209,7 +209,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51431 if (fscache_submit_exclusive_op(object, op) < 0)
51432 goto nobufs;
51433 spin_unlock(&cookie->lock);
51434 - fscache_stat(&fscache_n_attr_changed_ok);
51435 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
51436 fscache_put_operation(op);
51437 _leave(" = 0");
51438 return 0;
51439 @@ -217,7 +217,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
51440 nobufs:
51441 spin_unlock(&cookie->lock);
51442 kfree(op);
51443 - fscache_stat(&fscache_n_attr_changed_nobufs);
51444 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
51445 _leave(" = %d", -ENOBUFS);
51446 return -ENOBUFS;
51447 }
51448 @@ -255,7 +255,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
51449 /* allocate a retrieval operation and attempt to submit it */
51450 op = kzalloc(sizeof(*op), GFP_NOIO);
51451 if (!op) {
51452 - fscache_stat(&fscache_n_retrievals_nomem);
51453 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51454 return NULL;
51455 }
51456
51457 @@ -283,13 +283,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
51458 return 0;
51459 }
51460
51461 - fscache_stat(&fscache_n_retrievals_wait);
51462 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
51463
51464 jif = jiffies;
51465 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
51466 fscache_wait_bit_interruptible,
51467 TASK_INTERRUPTIBLE) != 0) {
51468 - fscache_stat(&fscache_n_retrievals_intr);
51469 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51470 _leave(" = -ERESTARTSYS");
51471 return -ERESTARTSYS;
51472 }
51473 @@ -318,8 +318,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
51474 */
51475 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51476 struct fscache_retrieval *op,
51477 - atomic_t *stat_op_waits,
51478 - atomic_t *stat_object_dead)
51479 + atomic_unchecked_t *stat_op_waits,
51480 + atomic_unchecked_t *stat_object_dead)
51481 {
51482 int ret;
51483
51484 @@ -327,7 +327,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51485 goto check_if_dead;
51486
51487 _debug(">>> WT");
51488 - fscache_stat(stat_op_waits);
51489 + fscache_stat_unchecked(stat_op_waits);
51490 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
51491 fscache_wait_bit_interruptible,
51492 TASK_INTERRUPTIBLE) != 0) {
51493 @@ -344,14 +344,14 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
51494
51495 check_if_dead:
51496 if (op->op.state == FSCACHE_OP_ST_CANCELLED) {
51497 - fscache_stat(stat_object_dead);
51498 + fscache_stat_unchecked(stat_object_dead);
51499 _leave(" = -ENOBUFS [cancelled]");
51500 return -ENOBUFS;
51501 }
51502 if (unlikely(fscache_object_is_dead(object))) {
51503 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->op.state);
51504 fscache_cancel_op(&op->op, fscache_do_cancel_retrieval);
51505 - fscache_stat(stat_object_dead);
51506 + fscache_stat_unchecked(stat_object_dead);
51507 return -ENOBUFS;
51508 }
51509 return 0;
51510 @@ -378,7 +378,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51511
51512 _enter("%p,%p,,,", cookie, page);
51513
51514 - fscache_stat(&fscache_n_retrievals);
51515 + fscache_stat_unchecked(&fscache_n_retrievals);
51516
51517 if (hlist_empty(&cookie->backing_objects))
51518 goto nobufs;
51519 @@ -417,7 +417,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51520 goto nobufs_unlock_dec;
51521 spin_unlock(&cookie->lock);
51522
51523 - fscache_stat(&fscache_n_retrieval_ops);
51524 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
51525
51526 /* pin the netfs read context in case we need to do the actual netfs
51527 * read because we've encountered a cache read failure */
51528 @@ -447,15 +447,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
51529
51530 error:
51531 if (ret == -ENOMEM)
51532 - fscache_stat(&fscache_n_retrievals_nomem);
51533 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51534 else if (ret == -ERESTARTSYS)
51535 - fscache_stat(&fscache_n_retrievals_intr);
51536 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51537 else if (ret == -ENODATA)
51538 - fscache_stat(&fscache_n_retrievals_nodata);
51539 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51540 else if (ret < 0)
51541 - fscache_stat(&fscache_n_retrievals_nobufs);
51542 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51543 else
51544 - fscache_stat(&fscache_n_retrievals_ok);
51545 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
51546
51547 fscache_put_retrieval(op);
51548 _leave(" = %d", ret);
51549 @@ -467,7 +467,7 @@ nobufs_unlock:
51550 spin_unlock(&cookie->lock);
51551 kfree(op);
51552 nobufs:
51553 - fscache_stat(&fscache_n_retrievals_nobufs);
51554 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51555 _leave(" = -ENOBUFS");
51556 return -ENOBUFS;
51557 }
51558 @@ -505,7 +505,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51559
51560 _enter("%p,,%d,,,", cookie, *nr_pages);
51561
51562 - fscache_stat(&fscache_n_retrievals);
51563 + fscache_stat_unchecked(&fscache_n_retrievals);
51564
51565 if (hlist_empty(&cookie->backing_objects))
51566 goto nobufs;
51567 @@ -541,7 +541,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51568 goto nobufs_unlock_dec;
51569 spin_unlock(&cookie->lock);
51570
51571 - fscache_stat(&fscache_n_retrieval_ops);
51572 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
51573
51574 /* pin the netfs read context in case we need to do the actual netfs
51575 * read because we've encountered a cache read failure */
51576 @@ -571,15 +571,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
51577
51578 error:
51579 if (ret == -ENOMEM)
51580 - fscache_stat(&fscache_n_retrievals_nomem);
51581 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
51582 else if (ret == -ERESTARTSYS)
51583 - fscache_stat(&fscache_n_retrievals_intr);
51584 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
51585 else if (ret == -ENODATA)
51586 - fscache_stat(&fscache_n_retrievals_nodata);
51587 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
51588 else if (ret < 0)
51589 - fscache_stat(&fscache_n_retrievals_nobufs);
51590 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51591 else
51592 - fscache_stat(&fscache_n_retrievals_ok);
51593 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
51594
51595 fscache_put_retrieval(op);
51596 _leave(" = %d", ret);
51597 @@ -591,7 +591,7 @@ nobufs_unlock:
51598 spin_unlock(&cookie->lock);
51599 kfree(op);
51600 nobufs:
51601 - fscache_stat(&fscache_n_retrievals_nobufs);
51602 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
51603 _leave(" = -ENOBUFS");
51604 return -ENOBUFS;
51605 }
51606 @@ -615,7 +615,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51607
51608 _enter("%p,%p,,,", cookie, page);
51609
51610 - fscache_stat(&fscache_n_allocs);
51611 + fscache_stat_unchecked(&fscache_n_allocs);
51612
51613 if (hlist_empty(&cookie->backing_objects))
51614 goto nobufs;
51615 @@ -647,7 +647,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51616 goto nobufs_unlock;
51617 spin_unlock(&cookie->lock);
51618
51619 - fscache_stat(&fscache_n_alloc_ops);
51620 + fscache_stat_unchecked(&fscache_n_alloc_ops);
51621
51622 ret = fscache_wait_for_retrieval_activation(
51623 object, op,
51624 @@ -663,11 +663,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
51625
51626 error:
51627 if (ret == -ERESTARTSYS)
51628 - fscache_stat(&fscache_n_allocs_intr);
51629 + fscache_stat_unchecked(&fscache_n_allocs_intr);
51630 else if (ret < 0)
51631 - fscache_stat(&fscache_n_allocs_nobufs);
51632 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51633 else
51634 - fscache_stat(&fscache_n_allocs_ok);
51635 + fscache_stat_unchecked(&fscache_n_allocs_ok);
51636
51637 fscache_put_retrieval(op);
51638 _leave(" = %d", ret);
51639 @@ -677,7 +677,7 @@ nobufs_unlock:
51640 spin_unlock(&cookie->lock);
51641 kfree(op);
51642 nobufs:
51643 - fscache_stat(&fscache_n_allocs_nobufs);
51644 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
51645 _leave(" = -ENOBUFS");
51646 return -ENOBUFS;
51647 }
51648 @@ -736,7 +736,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51649
51650 spin_lock(&cookie->stores_lock);
51651
51652 - fscache_stat(&fscache_n_store_calls);
51653 + fscache_stat_unchecked(&fscache_n_store_calls);
51654
51655 /* find a page to store */
51656 page = NULL;
51657 @@ -747,7 +747,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51658 page = results[0];
51659 _debug("gang %d [%lx]", n, page->index);
51660 if (page->index > op->store_limit) {
51661 - fscache_stat(&fscache_n_store_pages_over_limit);
51662 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
51663 goto superseded;
51664 }
51665
51666 @@ -759,7 +759,7 @@ static void fscache_write_op(struct fscache_operation *_op)
51667 spin_unlock(&cookie->stores_lock);
51668 spin_unlock(&object->lock);
51669
51670 - fscache_stat(&fscache_n_store_pages);
51671 + fscache_stat_unchecked(&fscache_n_store_pages);
51672 fscache_stat(&fscache_n_cop_write_page);
51673 ret = object->cache->ops->write_page(op, page);
51674 fscache_stat_d(&fscache_n_cop_write_page);
51675 @@ -860,7 +860,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51676 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51677 ASSERT(PageFsCache(page));
51678
51679 - fscache_stat(&fscache_n_stores);
51680 + fscache_stat_unchecked(&fscache_n_stores);
51681
51682 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
51683 _leave(" = -ENOBUFS [invalidating]");
51684 @@ -916,7 +916,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51685 spin_unlock(&cookie->stores_lock);
51686 spin_unlock(&object->lock);
51687
51688 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
51689 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
51690 op->store_limit = object->store_limit;
51691
51692 if (fscache_submit_op(object, &op->op) < 0)
51693 @@ -924,8 +924,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51694
51695 spin_unlock(&cookie->lock);
51696 radix_tree_preload_end();
51697 - fscache_stat(&fscache_n_store_ops);
51698 - fscache_stat(&fscache_n_stores_ok);
51699 + fscache_stat_unchecked(&fscache_n_store_ops);
51700 + fscache_stat_unchecked(&fscache_n_stores_ok);
51701
51702 /* the work queue now carries its own ref on the object */
51703 fscache_put_operation(&op->op);
51704 @@ -933,14 +933,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
51705 return 0;
51706
51707 already_queued:
51708 - fscache_stat(&fscache_n_stores_again);
51709 + fscache_stat_unchecked(&fscache_n_stores_again);
51710 already_pending:
51711 spin_unlock(&cookie->stores_lock);
51712 spin_unlock(&object->lock);
51713 spin_unlock(&cookie->lock);
51714 radix_tree_preload_end();
51715 kfree(op);
51716 - fscache_stat(&fscache_n_stores_ok);
51717 + fscache_stat_unchecked(&fscache_n_stores_ok);
51718 _leave(" = 0");
51719 return 0;
51720
51721 @@ -959,14 +959,14 @@ nobufs:
51722 spin_unlock(&cookie->lock);
51723 radix_tree_preload_end();
51724 kfree(op);
51725 - fscache_stat(&fscache_n_stores_nobufs);
51726 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
51727 _leave(" = -ENOBUFS");
51728 return -ENOBUFS;
51729
51730 nomem_free:
51731 kfree(op);
51732 nomem:
51733 - fscache_stat(&fscache_n_stores_oom);
51734 + fscache_stat_unchecked(&fscache_n_stores_oom);
51735 _leave(" = -ENOMEM");
51736 return -ENOMEM;
51737 }
51738 @@ -984,7 +984,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
51739 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
51740 ASSERTCMP(page, !=, NULL);
51741
51742 - fscache_stat(&fscache_n_uncaches);
51743 + fscache_stat_unchecked(&fscache_n_uncaches);
51744
51745 /* cache withdrawal may beat us to it */
51746 if (!PageFsCache(page))
51747 @@ -1035,7 +1035,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
51748 struct fscache_cookie *cookie = op->op.object->cookie;
51749
51750 #ifdef CONFIG_FSCACHE_STATS
51751 - atomic_inc(&fscache_n_marks);
51752 + atomic_inc_unchecked(&fscache_n_marks);
51753 #endif
51754
51755 _debug("- mark %p{%lx}", page, page->index);
51756 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
51757 index 8179e8b..5072cc7 100644
51758 --- a/fs/fscache/stats.c
51759 +++ b/fs/fscache/stats.c
51760 @@ -18,99 +18,99 @@
51761 /*
51762 * operation counters
51763 */
51764 -atomic_t fscache_n_op_pend;
51765 -atomic_t fscache_n_op_run;
51766 -atomic_t fscache_n_op_enqueue;
51767 -atomic_t fscache_n_op_requeue;
51768 -atomic_t fscache_n_op_deferred_release;
51769 -atomic_t fscache_n_op_release;
51770 -atomic_t fscache_n_op_gc;
51771 -atomic_t fscache_n_op_cancelled;
51772 -atomic_t fscache_n_op_rejected;
51773 +atomic_unchecked_t fscache_n_op_pend;
51774 +atomic_unchecked_t fscache_n_op_run;
51775 +atomic_unchecked_t fscache_n_op_enqueue;
51776 +atomic_unchecked_t fscache_n_op_requeue;
51777 +atomic_unchecked_t fscache_n_op_deferred_release;
51778 +atomic_unchecked_t fscache_n_op_release;
51779 +atomic_unchecked_t fscache_n_op_gc;
51780 +atomic_unchecked_t fscache_n_op_cancelled;
51781 +atomic_unchecked_t fscache_n_op_rejected;
51782
51783 -atomic_t fscache_n_attr_changed;
51784 -atomic_t fscache_n_attr_changed_ok;
51785 -atomic_t fscache_n_attr_changed_nobufs;
51786 -atomic_t fscache_n_attr_changed_nomem;
51787 -atomic_t fscache_n_attr_changed_calls;
51788 +atomic_unchecked_t fscache_n_attr_changed;
51789 +atomic_unchecked_t fscache_n_attr_changed_ok;
51790 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
51791 +atomic_unchecked_t fscache_n_attr_changed_nomem;
51792 +atomic_unchecked_t fscache_n_attr_changed_calls;
51793
51794 -atomic_t fscache_n_allocs;
51795 -atomic_t fscache_n_allocs_ok;
51796 -atomic_t fscache_n_allocs_wait;
51797 -atomic_t fscache_n_allocs_nobufs;
51798 -atomic_t fscache_n_allocs_intr;
51799 -atomic_t fscache_n_allocs_object_dead;
51800 -atomic_t fscache_n_alloc_ops;
51801 -atomic_t fscache_n_alloc_op_waits;
51802 +atomic_unchecked_t fscache_n_allocs;
51803 +atomic_unchecked_t fscache_n_allocs_ok;
51804 +atomic_unchecked_t fscache_n_allocs_wait;
51805 +atomic_unchecked_t fscache_n_allocs_nobufs;
51806 +atomic_unchecked_t fscache_n_allocs_intr;
51807 +atomic_unchecked_t fscache_n_allocs_object_dead;
51808 +atomic_unchecked_t fscache_n_alloc_ops;
51809 +atomic_unchecked_t fscache_n_alloc_op_waits;
51810
51811 -atomic_t fscache_n_retrievals;
51812 -atomic_t fscache_n_retrievals_ok;
51813 -atomic_t fscache_n_retrievals_wait;
51814 -atomic_t fscache_n_retrievals_nodata;
51815 -atomic_t fscache_n_retrievals_nobufs;
51816 -atomic_t fscache_n_retrievals_intr;
51817 -atomic_t fscache_n_retrievals_nomem;
51818 -atomic_t fscache_n_retrievals_object_dead;
51819 -atomic_t fscache_n_retrieval_ops;
51820 -atomic_t fscache_n_retrieval_op_waits;
51821 +atomic_unchecked_t fscache_n_retrievals;
51822 +atomic_unchecked_t fscache_n_retrievals_ok;
51823 +atomic_unchecked_t fscache_n_retrievals_wait;
51824 +atomic_unchecked_t fscache_n_retrievals_nodata;
51825 +atomic_unchecked_t fscache_n_retrievals_nobufs;
51826 +atomic_unchecked_t fscache_n_retrievals_intr;
51827 +atomic_unchecked_t fscache_n_retrievals_nomem;
51828 +atomic_unchecked_t fscache_n_retrievals_object_dead;
51829 +atomic_unchecked_t fscache_n_retrieval_ops;
51830 +atomic_unchecked_t fscache_n_retrieval_op_waits;
51831
51832 -atomic_t fscache_n_stores;
51833 -atomic_t fscache_n_stores_ok;
51834 -atomic_t fscache_n_stores_again;
51835 -atomic_t fscache_n_stores_nobufs;
51836 -atomic_t fscache_n_stores_oom;
51837 -atomic_t fscache_n_store_ops;
51838 -atomic_t fscache_n_store_calls;
51839 -atomic_t fscache_n_store_pages;
51840 -atomic_t fscache_n_store_radix_deletes;
51841 -atomic_t fscache_n_store_pages_over_limit;
51842 +atomic_unchecked_t fscache_n_stores;
51843 +atomic_unchecked_t fscache_n_stores_ok;
51844 +atomic_unchecked_t fscache_n_stores_again;
51845 +atomic_unchecked_t fscache_n_stores_nobufs;
51846 +atomic_unchecked_t fscache_n_stores_oom;
51847 +atomic_unchecked_t fscache_n_store_ops;
51848 +atomic_unchecked_t fscache_n_store_calls;
51849 +atomic_unchecked_t fscache_n_store_pages;
51850 +atomic_unchecked_t fscache_n_store_radix_deletes;
51851 +atomic_unchecked_t fscache_n_store_pages_over_limit;
51852
51853 -atomic_t fscache_n_store_vmscan_not_storing;
51854 -atomic_t fscache_n_store_vmscan_gone;
51855 -atomic_t fscache_n_store_vmscan_busy;
51856 -atomic_t fscache_n_store_vmscan_cancelled;
51857 -atomic_t fscache_n_store_vmscan_wait;
51858 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
51859 +atomic_unchecked_t fscache_n_store_vmscan_gone;
51860 +atomic_unchecked_t fscache_n_store_vmscan_busy;
51861 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
51862 +atomic_unchecked_t fscache_n_store_vmscan_wait;
51863
51864 -atomic_t fscache_n_marks;
51865 -atomic_t fscache_n_uncaches;
51866 +atomic_unchecked_t fscache_n_marks;
51867 +atomic_unchecked_t fscache_n_uncaches;
51868
51869 -atomic_t fscache_n_acquires;
51870 -atomic_t fscache_n_acquires_null;
51871 -atomic_t fscache_n_acquires_no_cache;
51872 -atomic_t fscache_n_acquires_ok;
51873 -atomic_t fscache_n_acquires_nobufs;
51874 -atomic_t fscache_n_acquires_oom;
51875 +atomic_unchecked_t fscache_n_acquires;
51876 +atomic_unchecked_t fscache_n_acquires_null;
51877 +atomic_unchecked_t fscache_n_acquires_no_cache;
51878 +atomic_unchecked_t fscache_n_acquires_ok;
51879 +atomic_unchecked_t fscache_n_acquires_nobufs;
51880 +atomic_unchecked_t fscache_n_acquires_oom;
51881
51882 -atomic_t fscache_n_invalidates;
51883 -atomic_t fscache_n_invalidates_run;
51884 +atomic_unchecked_t fscache_n_invalidates;
51885 +atomic_unchecked_t fscache_n_invalidates_run;
51886
51887 -atomic_t fscache_n_updates;
51888 -atomic_t fscache_n_updates_null;
51889 -atomic_t fscache_n_updates_run;
51890 +atomic_unchecked_t fscache_n_updates;
51891 +atomic_unchecked_t fscache_n_updates_null;
51892 +atomic_unchecked_t fscache_n_updates_run;
51893
51894 -atomic_t fscache_n_relinquishes;
51895 -atomic_t fscache_n_relinquishes_null;
51896 -atomic_t fscache_n_relinquishes_waitcrt;
51897 -atomic_t fscache_n_relinquishes_retire;
51898 +atomic_unchecked_t fscache_n_relinquishes;
51899 +atomic_unchecked_t fscache_n_relinquishes_null;
51900 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
51901 +atomic_unchecked_t fscache_n_relinquishes_retire;
51902
51903 -atomic_t fscache_n_cookie_index;
51904 -atomic_t fscache_n_cookie_data;
51905 -atomic_t fscache_n_cookie_special;
51906 +atomic_unchecked_t fscache_n_cookie_index;
51907 +atomic_unchecked_t fscache_n_cookie_data;
51908 +atomic_unchecked_t fscache_n_cookie_special;
51909
51910 -atomic_t fscache_n_object_alloc;
51911 -atomic_t fscache_n_object_no_alloc;
51912 -atomic_t fscache_n_object_lookups;
51913 -atomic_t fscache_n_object_lookups_negative;
51914 -atomic_t fscache_n_object_lookups_positive;
51915 -atomic_t fscache_n_object_lookups_timed_out;
51916 -atomic_t fscache_n_object_created;
51917 -atomic_t fscache_n_object_avail;
51918 -atomic_t fscache_n_object_dead;
51919 +atomic_unchecked_t fscache_n_object_alloc;
51920 +atomic_unchecked_t fscache_n_object_no_alloc;
51921 +atomic_unchecked_t fscache_n_object_lookups;
51922 +atomic_unchecked_t fscache_n_object_lookups_negative;
51923 +atomic_unchecked_t fscache_n_object_lookups_positive;
51924 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
51925 +atomic_unchecked_t fscache_n_object_created;
51926 +atomic_unchecked_t fscache_n_object_avail;
51927 +atomic_unchecked_t fscache_n_object_dead;
51928
51929 -atomic_t fscache_n_checkaux_none;
51930 -atomic_t fscache_n_checkaux_okay;
51931 -atomic_t fscache_n_checkaux_update;
51932 -atomic_t fscache_n_checkaux_obsolete;
51933 +atomic_unchecked_t fscache_n_checkaux_none;
51934 +atomic_unchecked_t fscache_n_checkaux_okay;
51935 +atomic_unchecked_t fscache_n_checkaux_update;
51936 +atomic_unchecked_t fscache_n_checkaux_obsolete;
51937
51938 atomic_t fscache_n_cop_alloc_object;
51939 atomic_t fscache_n_cop_lookup_object;
51940 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
51941 seq_puts(m, "FS-Cache statistics\n");
51942
51943 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
51944 - atomic_read(&fscache_n_cookie_index),
51945 - atomic_read(&fscache_n_cookie_data),
51946 - atomic_read(&fscache_n_cookie_special));
51947 + atomic_read_unchecked(&fscache_n_cookie_index),
51948 + atomic_read_unchecked(&fscache_n_cookie_data),
51949 + atomic_read_unchecked(&fscache_n_cookie_special));
51950
51951 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
51952 - atomic_read(&fscache_n_object_alloc),
51953 - atomic_read(&fscache_n_object_no_alloc),
51954 - atomic_read(&fscache_n_object_avail),
51955 - atomic_read(&fscache_n_object_dead));
51956 + atomic_read_unchecked(&fscache_n_object_alloc),
51957 + atomic_read_unchecked(&fscache_n_object_no_alloc),
51958 + atomic_read_unchecked(&fscache_n_object_avail),
51959 + atomic_read_unchecked(&fscache_n_object_dead));
51960 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
51961 - atomic_read(&fscache_n_checkaux_none),
51962 - atomic_read(&fscache_n_checkaux_okay),
51963 - atomic_read(&fscache_n_checkaux_update),
51964 - atomic_read(&fscache_n_checkaux_obsolete));
51965 + atomic_read_unchecked(&fscache_n_checkaux_none),
51966 + atomic_read_unchecked(&fscache_n_checkaux_okay),
51967 + atomic_read_unchecked(&fscache_n_checkaux_update),
51968 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
51969
51970 seq_printf(m, "Pages : mrk=%u unc=%u\n",
51971 - atomic_read(&fscache_n_marks),
51972 - atomic_read(&fscache_n_uncaches));
51973 + atomic_read_unchecked(&fscache_n_marks),
51974 + atomic_read_unchecked(&fscache_n_uncaches));
51975
51976 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
51977 " oom=%u\n",
51978 - atomic_read(&fscache_n_acquires),
51979 - atomic_read(&fscache_n_acquires_null),
51980 - atomic_read(&fscache_n_acquires_no_cache),
51981 - atomic_read(&fscache_n_acquires_ok),
51982 - atomic_read(&fscache_n_acquires_nobufs),
51983 - atomic_read(&fscache_n_acquires_oom));
51984 + atomic_read_unchecked(&fscache_n_acquires),
51985 + atomic_read_unchecked(&fscache_n_acquires_null),
51986 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
51987 + atomic_read_unchecked(&fscache_n_acquires_ok),
51988 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
51989 + atomic_read_unchecked(&fscache_n_acquires_oom));
51990
51991 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
51992 - atomic_read(&fscache_n_object_lookups),
51993 - atomic_read(&fscache_n_object_lookups_negative),
51994 - atomic_read(&fscache_n_object_lookups_positive),
51995 - atomic_read(&fscache_n_object_created),
51996 - atomic_read(&fscache_n_object_lookups_timed_out));
51997 + atomic_read_unchecked(&fscache_n_object_lookups),
51998 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
51999 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
52000 + atomic_read_unchecked(&fscache_n_object_created),
52001 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
52002
52003 seq_printf(m, "Invals : n=%u run=%u\n",
52004 - atomic_read(&fscache_n_invalidates),
52005 - atomic_read(&fscache_n_invalidates_run));
52006 + atomic_read_unchecked(&fscache_n_invalidates),
52007 + atomic_read_unchecked(&fscache_n_invalidates_run));
52008
52009 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
52010 - atomic_read(&fscache_n_updates),
52011 - atomic_read(&fscache_n_updates_null),
52012 - atomic_read(&fscache_n_updates_run));
52013 + atomic_read_unchecked(&fscache_n_updates),
52014 + atomic_read_unchecked(&fscache_n_updates_null),
52015 + atomic_read_unchecked(&fscache_n_updates_run));
52016
52017 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
52018 - atomic_read(&fscache_n_relinquishes),
52019 - atomic_read(&fscache_n_relinquishes_null),
52020 - atomic_read(&fscache_n_relinquishes_waitcrt),
52021 - atomic_read(&fscache_n_relinquishes_retire));
52022 + atomic_read_unchecked(&fscache_n_relinquishes),
52023 + atomic_read_unchecked(&fscache_n_relinquishes_null),
52024 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
52025 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
52026
52027 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
52028 - atomic_read(&fscache_n_attr_changed),
52029 - atomic_read(&fscache_n_attr_changed_ok),
52030 - atomic_read(&fscache_n_attr_changed_nobufs),
52031 - atomic_read(&fscache_n_attr_changed_nomem),
52032 - atomic_read(&fscache_n_attr_changed_calls));
52033 + atomic_read_unchecked(&fscache_n_attr_changed),
52034 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
52035 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
52036 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
52037 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
52038
52039 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
52040 - atomic_read(&fscache_n_allocs),
52041 - atomic_read(&fscache_n_allocs_ok),
52042 - atomic_read(&fscache_n_allocs_wait),
52043 - atomic_read(&fscache_n_allocs_nobufs),
52044 - atomic_read(&fscache_n_allocs_intr));
52045 + atomic_read_unchecked(&fscache_n_allocs),
52046 + atomic_read_unchecked(&fscache_n_allocs_ok),
52047 + atomic_read_unchecked(&fscache_n_allocs_wait),
52048 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
52049 + atomic_read_unchecked(&fscache_n_allocs_intr));
52050 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
52051 - atomic_read(&fscache_n_alloc_ops),
52052 - atomic_read(&fscache_n_alloc_op_waits),
52053 - atomic_read(&fscache_n_allocs_object_dead));
52054 + atomic_read_unchecked(&fscache_n_alloc_ops),
52055 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
52056 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
52057
52058 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
52059 " int=%u oom=%u\n",
52060 - atomic_read(&fscache_n_retrievals),
52061 - atomic_read(&fscache_n_retrievals_ok),
52062 - atomic_read(&fscache_n_retrievals_wait),
52063 - atomic_read(&fscache_n_retrievals_nodata),
52064 - atomic_read(&fscache_n_retrievals_nobufs),
52065 - atomic_read(&fscache_n_retrievals_intr),
52066 - atomic_read(&fscache_n_retrievals_nomem));
52067 + atomic_read_unchecked(&fscache_n_retrievals),
52068 + atomic_read_unchecked(&fscache_n_retrievals_ok),
52069 + atomic_read_unchecked(&fscache_n_retrievals_wait),
52070 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
52071 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
52072 + atomic_read_unchecked(&fscache_n_retrievals_intr),
52073 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
52074 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
52075 - atomic_read(&fscache_n_retrieval_ops),
52076 - atomic_read(&fscache_n_retrieval_op_waits),
52077 - atomic_read(&fscache_n_retrievals_object_dead));
52078 + atomic_read_unchecked(&fscache_n_retrieval_ops),
52079 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
52080 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
52081
52082 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
52083 - atomic_read(&fscache_n_stores),
52084 - atomic_read(&fscache_n_stores_ok),
52085 - atomic_read(&fscache_n_stores_again),
52086 - atomic_read(&fscache_n_stores_nobufs),
52087 - atomic_read(&fscache_n_stores_oom));
52088 + atomic_read_unchecked(&fscache_n_stores),
52089 + atomic_read_unchecked(&fscache_n_stores_ok),
52090 + atomic_read_unchecked(&fscache_n_stores_again),
52091 + atomic_read_unchecked(&fscache_n_stores_nobufs),
52092 + atomic_read_unchecked(&fscache_n_stores_oom));
52093 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
52094 - atomic_read(&fscache_n_store_ops),
52095 - atomic_read(&fscache_n_store_calls),
52096 - atomic_read(&fscache_n_store_pages),
52097 - atomic_read(&fscache_n_store_radix_deletes),
52098 - atomic_read(&fscache_n_store_pages_over_limit));
52099 + atomic_read_unchecked(&fscache_n_store_ops),
52100 + atomic_read_unchecked(&fscache_n_store_calls),
52101 + atomic_read_unchecked(&fscache_n_store_pages),
52102 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
52103 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
52104
52105 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
52106 - atomic_read(&fscache_n_store_vmscan_not_storing),
52107 - atomic_read(&fscache_n_store_vmscan_gone),
52108 - atomic_read(&fscache_n_store_vmscan_busy),
52109 - atomic_read(&fscache_n_store_vmscan_cancelled),
52110 - atomic_read(&fscache_n_store_vmscan_wait));
52111 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
52112 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
52113 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
52114 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
52115 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
52116
52117 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
52118 - atomic_read(&fscache_n_op_pend),
52119 - atomic_read(&fscache_n_op_run),
52120 - atomic_read(&fscache_n_op_enqueue),
52121 - atomic_read(&fscache_n_op_cancelled),
52122 - atomic_read(&fscache_n_op_rejected));
52123 + atomic_read_unchecked(&fscache_n_op_pend),
52124 + atomic_read_unchecked(&fscache_n_op_run),
52125 + atomic_read_unchecked(&fscache_n_op_enqueue),
52126 + atomic_read_unchecked(&fscache_n_op_cancelled),
52127 + atomic_read_unchecked(&fscache_n_op_rejected));
52128 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
52129 - atomic_read(&fscache_n_op_deferred_release),
52130 - atomic_read(&fscache_n_op_release),
52131 - atomic_read(&fscache_n_op_gc));
52132 + atomic_read_unchecked(&fscache_n_op_deferred_release),
52133 + atomic_read_unchecked(&fscache_n_op_release),
52134 + atomic_read_unchecked(&fscache_n_op_gc));
52135
52136 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
52137 atomic_read(&fscache_n_cop_alloc_object),
52138 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
52139 index e397b67..b0d8709 100644
52140 --- a/fs/fuse/cuse.c
52141 +++ b/fs/fuse/cuse.c
52142 @@ -593,10 +593,12 @@ static int __init cuse_init(void)
52143 INIT_LIST_HEAD(&cuse_conntbl[i]);
52144
52145 /* inherit and extend fuse_dev_operations */
52146 - cuse_channel_fops = fuse_dev_operations;
52147 - cuse_channel_fops.owner = THIS_MODULE;
52148 - cuse_channel_fops.open = cuse_channel_open;
52149 - cuse_channel_fops.release = cuse_channel_release;
52150 + pax_open_kernel();
52151 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
52152 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
52153 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
52154 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
52155 + pax_close_kernel();
52156
52157 cuse_class = class_create(THIS_MODULE, "cuse");
52158 if (IS_ERR(cuse_class))
52159 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
52160 index e83351a..41e3c9c 100644
52161 --- a/fs/fuse/dev.c
52162 +++ b/fs/fuse/dev.c
52163 @@ -1236,7 +1236,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
52164 ret = 0;
52165 pipe_lock(pipe);
52166
52167 - if (!pipe->readers) {
52168 + if (!atomic_read(&pipe->readers)) {
52169 send_sig(SIGPIPE, current, 0);
52170 if (!ret)
52171 ret = -EPIPE;
52172 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
52173 index 315e1f8..91f890c 100644
52174 --- a/fs/fuse/dir.c
52175 +++ b/fs/fuse/dir.c
52176 @@ -1233,7 +1233,7 @@ static char *read_link(struct dentry *dentry)
52177 return link;
52178 }
52179
52180 -static void free_link(char *link)
52181 +static void free_link(const char *link)
52182 {
52183 if (!IS_ERR(link))
52184 free_page((unsigned long) link);
52185 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
52186 index 2b6f569..fcb4d1f 100644
52187 --- a/fs/gfs2/inode.c
52188 +++ b/fs/gfs2/inode.c
52189 @@ -1499,7 +1499,7 @@ out:
52190
52191 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
52192 {
52193 - char *s = nd_get_link(nd);
52194 + const char *s = nd_get_link(nd);
52195 if (!IS_ERR(s))
52196 kfree(s);
52197 }
52198 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
52199 index 78bde32..767e906 100644
52200 --- a/fs/hugetlbfs/inode.c
52201 +++ b/fs/hugetlbfs/inode.c
52202 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52203 struct mm_struct *mm = current->mm;
52204 struct vm_area_struct *vma;
52205 struct hstate *h = hstate_file(file);
52206 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
52207 struct vm_unmapped_area_info info;
52208
52209 if (len & ~huge_page_mask(h))
52210 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
52211 return addr;
52212 }
52213
52214 +#ifdef CONFIG_PAX_RANDMMAP
52215 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
52216 +#endif
52217 +
52218 if (addr) {
52219 addr = ALIGN(addr, huge_page_size(h));
52220 vma = find_vma(mm, addr);
52221 - if (TASK_SIZE - len >= addr &&
52222 - (!vma || addr + len <= vma->vm_start))
52223 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
52224 return addr;
52225 }
52226
52227 info.flags = 0;
52228 info.length = len;
52229 info.low_limit = TASK_UNMAPPED_BASE;
52230 +
52231 +#ifdef CONFIG_PAX_RANDMMAP
52232 + if (mm->pax_flags & MF_PAX_RANDMMAP)
52233 + info.low_limit += mm->delta_mmap;
52234 +#endif
52235 +
52236 info.high_limit = TASK_SIZE;
52237 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
52238 info.align_offset = 0;
52239 @@ -897,7 +907,7 @@ static struct file_system_type hugetlbfs_fs_type = {
52240 .kill_sb = kill_litter_super,
52241 };
52242
52243 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52244 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
52245
52246 static int can_do_hugetlb_shm(void)
52247 {
52248 diff --git a/fs/inode.c b/fs/inode.c
52249 index 14084b7..29af1d9 100644
52250 --- a/fs/inode.c
52251 +++ b/fs/inode.c
52252 @@ -880,8 +880,8 @@ unsigned int get_next_ino(void)
52253
52254 #ifdef CONFIG_SMP
52255 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
52256 - static atomic_t shared_last_ino;
52257 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
52258 + static atomic_unchecked_t shared_last_ino;
52259 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
52260
52261 res = next - LAST_INO_BATCH;
52262 }
52263 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
52264 index 4a6cf28..d3a29d3 100644
52265 --- a/fs/jffs2/erase.c
52266 +++ b/fs/jffs2/erase.c
52267 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
52268 struct jffs2_unknown_node marker = {
52269 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
52270 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52271 - .totlen = cpu_to_je32(c->cleanmarker_size)
52272 + .totlen = cpu_to_je32(c->cleanmarker_size),
52273 + .hdr_crc = cpu_to_je32(0)
52274 };
52275
52276 jffs2_prealloc_raw_node_refs(c, jeb, 1);
52277 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
52278 index a6597d6..41b30ec 100644
52279 --- a/fs/jffs2/wbuf.c
52280 +++ b/fs/jffs2/wbuf.c
52281 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
52282 {
52283 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
52284 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
52285 - .totlen = constant_cpu_to_je32(8)
52286 + .totlen = constant_cpu_to_je32(8),
52287 + .hdr_crc = constant_cpu_to_je32(0)
52288 };
52289
52290 /*
52291 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
52292 index 1a543be..a4e1363 100644
52293 --- a/fs/jfs/super.c
52294 +++ b/fs/jfs/super.c
52295 @@ -225,7 +225,7 @@ static const match_table_t tokens = {
52296 static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52297 int *flag)
52298 {
52299 - void *nls_map = (void *)-1; /* -1: no change; NULL: none */
52300 + const void *nls_map = (const void *)-1; /* -1: no change; NULL: none */
52301 char *p;
52302 struct jfs_sb_info *sbi = JFS_SBI(sb);
52303
52304 @@ -253,7 +253,7 @@ static int parse_options(char *options, struct super_block *sb, s64 *newLVSize,
52305 /* Don't do anything ;-) */
52306 break;
52307 case Opt_iocharset:
52308 - if (nls_map && nls_map != (void *) -1)
52309 + if (nls_map && nls_map != (const void *) -1)
52310 unload_nls(nls_map);
52311 if (!strcmp(args[0].from, "none"))
52312 nls_map = NULL;
52313 @@ -855,7 +855,7 @@ static int __init init_jfs_fs(void)
52314
52315 jfs_inode_cachep =
52316 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
52317 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
52318 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
52319 init_once);
52320 if (jfs_inode_cachep == NULL)
52321 return -ENOMEM;
52322 diff --git a/fs/libfs.c b/fs/libfs.c
52323 index 916da8c..1588998 100644
52324 --- a/fs/libfs.c
52325 +++ b/fs/libfs.c
52326 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52327
52328 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
52329 struct dentry *next;
52330 + char d_name[sizeof(next->d_iname)];
52331 + const unsigned char *name;
52332 +
52333 next = list_entry(p, struct dentry, d_u.d_child);
52334 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
52335 if (!simple_positive(next)) {
52336 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
52337
52338 spin_unlock(&next->d_lock);
52339 spin_unlock(&dentry->d_lock);
52340 - if (filldir(dirent, next->d_name.name,
52341 + name = next->d_name.name;
52342 + if (name == next->d_iname) {
52343 + memcpy(d_name, name, next->d_name.len);
52344 + name = d_name;
52345 + }
52346 + if (filldir(dirent, name,
52347 next->d_name.len, filp->f_pos,
52348 next->d_inode->i_ino,
52349 dt_type(next->d_inode)) < 0)
52350 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
52351 index 52e5120..808936e 100644
52352 --- a/fs/lockd/clntproc.c
52353 +++ b/fs/lockd/clntproc.c
52354 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
52355 /*
52356 * Cookie counter for NLM requests
52357 */
52358 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
52359 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
52360
52361 void nlmclnt_next_cookie(struct nlm_cookie *c)
52362 {
52363 - u32 cookie = atomic_inc_return(&nlm_cookie);
52364 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
52365
52366 memcpy(c->data, &cookie, 4);
52367 c->len=4;
52368 diff --git a/fs/locks.c b/fs/locks.c
52369 index a94e331..060bce3 100644
52370 --- a/fs/locks.c
52371 +++ b/fs/locks.c
52372 @@ -2064,16 +2064,16 @@ void locks_remove_flock(struct file *filp)
52373 return;
52374
52375 if (filp->f_op && filp->f_op->flock) {
52376 - struct file_lock fl = {
52377 + struct file_lock flock = {
52378 .fl_pid = current->tgid,
52379 .fl_file = filp,
52380 .fl_flags = FL_FLOCK,
52381 .fl_type = F_UNLCK,
52382 .fl_end = OFFSET_MAX,
52383 };
52384 - filp->f_op->flock(filp, F_SETLKW, &fl);
52385 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
52386 - fl.fl_ops->fl_release_private(&fl);
52387 + filp->f_op->flock(filp, F_SETLKW, &flock);
52388 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
52389 + flock.fl_ops->fl_release_private(&flock);
52390 }
52391
52392 lock_flocks();
52393 diff --git a/fs/namei.c b/fs/namei.c
52394 index 43a97ee..4e585fd 100644
52395 --- a/fs/namei.c
52396 +++ b/fs/namei.c
52397 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
52398 if (ret != -EACCES)
52399 return ret;
52400
52401 +#ifdef CONFIG_GRKERNSEC
52402 + /* we'll block if we have to log due to a denied capability use */
52403 + if (mask & MAY_NOT_BLOCK)
52404 + return -ECHILD;
52405 +#endif
52406 +
52407 if (S_ISDIR(inode->i_mode)) {
52408 /* DACs are overridable for directories */
52409 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
52410 - return 0;
52411 if (!(mask & MAY_WRITE))
52412 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52413 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52414 + inode_capable(inode, CAP_DAC_READ_SEARCH))
52415 return 0;
52416 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
52417 + return 0;
52418 return -EACCES;
52419 }
52420 /*
52421 + * Searching includes executable on directories, else just read.
52422 + */
52423 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52424 + if (mask == MAY_READ)
52425 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
52426 + inode_capable(inode, CAP_DAC_READ_SEARCH))
52427 + return 0;
52428 +
52429 + /*
52430 * Read/write DACs are always overridable.
52431 * Executable DACs are overridable when there is
52432 * at least one exec bit set.
52433 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
52434 if (inode_capable(inode, CAP_DAC_OVERRIDE))
52435 return 0;
52436
52437 - /*
52438 - * Searching includes executable on directories, else just read.
52439 - */
52440 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
52441 - if (mask == MAY_READ)
52442 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
52443 - return 0;
52444 -
52445 return -EACCES;
52446 }
52447
52448 @@ -826,7 +834,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52449 {
52450 struct dentry *dentry = link->dentry;
52451 int error;
52452 - char *s;
52453 + const char *s;
52454
52455 BUG_ON(nd->flags & LOOKUP_RCU);
52456
52457 @@ -847,6 +855,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
52458 if (error)
52459 goto out_put_nd_path;
52460
52461 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
52462 + dentry->d_inode, dentry, nd->path.mnt)) {
52463 + error = -EACCES;
52464 + goto out_put_nd_path;
52465 + }
52466 +
52467 nd->last_type = LAST_BIND;
52468 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
52469 error = PTR_ERR(*p);
52470 @@ -1596,6 +1610,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
52471 break;
52472 res = walk_component(nd, path, &nd->last,
52473 nd->last_type, LOOKUP_FOLLOW);
52474 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
52475 + res = -EACCES;
52476 put_link(nd, &link, cookie);
52477 } while (res > 0);
52478
52479 @@ -1694,7 +1710,7 @@ EXPORT_SYMBOL(full_name_hash);
52480 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
52481 {
52482 unsigned long a, b, adata, bdata, mask, hash, len;
52483 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52484 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
52485
52486 hash = a = 0;
52487 len = -sizeof(unsigned long);
52488 @@ -1979,6 +1995,8 @@ static int path_lookupat(int dfd, const char *name,
52489 if (err)
52490 break;
52491 err = lookup_last(nd, &path);
52492 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
52493 + err = -EACCES;
52494 put_link(nd, &link, cookie);
52495 }
52496 }
52497 @@ -1986,6 +2004,19 @@ static int path_lookupat(int dfd, const char *name,
52498 if (!err)
52499 err = complete_walk(nd);
52500
52501 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
52502 +#ifdef CONFIG_GRKERNSEC
52503 + if (flags & LOOKUP_RCU) {
52504 + path_put(&nd->path);
52505 + err = -ECHILD;
52506 + } else
52507 +#endif
52508 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52509 + path_put(&nd->path);
52510 + err = -ENOENT;
52511 + }
52512 + }
52513 +
52514 if (!err && nd->flags & LOOKUP_DIRECTORY) {
52515 if (!nd->inode->i_op->lookup) {
52516 path_put(&nd->path);
52517 @@ -2013,8 +2044,17 @@ static int filename_lookup(int dfd, struct filename *name,
52518 retval = path_lookupat(dfd, name->name,
52519 flags | LOOKUP_REVAL, nd);
52520
52521 - if (likely(!retval))
52522 + if (likely(!retval)) {
52523 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
52524 +#ifdef CONFIG_GRKERNSEC
52525 + if (flags & LOOKUP_RCU)
52526 + return -ECHILD;
52527 +#endif
52528 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
52529 + return -ENOENT;
52530 + }
52531 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
52532 + }
52533 return retval;
52534 }
52535
52536 @@ -2392,6 +2432,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
52537 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
52538 return -EPERM;
52539
52540 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
52541 + return -EPERM;
52542 + if (gr_handle_rawio(inode))
52543 + return -EPERM;
52544 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
52545 + return -EACCES;
52546 +
52547 return 0;
52548 }
52549
52550 @@ -2613,7 +2660,7 @@ looked_up:
52551 * cleared otherwise prior to returning.
52552 */
52553 static int lookup_open(struct nameidata *nd, struct path *path,
52554 - struct file *file,
52555 + struct path *link, struct file *file,
52556 const struct open_flags *op,
52557 bool got_write, int *opened)
52558 {
52559 @@ -2648,6 +2695,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52560 /* Negative dentry, just create the file */
52561 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
52562 umode_t mode = op->mode;
52563 +
52564 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
52565 + error = -EACCES;
52566 + goto out_dput;
52567 + }
52568 +
52569 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
52570 + error = -EACCES;
52571 + goto out_dput;
52572 + }
52573 +
52574 if (!IS_POSIXACL(dir->d_inode))
52575 mode &= ~current_umask();
52576 /*
52577 @@ -2669,6 +2727,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
52578 nd->flags & LOOKUP_EXCL);
52579 if (error)
52580 goto out_dput;
52581 + else
52582 + gr_handle_create(dentry, nd->path.mnt);
52583 }
52584 out_no_open:
52585 path->dentry = dentry;
52586 @@ -2683,7 +2743,7 @@ out_dput:
52587 /*
52588 * Handle the last step of open()
52589 */
52590 -static int do_last(struct nameidata *nd, struct path *path,
52591 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
52592 struct file *file, const struct open_flags *op,
52593 int *opened, struct filename *name)
52594 {
52595 @@ -2712,16 +2772,44 @@ static int do_last(struct nameidata *nd, struct path *path,
52596 error = complete_walk(nd);
52597 if (error)
52598 return error;
52599 +#ifdef CONFIG_GRKERNSEC
52600 + if (nd->flags & LOOKUP_RCU) {
52601 + error = -ECHILD;
52602 + goto out;
52603 + }
52604 +#endif
52605 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52606 + error = -ENOENT;
52607 + goto out;
52608 + }
52609 audit_inode(name, nd->path.dentry, 0);
52610 if (open_flag & O_CREAT) {
52611 error = -EISDIR;
52612 goto out;
52613 }
52614 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52615 + error = -EACCES;
52616 + goto out;
52617 + }
52618 goto finish_open;
52619 case LAST_BIND:
52620 error = complete_walk(nd);
52621 if (error)
52622 return error;
52623 +#ifdef CONFIG_GRKERNSEC
52624 + if (nd->flags & LOOKUP_RCU) {
52625 + error = -ECHILD;
52626 + goto out;
52627 + }
52628 +#endif
52629 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
52630 + error = -ENOENT;
52631 + goto out;
52632 + }
52633 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52634 + error = -EACCES;
52635 + goto out;
52636 + }
52637 audit_inode(name, dir, 0);
52638 goto finish_open;
52639 }
52640 @@ -2770,7 +2858,7 @@ retry_lookup:
52641 */
52642 }
52643 mutex_lock(&dir->d_inode->i_mutex);
52644 - error = lookup_open(nd, path, file, op, got_write, opened);
52645 + error = lookup_open(nd, path, link, file, op, got_write, opened);
52646 mutex_unlock(&dir->d_inode->i_mutex);
52647
52648 if (error <= 0) {
52649 @@ -2794,11 +2882,28 @@ retry_lookup:
52650 goto finish_open_created;
52651 }
52652
52653 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
52654 + error = -ENOENT;
52655 + goto exit_dput;
52656 + }
52657 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
52658 + error = -EACCES;
52659 + goto exit_dput;
52660 + }
52661 +
52662 /*
52663 * create/update audit record if it already exists.
52664 */
52665 - if (path->dentry->d_inode)
52666 + if (path->dentry->d_inode) {
52667 + /* only check if O_CREAT is specified, all other checks need to go
52668 + into may_open */
52669 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
52670 + error = -EACCES;
52671 + goto exit_dput;
52672 + }
52673 +
52674 audit_inode(name, path->dentry, 0);
52675 + }
52676
52677 /*
52678 * If atomic_open() acquired write access it is dropped now due to
52679 @@ -2839,6 +2944,11 @@ finish_lookup:
52680 }
52681 }
52682 BUG_ON(inode != path->dentry->d_inode);
52683 + /* if we're resolving a symlink to another symlink */
52684 + if (link && gr_handle_symlink_owner(link, inode)) {
52685 + error = -EACCES;
52686 + goto out;
52687 + }
52688 return 1;
52689 }
52690
52691 @@ -2848,7 +2958,6 @@ finish_lookup:
52692 save_parent.dentry = nd->path.dentry;
52693 save_parent.mnt = mntget(path->mnt);
52694 nd->path.dentry = path->dentry;
52695 -
52696 }
52697 nd->inode = inode;
52698 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
52699 @@ -2857,6 +2966,22 @@ finish_lookup:
52700 path_put(&save_parent);
52701 return error;
52702 }
52703 +
52704 +#ifdef CONFIG_GRKERNSEC
52705 + if (nd->flags & LOOKUP_RCU) {
52706 + error = -ECHILD;
52707 + goto out;
52708 + }
52709 +#endif
52710 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
52711 + error = -ENOENT;
52712 + goto out;
52713 + }
52714 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
52715 + error = -EACCES;
52716 + goto out;
52717 + }
52718 +
52719 error = -EISDIR;
52720 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
52721 goto out;
52722 @@ -2955,7 +3080,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
52723 if (unlikely(error))
52724 goto out;
52725
52726 - error = do_last(nd, &path, file, op, &opened, pathname);
52727 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
52728 while (unlikely(error > 0)) { /* trailing symlink */
52729 struct path link = path;
52730 void *cookie;
52731 @@ -2973,7 +3098,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
52732 error = follow_link(&link, nd, &cookie);
52733 if (unlikely(error))
52734 break;
52735 - error = do_last(nd, &path, file, op, &opened, pathname);
52736 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
52737 put_link(nd, &link, cookie);
52738 }
52739 out:
52740 @@ -3073,8 +3198,12 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
52741 goto unlock;
52742
52743 error = -EEXIST;
52744 - if (dentry->d_inode)
52745 + if (dentry->d_inode) {
52746 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
52747 + error = -ENOENT;
52748 + }
52749 goto fail;
52750 + }
52751 /*
52752 * Special case - lookup gave negative, but... we had foo/bar/
52753 * From the vfs_mknod() POV we just have a negative dentry -
52754 @@ -3126,6 +3255,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
52755 }
52756 EXPORT_SYMBOL(user_path_create);
52757
52758 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
52759 +{
52760 + struct filename *tmp = getname(pathname);
52761 + struct dentry *res;
52762 + if (IS_ERR(tmp))
52763 + return ERR_CAST(tmp);
52764 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
52765 + if (IS_ERR(res))
52766 + putname(tmp);
52767 + else
52768 + *to = tmp;
52769 + return res;
52770 +}
52771 +
52772 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
52773 {
52774 int error = may_create(dir, dentry);
52775 @@ -3188,6 +3331,17 @@ retry:
52776
52777 if (!IS_POSIXACL(path.dentry->d_inode))
52778 mode &= ~current_umask();
52779 +
52780 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
52781 + error = -EPERM;
52782 + goto out;
52783 + }
52784 +
52785 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
52786 + error = -EACCES;
52787 + goto out;
52788 + }
52789 +
52790 error = security_path_mknod(&path, dentry, mode, dev);
52791 if (error)
52792 goto out;
52793 @@ -3204,6 +3358,8 @@ retry:
52794 break;
52795 }
52796 out:
52797 + if (!error)
52798 + gr_handle_create(dentry, path.mnt);
52799 done_path_create(&path, dentry);
52800 if (retry_estale(error, lookup_flags)) {
52801 lookup_flags |= LOOKUP_REVAL;
52802 @@ -3256,9 +3412,16 @@ retry:
52803
52804 if (!IS_POSIXACL(path.dentry->d_inode))
52805 mode &= ~current_umask();
52806 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
52807 + error = -EACCES;
52808 + goto out;
52809 + }
52810 error = security_path_mkdir(&path, dentry, mode);
52811 if (!error)
52812 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
52813 + if (!error)
52814 + gr_handle_create(dentry, path.mnt);
52815 +out:
52816 done_path_create(&path, dentry);
52817 if (retry_estale(error, lookup_flags)) {
52818 lookup_flags |= LOOKUP_REVAL;
52819 @@ -3339,6 +3502,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
52820 struct filename *name;
52821 struct dentry *dentry;
52822 struct nameidata nd;
52823 + ino_t saved_ino = 0;
52824 + dev_t saved_dev = 0;
52825 unsigned int lookup_flags = 0;
52826 retry:
52827 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
52828 @@ -3371,10 +3536,21 @@ retry:
52829 error = -ENOENT;
52830 goto exit3;
52831 }
52832 +
52833 + saved_ino = dentry->d_inode->i_ino;
52834 + saved_dev = gr_get_dev_from_dentry(dentry);
52835 +
52836 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
52837 + error = -EACCES;
52838 + goto exit3;
52839 + }
52840 +
52841 error = security_path_rmdir(&nd.path, dentry);
52842 if (error)
52843 goto exit3;
52844 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
52845 + if (!error && (saved_dev || saved_ino))
52846 + gr_handle_delete(saved_ino, saved_dev);
52847 exit3:
52848 dput(dentry);
52849 exit2:
52850 @@ -3440,6 +3616,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
52851 struct dentry *dentry;
52852 struct nameidata nd;
52853 struct inode *inode = NULL;
52854 + ino_t saved_ino = 0;
52855 + dev_t saved_dev = 0;
52856 unsigned int lookup_flags = 0;
52857 retry:
52858 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
52859 @@ -3466,10 +3644,22 @@ retry:
52860 if (!inode)
52861 goto slashes;
52862 ihold(inode);
52863 +
52864 + if (inode->i_nlink <= 1) {
52865 + saved_ino = inode->i_ino;
52866 + saved_dev = gr_get_dev_from_dentry(dentry);
52867 + }
52868 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
52869 + error = -EACCES;
52870 + goto exit2;
52871 + }
52872 +
52873 error = security_path_unlink(&nd.path, dentry);
52874 if (error)
52875 goto exit2;
52876 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
52877 + if (!error && (saved_ino || saved_dev))
52878 + gr_handle_delete(saved_ino, saved_dev);
52879 exit2:
52880 dput(dentry);
52881 }
52882 @@ -3547,9 +3737,17 @@ retry:
52883 if (IS_ERR(dentry))
52884 goto out_putname;
52885
52886 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
52887 + error = -EACCES;
52888 + goto out;
52889 + }
52890 +
52891 error = security_path_symlink(&path, dentry, from->name);
52892 if (!error)
52893 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
52894 + if (!error)
52895 + gr_handle_create(dentry, path.mnt);
52896 +out:
52897 done_path_create(&path, dentry);
52898 if (retry_estale(error, lookup_flags)) {
52899 lookup_flags |= LOOKUP_REVAL;
52900 @@ -3623,6 +3821,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
52901 {
52902 struct dentry *new_dentry;
52903 struct path old_path, new_path;
52904 + struct filename *to = NULL;
52905 int how = 0;
52906 int error;
52907
52908 @@ -3646,7 +3845,7 @@ retry:
52909 if (error)
52910 return error;
52911
52912 - new_dentry = user_path_create(newdfd, newname, &new_path,
52913 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
52914 (how & LOOKUP_REVAL));
52915 error = PTR_ERR(new_dentry);
52916 if (IS_ERR(new_dentry))
52917 @@ -3658,11 +3857,28 @@ retry:
52918 error = may_linkat(&old_path);
52919 if (unlikely(error))
52920 goto out_dput;
52921 +
52922 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
52923 + old_path.dentry->d_inode,
52924 + old_path.dentry->d_inode->i_mode, to)) {
52925 + error = -EACCES;
52926 + goto out_dput;
52927 + }
52928 +
52929 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
52930 + old_path.dentry, old_path.mnt, to)) {
52931 + error = -EACCES;
52932 + goto out_dput;
52933 + }
52934 +
52935 error = security_path_link(old_path.dentry, &new_path, new_dentry);
52936 if (error)
52937 goto out_dput;
52938 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
52939 + if (!error)
52940 + gr_handle_create(new_dentry, new_path.mnt);
52941 out_dput:
52942 + putname(to);
52943 done_path_create(&new_path, new_dentry);
52944 if (retry_estale(error, how)) {
52945 how |= LOOKUP_REVAL;
52946 @@ -3908,12 +4124,21 @@ retry:
52947 if (new_dentry == trap)
52948 goto exit5;
52949
52950 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
52951 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
52952 + to);
52953 + if (error)
52954 + goto exit5;
52955 +
52956 error = security_path_rename(&oldnd.path, old_dentry,
52957 &newnd.path, new_dentry);
52958 if (error)
52959 goto exit5;
52960 error = vfs_rename(old_dir->d_inode, old_dentry,
52961 new_dir->d_inode, new_dentry);
52962 + if (!error)
52963 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
52964 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
52965 exit5:
52966 dput(new_dentry);
52967 exit4:
52968 @@ -3945,6 +4170,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
52969
52970 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
52971 {
52972 + char tmpbuf[64];
52973 + const char *newlink;
52974 int len;
52975
52976 len = PTR_ERR(link);
52977 @@ -3954,7 +4181,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
52978 len = strlen(link);
52979 if (len > (unsigned) buflen)
52980 len = buflen;
52981 - if (copy_to_user(buffer, link, len))
52982 +
52983 + if (len < sizeof(tmpbuf)) {
52984 + memcpy(tmpbuf, link, len);
52985 + newlink = tmpbuf;
52986 + } else
52987 + newlink = link;
52988 +
52989 + if (copy_to_user(buffer, newlink, len))
52990 len = -EFAULT;
52991 out:
52992 return len;
52993 diff --git a/fs/namespace.c b/fs/namespace.c
52994 index a51054f..f9b53e5 100644
52995 --- a/fs/namespace.c
52996 +++ b/fs/namespace.c
52997 @@ -1215,6 +1215,9 @@ static int do_umount(struct mount *mnt, int flags)
52998 if (!(sb->s_flags & MS_RDONLY))
52999 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
53000 up_write(&sb->s_umount);
53001 +
53002 + gr_log_remount(mnt->mnt_devname, retval);
53003 +
53004 return retval;
53005 }
53006
53007 @@ -1234,6 +1237,9 @@ static int do_umount(struct mount *mnt, int flags)
53008 br_write_unlock(&vfsmount_lock);
53009 up_write(&namespace_sem);
53010 release_mounts(&umount_list);
53011 +
53012 + gr_log_unmount(mnt->mnt_devname, retval);
53013 +
53014 return retval;
53015 }
53016
53017 @@ -2287,6 +2293,16 @@ long do_mount(const char *dev_name, const char *dir_name,
53018 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
53019 MS_STRICTATIME);
53020
53021 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
53022 + retval = -EPERM;
53023 + goto dput_out;
53024 + }
53025 +
53026 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
53027 + retval = -EPERM;
53028 + goto dput_out;
53029 + }
53030 +
53031 if (flags & MS_REMOUNT)
53032 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
53033 data_page);
53034 @@ -2301,6 +2317,9 @@ long do_mount(const char *dev_name, const char *dir_name,
53035 dev_name, data_page);
53036 dput_out:
53037 path_put(&path);
53038 +
53039 + gr_log_mount(dev_name, dir_name, retval);
53040 +
53041 return retval;
53042 }
53043
53044 @@ -2587,6 +2606,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
53045 if (error)
53046 goto out2;
53047
53048 + if (gr_handle_chroot_pivot()) {
53049 + error = -EPERM;
53050 + goto out2;
53051 + }
53052 +
53053 get_fs_root(current->fs, &root);
53054 error = lock_mount(&old);
53055 if (error)
53056 @@ -2790,7 +2814,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
53057 !nsown_capable(CAP_SYS_ADMIN))
53058 return -EPERM;
53059
53060 - if (fs->users != 1)
53061 + if (atomic_read(&fs->users) != 1)
53062 return -EINVAL;
53063
53064 get_mnt_ns(mnt_ns);
53065 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
53066 index 59461c9..b17c57e 100644
53067 --- a/fs/nfs/callback_xdr.c
53068 +++ b/fs/nfs/callback_xdr.c
53069 @@ -51,7 +51,7 @@ struct callback_op {
53070 callback_decode_arg_t decode_args;
53071 callback_encode_res_t encode_res;
53072 long res_maxsize;
53073 -};
53074 +} __do_const;
53075
53076 static struct callback_op callback_ops[];
53077
53078 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
53079 index ebeb94c..ff35337 100644
53080 --- a/fs/nfs/inode.c
53081 +++ b/fs/nfs/inode.c
53082 @@ -1042,16 +1042,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
53083 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
53084 }
53085
53086 -static atomic_long_t nfs_attr_generation_counter;
53087 +static atomic_long_unchecked_t nfs_attr_generation_counter;
53088
53089 static unsigned long nfs_read_attr_generation_counter(void)
53090 {
53091 - return atomic_long_read(&nfs_attr_generation_counter);
53092 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
53093 }
53094
53095 unsigned long nfs_inc_attr_generation_counter(void)
53096 {
53097 - return atomic_long_inc_return(&nfs_attr_generation_counter);
53098 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
53099 }
53100
53101 void nfs_fattr_init(struct nfs_fattr *fattr)
53102 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
53103 index 9d1c5db..1e13db8 100644
53104 --- a/fs/nfsd/nfs4proc.c
53105 +++ b/fs/nfsd/nfs4proc.c
53106 @@ -1097,7 +1097,7 @@ struct nfsd4_operation {
53107 nfsd4op_rsize op_rsize_bop;
53108 stateid_getter op_get_currentstateid;
53109 stateid_setter op_set_currentstateid;
53110 -};
53111 +} __do_const;
53112
53113 static struct nfsd4_operation nfsd4_ops[];
53114
53115 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
53116 index 0dc1158..ccf0338 100644
53117 --- a/fs/nfsd/nfs4xdr.c
53118 +++ b/fs/nfsd/nfs4xdr.c
53119 @@ -1456,7 +1456,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
53120
53121 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
53122
53123 -static nfsd4_dec nfsd4_dec_ops[] = {
53124 +static const nfsd4_dec nfsd4_dec_ops[] = {
53125 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53126 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53127 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53128 @@ -1496,7 +1496,7 @@ static nfsd4_dec nfsd4_dec_ops[] = {
53129 [OP_RELEASE_LOCKOWNER] = (nfsd4_dec)nfsd4_decode_release_lockowner,
53130 };
53131
53132 -static nfsd4_dec nfsd41_dec_ops[] = {
53133 +static const nfsd4_dec nfsd41_dec_ops[] = {
53134 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
53135 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
53136 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
53137 @@ -1558,7 +1558,7 @@ static nfsd4_dec nfsd41_dec_ops[] = {
53138 };
53139
53140 struct nfsd4_minorversion_ops {
53141 - nfsd4_dec *decoders;
53142 + const nfsd4_dec *decoders;
53143 int nops;
53144 };
53145
53146 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
53147 index d586117..143d568 100644
53148 --- a/fs/nfsd/vfs.c
53149 +++ b/fs/nfsd/vfs.c
53150 @@ -939,7 +939,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53151 } else {
53152 oldfs = get_fs();
53153 set_fs(KERNEL_DS);
53154 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
53155 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
53156 set_fs(oldfs);
53157 }
53158
53159 @@ -1025,7 +1025,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
53160
53161 /* Write the data. */
53162 oldfs = get_fs(); set_fs(KERNEL_DS);
53163 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
53164 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
53165 set_fs(oldfs);
53166 if (host_err < 0)
53167 goto out_nfserr;
53168 @@ -1571,7 +1571,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
53169 */
53170
53171 oldfs = get_fs(); set_fs(KERNEL_DS);
53172 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
53173 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
53174 set_fs(oldfs);
53175
53176 if (host_err < 0)
53177 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
53178 index fea6bd5..8ee9d81 100644
53179 --- a/fs/nls/nls_base.c
53180 +++ b/fs/nls/nls_base.c
53181 @@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
53182
53183 int register_nls(struct nls_table * nls)
53184 {
53185 - struct nls_table ** tmp = &tables;
53186 + struct nls_table *tmp = tables;
53187
53188 if (nls->next)
53189 return -EBUSY;
53190
53191 spin_lock(&nls_lock);
53192 - while (*tmp) {
53193 - if (nls == *tmp) {
53194 + while (tmp) {
53195 + if (nls == tmp) {
53196 spin_unlock(&nls_lock);
53197 return -EBUSY;
53198 }
53199 - tmp = &(*tmp)->next;
53200 + tmp = tmp->next;
53201 }
53202 - nls->next = tables;
53203 + pax_open_kernel();
53204 + *(struct nls_table **)&nls->next = tables;
53205 + pax_close_kernel();
53206 tables = nls;
53207 spin_unlock(&nls_lock);
53208 return 0;
53209 @@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
53210
53211 int unregister_nls(struct nls_table * nls)
53212 {
53213 - struct nls_table ** tmp = &tables;
53214 + struct nls_table * const * tmp = &tables;
53215
53216 spin_lock(&nls_lock);
53217 while (*tmp) {
53218 if (nls == *tmp) {
53219 - *tmp = nls->next;
53220 + pax_open_kernel();
53221 + *(struct nls_table **)tmp = nls->next;
53222 + pax_close_kernel();
53223 spin_unlock(&nls_lock);
53224 return 0;
53225 }
53226 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
53227 index 7424929..35f6be5 100644
53228 --- a/fs/nls/nls_euc-jp.c
53229 +++ b/fs/nls/nls_euc-jp.c
53230 @@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
53231 p_nls = load_nls("cp932");
53232
53233 if (p_nls) {
53234 - table.charset2upper = p_nls->charset2upper;
53235 - table.charset2lower = p_nls->charset2lower;
53236 + pax_open_kernel();
53237 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53238 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53239 + pax_close_kernel();
53240 return register_nls(&table);
53241 }
53242
53243 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
53244 index e7bc1d7..06bd4bb 100644
53245 --- a/fs/nls/nls_koi8-ru.c
53246 +++ b/fs/nls/nls_koi8-ru.c
53247 @@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
53248 p_nls = load_nls("koi8-u");
53249
53250 if (p_nls) {
53251 - table.charset2upper = p_nls->charset2upper;
53252 - table.charset2lower = p_nls->charset2lower;
53253 + pax_open_kernel();
53254 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
53255 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
53256 + pax_close_kernel();
53257 return register_nls(&table);
53258 }
53259
53260 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
53261 index 9ff4a5e..deb1f0f 100644
53262 --- a/fs/notify/fanotify/fanotify_user.c
53263 +++ b/fs/notify/fanotify/fanotify_user.c
53264 @@ -251,8 +251,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
53265
53266 fd = fanotify_event_metadata.fd;
53267 ret = -EFAULT;
53268 - if (copy_to_user(buf, &fanotify_event_metadata,
53269 - fanotify_event_metadata.event_len))
53270 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
53271 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
53272 goto out_close_fd;
53273
53274 ret = prepare_for_access_response(group, event, fd);
53275 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
53276 index 7b51b05..5ea5ef6 100644
53277 --- a/fs/notify/notification.c
53278 +++ b/fs/notify/notification.c
53279 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
53280 * get set to 0 so it will never get 'freed'
53281 */
53282 static struct fsnotify_event *q_overflow_event;
53283 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53284 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53285
53286 /**
53287 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
53288 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
53289 */
53290 u32 fsnotify_get_cookie(void)
53291 {
53292 - return atomic_inc_return(&fsnotify_sync_cookie);
53293 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
53294 }
53295 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
53296
53297 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
53298 index 99e3610..02c1068 100644
53299 --- a/fs/ntfs/dir.c
53300 +++ b/fs/ntfs/dir.c
53301 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
53302 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
53303 ~(s64)(ndir->itype.index.block_size - 1)));
53304 /* Bounds checks. */
53305 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53306 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
53307 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
53308 "inode 0x%lx or driver bug.", vdir->i_ino);
53309 goto err_out;
53310 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
53311 index 5b2d4f0..c6de396 100644
53312 --- a/fs/ntfs/file.c
53313 +++ b/fs/ntfs/file.c
53314 @@ -2242,6 +2242,6 @@ const struct inode_operations ntfs_file_inode_ops = {
53315 #endif /* NTFS_RW */
53316 };
53317
53318 -const struct file_operations ntfs_empty_file_ops = {};
53319 +const struct file_operations ntfs_empty_file_ops __read_only;
53320
53321 -const struct inode_operations ntfs_empty_inode_ops = {};
53322 +const struct inode_operations ntfs_empty_inode_ops __read_only;
53323 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
53324 index a9f78c7..ed8a381 100644
53325 --- a/fs/ocfs2/localalloc.c
53326 +++ b/fs/ocfs2/localalloc.c
53327 @@ -1279,7 +1279,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
53328 goto bail;
53329 }
53330
53331 - atomic_inc(&osb->alloc_stats.moves);
53332 + atomic_inc_unchecked(&osb->alloc_stats.moves);
53333
53334 bail:
53335 if (handle)
53336 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
53337 index d355e6e..578d905 100644
53338 --- a/fs/ocfs2/ocfs2.h
53339 +++ b/fs/ocfs2/ocfs2.h
53340 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
53341
53342 struct ocfs2_alloc_stats
53343 {
53344 - atomic_t moves;
53345 - atomic_t local_data;
53346 - atomic_t bitmap_data;
53347 - atomic_t bg_allocs;
53348 - atomic_t bg_extends;
53349 + atomic_unchecked_t moves;
53350 + atomic_unchecked_t local_data;
53351 + atomic_unchecked_t bitmap_data;
53352 + atomic_unchecked_t bg_allocs;
53353 + atomic_unchecked_t bg_extends;
53354 };
53355
53356 enum ocfs2_local_alloc_state
53357 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
53358 index b7e74b5..19c6536 100644
53359 --- a/fs/ocfs2/suballoc.c
53360 +++ b/fs/ocfs2/suballoc.c
53361 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
53362 mlog_errno(status);
53363 goto bail;
53364 }
53365 - atomic_inc(&osb->alloc_stats.bg_extends);
53366 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
53367
53368 /* You should never ask for this much metadata */
53369 BUG_ON(bits_wanted >
53370 @@ -2007,7 +2007,7 @@ int ocfs2_claim_metadata(handle_t *handle,
53371 mlog_errno(status);
53372 goto bail;
53373 }
53374 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53375 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53376
53377 *suballoc_loc = res.sr_bg_blkno;
53378 *suballoc_bit_start = res.sr_bit_offset;
53379 @@ -2171,7 +2171,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
53380 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
53381 res->sr_bits);
53382
53383 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53384 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53385
53386 BUG_ON(res->sr_bits != 1);
53387
53388 @@ -2213,7 +2213,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
53389 mlog_errno(status);
53390 goto bail;
53391 }
53392 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53393 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
53394
53395 BUG_ON(res.sr_bits != 1);
53396
53397 @@ -2317,7 +2317,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53398 cluster_start,
53399 num_clusters);
53400 if (!status)
53401 - atomic_inc(&osb->alloc_stats.local_data);
53402 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
53403 } else {
53404 if (min_clusters > (osb->bitmap_cpg - 1)) {
53405 /* The only paths asking for contiguousness
53406 @@ -2343,7 +2343,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
53407 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
53408 res.sr_bg_blkno,
53409 res.sr_bit_offset);
53410 - atomic_inc(&osb->alloc_stats.bitmap_data);
53411 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
53412 *num_clusters = res.sr_bits;
53413 }
53414 }
53415 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
53416 index 0e91ec2..f4b3fc6 100644
53417 --- a/fs/ocfs2/super.c
53418 +++ b/fs/ocfs2/super.c
53419 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
53420 "%10s => GlobalAllocs: %d LocalAllocs: %d "
53421 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
53422 "Stats",
53423 - atomic_read(&osb->alloc_stats.bitmap_data),
53424 - atomic_read(&osb->alloc_stats.local_data),
53425 - atomic_read(&osb->alloc_stats.bg_allocs),
53426 - atomic_read(&osb->alloc_stats.moves),
53427 - atomic_read(&osb->alloc_stats.bg_extends));
53428 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
53429 + atomic_read_unchecked(&osb->alloc_stats.local_data),
53430 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
53431 + atomic_read_unchecked(&osb->alloc_stats.moves),
53432 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
53433
53434 out += snprintf(buf + out, len - out,
53435 "%10s => State: %u Descriptor: %llu Size: %u bits "
53436 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
53437 spin_lock_init(&osb->osb_xattr_lock);
53438 ocfs2_init_steal_slots(osb);
53439
53440 - atomic_set(&osb->alloc_stats.moves, 0);
53441 - atomic_set(&osb->alloc_stats.local_data, 0);
53442 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
53443 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
53444 - atomic_set(&osb->alloc_stats.bg_extends, 0);
53445 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
53446 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
53447 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
53448 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
53449 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
53450
53451 /* Copy the blockcheck stats from the superblock probe */
53452 osb->osb_ecc_stats = *stats;
53453 diff --git a/fs/open.c b/fs/open.c
53454 index 9b33c0c..2ffcca2 100644
53455 --- a/fs/open.c
53456 +++ b/fs/open.c
53457 @@ -31,6 +31,8 @@
53458 #include <linux/ima.h>
53459 #include <linux/dnotify.h>
53460
53461 +#define CREATE_TRACE_POINTS
53462 +#include <trace/events/fs.h>
53463 #include "internal.h"
53464
53465 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
53466 @@ -101,6 +103,8 @@ long vfs_truncate(struct path *path, loff_t length)
53467 error = locks_verify_truncate(inode, NULL, length);
53468 if (!error)
53469 error = security_path_truncate(path);
53470 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
53471 + error = -EACCES;
53472 if (!error)
53473 error = do_truncate(path->dentry, length, 0, NULL);
53474
53475 @@ -178,6 +182,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
53476 error = locks_verify_truncate(inode, f.file, length);
53477 if (!error)
53478 error = security_path_truncate(&f.file->f_path);
53479 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
53480 + error = -EACCES;
53481 if (!error)
53482 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
53483 sb_end_write(inode->i_sb);
53484 @@ -373,6 +379,9 @@ retry:
53485 if (__mnt_is_readonly(path.mnt))
53486 res = -EROFS;
53487
53488 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
53489 + res = -EACCES;
53490 +
53491 out_path_release:
53492 path_put(&path);
53493 if (retry_estale(res, lookup_flags)) {
53494 @@ -404,6 +413,8 @@ retry:
53495 if (error)
53496 goto dput_and_out;
53497
53498 + gr_log_chdir(path.dentry, path.mnt);
53499 +
53500 set_fs_pwd(current->fs, &path);
53501
53502 dput_and_out:
53503 @@ -433,6 +444,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
53504 goto out_putf;
53505
53506 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
53507 +
53508 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
53509 + error = -EPERM;
53510 +
53511 + if (!error)
53512 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
53513 +
53514 if (!error)
53515 set_fs_pwd(current->fs, &f.file->f_path);
53516 out_putf:
53517 @@ -462,7 +480,13 @@ retry:
53518 if (error)
53519 goto dput_and_out;
53520
53521 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
53522 + goto dput_and_out;
53523 +
53524 set_fs_root(current->fs, &path);
53525 +
53526 + gr_handle_chroot_chdir(&path);
53527 +
53528 error = 0;
53529 dput_and_out:
53530 path_put(&path);
53531 @@ -484,6 +508,16 @@ static int chmod_common(struct path *path, umode_t mode)
53532 if (error)
53533 return error;
53534 mutex_lock(&inode->i_mutex);
53535 +
53536 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
53537 + error = -EACCES;
53538 + goto out_unlock;
53539 + }
53540 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
53541 + error = -EACCES;
53542 + goto out_unlock;
53543 + }
53544 +
53545 error = security_path_chmod(path, mode);
53546 if (error)
53547 goto out_unlock;
53548 @@ -544,6 +578,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
53549 uid = make_kuid(current_user_ns(), user);
53550 gid = make_kgid(current_user_ns(), group);
53551
53552 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
53553 + return -EACCES;
53554 +
53555 newattrs.ia_valid = ATTR_CTIME;
53556 if (user != (uid_t) -1) {
53557 if (!uid_valid(uid))
53558 @@ -960,6 +997,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
53559 } else {
53560 fsnotify_open(f);
53561 fd_install(fd, f);
53562 + trace_do_sys_open(tmp->name, flags, mode);
53563 }
53564 }
53565 putname(tmp);
53566 diff --git a/fs/pipe.c b/fs/pipe.c
53567 index bd3479d..fb92c4d 100644
53568 --- a/fs/pipe.c
53569 +++ b/fs/pipe.c
53570 @@ -438,9 +438,9 @@ redo:
53571 }
53572 if (bufs) /* More to do? */
53573 continue;
53574 - if (!pipe->writers)
53575 + if (!atomic_read(&pipe->writers))
53576 break;
53577 - if (!pipe->waiting_writers) {
53578 + if (!atomic_read(&pipe->waiting_writers)) {
53579 /* syscall merging: Usually we must not sleep
53580 * if O_NONBLOCK is set, or if we got some data.
53581 * But if a writer sleeps in kernel space, then
53582 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
53583 mutex_lock(&inode->i_mutex);
53584 pipe = inode->i_pipe;
53585
53586 - if (!pipe->readers) {
53587 + if (!atomic_read(&pipe->readers)) {
53588 send_sig(SIGPIPE, current, 0);
53589 ret = -EPIPE;
53590 goto out;
53591 @@ -553,7 +553,7 @@ redo1:
53592 for (;;) {
53593 int bufs;
53594
53595 - if (!pipe->readers) {
53596 + if (!atomic_read(&pipe->readers)) {
53597 send_sig(SIGPIPE, current, 0);
53598 if (!ret)
53599 ret = -EPIPE;
53600 @@ -644,9 +644,9 @@ redo2:
53601 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
53602 do_wakeup = 0;
53603 }
53604 - pipe->waiting_writers++;
53605 + atomic_inc(&pipe->waiting_writers);
53606 pipe_wait(pipe);
53607 - pipe->waiting_writers--;
53608 + atomic_dec(&pipe->waiting_writers);
53609 }
53610 out:
53611 mutex_unlock(&inode->i_mutex);
53612 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53613 mask = 0;
53614 if (filp->f_mode & FMODE_READ) {
53615 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
53616 - if (!pipe->writers && filp->f_version != pipe->w_counter)
53617 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
53618 mask |= POLLHUP;
53619 }
53620
53621 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
53622 * Most Unices do not set POLLERR for FIFOs but on Linux they
53623 * behave exactly like pipes for poll().
53624 */
53625 - if (!pipe->readers)
53626 + if (!atomic_read(&pipe->readers))
53627 mask |= POLLERR;
53628 }
53629
53630 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
53631
53632 mutex_lock(&inode->i_mutex);
53633 pipe = inode->i_pipe;
53634 - pipe->readers -= decr;
53635 - pipe->writers -= decw;
53636 + atomic_sub(decr, &pipe->readers);
53637 + atomic_sub(decw, &pipe->writers);
53638
53639 - if (!pipe->readers && !pipe->writers) {
53640 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
53641 free_pipe_info(inode);
53642 } else {
53643 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
53644 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
53645
53646 if (inode->i_pipe) {
53647 ret = 0;
53648 - inode->i_pipe->readers++;
53649 + atomic_inc(&inode->i_pipe->readers);
53650 }
53651
53652 mutex_unlock(&inode->i_mutex);
53653 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
53654
53655 if (inode->i_pipe) {
53656 ret = 0;
53657 - inode->i_pipe->writers++;
53658 + atomic_inc(&inode->i_pipe->writers);
53659 }
53660
53661 mutex_unlock(&inode->i_mutex);
53662 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
53663 if (inode->i_pipe) {
53664 ret = 0;
53665 if (filp->f_mode & FMODE_READ)
53666 - inode->i_pipe->readers++;
53667 + atomic_inc(&inode->i_pipe->readers);
53668 if (filp->f_mode & FMODE_WRITE)
53669 - inode->i_pipe->writers++;
53670 + atomic_inc(&inode->i_pipe->writers);
53671 }
53672
53673 mutex_unlock(&inode->i_mutex);
53674 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
53675 inode->i_pipe = NULL;
53676 }
53677
53678 -static struct vfsmount *pipe_mnt __read_mostly;
53679 +struct vfsmount *pipe_mnt __read_mostly;
53680
53681 /*
53682 * pipefs_dname() is called from d_path().
53683 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
53684 goto fail_iput;
53685 inode->i_pipe = pipe;
53686
53687 - pipe->readers = pipe->writers = 1;
53688 + atomic_set(&pipe->readers, 1);
53689 + atomic_set(&pipe->writers, 1);
53690 inode->i_fop = &rdwr_pipefifo_fops;
53691
53692 /*
53693 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
53694 index 15af622..0e9f4467 100644
53695 --- a/fs/proc/Kconfig
53696 +++ b/fs/proc/Kconfig
53697 @@ -30,12 +30,12 @@ config PROC_FS
53698
53699 config PROC_KCORE
53700 bool "/proc/kcore support" if !ARM
53701 - depends on PROC_FS && MMU
53702 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
53703
53704 config PROC_VMCORE
53705 bool "/proc/vmcore support"
53706 - depends on PROC_FS && CRASH_DUMP
53707 - default y
53708 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
53709 + default n
53710 help
53711 Exports the dump image of crashed kernel in ELF format.
53712
53713 @@ -59,8 +59,8 @@ config PROC_SYSCTL
53714 limited in memory.
53715
53716 config PROC_PAGE_MONITOR
53717 - default y
53718 - depends on PROC_FS && MMU
53719 + default n
53720 + depends on PROC_FS && MMU && !GRKERNSEC
53721 bool "Enable /proc page monitoring" if EXPERT
53722 help
53723 Various /proc files exist to monitor process memory utilization:
53724 diff --git a/fs/proc/array.c b/fs/proc/array.c
53725 index 6a91e6f..e54dbc14 100644
53726 --- a/fs/proc/array.c
53727 +++ b/fs/proc/array.c
53728 @@ -60,6 +60,7 @@
53729 #include <linux/tty.h>
53730 #include <linux/string.h>
53731 #include <linux/mman.h>
53732 +#include <linux/grsecurity.h>
53733 #include <linux/proc_fs.h>
53734 #include <linux/ioport.h>
53735 #include <linux/uaccess.h>
53736 @@ -362,6 +363,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
53737 seq_putc(m, '\n');
53738 }
53739
53740 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53741 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
53742 +{
53743 + if (p->mm)
53744 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
53745 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
53746 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
53747 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
53748 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
53749 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
53750 + else
53751 + seq_printf(m, "PaX:\t-----\n");
53752 +}
53753 +#endif
53754 +
53755 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53756 struct pid *pid, struct task_struct *task)
53757 {
53758 @@ -380,9 +396,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
53759 task_cpus_allowed(m, task);
53760 cpuset_task_status_allowed(m, task);
53761 task_context_switch_counts(m, task);
53762 +
53763 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
53764 + task_pax(m, task);
53765 +#endif
53766 +
53767 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
53768 + task_grsec_rbac(m, task);
53769 +#endif
53770 +
53771 return 0;
53772 }
53773
53774 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53775 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53776 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
53777 + _mm->pax_flags & MF_PAX_SEGMEXEC))
53778 +#endif
53779 +
53780 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53781 struct pid *pid, struct task_struct *task, int whole)
53782 {
53783 @@ -404,6 +435,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53784 char tcomm[sizeof(task->comm)];
53785 unsigned long flags;
53786
53787 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53788 + if (current->exec_id != m->exec_id) {
53789 + gr_log_badprocpid("stat");
53790 + return 0;
53791 + }
53792 +#endif
53793 +
53794 state = *get_task_state(task);
53795 vsize = eip = esp = 0;
53796 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
53797 @@ -475,6 +513,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53798 gtime = task->gtime;
53799 }
53800
53801 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53802 + if (PAX_RAND_FLAGS(mm)) {
53803 + eip = 0;
53804 + esp = 0;
53805 + wchan = 0;
53806 + }
53807 +#endif
53808 +#ifdef CONFIG_GRKERNSEC_HIDESYM
53809 + wchan = 0;
53810 + eip =0;
53811 + esp =0;
53812 +#endif
53813 +
53814 /* scale priority and nice values from timeslices to -20..20 */
53815 /* to make it look like a "normal" Unix priority/nice value */
53816 priority = task_prio(task);
53817 @@ -511,9 +562,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53818 seq_put_decimal_ull(m, ' ', vsize);
53819 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
53820 seq_put_decimal_ull(m, ' ', rsslim);
53821 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53822 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
53823 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
53824 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
53825 +#else
53826 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
53827 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
53828 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
53829 +#endif
53830 seq_put_decimal_ull(m, ' ', esp);
53831 seq_put_decimal_ull(m, ' ', eip);
53832 /* The signal information here is obsolete.
53833 @@ -535,7 +592,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
53834 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
53835 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
53836
53837 - if (mm && permitted) {
53838 + if (mm && permitted
53839 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53840 + && !PAX_RAND_FLAGS(mm)
53841 +#endif
53842 + ) {
53843 seq_put_decimal_ull(m, ' ', mm->start_data);
53844 seq_put_decimal_ull(m, ' ', mm->end_data);
53845 seq_put_decimal_ull(m, ' ', mm->start_brk);
53846 @@ -573,8 +634,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53847 struct pid *pid, struct task_struct *task)
53848 {
53849 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
53850 - struct mm_struct *mm = get_task_mm(task);
53851 + struct mm_struct *mm;
53852
53853 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53854 + if (current->exec_id != m->exec_id) {
53855 + gr_log_badprocpid("statm");
53856 + return 0;
53857 + }
53858 +#endif
53859 + mm = get_task_mm(task);
53860 if (mm) {
53861 size = task_statm(mm, &shared, &text, &data, &resident);
53862 mmput(mm);
53863 @@ -597,6 +665,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
53864 return 0;
53865 }
53866
53867 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
53868 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
53869 +{
53870 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
53871 +}
53872 +#endif
53873 +
53874 #ifdef CONFIG_CHECKPOINT_RESTORE
53875 static struct pid *
53876 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
53877 diff --git a/fs/proc/base.c b/fs/proc/base.c
53878 index 9b43ff77..ba3e990 100644
53879 --- a/fs/proc/base.c
53880 +++ b/fs/proc/base.c
53881 @@ -111,6 +111,14 @@ struct pid_entry {
53882 union proc_op op;
53883 };
53884
53885 +struct getdents_callback {
53886 + struct linux_dirent __user * current_dir;
53887 + struct linux_dirent __user * previous;
53888 + struct file * file;
53889 + int count;
53890 + int error;
53891 +};
53892 +
53893 #define NOD(NAME, MODE, IOP, FOP, OP) { \
53894 .name = (NAME), \
53895 .len = sizeof(NAME) - 1, \
53896 @@ -208,6 +216,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
53897 if (!mm->arg_end)
53898 goto out_mm; /* Shh! No looking before we're done */
53899
53900 + if (gr_acl_handle_procpidmem(task))
53901 + goto out_mm;
53902 +
53903 len = mm->arg_end - mm->arg_start;
53904
53905 if (len > PAGE_SIZE)
53906 @@ -235,12 +246,28 @@ out:
53907 return res;
53908 }
53909
53910 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53911 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
53912 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
53913 + _mm->pax_flags & MF_PAX_SEGMEXEC))
53914 +#endif
53915 +
53916 static int proc_pid_auxv(struct task_struct *task, char *buffer)
53917 {
53918 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
53919 int res = PTR_ERR(mm);
53920 if (mm && !IS_ERR(mm)) {
53921 unsigned int nwords = 0;
53922 +
53923 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
53924 + /* allow if we're currently ptracing this task */
53925 + if (PAX_RAND_FLAGS(mm) &&
53926 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
53927 + mmput(mm);
53928 + return 0;
53929 + }
53930 +#endif
53931 +
53932 do {
53933 nwords += 2;
53934 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
53935 @@ -254,7 +281,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
53936 }
53937
53938
53939 -#ifdef CONFIG_KALLSYMS
53940 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53941 /*
53942 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
53943 * Returns the resolved symbol. If that fails, simply return the address.
53944 @@ -293,7 +320,7 @@ static void unlock_trace(struct task_struct *task)
53945 mutex_unlock(&task->signal->cred_guard_mutex);
53946 }
53947
53948 -#ifdef CONFIG_STACKTRACE
53949 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
53950
53951 #define MAX_STACK_TRACE_DEPTH 64
53952
53953 @@ -485,7 +512,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
53954 return count;
53955 }
53956
53957 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
53958 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
53959 static int proc_pid_syscall(struct task_struct *task, char *buffer)
53960 {
53961 long nr;
53962 @@ -514,7 +541,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
53963 /************************************************************************/
53964
53965 /* permission checks */
53966 -static int proc_fd_access_allowed(struct inode *inode)
53967 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
53968 {
53969 struct task_struct *task;
53970 int allowed = 0;
53971 @@ -524,7 +551,10 @@ static int proc_fd_access_allowed(struct inode *inode)
53972 */
53973 task = get_proc_task(inode);
53974 if (task) {
53975 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
53976 + if (log)
53977 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
53978 + else
53979 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
53980 put_task_struct(task);
53981 }
53982 return allowed;
53983 @@ -555,10 +585,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
53984 struct task_struct *task,
53985 int hide_pid_min)
53986 {
53987 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
53988 + return false;
53989 +
53990 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
53991 + rcu_read_lock();
53992 + {
53993 + const struct cred *tmpcred = current_cred();
53994 + const struct cred *cred = __task_cred(task);
53995 +
53996 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
53997 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
53998 + || in_group_p(grsec_proc_gid)
53999 +#endif
54000 + ) {
54001 + rcu_read_unlock();
54002 + return true;
54003 + }
54004 + }
54005 + rcu_read_unlock();
54006 +
54007 + if (!pid->hide_pid)
54008 + return false;
54009 +#endif
54010 +
54011 if (pid->hide_pid < hide_pid_min)
54012 return true;
54013 if (in_group_p(pid->pid_gid))
54014 return true;
54015 +
54016 return ptrace_may_access(task, PTRACE_MODE_READ);
54017 }
54018
54019 @@ -576,7 +631,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
54020 put_task_struct(task);
54021
54022 if (!has_perms) {
54023 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54024 + {
54025 +#else
54026 if (pid->hide_pid == 2) {
54027 +#endif
54028 /*
54029 * Let's make getdents(), stat(), and open()
54030 * consistent with each other. If a process
54031 @@ -674,6 +733,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54032 if (!task)
54033 return -ESRCH;
54034
54035 + if (gr_acl_handle_procpidmem(task)) {
54036 + put_task_struct(task);
54037 + return -EPERM;
54038 + }
54039 +
54040 mm = mm_access(task, mode);
54041 put_task_struct(task);
54042
54043 @@ -689,6 +753,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
54044
54045 file->private_data = mm;
54046
54047 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54048 + file->f_version = current->exec_id;
54049 +#endif
54050 +
54051 return 0;
54052 }
54053
54054 @@ -710,6 +778,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
54055 ssize_t copied;
54056 char *page;
54057
54058 +#ifdef CONFIG_GRKERNSEC
54059 + if (write)
54060 + return -EPERM;
54061 +#endif
54062 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54063 + if (file->f_version != current->exec_id) {
54064 + gr_log_badprocpid("mem");
54065 + return 0;
54066 + }
54067 +#endif
54068 +
54069 if (!mm)
54070 return 0;
54071
54072 @@ -814,6 +893,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
54073 if (!mm)
54074 return 0;
54075
54076 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54077 + if (file->f_version != current->exec_id) {
54078 + gr_log_badprocpid("environ");
54079 + return 0;
54080 + }
54081 +#endif
54082 +
54083 page = (char *)__get_free_page(GFP_TEMPORARY);
54084 if (!page)
54085 return -ENOMEM;
54086 @@ -1429,7 +1515,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
54087 int error = -EACCES;
54088
54089 /* Are we allowed to snoop on the tasks file descriptors? */
54090 - if (!proc_fd_access_allowed(inode))
54091 + if (!proc_fd_access_allowed(inode, 0))
54092 goto out;
54093
54094 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54095 @@ -1473,8 +1559,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
54096 struct path path;
54097
54098 /* Are we allowed to snoop on the tasks file descriptors? */
54099 - if (!proc_fd_access_allowed(inode))
54100 - goto out;
54101 + /* logging this is needed for learning on chromium to work properly,
54102 + but we don't want to flood the logs from 'ps' which does a readlink
54103 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
54104 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
54105 + */
54106 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
54107 + if (!proc_fd_access_allowed(inode,0))
54108 + goto out;
54109 + } else {
54110 + if (!proc_fd_access_allowed(inode,1))
54111 + goto out;
54112 + }
54113
54114 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
54115 if (error)
54116 @@ -1524,7 +1620,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
54117 rcu_read_lock();
54118 cred = __task_cred(task);
54119 inode->i_uid = cred->euid;
54120 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54121 + inode->i_gid = grsec_proc_gid;
54122 +#else
54123 inode->i_gid = cred->egid;
54124 +#endif
54125 rcu_read_unlock();
54126 }
54127 security_task_to_inode(task, inode);
54128 @@ -1560,10 +1660,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
54129 return -ENOENT;
54130 }
54131 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54132 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54133 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54134 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54135 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54136 +#endif
54137 task_dumpable(task)) {
54138 cred = __task_cred(task);
54139 stat->uid = cred->euid;
54140 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54141 + stat->gid = grsec_proc_gid;
54142 +#else
54143 stat->gid = cred->egid;
54144 +#endif
54145 }
54146 }
54147 rcu_read_unlock();
54148 @@ -1601,11 +1710,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
54149
54150 if (task) {
54151 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
54152 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54153 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
54154 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54155 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
54156 +#endif
54157 task_dumpable(task)) {
54158 rcu_read_lock();
54159 cred = __task_cred(task);
54160 inode->i_uid = cred->euid;
54161 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54162 + inode->i_gid = grsec_proc_gid;
54163 +#else
54164 inode->i_gid = cred->egid;
54165 +#endif
54166 rcu_read_unlock();
54167 } else {
54168 inode->i_uid = GLOBAL_ROOT_UID;
54169 @@ -2058,6 +2176,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
54170 if (!task)
54171 goto out_no_task;
54172
54173 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54174 + goto out;
54175 +
54176 /*
54177 * Yes, it does not scale. And it should not. Don't add
54178 * new entries into /proc/<tgid>/ without very good reasons.
54179 @@ -2102,6 +2223,9 @@ static int proc_pident_readdir(struct file *filp,
54180 if (!task)
54181 goto out_no_task;
54182
54183 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54184 + goto out;
54185 +
54186 ret = 0;
54187 i = filp->f_pos;
54188 switch (i) {
54189 @@ -2515,7 +2639,7 @@ static const struct pid_entry tgid_base_stuff[] = {
54190 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
54191 #endif
54192 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54193 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54194 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54195 INF("syscall", S_IRUGO, proc_pid_syscall),
54196 #endif
54197 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54198 @@ -2540,10 +2664,10 @@ static const struct pid_entry tgid_base_stuff[] = {
54199 #ifdef CONFIG_SECURITY
54200 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54201 #endif
54202 -#ifdef CONFIG_KALLSYMS
54203 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54204 INF("wchan", S_IRUGO, proc_pid_wchan),
54205 #endif
54206 -#ifdef CONFIG_STACKTRACE
54207 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54208 ONE("stack", S_IRUGO, proc_pid_stack),
54209 #endif
54210 #ifdef CONFIG_SCHEDSTATS
54211 @@ -2577,6 +2701,9 @@ static const struct pid_entry tgid_base_stuff[] = {
54212 #ifdef CONFIG_HARDWALL
54213 INF("hardwall", S_IRUGO, proc_pid_hardwall),
54214 #endif
54215 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54216 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
54217 +#endif
54218 #ifdef CONFIG_USER_NS
54219 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
54220 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
54221 @@ -2705,7 +2832,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
54222 if (!inode)
54223 goto out;
54224
54225 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54226 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
54227 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54228 + inode->i_gid = grsec_proc_gid;
54229 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
54230 +#else
54231 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
54232 +#endif
54233 inode->i_op = &proc_tgid_base_inode_operations;
54234 inode->i_fop = &proc_tgid_base_operations;
54235 inode->i_flags|=S_IMMUTABLE;
54236 @@ -2743,7 +2877,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
54237 if (!task)
54238 goto out;
54239
54240 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
54241 + goto out_put_task;
54242 +
54243 result = proc_pid_instantiate(dir, dentry, task, NULL);
54244 +out_put_task:
54245 put_task_struct(task);
54246 out:
54247 return result;
54248 @@ -2806,6 +2944,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
54249 static int fake_filldir(void *buf, const char *name, int namelen,
54250 loff_t offset, u64 ino, unsigned d_type)
54251 {
54252 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
54253 + __buf->error = -EINVAL;
54254 return 0;
54255 }
54256
54257 @@ -2857,7 +2997,7 @@ static const struct pid_entry tid_base_stuff[] = {
54258 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
54259 #endif
54260 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
54261 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
54262 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
54263 INF("syscall", S_IRUGO, proc_pid_syscall),
54264 #endif
54265 INF("cmdline", S_IRUGO, proc_pid_cmdline),
54266 @@ -2884,10 +3024,10 @@ static const struct pid_entry tid_base_stuff[] = {
54267 #ifdef CONFIG_SECURITY
54268 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
54269 #endif
54270 -#ifdef CONFIG_KALLSYMS
54271 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54272 INF("wchan", S_IRUGO, proc_pid_wchan),
54273 #endif
54274 -#ifdef CONFIG_STACKTRACE
54275 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
54276 ONE("stack", S_IRUGO, proc_pid_stack),
54277 #endif
54278 #ifdef CONFIG_SCHEDSTATS
54279 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
54280 index 82676e3..5f8518a 100644
54281 --- a/fs/proc/cmdline.c
54282 +++ b/fs/proc/cmdline.c
54283 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
54284
54285 static int __init proc_cmdline_init(void)
54286 {
54287 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54288 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
54289 +#else
54290 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
54291 +#endif
54292 return 0;
54293 }
54294 module_init(proc_cmdline_init);
54295 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
54296 index b143471..bb105e5 100644
54297 --- a/fs/proc/devices.c
54298 +++ b/fs/proc/devices.c
54299 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
54300
54301 static int __init proc_devices_init(void)
54302 {
54303 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54304 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
54305 +#else
54306 proc_create("devices", 0, NULL, &proc_devinfo_operations);
54307 +#endif
54308 return 0;
54309 }
54310 module_init(proc_devices_init);
54311 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
54312 index d7a4a28..0201742 100644
54313 --- a/fs/proc/fd.c
54314 +++ b/fs/proc/fd.c
54315 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
54316 if (!task)
54317 return -ENOENT;
54318
54319 - files = get_files_struct(task);
54320 + if (!gr_acl_handle_procpidmem(task))
54321 + files = get_files_struct(task);
54322 put_task_struct(task);
54323
54324 if (files) {
54325 @@ -302,11 +303,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
54326 */
54327 int proc_fd_permission(struct inode *inode, int mask)
54328 {
54329 + struct task_struct *task;
54330 int rv = generic_permission(inode, mask);
54331 - if (rv == 0)
54332 - return 0;
54333 +
54334 if (task_pid(current) == proc_pid(inode))
54335 rv = 0;
54336 +
54337 + task = get_proc_task(inode);
54338 + if (task == NULL)
54339 + return rv;
54340 +
54341 + if (gr_acl_handle_procpidmem(task))
54342 + rv = -EACCES;
54343 +
54344 + put_task_struct(task);
54345 +
54346 return rv;
54347 }
54348
54349 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
54350 index 439ae688..c21ac36 100644
54351 --- a/fs/proc/inode.c
54352 +++ b/fs/proc/inode.c
54353 @@ -21,11 +21,17 @@
54354 #include <linux/seq_file.h>
54355 #include <linux/slab.h>
54356 #include <linux/mount.h>
54357 +#include <linux/grsecurity.h>
54358
54359 #include <asm/uaccess.h>
54360
54361 #include "internal.h"
54362
54363 +#ifdef CONFIG_PROC_SYSCTL
54364 +extern const struct inode_operations proc_sys_inode_operations;
54365 +extern const struct inode_operations proc_sys_dir_operations;
54366 +#endif
54367 +
54368 static void proc_evict_inode(struct inode *inode)
54369 {
54370 struct proc_dir_entry *de;
54371 @@ -53,6 +59,13 @@ static void proc_evict_inode(struct inode *inode)
54372 ns = PROC_I(inode)->ns;
54373 if (ns_ops && ns)
54374 ns_ops->put(ns);
54375 +
54376 +#ifdef CONFIG_PROC_SYSCTL
54377 + if (inode->i_op == &proc_sys_inode_operations ||
54378 + inode->i_op == &proc_sys_dir_operations)
54379 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
54380 +#endif
54381 +
54382 }
54383
54384 static struct kmem_cache * proc_inode_cachep;
54385 @@ -457,7 +470,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
54386 if (de->mode) {
54387 inode->i_mode = de->mode;
54388 inode->i_uid = de->uid;
54389 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
54390 + inode->i_gid = grsec_proc_gid;
54391 +#else
54392 inode->i_gid = de->gid;
54393 +#endif
54394 }
54395 if (de->size)
54396 inode->i_size = de->size;
54397 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
54398 index 252544c..04395b9 100644
54399 --- a/fs/proc/internal.h
54400 +++ b/fs/proc/internal.h
54401 @@ -55,6 +55,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
54402 struct pid *pid, struct task_struct *task);
54403 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
54404 struct pid *pid, struct task_struct *task);
54405 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
54406 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
54407 +#endif
54408 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
54409
54410 extern const struct file_operations proc_tid_children_operations;
54411 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
54412 index e96d4f1..8b116ed 100644
54413 --- a/fs/proc/kcore.c
54414 +++ b/fs/proc/kcore.c
54415 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54416 * the addresses in the elf_phdr on our list.
54417 */
54418 start = kc_offset_to_vaddr(*fpos - elf_buflen);
54419 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
54420 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
54421 + if (tsz > buflen)
54422 tsz = buflen;
54423 -
54424 +
54425 while (buflen) {
54426 struct kcore_list *m;
54427
54428 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54429 kfree(elf_buf);
54430 } else {
54431 if (kern_addr_valid(start)) {
54432 - unsigned long n;
54433 + char *elf_buf;
54434 + mm_segment_t oldfs;
54435
54436 - n = copy_to_user(buffer, (char *)start, tsz);
54437 - /*
54438 - * We cannot distinguish between fault on source
54439 - * and fault on destination. When this happens
54440 - * we clear too and hope it will trigger the
54441 - * EFAULT again.
54442 - */
54443 - if (n) {
54444 - if (clear_user(buffer + tsz - n,
54445 - n))
54446 + elf_buf = kmalloc(tsz, GFP_KERNEL);
54447 + if (!elf_buf)
54448 + return -ENOMEM;
54449 + oldfs = get_fs();
54450 + set_fs(KERNEL_DS);
54451 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
54452 + set_fs(oldfs);
54453 + if (copy_to_user(buffer, elf_buf, tsz)) {
54454 + kfree(elf_buf);
54455 return -EFAULT;
54456 + }
54457 }
54458 + set_fs(oldfs);
54459 + kfree(elf_buf);
54460 } else {
54461 if (clear_user(buffer, tsz))
54462 return -EFAULT;
54463 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
54464
54465 static int open_kcore(struct inode *inode, struct file *filp)
54466 {
54467 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
54468 + return -EPERM;
54469 +#endif
54470 if (!capable(CAP_SYS_RAWIO))
54471 return -EPERM;
54472 if (kcore_need_update)
54473 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
54474 index 80e4645..53e5fcf 100644
54475 --- a/fs/proc/meminfo.c
54476 +++ b/fs/proc/meminfo.c
54477 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
54478 vmi.used >> 10,
54479 vmi.largest_chunk >> 10
54480 #ifdef CONFIG_MEMORY_FAILURE
54481 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
54482 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
54483 #endif
54484 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
54485 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
54486 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
54487 index b1822dd..df622cb 100644
54488 --- a/fs/proc/nommu.c
54489 +++ b/fs/proc/nommu.c
54490 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
54491 if (len < 1)
54492 len = 1;
54493 seq_printf(m, "%*c", len, ' ');
54494 - seq_path(m, &file->f_path, "");
54495 + seq_path(m, &file->f_path, "\n\\");
54496 }
54497
54498 seq_putc(m, '\n');
54499 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
54500 index fe72cd0..21b52ff 100644
54501 --- a/fs/proc/proc_net.c
54502 +++ b/fs/proc/proc_net.c
54503 @@ -23,6 +23,7 @@
54504 #include <linux/nsproxy.h>
54505 #include <net/net_namespace.h>
54506 #include <linux/seq_file.h>
54507 +#include <linux/grsecurity.h>
54508
54509 #include "internal.h"
54510
54511 @@ -105,6 +106,17 @@ static struct net *get_proc_task_net(struct inode *dir)
54512 struct task_struct *task;
54513 struct nsproxy *ns;
54514 struct net *net = NULL;
54515 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54516 + const struct cred *cred = current_cred();
54517 +#endif
54518 +
54519 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54520 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
54521 + return net;
54522 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54523 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
54524 + return net;
54525 +#endif
54526
54527 rcu_read_lock();
54528 task = pid_task(proc_pid(dir), PIDTYPE_PID);
54529 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
54530 index 1827d88..43b0279 100644
54531 --- a/fs/proc/proc_sysctl.c
54532 +++ b/fs/proc/proc_sysctl.c
54533 @@ -12,11 +12,15 @@
54534 #include <linux/module.h>
54535 #include "internal.h"
54536
54537 +extern int gr_handle_chroot_sysctl(const int op);
54538 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
54539 + const int op);
54540 +
54541 static const struct dentry_operations proc_sys_dentry_operations;
54542 static const struct file_operations proc_sys_file_operations;
54543 -static const struct inode_operations proc_sys_inode_operations;
54544 +const struct inode_operations proc_sys_inode_operations;
54545 static const struct file_operations proc_sys_dir_file_operations;
54546 -static const struct inode_operations proc_sys_dir_operations;
54547 +const struct inode_operations proc_sys_dir_operations;
54548
54549 void proc_sys_poll_notify(struct ctl_table_poll *poll)
54550 {
54551 @@ -466,6 +470,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
54552
54553 err = NULL;
54554 d_set_d_op(dentry, &proc_sys_dentry_operations);
54555 +
54556 + gr_handle_proc_create(dentry, inode);
54557 +
54558 d_add(dentry, inode);
54559
54560 out:
54561 @@ -481,6 +488,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54562 struct inode *inode = filp->f_path.dentry->d_inode;
54563 struct ctl_table_header *head = grab_header(inode);
54564 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
54565 + int op = write ? MAY_WRITE : MAY_READ;
54566 ssize_t error;
54567 size_t res;
54568
54569 @@ -492,7 +500,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54570 * and won't be until we finish.
54571 */
54572 error = -EPERM;
54573 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
54574 + if (sysctl_perm(head, table, op))
54575 goto out;
54576
54577 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
54578 @@ -500,6 +508,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
54579 if (!table->proc_handler)
54580 goto out;
54581
54582 +#ifdef CONFIG_GRKERNSEC
54583 + error = -EPERM;
54584 + if (gr_handle_chroot_sysctl(op))
54585 + goto out;
54586 + dget(filp->f_path.dentry);
54587 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
54588 + dput(filp->f_path.dentry);
54589 + goto out;
54590 + }
54591 + dput(filp->f_path.dentry);
54592 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
54593 + goto out;
54594 + if (write && !capable(CAP_SYS_ADMIN))
54595 + goto out;
54596 +#endif
54597 +
54598 /* careful: calling conventions are nasty here */
54599 res = count;
54600 error = table->proc_handler(table, write, buf, &res, ppos);
54601 @@ -597,6 +621,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
54602 return -ENOMEM;
54603 } else {
54604 d_set_d_op(child, &proc_sys_dentry_operations);
54605 +
54606 + gr_handle_proc_create(child, inode);
54607 +
54608 d_add(child, inode);
54609 }
54610 } else {
54611 @@ -640,6 +667,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
54612 if ((*pos)++ < file->f_pos)
54613 return 0;
54614
54615 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
54616 + return 0;
54617 +
54618 if (unlikely(S_ISLNK(table->mode)))
54619 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
54620 else
54621 @@ -750,6 +780,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
54622 if (IS_ERR(head))
54623 return PTR_ERR(head);
54624
54625 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
54626 + return -ENOENT;
54627 +
54628 generic_fillattr(inode, stat);
54629 if (table)
54630 stat->mode = (stat->mode & S_IFMT) | table->mode;
54631 @@ -772,13 +805,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
54632 .llseek = generic_file_llseek,
54633 };
54634
54635 -static const struct inode_operations proc_sys_inode_operations = {
54636 +const struct inode_operations proc_sys_inode_operations = {
54637 .permission = proc_sys_permission,
54638 .setattr = proc_sys_setattr,
54639 .getattr = proc_sys_getattr,
54640 };
54641
54642 -static const struct inode_operations proc_sys_dir_operations = {
54643 +const struct inode_operations proc_sys_dir_operations = {
54644 .lookup = proc_sys_lookup,
54645 .permission = proc_sys_permission,
54646 .setattr = proc_sys_setattr,
54647 @@ -854,7 +887,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
54648 static struct ctl_dir *new_dir(struct ctl_table_set *set,
54649 const char *name, int namelen)
54650 {
54651 - struct ctl_table *table;
54652 + ctl_table_no_const *table;
54653 struct ctl_dir *new;
54654 struct ctl_node *node;
54655 char *new_name;
54656 @@ -866,7 +899,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
54657 return NULL;
54658
54659 node = (struct ctl_node *)(new + 1);
54660 - table = (struct ctl_table *)(node + 1);
54661 + table = (ctl_table_no_const *)(node + 1);
54662 new_name = (char *)(table + 2);
54663 memcpy(new_name, name, namelen);
54664 new_name[namelen] = '\0';
54665 @@ -1035,7 +1068,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
54666 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
54667 struct ctl_table_root *link_root)
54668 {
54669 - struct ctl_table *link_table, *entry, *link;
54670 + ctl_table_no_const *link_table, *link;
54671 + struct ctl_table *entry;
54672 struct ctl_table_header *links;
54673 struct ctl_node *node;
54674 char *link_name;
54675 @@ -1058,7 +1092,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
54676 return NULL;
54677
54678 node = (struct ctl_node *)(links + 1);
54679 - link_table = (struct ctl_table *)(node + nr_entries);
54680 + link_table = (ctl_table_no_const *)(node + nr_entries);
54681 link_name = (char *)&link_table[nr_entries + 1];
54682
54683 for (link = link_table, entry = table; entry->procname; link++, entry++) {
54684 @@ -1306,8 +1340,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54685 struct ctl_table_header ***subheader, struct ctl_table_set *set,
54686 struct ctl_table *table)
54687 {
54688 - struct ctl_table *ctl_table_arg = NULL;
54689 - struct ctl_table *entry, *files;
54690 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
54691 + struct ctl_table *entry;
54692 int nr_files = 0;
54693 int nr_dirs = 0;
54694 int err = -ENOMEM;
54695 @@ -1319,10 +1353,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54696 nr_files++;
54697 }
54698
54699 - files = table;
54700 /* If there are mixed files and directories we need a new table */
54701 if (nr_dirs && nr_files) {
54702 - struct ctl_table *new;
54703 + ctl_table_no_const *new;
54704 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
54705 GFP_KERNEL);
54706 if (!files)
54707 @@ -1340,7 +1373,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
54708 /* Register everything except a directory full of subdirectories */
54709 if (nr_files || !nr_dirs) {
54710 struct ctl_table_header *header;
54711 - header = __register_sysctl_table(set, path, files);
54712 + header = __register_sysctl_table(set, path, files ? files : table);
54713 if (!header) {
54714 kfree(ctl_table_arg);
54715 goto out;
54716 diff --git a/fs/proc/root.c b/fs/proc/root.c
54717 index c6e9fac..a740964 100644
54718 --- a/fs/proc/root.c
54719 +++ b/fs/proc/root.c
54720 @@ -176,7 +176,15 @@ void __init proc_root_init(void)
54721 #ifdef CONFIG_PROC_DEVICETREE
54722 proc_device_tree_init();
54723 #endif
54724 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
54725 +#ifdef CONFIG_GRKERNSEC_PROC_USER
54726 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
54727 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
54728 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
54729 +#endif
54730 +#else
54731 proc_mkdir("bus", NULL);
54732 +#endif
54733 proc_sys_init();
54734 }
54735
54736 diff --git a/fs/proc/self.c b/fs/proc/self.c
54737 index aa5cc3b..c91a5d0 100644
54738 --- a/fs/proc/self.c
54739 +++ b/fs/proc/self.c
54740 @@ -37,7 +37,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
54741 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
54742 void *cookie)
54743 {
54744 - char *s = nd_get_link(nd);
54745 + const char *s = nd_get_link(nd);
54746 if (!IS_ERR(s))
54747 kfree(s);
54748 }
54749 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
54750 index ca5ce7f..02c1cf0 100644
54751 --- a/fs/proc/task_mmu.c
54752 +++ b/fs/proc/task_mmu.c
54753 @@ -11,12 +11,19 @@
54754 #include <linux/rmap.h>
54755 #include <linux/swap.h>
54756 #include <linux/swapops.h>
54757 +#include <linux/grsecurity.h>
54758
54759 #include <asm/elf.h>
54760 #include <asm/uaccess.h>
54761 #include <asm/tlbflush.h>
54762 #include "internal.h"
54763
54764 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54765 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
54766 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
54767 + _mm->pax_flags & MF_PAX_SEGMEXEC))
54768 +#endif
54769 +
54770 void task_mem(struct seq_file *m, struct mm_struct *mm)
54771 {
54772 unsigned long data, text, lib, swap;
54773 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54774 "VmExe:\t%8lu kB\n"
54775 "VmLib:\t%8lu kB\n"
54776 "VmPTE:\t%8lu kB\n"
54777 - "VmSwap:\t%8lu kB\n",
54778 - hiwater_vm << (PAGE_SHIFT-10),
54779 + "VmSwap:\t%8lu kB\n"
54780 +
54781 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54782 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
54783 +#endif
54784 +
54785 + ,hiwater_vm << (PAGE_SHIFT-10),
54786 total_vm << (PAGE_SHIFT-10),
54787 mm->locked_vm << (PAGE_SHIFT-10),
54788 mm->pinned_vm << (PAGE_SHIFT-10),
54789 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54790 data << (PAGE_SHIFT-10),
54791 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
54792 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
54793 - swap << (PAGE_SHIFT-10));
54794 + swap << (PAGE_SHIFT-10)
54795 +
54796 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
54797 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54798 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
54799 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
54800 +#else
54801 + , mm->context.user_cs_base
54802 + , mm->context.user_cs_limit
54803 +#endif
54804 +#endif
54805 +
54806 + );
54807 }
54808
54809 unsigned long task_vsize(struct mm_struct *mm)
54810 @@ -277,13 +301,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54811 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
54812 }
54813
54814 - /* We don't show the stack guard page in /proc/maps */
54815 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54816 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
54817 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
54818 +#else
54819 start = vma->vm_start;
54820 - if (stack_guard_page_start(vma, start))
54821 - start += PAGE_SIZE;
54822 end = vma->vm_end;
54823 - if (stack_guard_page_end(vma, end))
54824 - end -= PAGE_SIZE;
54825 +#endif
54826
54827 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
54828 start,
54829 @@ -292,7 +316,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54830 flags & VM_WRITE ? 'w' : '-',
54831 flags & VM_EXEC ? 'x' : '-',
54832 flags & VM_MAYSHARE ? 's' : 'p',
54833 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54834 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
54835 +#else
54836 pgoff,
54837 +#endif
54838 MAJOR(dev), MINOR(dev), ino, &len);
54839
54840 /*
54841 @@ -301,7 +329,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54842 */
54843 if (file) {
54844 pad_len_spaces(m, len);
54845 - seq_path(m, &file->f_path, "\n");
54846 + seq_path(m, &file->f_path, "\n\\");
54847 goto done;
54848 }
54849
54850 @@ -327,8 +355,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
54851 * Thread stack in /proc/PID/task/TID/maps or
54852 * the main process stack.
54853 */
54854 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
54855 - vma->vm_end >= mm->start_stack)) {
54856 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
54857 + (vma->vm_start <= mm->start_stack &&
54858 + vma->vm_end >= mm->start_stack)) {
54859 name = "[stack]";
54860 } else {
54861 /* Thread stack in /proc/PID/maps */
54862 @@ -352,6 +381,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
54863 struct proc_maps_private *priv = m->private;
54864 struct task_struct *task = priv->task;
54865
54866 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54867 + if (current->exec_id != m->exec_id) {
54868 + gr_log_badprocpid("maps");
54869 + return 0;
54870 + }
54871 +#endif
54872 +
54873 show_map_vma(m, vma, is_pid);
54874
54875 if (m->count < m->size) /* vma is copied successfully */
54876 @@ -589,12 +625,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
54877 .private = &mss,
54878 };
54879
54880 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54881 + if (current->exec_id != m->exec_id) {
54882 + gr_log_badprocpid("smaps");
54883 + return 0;
54884 + }
54885 +#endif
54886 memset(&mss, 0, sizeof mss);
54887 - mss.vma = vma;
54888 - /* mmap_sem is held in m_start */
54889 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
54890 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
54891 -
54892 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54893 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
54894 +#endif
54895 + mss.vma = vma;
54896 + /* mmap_sem is held in m_start */
54897 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
54898 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
54899 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54900 + }
54901 +#endif
54902 show_map_vma(m, vma, is_pid);
54903
54904 seq_printf(m,
54905 @@ -612,7 +659,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
54906 "KernelPageSize: %8lu kB\n"
54907 "MMUPageSize: %8lu kB\n"
54908 "Locked: %8lu kB\n",
54909 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54910 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
54911 +#else
54912 (vma->vm_end - vma->vm_start) >> 10,
54913 +#endif
54914 mss.resident >> 10,
54915 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
54916 mss.shared_clean >> 10,
54917 @@ -1264,6 +1315,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
54918 int n;
54919 char buffer[50];
54920
54921 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54922 + if (current->exec_id != m->exec_id) {
54923 + gr_log_badprocpid("numa_maps");
54924 + return 0;
54925 + }
54926 +#endif
54927 +
54928 if (!mm)
54929 return 0;
54930
54931 @@ -1281,11 +1339,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
54932 mpol_to_str(buffer, sizeof(buffer), pol);
54933 mpol_cond_put(pol);
54934
54935 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
54936 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
54937 +#else
54938 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
54939 +#endif
54940
54941 if (file) {
54942 seq_printf(m, " file=");
54943 - seq_path(m, &file->f_path, "\n\t= ");
54944 + seq_path(m, &file->f_path, "\n\t\\= ");
54945 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
54946 seq_printf(m, " heap");
54947 } else {
54948 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
54949 index 1ccfa53..0848f95 100644
54950 --- a/fs/proc/task_nommu.c
54951 +++ b/fs/proc/task_nommu.c
54952 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
54953 else
54954 bytes += kobjsize(mm);
54955
54956 - if (current->fs && current->fs->users > 1)
54957 + if (current->fs && atomic_read(&current->fs->users) > 1)
54958 sbytes += kobjsize(current->fs);
54959 else
54960 bytes += kobjsize(current->fs);
54961 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
54962
54963 if (file) {
54964 pad_len_spaces(m, len);
54965 - seq_path(m, &file->f_path, "");
54966 + seq_path(m, &file->f_path, "\n\\");
54967 } else if (mm) {
54968 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
54969
54970 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
54971 index 16e8abb..2dcf914 100644
54972 --- a/fs/quota/netlink.c
54973 +++ b/fs/quota/netlink.c
54974 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
54975 void quota_send_warning(struct kqid qid, dev_t dev,
54976 const char warntype)
54977 {
54978 - static atomic_t seq;
54979 + static atomic_unchecked_t seq;
54980 struct sk_buff *skb;
54981 void *msg_head;
54982 int ret;
54983 @@ -49,7 +49,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
54984 "VFS: Not enough memory to send quota warning.\n");
54985 return;
54986 }
54987 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
54988 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
54989 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
54990 if (!msg_head) {
54991 printk(KERN_ERR
54992 diff --git a/fs/readdir.c b/fs/readdir.c
54993 index 5e69ef5..e5d9099 100644
54994 --- a/fs/readdir.c
54995 +++ b/fs/readdir.c
54996 @@ -17,6 +17,7 @@
54997 #include <linux/security.h>
54998 #include <linux/syscalls.h>
54999 #include <linux/unistd.h>
55000 +#include <linux/namei.h>
55001
55002 #include <asm/uaccess.h>
55003
55004 @@ -67,6 +68,7 @@ struct old_linux_dirent {
55005
55006 struct readdir_callback {
55007 struct old_linux_dirent __user * dirent;
55008 + struct file * file;
55009 int result;
55010 };
55011
55012 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
55013 buf->result = -EOVERFLOW;
55014 return -EOVERFLOW;
55015 }
55016 +
55017 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55018 + return 0;
55019 +
55020 buf->result++;
55021 dirent = buf->dirent;
55022 if (!access_ok(VERIFY_WRITE, dirent,
55023 @@ -114,6 +120,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
55024
55025 buf.result = 0;
55026 buf.dirent = dirent;
55027 + buf.file = f.file;
55028
55029 error = vfs_readdir(f.file, fillonedir, &buf);
55030 if (buf.result)
55031 @@ -139,6 +146,7 @@ struct linux_dirent {
55032 struct getdents_callback {
55033 struct linux_dirent __user * current_dir;
55034 struct linux_dirent __user * previous;
55035 + struct file * file;
55036 int count;
55037 int error;
55038 };
55039 @@ -160,6 +168,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
55040 buf->error = -EOVERFLOW;
55041 return -EOVERFLOW;
55042 }
55043 +
55044 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55045 + return 0;
55046 +
55047 dirent = buf->previous;
55048 if (dirent) {
55049 if (__put_user(offset, &dirent->d_off))
55050 @@ -205,6 +217,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55051 buf.previous = NULL;
55052 buf.count = count;
55053 buf.error = 0;
55054 + buf.file = f.file;
55055
55056 error = vfs_readdir(f.file, filldir, &buf);
55057 if (error >= 0)
55058 @@ -223,6 +236,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
55059 struct getdents_callback64 {
55060 struct linux_dirent64 __user * current_dir;
55061 struct linux_dirent64 __user * previous;
55062 + struct file *file;
55063 int count;
55064 int error;
55065 };
55066 @@ -238,6 +252,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
55067 buf->error = -EINVAL; /* only used if we fail.. */
55068 if (reclen > buf->count)
55069 return -EINVAL;
55070 +
55071 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
55072 + return 0;
55073 +
55074 dirent = buf->previous;
55075 if (dirent) {
55076 if (__put_user(offset, &dirent->d_off))
55077 @@ -283,6 +301,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55078
55079 buf.current_dir = dirent;
55080 buf.previous = NULL;
55081 + buf.file = f.file;
55082 buf.count = count;
55083 buf.error = 0;
55084
55085 @@ -291,7 +310,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
55086 error = buf.error;
55087 lastdirent = buf.previous;
55088 if (lastdirent) {
55089 - typeof(lastdirent->d_off) d_off = f.file->f_pos;
55090 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = f.file->f_pos;
55091 if (__put_user(d_off, &lastdirent->d_off))
55092 error = -EFAULT;
55093 else
55094 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
55095 index 2b7882b..1c5ef48 100644
55096 --- a/fs/reiserfs/do_balan.c
55097 +++ b/fs/reiserfs/do_balan.c
55098 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
55099 return;
55100 }
55101
55102 - atomic_inc(&(fs_generation(tb->tb_sb)));
55103 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
55104 do_balance_starts(tb);
55105
55106 /* balance leaf returns 0 except if combining L R and S into
55107 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
55108 index e60e870..f40ac16 100644
55109 --- a/fs/reiserfs/procfs.c
55110 +++ b/fs/reiserfs/procfs.c
55111 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
55112 "SMALL_TAILS " : "NO_TAILS ",
55113 replay_only(sb) ? "REPLAY_ONLY " : "",
55114 convert_reiserfs(sb) ? "CONV " : "",
55115 - atomic_read(&r->s_generation_counter),
55116 + atomic_read_unchecked(&r->s_generation_counter),
55117 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
55118 SF(s_do_balance), SF(s_unneeded_left_neighbor),
55119 SF(s_good_search_by_key_reada), SF(s_bmaps),
55120 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
55121 index 157e474..65a6114 100644
55122 --- a/fs/reiserfs/reiserfs.h
55123 +++ b/fs/reiserfs/reiserfs.h
55124 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
55125 /* Comment? -Hans */
55126 wait_queue_head_t s_wait;
55127 /* To be obsoleted soon by per buffer seals.. -Hans */
55128 - atomic_t s_generation_counter; // increased by one every time the
55129 + atomic_unchecked_t s_generation_counter; // increased by one every time the
55130 // tree gets re-balanced
55131 unsigned long s_properties; /* File system properties. Currently holds
55132 on-disk FS format */
55133 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
55134 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
55135
55136 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
55137 -#define get_generation(s) atomic_read (&fs_generation(s))
55138 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
55139 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
55140 #define __fs_changed(gen,s) (gen != get_generation (s))
55141 #define fs_changed(gen,s) \
55142 diff --git a/fs/select.c b/fs/select.c
55143 index 2ef72d9..f213b17 100644
55144 --- a/fs/select.c
55145 +++ b/fs/select.c
55146 @@ -20,6 +20,7 @@
55147 #include <linux/export.h>
55148 #include <linux/slab.h>
55149 #include <linux/poll.h>
55150 +#include <linux/security.h>
55151 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
55152 #include <linux/file.h>
55153 #include <linux/fdtable.h>
55154 @@ -826,6 +827,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
55155 struct poll_list *walk = head;
55156 unsigned long todo = nfds;
55157
55158 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
55159 if (nfds > rlimit(RLIMIT_NOFILE))
55160 return -EINVAL;
55161
55162 diff --git a/fs/seq_file.c b/fs/seq_file.c
55163 index f2bc3df..239d4f6 100644
55164 --- a/fs/seq_file.c
55165 +++ b/fs/seq_file.c
55166 @@ -10,6 +10,7 @@
55167 #include <linux/seq_file.h>
55168 #include <linux/slab.h>
55169 #include <linux/cred.h>
55170 +#include <linux/sched.h>
55171
55172 #include <asm/uaccess.h>
55173 #include <asm/page.h>
55174 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
55175 #ifdef CONFIG_USER_NS
55176 p->user_ns = file->f_cred->user_ns;
55177 #endif
55178 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
55179 + p->exec_id = current->exec_id;
55180 +#endif
55181
55182 /*
55183 * Wrappers around seq_open(e.g. swaps_open) need to be
55184 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55185 return 0;
55186 }
55187 if (!m->buf) {
55188 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55189 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55190 if (!m->buf)
55191 return -ENOMEM;
55192 }
55193 @@ -136,7 +140,7 @@ static int traverse(struct seq_file *m, loff_t offset)
55194 Eoverflow:
55195 m->op->stop(m, p);
55196 kfree(m->buf);
55197 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55198 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55199 return !m->buf ? -ENOMEM : -EAGAIN;
55200 }
55201
55202 @@ -191,7 +195,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55203
55204 /* grab buffer if we didn't have one */
55205 if (!m->buf) {
55206 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
55207 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
55208 if (!m->buf)
55209 goto Enomem;
55210 }
55211 @@ -232,7 +236,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
55212 goto Fill;
55213 m->op->stop(m, p);
55214 kfree(m->buf);
55215 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
55216 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
55217 if (!m->buf)
55218 goto Enomem;
55219 m->count = 0;
55220 @@ -581,7 +585,7 @@ static void single_stop(struct seq_file *p, void *v)
55221 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
55222 void *data)
55223 {
55224 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
55225 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
55226 int res = -ENOMEM;
55227
55228 if (op) {
55229 diff --git a/fs/splice.c b/fs/splice.c
55230 index 6909d89..5b2e8f9 100644
55231 --- a/fs/splice.c
55232 +++ b/fs/splice.c
55233 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55234 pipe_lock(pipe);
55235
55236 for (;;) {
55237 - if (!pipe->readers) {
55238 + if (!atomic_read(&pipe->readers)) {
55239 send_sig(SIGPIPE, current, 0);
55240 if (!ret)
55241 ret = -EPIPE;
55242 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
55243 do_wakeup = 0;
55244 }
55245
55246 - pipe->waiting_writers++;
55247 + atomic_inc(&pipe->waiting_writers);
55248 pipe_wait(pipe);
55249 - pipe->waiting_writers--;
55250 + atomic_dec(&pipe->waiting_writers);
55251 }
55252
55253 pipe_unlock(pipe);
55254 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
55255 old_fs = get_fs();
55256 set_fs(get_ds());
55257 /* The cast to a user pointer is valid due to the set_fs() */
55258 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
55259 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
55260 set_fs(old_fs);
55261
55262 return res;
55263 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
55264 old_fs = get_fs();
55265 set_fs(get_ds());
55266 /* The cast to a user pointer is valid due to the set_fs() */
55267 - res = vfs_write(file, (const char __user *)buf, count, &pos);
55268 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
55269 set_fs(old_fs);
55270
55271 return res;
55272 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
55273 goto err;
55274
55275 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
55276 - vec[i].iov_base = (void __user *) page_address(page);
55277 + vec[i].iov_base = (void __force_user *) page_address(page);
55278 vec[i].iov_len = this_len;
55279 spd.pages[i] = page;
55280 spd.nr_pages++;
55281 @@ -851,10 +851,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
55282 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
55283 {
55284 while (!pipe->nrbufs) {
55285 - if (!pipe->writers)
55286 + if (!atomic_read(&pipe->writers))
55287 return 0;
55288
55289 - if (!pipe->waiting_writers && sd->num_spliced)
55290 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
55291 return 0;
55292
55293 if (sd->flags & SPLICE_F_NONBLOCK)
55294 @@ -1189,7 +1189,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
55295 * out of the pipe right after the splice_to_pipe(). So set
55296 * PIPE_READERS appropriately.
55297 */
55298 - pipe->readers = 1;
55299 + atomic_set(&pipe->readers, 1);
55300
55301 current->splice_pipe = pipe;
55302 }
55303 @@ -1738,9 +1738,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55304 ret = -ERESTARTSYS;
55305 break;
55306 }
55307 - if (!pipe->writers)
55308 + if (!atomic_read(&pipe->writers))
55309 break;
55310 - if (!pipe->waiting_writers) {
55311 + if (!atomic_read(&pipe->waiting_writers)) {
55312 if (flags & SPLICE_F_NONBLOCK) {
55313 ret = -EAGAIN;
55314 break;
55315 @@ -1772,7 +1772,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55316 pipe_lock(pipe);
55317
55318 while (pipe->nrbufs >= pipe->buffers) {
55319 - if (!pipe->readers) {
55320 + if (!atomic_read(&pipe->readers)) {
55321 send_sig(SIGPIPE, current, 0);
55322 ret = -EPIPE;
55323 break;
55324 @@ -1785,9 +1785,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
55325 ret = -ERESTARTSYS;
55326 break;
55327 }
55328 - pipe->waiting_writers++;
55329 + atomic_inc(&pipe->waiting_writers);
55330 pipe_wait(pipe);
55331 - pipe->waiting_writers--;
55332 + atomic_dec(&pipe->waiting_writers);
55333 }
55334
55335 pipe_unlock(pipe);
55336 @@ -1823,14 +1823,14 @@ retry:
55337 pipe_double_lock(ipipe, opipe);
55338
55339 do {
55340 - if (!opipe->readers) {
55341 + if (!atomic_read(&opipe->readers)) {
55342 send_sig(SIGPIPE, current, 0);
55343 if (!ret)
55344 ret = -EPIPE;
55345 break;
55346 }
55347
55348 - if (!ipipe->nrbufs && !ipipe->writers)
55349 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
55350 break;
55351
55352 /*
55353 @@ -1927,7 +1927,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55354 pipe_double_lock(ipipe, opipe);
55355
55356 do {
55357 - if (!opipe->readers) {
55358 + if (!atomic_read(&opipe->readers)) {
55359 send_sig(SIGPIPE, current, 0);
55360 if (!ret)
55361 ret = -EPIPE;
55362 @@ -1972,7 +1972,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
55363 * return EAGAIN if we have the potential of some data in the
55364 * future, otherwise just return 0
55365 */
55366 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
55367 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
55368 ret = -EAGAIN;
55369
55370 pipe_unlock(ipipe);
55371 diff --git a/fs/stat.c b/fs/stat.c
55372 index 14f4545..9b7f55b 100644
55373 --- a/fs/stat.c
55374 +++ b/fs/stat.c
55375 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
55376 stat->gid = inode->i_gid;
55377 stat->rdev = inode->i_rdev;
55378 stat->size = i_size_read(inode);
55379 - stat->atime = inode->i_atime;
55380 - stat->mtime = inode->i_mtime;
55381 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55382 + stat->atime = inode->i_ctime;
55383 + stat->mtime = inode->i_ctime;
55384 + } else {
55385 + stat->atime = inode->i_atime;
55386 + stat->mtime = inode->i_mtime;
55387 + }
55388 stat->ctime = inode->i_ctime;
55389 stat->blksize = (1 << inode->i_blkbits);
55390 stat->blocks = inode->i_blocks;
55391 @@ -46,8 +51,14 @@ int vfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
55392 if (retval)
55393 return retval;
55394
55395 - if (inode->i_op->getattr)
55396 - return inode->i_op->getattr(mnt, dentry, stat);
55397 + if (inode->i_op->getattr) {
55398 + retval = inode->i_op->getattr(mnt, dentry, stat);
55399 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
55400 + stat->atime = stat->ctime;
55401 + stat->mtime = stat->ctime;
55402 + }
55403 + return retval;
55404 + }
55405
55406 generic_fillattr(inode, stat);
55407 return 0;
55408 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
55409 index 2fbdff6..5530a61 100644
55410 --- a/fs/sysfs/dir.c
55411 +++ b/fs/sysfs/dir.c
55412 @@ -685,6 +685,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
55413 struct sysfs_dirent *sd;
55414 int rc;
55415
55416 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
55417 + const char *parent_name = parent_sd->s_name;
55418 +
55419 + mode = S_IFDIR | S_IRWXU;
55420 +
55421 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
55422 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
55423 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
55424 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
55425 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
55426 +#endif
55427 +
55428 /* allocate */
55429 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
55430 if (!sd)
55431 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
55432 index 602f56d..6853db8 100644
55433 --- a/fs/sysfs/file.c
55434 +++ b/fs/sysfs/file.c
55435 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
55436
55437 struct sysfs_open_dirent {
55438 atomic_t refcnt;
55439 - atomic_t event;
55440 + atomic_unchecked_t event;
55441 wait_queue_head_t poll;
55442 struct list_head buffers; /* goes through sysfs_buffer.list */
55443 };
55444 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
55445 if (!sysfs_get_active(attr_sd))
55446 return -ENODEV;
55447
55448 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
55449 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
55450 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
55451
55452 sysfs_put_active(attr_sd);
55453 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
55454 return -ENOMEM;
55455
55456 atomic_set(&new_od->refcnt, 0);
55457 - atomic_set(&new_od->event, 1);
55458 + atomic_set_unchecked(&new_od->event, 1);
55459 init_waitqueue_head(&new_od->poll);
55460 INIT_LIST_HEAD(&new_od->buffers);
55461 goto retry;
55462 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
55463
55464 sysfs_put_active(attr_sd);
55465
55466 - if (buffer->event != atomic_read(&od->event))
55467 + if (buffer->event != atomic_read_unchecked(&od->event))
55468 goto trigger;
55469
55470 return DEFAULT_POLLMASK;
55471 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
55472
55473 od = sd->s_attr.open;
55474 if (od) {
55475 - atomic_inc(&od->event);
55476 + atomic_inc_unchecked(&od->event);
55477 wake_up_interruptible(&od->poll);
55478 }
55479
55480 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
55481 index 3c9eb56..9dea5be 100644
55482 --- a/fs/sysfs/symlink.c
55483 +++ b/fs/sysfs/symlink.c
55484 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
55485
55486 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
55487 {
55488 - char *page = nd_get_link(nd);
55489 + const char *page = nd_get_link(nd);
55490 if (!IS_ERR(page))
55491 free_page((unsigned long)page);
55492 }
55493 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
55494 index c175b4d..8f36a16 100644
55495 --- a/fs/udf/misc.c
55496 +++ b/fs/udf/misc.c
55497 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
55498
55499 u8 udf_tag_checksum(const struct tag *t)
55500 {
55501 - u8 *data = (u8 *)t;
55502 + const u8 *data = (const u8 *)t;
55503 u8 checksum = 0;
55504 int i;
55505 for (i = 0; i < sizeof(struct tag); ++i)
55506 diff --git a/fs/utimes.c b/fs/utimes.c
55507 index f4fb7ec..3fe03c0 100644
55508 --- a/fs/utimes.c
55509 +++ b/fs/utimes.c
55510 @@ -1,6 +1,7 @@
55511 #include <linux/compiler.h>
55512 #include <linux/file.h>
55513 #include <linux/fs.h>
55514 +#include <linux/security.h>
55515 #include <linux/linkage.h>
55516 #include <linux/mount.h>
55517 #include <linux/namei.h>
55518 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
55519 goto mnt_drop_write_and_out;
55520 }
55521 }
55522 +
55523 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
55524 + error = -EACCES;
55525 + goto mnt_drop_write_and_out;
55526 + }
55527 +
55528 mutex_lock(&inode->i_mutex);
55529 error = notify_change(path->dentry, &newattrs);
55530 mutex_unlock(&inode->i_mutex);
55531 diff --git a/fs/xattr.c b/fs/xattr.c
55532 index 3377dff..4feded6 100644
55533 --- a/fs/xattr.c
55534 +++ b/fs/xattr.c
55535 @@ -319,7 +319,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
55536 * Extended attribute SET operations
55537 */
55538 static long
55539 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
55540 +setxattr(struct path *path, const char __user *name, const void __user *value,
55541 size_t size, int flags)
55542 {
55543 int error;
55544 @@ -355,7 +355,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
55545 posix_acl_fix_xattr_from_user(kvalue, size);
55546 }
55547
55548 - error = vfs_setxattr(d, kname, kvalue, size, flags);
55549 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
55550 + error = -EACCES;
55551 + goto out;
55552 + }
55553 +
55554 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
55555 out:
55556 if (vvalue)
55557 vfree(vvalue);
55558 @@ -377,7 +382,7 @@ retry:
55559 return error;
55560 error = mnt_want_write(path.mnt);
55561 if (!error) {
55562 - error = setxattr(path.dentry, name, value, size, flags);
55563 + error = setxattr(&path, name, value, size, flags);
55564 mnt_drop_write(path.mnt);
55565 }
55566 path_put(&path);
55567 @@ -401,7 +406,7 @@ retry:
55568 return error;
55569 error = mnt_want_write(path.mnt);
55570 if (!error) {
55571 - error = setxattr(path.dentry, name, value, size, flags);
55572 + error = setxattr(&path, name, value, size, flags);
55573 mnt_drop_write(path.mnt);
55574 }
55575 path_put(&path);
55576 @@ -416,16 +421,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
55577 const void __user *,value, size_t, size, int, flags)
55578 {
55579 struct fd f = fdget(fd);
55580 - struct dentry *dentry;
55581 int error = -EBADF;
55582
55583 if (!f.file)
55584 return error;
55585 - dentry = f.file->f_path.dentry;
55586 - audit_inode(NULL, dentry, 0);
55587 + audit_inode(NULL, f.file->f_path.dentry, 0);
55588 error = mnt_want_write_file(f.file);
55589 if (!error) {
55590 - error = setxattr(dentry, name, value, size, flags);
55591 + error = setxattr(&f.file->f_path, name, value, size, flags);
55592 mnt_drop_write_file(f.file);
55593 }
55594 fdput(f);
55595 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
55596 index 9fbea87..6b19972 100644
55597 --- a/fs/xattr_acl.c
55598 +++ b/fs/xattr_acl.c
55599 @@ -76,8 +76,8 @@ struct posix_acl *
55600 posix_acl_from_xattr(struct user_namespace *user_ns,
55601 const void *value, size_t size)
55602 {
55603 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
55604 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
55605 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
55606 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
55607 int count;
55608 struct posix_acl *acl;
55609 struct posix_acl_entry *acl_e;
55610 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
55611 index 572a858..12a9b0d 100644
55612 --- a/fs/xfs/xfs_bmap.c
55613 +++ b/fs/xfs/xfs_bmap.c
55614 @@ -192,7 +192,7 @@ xfs_bmap_validate_ret(
55615 int nmap,
55616 int ret_nmap);
55617 #else
55618 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
55619 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
55620 #endif /* DEBUG */
55621
55622 STATIC int
55623 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
55624 index 1b9fc3e..e1bdde0 100644
55625 --- a/fs/xfs/xfs_dir2_sf.c
55626 +++ b/fs/xfs/xfs_dir2_sf.c
55627 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
55628 }
55629
55630 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
55631 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
55632 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
55633 + char name[sfep->namelen];
55634 + memcpy(name, sfep->name, sfep->namelen);
55635 + if (filldir(dirent, name, sfep->namelen,
55636 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
55637 + *offset = off & 0x7fffffff;
55638 + return 0;
55639 + }
55640 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
55641 off & 0x7fffffff, ino, DT_UNKNOWN)) {
55642 *offset = off & 0x7fffffff;
55643 return 0;
55644 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
55645 index c1c3ef8..0952438 100644
55646 --- a/fs/xfs/xfs_ioctl.c
55647 +++ b/fs/xfs/xfs_ioctl.c
55648 @@ -127,7 +127,7 @@ xfs_find_handle(
55649 }
55650
55651 error = -EFAULT;
55652 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
55653 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
55654 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
55655 goto out_put;
55656
55657 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
55658 index d82efaa..0904a8e 100644
55659 --- a/fs/xfs/xfs_iops.c
55660 +++ b/fs/xfs/xfs_iops.c
55661 @@ -395,7 +395,7 @@ xfs_vn_put_link(
55662 struct nameidata *nd,
55663 void *p)
55664 {
55665 - char *s = nd_get_link(nd);
55666 + const char *s = nd_get_link(nd);
55667
55668 if (!IS_ERR(s))
55669 kfree(s);
55670 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
55671 new file mode 100644
55672 index 0000000..92247e4
55673 --- /dev/null
55674 +++ b/grsecurity/Kconfig
55675 @@ -0,0 +1,1021 @@
55676 +#
55677 +# grecurity configuration
55678 +#
55679 +menu "Memory Protections"
55680 +depends on GRKERNSEC
55681 +
55682 +config GRKERNSEC_KMEM
55683 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
55684 + default y if GRKERNSEC_CONFIG_AUTO
55685 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
55686 + help
55687 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
55688 + be written to or read from to modify or leak the contents of the running
55689 + kernel. /dev/port will also not be allowed to be opened and support
55690 + for /dev/cpu/*/msr will be removed. If you have module
55691 + support disabled, enabling this will close up five ways that are
55692 + currently used to insert malicious code into the running kernel.
55693 +
55694 + Even with all these features enabled, we still highly recommend that
55695 + you use the RBAC system, as it is still possible for an attacker to
55696 + modify the running kernel through privileged I/O granted by ioperm/iopl.
55697 +
55698 + If you are not using XFree86, you may be able to stop this additional
55699 + case by enabling the 'Disable privileged I/O' option. Though nothing
55700 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
55701 + but only to video memory, which is the only writing we allow in this
55702 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
55703 + not be allowed to mprotect it with PROT_WRITE later.
55704 + Enabling this feature will prevent the "cpupower" and "powertop" tools
55705 + from working.
55706 +
55707 + It is highly recommended that you say Y here if you meet all the
55708 + conditions above.
55709 +
55710 +config GRKERNSEC_VM86
55711 + bool "Restrict VM86 mode"
55712 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55713 + depends on X86_32
55714 +
55715 + help
55716 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
55717 + make use of a special execution mode on 32bit x86 processors called
55718 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
55719 + video cards and will still work with this option enabled. The purpose
55720 + of the option is to prevent exploitation of emulation errors in
55721 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
55722 + Nearly all users should be able to enable this option.
55723 +
55724 +config GRKERNSEC_IO
55725 + bool "Disable privileged I/O"
55726 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
55727 + depends on X86
55728 + select RTC_CLASS
55729 + select RTC_INTF_DEV
55730 + select RTC_DRV_CMOS
55731 +
55732 + help
55733 + If you say Y here, all ioperm and iopl calls will return an error.
55734 + Ioperm and iopl can be used to modify the running kernel.
55735 + Unfortunately, some programs need this access to operate properly,
55736 + the most notable of which are XFree86 and hwclock. hwclock can be
55737 + remedied by having RTC support in the kernel, so real-time
55738 + clock support is enabled if this option is enabled, to ensure
55739 + that hwclock operates correctly. XFree86 still will not
55740 + operate correctly with this option enabled, so DO NOT CHOOSE Y
55741 + IF YOU USE XFree86. If you use XFree86 and you still want to
55742 + protect your kernel against modification, use the RBAC system.
55743 +
55744 +config GRKERNSEC_JIT_HARDEN
55745 + bool "Harden BPF JIT against spray attacks"
55746 + default y if GRKERNSEC_CONFIG_AUTO
55747 + depends on BPF_JIT
55748 + help
55749 + If you say Y here, the native code generated by the kernel's Berkeley
55750 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
55751 + attacks that attempt to fit attacker-beneficial instructions in
55752 + 32bit immediate fields of JIT-generated native instructions. The
55753 + attacker will generally aim to cause an unintended instruction sequence
55754 + of JIT-generated native code to execute by jumping into the middle of
55755 + a generated instruction. This feature effectively randomizes the 32bit
55756 + immediate constants present in the generated code to thwart such attacks.
55757 +
55758 + If you're using KERNEXEC, it's recommended that you enable this option
55759 + to supplement the hardening of the kernel.
55760 +
55761 +config GRKERNSEC_RAND_THREADSTACK
55762 + bool "Insert random gaps between thread stacks"
55763 + default y if GRKERNSEC_CONFIG_AUTO
55764 + depends on PAX_RANDMMAP && !PPC
55765 + help
55766 + If you say Y here, a random-sized gap will be enforced between allocated
55767 + thread stacks. Glibc's NPTL and other threading libraries that
55768 + pass MAP_STACK to the kernel for thread stack allocation are supported.
55769 + The implementation currently provides 8 bits of entropy for the gap.
55770 +
55771 + Many distributions do not compile threaded remote services with the
55772 + -fstack-check argument to GCC, causing the variable-sized stack-based
55773 + allocator, alloca(), to not probe the stack on allocation. This
55774 + permits an unbounded alloca() to skip over any guard page and potentially
55775 + modify another thread's stack reliably. An enforced random gap
55776 + reduces the reliability of such an attack and increases the chance
55777 + that such a read/write to another thread's stack instead lands in
55778 + an unmapped area, causing a crash and triggering grsecurity's
55779 + anti-bruteforcing logic.
55780 +
55781 +config GRKERNSEC_PROC_MEMMAP
55782 + bool "Harden ASLR against information leaks and entropy reduction"
55783 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
55784 + depends on PAX_NOEXEC || PAX_ASLR
55785 + help
55786 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
55787 + give no information about the addresses of its mappings if
55788 + PaX features that rely on random addresses are enabled on the task.
55789 + In addition to sanitizing this information and disabling other
55790 + dangerous sources of information, this option causes reads of sensitive
55791 + /proc/<pid> entries where the file descriptor was opened in a different
55792 + task than the one performing the read. Such attempts are logged.
55793 + This option also limits argv/env strings for suid/sgid binaries
55794 + to 512KB to prevent a complete exhaustion of the stack entropy provided
55795 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
55796 + binaries to prevent alternative mmap layouts from being abused.
55797 +
55798 + If you use PaX it is essential that you say Y here as it closes up
55799 + several holes that make full ASLR useless locally.
55800 +
55801 +config GRKERNSEC_BRUTE
55802 + bool "Deter exploit bruteforcing"
55803 + default y if GRKERNSEC_CONFIG_AUTO
55804 + help
55805 + If you say Y here, attempts to bruteforce exploits against forking
55806 + daemons such as apache or sshd, as well as against suid/sgid binaries
55807 + will be deterred. When a child of a forking daemon is killed by PaX
55808 + or crashes due to an illegal instruction or other suspicious signal,
55809 + the parent process will be delayed 30 seconds upon every subsequent
55810 + fork until the administrator is able to assess the situation and
55811 + restart the daemon.
55812 + In the suid/sgid case, the attempt is logged, the user has all their
55813 + processes terminated, and they are prevented from executing any further
55814 + processes for 15 minutes.
55815 + It is recommended that you also enable signal logging in the auditing
55816 + section so that logs are generated when a process triggers a suspicious
55817 + signal.
55818 + If the sysctl option is enabled, a sysctl option with name
55819 + "deter_bruteforce" is created.
55820 +
55821 +
55822 +config GRKERNSEC_MODHARDEN
55823 + bool "Harden module auto-loading"
55824 + default y if GRKERNSEC_CONFIG_AUTO
55825 + depends on MODULES
55826 + help
55827 + If you say Y here, module auto-loading in response to use of some
55828 + feature implemented by an unloaded module will be restricted to
55829 + root users. Enabling this option helps defend against attacks
55830 + by unprivileged users who abuse the auto-loading behavior to
55831 + cause a vulnerable module to load that is then exploited.
55832 +
55833 + If this option prevents a legitimate use of auto-loading for a
55834 + non-root user, the administrator can execute modprobe manually
55835 + with the exact name of the module mentioned in the alert log.
55836 + Alternatively, the administrator can add the module to the list
55837 + of modules loaded at boot by modifying init scripts.
55838 +
55839 + Modification of init scripts will most likely be needed on
55840 + Ubuntu servers with encrypted home directory support enabled,
55841 + as the first non-root user logging in will cause the ecb(aes),
55842 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
55843 +
55844 +config GRKERNSEC_HIDESYM
55845 + bool "Hide kernel symbols"
55846 + default y if GRKERNSEC_CONFIG_AUTO
55847 + select PAX_USERCOPY_SLABS
55848 + help
55849 + If you say Y here, getting information on loaded modules, and
55850 + displaying all kernel symbols through a syscall will be restricted
55851 + to users with CAP_SYS_MODULE. For software compatibility reasons,
55852 + /proc/kallsyms will be restricted to the root user. The RBAC
55853 + system can hide that entry even from root.
55854 +
55855 + This option also prevents leaking of kernel addresses through
55856 + several /proc entries.
55857 +
55858 + Note that this option is only effective provided the following
55859 + conditions are met:
55860 + 1) The kernel using grsecurity is not precompiled by some distribution
55861 + 2) You have also enabled GRKERNSEC_DMESG
55862 + 3) You are using the RBAC system and hiding other files such as your
55863 + kernel image and System.map. Alternatively, enabling this option
55864 + causes the permissions on /boot, /lib/modules, and the kernel
55865 + source directory to change at compile time to prevent
55866 + reading by non-root users.
55867 + If the above conditions are met, this option will aid in providing a
55868 + useful protection against local kernel exploitation of overflows
55869 + and arbitrary read/write vulnerabilities.
55870 +
55871 +config GRKERNSEC_KERN_LOCKOUT
55872 + bool "Active kernel exploit response"
55873 + default y if GRKERNSEC_CONFIG_AUTO
55874 + depends on X86 || ARM || PPC || SPARC
55875 + help
55876 + If you say Y here, when a PaX alert is triggered due to suspicious
55877 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
55878 + or an OOPS occurs due to bad memory accesses, instead of just
55879 + terminating the offending process (and potentially allowing
55880 + a subsequent exploit from the same user), we will take one of two
55881 + actions:
55882 + If the user was root, we will panic the system
55883 + If the user was non-root, we will log the attempt, terminate
55884 + all processes owned by the user, then prevent them from creating
55885 + any new processes until the system is restarted
55886 + This deters repeated kernel exploitation/bruteforcing attempts
55887 + and is useful for later forensics.
55888 +
55889 +endmenu
55890 +menu "Role Based Access Control Options"
55891 +depends on GRKERNSEC
55892 +
55893 +config GRKERNSEC_RBAC_DEBUG
55894 + bool
55895 +
55896 +config GRKERNSEC_NO_RBAC
55897 + bool "Disable RBAC system"
55898 + help
55899 + If you say Y here, the /dev/grsec device will be removed from the kernel,
55900 + preventing the RBAC system from being enabled. You should only say Y
55901 + here if you have no intention of using the RBAC system, so as to prevent
55902 + an attacker with root access from misusing the RBAC system to hide files
55903 + and processes when loadable module support and /dev/[k]mem have been
55904 + locked down.
55905 +
55906 +config GRKERNSEC_ACL_HIDEKERN
55907 + bool "Hide kernel processes"
55908 + help
55909 + If you say Y here, all kernel threads will be hidden to all
55910 + processes but those whose subject has the "view hidden processes"
55911 + flag.
55912 +
55913 +config GRKERNSEC_ACL_MAXTRIES
55914 + int "Maximum tries before password lockout"
55915 + default 3
55916 + help
55917 + This option enforces the maximum number of times a user can attempt
55918 + to authorize themselves with the grsecurity RBAC system before being
55919 + denied the ability to attempt authorization again for a specified time.
55920 + The lower the number, the harder it will be to brute-force a password.
55921 +
55922 +config GRKERNSEC_ACL_TIMEOUT
55923 + int "Time to wait after max password tries, in seconds"
55924 + default 30
55925 + help
55926 + This option specifies the time the user must wait after attempting to
55927 + authorize to the RBAC system with the maximum number of invalid
55928 + passwords. The higher the number, the harder it will be to brute-force
55929 + a password.
55930 +
55931 +endmenu
55932 +menu "Filesystem Protections"
55933 +depends on GRKERNSEC
55934 +
55935 +config GRKERNSEC_PROC
55936 + bool "Proc restrictions"
55937 + default y if GRKERNSEC_CONFIG_AUTO
55938 + help
55939 + If you say Y here, the permissions of the /proc filesystem
55940 + will be altered to enhance system security and privacy. You MUST
55941 + choose either a user only restriction or a user and group restriction.
55942 + Depending upon the option you choose, you can either restrict users to
55943 + see only the processes they themselves run, or choose a group that can
55944 + view all processes and files normally restricted to root if you choose
55945 + the "restrict to user only" option. NOTE: If you're running identd or
55946 + ntpd as a non-root user, you will have to run it as the group you
55947 + specify here.
55948 +
55949 +config GRKERNSEC_PROC_USER
55950 + bool "Restrict /proc to user only"
55951 + depends on GRKERNSEC_PROC
55952 + help
55953 + If you say Y here, non-root users will only be able to view their own
55954 + processes, and restricts them from viewing network-related information,
55955 + and viewing kernel symbol and module information.
55956 +
55957 +config GRKERNSEC_PROC_USERGROUP
55958 + bool "Allow special group"
55959 + default y if GRKERNSEC_CONFIG_AUTO
55960 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
55961 + help
55962 + If you say Y here, you will be able to select a group that will be
55963 + able to view all processes and network-related information. If you've
55964 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
55965 + remain hidden. This option is useful if you want to run identd as
55966 + a non-root user. The group you select may also be chosen at boot time
55967 + via "grsec_proc_gid=" on the kernel commandline.
55968 +
55969 +config GRKERNSEC_PROC_GID
55970 + int "GID for special group"
55971 + depends on GRKERNSEC_PROC_USERGROUP
55972 + default 1001
55973 +
55974 +config GRKERNSEC_PROC_ADD
55975 + bool "Additional restrictions"
55976 + default y if GRKERNSEC_CONFIG_AUTO
55977 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
55978 + help
55979 + If you say Y here, additional restrictions will be placed on
55980 + /proc that keep normal users from viewing device information and
55981 + slabinfo information that could be useful for exploits.
55982 +
55983 +config GRKERNSEC_LINK
55984 + bool "Linking restrictions"
55985 + default y if GRKERNSEC_CONFIG_AUTO
55986 + help
55987 + If you say Y here, /tmp race exploits will be prevented, since users
55988 + will no longer be able to follow symlinks owned by other users in
55989 + world-writable +t directories (e.g. /tmp), unless the owner of the
55990 + symlink is the owner of the directory. users will also not be
55991 + able to hardlink to files they do not own. If the sysctl option is
55992 + enabled, a sysctl option with name "linking_restrictions" is created.
55993 +
55994 +config GRKERNSEC_SYMLINKOWN
55995 + bool "Kernel-enforced SymlinksIfOwnerMatch"
55996 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
55997 + help
55998 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
55999 + that prevents it from being used as a security feature. As Apache
56000 + verifies the symlink by performing a stat() against the target of
56001 + the symlink before it is followed, an attacker can setup a symlink
56002 + to point to a same-owned file, then replace the symlink with one
56003 + that targets another user's file just after Apache "validates" the
56004 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
56005 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
56006 + will be in place for the group you specify. If the sysctl option
56007 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
56008 + created.
56009 +
56010 +config GRKERNSEC_SYMLINKOWN_GID
56011 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
56012 + depends on GRKERNSEC_SYMLINKOWN
56013 + default 1006
56014 + help
56015 + Setting this GID determines what group kernel-enforced
56016 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
56017 + is enabled, a sysctl option with name "symlinkown_gid" is created.
56018 +
56019 +config GRKERNSEC_FIFO
56020 + bool "FIFO restrictions"
56021 + default y if GRKERNSEC_CONFIG_AUTO
56022 + help
56023 + If you say Y here, users will not be able to write to FIFOs they don't
56024 + own in world-writable +t directories (e.g. /tmp), unless the owner of
56025 + the FIFO is the same owner of the directory it's held in. If the sysctl
56026 + option is enabled, a sysctl option with name "fifo_restrictions" is
56027 + created.
56028 +
56029 +config GRKERNSEC_SYSFS_RESTRICT
56030 + bool "Sysfs/debugfs restriction"
56031 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
56032 + depends on SYSFS
56033 + help
56034 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
56035 + any filesystem normally mounted under it (e.g. debugfs) will be
56036 + mostly accessible only by root. These filesystems generally provide access
56037 + to hardware and debug information that isn't appropriate for unprivileged
56038 + users of the system. Sysfs and debugfs have also become a large source
56039 + of new vulnerabilities, ranging from infoleaks to local compromise.
56040 + There has been very little oversight with an eye toward security involved
56041 + in adding new exporters of information to these filesystems, so their
56042 + use is discouraged.
56043 + For reasons of compatibility, a few directories have been whitelisted
56044 + for access by non-root users:
56045 + /sys/fs/selinux
56046 + /sys/fs/fuse
56047 + /sys/devices/system/cpu
56048 +
56049 +config GRKERNSEC_ROFS
56050 + bool "Runtime read-only mount protection"
56051 + help
56052 + If you say Y here, a sysctl option with name "romount_protect" will
56053 + be created. By setting this option to 1 at runtime, filesystems
56054 + will be protected in the following ways:
56055 + * No new writable mounts will be allowed
56056 + * Existing read-only mounts won't be able to be remounted read/write
56057 + * Write operations will be denied on all block devices
56058 + This option acts independently of grsec_lock: once it is set to 1,
56059 + it cannot be turned off. Therefore, please be mindful of the resulting
56060 + behavior if this option is enabled in an init script on a read-only
56061 + filesystem. This feature is mainly intended for secure embedded systems.
56062 +
56063 +config GRKERNSEC_DEVICE_SIDECHANNEL
56064 + bool "Eliminate stat/notify-based device sidechannels"
56065 + default y if GRKERNSEC_CONFIG_AUTO
56066 + help
56067 + If you say Y here, timing analyses on block or character
56068 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
56069 + will be thwarted for unprivileged users. If a process without
56070 + CAP_MKNOD stats such a device, the last access and last modify times
56071 + will match the device's create time. No access or modify events
56072 + will be triggered through inotify/dnotify/fanotify for such devices.
56073 + This feature will prevent attacks that may at a minimum
56074 + allow an attacker to determine the administrator's password length.
56075 +
56076 +config GRKERNSEC_CHROOT
56077 + bool "Chroot jail restrictions"
56078 + default y if GRKERNSEC_CONFIG_AUTO
56079 + help
56080 + If you say Y here, you will be able to choose several options that will
56081 + make breaking out of a chrooted jail much more difficult. If you
56082 + encounter no software incompatibilities with the following options, it
56083 + is recommended that you enable each one.
56084 +
56085 +config GRKERNSEC_CHROOT_MOUNT
56086 + bool "Deny mounts"
56087 + default y if GRKERNSEC_CONFIG_AUTO
56088 + depends on GRKERNSEC_CHROOT
56089 + help
56090 + If you say Y here, processes inside a chroot will not be able to
56091 + mount or remount filesystems. If the sysctl option is enabled, a
56092 + sysctl option with name "chroot_deny_mount" is created.
56093 +
56094 +config GRKERNSEC_CHROOT_DOUBLE
56095 + bool "Deny double-chroots"
56096 + default y if GRKERNSEC_CONFIG_AUTO
56097 + depends on GRKERNSEC_CHROOT
56098 + help
56099 + If you say Y here, processes inside a chroot will not be able to chroot
56100 + again outside the chroot. This is a widely used method of breaking
56101 + out of a chroot jail and should not be allowed. If the sysctl
56102 + option is enabled, a sysctl option with name
56103 + "chroot_deny_chroot" is created.
56104 +
56105 +config GRKERNSEC_CHROOT_PIVOT
56106 + bool "Deny pivot_root in chroot"
56107 + default y if GRKERNSEC_CONFIG_AUTO
56108 + depends on GRKERNSEC_CHROOT
56109 + help
56110 + If you say Y here, processes inside a chroot will not be able to use
56111 + a function called pivot_root() that was introduced in Linux 2.3.41. It
56112 + works similar to chroot in that it changes the root filesystem. This
56113 + function could be misused in a chrooted process to attempt to break out
56114 + of the chroot, and therefore should not be allowed. If the sysctl
56115 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
56116 + created.
56117 +
56118 +config GRKERNSEC_CHROOT_CHDIR
56119 + bool "Enforce chdir(\"/\") on all chroots"
56120 + default y if GRKERNSEC_CONFIG_AUTO
56121 + depends on GRKERNSEC_CHROOT
56122 + help
56123 + If you say Y here, the current working directory of all newly-chrooted
56124 + applications will be set to the the root directory of the chroot.
56125 + The man page on chroot(2) states:
56126 + Note that this call does not change the current working
56127 + directory, so that `.' can be outside the tree rooted at
56128 + `/'. In particular, the super-user can escape from a
56129 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
56130 +
56131 + It is recommended that you say Y here, since it's not known to break
56132 + any software. If the sysctl option is enabled, a sysctl option with
56133 + name "chroot_enforce_chdir" is created.
56134 +
56135 +config GRKERNSEC_CHROOT_CHMOD
56136 + bool "Deny (f)chmod +s"
56137 + default y if GRKERNSEC_CONFIG_AUTO
56138 + depends on GRKERNSEC_CHROOT
56139 + help
56140 + If you say Y here, processes inside a chroot will not be able to chmod
56141 + or fchmod files to make them have suid or sgid bits. This protects
56142 + against another published method of breaking a chroot. If the sysctl
56143 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
56144 + created.
56145 +
56146 +config GRKERNSEC_CHROOT_FCHDIR
56147 + bool "Deny fchdir out of chroot"
56148 + default y if GRKERNSEC_CONFIG_AUTO
56149 + depends on GRKERNSEC_CHROOT
56150 + help
56151 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
56152 + to a file descriptor of the chrooting process that points to a directory
56153 + outside the filesystem will be stopped. If the sysctl option
56154 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
56155 +
56156 +config GRKERNSEC_CHROOT_MKNOD
56157 + bool "Deny mknod"
56158 + default y if GRKERNSEC_CONFIG_AUTO
56159 + depends on GRKERNSEC_CHROOT
56160 + help
56161 + If you say Y here, processes inside a chroot will not be allowed to
56162 + mknod. The problem with using mknod inside a chroot is that it
56163 + would allow an attacker to create a device entry that is the same
56164 + as one on the physical root of your system, which could range from
56165 + anything from the console device to a device for your harddrive (which
56166 + they could then use to wipe the drive or steal data). It is recommended
56167 + that you say Y here, unless you run into software incompatibilities.
56168 + If the sysctl option is enabled, a sysctl option with name
56169 + "chroot_deny_mknod" is created.
56170 +
56171 +config GRKERNSEC_CHROOT_SHMAT
56172 + bool "Deny shmat() out of chroot"
56173 + default y if GRKERNSEC_CONFIG_AUTO
56174 + depends on GRKERNSEC_CHROOT
56175 + help
56176 + If you say Y here, processes inside a chroot will not be able to attach
56177 + to shared memory segments that were created outside of the chroot jail.
56178 + It is recommended that you say Y here. If the sysctl option is enabled,
56179 + a sysctl option with name "chroot_deny_shmat" is created.
56180 +
56181 +config GRKERNSEC_CHROOT_UNIX
56182 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
56183 + default y if GRKERNSEC_CONFIG_AUTO
56184 + depends on GRKERNSEC_CHROOT
56185 + help
56186 + If you say Y here, processes inside a chroot will not be able to
56187 + connect to abstract (meaning not belonging to a filesystem) Unix
56188 + domain sockets that were bound outside of a chroot. It is recommended
56189 + that you say Y here. If the sysctl option is enabled, a sysctl option
56190 + with name "chroot_deny_unix" is created.
56191 +
56192 +config GRKERNSEC_CHROOT_FINDTASK
56193 + bool "Protect outside processes"
56194 + default y if GRKERNSEC_CONFIG_AUTO
56195 + depends on GRKERNSEC_CHROOT
56196 + help
56197 + If you say Y here, processes inside a chroot will not be able to
56198 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
56199 + getsid, or view any process outside of the chroot. If the sysctl
56200 + option is enabled, a sysctl option with name "chroot_findtask" is
56201 + created.
56202 +
56203 +config GRKERNSEC_CHROOT_NICE
56204 + bool "Restrict priority changes"
56205 + default y if GRKERNSEC_CONFIG_AUTO
56206 + depends on GRKERNSEC_CHROOT
56207 + help
56208 + If you say Y here, processes inside a chroot will not be able to raise
56209 + the priority of processes in the chroot, or alter the priority of
56210 + processes outside the chroot. This provides more security than simply
56211 + removing CAP_SYS_NICE from the process' capability set. If the
56212 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
56213 + is created.
56214 +
56215 +config GRKERNSEC_CHROOT_SYSCTL
56216 + bool "Deny sysctl writes"
56217 + default y if GRKERNSEC_CONFIG_AUTO
56218 + depends on GRKERNSEC_CHROOT
56219 + help
56220 + If you say Y here, an attacker in a chroot will not be able to
56221 + write to sysctl entries, either by sysctl(2) or through a /proc
56222 + interface. It is strongly recommended that you say Y here. If the
56223 + sysctl option is enabled, a sysctl option with name
56224 + "chroot_deny_sysctl" is created.
56225 +
56226 +config GRKERNSEC_CHROOT_CAPS
56227 + bool "Capability restrictions"
56228 + default y if GRKERNSEC_CONFIG_AUTO
56229 + depends on GRKERNSEC_CHROOT
56230 + help
56231 + If you say Y here, the capabilities on all processes within a
56232 + chroot jail will be lowered to stop module insertion, raw i/o,
56233 + system and net admin tasks, rebooting the system, modifying immutable
56234 + files, modifying IPC owned by another, and changing the system time.
56235 + This is left an option because it can break some apps. Disable this
56236 + if your chrooted apps are having problems performing those kinds of
56237 + tasks. If the sysctl option is enabled, a sysctl option with
56238 + name "chroot_caps" is created.
56239 +
56240 +endmenu
56241 +menu "Kernel Auditing"
56242 +depends on GRKERNSEC
56243 +
56244 +config GRKERNSEC_AUDIT_GROUP
56245 + bool "Single group for auditing"
56246 + help
56247 + If you say Y here, the exec and chdir logging features will only operate
56248 + on a group you specify. This option is recommended if you only want to
56249 + watch certain users instead of having a large amount of logs from the
56250 + entire system. If the sysctl option is enabled, a sysctl option with
56251 + name "audit_group" is created.
56252 +
56253 +config GRKERNSEC_AUDIT_GID
56254 + int "GID for auditing"
56255 + depends on GRKERNSEC_AUDIT_GROUP
56256 + default 1007
56257 +
56258 +config GRKERNSEC_EXECLOG
56259 + bool "Exec logging"
56260 + help
56261 + If you say Y here, all execve() calls will be logged (since the
56262 + other exec*() calls are frontends to execve(), all execution
56263 + will be logged). Useful for shell-servers that like to keep track
56264 + of their users. If the sysctl option is enabled, a sysctl option with
56265 + name "exec_logging" is created.
56266 + WARNING: This option when enabled will produce a LOT of logs, especially
56267 + on an active system.
56268 +
56269 +config GRKERNSEC_RESLOG
56270 + bool "Resource logging"
56271 + default y if GRKERNSEC_CONFIG_AUTO
56272 + help
56273 + If you say Y here, all attempts to overstep resource limits will
56274 + be logged with the resource name, the requested size, and the current
56275 + limit. It is highly recommended that you say Y here. If the sysctl
56276 + option is enabled, a sysctl option with name "resource_logging" is
56277 + created. If the RBAC system is enabled, the sysctl value is ignored.
56278 +
56279 +config GRKERNSEC_CHROOT_EXECLOG
56280 + bool "Log execs within chroot"
56281 + help
56282 + If you say Y here, all executions inside a chroot jail will be logged
56283 + to syslog. This can cause a large amount of logs if certain
56284 + applications (eg. djb's daemontools) are installed on the system, and
56285 + is therefore left as an option. If the sysctl option is enabled, a
56286 + sysctl option with name "chroot_execlog" is created.
56287 +
56288 +config GRKERNSEC_AUDIT_PTRACE
56289 + bool "Ptrace logging"
56290 + help
56291 + If you say Y here, all attempts to attach to a process via ptrace
56292 + will be logged. If the sysctl option is enabled, a sysctl option
56293 + with name "audit_ptrace" is created.
56294 +
56295 +config GRKERNSEC_AUDIT_CHDIR
56296 + bool "Chdir logging"
56297 + help
56298 + If you say Y here, all chdir() calls will be logged. If the sysctl
56299 + option is enabled, a sysctl option with name "audit_chdir" is created.
56300 +
56301 +config GRKERNSEC_AUDIT_MOUNT
56302 + bool "(Un)Mount logging"
56303 + help
56304 + If you say Y here, all mounts and unmounts will be logged. If the
56305 + sysctl option is enabled, a sysctl option with name "audit_mount" is
56306 + created.
56307 +
56308 +config GRKERNSEC_SIGNAL
56309 + bool "Signal logging"
56310 + default y if GRKERNSEC_CONFIG_AUTO
56311 + help
56312 + If you say Y here, certain important signals will be logged, such as
56313 + SIGSEGV, which will as a result inform you of when a error in a program
56314 + occurred, which in some cases could mean a possible exploit attempt.
56315 + If the sysctl option is enabled, a sysctl option with name
56316 + "signal_logging" is created.
56317 +
56318 +config GRKERNSEC_FORKFAIL
56319 + bool "Fork failure logging"
56320 + help
56321 + If you say Y here, all failed fork() attempts will be logged.
56322 + This could suggest a fork bomb, or someone attempting to overstep
56323 + their process limit. If the sysctl option is enabled, a sysctl option
56324 + with name "forkfail_logging" is created.
56325 +
56326 +config GRKERNSEC_TIME
56327 + bool "Time change logging"
56328 + default y if GRKERNSEC_CONFIG_AUTO
56329 + help
56330 + If you say Y here, any changes of the system clock will be logged.
56331 + If the sysctl option is enabled, a sysctl option with name
56332 + "timechange_logging" is created.
56333 +
56334 +config GRKERNSEC_PROC_IPADDR
56335 + bool "/proc/<pid>/ipaddr support"
56336 + default y if GRKERNSEC_CONFIG_AUTO
56337 + help
56338 + If you say Y here, a new entry will be added to each /proc/<pid>
56339 + directory that contains the IP address of the person using the task.
56340 + The IP is carried across local TCP and AF_UNIX stream sockets.
56341 + This information can be useful for IDS/IPSes to perform remote response
56342 + to a local attack. The entry is readable by only the owner of the
56343 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
56344 + the RBAC system), and thus does not create privacy concerns.
56345 +
56346 +config GRKERNSEC_RWXMAP_LOG
56347 + bool 'Denied RWX mmap/mprotect logging'
56348 + default y if GRKERNSEC_CONFIG_AUTO
56349 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
56350 + help
56351 + If you say Y here, calls to mmap() and mprotect() with explicit
56352 + usage of PROT_WRITE and PROT_EXEC together will be logged when
56353 + denied by the PAX_MPROTECT feature. If the sysctl option is
56354 + enabled, a sysctl option with name "rwxmap_logging" is created.
56355 +
56356 +config GRKERNSEC_AUDIT_TEXTREL
56357 + bool 'ELF text relocations logging (READ HELP)'
56358 + depends on PAX_MPROTECT
56359 + help
56360 + If you say Y here, text relocations will be logged with the filename
56361 + of the offending library or binary. The purpose of the feature is
56362 + to help Linux distribution developers get rid of libraries and
56363 + binaries that need text relocations which hinder the future progress
56364 + of PaX. Only Linux distribution developers should say Y here, and
56365 + never on a production machine, as this option creates an information
56366 + leak that could aid an attacker in defeating the randomization of
56367 + a single memory region. If the sysctl option is enabled, a sysctl
56368 + option with name "audit_textrel" is created.
56369 +
56370 +endmenu
56371 +
56372 +menu "Executable Protections"
56373 +depends on GRKERNSEC
56374 +
56375 +config GRKERNSEC_DMESG
56376 + bool "Dmesg(8) restriction"
56377 + default y if GRKERNSEC_CONFIG_AUTO
56378 + help
56379 + If you say Y here, non-root users will not be able to use dmesg(8)
56380 + to view the contents of the kernel's circular log buffer.
56381 + The kernel's log buffer often contains kernel addresses and other
56382 + identifying information useful to an attacker in fingerprinting a
56383 + system for a targeted exploit.
56384 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
56385 + created.
56386 +
56387 +config GRKERNSEC_HARDEN_PTRACE
56388 + bool "Deter ptrace-based process snooping"
56389 + default y if GRKERNSEC_CONFIG_AUTO
56390 + help
56391 + If you say Y here, TTY sniffers and other malicious monitoring
56392 + programs implemented through ptrace will be defeated. If you
56393 + have been using the RBAC system, this option has already been
56394 + enabled for several years for all users, with the ability to make
56395 + fine-grained exceptions.
56396 +
56397 + This option only affects the ability of non-root users to ptrace
56398 + processes that are not a descendent of the ptracing process.
56399 + This means that strace ./binary and gdb ./binary will still work,
56400 + but attaching to arbitrary processes will not. If the sysctl
56401 + option is enabled, a sysctl option with name "harden_ptrace" is
56402 + created.
56403 +
56404 +config GRKERNSEC_PTRACE_READEXEC
56405 + bool "Require read access to ptrace sensitive binaries"
56406 + default y if GRKERNSEC_CONFIG_AUTO
56407 + help
56408 + If you say Y here, unprivileged users will not be able to ptrace unreadable
56409 + binaries. This option is useful in environments that
56410 + remove the read bits (e.g. file mode 4711) from suid binaries to
56411 + prevent infoleaking of their contents. This option adds
56412 + consistency to the use of that file mode, as the binary could normally
56413 + be read out when run without privileges while ptracing.
56414 +
56415 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
56416 + is created.
56417 +
56418 +config GRKERNSEC_SETXID
56419 + bool "Enforce consistent multithreaded privileges"
56420 + default y if GRKERNSEC_CONFIG_AUTO
56421 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
56422 + help
56423 + If you say Y here, a change from a root uid to a non-root uid
56424 + in a multithreaded application will cause the resulting uids,
56425 + gids, supplementary groups, and capabilities in that thread
56426 + to be propagated to the other threads of the process. In most
56427 + cases this is unnecessary, as glibc will emulate this behavior
56428 + on behalf of the application. Other libcs do not act in the
56429 + same way, allowing the other threads of the process to continue
56430 + running with root privileges. If the sysctl option is enabled,
56431 + a sysctl option with name "consistent_setxid" is created.
56432 +
56433 +config GRKERNSEC_TPE
56434 + bool "Trusted Path Execution (TPE)"
56435 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
56436 + help
56437 + If you say Y here, you will be able to choose a gid to add to the
56438 + supplementary groups of users you want to mark as "untrusted."
56439 + These users will not be able to execute any files that are not in
56440 + root-owned directories writable only by root. If the sysctl option
56441 + is enabled, a sysctl option with name "tpe" is created.
56442 +
56443 +config GRKERNSEC_TPE_ALL
56444 + bool "Partially restrict all non-root users"
56445 + depends on GRKERNSEC_TPE
56446 + help
56447 + If you say Y here, all non-root users will be covered under
56448 + a weaker TPE restriction. This is separate from, and in addition to,
56449 + the main TPE options that you have selected elsewhere. Thus, if a
56450 + "trusted" GID is chosen, this restriction applies to even that GID.
56451 + Under this restriction, all non-root users will only be allowed to
56452 + execute files in directories they own that are not group or
56453 + world-writable, or in directories owned by root and writable only by
56454 + root. If the sysctl option is enabled, a sysctl option with name
56455 + "tpe_restrict_all" is created.
56456 +
56457 +config GRKERNSEC_TPE_INVERT
56458 + bool "Invert GID option"
56459 + depends on GRKERNSEC_TPE
56460 + help
56461 + If you say Y here, the group you specify in the TPE configuration will
56462 + decide what group TPE restrictions will be *disabled* for. This
56463 + option is useful if you want TPE restrictions to be applied to most
56464 + users on the system. If the sysctl option is enabled, a sysctl option
56465 + with name "tpe_invert" is created. Unlike other sysctl options, this
56466 + entry will default to on for backward-compatibility.
56467 +
56468 +config GRKERNSEC_TPE_GID
56469 + int
56470 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
56471 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
56472 +
56473 +config GRKERNSEC_TPE_UNTRUSTED_GID
56474 + int "GID for TPE-untrusted users"
56475 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
56476 + default 1005
56477 + help
56478 + Setting this GID determines what group TPE restrictions will be
56479 + *enabled* for. If the sysctl option is enabled, a sysctl option
56480 + with name "tpe_gid" is created.
56481 +
56482 +config GRKERNSEC_TPE_TRUSTED_GID
56483 + int "GID for TPE-trusted users"
56484 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
56485 + default 1005
56486 + help
56487 + Setting this GID determines what group TPE restrictions will be
56488 + *disabled* for. If the sysctl option is enabled, a sysctl option
56489 + with name "tpe_gid" is created.
56490 +
56491 +endmenu
56492 +menu "Network Protections"
56493 +depends on GRKERNSEC
56494 +
56495 +config GRKERNSEC_RANDNET
56496 + bool "Larger entropy pools"
56497 + default y if GRKERNSEC_CONFIG_AUTO
56498 + help
56499 + If you say Y here, the entropy pools used for many features of Linux
56500 + and grsecurity will be doubled in size. Since several grsecurity
56501 + features use additional randomness, it is recommended that you say Y
56502 + here. Saying Y here has a similar effect as modifying
56503 + /proc/sys/kernel/random/poolsize.
56504 +
56505 +config GRKERNSEC_BLACKHOLE
56506 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
56507 + default y if GRKERNSEC_CONFIG_AUTO
56508 + depends on NET
56509 + help
56510 + If you say Y here, neither TCP resets nor ICMP
56511 + destination-unreachable packets will be sent in response to packets
56512 + sent to ports for which no associated listening process exists.
56513 + This feature supports both IPV4 and IPV6 and exempts the
56514 + loopback interface from blackholing. Enabling this feature
56515 + makes a host more resilient to DoS attacks and reduces network
56516 + visibility against scanners.
56517 +
56518 + The blackhole feature as-implemented is equivalent to the FreeBSD
56519 + blackhole feature, as it prevents RST responses to all packets, not
56520 + just SYNs. Under most application behavior this causes no
56521 + problems, but applications (like haproxy) may not close certain
56522 + connections in a way that cleanly terminates them on the remote
56523 + end, leaving the remote host in LAST_ACK state. Because of this
56524 + side-effect and to prevent intentional LAST_ACK DoSes, this
56525 + feature also adds automatic mitigation against such attacks.
56526 + The mitigation drastically reduces the amount of time a socket
56527 + can spend in LAST_ACK state. If you're using haproxy and not
56528 + all servers it connects to have this option enabled, consider
56529 + disabling this feature on the haproxy host.
56530 +
56531 + If the sysctl option is enabled, two sysctl options with names
56532 + "ip_blackhole" and "lastack_retries" will be created.
56533 + While "ip_blackhole" takes the standard zero/non-zero on/off
56534 + toggle, "lastack_retries" uses the same kinds of values as
56535 + "tcp_retries1" and "tcp_retries2". The default value of 4
56536 + prevents a socket from lasting more than 45 seconds in LAST_ACK
56537 + state.
56538 +
56539 +config GRKERNSEC_NO_SIMULT_CONNECT
56540 + bool "Disable TCP Simultaneous Connect"
56541 + default y if GRKERNSEC_CONFIG_AUTO
56542 + depends on NET
56543 + help
56544 + If you say Y here, a feature by Willy Tarreau will be enabled that
56545 + removes a weakness in Linux's strict implementation of TCP that
56546 + allows two clients to connect to each other without either entering
56547 + a listening state. The weakness allows an attacker to easily prevent
56548 + a client from connecting to a known server provided the source port
56549 + for the connection is guessed correctly.
56550 +
56551 + As the weakness could be used to prevent an antivirus or IPS from
56552 + fetching updates, or prevent an SSL gateway from fetching a CRL,
56553 + it should be eliminated by enabling this option. Though Linux is
56554 + one of few operating systems supporting simultaneous connect, it
56555 + has no legitimate use in practice and is rarely supported by firewalls.
56556 +
56557 +config GRKERNSEC_SOCKET
56558 + bool "Socket restrictions"
56559 + depends on NET
56560 + help
56561 + If you say Y here, you will be able to choose from several options.
56562 + If you assign a GID on your system and add it to the supplementary
56563 + groups of users you want to restrict socket access to, this patch
56564 + will perform up to three things, based on the option(s) you choose.
56565 +
56566 +config GRKERNSEC_SOCKET_ALL
56567 + bool "Deny any sockets to group"
56568 + depends on GRKERNSEC_SOCKET
56569 + help
56570 + If you say Y here, you will be able to choose a GID of whose users will
56571 + be unable to connect to other hosts from your machine or run server
56572 + applications from your machine. If the sysctl option is enabled, a
56573 + sysctl option with name "socket_all" is created.
56574 +
56575 +config GRKERNSEC_SOCKET_ALL_GID
56576 + int "GID to deny all sockets for"
56577 + depends on GRKERNSEC_SOCKET_ALL
56578 + default 1004
56579 + help
56580 + Here you can choose the GID to disable socket access for. Remember to
56581 + add the users you want socket access disabled for to the GID
56582 + specified here. If the sysctl option is enabled, a sysctl option
56583 + with name "socket_all_gid" is created.
56584 +
56585 +config GRKERNSEC_SOCKET_CLIENT
56586 + bool "Deny client sockets to group"
56587 + depends on GRKERNSEC_SOCKET
56588 + help
56589 + If you say Y here, you will be able to choose a GID of whose users will
56590 + be unable to connect to other hosts from your machine, but will be
56591 + able to run servers. If this option is enabled, all users in the group
56592 + you specify will have to use passive mode when initiating ftp transfers
56593 + from the shell on your machine. If the sysctl option is enabled, a
56594 + sysctl option with name "socket_client" is created.
56595 +
56596 +config GRKERNSEC_SOCKET_CLIENT_GID
56597 + int "GID to deny client sockets for"
56598 + depends on GRKERNSEC_SOCKET_CLIENT
56599 + default 1003
56600 + help
56601 + Here you can choose the GID to disable client socket access for.
56602 + Remember to add the users you want client socket access disabled for to
56603 + the GID specified here. If the sysctl option is enabled, a sysctl
56604 + option with name "socket_client_gid" is created.
56605 +
56606 +config GRKERNSEC_SOCKET_SERVER
56607 + bool "Deny server sockets to group"
56608 + depends on GRKERNSEC_SOCKET
56609 + help
56610 + If you say Y here, you will be able to choose a GID of whose users will
56611 + be unable to run server applications from your machine. If the sysctl
56612 + option is enabled, a sysctl option with name "socket_server" is created.
56613 +
56614 +config GRKERNSEC_SOCKET_SERVER_GID
56615 + int "GID to deny server sockets for"
56616 + depends on GRKERNSEC_SOCKET_SERVER
56617 + default 1002
56618 + help
56619 + Here you can choose the GID to disable server socket access for.
56620 + Remember to add the users you want server socket access disabled for to
56621 + the GID specified here. If the sysctl option is enabled, a sysctl
56622 + option with name "socket_server_gid" is created.
56623 +
56624 +endmenu
56625 +menu "Sysctl Support"
56626 +depends on GRKERNSEC && SYSCTL
56627 +
56628 +config GRKERNSEC_SYSCTL
56629 + bool "Sysctl support"
56630 + default y if GRKERNSEC_CONFIG_AUTO
56631 + help
56632 + If you say Y here, you will be able to change the options that
56633 + grsecurity runs with at bootup, without having to recompile your
56634 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
56635 + to enable (1) or disable (0) various features. All the sysctl entries
56636 + are mutable until the "grsec_lock" entry is set to a non-zero value.
56637 + All features enabled in the kernel configuration are disabled at boot
56638 + if you do not say Y to the "Turn on features by default" option.
56639 + All options should be set at startup, and the grsec_lock entry should
56640 + be set to a non-zero value after all the options are set.
56641 + *THIS IS EXTREMELY IMPORTANT*
56642 +
56643 +config GRKERNSEC_SYSCTL_DISTRO
56644 + bool "Extra sysctl support for distro makers (READ HELP)"
56645 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
56646 + help
56647 + If you say Y here, additional sysctl options will be created
56648 + for features that affect processes running as root. Therefore,
56649 + it is critical when using this option that the grsec_lock entry be
56650 + enabled after boot. Only distros with prebuilt kernel packages
56651 + with this option enabled that can ensure grsec_lock is enabled
56652 + after boot should use this option.
56653 + *Failure to set grsec_lock after boot makes all grsec features
56654 + this option covers useless*
56655 +
56656 + Currently this option creates the following sysctl entries:
56657 + "Disable Privileged I/O": "disable_priv_io"
56658 +
56659 +config GRKERNSEC_SYSCTL_ON
56660 + bool "Turn on features by default"
56661 + default y if GRKERNSEC_CONFIG_AUTO
56662 + depends on GRKERNSEC_SYSCTL
56663 + help
56664 + If you say Y here, instead of having all features enabled in the
56665 + kernel configuration disabled at boot time, the features will be
56666 + enabled at boot time. It is recommended you say Y here unless
56667 + there is some reason you would want all sysctl-tunable features to
56668 + be disabled by default. As mentioned elsewhere, it is important
56669 + to enable the grsec_lock entry once you have finished modifying
56670 + the sysctl entries.
56671 +
56672 +endmenu
56673 +menu "Logging Options"
56674 +depends on GRKERNSEC
56675 +
56676 +config GRKERNSEC_FLOODTIME
56677 + int "Seconds in between log messages (minimum)"
56678 + default 10
56679 + help
56680 + This option allows you to enforce the number of seconds between
56681 + grsecurity log messages. The default should be suitable for most
56682 + people, however, if you choose to change it, choose a value small enough
56683 + to allow informative logs to be produced, but large enough to
56684 + prevent flooding.
56685 +
56686 +config GRKERNSEC_FLOODBURST
56687 + int "Number of messages in a burst (maximum)"
56688 + default 6
56689 + help
56690 + This option allows you to choose the maximum number of messages allowed
56691 + within the flood time interval you chose in a separate option. The
56692 + default should be suitable for most people, however if you find that
56693 + many of your logs are being interpreted as flooding, you may want to
56694 + raise this value.
56695 +
56696 +endmenu
56697 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
56698 new file mode 100644
56699 index 0000000..1b9afa9
56700 --- /dev/null
56701 +++ b/grsecurity/Makefile
56702 @@ -0,0 +1,38 @@
56703 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
56704 +# during 2001-2009 it has been completely redesigned by Brad Spengler
56705 +# into an RBAC system
56706 +#
56707 +# All code in this directory and various hooks inserted throughout the kernel
56708 +# are copyright Brad Spengler - Open Source Security, Inc., and released
56709 +# under the GPL v2 or higher
56710 +
56711 +KBUILD_CFLAGS += -Werror
56712 +
56713 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
56714 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
56715 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
56716 +
56717 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
56718 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
56719 + gracl_learn.o grsec_log.o
56720 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
56721 +
56722 +ifdef CONFIG_NET
56723 +obj-y += grsec_sock.o
56724 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
56725 +endif
56726 +
56727 +ifndef CONFIG_GRKERNSEC
56728 +obj-y += grsec_disabled.o
56729 +endif
56730 +
56731 +ifdef CONFIG_GRKERNSEC_HIDESYM
56732 +extra-y := grsec_hidesym.o
56733 +$(obj)/grsec_hidesym.o:
56734 + @-chmod -f 500 /boot
56735 + @-chmod -f 500 /lib/modules
56736 + @-chmod -f 500 /lib64/modules
56737 + @-chmod -f 500 /lib32/modules
56738 + @-chmod -f 700 .
56739 + @echo ' grsec: protected kernel image paths'
56740 +endif
56741 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
56742 new file mode 100644
56743 index 0000000..0767b2e
56744 --- /dev/null
56745 +++ b/grsecurity/gracl.c
56746 @@ -0,0 +1,4067 @@
56747 +#include <linux/kernel.h>
56748 +#include <linux/module.h>
56749 +#include <linux/sched.h>
56750 +#include <linux/mm.h>
56751 +#include <linux/file.h>
56752 +#include <linux/fs.h>
56753 +#include <linux/namei.h>
56754 +#include <linux/mount.h>
56755 +#include <linux/tty.h>
56756 +#include <linux/proc_fs.h>
56757 +#include <linux/lglock.h>
56758 +#include <linux/slab.h>
56759 +#include <linux/vmalloc.h>
56760 +#include <linux/types.h>
56761 +#include <linux/sysctl.h>
56762 +#include <linux/netdevice.h>
56763 +#include <linux/ptrace.h>
56764 +#include <linux/gracl.h>
56765 +#include <linux/gralloc.h>
56766 +#include <linux/security.h>
56767 +#include <linux/grinternal.h>
56768 +#include <linux/pid_namespace.h>
56769 +#include <linux/stop_machine.h>
56770 +#include <linux/fdtable.h>
56771 +#include <linux/percpu.h>
56772 +#include <linux/lglock.h>
56773 +#include <linux/hugetlb.h>
56774 +#include "../fs/mount.h"
56775 +
56776 +#include <asm/uaccess.h>
56777 +#include <asm/errno.h>
56778 +#include <asm/mman.h>
56779 +
56780 +extern struct lglock vfsmount_lock;
56781 +
56782 +static struct acl_role_db acl_role_set;
56783 +static struct name_db name_set;
56784 +static struct inodev_db inodev_set;
56785 +
56786 +/* for keeping track of userspace pointers used for subjects, so we
56787 + can share references in the kernel as well
56788 +*/
56789 +
56790 +static struct path real_root;
56791 +
56792 +static struct acl_subj_map_db subj_map_set;
56793 +
56794 +static struct acl_role_label *default_role;
56795 +
56796 +static struct acl_role_label *role_list;
56797 +
56798 +static u16 acl_sp_role_value;
56799 +
56800 +extern char *gr_shared_page[4];
56801 +static DEFINE_MUTEX(gr_dev_mutex);
56802 +DEFINE_RWLOCK(gr_inode_lock);
56803 +
56804 +struct gr_arg *gr_usermode;
56805 +
56806 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
56807 +
56808 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
56809 +extern void gr_clear_learn_entries(void);
56810 +
56811 +unsigned char *gr_system_salt;
56812 +unsigned char *gr_system_sum;
56813 +
56814 +static struct sprole_pw **acl_special_roles = NULL;
56815 +static __u16 num_sprole_pws = 0;
56816 +
56817 +static struct acl_role_label *kernel_role = NULL;
56818 +
56819 +static unsigned int gr_auth_attempts = 0;
56820 +static unsigned long gr_auth_expires = 0UL;
56821 +
56822 +#ifdef CONFIG_NET
56823 +extern struct vfsmount *sock_mnt;
56824 +#endif
56825 +
56826 +extern struct vfsmount *pipe_mnt;
56827 +extern struct vfsmount *shm_mnt;
56828 +
56829 +#ifdef CONFIG_HUGETLBFS
56830 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
56831 +#endif
56832 +
56833 +static struct acl_object_label *fakefs_obj_rw;
56834 +static struct acl_object_label *fakefs_obj_rwx;
56835 +
56836 +extern int gr_init_uidset(void);
56837 +extern void gr_free_uidset(void);
56838 +extern void gr_remove_uid(uid_t uid);
56839 +extern int gr_find_uid(uid_t uid);
56840 +
56841 +__inline__ int
56842 +gr_acl_is_enabled(void)
56843 +{
56844 + return (gr_status & GR_READY);
56845 +}
56846 +
56847 +#ifdef CONFIG_BTRFS_FS
56848 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
56849 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
56850 +#endif
56851 +
56852 +static inline dev_t __get_dev(const struct dentry *dentry)
56853 +{
56854 +#ifdef CONFIG_BTRFS_FS
56855 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
56856 + return get_btrfs_dev_from_inode(dentry->d_inode);
56857 + else
56858 +#endif
56859 + return dentry->d_inode->i_sb->s_dev;
56860 +}
56861 +
56862 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
56863 +{
56864 + return __get_dev(dentry);
56865 +}
56866 +
56867 +static char gr_task_roletype_to_char(struct task_struct *task)
56868 +{
56869 + switch (task->role->roletype &
56870 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
56871 + GR_ROLE_SPECIAL)) {
56872 + case GR_ROLE_DEFAULT:
56873 + return 'D';
56874 + case GR_ROLE_USER:
56875 + return 'U';
56876 + case GR_ROLE_GROUP:
56877 + return 'G';
56878 + case GR_ROLE_SPECIAL:
56879 + return 'S';
56880 + }
56881 +
56882 + return 'X';
56883 +}
56884 +
56885 +char gr_roletype_to_char(void)
56886 +{
56887 + return gr_task_roletype_to_char(current);
56888 +}
56889 +
56890 +__inline__ int
56891 +gr_acl_tpe_check(void)
56892 +{
56893 + if (unlikely(!(gr_status & GR_READY)))
56894 + return 0;
56895 + if (current->role->roletype & GR_ROLE_TPE)
56896 + return 1;
56897 + else
56898 + return 0;
56899 +}
56900 +
56901 +int
56902 +gr_handle_rawio(const struct inode *inode)
56903 +{
56904 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
56905 + if (inode && S_ISBLK(inode->i_mode) &&
56906 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
56907 + !capable(CAP_SYS_RAWIO))
56908 + return 1;
56909 +#endif
56910 + return 0;
56911 +}
56912 +
56913 +static int
56914 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
56915 +{
56916 + if (likely(lena != lenb))
56917 + return 0;
56918 +
56919 + return !memcmp(a, b, lena);
56920 +}
56921 +
56922 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
56923 +{
56924 + *buflen -= namelen;
56925 + if (*buflen < 0)
56926 + return -ENAMETOOLONG;
56927 + *buffer -= namelen;
56928 + memcpy(*buffer, str, namelen);
56929 + return 0;
56930 +}
56931 +
56932 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
56933 +{
56934 + return prepend(buffer, buflen, name->name, name->len);
56935 +}
56936 +
56937 +static int prepend_path(const struct path *path, struct path *root,
56938 + char **buffer, int *buflen)
56939 +{
56940 + struct dentry *dentry = path->dentry;
56941 + struct vfsmount *vfsmnt = path->mnt;
56942 + struct mount *mnt = real_mount(vfsmnt);
56943 + bool slash = false;
56944 + int error = 0;
56945 +
56946 + while (dentry != root->dentry || vfsmnt != root->mnt) {
56947 + struct dentry * parent;
56948 +
56949 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
56950 + /* Global root? */
56951 + if (!mnt_has_parent(mnt)) {
56952 + goto out;
56953 + }
56954 + dentry = mnt->mnt_mountpoint;
56955 + mnt = mnt->mnt_parent;
56956 + vfsmnt = &mnt->mnt;
56957 + continue;
56958 + }
56959 + parent = dentry->d_parent;
56960 + prefetch(parent);
56961 + spin_lock(&dentry->d_lock);
56962 + error = prepend_name(buffer, buflen, &dentry->d_name);
56963 + spin_unlock(&dentry->d_lock);
56964 + if (!error)
56965 + error = prepend(buffer, buflen, "/", 1);
56966 + if (error)
56967 + break;
56968 +
56969 + slash = true;
56970 + dentry = parent;
56971 + }
56972 +
56973 +out:
56974 + if (!error && !slash)
56975 + error = prepend(buffer, buflen, "/", 1);
56976 +
56977 + return error;
56978 +}
56979 +
56980 +/* this must be called with vfsmount_lock and rename_lock held */
56981 +
56982 +static char *__our_d_path(const struct path *path, struct path *root,
56983 + char *buf, int buflen)
56984 +{
56985 + char *res = buf + buflen;
56986 + int error;
56987 +
56988 + prepend(&res, &buflen, "\0", 1);
56989 + error = prepend_path(path, root, &res, &buflen);
56990 + if (error)
56991 + return ERR_PTR(error);
56992 +
56993 + return res;
56994 +}
56995 +
56996 +static char *
56997 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
56998 +{
56999 + char *retval;
57000 +
57001 + retval = __our_d_path(path, root, buf, buflen);
57002 + if (unlikely(IS_ERR(retval)))
57003 + retval = strcpy(buf, "<path too long>");
57004 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
57005 + retval[1] = '\0';
57006 +
57007 + return retval;
57008 +}
57009 +
57010 +static char *
57011 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57012 + char *buf, int buflen)
57013 +{
57014 + struct path path;
57015 + char *res;
57016 +
57017 + path.dentry = (struct dentry *)dentry;
57018 + path.mnt = (struct vfsmount *)vfsmnt;
57019 +
57020 + /* we can use real_root.dentry, real_root.mnt, because this is only called
57021 + by the RBAC system */
57022 + res = gen_full_path(&path, &real_root, buf, buflen);
57023 +
57024 + return res;
57025 +}
57026 +
57027 +static char *
57028 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
57029 + char *buf, int buflen)
57030 +{
57031 + char *res;
57032 + struct path path;
57033 + struct path root;
57034 + struct task_struct *reaper = init_pid_ns.child_reaper;
57035 +
57036 + path.dentry = (struct dentry *)dentry;
57037 + path.mnt = (struct vfsmount *)vfsmnt;
57038 +
57039 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
57040 + get_fs_root(reaper->fs, &root);
57041 +
57042 + write_seqlock(&rename_lock);
57043 + br_read_lock(&vfsmount_lock);
57044 + res = gen_full_path(&path, &root, buf, buflen);
57045 + br_read_unlock(&vfsmount_lock);
57046 + write_sequnlock(&rename_lock);
57047 +
57048 + path_put(&root);
57049 + return res;
57050 +}
57051 +
57052 +static char *
57053 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57054 +{
57055 + char *ret;
57056 + write_seqlock(&rename_lock);
57057 + br_read_lock(&vfsmount_lock);
57058 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57059 + PAGE_SIZE);
57060 + br_read_unlock(&vfsmount_lock);
57061 + write_sequnlock(&rename_lock);
57062 + return ret;
57063 +}
57064 +
57065 +static char *
57066 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
57067 +{
57068 + char *ret;
57069 + char *buf;
57070 + int buflen;
57071 +
57072 + write_seqlock(&rename_lock);
57073 + br_read_lock(&vfsmount_lock);
57074 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
57075 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
57076 + buflen = (int)(ret - buf);
57077 + if (buflen >= 5)
57078 + prepend(&ret, &buflen, "/proc", 5);
57079 + else
57080 + ret = strcpy(buf, "<path too long>");
57081 + br_read_unlock(&vfsmount_lock);
57082 + write_sequnlock(&rename_lock);
57083 + return ret;
57084 +}
57085 +
57086 +char *
57087 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
57088 +{
57089 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
57090 + PAGE_SIZE);
57091 +}
57092 +
57093 +char *
57094 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
57095 +{
57096 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
57097 + PAGE_SIZE);
57098 +}
57099 +
57100 +char *
57101 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
57102 +{
57103 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
57104 + PAGE_SIZE);
57105 +}
57106 +
57107 +char *
57108 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
57109 +{
57110 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
57111 + PAGE_SIZE);
57112 +}
57113 +
57114 +char *
57115 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
57116 +{
57117 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
57118 + PAGE_SIZE);
57119 +}
57120 +
57121 +__inline__ __u32
57122 +to_gr_audit(const __u32 reqmode)
57123 +{
57124 + /* masks off auditable permission flags, then shifts them to create
57125 + auditing flags, and adds the special case of append auditing if
57126 + we're requesting write */
57127 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
57128 +}
57129 +
57130 +struct acl_subject_label *
57131 +lookup_subject_map(const struct acl_subject_label *userp)
57132 +{
57133 + unsigned int index = gr_shash(userp, subj_map_set.s_size);
57134 + struct subject_map *match;
57135 +
57136 + match = subj_map_set.s_hash[index];
57137 +
57138 + while (match && match->user != userp)
57139 + match = match->next;
57140 +
57141 + if (match != NULL)
57142 + return match->kernel;
57143 + else
57144 + return NULL;
57145 +}
57146 +
57147 +static void
57148 +insert_subj_map_entry(struct subject_map *subjmap)
57149 +{
57150 + unsigned int index = gr_shash(subjmap->user, subj_map_set.s_size);
57151 + struct subject_map **curr;
57152 +
57153 + subjmap->prev = NULL;
57154 +
57155 + curr = &subj_map_set.s_hash[index];
57156 + if (*curr != NULL)
57157 + (*curr)->prev = subjmap;
57158 +
57159 + subjmap->next = *curr;
57160 + *curr = subjmap;
57161 +
57162 + return;
57163 +}
57164 +
57165 +static struct acl_role_label *
57166 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
57167 + const gid_t gid)
57168 +{
57169 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
57170 + struct acl_role_label *match;
57171 + struct role_allowed_ip *ipp;
57172 + unsigned int x;
57173 + u32 curr_ip = task->signal->curr_ip;
57174 +
57175 + task->signal->saved_ip = curr_ip;
57176 +
57177 + match = acl_role_set.r_hash[index];
57178 +
57179 + while (match) {
57180 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
57181 + for (x = 0; x < match->domain_child_num; x++) {
57182 + if (match->domain_children[x] == uid)
57183 + goto found;
57184 + }
57185 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
57186 + break;
57187 + match = match->next;
57188 + }
57189 +found:
57190 + if (match == NULL) {
57191 + try_group:
57192 + index = gr_rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
57193 + match = acl_role_set.r_hash[index];
57194 +
57195 + while (match) {
57196 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
57197 + for (x = 0; x < match->domain_child_num; x++) {
57198 + if (match->domain_children[x] == gid)
57199 + goto found2;
57200 + }
57201 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
57202 + break;
57203 + match = match->next;
57204 + }
57205 +found2:
57206 + if (match == NULL)
57207 + match = default_role;
57208 + if (match->allowed_ips == NULL)
57209 + return match;
57210 + else {
57211 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57212 + if (likely
57213 + ((ntohl(curr_ip) & ipp->netmask) ==
57214 + (ntohl(ipp->addr) & ipp->netmask)))
57215 + return match;
57216 + }
57217 + match = default_role;
57218 + }
57219 + } else if (match->allowed_ips == NULL) {
57220 + return match;
57221 + } else {
57222 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
57223 + if (likely
57224 + ((ntohl(curr_ip) & ipp->netmask) ==
57225 + (ntohl(ipp->addr) & ipp->netmask)))
57226 + return match;
57227 + }
57228 + goto try_group;
57229 + }
57230 +
57231 + return match;
57232 +}
57233 +
57234 +struct acl_subject_label *
57235 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
57236 + const struct acl_role_label *role)
57237 +{
57238 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57239 + struct acl_subject_label *match;
57240 +
57241 + match = role->subj_hash[index];
57242 +
57243 + while (match && (match->inode != ino || match->device != dev ||
57244 + (match->mode & GR_DELETED))) {
57245 + match = match->next;
57246 + }
57247 +
57248 + if (match && !(match->mode & GR_DELETED))
57249 + return match;
57250 + else
57251 + return NULL;
57252 +}
57253 +
57254 +struct acl_subject_label *
57255 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
57256 + const struct acl_role_label *role)
57257 +{
57258 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
57259 + struct acl_subject_label *match;
57260 +
57261 + match = role->subj_hash[index];
57262 +
57263 + while (match && (match->inode != ino || match->device != dev ||
57264 + !(match->mode & GR_DELETED))) {
57265 + match = match->next;
57266 + }
57267 +
57268 + if (match && (match->mode & GR_DELETED))
57269 + return match;
57270 + else
57271 + return NULL;
57272 +}
57273 +
57274 +static struct acl_object_label *
57275 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
57276 + const struct acl_subject_label *subj)
57277 +{
57278 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57279 + struct acl_object_label *match;
57280 +
57281 + match = subj->obj_hash[index];
57282 +
57283 + while (match && (match->inode != ino || match->device != dev ||
57284 + (match->mode & GR_DELETED))) {
57285 + match = match->next;
57286 + }
57287 +
57288 + if (match && !(match->mode & GR_DELETED))
57289 + return match;
57290 + else
57291 + return NULL;
57292 +}
57293 +
57294 +static struct acl_object_label *
57295 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
57296 + const struct acl_subject_label *subj)
57297 +{
57298 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
57299 + struct acl_object_label *match;
57300 +
57301 + match = subj->obj_hash[index];
57302 +
57303 + while (match && (match->inode != ino || match->device != dev ||
57304 + !(match->mode & GR_DELETED))) {
57305 + match = match->next;
57306 + }
57307 +
57308 + if (match && (match->mode & GR_DELETED))
57309 + return match;
57310 +
57311 + match = subj->obj_hash[index];
57312 +
57313 + while (match && (match->inode != ino || match->device != dev ||
57314 + (match->mode & GR_DELETED))) {
57315 + match = match->next;
57316 + }
57317 +
57318 + if (match && !(match->mode & GR_DELETED))
57319 + return match;
57320 + else
57321 + return NULL;
57322 +}
57323 +
57324 +static struct name_entry *
57325 +lookup_name_entry(const char *name)
57326 +{
57327 + unsigned int len = strlen(name);
57328 + unsigned int key = full_name_hash(name, len);
57329 + unsigned int index = key % name_set.n_size;
57330 + struct name_entry *match;
57331 +
57332 + match = name_set.n_hash[index];
57333 +
57334 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
57335 + match = match->next;
57336 +
57337 + return match;
57338 +}
57339 +
57340 +static struct name_entry *
57341 +lookup_name_entry_create(const char *name)
57342 +{
57343 + unsigned int len = strlen(name);
57344 + unsigned int key = full_name_hash(name, len);
57345 + unsigned int index = key % name_set.n_size;
57346 + struct name_entry *match;
57347 +
57348 + match = name_set.n_hash[index];
57349 +
57350 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57351 + !match->deleted))
57352 + match = match->next;
57353 +
57354 + if (match && match->deleted)
57355 + return match;
57356 +
57357 + match = name_set.n_hash[index];
57358 +
57359 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
57360 + match->deleted))
57361 + match = match->next;
57362 +
57363 + if (match && !match->deleted)
57364 + return match;
57365 + else
57366 + return NULL;
57367 +}
57368 +
57369 +static struct inodev_entry *
57370 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
57371 +{
57372 + unsigned int index = gr_fhash(ino, dev, inodev_set.i_size);
57373 + struct inodev_entry *match;
57374 +
57375 + match = inodev_set.i_hash[index];
57376 +
57377 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
57378 + match = match->next;
57379 +
57380 + return match;
57381 +}
57382 +
57383 +static void
57384 +insert_inodev_entry(struct inodev_entry *entry)
57385 +{
57386 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
57387 + inodev_set.i_size);
57388 + struct inodev_entry **curr;
57389 +
57390 + entry->prev = NULL;
57391 +
57392 + curr = &inodev_set.i_hash[index];
57393 + if (*curr != NULL)
57394 + (*curr)->prev = entry;
57395 +
57396 + entry->next = *curr;
57397 + *curr = entry;
57398 +
57399 + return;
57400 +}
57401 +
57402 +static void
57403 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
57404 +{
57405 + unsigned int index =
57406 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
57407 + struct acl_role_label **curr;
57408 + struct acl_role_label *tmp, *tmp2;
57409 +
57410 + curr = &acl_role_set.r_hash[index];
57411 +
57412 + /* simple case, slot is empty, just set it to our role */
57413 + if (*curr == NULL) {
57414 + *curr = role;
57415 + } else {
57416 + /* example:
57417 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
57418 + 2 -> 3
57419 + */
57420 + /* first check to see if we can already be reached via this slot */
57421 + tmp = *curr;
57422 + while (tmp && tmp != role)
57423 + tmp = tmp->next;
57424 + if (tmp == role) {
57425 + /* we don't need to add ourselves to this slot's chain */
57426 + return;
57427 + }
57428 + /* we need to add ourselves to this chain, two cases */
57429 + if (role->next == NULL) {
57430 + /* simple case, append the current chain to our role */
57431 + role->next = *curr;
57432 + *curr = role;
57433 + } else {
57434 + /* 1 -> 2 -> 3 -> 4
57435 + 2 -> 3 -> 4
57436 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
57437 + */
57438 + /* trickier case: walk our role's chain until we find
57439 + the role for the start of the current slot's chain */
57440 + tmp = role;
57441 + tmp2 = *curr;
57442 + while (tmp->next && tmp->next != tmp2)
57443 + tmp = tmp->next;
57444 + if (tmp->next == tmp2) {
57445 + /* from example above, we found 3, so just
57446 + replace this slot's chain with ours */
57447 + *curr = role;
57448 + } else {
57449 + /* we didn't find a subset of our role's chain
57450 + in the current slot's chain, so append their
57451 + chain to ours, and set us as the first role in
57452 + the slot's chain
57453 +
57454 + we could fold this case with the case above,
57455 + but making it explicit for clarity
57456 + */
57457 + tmp->next = tmp2;
57458 + *curr = role;
57459 + }
57460 + }
57461 + }
57462 +
57463 + return;
57464 +}
57465 +
57466 +static void
57467 +insert_acl_role_label(struct acl_role_label *role)
57468 +{
57469 + int i;
57470 +
57471 + if (role_list == NULL) {
57472 + role_list = role;
57473 + role->prev = NULL;
57474 + } else {
57475 + role->prev = role_list;
57476 + role_list = role;
57477 + }
57478 +
57479 + /* used for hash chains */
57480 + role->next = NULL;
57481 +
57482 + if (role->roletype & GR_ROLE_DOMAIN) {
57483 + for (i = 0; i < role->domain_child_num; i++)
57484 + __insert_acl_role_label(role, role->domain_children[i]);
57485 + } else
57486 + __insert_acl_role_label(role, role->uidgid);
57487 +}
57488 +
57489 +static int
57490 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
57491 +{
57492 + struct name_entry **curr, *nentry;
57493 + struct inodev_entry *ientry;
57494 + unsigned int len = strlen(name);
57495 + unsigned int key = full_name_hash(name, len);
57496 + unsigned int index = key % name_set.n_size;
57497 +
57498 + curr = &name_set.n_hash[index];
57499 +
57500 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
57501 + curr = &((*curr)->next);
57502 +
57503 + if (*curr != NULL)
57504 + return 1;
57505 +
57506 + nentry = acl_alloc(sizeof (struct name_entry));
57507 + if (nentry == NULL)
57508 + return 0;
57509 + ientry = acl_alloc(sizeof (struct inodev_entry));
57510 + if (ientry == NULL)
57511 + return 0;
57512 + ientry->nentry = nentry;
57513 +
57514 + nentry->key = key;
57515 + nentry->name = name;
57516 + nentry->inode = inode;
57517 + nentry->device = device;
57518 + nentry->len = len;
57519 + nentry->deleted = deleted;
57520 +
57521 + nentry->prev = NULL;
57522 + curr = &name_set.n_hash[index];
57523 + if (*curr != NULL)
57524 + (*curr)->prev = nentry;
57525 + nentry->next = *curr;
57526 + *curr = nentry;
57527 +
57528 + /* insert us into the table searchable by inode/dev */
57529 + insert_inodev_entry(ientry);
57530 +
57531 + return 1;
57532 +}
57533 +
57534 +static void
57535 +insert_acl_obj_label(struct acl_object_label *obj,
57536 + struct acl_subject_label *subj)
57537 +{
57538 + unsigned int index =
57539 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
57540 + struct acl_object_label **curr;
57541 +
57542 +
57543 + obj->prev = NULL;
57544 +
57545 + curr = &subj->obj_hash[index];
57546 + if (*curr != NULL)
57547 + (*curr)->prev = obj;
57548 +
57549 + obj->next = *curr;
57550 + *curr = obj;
57551 +
57552 + return;
57553 +}
57554 +
57555 +static void
57556 +insert_acl_subj_label(struct acl_subject_label *obj,
57557 + struct acl_role_label *role)
57558 +{
57559 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
57560 + struct acl_subject_label **curr;
57561 +
57562 + obj->prev = NULL;
57563 +
57564 + curr = &role->subj_hash[index];
57565 + if (*curr != NULL)
57566 + (*curr)->prev = obj;
57567 +
57568 + obj->next = *curr;
57569 + *curr = obj;
57570 +
57571 + return;
57572 +}
57573 +
57574 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
57575 +
57576 +static void *
57577 +create_table(__u32 * len, int elementsize)
57578 +{
57579 + unsigned int table_sizes[] = {
57580 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
57581 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
57582 + 4194301, 8388593, 16777213, 33554393, 67108859
57583 + };
57584 + void *newtable = NULL;
57585 + unsigned int pwr = 0;
57586 +
57587 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
57588 + table_sizes[pwr] <= *len)
57589 + pwr++;
57590 +
57591 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
57592 + return newtable;
57593 +
57594 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
57595 + newtable =
57596 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
57597 + else
57598 + newtable = vmalloc(table_sizes[pwr] * elementsize);
57599 +
57600 + *len = table_sizes[pwr];
57601 +
57602 + return newtable;
57603 +}
57604 +
57605 +static int
57606 +init_variables(const struct gr_arg *arg)
57607 +{
57608 + struct task_struct *reaper = init_pid_ns.child_reaper;
57609 + unsigned int stacksize;
57610 +
57611 + subj_map_set.s_size = arg->role_db.num_subjects;
57612 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
57613 + name_set.n_size = arg->role_db.num_objects;
57614 + inodev_set.i_size = arg->role_db.num_objects;
57615 +
57616 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
57617 + !name_set.n_size || !inodev_set.i_size)
57618 + return 1;
57619 +
57620 + if (!gr_init_uidset())
57621 + return 1;
57622 +
57623 + /* set up the stack that holds allocation info */
57624 +
57625 + stacksize = arg->role_db.num_pointers + 5;
57626 +
57627 + if (!acl_alloc_stack_init(stacksize))
57628 + return 1;
57629 +
57630 + /* grab reference for the real root dentry and vfsmount */
57631 + get_fs_root(reaper->fs, &real_root);
57632 +
57633 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
57634 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
57635 +#endif
57636 +
57637 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
57638 + if (fakefs_obj_rw == NULL)
57639 + return 1;
57640 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
57641 +
57642 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
57643 + if (fakefs_obj_rwx == NULL)
57644 + return 1;
57645 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
57646 +
57647 + subj_map_set.s_hash =
57648 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
57649 + acl_role_set.r_hash =
57650 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
57651 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
57652 + inodev_set.i_hash =
57653 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
57654 +
57655 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
57656 + !name_set.n_hash || !inodev_set.i_hash)
57657 + return 1;
57658 +
57659 + memset(subj_map_set.s_hash, 0,
57660 + sizeof(struct subject_map *) * subj_map_set.s_size);
57661 + memset(acl_role_set.r_hash, 0,
57662 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
57663 + memset(name_set.n_hash, 0,
57664 + sizeof (struct name_entry *) * name_set.n_size);
57665 + memset(inodev_set.i_hash, 0,
57666 + sizeof (struct inodev_entry *) * inodev_set.i_size);
57667 +
57668 + return 0;
57669 +}
57670 +
57671 +/* free information not needed after startup
57672 + currently contains user->kernel pointer mappings for subjects
57673 +*/
57674 +
57675 +static void
57676 +free_init_variables(void)
57677 +{
57678 + __u32 i;
57679 +
57680 + if (subj_map_set.s_hash) {
57681 + for (i = 0; i < subj_map_set.s_size; i++) {
57682 + if (subj_map_set.s_hash[i]) {
57683 + kfree(subj_map_set.s_hash[i]);
57684 + subj_map_set.s_hash[i] = NULL;
57685 + }
57686 + }
57687 +
57688 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
57689 + PAGE_SIZE)
57690 + kfree(subj_map_set.s_hash);
57691 + else
57692 + vfree(subj_map_set.s_hash);
57693 + }
57694 +
57695 + return;
57696 +}
57697 +
57698 +static void
57699 +free_variables(void)
57700 +{
57701 + struct acl_subject_label *s;
57702 + struct acl_role_label *r;
57703 + struct task_struct *task, *task2;
57704 + unsigned int x;
57705 +
57706 + gr_clear_learn_entries();
57707 +
57708 + read_lock(&tasklist_lock);
57709 + do_each_thread(task2, task) {
57710 + task->acl_sp_role = 0;
57711 + task->acl_role_id = 0;
57712 + task->acl = NULL;
57713 + task->role = NULL;
57714 + } while_each_thread(task2, task);
57715 + read_unlock(&tasklist_lock);
57716 +
57717 + /* release the reference to the real root dentry and vfsmount */
57718 + path_put(&real_root);
57719 + memset(&real_root, 0, sizeof(real_root));
57720 +
57721 + /* free all object hash tables */
57722 +
57723 + FOR_EACH_ROLE_START(r)
57724 + if (r->subj_hash == NULL)
57725 + goto next_role;
57726 + FOR_EACH_SUBJECT_START(r, s, x)
57727 + if (s->obj_hash == NULL)
57728 + break;
57729 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
57730 + kfree(s->obj_hash);
57731 + else
57732 + vfree(s->obj_hash);
57733 + FOR_EACH_SUBJECT_END(s, x)
57734 + FOR_EACH_NESTED_SUBJECT_START(r, s)
57735 + if (s->obj_hash == NULL)
57736 + break;
57737 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
57738 + kfree(s->obj_hash);
57739 + else
57740 + vfree(s->obj_hash);
57741 + FOR_EACH_NESTED_SUBJECT_END(s)
57742 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
57743 + kfree(r->subj_hash);
57744 + else
57745 + vfree(r->subj_hash);
57746 + r->subj_hash = NULL;
57747 +next_role:
57748 + FOR_EACH_ROLE_END(r)
57749 +
57750 + acl_free_all();
57751 +
57752 + if (acl_role_set.r_hash) {
57753 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
57754 + PAGE_SIZE)
57755 + kfree(acl_role_set.r_hash);
57756 + else
57757 + vfree(acl_role_set.r_hash);
57758 + }
57759 + if (name_set.n_hash) {
57760 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
57761 + PAGE_SIZE)
57762 + kfree(name_set.n_hash);
57763 + else
57764 + vfree(name_set.n_hash);
57765 + }
57766 +
57767 + if (inodev_set.i_hash) {
57768 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
57769 + PAGE_SIZE)
57770 + kfree(inodev_set.i_hash);
57771 + else
57772 + vfree(inodev_set.i_hash);
57773 + }
57774 +
57775 + gr_free_uidset();
57776 +
57777 + memset(&name_set, 0, sizeof (struct name_db));
57778 + memset(&inodev_set, 0, sizeof (struct inodev_db));
57779 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
57780 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
57781 +
57782 + default_role = NULL;
57783 + kernel_role = NULL;
57784 + role_list = NULL;
57785 +
57786 + return;
57787 +}
57788 +
57789 +static __u32
57790 +count_user_objs(struct acl_object_label *userp)
57791 +{
57792 + struct acl_object_label o_tmp;
57793 + __u32 num = 0;
57794 +
57795 + while (userp) {
57796 + if (copy_from_user(&o_tmp, userp,
57797 + sizeof (struct acl_object_label)))
57798 + break;
57799 +
57800 + userp = o_tmp.prev;
57801 + num++;
57802 + }
57803 +
57804 + return num;
57805 +}
57806 +
57807 +static struct acl_subject_label *
57808 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
57809 +
57810 +static int
57811 +copy_user_glob(struct acl_object_label *obj)
57812 +{
57813 + struct acl_object_label *g_tmp, **guser;
57814 + unsigned int len;
57815 + char *tmp;
57816 +
57817 + if (obj->globbed == NULL)
57818 + return 0;
57819 +
57820 + guser = &obj->globbed;
57821 + while (*guser) {
57822 + g_tmp = (struct acl_object_label *)
57823 + acl_alloc(sizeof (struct acl_object_label));
57824 + if (g_tmp == NULL)
57825 + return -ENOMEM;
57826 +
57827 + if (copy_from_user(g_tmp, *guser,
57828 + sizeof (struct acl_object_label)))
57829 + return -EFAULT;
57830 +
57831 + len = strnlen_user(g_tmp->filename, PATH_MAX);
57832 +
57833 + if (!len || len >= PATH_MAX)
57834 + return -EINVAL;
57835 +
57836 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57837 + return -ENOMEM;
57838 +
57839 + if (copy_from_user(tmp, g_tmp->filename, len))
57840 + return -EFAULT;
57841 + tmp[len-1] = '\0';
57842 + g_tmp->filename = tmp;
57843 +
57844 + *guser = g_tmp;
57845 + guser = &(g_tmp->next);
57846 + }
57847 +
57848 + return 0;
57849 +}
57850 +
57851 +static int
57852 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
57853 + struct acl_role_label *role)
57854 +{
57855 + struct acl_object_label *o_tmp;
57856 + unsigned int len;
57857 + int ret;
57858 + char *tmp;
57859 +
57860 + while (userp) {
57861 + if ((o_tmp = (struct acl_object_label *)
57862 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
57863 + return -ENOMEM;
57864 +
57865 + if (copy_from_user(o_tmp, userp,
57866 + sizeof (struct acl_object_label)))
57867 + return -EFAULT;
57868 +
57869 + userp = o_tmp->prev;
57870 +
57871 + len = strnlen_user(o_tmp->filename, PATH_MAX);
57872 +
57873 + if (!len || len >= PATH_MAX)
57874 + return -EINVAL;
57875 +
57876 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57877 + return -ENOMEM;
57878 +
57879 + if (copy_from_user(tmp, o_tmp->filename, len))
57880 + return -EFAULT;
57881 + tmp[len-1] = '\0';
57882 + o_tmp->filename = tmp;
57883 +
57884 + insert_acl_obj_label(o_tmp, subj);
57885 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
57886 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
57887 + return -ENOMEM;
57888 +
57889 + ret = copy_user_glob(o_tmp);
57890 + if (ret)
57891 + return ret;
57892 +
57893 + if (o_tmp->nested) {
57894 + int already_copied;
57895 +
57896 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
57897 + if (IS_ERR(o_tmp->nested))
57898 + return PTR_ERR(o_tmp->nested);
57899 +
57900 + /* insert into nested subject list if we haven't copied this one yet
57901 + to prevent duplicate entries */
57902 + if (!already_copied) {
57903 + o_tmp->nested->next = role->hash->first;
57904 + role->hash->first = o_tmp->nested;
57905 + }
57906 + }
57907 + }
57908 +
57909 + return 0;
57910 +}
57911 +
57912 +static __u32
57913 +count_user_subjs(struct acl_subject_label *userp)
57914 +{
57915 + struct acl_subject_label s_tmp;
57916 + __u32 num = 0;
57917 +
57918 + while (userp) {
57919 + if (copy_from_user(&s_tmp, userp,
57920 + sizeof (struct acl_subject_label)))
57921 + break;
57922 +
57923 + userp = s_tmp.prev;
57924 + }
57925 +
57926 + return num;
57927 +}
57928 +
57929 +static int
57930 +copy_user_allowedips(struct acl_role_label *rolep)
57931 +{
57932 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
57933 +
57934 + ruserip = rolep->allowed_ips;
57935 +
57936 + while (ruserip) {
57937 + rlast = rtmp;
57938 +
57939 + if ((rtmp = (struct role_allowed_ip *)
57940 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
57941 + return -ENOMEM;
57942 +
57943 + if (copy_from_user(rtmp, ruserip,
57944 + sizeof (struct role_allowed_ip)))
57945 + return -EFAULT;
57946 +
57947 + ruserip = rtmp->prev;
57948 +
57949 + if (!rlast) {
57950 + rtmp->prev = NULL;
57951 + rolep->allowed_ips = rtmp;
57952 + } else {
57953 + rlast->next = rtmp;
57954 + rtmp->prev = rlast;
57955 + }
57956 +
57957 + if (!ruserip)
57958 + rtmp->next = NULL;
57959 + }
57960 +
57961 + return 0;
57962 +}
57963 +
57964 +static int
57965 +copy_user_transitions(struct acl_role_label *rolep)
57966 +{
57967 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
57968 +
57969 + unsigned int len;
57970 + char *tmp;
57971 +
57972 + rusertp = rolep->transitions;
57973 +
57974 + while (rusertp) {
57975 + rlast = rtmp;
57976 +
57977 + if ((rtmp = (struct role_transition *)
57978 + acl_alloc(sizeof (struct role_transition))) == NULL)
57979 + return -ENOMEM;
57980 +
57981 + if (copy_from_user(rtmp, rusertp,
57982 + sizeof (struct role_transition)))
57983 + return -EFAULT;
57984 +
57985 + rusertp = rtmp->prev;
57986 +
57987 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
57988 +
57989 + if (!len || len >= GR_SPROLE_LEN)
57990 + return -EINVAL;
57991 +
57992 + if ((tmp = (char *) acl_alloc(len)) == NULL)
57993 + return -ENOMEM;
57994 +
57995 + if (copy_from_user(tmp, rtmp->rolename, len))
57996 + return -EFAULT;
57997 + tmp[len-1] = '\0';
57998 + rtmp->rolename = tmp;
57999 +
58000 + if (!rlast) {
58001 + rtmp->prev = NULL;
58002 + rolep->transitions = rtmp;
58003 + } else {
58004 + rlast->next = rtmp;
58005 + rtmp->prev = rlast;
58006 + }
58007 +
58008 + if (!rusertp)
58009 + rtmp->next = NULL;
58010 + }
58011 +
58012 + return 0;
58013 +}
58014 +
58015 +static struct acl_subject_label *
58016 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
58017 +{
58018 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
58019 + unsigned int len;
58020 + char *tmp;
58021 + __u32 num_objs;
58022 + struct acl_ip_label **i_tmp, *i_utmp2;
58023 + struct gr_hash_struct ghash;
58024 + struct subject_map *subjmap;
58025 + unsigned int i_num;
58026 + int err;
58027 +
58028 + if (already_copied != NULL)
58029 + *already_copied = 0;
58030 +
58031 + s_tmp = lookup_subject_map(userp);
58032 +
58033 + /* we've already copied this subject into the kernel, just return
58034 + the reference to it, and don't copy it over again
58035 + */
58036 + if (s_tmp) {
58037 + if (already_copied != NULL)
58038 + *already_copied = 1;
58039 + return(s_tmp);
58040 + }
58041 +
58042 + if ((s_tmp = (struct acl_subject_label *)
58043 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
58044 + return ERR_PTR(-ENOMEM);
58045 +
58046 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
58047 + if (subjmap == NULL)
58048 + return ERR_PTR(-ENOMEM);
58049 +
58050 + subjmap->user = userp;
58051 + subjmap->kernel = s_tmp;
58052 + insert_subj_map_entry(subjmap);
58053 +
58054 + if (copy_from_user(s_tmp, userp,
58055 + sizeof (struct acl_subject_label)))
58056 + return ERR_PTR(-EFAULT);
58057 +
58058 + len = strnlen_user(s_tmp->filename, PATH_MAX);
58059 +
58060 + if (!len || len >= PATH_MAX)
58061 + return ERR_PTR(-EINVAL);
58062 +
58063 + if ((tmp = (char *) acl_alloc(len)) == NULL)
58064 + return ERR_PTR(-ENOMEM);
58065 +
58066 + if (copy_from_user(tmp, s_tmp->filename, len))
58067 + return ERR_PTR(-EFAULT);
58068 + tmp[len-1] = '\0';
58069 + s_tmp->filename = tmp;
58070 +
58071 + if (!strcmp(s_tmp->filename, "/"))
58072 + role->root_label = s_tmp;
58073 +
58074 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
58075 + return ERR_PTR(-EFAULT);
58076 +
58077 + /* copy user and group transition tables */
58078 +
58079 + if (s_tmp->user_trans_num) {
58080 + uid_t *uidlist;
58081 +
58082 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
58083 + if (uidlist == NULL)
58084 + return ERR_PTR(-ENOMEM);
58085 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
58086 + return ERR_PTR(-EFAULT);
58087 +
58088 + s_tmp->user_transitions = uidlist;
58089 + }
58090 +
58091 + if (s_tmp->group_trans_num) {
58092 + gid_t *gidlist;
58093 +
58094 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
58095 + if (gidlist == NULL)
58096 + return ERR_PTR(-ENOMEM);
58097 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
58098 + return ERR_PTR(-EFAULT);
58099 +
58100 + s_tmp->group_transitions = gidlist;
58101 + }
58102 +
58103 + /* set up object hash table */
58104 + num_objs = count_user_objs(ghash.first);
58105 +
58106 + s_tmp->obj_hash_size = num_objs;
58107 + s_tmp->obj_hash =
58108 + (struct acl_object_label **)
58109 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
58110 +
58111 + if (!s_tmp->obj_hash)
58112 + return ERR_PTR(-ENOMEM);
58113 +
58114 + memset(s_tmp->obj_hash, 0,
58115 + s_tmp->obj_hash_size *
58116 + sizeof (struct acl_object_label *));
58117 +
58118 + /* add in objects */
58119 + err = copy_user_objs(ghash.first, s_tmp, role);
58120 +
58121 + if (err)
58122 + return ERR_PTR(err);
58123 +
58124 + /* set pointer for parent subject */
58125 + if (s_tmp->parent_subject) {
58126 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
58127 +
58128 + if (IS_ERR(s_tmp2))
58129 + return s_tmp2;
58130 +
58131 + s_tmp->parent_subject = s_tmp2;
58132 + }
58133 +
58134 + /* add in ip acls */
58135 +
58136 + if (!s_tmp->ip_num) {
58137 + s_tmp->ips = NULL;
58138 + goto insert;
58139 + }
58140 +
58141 + i_tmp =
58142 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
58143 + sizeof (struct acl_ip_label *));
58144 +
58145 + if (!i_tmp)
58146 + return ERR_PTR(-ENOMEM);
58147 +
58148 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
58149 + *(i_tmp + i_num) =
58150 + (struct acl_ip_label *)
58151 + acl_alloc(sizeof (struct acl_ip_label));
58152 + if (!*(i_tmp + i_num))
58153 + return ERR_PTR(-ENOMEM);
58154 +
58155 + if (copy_from_user
58156 + (&i_utmp2, s_tmp->ips + i_num,
58157 + sizeof (struct acl_ip_label *)))
58158 + return ERR_PTR(-EFAULT);
58159 +
58160 + if (copy_from_user
58161 + (*(i_tmp + i_num), i_utmp2,
58162 + sizeof (struct acl_ip_label)))
58163 + return ERR_PTR(-EFAULT);
58164 +
58165 + if ((*(i_tmp + i_num))->iface == NULL)
58166 + continue;
58167 +
58168 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
58169 + if (!len || len >= IFNAMSIZ)
58170 + return ERR_PTR(-EINVAL);
58171 + tmp = acl_alloc(len);
58172 + if (tmp == NULL)
58173 + return ERR_PTR(-ENOMEM);
58174 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
58175 + return ERR_PTR(-EFAULT);
58176 + (*(i_tmp + i_num))->iface = tmp;
58177 + }
58178 +
58179 + s_tmp->ips = i_tmp;
58180 +
58181 +insert:
58182 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
58183 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
58184 + return ERR_PTR(-ENOMEM);
58185 +
58186 + return s_tmp;
58187 +}
58188 +
58189 +static int
58190 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
58191 +{
58192 + struct acl_subject_label s_pre;
58193 + struct acl_subject_label * ret;
58194 + int err;
58195 +
58196 + while (userp) {
58197 + if (copy_from_user(&s_pre, userp,
58198 + sizeof (struct acl_subject_label)))
58199 + return -EFAULT;
58200 +
58201 + ret = do_copy_user_subj(userp, role, NULL);
58202 +
58203 + err = PTR_ERR(ret);
58204 + if (IS_ERR(ret))
58205 + return err;
58206 +
58207 + insert_acl_subj_label(ret, role);
58208 +
58209 + userp = s_pre.prev;
58210 + }
58211 +
58212 + return 0;
58213 +}
58214 +
58215 +static int
58216 +copy_user_acl(struct gr_arg *arg)
58217 +{
58218 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
58219 + struct acl_subject_label *subj_list;
58220 + struct sprole_pw *sptmp;
58221 + struct gr_hash_struct *ghash;
58222 + uid_t *domainlist;
58223 + unsigned int r_num;
58224 + unsigned int len;
58225 + char *tmp;
58226 + int err = 0;
58227 + __u16 i;
58228 + __u32 num_subjs;
58229 +
58230 + /* we need a default and kernel role */
58231 + if (arg->role_db.num_roles < 2)
58232 + return -EINVAL;
58233 +
58234 + /* copy special role authentication info from userspace */
58235 +
58236 + num_sprole_pws = arg->num_sprole_pws;
58237 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
58238 +
58239 + if (!acl_special_roles && num_sprole_pws)
58240 + return -ENOMEM;
58241 +
58242 + for (i = 0; i < num_sprole_pws; i++) {
58243 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
58244 + if (!sptmp)
58245 + return -ENOMEM;
58246 + if (copy_from_user(sptmp, arg->sprole_pws + i,
58247 + sizeof (struct sprole_pw)))
58248 + return -EFAULT;
58249 +
58250 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
58251 +
58252 + if (!len || len >= GR_SPROLE_LEN)
58253 + return -EINVAL;
58254 +
58255 + if ((tmp = (char *) acl_alloc(len)) == NULL)
58256 + return -ENOMEM;
58257 +
58258 + if (copy_from_user(tmp, sptmp->rolename, len))
58259 + return -EFAULT;
58260 +
58261 + tmp[len-1] = '\0';
58262 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
58263 + printk(KERN_ALERT "Copying special role %s\n", tmp);
58264 +#endif
58265 + sptmp->rolename = tmp;
58266 + acl_special_roles[i] = sptmp;
58267 + }
58268 +
58269 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
58270 +
58271 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
58272 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
58273 +
58274 + if (!r_tmp)
58275 + return -ENOMEM;
58276 +
58277 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
58278 + sizeof (struct acl_role_label *)))
58279 + return -EFAULT;
58280 +
58281 + if (copy_from_user(r_tmp, r_utmp2,
58282 + sizeof (struct acl_role_label)))
58283 + return -EFAULT;
58284 +
58285 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
58286 +
58287 + if (!len || len >= PATH_MAX)
58288 + return -EINVAL;
58289 +
58290 + if ((tmp = (char *) acl_alloc(len)) == NULL)
58291 + return -ENOMEM;
58292 +
58293 + if (copy_from_user(tmp, r_tmp->rolename, len))
58294 + return -EFAULT;
58295 +
58296 + tmp[len-1] = '\0';
58297 + r_tmp->rolename = tmp;
58298 +
58299 + if (!strcmp(r_tmp->rolename, "default")
58300 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
58301 + default_role = r_tmp;
58302 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
58303 + kernel_role = r_tmp;
58304 + }
58305 +
58306 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
58307 + return -ENOMEM;
58308 +
58309 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
58310 + return -EFAULT;
58311 +
58312 + r_tmp->hash = ghash;
58313 +
58314 + num_subjs = count_user_subjs(r_tmp->hash->first);
58315 +
58316 + r_tmp->subj_hash_size = num_subjs;
58317 + r_tmp->subj_hash =
58318 + (struct acl_subject_label **)
58319 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
58320 +
58321 + if (!r_tmp->subj_hash)
58322 + return -ENOMEM;
58323 +
58324 + err = copy_user_allowedips(r_tmp);
58325 + if (err)
58326 + return err;
58327 +
58328 + /* copy domain info */
58329 + if (r_tmp->domain_children != NULL) {
58330 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
58331 + if (domainlist == NULL)
58332 + return -ENOMEM;
58333 +
58334 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
58335 + return -EFAULT;
58336 +
58337 + r_tmp->domain_children = domainlist;
58338 + }
58339 +
58340 + err = copy_user_transitions(r_tmp);
58341 + if (err)
58342 + return err;
58343 +
58344 + memset(r_tmp->subj_hash, 0,
58345 + r_tmp->subj_hash_size *
58346 + sizeof (struct acl_subject_label *));
58347 +
58348 + /* acquire the list of subjects, then NULL out
58349 + the list prior to parsing the subjects for this role,
58350 + as during this parsing the list is replaced with a list
58351 + of *nested* subjects for the role
58352 + */
58353 + subj_list = r_tmp->hash->first;
58354 +
58355 + /* set nested subject list to null */
58356 + r_tmp->hash->first = NULL;
58357 +
58358 + err = copy_user_subjs(subj_list, r_tmp);
58359 +
58360 + if (err)
58361 + return err;
58362 +
58363 + insert_acl_role_label(r_tmp);
58364 + }
58365 +
58366 + if (default_role == NULL || kernel_role == NULL)
58367 + return -EINVAL;
58368 +
58369 + return err;
58370 +}
58371 +
58372 +static int
58373 +gracl_init(struct gr_arg *args)
58374 +{
58375 + int error = 0;
58376 +
58377 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
58378 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
58379 +
58380 + if (init_variables(args)) {
58381 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
58382 + error = -ENOMEM;
58383 + free_variables();
58384 + goto out;
58385 + }
58386 +
58387 + error = copy_user_acl(args);
58388 + free_init_variables();
58389 + if (error) {
58390 + free_variables();
58391 + goto out;
58392 + }
58393 +
58394 + if ((error = gr_set_acls(0))) {
58395 + free_variables();
58396 + goto out;
58397 + }
58398 +
58399 + pax_open_kernel();
58400 + gr_status |= GR_READY;
58401 + pax_close_kernel();
58402 +
58403 + out:
58404 + return error;
58405 +}
58406 +
58407 +/* derived from glibc fnmatch() 0: match, 1: no match*/
58408 +
58409 +static int
58410 +glob_match(const char *p, const char *n)
58411 +{
58412 + char c;
58413 +
58414 + while ((c = *p++) != '\0') {
58415 + switch (c) {
58416 + case '?':
58417 + if (*n == '\0')
58418 + return 1;
58419 + else if (*n == '/')
58420 + return 1;
58421 + break;
58422 + case '\\':
58423 + if (*n != c)
58424 + return 1;
58425 + break;
58426 + case '*':
58427 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
58428 + if (*n == '/')
58429 + return 1;
58430 + else if (c == '?') {
58431 + if (*n == '\0')
58432 + return 1;
58433 + else
58434 + ++n;
58435 + }
58436 + }
58437 + if (c == '\0') {
58438 + return 0;
58439 + } else {
58440 + const char *endp;
58441 +
58442 + if ((endp = strchr(n, '/')) == NULL)
58443 + endp = n + strlen(n);
58444 +
58445 + if (c == '[') {
58446 + for (--p; n < endp; ++n)
58447 + if (!glob_match(p, n))
58448 + return 0;
58449 + } else if (c == '/') {
58450 + while (*n != '\0' && *n != '/')
58451 + ++n;
58452 + if (*n == '/' && !glob_match(p, n + 1))
58453 + return 0;
58454 + } else {
58455 + for (--p; n < endp; ++n)
58456 + if (*n == c && !glob_match(p, n))
58457 + return 0;
58458 + }
58459 +
58460 + return 1;
58461 + }
58462 + case '[':
58463 + {
58464 + int not;
58465 + char cold;
58466 +
58467 + if (*n == '\0' || *n == '/')
58468 + return 1;
58469 +
58470 + not = (*p == '!' || *p == '^');
58471 + if (not)
58472 + ++p;
58473 +
58474 + c = *p++;
58475 + for (;;) {
58476 + unsigned char fn = (unsigned char)*n;
58477 +
58478 + if (c == '\0')
58479 + return 1;
58480 + else {
58481 + if (c == fn)
58482 + goto matched;
58483 + cold = c;
58484 + c = *p++;
58485 +
58486 + if (c == '-' && *p != ']') {
58487 + unsigned char cend = *p++;
58488 +
58489 + if (cend == '\0')
58490 + return 1;
58491 +
58492 + if (cold <= fn && fn <= cend)
58493 + goto matched;
58494 +
58495 + c = *p++;
58496 + }
58497 + }
58498 +
58499 + if (c == ']')
58500 + break;
58501 + }
58502 + if (!not)
58503 + return 1;
58504 + break;
58505 + matched:
58506 + while (c != ']') {
58507 + if (c == '\0')
58508 + return 1;
58509 +
58510 + c = *p++;
58511 + }
58512 + if (not)
58513 + return 1;
58514 + }
58515 + break;
58516 + default:
58517 + if (c != *n)
58518 + return 1;
58519 + }
58520 +
58521 + ++n;
58522 + }
58523 +
58524 + if (*n == '\0')
58525 + return 0;
58526 +
58527 + if (*n == '/')
58528 + return 0;
58529 +
58530 + return 1;
58531 +}
58532 +
58533 +static struct acl_object_label *
58534 +chk_glob_label(struct acl_object_label *globbed,
58535 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
58536 +{
58537 + struct acl_object_label *tmp;
58538 +
58539 + if (*path == NULL)
58540 + *path = gr_to_filename_nolock(dentry, mnt);
58541 +
58542 + tmp = globbed;
58543 +
58544 + while (tmp) {
58545 + if (!glob_match(tmp->filename, *path))
58546 + return tmp;
58547 + tmp = tmp->next;
58548 + }
58549 +
58550 + return NULL;
58551 +}
58552 +
58553 +static struct acl_object_label *
58554 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58555 + const ino_t curr_ino, const dev_t curr_dev,
58556 + const struct acl_subject_label *subj, char **path, const int checkglob)
58557 +{
58558 + struct acl_subject_label *tmpsubj;
58559 + struct acl_object_label *retval;
58560 + struct acl_object_label *retval2;
58561 +
58562 + tmpsubj = (struct acl_subject_label *) subj;
58563 + read_lock(&gr_inode_lock);
58564 + do {
58565 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
58566 + if (retval) {
58567 + if (checkglob && retval->globbed) {
58568 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
58569 + if (retval2)
58570 + retval = retval2;
58571 + }
58572 + break;
58573 + }
58574 + } while ((tmpsubj = tmpsubj->parent_subject));
58575 + read_unlock(&gr_inode_lock);
58576 +
58577 + return retval;
58578 +}
58579 +
58580 +static __inline__ struct acl_object_label *
58581 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
58582 + struct dentry *curr_dentry,
58583 + const struct acl_subject_label *subj, char **path, const int checkglob)
58584 +{
58585 + int newglob = checkglob;
58586 + ino_t inode;
58587 + dev_t device;
58588 +
58589 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
58590 + as we don't want a / * rule to match instead of the / object
58591 + don't do this for create lookups that call this function though, since they're looking up
58592 + on the parent and thus need globbing checks on all paths
58593 + */
58594 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
58595 + newglob = GR_NO_GLOB;
58596 +
58597 + spin_lock(&curr_dentry->d_lock);
58598 + inode = curr_dentry->d_inode->i_ino;
58599 + device = __get_dev(curr_dentry);
58600 + spin_unlock(&curr_dentry->d_lock);
58601 +
58602 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
58603 +}
58604 +
58605 +#ifdef CONFIG_HUGETLBFS
58606 +static inline bool
58607 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
58608 +{
58609 + int i;
58610 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
58611 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
58612 + return true;
58613 + }
58614 +
58615 + return false;
58616 +}
58617 +#endif
58618 +
58619 +static struct acl_object_label *
58620 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58621 + const struct acl_subject_label *subj, char *path, const int checkglob)
58622 +{
58623 + struct dentry *dentry = (struct dentry *) l_dentry;
58624 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
58625 + struct mount *real_mnt = real_mount(mnt);
58626 + struct acl_object_label *retval;
58627 + struct dentry *parent;
58628 +
58629 + write_seqlock(&rename_lock);
58630 + br_read_lock(&vfsmount_lock);
58631 +
58632 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
58633 +#ifdef CONFIG_NET
58634 + mnt == sock_mnt ||
58635 +#endif
58636 +#ifdef CONFIG_HUGETLBFS
58637 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
58638 +#endif
58639 + /* ignore Eric Biederman */
58640 + IS_PRIVATE(l_dentry->d_inode))) {
58641 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
58642 + goto out;
58643 + }
58644 +
58645 + for (;;) {
58646 + if (dentry == real_root.dentry && mnt == real_root.mnt)
58647 + break;
58648 +
58649 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
58650 + if (!mnt_has_parent(real_mnt))
58651 + break;
58652 +
58653 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58654 + if (retval != NULL)
58655 + goto out;
58656 +
58657 + dentry = real_mnt->mnt_mountpoint;
58658 + real_mnt = real_mnt->mnt_parent;
58659 + mnt = &real_mnt->mnt;
58660 + continue;
58661 + }
58662 +
58663 + parent = dentry->d_parent;
58664 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58665 + if (retval != NULL)
58666 + goto out;
58667 +
58668 + dentry = parent;
58669 + }
58670 +
58671 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
58672 +
58673 + /* real_root is pinned so we don't have to hold a reference */
58674 + if (retval == NULL)
58675 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
58676 +out:
58677 + br_read_unlock(&vfsmount_lock);
58678 + write_sequnlock(&rename_lock);
58679 +
58680 + BUG_ON(retval == NULL);
58681 +
58682 + return retval;
58683 +}
58684 +
58685 +static __inline__ struct acl_object_label *
58686 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58687 + const struct acl_subject_label *subj)
58688 +{
58689 + char *path = NULL;
58690 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
58691 +}
58692 +
58693 +static __inline__ struct acl_object_label *
58694 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58695 + const struct acl_subject_label *subj)
58696 +{
58697 + char *path = NULL;
58698 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
58699 +}
58700 +
58701 +static __inline__ struct acl_object_label *
58702 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58703 + const struct acl_subject_label *subj, char *path)
58704 +{
58705 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
58706 +}
58707 +
58708 +static struct acl_subject_label *
58709 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
58710 + const struct acl_role_label *role)
58711 +{
58712 + struct dentry *dentry = (struct dentry *) l_dentry;
58713 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
58714 + struct mount *real_mnt = real_mount(mnt);
58715 + struct acl_subject_label *retval;
58716 + struct dentry *parent;
58717 +
58718 + write_seqlock(&rename_lock);
58719 + br_read_lock(&vfsmount_lock);
58720 +
58721 + for (;;) {
58722 + if (dentry == real_root.dentry && mnt == real_root.mnt)
58723 + break;
58724 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
58725 + if (!mnt_has_parent(real_mnt))
58726 + break;
58727 +
58728 + spin_lock(&dentry->d_lock);
58729 + read_lock(&gr_inode_lock);
58730 + retval =
58731 + lookup_acl_subj_label(dentry->d_inode->i_ino,
58732 + __get_dev(dentry), role);
58733 + read_unlock(&gr_inode_lock);
58734 + spin_unlock(&dentry->d_lock);
58735 + if (retval != NULL)
58736 + goto out;
58737 +
58738 + dentry = real_mnt->mnt_mountpoint;
58739 + real_mnt = real_mnt->mnt_parent;
58740 + mnt = &real_mnt->mnt;
58741 + continue;
58742 + }
58743 +
58744 + spin_lock(&dentry->d_lock);
58745 + read_lock(&gr_inode_lock);
58746 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
58747 + __get_dev(dentry), role);
58748 + read_unlock(&gr_inode_lock);
58749 + parent = dentry->d_parent;
58750 + spin_unlock(&dentry->d_lock);
58751 +
58752 + if (retval != NULL)
58753 + goto out;
58754 +
58755 + dentry = parent;
58756 + }
58757 +
58758 + spin_lock(&dentry->d_lock);
58759 + read_lock(&gr_inode_lock);
58760 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
58761 + __get_dev(dentry), role);
58762 + read_unlock(&gr_inode_lock);
58763 + spin_unlock(&dentry->d_lock);
58764 +
58765 + if (unlikely(retval == NULL)) {
58766 + /* real_root is pinned, we don't need to hold a reference */
58767 + read_lock(&gr_inode_lock);
58768 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
58769 + __get_dev(real_root.dentry), role);
58770 + read_unlock(&gr_inode_lock);
58771 + }
58772 +out:
58773 + br_read_unlock(&vfsmount_lock);
58774 + write_sequnlock(&rename_lock);
58775 +
58776 + BUG_ON(retval == NULL);
58777 +
58778 + return retval;
58779 +}
58780 +
58781 +static void
58782 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
58783 +{
58784 + struct task_struct *task = current;
58785 + const struct cred *cred = current_cred();
58786 +
58787 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
58788 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58789 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58790 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
58791 +
58792 + return;
58793 +}
58794 +
58795 +static void
58796 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
58797 +{
58798 + struct task_struct *task = current;
58799 + const struct cred *cred = current_cred();
58800 +
58801 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
58802 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58803 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58804 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
58805 +
58806 + return;
58807 +}
58808 +
58809 +static void
58810 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
58811 +{
58812 + struct task_struct *task = current;
58813 + const struct cred *cred = current_cred();
58814 +
58815 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
58816 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
58817 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
58818 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
58819 +
58820 + return;
58821 +}
58822 +
58823 +__u32
58824 +gr_search_file(const struct dentry * dentry, const __u32 mode,
58825 + const struct vfsmount * mnt)
58826 +{
58827 + __u32 retval = mode;
58828 + struct acl_subject_label *curracl;
58829 + struct acl_object_label *currobj;
58830 +
58831 + if (unlikely(!(gr_status & GR_READY)))
58832 + return (mode & ~GR_AUDITS);
58833 +
58834 + curracl = current->acl;
58835 +
58836 + currobj = chk_obj_label(dentry, mnt, curracl);
58837 + retval = currobj->mode & mode;
58838 +
58839 + /* if we're opening a specified transfer file for writing
58840 + (e.g. /dev/initctl), then transfer our role to init
58841 + */
58842 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
58843 + current->role->roletype & GR_ROLE_PERSIST)) {
58844 + struct task_struct *task = init_pid_ns.child_reaper;
58845 +
58846 + if (task->role != current->role) {
58847 + task->acl_sp_role = 0;
58848 + task->acl_role_id = current->acl_role_id;
58849 + task->role = current->role;
58850 + rcu_read_lock();
58851 + read_lock(&grsec_exec_file_lock);
58852 + gr_apply_subject_to_task(task);
58853 + read_unlock(&grsec_exec_file_lock);
58854 + rcu_read_unlock();
58855 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
58856 + }
58857 + }
58858 +
58859 + if (unlikely
58860 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
58861 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
58862 + __u32 new_mode = mode;
58863 +
58864 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
58865 +
58866 + retval = new_mode;
58867 +
58868 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
58869 + new_mode |= GR_INHERIT;
58870 +
58871 + if (!(mode & GR_NOLEARN))
58872 + gr_log_learn(dentry, mnt, new_mode);
58873 + }
58874 +
58875 + return retval;
58876 +}
58877 +
58878 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
58879 + const struct dentry *parent,
58880 + const struct vfsmount *mnt)
58881 +{
58882 + struct name_entry *match;
58883 + struct acl_object_label *matchpo;
58884 + struct acl_subject_label *curracl;
58885 + char *path;
58886 +
58887 + if (unlikely(!(gr_status & GR_READY)))
58888 + return NULL;
58889 +
58890 + preempt_disable();
58891 + path = gr_to_filename_rbac(new_dentry, mnt);
58892 + match = lookup_name_entry_create(path);
58893 +
58894 + curracl = current->acl;
58895 +
58896 + if (match) {
58897 + read_lock(&gr_inode_lock);
58898 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
58899 + read_unlock(&gr_inode_lock);
58900 +
58901 + if (matchpo) {
58902 + preempt_enable();
58903 + return matchpo;
58904 + }
58905 + }
58906 +
58907 + // lookup parent
58908 +
58909 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
58910 +
58911 + preempt_enable();
58912 + return matchpo;
58913 +}
58914 +
58915 +__u32
58916 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
58917 + const struct vfsmount * mnt, const __u32 mode)
58918 +{
58919 + struct acl_object_label *matchpo;
58920 + __u32 retval;
58921 +
58922 + if (unlikely(!(gr_status & GR_READY)))
58923 + return (mode & ~GR_AUDITS);
58924 +
58925 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
58926 +
58927 + retval = matchpo->mode & mode;
58928 +
58929 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
58930 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
58931 + __u32 new_mode = mode;
58932 +
58933 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
58934 +
58935 + gr_log_learn(new_dentry, mnt, new_mode);
58936 + return new_mode;
58937 + }
58938 +
58939 + return retval;
58940 +}
58941 +
58942 +__u32
58943 +gr_check_link(const struct dentry * new_dentry,
58944 + const struct dentry * parent_dentry,
58945 + const struct vfsmount * parent_mnt,
58946 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
58947 +{
58948 + struct acl_object_label *obj;
58949 + __u32 oldmode, newmode;
58950 + __u32 needmode;
58951 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
58952 + GR_DELETE | GR_INHERIT;
58953 +
58954 + if (unlikely(!(gr_status & GR_READY)))
58955 + return (GR_CREATE | GR_LINK);
58956 +
58957 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
58958 + oldmode = obj->mode;
58959 +
58960 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
58961 + newmode = obj->mode;
58962 +
58963 + needmode = newmode & checkmodes;
58964 +
58965 + // old name for hardlink must have at least the permissions of the new name
58966 + if ((oldmode & needmode) != needmode)
58967 + goto bad;
58968 +
58969 + // if old name had restrictions/auditing, make sure the new name does as well
58970 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
58971 +
58972 + // don't allow hardlinking of suid/sgid/fcapped files without permission
58973 + if (is_privileged_binary(old_dentry))
58974 + needmode |= GR_SETID;
58975 +
58976 + if ((newmode & needmode) != needmode)
58977 + goto bad;
58978 +
58979 + // enforce minimum permissions
58980 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
58981 + return newmode;
58982 +bad:
58983 + needmode = oldmode;
58984 + if (is_privileged_binary(old_dentry))
58985 + needmode |= GR_SETID;
58986 +
58987 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
58988 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
58989 + return (GR_CREATE | GR_LINK);
58990 + } else if (newmode & GR_SUPPRESS)
58991 + return GR_SUPPRESS;
58992 + else
58993 + return 0;
58994 +}
58995 +
58996 +int
58997 +gr_check_hidden_task(const struct task_struct *task)
58998 +{
58999 + if (unlikely(!(gr_status & GR_READY)))
59000 + return 0;
59001 +
59002 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
59003 + return 1;
59004 +
59005 + return 0;
59006 +}
59007 +
59008 +int
59009 +gr_check_protected_task(const struct task_struct *task)
59010 +{
59011 + if (unlikely(!(gr_status & GR_READY) || !task))
59012 + return 0;
59013 +
59014 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59015 + task->acl != current->acl)
59016 + return 1;
59017 +
59018 + return 0;
59019 +}
59020 +
59021 +int
59022 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
59023 +{
59024 + struct task_struct *p;
59025 + int ret = 0;
59026 +
59027 + if (unlikely(!(gr_status & GR_READY) || !pid))
59028 + return ret;
59029 +
59030 + read_lock(&tasklist_lock);
59031 + do_each_pid_task(pid, type, p) {
59032 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
59033 + p->acl != current->acl) {
59034 + ret = 1;
59035 + goto out;
59036 + }
59037 + } while_each_pid_task(pid, type, p);
59038 +out:
59039 + read_unlock(&tasklist_lock);
59040 +
59041 + return ret;
59042 +}
59043 +
59044 +void
59045 +gr_copy_label(struct task_struct *tsk)
59046 +{
59047 + tsk->signal->used_accept = 0;
59048 + tsk->acl_sp_role = 0;
59049 + tsk->acl_role_id = current->acl_role_id;
59050 + tsk->acl = current->acl;
59051 + tsk->role = current->role;
59052 + tsk->signal->curr_ip = current->signal->curr_ip;
59053 + tsk->signal->saved_ip = current->signal->saved_ip;
59054 + if (current->exec_file)
59055 + get_file(current->exec_file);
59056 + tsk->exec_file = current->exec_file;
59057 + tsk->is_writable = current->is_writable;
59058 + if (unlikely(current->signal->used_accept)) {
59059 + current->signal->curr_ip = 0;
59060 + current->signal->saved_ip = 0;
59061 + }
59062 +
59063 + return;
59064 +}
59065 +
59066 +static void
59067 +gr_set_proc_res(struct task_struct *task)
59068 +{
59069 + struct acl_subject_label *proc;
59070 + unsigned short i;
59071 +
59072 + proc = task->acl;
59073 +
59074 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
59075 + return;
59076 +
59077 + for (i = 0; i < RLIM_NLIMITS; i++) {
59078 + if (!(proc->resmask & (1 << i)))
59079 + continue;
59080 +
59081 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
59082 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
59083 + }
59084 +
59085 + return;
59086 +}
59087 +
59088 +extern int __gr_process_user_ban(struct user_struct *user);
59089 +
59090 +int
59091 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
59092 +{
59093 + unsigned int i;
59094 + __u16 num;
59095 + uid_t *uidlist;
59096 + uid_t curuid;
59097 + int realok = 0;
59098 + int effectiveok = 0;
59099 + int fsok = 0;
59100 + uid_t globalreal, globaleffective, globalfs;
59101 +
59102 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59103 + struct user_struct *user;
59104 +
59105 + if (!uid_valid(real))
59106 + goto skipit;
59107 +
59108 + /* find user based on global namespace */
59109 +
59110 + globalreal = GR_GLOBAL_UID(real);
59111 +
59112 + user = find_user(make_kuid(&init_user_ns, globalreal));
59113 + if (user == NULL)
59114 + goto skipit;
59115 +
59116 + if (__gr_process_user_ban(user)) {
59117 + /* for find_user */
59118 + free_uid(user);
59119 + return 1;
59120 + }
59121 +
59122 + /* for find_user */
59123 + free_uid(user);
59124 +
59125 +skipit:
59126 +#endif
59127 +
59128 + if (unlikely(!(gr_status & GR_READY)))
59129 + return 0;
59130 +
59131 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59132 + gr_log_learn_uid_change(real, effective, fs);
59133 +
59134 + num = current->acl->user_trans_num;
59135 + uidlist = current->acl->user_transitions;
59136 +
59137 + if (uidlist == NULL)
59138 + return 0;
59139 +
59140 + if (!uid_valid(real)) {
59141 + realok = 1;
59142 + globalreal = (uid_t)-1;
59143 + } else {
59144 + globalreal = GR_GLOBAL_UID(real);
59145 + }
59146 + if (!uid_valid(effective)) {
59147 + effectiveok = 1;
59148 + globaleffective = (uid_t)-1;
59149 + } else {
59150 + globaleffective = GR_GLOBAL_UID(effective);
59151 + }
59152 + if (!uid_valid(fs)) {
59153 + fsok = 1;
59154 + globalfs = (uid_t)-1;
59155 + } else {
59156 + globalfs = GR_GLOBAL_UID(fs);
59157 + }
59158 +
59159 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
59160 + for (i = 0; i < num; i++) {
59161 + curuid = uidlist[i];
59162 + if (globalreal == curuid)
59163 + realok = 1;
59164 + if (globaleffective == curuid)
59165 + effectiveok = 1;
59166 + if (globalfs == curuid)
59167 + fsok = 1;
59168 + }
59169 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
59170 + for (i = 0; i < num; i++) {
59171 + curuid = uidlist[i];
59172 + if (globalreal == curuid)
59173 + break;
59174 + if (globaleffective == curuid)
59175 + break;
59176 + if (globalfs == curuid)
59177 + break;
59178 + }
59179 + /* not in deny list */
59180 + if (i == num) {
59181 + realok = 1;
59182 + effectiveok = 1;
59183 + fsok = 1;
59184 + }
59185 + }
59186 +
59187 + if (realok && effectiveok && fsok)
59188 + return 0;
59189 + else {
59190 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59191 + return 1;
59192 + }
59193 +}
59194 +
59195 +int
59196 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
59197 +{
59198 + unsigned int i;
59199 + __u16 num;
59200 + gid_t *gidlist;
59201 + gid_t curgid;
59202 + int realok = 0;
59203 + int effectiveok = 0;
59204 + int fsok = 0;
59205 + gid_t globalreal, globaleffective, globalfs;
59206 +
59207 + if (unlikely(!(gr_status & GR_READY)))
59208 + return 0;
59209 +
59210 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
59211 + gr_log_learn_gid_change(real, effective, fs);
59212 +
59213 + num = current->acl->group_trans_num;
59214 + gidlist = current->acl->group_transitions;
59215 +
59216 + if (gidlist == NULL)
59217 + return 0;
59218 +
59219 + if (!gid_valid(real)) {
59220 + realok = 1;
59221 + globalreal = (gid_t)-1;
59222 + } else {
59223 + globalreal = GR_GLOBAL_GID(real);
59224 + }
59225 + if (!gid_valid(effective)) {
59226 + effectiveok = 1;
59227 + globaleffective = (gid_t)-1;
59228 + } else {
59229 + globaleffective = GR_GLOBAL_GID(effective);
59230 + }
59231 + if (!gid_valid(fs)) {
59232 + fsok = 1;
59233 + globalfs = (gid_t)-1;
59234 + } else {
59235 + globalfs = GR_GLOBAL_GID(fs);
59236 + }
59237 +
59238 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
59239 + for (i = 0; i < num; i++) {
59240 + curgid = gidlist[i];
59241 + if (globalreal == curgid)
59242 + realok = 1;
59243 + if (globaleffective == curgid)
59244 + effectiveok = 1;
59245 + if (globalfs == curgid)
59246 + fsok = 1;
59247 + }
59248 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
59249 + for (i = 0; i < num; i++) {
59250 + curgid = gidlist[i];
59251 + if (globalreal == curgid)
59252 + break;
59253 + if (globaleffective == curgid)
59254 + break;
59255 + if (globalfs == curgid)
59256 + break;
59257 + }
59258 + /* not in deny list */
59259 + if (i == num) {
59260 + realok = 1;
59261 + effectiveok = 1;
59262 + fsok = 1;
59263 + }
59264 + }
59265 +
59266 + if (realok && effectiveok && fsok)
59267 + return 0;
59268 + else {
59269 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
59270 + return 1;
59271 + }
59272 +}
59273 +
59274 +extern int gr_acl_is_capable(const int cap);
59275 +
59276 +void
59277 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
59278 +{
59279 + struct acl_role_label *role = task->role;
59280 + struct acl_subject_label *subj = NULL;
59281 + struct acl_object_label *obj;
59282 + struct file *filp;
59283 + uid_t uid;
59284 + gid_t gid;
59285 +
59286 + if (unlikely(!(gr_status & GR_READY)))
59287 + return;
59288 +
59289 + uid = GR_GLOBAL_UID(kuid);
59290 + gid = GR_GLOBAL_GID(kgid);
59291 +
59292 + filp = task->exec_file;
59293 +
59294 + /* kernel process, we'll give them the kernel role */
59295 + if (unlikely(!filp)) {
59296 + task->role = kernel_role;
59297 + task->acl = kernel_role->root_label;
59298 + return;
59299 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
59300 + role = lookup_acl_role_label(task, uid, gid);
59301 +
59302 + /* don't change the role if we're not a privileged process */
59303 + if (role && task->role != role &&
59304 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
59305 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
59306 + return;
59307 +
59308 + /* perform subject lookup in possibly new role
59309 + we can use this result below in the case where role == task->role
59310 + */
59311 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
59312 +
59313 + /* if we changed uid/gid, but result in the same role
59314 + and are using inheritance, don't lose the inherited subject
59315 + if current subject is other than what normal lookup
59316 + would result in, we arrived via inheritance, don't
59317 + lose subject
59318 + */
59319 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
59320 + (subj == task->acl)))
59321 + task->acl = subj;
59322 +
59323 + task->role = role;
59324 +
59325 + task->is_writable = 0;
59326 +
59327 + /* ignore additional mmap checks for processes that are writable
59328 + by the default ACL */
59329 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59330 + if (unlikely(obj->mode & GR_WRITE))
59331 + task->is_writable = 1;
59332 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
59333 + if (unlikely(obj->mode & GR_WRITE))
59334 + task->is_writable = 1;
59335 +
59336 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59337 + 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);
59338 +#endif
59339 +
59340 + gr_set_proc_res(task);
59341 +
59342 + return;
59343 +}
59344 +
59345 +int
59346 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
59347 + const int unsafe_flags)
59348 +{
59349 + struct task_struct *task = current;
59350 + struct acl_subject_label *newacl;
59351 + struct acl_object_label *obj;
59352 + __u32 retmode;
59353 +
59354 + if (unlikely(!(gr_status & GR_READY)))
59355 + return 0;
59356 +
59357 + newacl = chk_subj_label(dentry, mnt, task->role);
59358 +
59359 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
59360 + did an exec
59361 + */
59362 + rcu_read_lock();
59363 + read_lock(&tasklist_lock);
59364 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
59365 + (task->parent->acl->mode & GR_POVERRIDE))) {
59366 + read_unlock(&tasklist_lock);
59367 + rcu_read_unlock();
59368 + goto skip_check;
59369 + }
59370 + read_unlock(&tasklist_lock);
59371 + rcu_read_unlock();
59372 +
59373 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
59374 + !(task->role->roletype & GR_ROLE_GOD) &&
59375 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
59376 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
59377 + if (unsafe_flags & LSM_UNSAFE_SHARE)
59378 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
59379 + else
59380 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
59381 + return -EACCES;
59382 + }
59383 +
59384 +skip_check:
59385 +
59386 + obj = chk_obj_label(dentry, mnt, task->acl);
59387 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
59388 +
59389 + if (!(task->acl->mode & GR_INHERITLEARN) &&
59390 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
59391 + if (obj->nested)
59392 + task->acl = obj->nested;
59393 + else
59394 + task->acl = newacl;
59395 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
59396 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
59397 +
59398 + task->is_writable = 0;
59399 +
59400 + /* ignore additional mmap checks for processes that are writable
59401 + by the default ACL */
59402 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
59403 + if (unlikely(obj->mode & GR_WRITE))
59404 + task->is_writable = 1;
59405 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
59406 + if (unlikely(obj->mode & GR_WRITE))
59407 + task->is_writable = 1;
59408 +
59409 + gr_set_proc_res(task);
59410 +
59411 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59412 + 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);
59413 +#endif
59414 + return 0;
59415 +}
59416 +
59417 +/* always called with valid inodev ptr */
59418 +static void
59419 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
59420 +{
59421 + struct acl_object_label *matchpo;
59422 + struct acl_subject_label *matchps;
59423 + struct acl_subject_label *subj;
59424 + struct acl_role_label *role;
59425 + unsigned int x;
59426 +
59427 + FOR_EACH_ROLE_START(role)
59428 + FOR_EACH_SUBJECT_START(role, subj, x)
59429 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59430 + matchpo->mode |= GR_DELETED;
59431 + FOR_EACH_SUBJECT_END(subj,x)
59432 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
59433 + /* nested subjects aren't in the role's subj_hash table */
59434 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
59435 + matchpo->mode |= GR_DELETED;
59436 + FOR_EACH_NESTED_SUBJECT_END(subj)
59437 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
59438 + matchps->mode |= GR_DELETED;
59439 + FOR_EACH_ROLE_END(role)
59440 +
59441 + inodev->nentry->deleted = 1;
59442 +
59443 + return;
59444 +}
59445 +
59446 +void
59447 +gr_handle_delete(const ino_t ino, const dev_t dev)
59448 +{
59449 + struct inodev_entry *inodev;
59450 +
59451 + if (unlikely(!(gr_status & GR_READY)))
59452 + return;
59453 +
59454 + write_lock(&gr_inode_lock);
59455 + inodev = lookup_inodev_entry(ino, dev);
59456 + if (inodev != NULL)
59457 + do_handle_delete(inodev, ino, dev);
59458 + write_unlock(&gr_inode_lock);
59459 +
59460 + return;
59461 +}
59462 +
59463 +static void
59464 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
59465 + const ino_t newinode, const dev_t newdevice,
59466 + struct acl_subject_label *subj)
59467 +{
59468 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
59469 + struct acl_object_label *match;
59470 +
59471 + match = subj->obj_hash[index];
59472 +
59473 + while (match && (match->inode != oldinode ||
59474 + match->device != olddevice ||
59475 + !(match->mode & GR_DELETED)))
59476 + match = match->next;
59477 +
59478 + if (match && (match->inode == oldinode)
59479 + && (match->device == olddevice)
59480 + && (match->mode & GR_DELETED)) {
59481 + if (match->prev == NULL) {
59482 + subj->obj_hash[index] = match->next;
59483 + if (match->next != NULL)
59484 + match->next->prev = NULL;
59485 + } else {
59486 + match->prev->next = match->next;
59487 + if (match->next != NULL)
59488 + match->next->prev = match->prev;
59489 + }
59490 + match->prev = NULL;
59491 + match->next = NULL;
59492 + match->inode = newinode;
59493 + match->device = newdevice;
59494 + match->mode &= ~GR_DELETED;
59495 +
59496 + insert_acl_obj_label(match, subj);
59497 + }
59498 +
59499 + return;
59500 +}
59501 +
59502 +static void
59503 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
59504 + const ino_t newinode, const dev_t newdevice,
59505 + struct acl_role_label *role)
59506 +{
59507 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
59508 + struct acl_subject_label *match;
59509 +
59510 + match = role->subj_hash[index];
59511 +
59512 + while (match && (match->inode != oldinode ||
59513 + match->device != olddevice ||
59514 + !(match->mode & GR_DELETED)))
59515 + match = match->next;
59516 +
59517 + if (match && (match->inode == oldinode)
59518 + && (match->device == olddevice)
59519 + && (match->mode & GR_DELETED)) {
59520 + if (match->prev == NULL) {
59521 + role->subj_hash[index] = match->next;
59522 + if (match->next != NULL)
59523 + match->next->prev = NULL;
59524 + } else {
59525 + match->prev->next = match->next;
59526 + if (match->next != NULL)
59527 + match->next->prev = match->prev;
59528 + }
59529 + match->prev = NULL;
59530 + match->next = NULL;
59531 + match->inode = newinode;
59532 + match->device = newdevice;
59533 + match->mode &= ~GR_DELETED;
59534 +
59535 + insert_acl_subj_label(match, role);
59536 + }
59537 +
59538 + return;
59539 +}
59540 +
59541 +static void
59542 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
59543 + const ino_t newinode, const dev_t newdevice)
59544 +{
59545 + unsigned int index = gr_fhash(oldinode, olddevice, inodev_set.i_size);
59546 + struct inodev_entry *match;
59547 +
59548 + match = inodev_set.i_hash[index];
59549 +
59550 + while (match && (match->nentry->inode != oldinode ||
59551 + match->nentry->device != olddevice || !match->nentry->deleted))
59552 + match = match->next;
59553 +
59554 + if (match && (match->nentry->inode == oldinode)
59555 + && (match->nentry->device == olddevice) &&
59556 + match->nentry->deleted) {
59557 + if (match->prev == NULL) {
59558 + inodev_set.i_hash[index] = match->next;
59559 + if (match->next != NULL)
59560 + match->next->prev = NULL;
59561 + } else {
59562 + match->prev->next = match->next;
59563 + if (match->next != NULL)
59564 + match->next->prev = match->prev;
59565 + }
59566 + match->prev = NULL;
59567 + match->next = NULL;
59568 + match->nentry->inode = newinode;
59569 + match->nentry->device = newdevice;
59570 + match->nentry->deleted = 0;
59571 +
59572 + insert_inodev_entry(match);
59573 + }
59574 +
59575 + return;
59576 +}
59577 +
59578 +static void
59579 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
59580 +{
59581 + struct acl_subject_label *subj;
59582 + struct acl_role_label *role;
59583 + unsigned int x;
59584 +
59585 + FOR_EACH_ROLE_START(role)
59586 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
59587 +
59588 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
59589 + if ((subj->inode == ino) && (subj->device == dev)) {
59590 + subj->inode = ino;
59591 + subj->device = dev;
59592 + }
59593 + /* nested subjects aren't in the role's subj_hash table */
59594 + update_acl_obj_label(matchn->inode, matchn->device,
59595 + ino, dev, subj);
59596 + FOR_EACH_NESTED_SUBJECT_END(subj)
59597 + FOR_EACH_SUBJECT_START(role, subj, x)
59598 + update_acl_obj_label(matchn->inode, matchn->device,
59599 + ino, dev, subj);
59600 + FOR_EACH_SUBJECT_END(subj,x)
59601 + FOR_EACH_ROLE_END(role)
59602 +
59603 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
59604 +
59605 + return;
59606 +}
59607 +
59608 +static void
59609 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
59610 + const struct vfsmount *mnt)
59611 +{
59612 + ino_t ino = dentry->d_inode->i_ino;
59613 + dev_t dev = __get_dev(dentry);
59614 +
59615 + __do_handle_create(matchn, ino, dev);
59616 +
59617 + return;
59618 +}
59619 +
59620 +void
59621 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
59622 +{
59623 + struct name_entry *matchn;
59624 +
59625 + if (unlikely(!(gr_status & GR_READY)))
59626 + return;
59627 +
59628 + preempt_disable();
59629 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
59630 +
59631 + if (unlikely((unsigned long)matchn)) {
59632 + write_lock(&gr_inode_lock);
59633 + do_handle_create(matchn, dentry, mnt);
59634 + write_unlock(&gr_inode_lock);
59635 + }
59636 + preempt_enable();
59637 +
59638 + return;
59639 +}
59640 +
59641 +void
59642 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
59643 +{
59644 + struct name_entry *matchn;
59645 +
59646 + if (unlikely(!(gr_status & GR_READY)))
59647 + return;
59648 +
59649 + preempt_disable();
59650 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
59651 +
59652 + if (unlikely((unsigned long)matchn)) {
59653 + write_lock(&gr_inode_lock);
59654 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
59655 + write_unlock(&gr_inode_lock);
59656 + }
59657 + preempt_enable();
59658 +
59659 + return;
59660 +}
59661 +
59662 +void
59663 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
59664 + struct dentry *old_dentry,
59665 + struct dentry *new_dentry,
59666 + struct vfsmount *mnt, const __u8 replace)
59667 +{
59668 + struct name_entry *matchn;
59669 + struct inodev_entry *inodev;
59670 + struct inode *inode = new_dentry->d_inode;
59671 + ino_t old_ino = old_dentry->d_inode->i_ino;
59672 + dev_t old_dev = __get_dev(old_dentry);
59673 +
59674 + /* vfs_rename swaps the name and parent link for old_dentry and
59675 + new_dentry
59676 + at this point, old_dentry has the new name, parent link, and inode
59677 + for the renamed file
59678 + if a file is being replaced by a rename, new_dentry has the inode
59679 + and name for the replaced file
59680 + */
59681 +
59682 + if (unlikely(!(gr_status & GR_READY)))
59683 + return;
59684 +
59685 + preempt_disable();
59686 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
59687 +
59688 + /* we wouldn't have to check d_inode if it weren't for
59689 + NFS silly-renaming
59690 + */
59691 +
59692 + write_lock(&gr_inode_lock);
59693 + if (unlikely(replace && inode)) {
59694 + ino_t new_ino = inode->i_ino;
59695 + dev_t new_dev = __get_dev(new_dentry);
59696 +
59697 + inodev = lookup_inodev_entry(new_ino, new_dev);
59698 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
59699 + do_handle_delete(inodev, new_ino, new_dev);
59700 + }
59701 +
59702 + inodev = lookup_inodev_entry(old_ino, old_dev);
59703 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
59704 + do_handle_delete(inodev, old_ino, old_dev);
59705 +
59706 + if (unlikely((unsigned long)matchn))
59707 + do_handle_create(matchn, old_dentry, mnt);
59708 +
59709 + write_unlock(&gr_inode_lock);
59710 + preempt_enable();
59711 +
59712 + return;
59713 +}
59714 +
59715 +static int
59716 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
59717 + unsigned char **sum)
59718 +{
59719 + struct acl_role_label *r;
59720 + struct role_allowed_ip *ipp;
59721 + struct role_transition *trans;
59722 + unsigned int i;
59723 + int found = 0;
59724 + u32 curr_ip = current->signal->curr_ip;
59725 +
59726 + current->signal->saved_ip = curr_ip;
59727 +
59728 + /* check transition table */
59729 +
59730 + for (trans = current->role->transitions; trans; trans = trans->next) {
59731 + if (!strcmp(rolename, trans->rolename)) {
59732 + found = 1;
59733 + break;
59734 + }
59735 + }
59736 +
59737 + if (!found)
59738 + return 0;
59739 +
59740 + /* handle special roles that do not require authentication
59741 + and check ip */
59742 +
59743 + FOR_EACH_ROLE_START(r)
59744 + if (!strcmp(rolename, r->rolename) &&
59745 + (r->roletype & GR_ROLE_SPECIAL)) {
59746 + found = 0;
59747 + if (r->allowed_ips != NULL) {
59748 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
59749 + if ((ntohl(curr_ip) & ipp->netmask) ==
59750 + (ntohl(ipp->addr) & ipp->netmask))
59751 + found = 1;
59752 + }
59753 + } else
59754 + found = 2;
59755 + if (!found)
59756 + return 0;
59757 +
59758 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
59759 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
59760 + *salt = NULL;
59761 + *sum = NULL;
59762 + return 1;
59763 + }
59764 + }
59765 + FOR_EACH_ROLE_END(r)
59766 +
59767 + for (i = 0; i < num_sprole_pws; i++) {
59768 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
59769 + *salt = acl_special_roles[i]->salt;
59770 + *sum = acl_special_roles[i]->sum;
59771 + return 1;
59772 + }
59773 + }
59774 +
59775 + return 0;
59776 +}
59777 +
59778 +static void
59779 +assign_special_role(char *rolename)
59780 +{
59781 + struct acl_object_label *obj;
59782 + struct acl_role_label *r;
59783 + struct acl_role_label *assigned = NULL;
59784 + struct task_struct *tsk;
59785 + struct file *filp;
59786 +
59787 + FOR_EACH_ROLE_START(r)
59788 + if (!strcmp(rolename, r->rolename) &&
59789 + (r->roletype & GR_ROLE_SPECIAL)) {
59790 + assigned = r;
59791 + break;
59792 + }
59793 + FOR_EACH_ROLE_END(r)
59794 +
59795 + if (!assigned)
59796 + return;
59797 +
59798 + read_lock(&tasklist_lock);
59799 + read_lock(&grsec_exec_file_lock);
59800 +
59801 + tsk = current->real_parent;
59802 + if (tsk == NULL)
59803 + goto out_unlock;
59804 +
59805 + filp = tsk->exec_file;
59806 + if (filp == NULL)
59807 + goto out_unlock;
59808 +
59809 + tsk->is_writable = 0;
59810 +
59811 + tsk->acl_sp_role = 1;
59812 + tsk->acl_role_id = ++acl_sp_role_value;
59813 + tsk->role = assigned;
59814 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
59815 +
59816 + /* ignore additional mmap checks for processes that are writable
59817 + by the default ACL */
59818 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
59819 + if (unlikely(obj->mode & GR_WRITE))
59820 + tsk->is_writable = 1;
59821 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
59822 + if (unlikely(obj->mode & GR_WRITE))
59823 + tsk->is_writable = 1;
59824 +
59825 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
59826 + 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));
59827 +#endif
59828 +
59829 +out_unlock:
59830 + read_unlock(&grsec_exec_file_lock);
59831 + read_unlock(&tasklist_lock);
59832 + return;
59833 +}
59834 +
59835 +int gr_check_secure_terminal(struct task_struct *task)
59836 +{
59837 + struct task_struct *p, *p2, *p3;
59838 + struct files_struct *files;
59839 + struct fdtable *fdt;
59840 + struct file *our_file = NULL, *file;
59841 + int i;
59842 +
59843 + if (task->signal->tty == NULL)
59844 + return 1;
59845 +
59846 + files = get_files_struct(task);
59847 + if (files != NULL) {
59848 + rcu_read_lock();
59849 + fdt = files_fdtable(files);
59850 + for (i=0; i < fdt->max_fds; i++) {
59851 + file = fcheck_files(files, i);
59852 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
59853 + get_file(file);
59854 + our_file = file;
59855 + }
59856 + }
59857 + rcu_read_unlock();
59858 + put_files_struct(files);
59859 + }
59860 +
59861 + if (our_file == NULL)
59862 + return 1;
59863 +
59864 + read_lock(&tasklist_lock);
59865 + do_each_thread(p2, p) {
59866 + files = get_files_struct(p);
59867 + if (files == NULL ||
59868 + (p->signal && p->signal->tty == task->signal->tty)) {
59869 + if (files != NULL)
59870 + put_files_struct(files);
59871 + continue;
59872 + }
59873 + rcu_read_lock();
59874 + fdt = files_fdtable(files);
59875 + for (i=0; i < fdt->max_fds; i++) {
59876 + file = fcheck_files(files, i);
59877 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
59878 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
59879 + p3 = task;
59880 + while (task_pid_nr(p3) > 0) {
59881 + if (p3 == p)
59882 + break;
59883 + p3 = p3->real_parent;
59884 + }
59885 + if (p3 == p)
59886 + break;
59887 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
59888 + gr_handle_alertkill(p);
59889 + rcu_read_unlock();
59890 + put_files_struct(files);
59891 + read_unlock(&tasklist_lock);
59892 + fput(our_file);
59893 + return 0;
59894 + }
59895 + }
59896 + rcu_read_unlock();
59897 + put_files_struct(files);
59898 + } while_each_thread(p2, p);
59899 + read_unlock(&tasklist_lock);
59900 +
59901 + fput(our_file);
59902 + return 1;
59903 +}
59904 +
59905 +static int gr_rbac_disable(void *unused)
59906 +{
59907 + pax_open_kernel();
59908 + gr_status &= ~GR_READY;
59909 + pax_close_kernel();
59910 +
59911 + return 0;
59912 +}
59913 +
59914 +ssize_t
59915 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
59916 +{
59917 + struct gr_arg_wrapper uwrap;
59918 + unsigned char *sprole_salt = NULL;
59919 + unsigned char *sprole_sum = NULL;
59920 + int error = sizeof (struct gr_arg_wrapper);
59921 + int error2 = 0;
59922 +
59923 + mutex_lock(&gr_dev_mutex);
59924 +
59925 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
59926 + error = -EPERM;
59927 + goto out;
59928 + }
59929 +
59930 + if (count != sizeof (struct gr_arg_wrapper)) {
59931 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
59932 + error = -EINVAL;
59933 + goto out;
59934 + }
59935 +
59936 +
59937 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
59938 + gr_auth_expires = 0;
59939 + gr_auth_attempts = 0;
59940 + }
59941 +
59942 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
59943 + error = -EFAULT;
59944 + goto out;
59945 + }
59946 +
59947 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
59948 + error = -EINVAL;
59949 + goto out;
59950 + }
59951 +
59952 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
59953 + error = -EFAULT;
59954 + goto out;
59955 + }
59956 +
59957 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
59958 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
59959 + time_after(gr_auth_expires, get_seconds())) {
59960 + error = -EBUSY;
59961 + goto out;
59962 + }
59963 +
59964 + /* if non-root trying to do anything other than use a special role,
59965 + do not attempt authentication, do not count towards authentication
59966 + locking
59967 + */
59968 +
59969 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
59970 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
59971 + gr_is_global_nonroot(current_uid())) {
59972 + error = -EPERM;
59973 + goto out;
59974 + }
59975 +
59976 + /* ensure pw and special role name are null terminated */
59977 +
59978 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
59979 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
59980 +
59981 + /* Okay.
59982 + * We have our enough of the argument structure..(we have yet
59983 + * to copy_from_user the tables themselves) . Copy the tables
59984 + * only if we need them, i.e. for loading operations. */
59985 +
59986 + switch (gr_usermode->mode) {
59987 + case GR_STATUS:
59988 + if (gr_status & GR_READY) {
59989 + error = 1;
59990 + if (!gr_check_secure_terminal(current))
59991 + error = 3;
59992 + } else
59993 + error = 2;
59994 + goto out;
59995 + case GR_SHUTDOWN:
59996 + if ((gr_status & GR_READY)
59997 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
59998 + stop_machine(gr_rbac_disable, NULL, NULL);
59999 + free_variables();
60000 + memset(gr_usermode, 0, sizeof (struct gr_arg));
60001 + memset(gr_system_salt, 0, GR_SALT_LEN);
60002 + memset(gr_system_sum, 0, GR_SHA_LEN);
60003 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
60004 + } else if (gr_status & GR_READY) {
60005 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
60006 + error = -EPERM;
60007 + } else {
60008 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
60009 + error = -EAGAIN;
60010 + }
60011 + break;
60012 + case GR_ENABLE:
60013 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
60014 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
60015 + else {
60016 + if (gr_status & GR_READY)
60017 + error = -EAGAIN;
60018 + else
60019 + error = error2;
60020 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
60021 + }
60022 + break;
60023 + case GR_RELOAD:
60024 + if (!(gr_status & GR_READY)) {
60025 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
60026 + error = -EAGAIN;
60027 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60028 + stop_machine(gr_rbac_disable, NULL, NULL);
60029 + free_variables();
60030 + error2 = gracl_init(gr_usermode);
60031 + if (!error2)
60032 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
60033 + else {
60034 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60035 + error = error2;
60036 + }
60037 + } else {
60038 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
60039 + error = -EPERM;
60040 + }
60041 + break;
60042 + case GR_SEGVMOD:
60043 + if (unlikely(!(gr_status & GR_READY))) {
60044 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
60045 + error = -EAGAIN;
60046 + break;
60047 + }
60048 +
60049 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
60050 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
60051 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
60052 + struct acl_subject_label *segvacl;
60053 + segvacl =
60054 + lookup_acl_subj_label(gr_usermode->segv_inode,
60055 + gr_usermode->segv_device,
60056 + current->role);
60057 + if (segvacl) {
60058 + segvacl->crashes = 0;
60059 + segvacl->expires = 0;
60060 + }
60061 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
60062 + gr_remove_uid(gr_usermode->segv_uid);
60063 + }
60064 + } else {
60065 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
60066 + error = -EPERM;
60067 + }
60068 + break;
60069 + case GR_SPROLE:
60070 + case GR_SPROLEPAM:
60071 + if (unlikely(!(gr_status & GR_READY))) {
60072 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
60073 + error = -EAGAIN;
60074 + break;
60075 + }
60076 +
60077 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
60078 + current->role->expires = 0;
60079 + current->role->auth_attempts = 0;
60080 + }
60081 +
60082 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
60083 + time_after(current->role->expires, get_seconds())) {
60084 + error = -EBUSY;
60085 + goto out;
60086 + }
60087 +
60088 + if (lookup_special_role_auth
60089 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
60090 + && ((!sprole_salt && !sprole_sum)
60091 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
60092 + char *p = "";
60093 + assign_special_role(gr_usermode->sp_role);
60094 + read_lock(&tasklist_lock);
60095 + if (current->real_parent)
60096 + p = current->real_parent->role->rolename;
60097 + read_unlock(&tasklist_lock);
60098 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
60099 + p, acl_sp_role_value);
60100 + } else {
60101 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
60102 + error = -EPERM;
60103 + if(!(current->role->auth_attempts++))
60104 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60105 +
60106 + goto out;
60107 + }
60108 + break;
60109 + case GR_UNSPROLE:
60110 + if (unlikely(!(gr_status & GR_READY))) {
60111 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
60112 + error = -EAGAIN;
60113 + break;
60114 + }
60115 +
60116 + if (current->role->roletype & GR_ROLE_SPECIAL) {
60117 + char *p = "";
60118 + int i = 0;
60119 +
60120 + read_lock(&tasklist_lock);
60121 + if (current->real_parent) {
60122 + p = current->real_parent->role->rolename;
60123 + i = current->real_parent->acl_role_id;
60124 + }
60125 + read_unlock(&tasklist_lock);
60126 +
60127 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
60128 + gr_set_acls(1);
60129 + } else {
60130 + error = -EPERM;
60131 + goto out;
60132 + }
60133 + break;
60134 + default:
60135 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
60136 + error = -EINVAL;
60137 + break;
60138 + }
60139 +
60140 + if (error != -EPERM)
60141 + goto out;
60142 +
60143 + if(!(gr_auth_attempts++))
60144 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
60145 +
60146 + out:
60147 + mutex_unlock(&gr_dev_mutex);
60148 + return error;
60149 +}
60150 +
60151 +/* must be called with
60152 + rcu_read_lock();
60153 + read_lock(&tasklist_lock);
60154 + read_lock(&grsec_exec_file_lock);
60155 +*/
60156 +int gr_apply_subject_to_task(struct task_struct *task)
60157 +{
60158 + struct acl_object_label *obj;
60159 + char *tmpname;
60160 + struct acl_subject_label *tmpsubj;
60161 + struct file *filp;
60162 + struct name_entry *nmatch;
60163 +
60164 + filp = task->exec_file;
60165 + if (filp == NULL)
60166 + return 0;
60167 +
60168 + /* the following is to apply the correct subject
60169 + on binaries running when the RBAC system
60170 + is enabled, when the binaries have been
60171 + replaced or deleted since their execution
60172 + -----
60173 + when the RBAC system starts, the inode/dev
60174 + from exec_file will be one the RBAC system
60175 + is unaware of. It only knows the inode/dev
60176 + of the present file on disk, or the absence
60177 + of it.
60178 + */
60179 + preempt_disable();
60180 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
60181 +
60182 + nmatch = lookup_name_entry(tmpname);
60183 + preempt_enable();
60184 + tmpsubj = NULL;
60185 + if (nmatch) {
60186 + if (nmatch->deleted)
60187 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
60188 + else
60189 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
60190 + if (tmpsubj != NULL)
60191 + task->acl = tmpsubj;
60192 + }
60193 + if (tmpsubj == NULL)
60194 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
60195 + task->role);
60196 + if (task->acl) {
60197 + task->is_writable = 0;
60198 + /* ignore additional mmap checks for processes that are writable
60199 + by the default ACL */
60200 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60201 + if (unlikely(obj->mode & GR_WRITE))
60202 + task->is_writable = 1;
60203 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
60204 + if (unlikely(obj->mode & GR_WRITE))
60205 + task->is_writable = 1;
60206 +
60207 + gr_set_proc_res(task);
60208 +
60209 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
60210 + 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);
60211 +#endif
60212 + } else {
60213 + return 1;
60214 + }
60215 +
60216 + return 0;
60217 +}
60218 +
60219 +int
60220 +gr_set_acls(const int type)
60221 +{
60222 + struct task_struct *task, *task2;
60223 + struct acl_role_label *role = current->role;
60224 + __u16 acl_role_id = current->acl_role_id;
60225 + const struct cred *cred;
60226 + int ret;
60227 +
60228 + rcu_read_lock();
60229 + read_lock(&tasklist_lock);
60230 + read_lock(&grsec_exec_file_lock);
60231 + do_each_thread(task2, task) {
60232 + /* check to see if we're called from the exit handler,
60233 + if so, only replace ACLs that have inherited the admin
60234 + ACL */
60235 +
60236 + if (type && (task->role != role ||
60237 + task->acl_role_id != acl_role_id))
60238 + continue;
60239 +
60240 + task->acl_role_id = 0;
60241 + task->acl_sp_role = 0;
60242 +
60243 + if (task->exec_file) {
60244 + cred = __task_cred(task);
60245 + task->role = lookup_acl_role_label(task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
60246 + ret = gr_apply_subject_to_task(task);
60247 + if (ret) {
60248 + read_unlock(&grsec_exec_file_lock);
60249 + read_unlock(&tasklist_lock);
60250 + rcu_read_unlock();
60251 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
60252 + return ret;
60253 + }
60254 + } else {
60255 + // it's a kernel process
60256 + task->role = kernel_role;
60257 + task->acl = kernel_role->root_label;
60258 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
60259 + task->acl->mode &= ~GR_PROCFIND;
60260 +#endif
60261 + }
60262 + } while_each_thread(task2, task);
60263 + read_unlock(&grsec_exec_file_lock);
60264 + read_unlock(&tasklist_lock);
60265 + rcu_read_unlock();
60266 +
60267 + return 0;
60268 +}
60269 +
60270 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
60271 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
60272 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
60273 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
60274 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
60275 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
60276 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
60277 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
60278 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
60279 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
60280 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
60281 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
60282 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
60283 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
60284 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
60285 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
60286 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
60287 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
60288 +};
60289 +
60290 +void
60291 +gr_learn_resource(const struct task_struct *task,
60292 + const int res, const unsigned long wanted, const int gt)
60293 +{
60294 + struct acl_subject_label *acl;
60295 + const struct cred *cred;
60296 +
60297 + if (unlikely((gr_status & GR_READY) &&
60298 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
60299 + goto skip_reslog;
60300 +
60301 + gr_log_resource(task, res, wanted, gt);
60302 +skip_reslog:
60303 +
60304 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
60305 + return;
60306 +
60307 + acl = task->acl;
60308 +
60309 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
60310 + !(acl->resmask & (1 << (unsigned short) res))))
60311 + return;
60312 +
60313 + if (wanted >= acl->res[res].rlim_cur) {
60314 + unsigned long res_add;
60315 +
60316 + res_add = wanted + res_learn_bumps[res];
60317 +
60318 + acl->res[res].rlim_cur = res_add;
60319 +
60320 + if (wanted > acl->res[res].rlim_max)
60321 + acl->res[res].rlim_max = res_add;
60322 +
60323 + /* only log the subject filename, since resource logging is supported for
60324 + single-subject learning only */
60325 + rcu_read_lock();
60326 + cred = __task_cred(task);
60327 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60328 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
60329 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
60330 + "", (unsigned long) res, &task->signal->saved_ip);
60331 + rcu_read_unlock();
60332 + }
60333 +
60334 + return;
60335 +}
60336 +EXPORT_SYMBOL(gr_learn_resource);
60337 +#endif
60338 +
60339 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
60340 +void
60341 +pax_set_initial_flags(struct linux_binprm *bprm)
60342 +{
60343 + struct task_struct *task = current;
60344 + struct acl_subject_label *proc;
60345 + unsigned long flags;
60346 +
60347 + if (unlikely(!(gr_status & GR_READY)))
60348 + return;
60349 +
60350 + flags = pax_get_flags(task);
60351 +
60352 + proc = task->acl;
60353 +
60354 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
60355 + flags &= ~MF_PAX_PAGEEXEC;
60356 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
60357 + flags &= ~MF_PAX_SEGMEXEC;
60358 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
60359 + flags &= ~MF_PAX_RANDMMAP;
60360 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
60361 + flags &= ~MF_PAX_EMUTRAMP;
60362 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
60363 + flags &= ~MF_PAX_MPROTECT;
60364 +
60365 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
60366 + flags |= MF_PAX_PAGEEXEC;
60367 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
60368 + flags |= MF_PAX_SEGMEXEC;
60369 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
60370 + flags |= MF_PAX_RANDMMAP;
60371 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
60372 + flags |= MF_PAX_EMUTRAMP;
60373 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
60374 + flags |= MF_PAX_MPROTECT;
60375 +
60376 + pax_set_flags(task, flags);
60377 +
60378 + return;
60379 +}
60380 +#endif
60381 +
60382 +int
60383 +gr_handle_proc_ptrace(struct task_struct *task)
60384 +{
60385 + struct file *filp;
60386 + struct task_struct *tmp = task;
60387 + struct task_struct *curtemp = current;
60388 + __u32 retmode;
60389 +
60390 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60391 + if (unlikely(!(gr_status & GR_READY)))
60392 + return 0;
60393 +#endif
60394 +
60395 + read_lock(&tasklist_lock);
60396 + read_lock(&grsec_exec_file_lock);
60397 + filp = task->exec_file;
60398 +
60399 + while (task_pid_nr(tmp) > 0) {
60400 + if (tmp == curtemp)
60401 + break;
60402 + tmp = tmp->real_parent;
60403 + }
60404 +
60405 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60406 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
60407 + read_unlock(&grsec_exec_file_lock);
60408 + read_unlock(&tasklist_lock);
60409 + return 1;
60410 + }
60411 +
60412 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60413 + if (!(gr_status & GR_READY)) {
60414 + read_unlock(&grsec_exec_file_lock);
60415 + read_unlock(&tasklist_lock);
60416 + return 0;
60417 + }
60418 +#endif
60419 +
60420 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
60421 + read_unlock(&grsec_exec_file_lock);
60422 + read_unlock(&tasklist_lock);
60423 +
60424 + if (retmode & GR_NOPTRACE)
60425 + return 1;
60426 +
60427 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
60428 + && (current->acl != task->acl || (current->acl != current->role->root_label
60429 + && task_pid_nr(current) != task_pid_nr(task))))
60430 + return 1;
60431 +
60432 + return 0;
60433 +}
60434 +
60435 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
60436 +{
60437 + if (unlikely(!(gr_status & GR_READY)))
60438 + return;
60439 +
60440 + if (!(current->role->roletype & GR_ROLE_GOD))
60441 + return;
60442 +
60443 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
60444 + p->role->rolename, gr_task_roletype_to_char(p),
60445 + p->acl->filename);
60446 +}
60447 +
60448 +int
60449 +gr_handle_ptrace(struct task_struct *task, const long request)
60450 +{
60451 + struct task_struct *tmp = task;
60452 + struct task_struct *curtemp = current;
60453 + __u32 retmode;
60454 +
60455 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
60456 + if (unlikely(!(gr_status & GR_READY)))
60457 + return 0;
60458 +#endif
60459 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
60460 + read_lock(&tasklist_lock);
60461 + while (task_pid_nr(tmp) > 0) {
60462 + if (tmp == curtemp)
60463 + break;
60464 + tmp = tmp->real_parent;
60465 + }
60466 +
60467 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
60468 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
60469 + read_unlock(&tasklist_lock);
60470 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60471 + return 1;
60472 + }
60473 + read_unlock(&tasklist_lock);
60474 + }
60475 +
60476 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60477 + if (!(gr_status & GR_READY))
60478 + return 0;
60479 +#endif
60480 +
60481 + read_lock(&grsec_exec_file_lock);
60482 + if (unlikely(!task->exec_file)) {
60483 + read_unlock(&grsec_exec_file_lock);
60484 + return 0;
60485 + }
60486 +
60487 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
60488 + read_unlock(&grsec_exec_file_lock);
60489 +
60490 + if (retmode & GR_NOPTRACE) {
60491 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60492 + return 1;
60493 + }
60494 +
60495 + if (retmode & GR_PTRACERD) {
60496 + switch (request) {
60497 + case PTRACE_SEIZE:
60498 + case PTRACE_POKETEXT:
60499 + case PTRACE_POKEDATA:
60500 + case PTRACE_POKEUSR:
60501 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
60502 + case PTRACE_SETREGS:
60503 + case PTRACE_SETFPREGS:
60504 +#endif
60505 +#ifdef CONFIG_X86
60506 + case PTRACE_SETFPXREGS:
60507 +#endif
60508 +#ifdef CONFIG_ALTIVEC
60509 + case PTRACE_SETVRREGS:
60510 +#endif
60511 + return 1;
60512 + default:
60513 + return 0;
60514 + }
60515 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
60516 + !(current->role->roletype & GR_ROLE_GOD) &&
60517 + (current->acl != task->acl)) {
60518 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
60519 + return 1;
60520 + }
60521 +
60522 + return 0;
60523 +}
60524 +
60525 +static int is_writable_mmap(const struct file *filp)
60526 +{
60527 + struct task_struct *task = current;
60528 + struct acl_object_label *obj, *obj2;
60529 +
60530 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
60531 + !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))) {
60532 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
60533 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
60534 + task->role->root_label);
60535 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
60536 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
60537 + return 1;
60538 + }
60539 + }
60540 + return 0;
60541 +}
60542 +
60543 +int
60544 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
60545 +{
60546 + __u32 mode;
60547 +
60548 + if (unlikely(!file || !(prot & PROT_EXEC)))
60549 + return 1;
60550 +
60551 + if (is_writable_mmap(file))
60552 + return 0;
60553 +
60554 + mode =
60555 + gr_search_file(file->f_path.dentry,
60556 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
60557 + file->f_path.mnt);
60558 +
60559 + if (!gr_tpe_allow(file))
60560 + return 0;
60561 +
60562 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
60563 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60564 + return 0;
60565 + } else if (unlikely(!(mode & GR_EXEC))) {
60566 + return 0;
60567 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
60568 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60569 + return 1;
60570 + }
60571 +
60572 + return 1;
60573 +}
60574 +
60575 +int
60576 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
60577 +{
60578 + __u32 mode;
60579 +
60580 + if (unlikely(!file || !(prot & PROT_EXEC)))
60581 + return 1;
60582 +
60583 + if (is_writable_mmap(file))
60584 + return 0;
60585 +
60586 + mode =
60587 + gr_search_file(file->f_path.dentry,
60588 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
60589 + file->f_path.mnt);
60590 +
60591 + if (!gr_tpe_allow(file))
60592 + return 0;
60593 +
60594 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
60595 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60596 + return 0;
60597 + } else if (unlikely(!(mode & GR_EXEC))) {
60598 + return 0;
60599 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
60600 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
60601 + return 1;
60602 + }
60603 +
60604 + return 1;
60605 +}
60606 +
60607 +void
60608 +gr_acl_handle_psacct(struct task_struct *task, const long code)
60609 +{
60610 + unsigned long runtime;
60611 + unsigned long cputime;
60612 + unsigned int wday, cday;
60613 + __u8 whr, chr;
60614 + __u8 wmin, cmin;
60615 + __u8 wsec, csec;
60616 + struct timespec timeval;
60617 +
60618 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
60619 + !(task->acl->mode & GR_PROCACCT)))
60620 + return;
60621 +
60622 + do_posix_clock_monotonic_gettime(&timeval);
60623 + runtime = timeval.tv_sec - task->start_time.tv_sec;
60624 + wday = runtime / (3600 * 24);
60625 + runtime -= wday * (3600 * 24);
60626 + whr = runtime / 3600;
60627 + runtime -= whr * 3600;
60628 + wmin = runtime / 60;
60629 + runtime -= wmin * 60;
60630 + wsec = runtime;
60631 +
60632 + cputime = (task->utime + task->stime) / HZ;
60633 + cday = cputime / (3600 * 24);
60634 + cputime -= cday * (3600 * 24);
60635 + chr = cputime / 3600;
60636 + cputime -= chr * 3600;
60637 + cmin = cputime / 60;
60638 + cputime -= cmin * 60;
60639 + csec = cputime;
60640 +
60641 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
60642 +
60643 + return;
60644 +}
60645 +
60646 +void gr_set_kernel_label(struct task_struct *task)
60647 +{
60648 + if (gr_status & GR_READY) {
60649 + task->role = kernel_role;
60650 + task->acl = kernel_role->root_label;
60651 + }
60652 + return;
60653 +}
60654 +
60655 +#ifdef CONFIG_TASKSTATS
60656 +int gr_is_taskstats_denied(int pid)
60657 +{
60658 + struct task_struct *task;
60659 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60660 + const struct cred *cred;
60661 +#endif
60662 + int ret = 0;
60663 +
60664 + /* restrict taskstats viewing to un-chrooted root users
60665 + who have the 'view' subject flag if the RBAC system is enabled
60666 + */
60667 +
60668 + rcu_read_lock();
60669 + read_lock(&tasklist_lock);
60670 + task = find_task_by_vpid(pid);
60671 + if (task) {
60672 +#ifdef CONFIG_GRKERNSEC_CHROOT
60673 + if (proc_is_chrooted(task))
60674 + ret = -EACCES;
60675 +#endif
60676 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60677 + cred = __task_cred(task);
60678 +#ifdef CONFIG_GRKERNSEC_PROC_USER
60679 + if (gr_is_global_nonroot(cred->uid))
60680 + ret = -EACCES;
60681 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
60682 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
60683 + ret = -EACCES;
60684 +#endif
60685 +#endif
60686 + if (gr_status & GR_READY) {
60687 + if (!(task->acl->mode & GR_VIEW))
60688 + ret = -EACCES;
60689 + }
60690 + } else
60691 + ret = -ENOENT;
60692 +
60693 + read_unlock(&tasklist_lock);
60694 + rcu_read_unlock();
60695 +
60696 + return ret;
60697 +}
60698 +#endif
60699 +
60700 +/* AUXV entries are filled via a descendant of search_binary_handler
60701 + after we've already applied the subject for the target
60702 +*/
60703 +int gr_acl_enable_at_secure(void)
60704 +{
60705 + if (unlikely(!(gr_status & GR_READY)))
60706 + return 0;
60707 +
60708 + if (current->acl->mode & GR_ATSECURE)
60709 + return 1;
60710 +
60711 + return 0;
60712 +}
60713 +
60714 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
60715 +{
60716 + struct task_struct *task = current;
60717 + struct dentry *dentry = file->f_path.dentry;
60718 + struct vfsmount *mnt = file->f_path.mnt;
60719 + struct acl_object_label *obj, *tmp;
60720 + struct acl_subject_label *subj;
60721 + unsigned int bufsize;
60722 + int is_not_root;
60723 + char *path;
60724 + dev_t dev = __get_dev(dentry);
60725 +
60726 + if (unlikely(!(gr_status & GR_READY)))
60727 + return 1;
60728 +
60729 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
60730 + return 1;
60731 +
60732 + /* ignore Eric Biederman */
60733 + if (IS_PRIVATE(dentry->d_inode))
60734 + return 1;
60735 +
60736 + subj = task->acl;
60737 + read_lock(&gr_inode_lock);
60738 + do {
60739 + obj = lookup_acl_obj_label(ino, dev, subj);
60740 + if (obj != NULL) {
60741 + read_unlock(&gr_inode_lock);
60742 + return (obj->mode & GR_FIND) ? 1 : 0;
60743 + }
60744 + } while ((subj = subj->parent_subject));
60745 + read_unlock(&gr_inode_lock);
60746 +
60747 + /* this is purely an optimization since we're looking for an object
60748 + for the directory we're doing a readdir on
60749 + if it's possible for any globbed object to match the entry we're
60750 + filling into the directory, then the object we find here will be
60751 + an anchor point with attached globbed objects
60752 + */
60753 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
60754 + if (obj->globbed == NULL)
60755 + return (obj->mode & GR_FIND) ? 1 : 0;
60756 +
60757 + is_not_root = ((obj->filename[0] == '/') &&
60758 + (obj->filename[1] == '\0')) ? 0 : 1;
60759 + bufsize = PAGE_SIZE - namelen - is_not_root;
60760 +
60761 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
60762 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
60763 + return 1;
60764 +
60765 + preempt_disable();
60766 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
60767 + bufsize);
60768 +
60769 + bufsize = strlen(path);
60770 +
60771 + /* if base is "/", don't append an additional slash */
60772 + if (is_not_root)
60773 + *(path + bufsize) = '/';
60774 + memcpy(path + bufsize + is_not_root, name, namelen);
60775 + *(path + bufsize + namelen + is_not_root) = '\0';
60776 +
60777 + tmp = obj->globbed;
60778 + while (tmp) {
60779 + if (!glob_match(tmp->filename, path)) {
60780 + preempt_enable();
60781 + return (tmp->mode & GR_FIND) ? 1 : 0;
60782 + }
60783 + tmp = tmp->next;
60784 + }
60785 + preempt_enable();
60786 + return (obj->mode & GR_FIND) ? 1 : 0;
60787 +}
60788 +
60789 +void gr_put_exec_file(struct task_struct *task)
60790 +{
60791 + struct file *filp;
60792 +
60793 + write_lock(&grsec_exec_file_lock);
60794 + filp = task->exec_file;
60795 + task->exec_file = NULL;
60796 + write_unlock(&grsec_exec_file_lock);
60797 +
60798 + if (filp)
60799 + fput(filp);
60800 +
60801 + return;
60802 +}
60803 +
60804 +
60805 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
60806 +EXPORT_SYMBOL(gr_acl_is_enabled);
60807 +#endif
60808 +EXPORT_SYMBOL(gr_set_kernel_label);
60809 +#ifdef CONFIG_SECURITY
60810 +EXPORT_SYMBOL(gr_check_user_change);
60811 +EXPORT_SYMBOL(gr_check_group_change);
60812 +#endif
60813 +
60814 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
60815 new file mode 100644
60816 index 0000000..34fefda
60817 --- /dev/null
60818 +++ b/grsecurity/gracl_alloc.c
60819 @@ -0,0 +1,105 @@
60820 +#include <linux/kernel.h>
60821 +#include <linux/mm.h>
60822 +#include <linux/slab.h>
60823 +#include <linux/vmalloc.h>
60824 +#include <linux/gracl.h>
60825 +#include <linux/grsecurity.h>
60826 +
60827 +static unsigned long alloc_stack_next = 1;
60828 +static unsigned long alloc_stack_size = 1;
60829 +static void **alloc_stack;
60830 +
60831 +static __inline__ int
60832 +alloc_pop(void)
60833 +{
60834 + if (alloc_stack_next == 1)
60835 + return 0;
60836 +
60837 + kfree(alloc_stack[alloc_stack_next - 2]);
60838 +
60839 + alloc_stack_next--;
60840 +
60841 + return 1;
60842 +}
60843 +
60844 +static __inline__ int
60845 +alloc_push(void *buf)
60846 +{
60847 + if (alloc_stack_next >= alloc_stack_size)
60848 + return 1;
60849 +
60850 + alloc_stack[alloc_stack_next - 1] = buf;
60851 +
60852 + alloc_stack_next++;
60853 +
60854 + return 0;
60855 +}
60856 +
60857 +void *
60858 +acl_alloc(unsigned long len)
60859 +{
60860 + void *ret = NULL;
60861 +
60862 + if (!len || len > PAGE_SIZE)
60863 + goto out;
60864 +
60865 + ret = kmalloc(len, GFP_KERNEL);
60866 +
60867 + if (ret) {
60868 + if (alloc_push(ret)) {
60869 + kfree(ret);
60870 + ret = NULL;
60871 + }
60872 + }
60873 +
60874 +out:
60875 + return ret;
60876 +}
60877 +
60878 +void *
60879 +acl_alloc_num(unsigned long num, unsigned long len)
60880 +{
60881 + if (!len || (num > (PAGE_SIZE / len)))
60882 + return NULL;
60883 +
60884 + return acl_alloc(num * len);
60885 +}
60886 +
60887 +void
60888 +acl_free_all(void)
60889 +{
60890 + if (gr_acl_is_enabled() || !alloc_stack)
60891 + return;
60892 +
60893 + while (alloc_pop()) ;
60894 +
60895 + if (alloc_stack) {
60896 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
60897 + kfree(alloc_stack);
60898 + else
60899 + vfree(alloc_stack);
60900 + }
60901 +
60902 + alloc_stack = NULL;
60903 + alloc_stack_size = 1;
60904 + alloc_stack_next = 1;
60905 +
60906 + return;
60907 +}
60908 +
60909 +int
60910 +acl_alloc_stack_init(unsigned long size)
60911 +{
60912 + if ((size * sizeof (void *)) <= PAGE_SIZE)
60913 + alloc_stack =
60914 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
60915 + else
60916 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
60917 +
60918 + alloc_stack_size = size;
60919 +
60920 + if (!alloc_stack)
60921 + return 0;
60922 + else
60923 + return 1;
60924 +}
60925 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
60926 new file mode 100644
60927 index 0000000..bdd51ea
60928 --- /dev/null
60929 +++ b/grsecurity/gracl_cap.c
60930 @@ -0,0 +1,110 @@
60931 +#include <linux/kernel.h>
60932 +#include <linux/module.h>
60933 +#include <linux/sched.h>
60934 +#include <linux/gracl.h>
60935 +#include <linux/grsecurity.h>
60936 +#include <linux/grinternal.h>
60937 +
60938 +extern const char *captab_log[];
60939 +extern int captab_log_entries;
60940 +
60941 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
60942 +{
60943 + struct acl_subject_label *curracl;
60944 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
60945 + kernel_cap_t cap_audit = __cap_empty_set;
60946 +
60947 + if (!gr_acl_is_enabled())
60948 + return 1;
60949 +
60950 + curracl = task->acl;
60951 +
60952 + cap_drop = curracl->cap_lower;
60953 + cap_mask = curracl->cap_mask;
60954 + cap_audit = curracl->cap_invert_audit;
60955 +
60956 + while ((curracl = curracl->parent_subject)) {
60957 + /* if the cap isn't specified in the current computed mask but is specified in the
60958 + current level subject, and is lowered in the current level subject, then add
60959 + it to the set of dropped capabilities
60960 + otherwise, add the current level subject's mask to the current computed mask
60961 + */
60962 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
60963 + cap_raise(cap_mask, cap);
60964 + if (cap_raised(curracl->cap_lower, cap))
60965 + cap_raise(cap_drop, cap);
60966 + if (cap_raised(curracl->cap_invert_audit, cap))
60967 + cap_raise(cap_audit, cap);
60968 + }
60969 + }
60970 +
60971 + if (!cap_raised(cap_drop, cap)) {
60972 + if (cap_raised(cap_audit, cap))
60973 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
60974 + return 1;
60975 + }
60976 +
60977 + curracl = task->acl;
60978 +
60979 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
60980 + && cap_raised(cred->cap_effective, cap)) {
60981 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
60982 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
60983 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
60984 + gr_to_filename(task->exec_file->f_path.dentry,
60985 + task->exec_file->f_path.mnt) : curracl->filename,
60986 + curracl->filename, 0UL,
60987 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
60988 + return 1;
60989 + }
60990 +
60991 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
60992 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
60993 +
60994 + return 0;
60995 +}
60996 +
60997 +int
60998 +gr_acl_is_capable(const int cap)
60999 +{
61000 + return gr_task_acl_is_capable(current, current_cred(), cap);
61001 +}
61002 +
61003 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
61004 +{
61005 + struct acl_subject_label *curracl;
61006 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
61007 +
61008 + if (!gr_acl_is_enabled())
61009 + return 1;
61010 +
61011 + curracl = task->acl;
61012 +
61013 + cap_drop = curracl->cap_lower;
61014 + cap_mask = curracl->cap_mask;
61015 +
61016 + while ((curracl = curracl->parent_subject)) {
61017 + /* if the cap isn't specified in the current computed mask but is specified in the
61018 + current level subject, and is lowered in the current level subject, then add
61019 + it to the set of dropped capabilities
61020 + otherwise, add the current level subject's mask to the current computed mask
61021 + */
61022 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
61023 + cap_raise(cap_mask, cap);
61024 + if (cap_raised(curracl->cap_lower, cap))
61025 + cap_raise(cap_drop, cap);
61026 + }
61027 + }
61028 +
61029 + if (!cap_raised(cap_drop, cap))
61030 + return 1;
61031 +
61032 + return 0;
61033 +}
61034 +
61035 +int
61036 +gr_acl_is_capable_nolog(const int cap)
61037 +{
61038 + return gr_task_acl_is_capable_nolog(current, cap);
61039 +}
61040 +
61041 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
61042 new file mode 100644
61043 index 0000000..a340c17
61044 --- /dev/null
61045 +++ b/grsecurity/gracl_fs.c
61046 @@ -0,0 +1,431 @@
61047 +#include <linux/kernel.h>
61048 +#include <linux/sched.h>
61049 +#include <linux/types.h>
61050 +#include <linux/fs.h>
61051 +#include <linux/file.h>
61052 +#include <linux/stat.h>
61053 +#include <linux/grsecurity.h>
61054 +#include <linux/grinternal.h>
61055 +#include <linux/gracl.h>
61056 +
61057 +umode_t
61058 +gr_acl_umask(void)
61059 +{
61060 + if (unlikely(!gr_acl_is_enabled()))
61061 + return 0;
61062 +
61063 + return current->role->umask;
61064 +}
61065 +
61066 +__u32
61067 +gr_acl_handle_hidden_file(const struct dentry * dentry,
61068 + const struct vfsmount * mnt)
61069 +{
61070 + __u32 mode;
61071 +
61072 + if (unlikely(!dentry->d_inode))
61073 + return GR_FIND;
61074 +
61075 + mode =
61076 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
61077 +
61078 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
61079 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61080 + return mode;
61081 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
61082 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
61083 + return 0;
61084 + } else if (unlikely(!(mode & GR_FIND)))
61085 + return 0;
61086 +
61087 + return GR_FIND;
61088 +}
61089 +
61090 +__u32
61091 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
61092 + int acc_mode)
61093 +{
61094 + __u32 reqmode = GR_FIND;
61095 + __u32 mode;
61096 +
61097 + if (unlikely(!dentry->d_inode))
61098 + return reqmode;
61099 +
61100 + if (acc_mode & MAY_APPEND)
61101 + reqmode |= GR_APPEND;
61102 + else if (acc_mode & MAY_WRITE)
61103 + reqmode |= GR_WRITE;
61104 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
61105 + reqmode |= GR_READ;
61106 +
61107 + mode =
61108 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61109 + mnt);
61110 +
61111 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61112 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61113 + reqmode & GR_READ ? " reading" : "",
61114 + reqmode & GR_WRITE ? " writing" : reqmode &
61115 + GR_APPEND ? " appending" : "");
61116 + return reqmode;
61117 + } else
61118 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61119 + {
61120 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
61121 + reqmode & GR_READ ? " reading" : "",
61122 + reqmode & GR_WRITE ? " writing" : reqmode &
61123 + GR_APPEND ? " appending" : "");
61124 + return 0;
61125 + } else if (unlikely((mode & reqmode) != reqmode))
61126 + return 0;
61127 +
61128 + return reqmode;
61129 +}
61130 +
61131 +__u32
61132 +gr_acl_handle_creat(const struct dentry * dentry,
61133 + const struct dentry * p_dentry,
61134 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
61135 + const int imode)
61136 +{
61137 + __u32 reqmode = GR_WRITE | GR_CREATE;
61138 + __u32 mode;
61139 +
61140 + if (acc_mode & MAY_APPEND)
61141 + reqmode |= GR_APPEND;
61142 + // if a directory was required or the directory already exists, then
61143 + // don't count this open as a read
61144 + if ((acc_mode & MAY_READ) &&
61145 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
61146 + reqmode |= GR_READ;
61147 + if ((open_flags & O_CREAT) &&
61148 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61149 + reqmode |= GR_SETID;
61150 +
61151 + mode =
61152 + gr_check_create(dentry, p_dentry, p_mnt,
61153 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61154 +
61155 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61156 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61157 + reqmode & GR_READ ? " reading" : "",
61158 + reqmode & GR_WRITE ? " writing" : reqmode &
61159 + GR_APPEND ? " appending" : "");
61160 + return reqmode;
61161 + } else
61162 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61163 + {
61164 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
61165 + reqmode & GR_READ ? " reading" : "",
61166 + reqmode & GR_WRITE ? " writing" : reqmode &
61167 + GR_APPEND ? " appending" : "");
61168 + return 0;
61169 + } else if (unlikely((mode & reqmode) != reqmode))
61170 + return 0;
61171 +
61172 + return reqmode;
61173 +}
61174 +
61175 +__u32
61176 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
61177 + const int fmode)
61178 +{
61179 + __u32 mode, reqmode = GR_FIND;
61180 +
61181 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
61182 + reqmode |= GR_EXEC;
61183 + if (fmode & S_IWOTH)
61184 + reqmode |= GR_WRITE;
61185 + if (fmode & S_IROTH)
61186 + reqmode |= GR_READ;
61187 +
61188 + mode =
61189 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
61190 + mnt);
61191 +
61192 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
61193 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61194 + reqmode & GR_READ ? " reading" : "",
61195 + reqmode & GR_WRITE ? " writing" : "",
61196 + reqmode & GR_EXEC ? " executing" : "");
61197 + return reqmode;
61198 + } else
61199 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
61200 + {
61201 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
61202 + reqmode & GR_READ ? " reading" : "",
61203 + reqmode & GR_WRITE ? " writing" : "",
61204 + reqmode & GR_EXEC ? " executing" : "");
61205 + return 0;
61206 + } else if (unlikely((mode & reqmode) != reqmode))
61207 + return 0;
61208 +
61209 + return reqmode;
61210 +}
61211 +
61212 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
61213 +{
61214 + __u32 mode;
61215 +
61216 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
61217 +
61218 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61219 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
61220 + return mode;
61221 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61222 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
61223 + return 0;
61224 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
61225 + return 0;
61226 +
61227 + return (reqmode);
61228 +}
61229 +
61230 +__u32
61231 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
61232 +{
61233 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
61234 +}
61235 +
61236 +__u32
61237 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
61238 +{
61239 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
61240 +}
61241 +
61242 +__u32
61243 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
61244 +{
61245 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
61246 +}
61247 +
61248 +__u32
61249 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
61250 +{
61251 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
61252 +}
61253 +
61254 +__u32
61255 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
61256 + umode_t *modeptr)
61257 +{
61258 + umode_t mode;
61259 +
61260 + *modeptr &= ~gr_acl_umask();
61261 + mode = *modeptr;
61262 +
61263 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
61264 + return 1;
61265 +
61266 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
61267 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
61268 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
61269 + GR_CHMOD_ACL_MSG);
61270 + } else {
61271 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
61272 + }
61273 +}
61274 +
61275 +__u32
61276 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
61277 +{
61278 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
61279 +}
61280 +
61281 +__u32
61282 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
61283 +{
61284 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
61285 +}
61286 +
61287 +__u32
61288 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
61289 +{
61290 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
61291 +}
61292 +
61293 +__u32
61294 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
61295 +{
61296 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
61297 + GR_UNIXCONNECT_ACL_MSG);
61298 +}
61299 +
61300 +/* hardlinks require at minimum create and link permission,
61301 + any additional privilege required is based on the
61302 + privilege of the file being linked to
61303 +*/
61304 +__u32
61305 +gr_acl_handle_link(const struct dentry * new_dentry,
61306 + const struct dentry * parent_dentry,
61307 + const struct vfsmount * parent_mnt,
61308 + const struct dentry * old_dentry,
61309 + const struct vfsmount * old_mnt, const struct filename *to)
61310 +{
61311 + __u32 mode;
61312 + __u32 needmode = GR_CREATE | GR_LINK;
61313 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
61314 +
61315 + mode =
61316 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
61317 + old_mnt);
61318 +
61319 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
61320 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61321 + return mode;
61322 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61323 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
61324 + return 0;
61325 + } else if (unlikely((mode & needmode) != needmode))
61326 + return 0;
61327 +
61328 + return 1;
61329 +}
61330 +
61331 +__u32
61332 +gr_acl_handle_symlink(const struct dentry * new_dentry,
61333 + const struct dentry * parent_dentry,
61334 + const struct vfsmount * parent_mnt, const struct filename *from)
61335 +{
61336 + __u32 needmode = GR_WRITE | GR_CREATE;
61337 + __u32 mode;
61338 +
61339 + mode =
61340 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
61341 + GR_CREATE | GR_AUDIT_CREATE |
61342 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
61343 +
61344 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
61345 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61346 + return mode;
61347 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
61348 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
61349 + return 0;
61350 + } else if (unlikely((mode & needmode) != needmode))
61351 + return 0;
61352 +
61353 + return (GR_WRITE | GR_CREATE);
61354 +}
61355 +
61356 +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)
61357 +{
61358 + __u32 mode;
61359 +
61360 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
61361 +
61362 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
61363 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
61364 + return mode;
61365 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
61366 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
61367 + return 0;
61368 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
61369 + return 0;
61370 +
61371 + return (reqmode);
61372 +}
61373 +
61374 +__u32
61375 +gr_acl_handle_mknod(const struct dentry * new_dentry,
61376 + const struct dentry * parent_dentry,
61377 + const struct vfsmount * parent_mnt,
61378 + const int mode)
61379 +{
61380 + __u32 reqmode = GR_WRITE | GR_CREATE;
61381 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
61382 + reqmode |= GR_SETID;
61383 +
61384 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61385 + reqmode, GR_MKNOD_ACL_MSG);
61386 +}
61387 +
61388 +__u32
61389 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
61390 + const struct dentry *parent_dentry,
61391 + const struct vfsmount *parent_mnt)
61392 +{
61393 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
61394 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
61395 +}
61396 +
61397 +#define RENAME_CHECK_SUCCESS(old, new) \
61398 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
61399 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
61400 +
61401 +int
61402 +gr_acl_handle_rename(struct dentry *new_dentry,
61403 + struct dentry *parent_dentry,
61404 + const struct vfsmount *parent_mnt,
61405 + struct dentry *old_dentry,
61406 + struct inode *old_parent_inode,
61407 + struct vfsmount *old_mnt, const struct filename *newname)
61408 +{
61409 + __u32 comp1, comp2;
61410 + int error = 0;
61411 +
61412 + if (unlikely(!gr_acl_is_enabled()))
61413 + return 0;
61414 +
61415 + if (!new_dentry->d_inode) {
61416 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
61417 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
61418 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
61419 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
61420 + GR_DELETE | GR_AUDIT_DELETE |
61421 + GR_AUDIT_READ | GR_AUDIT_WRITE |
61422 + GR_SUPPRESS, old_mnt);
61423 + } else {
61424 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
61425 + GR_CREATE | GR_DELETE |
61426 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
61427 + GR_AUDIT_READ | GR_AUDIT_WRITE |
61428 + GR_SUPPRESS, parent_mnt);
61429 + comp2 =
61430 + gr_search_file(old_dentry,
61431 + GR_READ | GR_WRITE | GR_AUDIT_READ |
61432 + GR_DELETE | GR_AUDIT_DELETE |
61433 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
61434 + }
61435 +
61436 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
61437 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
61438 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61439 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
61440 + && !(comp2 & GR_SUPPRESS)) {
61441 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
61442 + error = -EACCES;
61443 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
61444 + error = -EACCES;
61445 +
61446 + return error;
61447 +}
61448 +
61449 +void
61450 +gr_acl_handle_exit(void)
61451 +{
61452 + u16 id;
61453 + char *rolename;
61454 +
61455 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
61456 + !(current->role->roletype & GR_ROLE_PERSIST))) {
61457 + id = current->acl_role_id;
61458 + rolename = current->role->rolename;
61459 + gr_set_acls(1);
61460 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
61461 + }
61462 +
61463 + gr_put_exec_file(current);
61464 + return;
61465 +}
61466 +
61467 +int
61468 +gr_acl_handle_procpidmem(const struct task_struct *task)
61469 +{
61470 + if (unlikely(!gr_acl_is_enabled()))
61471 + return 0;
61472 +
61473 + if (task != current && task->acl->mode & GR_PROTPROCFD)
61474 + return -EACCES;
61475 +
61476 + return 0;
61477 +}
61478 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
61479 new file mode 100644
61480 index 0000000..4699807
61481 --- /dev/null
61482 +++ b/grsecurity/gracl_ip.c
61483 @@ -0,0 +1,384 @@
61484 +#include <linux/kernel.h>
61485 +#include <asm/uaccess.h>
61486 +#include <asm/errno.h>
61487 +#include <net/sock.h>
61488 +#include <linux/file.h>
61489 +#include <linux/fs.h>
61490 +#include <linux/net.h>
61491 +#include <linux/in.h>
61492 +#include <linux/skbuff.h>
61493 +#include <linux/ip.h>
61494 +#include <linux/udp.h>
61495 +#include <linux/types.h>
61496 +#include <linux/sched.h>
61497 +#include <linux/netdevice.h>
61498 +#include <linux/inetdevice.h>
61499 +#include <linux/gracl.h>
61500 +#include <linux/grsecurity.h>
61501 +#include <linux/grinternal.h>
61502 +
61503 +#define GR_BIND 0x01
61504 +#define GR_CONNECT 0x02
61505 +#define GR_INVERT 0x04
61506 +#define GR_BINDOVERRIDE 0x08
61507 +#define GR_CONNECTOVERRIDE 0x10
61508 +#define GR_SOCK_FAMILY 0x20
61509 +
61510 +static const char * gr_protocols[IPPROTO_MAX] = {
61511 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
61512 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
61513 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
61514 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
61515 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
61516 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
61517 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
61518 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
61519 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
61520 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
61521 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
61522 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
61523 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
61524 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
61525 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
61526 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
61527 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
61528 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
61529 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
61530 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
61531 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
61532 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
61533 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
61534 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
61535 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
61536 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
61537 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
61538 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
61539 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
61540 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
61541 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
61542 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
61543 + };
61544 +
61545 +static const char * gr_socktypes[SOCK_MAX] = {
61546 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
61547 + "unknown:7", "unknown:8", "unknown:9", "packet"
61548 + };
61549 +
61550 +static const char * gr_sockfamilies[AF_MAX+1] = {
61551 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
61552 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
61553 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
61554 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
61555 + };
61556 +
61557 +const char *
61558 +gr_proto_to_name(unsigned char proto)
61559 +{
61560 + return gr_protocols[proto];
61561 +}
61562 +
61563 +const char *
61564 +gr_socktype_to_name(unsigned char type)
61565 +{
61566 + return gr_socktypes[type];
61567 +}
61568 +
61569 +const char *
61570 +gr_sockfamily_to_name(unsigned char family)
61571 +{
61572 + return gr_sockfamilies[family];
61573 +}
61574 +
61575 +int
61576 +gr_search_socket(const int domain, const int type, const int protocol)
61577 +{
61578 + struct acl_subject_label *curr;
61579 + const struct cred *cred = current_cred();
61580 +
61581 + if (unlikely(!gr_acl_is_enabled()))
61582 + goto exit;
61583 +
61584 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
61585 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
61586 + goto exit; // let the kernel handle it
61587 +
61588 + curr = current->acl;
61589 +
61590 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
61591 + /* the family is allowed, if this is PF_INET allow it only if
61592 + the extra sock type/protocol checks pass */
61593 + if (domain == PF_INET)
61594 + goto inet_check;
61595 + goto exit;
61596 + } else {
61597 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61598 + __u32 fakeip = 0;
61599 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61600 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61601 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61602 + gr_to_filename(current->exec_file->f_path.dentry,
61603 + current->exec_file->f_path.mnt) :
61604 + curr->filename, curr->filename,
61605 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
61606 + &current->signal->saved_ip);
61607 + goto exit;
61608 + }
61609 + goto exit_fail;
61610 + }
61611 +
61612 +inet_check:
61613 + /* the rest of this checking is for IPv4 only */
61614 + if (!curr->ips)
61615 + goto exit;
61616 +
61617 + if ((curr->ip_type & (1 << type)) &&
61618 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
61619 + goto exit;
61620 +
61621 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61622 + /* we don't place acls on raw sockets , and sometimes
61623 + dgram/ip sockets are opened for ioctl and not
61624 + bind/connect, so we'll fake a bind learn log */
61625 + if (type == SOCK_RAW || type == SOCK_PACKET) {
61626 + __u32 fakeip = 0;
61627 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61628 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61629 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61630 + gr_to_filename(current->exec_file->f_path.dentry,
61631 + current->exec_file->f_path.mnt) :
61632 + curr->filename, curr->filename,
61633 + &fakeip, 0, type,
61634 + protocol, GR_CONNECT, &current->signal->saved_ip);
61635 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
61636 + __u32 fakeip = 0;
61637 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61638 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61639 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61640 + gr_to_filename(current->exec_file->f_path.dentry,
61641 + current->exec_file->f_path.mnt) :
61642 + curr->filename, curr->filename,
61643 + &fakeip, 0, type,
61644 + protocol, GR_BIND, &current->signal->saved_ip);
61645 + }
61646 + /* we'll log when they use connect or bind */
61647 + goto exit;
61648 + }
61649 +
61650 +exit_fail:
61651 + if (domain == PF_INET)
61652 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
61653 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
61654 + else
61655 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
61656 + gr_socktype_to_name(type), protocol);
61657 +
61658 + return 0;
61659 +exit:
61660 + return 1;
61661 +}
61662 +
61663 +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)
61664 +{
61665 + if ((ip->mode & mode) &&
61666 + (ip_port >= ip->low) &&
61667 + (ip_port <= ip->high) &&
61668 + ((ntohl(ip_addr) & our_netmask) ==
61669 + (ntohl(our_addr) & our_netmask))
61670 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
61671 + && (ip->type & (1 << type))) {
61672 + if (ip->mode & GR_INVERT)
61673 + return 2; // specifically denied
61674 + else
61675 + return 1; // allowed
61676 + }
61677 +
61678 + return 0; // not specifically allowed, may continue parsing
61679 +}
61680 +
61681 +static int
61682 +gr_search_connectbind(const int full_mode, struct sock *sk,
61683 + struct sockaddr_in *addr, const int type)
61684 +{
61685 + char iface[IFNAMSIZ] = {0};
61686 + struct acl_subject_label *curr;
61687 + struct acl_ip_label *ip;
61688 + struct inet_sock *isk;
61689 + struct net_device *dev;
61690 + struct in_device *idev;
61691 + unsigned long i;
61692 + int ret;
61693 + int mode = full_mode & (GR_BIND | GR_CONNECT);
61694 + __u32 ip_addr = 0;
61695 + __u32 our_addr;
61696 + __u32 our_netmask;
61697 + char *p;
61698 + __u16 ip_port = 0;
61699 + const struct cred *cred = current_cred();
61700 +
61701 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
61702 + return 0;
61703 +
61704 + curr = current->acl;
61705 + isk = inet_sk(sk);
61706 +
61707 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
61708 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
61709 + addr->sin_addr.s_addr = curr->inaddr_any_override;
61710 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
61711 + struct sockaddr_in saddr;
61712 + int err;
61713 +
61714 + saddr.sin_family = AF_INET;
61715 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
61716 + saddr.sin_port = isk->inet_sport;
61717 +
61718 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
61719 + if (err)
61720 + return err;
61721 +
61722 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
61723 + if (err)
61724 + return err;
61725 + }
61726 +
61727 + if (!curr->ips)
61728 + return 0;
61729 +
61730 + ip_addr = addr->sin_addr.s_addr;
61731 + ip_port = ntohs(addr->sin_port);
61732 +
61733 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
61734 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
61735 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
61736 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
61737 + gr_to_filename(current->exec_file->f_path.dentry,
61738 + current->exec_file->f_path.mnt) :
61739 + curr->filename, curr->filename,
61740 + &ip_addr, ip_port, type,
61741 + sk->sk_protocol, mode, &current->signal->saved_ip);
61742 + return 0;
61743 + }
61744 +
61745 + for (i = 0; i < curr->ip_num; i++) {
61746 + ip = *(curr->ips + i);
61747 + if (ip->iface != NULL) {
61748 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
61749 + p = strchr(iface, ':');
61750 + if (p != NULL)
61751 + *p = '\0';
61752 + dev = dev_get_by_name(sock_net(sk), iface);
61753 + if (dev == NULL)
61754 + continue;
61755 + idev = in_dev_get(dev);
61756 + if (idev == NULL) {
61757 + dev_put(dev);
61758 + continue;
61759 + }
61760 + rcu_read_lock();
61761 + for_ifa(idev) {
61762 + if (!strcmp(ip->iface, ifa->ifa_label)) {
61763 + our_addr = ifa->ifa_address;
61764 + our_netmask = 0xffffffff;
61765 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
61766 + if (ret == 1) {
61767 + rcu_read_unlock();
61768 + in_dev_put(idev);
61769 + dev_put(dev);
61770 + return 0;
61771 + } else if (ret == 2) {
61772 + rcu_read_unlock();
61773 + in_dev_put(idev);
61774 + dev_put(dev);
61775 + goto denied;
61776 + }
61777 + }
61778 + } endfor_ifa(idev);
61779 + rcu_read_unlock();
61780 + in_dev_put(idev);
61781 + dev_put(dev);
61782 + } else {
61783 + our_addr = ip->addr;
61784 + our_netmask = ip->netmask;
61785 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
61786 + if (ret == 1)
61787 + return 0;
61788 + else if (ret == 2)
61789 + goto denied;
61790 + }
61791 + }
61792 +
61793 +denied:
61794 + if (mode == GR_BIND)
61795 + 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));
61796 + else if (mode == GR_CONNECT)
61797 + 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));
61798 +
61799 + return -EACCES;
61800 +}
61801 +
61802 +int
61803 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
61804 +{
61805 + /* always allow disconnection of dgram sockets with connect */
61806 + if (addr->sin_family == AF_UNSPEC)
61807 + return 0;
61808 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
61809 +}
61810 +
61811 +int
61812 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
61813 +{
61814 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
61815 +}
61816 +
61817 +int gr_search_listen(struct socket *sock)
61818 +{
61819 + struct sock *sk = sock->sk;
61820 + struct sockaddr_in addr;
61821 +
61822 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
61823 + addr.sin_port = inet_sk(sk)->inet_sport;
61824 +
61825 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
61826 +}
61827 +
61828 +int gr_search_accept(struct socket *sock)
61829 +{
61830 + struct sock *sk = sock->sk;
61831 + struct sockaddr_in addr;
61832 +
61833 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
61834 + addr.sin_port = inet_sk(sk)->inet_sport;
61835 +
61836 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
61837 +}
61838 +
61839 +int
61840 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
61841 +{
61842 + if (addr)
61843 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
61844 + else {
61845 + struct sockaddr_in sin;
61846 + const struct inet_sock *inet = inet_sk(sk);
61847 +
61848 + sin.sin_addr.s_addr = inet->inet_daddr;
61849 + sin.sin_port = inet->inet_dport;
61850 +
61851 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
61852 + }
61853 +}
61854 +
61855 +int
61856 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
61857 +{
61858 + struct sockaddr_in sin;
61859 +
61860 + if (unlikely(skb->len < sizeof (struct udphdr)))
61861 + return 0; // skip this packet
61862 +
61863 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
61864 + sin.sin_port = udp_hdr(skb)->source;
61865 +
61866 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
61867 +}
61868 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
61869 new file mode 100644
61870 index 0000000..25f54ef
61871 --- /dev/null
61872 +++ b/grsecurity/gracl_learn.c
61873 @@ -0,0 +1,207 @@
61874 +#include <linux/kernel.h>
61875 +#include <linux/mm.h>
61876 +#include <linux/sched.h>
61877 +#include <linux/poll.h>
61878 +#include <linux/string.h>
61879 +#include <linux/file.h>
61880 +#include <linux/types.h>
61881 +#include <linux/vmalloc.h>
61882 +#include <linux/grinternal.h>
61883 +
61884 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
61885 + size_t count, loff_t *ppos);
61886 +extern int gr_acl_is_enabled(void);
61887 +
61888 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
61889 +static int gr_learn_attached;
61890 +
61891 +/* use a 512k buffer */
61892 +#define LEARN_BUFFER_SIZE (512 * 1024)
61893 +
61894 +static DEFINE_SPINLOCK(gr_learn_lock);
61895 +static DEFINE_MUTEX(gr_learn_user_mutex);
61896 +
61897 +/* we need to maintain two buffers, so that the kernel context of grlearn
61898 + uses a semaphore around the userspace copying, and the other kernel contexts
61899 + use a spinlock when copying into the buffer, since they cannot sleep
61900 +*/
61901 +static char *learn_buffer;
61902 +static char *learn_buffer_user;
61903 +static int learn_buffer_len;
61904 +static int learn_buffer_user_len;
61905 +
61906 +static ssize_t
61907 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
61908 +{
61909 + DECLARE_WAITQUEUE(wait, current);
61910 + ssize_t retval = 0;
61911 +
61912 + add_wait_queue(&learn_wait, &wait);
61913 + set_current_state(TASK_INTERRUPTIBLE);
61914 + do {
61915 + mutex_lock(&gr_learn_user_mutex);
61916 + spin_lock(&gr_learn_lock);
61917 + if (learn_buffer_len)
61918 + break;
61919 + spin_unlock(&gr_learn_lock);
61920 + mutex_unlock(&gr_learn_user_mutex);
61921 + if (file->f_flags & O_NONBLOCK) {
61922 + retval = -EAGAIN;
61923 + goto out;
61924 + }
61925 + if (signal_pending(current)) {
61926 + retval = -ERESTARTSYS;
61927 + goto out;
61928 + }
61929 +
61930 + schedule();
61931 + } while (1);
61932 +
61933 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
61934 + learn_buffer_user_len = learn_buffer_len;
61935 + retval = learn_buffer_len;
61936 + learn_buffer_len = 0;
61937 +
61938 + spin_unlock(&gr_learn_lock);
61939 +
61940 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
61941 + retval = -EFAULT;
61942 +
61943 + mutex_unlock(&gr_learn_user_mutex);
61944 +out:
61945 + set_current_state(TASK_RUNNING);
61946 + remove_wait_queue(&learn_wait, &wait);
61947 + return retval;
61948 +}
61949 +
61950 +static unsigned int
61951 +poll_learn(struct file * file, poll_table * wait)
61952 +{
61953 + poll_wait(file, &learn_wait, wait);
61954 +
61955 + if (learn_buffer_len)
61956 + return (POLLIN | POLLRDNORM);
61957 +
61958 + return 0;
61959 +}
61960 +
61961 +void
61962 +gr_clear_learn_entries(void)
61963 +{
61964 + char *tmp;
61965 +
61966 + mutex_lock(&gr_learn_user_mutex);
61967 + spin_lock(&gr_learn_lock);
61968 + tmp = learn_buffer;
61969 + learn_buffer = NULL;
61970 + spin_unlock(&gr_learn_lock);
61971 + if (tmp)
61972 + vfree(tmp);
61973 + if (learn_buffer_user != NULL) {
61974 + vfree(learn_buffer_user);
61975 + learn_buffer_user = NULL;
61976 + }
61977 + learn_buffer_len = 0;
61978 + mutex_unlock(&gr_learn_user_mutex);
61979 +
61980 + return;
61981 +}
61982 +
61983 +void
61984 +gr_add_learn_entry(const char *fmt, ...)
61985 +{
61986 + va_list args;
61987 + unsigned int len;
61988 +
61989 + if (!gr_learn_attached)
61990 + return;
61991 +
61992 + spin_lock(&gr_learn_lock);
61993 +
61994 + /* leave a gap at the end so we know when it's "full" but don't have to
61995 + compute the exact length of the string we're trying to append
61996 + */
61997 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
61998 + spin_unlock(&gr_learn_lock);
61999 + wake_up_interruptible(&learn_wait);
62000 + return;
62001 + }
62002 + if (learn_buffer == NULL) {
62003 + spin_unlock(&gr_learn_lock);
62004 + return;
62005 + }
62006 +
62007 + va_start(args, fmt);
62008 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
62009 + va_end(args);
62010 +
62011 + learn_buffer_len += len + 1;
62012 +
62013 + spin_unlock(&gr_learn_lock);
62014 + wake_up_interruptible(&learn_wait);
62015 +
62016 + return;
62017 +}
62018 +
62019 +static int
62020 +open_learn(struct inode *inode, struct file *file)
62021 +{
62022 + if (file->f_mode & FMODE_READ && gr_learn_attached)
62023 + return -EBUSY;
62024 + if (file->f_mode & FMODE_READ) {
62025 + int retval = 0;
62026 + mutex_lock(&gr_learn_user_mutex);
62027 + if (learn_buffer == NULL)
62028 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
62029 + if (learn_buffer_user == NULL)
62030 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
62031 + if (learn_buffer == NULL) {
62032 + retval = -ENOMEM;
62033 + goto out_error;
62034 + }
62035 + if (learn_buffer_user == NULL) {
62036 + retval = -ENOMEM;
62037 + goto out_error;
62038 + }
62039 + learn_buffer_len = 0;
62040 + learn_buffer_user_len = 0;
62041 + gr_learn_attached = 1;
62042 +out_error:
62043 + mutex_unlock(&gr_learn_user_mutex);
62044 + return retval;
62045 + }
62046 + return 0;
62047 +}
62048 +
62049 +static int
62050 +close_learn(struct inode *inode, struct file *file)
62051 +{
62052 + if (file->f_mode & FMODE_READ) {
62053 + char *tmp = NULL;
62054 + mutex_lock(&gr_learn_user_mutex);
62055 + spin_lock(&gr_learn_lock);
62056 + tmp = learn_buffer;
62057 + learn_buffer = NULL;
62058 + spin_unlock(&gr_learn_lock);
62059 + if (tmp)
62060 + vfree(tmp);
62061 + if (learn_buffer_user != NULL) {
62062 + vfree(learn_buffer_user);
62063 + learn_buffer_user = NULL;
62064 + }
62065 + learn_buffer_len = 0;
62066 + learn_buffer_user_len = 0;
62067 + gr_learn_attached = 0;
62068 + mutex_unlock(&gr_learn_user_mutex);
62069 + }
62070 +
62071 + return 0;
62072 +}
62073 +
62074 +const struct file_operations grsec_fops = {
62075 + .read = read_learn,
62076 + .write = write_grsec_handler,
62077 + .open = open_learn,
62078 + .release = close_learn,
62079 + .poll = poll_learn,
62080 +};
62081 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
62082 new file mode 100644
62083 index 0000000..39645c9
62084 --- /dev/null
62085 +++ b/grsecurity/gracl_res.c
62086 @@ -0,0 +1,68 @@
62087 +#include <linux/kernel.h>
62088 +#include <linux/sched.h>
62089 +#include <linux/gracl.h>
62090 +#include <linux/grinternal.h>
62091 +
62092 +static const char *restab_log[] = {
62093 + [RLIMIT_CPU] = "RLIMIT_CPU",
62094 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
62095 + [RLIMIT_DATA] = "RLIMIT_DATA",
62096 + [RLIMIT_STACK] = "RLIMIT_STACK",
62097 + [RLIMIT_CORE] = "RLIMIT_CORE",
62098 + [RLIMIT_RSS] = "RLIMIT_RSS",
62099 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
62100 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
62101 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
62102 + [RLIMIT_AS] = "RLIMIT_AS",
62103 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
62104 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
62105 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
62106 + [RLIMIT_NICE] = "RLIMIT_NICE",
62107 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
62108 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
62109 + [GR_CRASH_RES] = "RLIMIT_CRASH"
62110 +};
62111 +
62112 +void
62113 +gr_log_resource(const struct task_struct *task,
62114 + const int res, const unsigned long wanted, const int gt)
62115 +{
62116 + const struct cred *cred;
62117 + unsigned long rlim;
62118 +
62119 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
62120 + return;
62121 +
62122 + // not yet supported resource
62123 + if (unlikely(!restab_log[res]))
62124 + return;
62125 +
62126 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
62127 + rlim = task_rlimit_max(task, res);
62128 + else
62129 + rlim = task_rlimit(task, res);
62130 +
62131 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
62132 + return;
62133 +
62134 + rcu_read_lock();
62135 + cred = __task_cred(task);
62136 +
62137 + if (res == RLIMIT_NPROC &&
62138 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
62139 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
62140 + goto out_rcu_unlock;
62141 + else if (res == RLIMIT_MEMLOCK &&
62142 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
62143 + goto out_rcu_unlock;
62144 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
62145 + goto out_rcu_unlock;
62146 + rcu_read_unlock();
62147 +
62148 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
62149 +
62150 + return;
62151 +out_rcu_unlock:
62152 + rcu_read_unlock();
62153 + return;
62154 +}
62155 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
62156 new file mode 100644
62157 index 0000000..8c8fc9d
62158 --- /dev/null
62159 +++ b/grsecurity/gracl_segv.c
62160 @@ -0,0 +1,303 @@
62161 +#include <linux/kernel.h>
62162 +#include <linux/mm.h>
62163 +#include <asm/uaccess.h>
62164 +#include <asm/errno.h>
62165 +#include <asm/mman.h>
62166 +#include <net/sock.h>
62167 +#include <linux/file.h>
62168 +#include <linux/fs.h>
62169 +#include <linux/net.h>
62170 +#include <linux/in.h>
62171 +#include <linux/slab.h>
62172 +#include <linux/types.h>
62173 +#include <linux/sched.h>
62174 +#include <linux/timer.h>
62175 +#include <linux/gracl.h>
62176 +#include <linux/grsecurity.h>
62177 +#include <linux/grinternal.h>
62178 +
62179 +static struct crash_uid *uid_set;
62180 +static unsigned short uid_used;
62181 +static DEFINE_SPINLOCK(gr_uid_lock);
62182 +extern rwlock_t gr_inode_lock;
62183 +extern struct acl_subject_label *
62184 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
62185 + struct acl_role_label *role);
62186 +
62187 +#ifdef CONFIG_BTRFS_FS
62188 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
62189 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
62190 +#endif
62191 +
62192 +static inline dev_t __get_dev(const struct dentry *dentry)
62193 +{
62194 +#ifdef CONFIG_BTRFS_FS
62195 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
62196 + return get_btrfs_dev_from_inode(dentry->d_inode);
62197 + else
62198 +#endif
62199 + return dentry->d_inode->i_sb->s_dev;
62200 +}
62201 +
62202 +int
62203 +gr_init_uidset(void)
62204 +{
62205 + uid_set =
62206 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
62207 + uid_used = 0;
62208 +
62209 + return uid_set ? 1 : 0;
62210 +}
62211 +
62212 +void
62213 +gr_free_uidset(void)
62214 +{
62215 + if (uid_set)
62216 + kfree(uid_set);
62217 +
62218 + return;
62219 +}
62220 +
62221 +int
62222 +gr_find_uid(const uid_t uid)
62223 +{
62224 + struct crash_uid *tmp = uid_set;
62225 + uid_t buid;
62226 + int low = 0, high = uid_used - 1, mid;
62227 +
62228 + while (high >= low) {
62229 + mid = (low + high) >> 1;
62230 + buid = tmp[mid].uid;
62231 + if (buid == uid)
62232 + return mid;
62233 + if (buid > uid)
62234 + high = mid - 1;
62235 + if (buid < uid)
62236 + low = mid + 1;
62237 + }
62238 +
62239 + return -1;
62240 +}
62241 +
62242 +static __inline__ void
62243 +gr_insertsort(void)
62244 +{
62245 + unsigned short i, j;
62246 + struct crash_uid index;
62247 +
62248 + for (i = 1; i < uid_used; i++) {
62249 + index = uid_set[i];
62250 + j = i;
62251 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
62252 + uid_set[j] = uid_set[j - 1];
62253 + j--;
62254 + }
62255 + uid_set[j] = index;
62256 + }
62257 +
62258 + return;
62259 +}
62260 +
62261 +static __inline__ void
62262 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
62263 +{
62264 + int loc;
62265 + uid_t uid = GR_GLOBAL_UID(kuid);
62266 +
62267 + if (uid_used == GR_UIDTABLE_MAX)
62268 + return;
62269 +
62270 + loc = gr_find_uid(uid);
62271 +
62272 + if (loc >= 0) {
62273 + uid_set[loc].expires = expires;
62274 + return;
62275 + }
62276 +
62277 + uid_set[uid_used].uid = uid;
62278 + uid_set[uid_used].expires = expires;
62279 + uid_used++;
62280 +
62281 + gr_insertsort();
62282 +
62283 + return;
62284 +}
62285 +
62286 +void
62287 +gr_remove_uid(const unsigned short loc)
62288 +{
62289 + unsigned short i;
62290 +
62291 + for (i = loc + 1; i < uid_used; i++)
62292 + uid_set[i - 1] = uid_set[i];
62293 +
62294 + uid_used--;
62295 +
62296 + return;
62297 +}
62298 +
62299 +int
62300 +gr_check_crash_uid(const kuid_t kuid)
62301 +{
62302 + int loc;
62303 + int ret = 0;
62304 + uid_t uid;
62305 +
62306 + if (unlikely(!gr_acl_is_enabled()))
62307 + return 0;
62308 +
62309 + uid = GR_GLOBAL_UID(kuid);
62310 +
62311 + spin_lock(&gr_uid_lock);
62312 + loc = gr_find_uid(uid);
62313 +
62314 + if (loc < 0)
62315 + goto out_unlock;
62316 +
62317 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
62318 + gr_remove_uid(loc);
62319 + else
62320 + ret = 1;
62321 +
62322 +out_unlock:
62323 + spin_unlock(&gr_uid_lock);
62324 + return ret;
62325 +}
62326 +
62327 +static __inline__ int
62328 +proc_is_setxid(const struct cred *cred)
62329 +{
62330 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
62331 + !uid_eq(cred->uid, cred->fsuid))
62332 + return 1;
62333 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
62334 + !gid_eq(cred->gid, cred->fsgid))
62335 + return 1;
62336 +
62337 + return 0;
62338 +}
62339 +
62340 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
62341 +
62342 +void
62343 +gr_handle_crash(struct task_struct *task, const int sig)
62344 +{
62345 + struct acl_subject_label *curr;
62346 + struct task_struct *tsk, *tsk2;
62347 + const struct cred *cred;
62348 + const struct cred *cred2;
62349 +
62350 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
62351 + return;
62352 +
62353 + if (unlikely(!gr_acl_is_enabled()))
62354 + return;
62355 +
62356 + curr = task->acl;
62357 +
62358 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
62359 + return;
62360 +
62361 + if (time_before_eq(curr->expires, get_seconds())) {
62362 + curr->expires = 0;
62363 + curr->crashes = 0;
62364 + }
62365 +
62366 + curr->crashes++;
62367 +
62368 + if (!curr->expires)
62369 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
62370 +
62371 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62372 + time_after(curr->expires, get_seconds())) {
62373 + rcu_read_lock();
62374 + cred = __task_cred(task);
62375 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
62376 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62377 + spin_lock(&gr_uid_lock);
62378 + gr_insert_uid(cred->uid, curr->expires);
62379 + spin_unlock(&gr_uid_lock);
62380 + curr->expires = 0;
62381 + curr->crashes = 0;
62382 + read_lock(&tasklist_lock);
62383 + do_each_thread(tsk2, tsk) {
62384 + cred2 = __task_cred(tsk);
62385 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
62386 + gr_fake_force_sig(SIGKILL, tsk);
62387 + } while_each_thread(tsk2, tsk);
62388 + read_unlock(&tasklist_lock);
62389 + } else {
62390 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
62391 + read_lock(&tasklist_lock);
62392 + read_lock(&grsec_exec_file_lock);
62393 + do_each_thread(tsk2, tsk) {
62394 + if (likely(tsk != task)) {
62395 + // if this thread has the same subject as the one that triggered
62396 + // RES_CRASH and it's the same binary, kill it
62397 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
62398 + gr_fake_force_sig(SIGKILL, tsk);
62399 + }
62400 + } while_each_thread(tsk2, tsk);
62401 + read_unlock(&grsec_exec_file_lock);
62402 + read_unlock(&tasklist_lock);
62403 + }
62404 + rcu_read_unlock();
62405 + }
62406 +
62407 + return;
62408 +}
62409 +
62410 +int
62411 +gr_check_crash_exec(const struct file *filp)
62412 +{
62413 + struct acl_subject_label *curr;
62414 +
62415 + if (unlikely(!gr_acl_is_enabled()))
62416 + return 0;
62417 +
62418 + read_lock(&gr_inode_lock);
62419 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
62420 + __get_dev(filp->f_path.dentry),
62421 + current->role);
62422 + read_unlock(&gr_inode_lock);
62423 +
62424 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
62425 + (!curr->crashes && !curr->expires))
62426 + return 0;
62427 +
62428 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
62429 + time_after(curr->expires, get_seconds()))
62430 + return 1;
62431 + else if (time_before_eq(curr->expires, get_seconds())) {
62432 + curr->crashes = 0;
62433 + curr->expires = 0;
62434 + }
62435 +
62436 + return 0;
62437 +}
62438 +
62439 +void
62440 +gr_handle_alertkill(struct task_struct *task)
62441 +{
62442 + struct acl_subject_label *curracl;
62443 + __u32 curr_ip;
62444 + struct task_struct *p, *p2;
62445 +
62446 + if (unlikely(!gr_acl_is_enabled()))
62447 + return;
62448 +
62449 + curracl = task->acl;
62450 + curr_ip = task->signal->curr_ip;
62451 +
62452 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
62453 + read_lock(&tasklist_lock);
62454 + do_each_thread(p2, p) {
62455 + if (p->signal->curr_ip == curr_ip)
62456 + gr_fake_force_sig(SIGKILL, p);
62457 + } while_each_thread(p2, p);
62458 + read_unlock(&tasklist_lock);
62459 + } else if (curracl->mode & GR_KILLPROC)
62460 + gr_fake_force_sig(SIGKILL, task);
62461 +
62462 + return;
62463 +}
62464 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
62465 new file mode 100644
62466 index 0000000..98011b0
62467 --- /dev/null
62468 +++ b/grsecurity/gracl_shm.c
62469 @@ -0,0 +1,40 @@
62470 +#include <linux/kernel.h>
62471 +#include <linux/mm.h>
62472 +#include <linux/sched.h>
62473 +#include <linux/file.h>
62474 +#include <linux/ipc.h>
62475 +#include <linux/gracl.h>
62476 +#include <linux/grsecurity.h>
62477 +#include <linux/grinternal.h>
62478 +
62479 +int
62480 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62481 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
62482 +{
62483 + struct task_struct *task;
62484 +
62485 + if (!gr_acl_is_enabled())
62486 + return 1;
62487 +
62488 + rcu_read_lock();
62489 + read_lock(&tasklist_lock);
62490 +
62491 + task = find_task_by_vpid(shm_cprid);
62492 +
62493 + if (unlikely(!task))
62494 + task = find_task_by_vpid(shm_lapid);
62495 +
62496 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
62497 + (task_pid_nr(task) == shm_lapid)) &&
62498 + (task->acl->mode & GR_PROTSHM) &&
62499 + (task->acl != current->acl))) {
62500 + read_unlock(&tasklist_lock);
62501 + rcu_read_unlock();
62502 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
62503 + return 0;
62504 + }
62505 + read_unlock(&tasklist_lock);
62506 + rcu_read_unlock();
62507 +
62508 + return 1;
62509 +}
62510 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
62511 new file mode 100644
62512 index 0000000..bc0be01
62513 --- /dev/null
62514 +++ b/grsecurity/grsec_chdir.c
62515 @@ -0,0 +1,19 @@
62516 +#include <linux/kernel.h>
62517 +#include <linux/sched.h>
62518 +#include <linux/fs.h>
62519 +#include <linux/file.h>
62520 +#include <linux/grsecurity.h>
62521 +#include <linux/grinternal.h>
62522 +
62523 +void
62524 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
62525 +{
62526 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
62527 + if ((grsec_enable_chdir && grsec_enable_group &&
62528 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
62529 + !grsec_enable_group)) {
62530 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
62531 + }
62532 +#endif
62533 + return;
62534 +}
62535 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
62536 new file mode 100644
62537 index 0000000..6d2de57
62538 --- /dev/null
62539 +++ b/grsecurity/grsec_chroot.c
62540 @@ -0,0 +1,357 @@
62541 +#include <linux/kernel.h>
62542 +#include <linux/module.h>
62543 +#include <linux/sched.h>
62544 +#include <linux/file.h>
62545 +#include <linux/fs.h>
62546 +#include <linux/mount.h>
62547 +#include <linux/types.h>
62548 +#include "../fs/mount.h"
62549 +#include <linux/grsecurity.h>
62550 +#include <linux/grinternal.h>
62551 +
62552 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
62553 +{
62554 +#ifdef CONFIG_GRKERNSEC
62555 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
62556 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
62557 + task->gr_is_chrooted = 1;
62558 + else
62559 + task->gr_is_chrooted = 0;
62560 +
62561 + task->gr_chroot_dentry = path->dentry;
62562 +#endif
62563 + return;
62564 +}
62565 +
62566 +void gr_clear_chroot_entries(struct task_struct *task)
62567 +{
62568 +#ifdef CONFIG_GRKERNSEC
62569 + task->gr_is_chrooted = 0;
62570 + task->gr_chroot_dentry = NULL;
62571 +#endif
62572 + return;
62573 +}
62574 +
62575 +int
62576 +gr_handle_chroot_unix(const pid_t pid)
62577 +{
62578 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
62579 + struct task_struct *p;
62580 +
62581 + if (unlikely(!grsec_enable_chroot_unix))
62582 + return 1;
62583 +
62584 + if (likely(!proc_is_chrooted(current)))
62585 + return 1;
62586 +
62587 + rcu_read_lock();
62588 + read_lock(&tasklist_lock);
62589 + p = find_task_by_vpid_unrestricted(pid);
62590 + if (unlikely(p && !have_same_root(current, p))) {
62591 + read_unlock(&tasklist_lock);
62592 + rcu_read_unlock();
62593 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
62594 + return 0;
62595 + }
62596 + read_unlock(&tasklist_lock);
62597 + rcu_read_unlock();
62598 +#endif
62599 + return 1;
62600 +}
62601 +
62602 +int
62603 +gr_handle_chroot_nice(void)
62604 +{
62605 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62606 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
62607 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
62608 + return -EPERM;
62609 + }
62610 +#endif
62611 + return 0;
62612 +}
62613 +
62614 +int
62615 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
62616 +{
62617 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
62618 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
62619 + && proc_is_chrooted(current)) {
62620 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
62621 + return -EACCES;
62622 + }
62623 +#endif
62624 + return 0;
62625 +}
62626 +
62627 +int
62628 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
62629 +{
62630 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62631 + struct task_struct *p;
62632 + int ret = 0;
62633 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
62634 + return ret;
62635 +
62636 + read_lock(&tasklist_lock);
62637 + do_each_pid_task(pid, type, p) {
62638 + if (!have_same_root(current, p)) {
62639 + ret = 1;
62640 + goto out;
62641 + }
62642 + } while_each_pid_task(pid, type, p);
62643 +out:
62644 + read_unlock(&tasklist_lock);
62645 + return ret;
62646 +#endif
62647 + return 0;
62648 +}
62649 +
62650 +int
62651 +gr_pid_is_chrooted(struct task_struct *p)
62652 +{
62653 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62654 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
62655 + return 0;
62656 +
62657 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
62658 + !have_same_root(current, p)) {
62659 + return 1;
62660 + }
62661 +#endif
62662 + return 0;
62663 +}
62664 +
62665 +EXPORT_SYMBOL(gr_pid_is_chrooted);
62666 +
62667 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
62668 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
62669 +{
62670 + struct path path, currentroot;
62671 + int ret = 0;
62672 +
62673 + path.dentry = (struct dentry *)u_dentry;
62674 + path.mnt = (struct vfsmount *)u_mnt;
62675 + get_fs_root(current->fs, &currentroot);
62676 + if (path_is_under(&path, &currentroot))
62677 + ret = 1;
62678 + path_put(&currentroot);
62679 +
62680 + return ret;
62681 +}
62682 +#endif
62683 +
62684 +int
62685 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
62686 +{
62687 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
62688 + if (!grsec_enable_chroot_fchdir)
62689 + return 1;
62690 +
62691 + if (!proc_is_chrooted(current))
62692 + return 1;
62693 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
62694 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
62695 + return 0;
62696 + }
62697 +#endif
62698 + return 1;
62699 +}
62700 +
62701 +int
62702 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
62703 + const time_t shm_createtime)
62704 +{
62705 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
62706 + struct task_struct *p;
62707 + time_t starttime;
62708 +
62709 + if (unlikely(!grsec_enable_chroot_shmat))
62710 + return 1;
62711 +
62712 + if (likely(!proc_is_chrooted(current)))
62713 + return 1;
62714 +
62715 + rcu_read_lock();
62716 + read_lock(&tasklist_lock);
62717 +
62718 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
62719 + starttime = p->start_time.tv_sec;
62720 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
62721 + if (have_same_root(current, p)) {
62722 + goto allow;
62723 + } else {
62724 + read_unlock(&tasklist_lock);
62725 + rcu_read_unlock();
62726 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
62727 + return 0;
62728 + }
62729 + }
62730 + /* creator exited, pid reuse, fall through to next check */
62731 + }
62732 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
62733 + if (unlikely(!have_same_root(current, p))) {
62734 + read_unlock(&tasklist_lock);
62735 + rcu_read_unlock();
62736 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
62737 + return 0;
62738 + }
62739 + }
62740 +
62741 +allow:
62742 + read_unlock(&tasklist_lock);
62743 + rcu_read_unlock();
62744 +#endif
62745 + return 1;
62746 +}
62747 +
62748 +void
62749 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
62750 +{
62751 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
62752 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
62753 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
62754 +#endif
62755 + return;
62756 +}
62757 +
62758 +int
62759 +gr_handle_chroot_mknod(const struct dentry *dentry,
62760 + const struct vfsmount *mnt, const int mode)
62761 +{
62762 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
62763 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
62764 + proc_is_chrooted(current)) {
62765 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
62766 + return -EPERM;
62767 + }
62768 +#endif
62769 + return 0;
62770 +}
62771 +
62772 +int
62773 +gr_handle_chroot_mount(const struct dentry *dentry,
62774 + const struct vfsmount *mnt, const char *dev_name)
62775 +{
62776 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
62777 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
62778 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
62779 + return -EPERM;
62780 + }
62781 +#endif
62782 + return 0;
62783 +}
62784 +
62785 +int
62786 +gr_handle_chroot_pivot(void)
62787 +{
62788 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
62789 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
62790 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
62791 + return -EPERM;
62792 + }
62793 +#endif
62794 + return 0;
62795 +}
62796 +
62797 +int
62798 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
62799 +{
62800 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
62801 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
62802 + !gr_is_outside_chroot(dentry, mnt)) {
62803 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
62804 + return -EPERM;
62805 + }
62806 +#endif
62807 + return 0;
62808 +}
62809 +
62810 +extern const char *captab_log[];
62811 +extern int captab_log_entries;
62812 +
62813 +int
62814 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
62815 +{
62816 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62817 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
62818 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
62819 + if (cap_raised(chroot_caps, cap)) {
62820 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
62821 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
62822 + }
62823 + return 0;
62824 + }
62825 + }
62826 +#endif
62827 + return 1;
62828 +}
62829 +
62830 +int
62831 +gr_chroot_is_capable(const int cap)
62832 +{
62833 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62834 + return gr_task_chroot_is_capable(current, current_cred(), cap);
62835 +#endif
62836 + return 1;
62837 +}
62838 +
62839 +int
62840 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
62841 +{
62842 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62843 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
62844 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
62845 + if (cap_raised(chroot_caps, cap)) {
62846 + return 0;
62847 + }
62848 + }
62849 +#endif
62850 + return 1;
62851 +}
62852 +
62853 +int
62854 +gr_chroot_is_capable_nolog(const int cap)
62855 +{
62856 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
62857 + return gr_task_chroot_is_capable_nolog(current, cap);
62858 +#endif
62859 + return 1;
62860 +}
62861 +
62862 +int
62863 +gr_handle_chroot_sysctl(const int op)
62864 +{
62865 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
62866 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
62867 + proc_is_chrooted(current))
62868 + return -EACCES;
62869 +#endif
62870 + return 0;
62871 +}
62872 +
62873 +void
62874 +gr_handle_chroot_chdir(struct path *path)
62875 +{
62876 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
62877 + if (grsec_enable_chroot_chdir)
62878 + set_fs_pwd(current->fs, path);
62879 +#endif
62880 + return;
62881 +}
62882 +
62883 +int
62884 +gr_handle_chroot_chmod(const struct dentry *dentry,
62885 + const struct vfsmount *mnt, const int mode)
62886 +{
62887 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
62888 + /* allow chmod +s on directories, but not files */
62889 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
62890 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
62891 + proc_is_chrooted(current)) {
62892 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
62893 + return -EPERM;
62894 + }
62895 +#endif
62896 + return 0;
62897 +}
62898 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
62899 new file mode 100644
62900 index 0000000..207d409
62901 --- /dev/null
62902 +++ b/grsecurity/grsec_disabled.c
62903 @@ -0,0 +1,434 @@
62904 +#include <linux/kernel.h>
62905 +#include <linux/module.h>
62906 +#include <linux/sched.h>
62907 +#include <linux/file.h>
62908 +#include <linux/fs.h>
62909 +#include <linux/kdev_t.h>
62910 +#include <linux/net.h>
62911 +#include <linux/in.h>
62912 +#include <linux/ip.h>
62913 +#include <linux/skbuff.h>
62914 +#include <linux/sysctl.h>
62915 +
62916 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
62917 +void
62918 +pax_set_initial_flags(struct linux_binprm *bprm)
62919 +{
62920 + return;
62921 +}
62922 +#endif
62923 +
62924 +#ifdef CONFIG_SYSCTL
62925 +__u32
62926 +gr_handle_sysctl(const struct ctl_table * table, const int op)
62927 +{
62928 + return 0;
62929 +}
62930 +#endif
62931 +
62932 +#ifdef CONFIG_TASKSTATS
62933 +int gr_is_taskstats_denied(int pid)
62934 +{
62935 + return 0;
62936 +}
62937 +#endif
62938 +
62939 +int
62940 +gr_acl_is_enabled(void)
62941 +{
62942 + return 0;
62943 +}
62944 +
62945 +void
62946 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
62947 +{
62948 + return;
62949 +}
62950 +
62951 +int
62952 +gr_handle_rawio(const struct inode *inode)
62953 +{
62954 + return 0;
62955 +}
62956 +
62957 +void
62958 +gr_acl_handle_psacct(struct task_struct *task, const long code)
62959 +{
62960 + return;
62961 +}
62962 +
62963 +int
62964 +gr_handle_ptrace(struct task_struct *task, const long request)
62965 +{
62966 + return 0;
62967 +}
62968 +
62969 +int
62970 +gr_handle_proc_ptrace(struct task_struct *task)
62971 +{
62972 + return 0;
62973 +}
62974 +
62975 +int
62976 +gr_set_acls(const int type)
62977 +{
62978 + return 0;
62979 +}
62980 +
62981 +int
62982 +gr_check_hidden_task(const struct task_struct *tsk)
62983 +{
62984 + return 0;
62985 +}
62986 +
62987 +int
62988 +gr_check_protected_task(const struct task_struct *task)
62989 +{
62990 + return 0;
62991 +}
62992 +
62993 +int
62994 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
62995 +{
62996 + return 0;
62997 +}
62998 +
62999 +void
63000 +gr_copy_label(struct task_struct *tsk)
63001 +{
63002 + return;
63003 +}
63004 +
63005 +void
63006 +gr_set_pax_flags(struct task_struct *task)
63007 +{
63008 + return;
63009 +}
63010 +
63011 +int
63012 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
63013 + const int unsafe_share)
63014 +{
63015 + return 0;
63016 +}
63017 +
63018 +void
63019 +gr_handle_delete(const ino_t ino, const dev_t dev)
63020 +{
63021 + return;
63022 +}
63023 +
63024 +void
63025 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
63026 +{
63027 + return;
63028 +}
63029 +
63030 +void
63031 +gr_handle_crash(struct task_struct *task, const int sig)
63032 +{
63033 + return;
63034 +}
63035 +
63036 +int
63037 +gr_check_crash_exec(const struct file *filp)
63038 +{
63039 + return 0;
63040 +}
63041 +
63042 +int
63043 +gr_check_crash_uid(const kuid_t uid)
63044 +{
63045 + return 0;
63046 +}
63047 +
63048 +void
63049 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
63050 + struct dentry *old_dentry,
63051 + struct dentry *new_dentry,
63052 + struct vfsmount *mnt, const __u8 replace)
63053 +{
63054 + return;
63055 +}
63056 +
63057 +int
63058 +gr_search_socket(const int family, const int type, const int protocol)
63059 +{
63060 + return 1;
63061 +}
63062 +
63063 +int
63064 +gr_search_connectbind(const int mode, const struct socket *sock,
63065 + const struct sockaddr_in *addr)
63066 +{
63067 + return 0;
63068 +}
63069 +
63070 +void
63071 +gr_handle_alertkill(struct task_struct *task)
63072 +{
63073 + return;
63074 +}
63075 +
63076 +__u32
63077 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
63078 +{
63079 + return 1;
63080 +}
63081 +
63082 +__u32
63083 +gr_acl_handle_hidden_file(const struct dentry * dentry,
63084 + const struct vfsmount * mnt)
63085 +{
63086 + return 1;
63087 +}
63088 +
63089 +__u32
63090 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
63091 + int acc_mode)
63092 +{
63093 + return 1;
63094 +}
63095 +
63096 +__u32
63097 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
63098 +{
63099 + return 1;
63100 +}
63101 +
63102 +__u32
63103 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
63104 +{
63105 + return 1;
63106 +}
63107 +
63108 +int
63109 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
63110 + unsigned int *vm_flags)
63111 +{
63112 + return 1;
63113 +}
63114 +
63115 +__u32
63116 +gr_acl_handle_truncate(const struct dentry * dentry,
63117 + const struct vfsmount * mnt)
63118 +{
63119 + return 1;
63120 +}
63121 +
63122 +__u32
63123 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
63124 +{
63125 + return 1;
63126 +}
63127 +
63128 +__u32
63129 +gr_acl_handle_access(const struct dentry * dentry,
63130 + const struct vfsmount * mnt, const int fmode)
63131 +{
63132 + return 1;
63133 +}
63134 +
63135 +__u32
63136 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
63137 + umode_t *mode)
63138 +{
63139 + return 1;
63140 +}
63141 +
63142 +__u32
63143 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
63144 +{
63145 + return 1;
63146 +}
63147 +
63148 +__u32
63149 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
63150 +{
63151 + return 1;
63152 +}
63153 +
63154 +void
63155 +grsecurity_init(void)
63156 +{
63157 + return;
63158 +}
63159 +
63160 +umode_t gr_acl_umask(void)
63161 +{
63162 + return 0;
63163 +}
63164 +
63165 +__u32
63166 +gr_acl_handle_mknod(const struct dentry * new_dentry,
63167 + const struct dentry * parent_dentry,
63168 + const struct vfsmount * parent_mnt,
63169 + const int mode)
63170 +{
63171 + return 1;
63172 +}
63173 +
63174 +__u32
63175 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
63176 + const struct dentry * parent_dentry,
63177 + const struct vfsmount * parent_mnt)
63178 +{
63179 + return 1;
63180 +}
63181 +
63182 +__u32
63183 +gr_acl_handle_symlink(const struct dentry * new_dentry,
63184 + const struct dentry * parent_dentry,
63185 + const struct vfsmount * parent_mnt, const struct filename *from)
63186 +{
63187 + return 1;
63188 +}
63189 +
63190 +__u32
63191 +gr_acl_handle_link(const struct dentry * new_dentry,
63192 + const struct dentry * parent_dentry,
63193 + const struct vfsmount * parent_mnt,
63194 + const struct dentry * old_dentry,
63195 + const struct vfsmount * old_mnt, const struct filename *to)
63196 +{
63197 + return 1;
63198 +}
63199 +
63200 +int
63201 +gr_acl_handle_rename(const struct dentry *new_dentry,
63202 + const struct dentry *parent_dentry,
63203 + const struct vfsmount *parent_mnt,
63204 + const struct dentry *old_dentry,
63205 + const struct inode *old_parent_inode,
63206 + const struct vfsmount *old_mnt, const struct filename *newname)
63207 +{
63208 + return 0;
63209 +}
63210 +
63211 +int
63212 +gr_acl_handle_filldir(const struct file *file, const char *name,
63213 + const int namelen, const ino_t ino)
63214 +{
63215 + return 1;
63216 +}
63217 +
63218 +int
63219 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
63220 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
63221 +{
63222 + return 1;
63223 +}
63224 +
63225 +int
63226 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
63227 +{
63228 + return 0;
63229 +}
63230 +
63231 +int
63232 +gr_search_accept(const struct socket *sock)
63233 +{
63234 + return 0;
63235 +}
63236 +
63237 +int
63238 +gr_search_listen(const struct socket *sock)
63239 +{
63240 + return 0;
63241 +}
63242 +
63243 +int
63244 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
63245 +{
63246 + return 0;
63247 +}
63248 +
63249 +__u32
63250 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
63251 +{
63252 + return 1;
63253 +}
63254 +
63255 +__u32
63256 +gr_acl_handle_creat(const struct dentry * dentry,
63257 + const struct dentry * p_dentry,
63258 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
63259 + const int imode)
63260 +{
63261 + return 1;
63262 +}
63263 +
63264 +void
63265 +gr_acl_handle_exit(void)
63266 +{
63267 + return;
63268 +}
63269 +
63270 +int
63271 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
63272 +{
63273 + return 1;
63274 +}
63275 +
63276 +void
63277 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
63278 +{
63279 + return;
63280 +}
63281 +
63282 +int
63283 +gr_acl_handle_procpidmem(const struct task_struct *task)
63284 +{
63285 + return 0;
63286 +}
63287 +
63288 +int
63289 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
63290 +{
63291 + return 0;
63292 +}
63293 +
63294 +int
63295 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
63296 +{
63297 + return 0;
63298 +}
63299 +
63300 +void
63301 +gr_set_kernel_label(struct task_struct *task)
63302 +{
63303 + return;
63304 +}
63305 +
63306 +int
63307 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
63308 +{
63309 + return 0;
63310 +}
63311 +
63312 +int
63313 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
63314 +{
63315 + return 0;
63316 +}
63317 +
63318 +int gr_acl_enable_at_secure(void)
63319 +{
63320 + return 0;
63321 +}
63322 +
63323 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
63324 +{
63325 + return dentry->d_inode->i_sb->s_dev;
63326 +}
63327 +
63328 +void gr_put_exec_file(struct task_struct *task)
63329 +{
63330 + return;
63331 +}
63332 +
63333 +EXPORT_SYMBOL(gr_set_kernel_label);
63334 +#ifdef CONFIG_SECURITY
63335 +EXPORT_SYMBOL(gr_check_user_change);
63336 +EXPORT_SYMBOL(gr_check_group_change);
63337 +#endif
63338 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
63339 new file mode 100644
63340 index 0000000..abfa971
63341 --- /dev/null
63342 +++ b/grsecurity/grsec_exec.c
63343 @@ -0,0 +1,174 @@
63344 +#include <linux/kernel.h>
63345 +#include <linux/sched.h>
63346 +#include <linux/file.h>
63347 +#include <linux/binfmts.h>
63348 +#include <linux/fs.h>
63349 +#include <linux/types.h>
63350 +#include <linux/grdefs.h>
63351 +#include <linux/grsecurity.h>
63352 +#include <linux/grinternal.h>
63353 +#include <linux/capability.h>
63354 +#include <linux/module.h>
63355 +
63356 +#include <asm/uaccess.h>
63357 +
63358 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63359 +static char gr_exec_arg_buf[132];
63360 +static DEFINE_MUTEX(gr_exec_arg_mutex);
63361 +#endif
63362 +
63363 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
63364 +
63365 +void
63366 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
63367 +{
63368 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63369 + char *grarg = gr_exec_arg_buf;
63370 + unsigned int i, x, execlen = 0;
63371 + char c;
63372 +
63373 + if (!((grsec_enable_execlog && grsec_enable_group &&
63374 + in_group_p(grsec_audit_gid))
63375 + || (grsec_enable_execlog && !grsec_enable_group)))
63376 + return;
63377 +
63378 + mutex_lock(&gr_exec_arg_mutex);
63379 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
63380 +
63381 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
63382 + const char __user *p;
63383 + unsigned int len;
63384 +
63385 + p = get_user_arg_ptr(argv, i);
63386 + if (IS_ERR(p))
63387 + goto log;
63388 +
63389 + len = strnlen_user(p, 128 - execlen);
63390 + if (len > 128 - execlen)
63391 + len = 128 - execlen;
63392 + else if (len > 0)
63393 + len--;
63394 + if (copy_from_user(grarg + execlen, p, len))
63395 + goto log;
63396 +
63397 + /* rewrite unprintable characters */
63398 + for (x = 0; x < len; x++) {
63399 + c = *(grarg + execlen + x);
63400 + if (c < 32 || c > 126)
63401 + *(grarg + execlen + x) = ' ';
63402 + }
63403 +
63404 + execlen += len;
63405 + *(grarg + execlen) = ' ';
63406 + *(grarg + execlen + 1) = '\0';
63407 + execlen++;
63408 + }
63409 +
63410 + log:
63411 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
63412 + bprm->file->f_path.mnt, grarg);
63413 + mutex_unlock(&gr_exec_arg_mutex);
63414 +#endif
63415 + return;
63416 +}
63417 +
63418 +#ifdef CONFIG_GRKERNSEC
63419 +extern int gr_acl_is_capable(const int cap);
63420 +extern int gr_acl_is_capable_nolog(const int cap);
63421 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63422 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
63423 +extern int gr_chroot_is_capable(const int cap);
63424 +extern int gr_chroot_is_capable_nolog(const int cap);
63425 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
63426 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
63427 +#endif
63428 +
63429 +const char *captab_log[] = {
63430 + "CAP_CHOWN",
63431 + "CAP_DAC_OVERRIDE",
63432 + "CAP_DAC_READ_SEARCH",
63433 + "CAP_FOWNER",
63434 + "CAP_FSETID",
63435 + "CAP_KILL",
63436 + "CAP_SETGID",
63437 + "CAP_SETUID",
63438 + "CAP_SETPCAP",
63439 + "CAP_LINUX_IMMUTABLE",
63440 + "CAP_NET_BIND_SERVICE",
63441 + "CAP_NET_BROADCAST",
63442 + "CAP_NET_ADMIN",
63443 + "CAP_NET_RAW",
63444 + "CAP_IPC_LOCK",
63445 + "CAP_IPC_OWNER",
63446 + "CAP_SYS_MODULE",
63447 + "CAP_SYS_RAWIO",
63448 + "CAP_SYS_CHROOT",
63449 + "CAP_SYS_PTRACE",
63450 + "CAP_SYS_PACCT",
63451 + "CAP_SYS_ADMIN",
63452 + "CAP_SYS_BOOT",
63453 + "CAP_SYS_NICE",
63454 + "CAP_SYS_RESOURCE",
63455 + "CAP_SYS_TIME",
63456 + "CAP_SYS_TTY_CONFIG",
63457 + "CAP_MKNOD",
63458 + "CAP_LEASE",
63459 + "CAP_AUDIT_WRITE",
63460 + "CAP_AUDIT_CONTROL",
63461 + "CAP_SETFCAP",
63462 + "CAP_MAC_OVERRIDE",
63463 + "CAP_MAC_ADMIN",
63464 + "CAP_SYSLOG",
63465 + "CAP_WAKE_ALARM"
63466 +};
63467 +
63468 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
63469 +
63470 +int gr_is_capable(const int cap)
63471 +{
63472 +#ifdef CONFIG_GRKERNSEC
63473 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
63474 + return 1;
63475 + return 0;
63476 +#else
63477 + return 1;
63478 +#endif
63479 +}
63480 +
63481 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
63482 +{
63483 +#ifdef CONFIG_GRKERNSEC
63484 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
63485 + return 1;
63486 + return 0;
63487 +#else
63488 + return 1;
63489 +#endif
63490 +}
63491 +
63492 +int gr_is_capable_nolog(const int cap)
63493 +{
63494 +#ifdef CONFIG_GRKERNSEC
63495 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
63496 + return 1;
63497 + return 0;
63498 +#else
63499 + return 1;
63500 +#endif
63501 +}
63502 +
63503 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
63504 +{
63505 +#ifdef CONFIG_GRKERNSEC
63506 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
63507 + return 1;
63508 + return 0;
63509 +#else
63510 + return 1;
63511 +#endif
63512 +}
63513 +
63514 +EXPORT_SYMBOL(gr_is_capable);
63515 +EXPORT_SYMBOL(gr_is_capable_nolog);
63516 +EXPORT_SYMBOL(gr_task_is_capable);
63517 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
63518 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
63519 new file mode 100644
63520 index 0000000..06cc6ea
63521 --- /dev/null
63522 +++ b/grsecurity/grsec_fifo.c
63523 @@ -0,0 +1,24 @@
63524 +#include <linux/kernel.h>
63525 +#include <linux/sched.h>
63526 +#include <linux/fs.h>
63527 +#include <linux/file.h>
63528 +#include <linux/grinternal.h>
63529 +
63530 +int
63531 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
63532 + const struct dentry *dir, const int flag, const int acc_mode)
63533 +{
63534 +#ifdef CONFIG_GRKERNSEC_FIFO
63535 + const struct cred *cred = current_cred();
63536 +
63537 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
63538 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
63539 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
63540 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
63541 + if (!inode_permission(dentry->d_inode, acc_mode))
63542 + 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));
63543 + return -EACCES;
63544 + }
63545 +#endif
63546 + return 0;
63547 +}
63548 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
63549 new file mode 100644
63550 index 0000000..8ca18bf
63551 --- /dev/null
63552 +++ b/grsecurity/grsec_fork.c
63553 @@ -0,0 +1,23 @@
63554 +#include <linux/kernel.h>
63555 +#include <linux/sched.h>
63556 +#include <linux/grsecurity.h>
63557 +#include <linux/grinternal.h>
63558 +#include <linux/errno.h>
63559 +
63560 +void
63561 +gr_log_forkfail(const int retval)
63562 +{
63563 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
63564 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
63565 + switch (retval) {
63566 + case -EAGAIN:
63567 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
63568 + break;
63569 + case -ENOMEM:
63570 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
63571 + break;
63572 + }
63573 + }
63574 +#endif
63575 + return;
63576 +}
63577 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
63578 new file mode 100644
63579 index 0000000..a862e9f
63580 --- /dev/null
63581 +++ b/grsecurity/grsec_init.c
63582 @@ -0,0 +1,283 @@
63583 +#include <linux/kernel.h>
63584 +#include <linux/sched.h>
63585 +#include <linux/mm.h>
63586 +#include <linux/gracl.h>
63587 +#include <linux/slab.h>
63588 +#include <linux/vmalloc.h>
63589 +#include <linux/percpu.h>
63590 +#include <linux/module.h>
63591 +
63592 +int grsec_enable_ptrace_readexec;
63593 +int grsec_enable_setxid;
63594 +int grsec_enable_symlinkown;
63595 +kgid_t grsec_symlinkown_gid;
63596 +int grsec_enable_brute;
63597 +int grsec_enable_link;
63598 +int grsec_enable_dmesg;
63599 +int grsec_enable_harden_ptrace;
63600 +int grsec_enable_fifo;
63601 +int grsec_enable_execlog;
63602 +int grsec_enable_signal;
63603 +int grsec_enable_forkfail;
63604 +int grsec_enable_audit_ptrace;
63605 +int grsec_enable_time;
63606 +int grsec_enable_audit_textrel;
63607 +int grsec_enable_group;
63608 +kgid_t grsec_audit_gid;
63609 +int grsec_enable_chdir;
63610 +int grsec_enable_mount;
63611 +int grsec_enable_rofs;
63612 +int grsec_enable_chroot_findtask;
63613 +int grsec_enable_chroot_mount;
63614 +int grsec_enable_chroot_shmat;
63615 +int grsec_enable_chroot_fchdir;
63616 +int grsec_enable_chroot_double;
63617 +int grsec_enable_chroot_pivot;
63618 +int grsec_enable_chroot_chdir;
63619 +int grsec_enable_chroot_chmod;
63620 +int grsec_enable_chroot_mknod;
63621 +int grsec_enable_chroot_nice;
63622 +int grsec_enable_chroot_execlog;
63623 +int grsec_enable_chroot_caps;
63624 +int grsec_enable_chroot_sysctl;
63625 +int grsec_enable_chroot_unix;
63626 +int grsec_enable_tpe;
63627 +kgid_t grsec_tpe_gid;
63628 +int grsec_enable_blackhole;
63629 +#ifdef CONFIG_IPV6_MODULE
63630 +EXPORT_SYMBOL(grsec_enable_blackhole);
63631 +#endif
63632 +int grsec_lastack_retries;
63633 +int grsec_enable_tpe_all;
63634 +int grsec_enable_tpe_invert;
63635 +int grsec_enable_socket_all;
63636 +kgid_t grsec_socket_all_gid;
63637 +int grsec_enable_socket_client;
63638 +kgid_t grsec_socket_client_gid;
63639 +int grsec_enable_socket_server;
63640 +kgid_t grsec_socket_server_gid;
63641 +int grsec_resource_logging;
63642 +int grsec_disable_privio;
63643 +int grsec_enable_log_rwxmaps;
63644 +int grsec_lock;
63645 +
63646 +DEFINE_SPINLOCK(grsec_alert_lock);
63647 +unsigned long grsec_alert_wtime = 0;
63648 +unsigned long grsec_alert_fyet = 0;
63649 +
63650 +DEFINE_SPINLOCK(grsec_audit_lock);
63651 +
63652 +DEFINE_RWLOCK(grsec_exec_file_lock);
63653 +
63654 +char *gr_shared_page[4];
63655 +
63656 +char *gr_alert_log_fmt;
63657 +char *gr_audit_log_fmt;
63658 +char *gr_alert_log_buf;
63659 +char *gr_audit_log_buf;
63660 +
63661 +extern struct gr_arg *gr_usermode;
63662 +extern unsigned char *gr_system_salt;
63663 +extern unsigned char *gr_system_sum;
63664 +
63665 +void __init
63666 +grsecurity_init(void)
63667 +{
63668 + int j;
63669 + /* create the per-cpu shared pages */
63670 +
63671 +#ifdef CONFIG_X86
63672 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
63673 +#endif
63674 +
63675 + for (j = 0; j < 4; j++) {
63676 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
63677 + if (gr_shared_page[j] == NULL) {
63678 + panic("Unable to allocate grsecurity shared page");
63679 + return;
63680 + }
63681 + }
63682 +
63683 + /* allocate log buffers */
63684 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
63685 + if (!gr_alert_log_fmt) {
63686 + panic("Unable to allocate grsecurity alert log format buffer");
63687 + return;
63688 + }
63689 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
63690 + if (!gr_audit_log_fmt) {
63691 + panic("Unable to allocate grsecurity audit log format buffer");
63692 + return;
63693 + }
63694 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
63695 + if (!gr_alert_log_buf) {
63696 + panic("Unable to allocate grsecurity alert log buffer");
63697 + return;
63698 + }
63699 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
63700 + if (!gr_audit_log_buf) {
63701 + panic("Unable to allocate grsecurity audit log buffer");
63702 + return;
63703 + }
63704 +
63705 + /* allocate memory for authentication structure */
63706 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
63707 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
63708 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
63709 +
63710 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
63711 + panic("Unable to allocate grsecurity authentication structure");
63712 + return;
63713 + }
63714 +
63715 +
63716 +#ifdef CONFIG_GRKERNSEC_IO
63717 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
63718 + grsec_disable_privio = 1;
63719 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
63720 + grsec_disable_privio = 1;
63721 +#else
63722 + grsec_disable_privio = 0;
63723 +#endif
63724 +#endif
63725 +
63726 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
63727 + /* for backward compatibility, tpe_invert always defaults to on if
63728 + enabled in the kernel
63729 + */
63730 + grsec_enable_tpe_invert = 1;
63731 +#endif
63732 +
63733 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
63734 +#ifndef CONFIG_GRKERNSEC_SYSCTL
63735 + grsec_lock = 1;
63736 +#endif
63737 +
63738 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
63739 + grsec_enable_audit_textrel = 1;
63740 +#endif
63741 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
63742 + grsec_enable_log_rwxmaps = 1;
63743 +#endif
63744 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
63745 + grsec_enable_group = 1;
63746 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
63747 +#endif
63748 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
63749 + grsec_enable_ptrace_readexec = 1;
63750 +#endif
63751 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
63752 + grsec_enable_chdir = 1;
63753 +#endif
63754 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
63755 + grsec_enable_harden_ptrace = 1;
63756 +#endif
63757 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
63758 + grsec_enable_mount = 1;
63759 +#endif
63760 +#ifdef CONFIG_GRKERNSEC_LINK
63761 + grsec_enable_link = 1;
63762 +#endif
63763 +#ifdef CONFIG_GRKERNSEC_BRUTE
63764 + grsec_enable_brute = 1;
63765 +#endif
63766 +#ifdef CONFIG_GRKERNSEC_DMESG
63767 + grsec_enable_dmesg = 1;
63768 +#endif
63769 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
63770 + grsec_enable_blackhole = 1;
63771 + grsec_lastack_retries = 4;
63772 +#endif
63773 +#ifdef CONFIG_GRKERNSEC_FIFO
63774 + grsec_enable_fifo = 1;
63775 +#endif
63776 +#ifdef CONFIG_GRKERNSEC_EXECLOG
63777 + grsec_enable_execlog = 1;
63778 +#endif
63779 +#ifdef CONFIG_GRKERNSEC_SETXID
63780 + grsec_enable_setxid = 1;
63781 +#endif
63782 +#ifdef CONFIG_GRKERNSEC_SIGNAL
63783 + grsec_enable_signal = 1;
63784 +#endif
63785 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
63786 + grsec_enable_forkfail = 1;
63787 +#endif
63788 +#ifdef CONFIG_GRKERNSEC_TIME
63789 + grsec_enable_time = 1;
63790 +#endif
63791 +#ifdef CONFIG_GRKERNSEC_RESLOG
63792 + grsec_resource_logging = 1;
63793 +#endif
63794 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
63795 + grsec_enable_chroot_findtask = 1;
63796 +#endif
63797 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
63798 + grsec_enable_chroot_unix = 1;
63799 +#endif
63800 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
63801 + grsec_enable_chroot_mount = 1;
63802 +#endif
63803 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
63804 + grsec_enable_chroot_fchdir = 1;
63805 +#endif
63806 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
63807 + grsec_enable_chroot_shmat = 1;
63808 +#endif
63809 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
63810 + grsec_enable_audit_ptrace = 1;
63811 +#endif
63812 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
63813 + grsec_enable_chroot_double = 1;
63814 +#endif
63815 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
63816 + grsec_enable_chroot_pivot = 1;
63817 +#endif
63818 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
63819 + grsec_enable_chroot_chdir = 1;
63820 +#endif
63821 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
63822 + grsec_enable_chroot_chmod = 1;
63823 +#endif
63824 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
63825 + grsec_enable_chroot_mknod = 1;
63826 +#endif
63827 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
63828 + grsec_enable_chroot_nice = 1;
63829 +#endif
63830 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
63831 + grsec_enable_chroot_execlog = 1;
63832 +#endif
63833 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
63834 + grsec_enable_chroot_caps = 1;
63835 +#endif
63836 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
63837 + grsec_enable_chroot_sysctl = 1;
63838 +#endif
63839 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
63840 + grsec_enable_symlinkown = 1;
63841 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
63842 +#endif
63843 +#ifdef CONFIG_GRKERNSEC_TPE
63844 + grsec_enable_tpe = 1;
63845 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
63846 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
63847 + grsec_enable_tpe_all = 1;
63848 +#endif
63849 +#endif
63850 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
63851 + grsec_enable_socket_all = 1;
63852 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
63853 +#endif
63854 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
63855 + grsec_enable_socket_client = 1;
63856 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
63857 +#endif
63858 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
63859 + grsec_enable_socket_server = 1;
63860 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
63861 +#endif
63862 +#endif
63863 +
63864 + return;
63865 +}
63866 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
63867 new file mode 100644
63868 index 0000000..5e05e20
63869 --- /dev/null
63870 +++ b/grsecurity/grsec_link.c
63871 @@ -0,0 +1,58 @@
63872 +#include <linux/kernel.h>
63873 +#include <linux/sched.h>
63874 +#include <linux/fs.h>
63875 +#include <linux/file.h>
63876 +#include <linux/grinternal.h>
63877 +
63878 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
63879 +{
63880 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
63881 + const struct inode *link_inode = link->dentry->d_inode;
63882 +
63883 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
63884 + /* ignore root-owned links, e.g. /proc/self */
63885 + gr_is_global_nonroot(link_inode->i_uid) && target &&
63886 + !uid_eq(link_inode->i_uid, target->i_uid)) {
63887 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
63888 + return 1;
63889 + }
63890 +#endif
63891 + return 0;
63892 +}
63893 +
63894 +int
63895 +gr_handle_follow_link(const struct inode *parent,
63896 + const struct inode *inode,
63897 + const struct dentry *dentry, const struct vfsmount *mnt)
63898 +{
63899 +#ifdef CONFIG_GRKERNSEC_LINK
63900 + const struct cred *cred = current_cred();
63901 +
63902 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
63903 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
63904 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
63905 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
63906 + return -EACCES;
63907 + }
63908 +#endif
63909 + return 0;
63910 +}
63911 +
63912 +int
63913 +gr_handle_hardlink(const struct dentry *dentry,
63914 + const struct vfsmount *mnt,
63915 + struct inode *inode, const int mode, const struct filename *to)
63916 +{
63917 +#ifdef CONFIG_GRKERNSEC_LINK
63918 + const struct cred *cred = current_cred();
63919 +
63920 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
63921 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
63922 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
63923 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
63924 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
63925 + return -EPERM;
63926 + }
63927 +#endif
63928 + return 0;
63929 +}
63930 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
63931 new file mode 100644
63932 index 0000000..7c06085
63933 --- /dev/null
63934 +++ b/grsecurity/grsec_log.c
63935 @@ -0,0 +1,326 @@
63936 +#include <linux/kernel.h>
63937 +#include <linux/sched.h>
63938 +#include <linux/file.h>
63939 +#include <linux/tty.h>
63940 +#include <linux/fs.h>
63941 +#include <linux/grinternal.h>
63942 +
63943 +#ifdef CONFIG_TREE_PREEMPT_RCU
63944 +#define DISABLE_PREEMPT() preempt_disable()
63945 +#define ENABLE_PREEMPT() preempt_enable()
63946 +#else
63947 +#define DISABLE_PREEMPT()
63948 +#define ENABLE_PREEMPT()
63949 +#endif
63950 +
63951 +#define BEGIN_LOCKS(x) \
63952 + DISABLE_PREEMPT(); \
63953 + rcu_read_lock(); \
63954 + read_lock(&tasklist_lock); \
63955 + read_lock(&grsec_exec_file_lock); \
63956 + if (x != GR_DO_AUDIT) \
63957 + spin_lock(&grsec_alert_lock); \
63958 + else \
63959 + spin_lock(&grsec_audit_lock)
63960 +
63961 +#define END_LOCKS(x) \
63962 + if (x != GR_DO_AUDIT) \
63963 + spin_unlock(&grsec_alert_lock); \
63964 + else \
63965 + spin_unlock(&grsec_audit_lock); \
63966 + read_unlock(&grsec_exec_file_lock); \
63967 + read_unlock(&tasklist_lock); \
63968 + rcu_read_unlock(); \
63969 + ENABLE_PREEMPT(); \
63970 + if (x == GR_DONT_AUDIT) \
63971 + gr_handle_alertkill(current)
63972 +
63973 +enum {
63974 + FLOODING,
63975 + NO_FLOODING
63976 +};
63977 +
63978 +extern char *gr_alert_log_fmt;
63979 +extern char *gr_audit_log_fmt;
63980 +extern char *gr_alert_log_buf;
63981 +extern char *gr_audit_log_buf;
63982 +
63983 +static int gr_log_start(int audit)
63984 +{
63985 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
63986 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
63987 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
63988 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
63989 + unsigned long curr_secs = get_seconds();
63990 +
63991 + if (audit == GR_DO_AUDIT)
63992 + goto set_fmt;
63993 +
63994 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
63995 + grsec_alert_wtime = curr_secs;
63996 + grsec_alert_fyet = 0;
63997 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
63998 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
63999 + grsec_alert_fyet++;
64000 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
64001 + grsec_alert_wtime = curr_secs;
64002 + grsec_alert_fyet++;
64003 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
64004 + return FLOODING;
64005 + }
64006 + else return FLOODING;
64007 +
64008 +set_fmt:
64009 +#endif
64010 + memset(buf, 0, PAGE_SIZE);
64011 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
64012 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
64013 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64014 + } else if (current->signal->curr_ip) {
64015 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
64016 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
64017 + } else if (gr_acl_is_enabled()) {
64018 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
64019 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
64020 + } else {
64021 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
64022 + strcpy(buf, fmt);
64023 + }
64024 +
64025 + return NO_FLOODING;
64026 +}
64027 +
64028 +static void gr_log_middle(int audit, const char *msg, va_list ap)
64029 + __attribute__ ((format (printf, 2, 0)));
64030 +
64031 +static void gr_log_middle(int audit, const char *msg, va_list ap)
64032 +{
64033 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64034 + unsigned int len = strlen(buf);
64035 +
64036 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64037 +
64038 + return;
64039 +}
64040 +
64041 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
64042 + __attribute__ ((format (printf, 2, 3)));
64043 +
64044 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
64045 +{
64046 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64047 + unsigned int len = strlen(buf);
64048 + va_list ap;
64049 +
64050 + va_start(ap, msg);
64051 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
64052 + va_end(ap);
64053 +
64054 + return;
64055 +}
64056 +
64057 +static void gr_log_end(int audit, int append_default)
64058 +{
64059 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
64060 + if (append_default) {
64061 + struct task_struct *task = current;
64062 + struct task_struct *parent = task->real_parent;
64063 + const struct cred *cred = __task_cred(task);
64064 + const struct cred *pcred = __task_cred(parent);
64065 + unsigned int len = strlen(buf);
64066 +
64067 + 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));
64068 + }
64069 +
64070 + printk("%s\n", buf);
64071 +
64072 + return;
64073 +}
64074 +
64075 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
64076 +{
64077 + int logtype;
64078 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
64079 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
64080 + void *voidptr = NULL;
64081 + int num1 = 0, num2 = 0;
64082 + unsigned long ulong1 = 0, ulong2 = 0;
64083 + struct dentry *dentry = NULL;
64084 + struct vfsmount *mnt = NULL;
64085 + struct file *file = NULL;
64086 + struct task_struct *task = NULL;
64087 + const struct cred *cred, *pcred;
64088 + va_list ap;
64089 +
64090 + BEGIN_LOCKS(audit);
64091 + logtype = gr_log_start(audit);
64092 + if (logtype == FLOODING) {
64093 + END_LOCKS(audit);
64094 + return;
64095 + }
64096 + va_start(ap, argtypes);
64097 + switch (argtypes) {
64098 + case GR_TTYSNIFF:
64099 + task = va_arg(ap, struct task_struct *);
64100 + 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));
64101 + break;
64102 + case GR_SYSCTL_HIDDEN:
64103 + str1 = va_arg(ap, char *);
64104 + gr_log_middle_varargs(audit, msg, result, str1);
64105 + break;
64106 + case GR_RBAC:
64107 + dentry = va_arg(ap, struct dentry *);
64108 + mnt = va_arg(ap, struct vfsmount *);
64109 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
64110 + break;
64111 + case GR_RBAC_STR:
64112 + dentry = va_arg(ap, struct dentry *);
64113 + mnt = va_arg(ap, struct vfsmount *);
64114 + str1 = va_arg(ap, char *);
64115 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
64116 + break;
64117 + case GR_STR_RBAC:
64118 + str1 = va_arg(ap, char *);
64119 + dentry = va_arg(ap, struct dentry *);
64120 + mnt = va_arg(ap, struct vfsmount *);
64121 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
64122 + break;
64123 + case GR_RBAC_MODE2:
64124 + dentry = va_arg(ap, struct dentry *);
64125 + mnt = va_arg(ap, struct vfsmount *);
64126 + str1 = va_arg(ap, char *);
64127 + str2 = va_arg(ap, char *);
64128 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
64129 + break;
64130 + case GR_RBAC_MODE3:
64131 + dentry = va_arg(ap, struct dentry *);
64132 + mnt = va_arg(ap, struct vfsmount *);
64133 + str1 = va_arg(ap, char *);
64134 + str2 = va_arg(ap, char *);
64135 + str3 = va_arg(ap, char *);
64136 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
64137 + break;
64138 + case GR_FILENAME:
64139 + dentry = va_arg(ap, struct dentry *);
64140 + mnt = va_arg(ap, struct vfsmount *);
64141 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
64142 + break;
64143 + case GR_STR_FILENAME:
64144 + str1 = va_arg(ap, char *);
64145 + dentry = va_arg(ap, struct dentry *);
64146 + mnt = va_arg(ap, struct vfsmount *);
64147 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
64148 + break;
64149 + case GR_FILENAME_STR:
64150 + dentry = va_arg(ap, struct dentry *);
64151 + mnt = va_arg(ap, struct vfsmount *);
64152 + str1 = va_arg(ap, char *);
64153 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
64154 + break;
64155 + case GR_FILENAME_TWO_INT:
64156 + dentry = va_arg(ap, struct dentry *);
64157 + mnt = va_arg(ap, struct vfsmount *);
64158 + num1 = va_arg(ap, int);
64159 + num2 = va_arg(ap, int);
64160 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
64161 + break;
64162 + case GR_FILENAME_TWO_INT_STR:
64163 + dentry = va_arg(ap, struct dentry *);
64164 + mnt = va_arg(ap, struct vfsmount *);
64165 + num1 = va_arg(ap, int);
64166 + num2 = va_arg(ap, int);
64167 + str1 = va_arg(ap, char *);
64168 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
64169 + break;
64170 + case GR_TEXTREL:
64171 + file = va_arg(ap, struct file *);
64172 + ulong1 = va_arg(ap, unsigned long);
64173 + ulong2 = va_arg(ap, unsigned long);
64174 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
64175 + break;
64176 + case GR_PTRACE:
64177 + task = va_arg(ap, struct task_struct *);
64178 + 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));
64179 + break;
64180 + case GR_RESOURCE:
64181 + task = va_arg(ap, struct task_struct *);
64182 + cred = __task_cred(task);
64183 + pcred = __task_cred(task->real_parent);
64184 + ulong1 = va_arg(ap, unsigned long);
64185 + str1 = va_arg(ap, char *);
64186 + ulong2 = va_arg(ap, unsigned long);
64187 + 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));
64188 + break;
64189 + case GR_CAP:
64190 + task = va_arg(ap, struct task_struct *);
64191 + cred = __task_cred(task);
64192 + pcred = __task_cred(task->real_parent);
64193 + str1 = va_arg(ap, char *);
64194 + 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));
64195 + break;
64196 + case GR_SIG:
64197 + str1 = va_arg(ap, char *);
64198 + voidptr = va_arg(ap, void *);
64199 + gr_log_middle_varargs(audit, msg, str1, voidptr);
64200 + break;
64201 + case GR_SIG2:
64202 + task = va_arg(ap, struct task_struct *);
64203 + cred = __task_cred(task);
64204 + pcred = __task_cred(task->real_parent);
64205 + num1 = va_arg(ap, int);
64206 + 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));
64207 + break;
64208 + case GR_CRASH1:
64209 + task = va_arg(ap, struct task_struct *);
64210 + cred = __task_cred(task);
64211 + pcred = __task_cred(task->real_parent);
64212 + ulong1 = va_arg(ap, unsigned long);
64213 + 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);
64214 + break;
64215 + case GR_CRASH2:
64216 + task = va_arg(ap, struct task_struct *);
64217 + cred = __task_cred(task);
64218 + pcred = __task_cred(task->real_parent);
64219 + ulong1 = va_arg(ap, unsigned long);
64220 + 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);
64221 + break;
64222 + case GR_RWXMAP:
64223 + file = va_arg(ap, struct file *);
64224 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
64225 + break;
64226 + case GR_PSACCT:
64227 + {
64228 + unsigned int wday, cday;
64229 + __u8 whr, chr;
64230 + __u8 wmin, cmin;
64231 + __u8 wsec, csec;
64232 + char cur_tty[64] = { 0 };
64233 + char parent_tty[64] = { 0 };
64234 +
64235 + task = va_arg(ap, struct task_struct *);
64236 + wday = va_arg(ap, unsigned int);
64237 + cday = va_arg(ap, unsigned int);
64238 + whr = va_arg(ap, int);
64239 + chr = va_arg(ap, int);
64240 + wmin = va_arg(ap, int);
64241 + cmin = va_arg(ap, int);
64242 + wsec = va_arg(ap, int);
64243 + csec = va_arg(ap, int);
64244 + ulong1 = va_arg(ap, unsigned long);
64245 + cred = __task_cred(task);
64246 + pcred = __task_cred(task->real_parent);
64247 +
64248 + 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));
64249 + }
64250 + break;
64251 + default:
64252 + gr_log_middle(audit, msg, ap);
64253 + }
64254 + va_end(ap);
64255 + // these don't need DEFAULTSECARGS printed on the end
64256 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
64257 + gr_log_end(audit, 0);
64258 + else
64259 + gr_log_end(audit, 1);
64260 + END_LOCKS(audit);
64261 +}
64262 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
64263 new file mode 100644
64264 index 0000000..f536303
64265 --- /dev/null
64266 +++ b/grsecurity/grsec_mem.c
64267 @@ -0,0 +1,40 @@
64268 +#include <linux/kernel.h>
64269 +#include <linux/sched.h>
64270 +#include <linux/mm.h>
64271 +#include <linux/mman.h>
64272 +#include <linux/grinternal.h>
64273 +
64274 +void
64275 +gr_handle_ioperm(void)
64276 +{
64277 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
64278 + return;
64279 +}
64280 +
64281 +void
64282 +gr_handle_iopl(void)
64283 +{
64284 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
64285 + return;
64286 +}
64287 +
64288 +void
64289 +gr_handle_mem_readwrite(u64 from, u64 to)
64290 +{
64291 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
64292 + return;
64293 +}
64294 +
64295 +void
64296 +gr_handle_vm86(void)
64297 +{
64298 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
64299 + return;
64300 +}
64301 +
64302 +void
64303 +gr_log_badprocpid(const char *entry)
64304 +{
64305 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
64306 + return;
64307 +}
64308 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
64309 new file mode 100644
64310 index 0000000..2131422
64311 --- /dev/null
64312 +++ b/grsecurity/grsec_mount.c
64313 @@ -0,0 +1,62 @@
64314 +#include <linux/kernel.h>
64315 +#include <linux/sched.h>
64316 +#include <linux/mount.h>
64317 +#include <linux/grsecurity.h>
64318 +#include <linux/grinternal.h>
64319 +
64320 +void
64321 +gr_log_remount(const char *devname, const int retval)
64322 +{
64323 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64324 + if (grsec_enable_mount && (retval >= 0))
64325 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
64326 +#endif
64327 + return;
64328 +}
64329 +
64330 +void
64331 +gr_log_unmount(const char *devname, const int retval)
64332 +{
64333 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64334 + if (grsec_enable_mount && (retval >= 0))
64335 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
64336 +#endif
64337 + return;
64338 +}
64339 +
64340 +void
64341 +gr_log_mount(const char *from, const char *to, const int retval)
64342 +{
64343 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
64344 + if (grsec_enable_mount && (retval >= 0))
64345 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
64346 +#endif
64347 + return;
64348 +}
64349 +
64350 +int
64351 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
64352 +{
64353 +#ifdef CONFIG_GRKERNSEC_ROFS
64354 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
64355 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
64356 + return -EPERM;
64357 + } else
64358 + return 0;
64359 +#endif
64360 + return 0;
64361 +}
64362 +
64363 +int
64364 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
64365 +{
64366 +#ifdef CONFIG_GRKERNSEC_ROFS
64367 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
64368 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
64369 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
64370 + return -EPERM;
64371 + } else
64372 + return 0;
64373 +#endif
64374 + return 0;
64375 +}
64376 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
64377 new file mode 100644
64378 index 0000000..a3b12a0
64379 --- /dev/null
64380 +++ b/grsecurity/grsec_pax.c
64381 @@ -0,0 +1,36 @@
64382 +#include <linux/kernel.h>
64383 +#include <linux/sched.h>
64384 +#include <linux/mm.h>
64385 +#include <linux/file.h>
64386 +#include <linux/grinternal.h>
64387 +#include <linux/grsecurity.h>
64388 +
64389 +void
64390 +gr_log_textrel(struct vm_area_struct * vma)
64391 +{
64392 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
64393 + if (grsec_enable_audit_textrel)
64394 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
64395 +#endif
64396 + return;
64397 +}
64398 +
64399 +void
64400 +gr_log_rwxmmap(struct file *file)
64401 +{
64402 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64403 + if (grsec_enable_log_rwxmaps)
64404 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
64405 +#endif
64406 + return;
64407 +}
64408 +
64409 +void
64410 +gr_log_rwxmprotect(struct file *file)
64411 +{
64412 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
64413 + if (grsec_enable_log_rwxmaps)
64414 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
64415 +#endif
64416 + return;
64417 +}
64418 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
64419 new file mode 100644
64420 index 0000000..f7f29aa
64421 --- /dev/null
64422 +++ b/grsecurity/grsec_ptrace.c
64423 @@ -0,0 +1,30 @@
64424 +#include <linux/kernel.h>
64425 +#include <linux/sched.h>
64426 +#include <linux/grinternal.h>
64427 +#include <linux/security.h>
64428 +
64429 +void
64430 +gr_audit_ptrace(struct task_struct *task)
64431 +{
64432 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
64433 + if (grsec_enable_audit_ptrace)
64434 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
64435 +#endif
64436 + return;
64437 +}
64438 +
64439 +int
64440 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
64441 +{
64442 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
64443 + const struct dentry *dentry = file->f_path.dentry;
64444 + const struct vfsmount *mnt = file->f_path.mnt;
64445 +
64446 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
64447 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
64448 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
64449 + return -EACCES;
64450 + }
64451 +#endif
64452 + return 0;
64453 +}
64454 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
64455 new file mode 100644
64456 index 0000000..e09715a
64457 --- /dev/null
64458 +++ b/grsecurity/grsec_sig.c
64459 @@ -0,0 +1,222 @@
64460 +#include <linux/kernel.h>
64461 +#include <linux/sched.h>
64462 +#include <linux/delay.h>
64463 +#include <linux/grsecurity.h>
64464 +#include <linux/grinternal.h>
64465 +#include <linux/hardirq.h>
64466 +
64467 +char *signames[] = {
64468 + [SIGSEGV] = "Segmentation fault",
64469 + [SIGILL] = "Illegal instruction",
64470 + [SIGABRT] = "Abort",
64471 + [SIGBUS] = "Invalid alignment/Bus error"
64472 +};
64473 +
64474 +void
64475 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
64476 +{
64477 +#ifdef CONFIG_GRKERNSEC_SIGNAL
64478 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
64479 + (sig == SIGABRT) || (sig == SIGBUS))) {
64480 + if (task_pid_nr(t) == task_pid_nr(current)) {
64481 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
64482 + } else {
64483 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
64484 + }
64485 + }
64486 +#endif
64487 + return;
64488 +}
64489 +
64490 +int
64491 +gr_handle_signal(const struct task_struct *p, const int sig)
64492 +{
64493 +#ifdef CONFIG_GRKERNSEC
64494 + /* ignore the 0 signal for protected task checks */
64495 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
64496 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
64497 + return -EPERM;
64498 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
64499 + return -EPERM;
64500 + }
64501 +#endif
64502 + return 0;
64503 +}
64504 +
64505 +#ifdef CONFIG_GRKERNSEC
64506 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
64507 +
64508 +int gr_fake_force_sig(int sig, struct task_struct *t)
64509 +{
64510 + unsigned long int flags;
64511 + int ret, blocked, ignored;
64512 + struct k_sigaction *action;
64513 +
64514 + spin_lock_irqsave(&t->sighand->siglock, flags);
64515 + action = &t->sighand->action[sig-1];
64516 + ignored = action->sa.sa_handler == SIG_IGN;
64517 + blocked = sigismember(&t->blocked, sig);
64518 + if (blocked || ignored) {
64519 + action->sa.sa_handler = SIG_DFL;
64520 + if (blocked) {
64521 + sigdelset(&t->blocked, sig);
64522 + recalc_sigpending_and_wake(t);
64523 + }
64524 + }
64525 + if (action->sa.sa_handler == SIG_DFL)
64526 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
64527 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
64528 +
64529 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
64530 +
64531 + return ret;
64532 +}
64533 +#endif
64534 +
64535 +#ifdef CONFIG_GRKERNSEC_BRUTE
64536 +#define GR_USER_BAN_TIME (15 * 60)
64537 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
64538 +
64539 +static int __get_dumpable(unsigned long mm_flags)
64540 +{
64541 + int ret;
64542 +
64543 + ret = mm_flags & MMF_DUMPABLE_MASK;
64544 + return (ret >= 2) ? 2 : ret;
64545 +}
64546 +#endif
64547 +
64548 +void gr_handle_brute_attach(unsigned long mm_flags)
64549 +{
64550 +#ifdef CONFIG_GRKERNSEC_BRUTE
64551 + struct task_struct *p = current;
64552 + kuid_t uid = GLOBAL_ROOT_UID;
64553 + int daemon = 0;
64554 +
64555 + if (!grsec_enable_brute)
64556 + return;
64557 +
64558 + rcu_read_lock();
64559 + read_lock(&tasklist_lock);
64560 + read_lock(&grsec_exec_file_lock);
64561 + if (p->real_parent && p->real_parent->exec_file == p->exec_file) {
64562 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
64563 + p->real_parent->brute = 1;
64564 + daemon = 1;
64565 + } else {
64566 + const struct cred *cred = __task_cred(p), *cred2;
64567 + struct task_struct *tsk, *tsk2;
64568 +
64569 + if (!__get_dumpable(mm_flags) && gr_is_global_nonroot(cred->uid)) {
64570 + struct user_struct *user;
64571 +
64572 + uid = cred->uid;
64573 +
64574 + /* this is put upon execution past expiration */
64575 + user = find_user(uid);
64576 + if (user == NULL)
64577 + goto unlock;
64578 + user->banned = 1;
64579 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
64580 + if (user->ban_expires == ~0UL)
64581 + user->ban_expires--;
64582 +
64583 + do_each_thread(tsk2, tsk) {
64584 + cred2 = __task_cred(tsk);
64585 + if (tsk != p && uid_eq(cred2->uid, uid))
64586 + gr_fake_force_sig(SIGKILL, tsk);
64587 + } while_each_thread(tsk2, tsk);
64588 + }
64589 + }
64590 +unlock:
64591 + read_unlock(&grsec_exec_file_lock);
64592 + read_unlock(&tasklist_lock);
64593 + rcu_read_unlock();
64594 +
64595 + if (gr_is_global_nonroot(uid))
64596 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
64597 + GR_GLOBAL_UID(uid), GR_USER_BAN_TIME / 60);
64598 + else if (daemon)
64599 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
64600 +
64601 +#endif
64602 + return;
64603 +}
64604 +
64605 +void gr_handle_brute_check(void)
64606 +{
64607 +#ifdef CONFIG_GRKERNSEC_BRUTE
64608 + struct task_struct *p = current;
64609 +
64610 + if (unlikely(p->brute)) {
64611 + if (!grsec_enable_brute)
64612 + p->brute = 0;
64613 + else if (time_before(get_seconds(), p->brute_expires))
64614 + msleep(30 * 1000);
64615 + }
64616 +#endif
64617 + return;
64618 +}
64619 +
64620 +void gr_handle_kernel_exploit(void)
64621 +{
64622 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
64623 + const struct cred *cred;
64624 + struct task_struct *tsk, *tsk2;
64625 + struct user_struct *user;
64626 + kuid_t uid;
64627 +
64628 + if (in_irq() || in_serving_softirq() || in_nmi())
64629 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
64630 +
64631 + uid = current_uid();
64632 +
64633 + if (gr_is_global_root(uid))
64634 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
64635 + else {
64636 + /* kill all the processes of this user, hold a reference
64637 + to their creds struct, and prevent them from creating
64638 + another process until system reset
64639 + */
64640 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
64641 + GR_GLOBAL_UID(uid));
64642 + /* we intentionally leak this ref */
64643 + user = get_uid(current->cred->user);
64644 + if (user) {
64645 + user->banned = 1;
64646 + user->ban_expires = ~0UL;
64647 + }
64648 +
64649 + read_lock(&tasklist_lock);
64650 + do_each_thread(tsk2, tsk) {
64651 + cred = __task_cred(tsk);
64652 + if (uid_eq(cred->uid, uid))
64653 + gr_fake_force_sig(SIGKILL, tsk);
64654 + } while_each_thread(tsk2, tsk);
64655 + read_unlock(&tasklist_lock);
64656 + }
64657 +#endif
64658 +}
64659 +
64660 +int __gr_process_user_ban(struct user_struct *user)
64661 +{
64662 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64663 + if (unlikely(user->banned)) {
64664 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
64665 + user->banned = 0;
64666 + user->ban_expires = 0;
64667 + free_uid(user);
64668 + } else
64669 + return -EPERM;
64670 + }
64671 +#endif
64672 + return 0;
64673 +}
64674 +
64675 +int gr_process_user_ban(void)
64676 +{
64677 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64678 + return __gr_process_user_ban(current->cred->user);
64679 +#endif
64680 + return 0;
64681 +}
64682 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
64683 new file mode 100644
64684 index 0000000..4030d57
64685 --- /dev/null
64686 +++ b/grsecurity/grsec_sock.c
64687 @@ -0,0 +1,244 @@
64688 +#include <linux/kernel.h>
64689 +#include <linux/module.h>
64690 +#include <linux/sched.h>
64691 +#include <linux/file.h>
64692 +#include <linux/net.h>
64693 +#include <linux/in.h>
64694 +#include <linux/ip.h>
64695 +#include <net/sock.h>
64696 +#include <net/inet_sock.h>
64697 +#include <linux/grsecurity.h>
64698 +#include <linux/grinternal.h>
64699 +#include <linux/gracl.h>
64700 +
64701 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
64702 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
64703 +
64704 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
64705 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
64706 +
64707 +#ifdef CONFIG_UNIX_MODULE
64708 +EXPORT_SYMBOL(gr_acl_handle_unix);
64709 +EXPORT_SYMBOL(gr_acl_handle_mknod);
64710 +EXPORT_SYMBOL(gr_handle_chroot_unix);
64711 +EXPORT_SYMBOL(gr_handle_create);
64712 +#endif
64713 +
64714 +#ifdef CONFIG_GRKERNSEC
64715 +#define gr_conn_table_size 32749
64716 +struct conn_table_entry {
64717 + struct conn_table_entry *next;
64718 + struct signal_struct *sig;
64719 +};
64720 +
64721 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
64722 +DEFINE_SPINLOCK(gr_conn_table_lock);
64723 +
64724 +extern const char * gr_socktype_to_name(unsigned char type);
64725 +extern const char * gr_proto_to_name(unsigned char proto);
64726 +extern const char * gr_sockfamily_to_name(unsigned char family);
64727 +
64728 +static __inline__ int
64729 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
64730 +{
64731 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
64732 +}
64733 +
64734 +static __inline__ int
64735 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
64736 + __u16 sport, __u16 dport)
64737 +{
64738 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
64739 + sig->gr_sport == sport && sig->gr_dport == dport))
64740 + return 1;
64741 + else
64742 + return 0;
64743 +}
64744 +
64745 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
64746 +{
64747 + struct conn_table_entry **match;
64748 + unsigned int index;
64749 +
64750 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
64751 + sig->gr_sport, sig->gr_dport,
64752 + gr_conn_table_size);
64753 +
64754 + newent->sig = sig;
64755 +
64756 + match = &gr_conn_table[index];
64757 + newent->next = *match;
64758 + *match = newent;
64759 +
64760 + return;
64761 +}
64762 +
64763 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
64764 +{
64765 + struct conn_table_entry *match, *last = NULL;
64766 + unsigned int index;
64767 +
64768 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
64769 + sig->gr_sport, sig->gr_dport,
64770 + gr_conn_table_size);
64771 +
64772 + match = gr_conn_table[index];
64773 + while (match && !conn_match(match->sig,
64774 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
64775 + sig->gr_dport)) {
64776 + last = match;
64777 + match = match->next;
64778 + }
64779 +
64780 + if (match) {
64781 + if (last)
64782 + last->next = match->next;
64783 + else
64784 + gr_conn_table[index] = NULL;
64785 + kfree(match);
64786 + }
64787 +
64788 + return;
64789 +}
64790 +
64791 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
64792 + __u16 sport, __u16 dport)
64793 +{
64794 + struct conn_table_entry *match;
64795 + unsigned int index;
64796 +
64797 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
64798 +
64799 + match = gr_conn_table[index];
64800 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
64801 + match = match->next;
64802 +
64803 + if (match)
64804 + return match->sig;
64805 + else
64806 + return NULL;
64807 +}
64808 +
64809 +#endif
64810 +
64811 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
64812 +{
64813 +#ifdef CONFIG_GRKERNSEC
64814 + struct signal_struct *sig = task->signal;
64815 + struct conn_table_entry *newent;
64816 +
64817 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
64818 + if (newent == NULL)
64819 + return;
64820 + /* no bh lock needed since we are called with bh disabled */
64821 + spin_lock(&gr_conn_table_lock);
64822 + gr_del_task_from_ip_table_nolock(sig);
64823 + sig->gr_saddr = inet->inet_rcv_saddr;
64824 + sig->gr_daddr = inet->inet_daddr;
64825 + sig->gr_sport = inet->inet_sport;
64826 + sig->gr_dport = inet->inet_dport;
64827 + gr_add_to_task_ip_table_nolock(sig, newent);
64828 + spin_unlock(&gr_conn_table_lock);
64829 +#endif
64830 + return;
64831 +}
64832 +
64833 +void gr_del_task_from_ip_table(struct task_struct *task)
64834 +{
64835 +#ifdef CONFIG_GRKERNSEC
64836 + spin_lock_bh(&gr_conn_table_lock);
64837 + gr_del_task_from_ip_table_nolock(task->signal);
64838 + spin_unlock_bh(&gr_conn_table_lock);
64839 +#endif
64840 + return;
64841 +}
64842 +
64843 +void
64844 +gr_attach_curr_ip(const struct sock *sk)
64845 +{
64846 +#ifdef CONFIG_GRKERNSEC
64847 + struct signal_struct *p, *set;
64848 + const struct inet_sock *inet = inet_sk(sk);
64849 +
64850 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
64851 + return;
64852 +
64853 + set = current->signal;
64854 +
64855 + spin_lock_bh(&gr_conn_table_lock);
64856 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
64857 + inet->inet_dport, inet->inet_sport);
64858 + if (unlikely(p != NULL)) {
64859 + set->curr_ip = p->curr_ip;
64860 + set->used_accept = 1;
64861 + gr_del_task_from_ip_table_nolock(p);
64862 + spin_unlock_bh(&gr_conn_table_lock);
64863 + return;
64864 + }
64865 + spin_unlock_bh(&gr_conn_table_lock);
64866 +
64867 + set->curr_ip = inet->inet_daddr;
64868 + set->used_accept = 1;
64869 +#endif
64870 + return;
64871 +}
64872 +
64873 +int
64874 +gr_handle_sock_all(const int family, const int type, const int protocol)
64875 +{
64876 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
64877 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
64878 + (family != AF_UNIX)) {
64879 + if (family == AF_INET)
64880 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
64881 + else
64882 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
64883 + return -EACCES;
64884 + }
64885 +#endif
64886 + return 0;
64887 +}
64888 +
64889 +int
64890 +gr_handle_sock_server(const struct sockaddr *sck)
64891 +{
64892 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64893 + if (grsec_enable_socket_server &&
64894 + in_group_p(grsec_socket_server_gid) &&
64895 + sck && (sck->sa_family != AF_UNIX) &&
64896 + (sck->sa_family != AF_LOCAL)) {
64897 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
64898 + return -EACCES;
64899 + }
64900 +#endif
64901 + return 0;
64902 +}
64903 +
64904 +int
64905 +gr_handle_sock_server_other(const struct sock *sck)
64906 +{
64907 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
64908 + if (grsec_enable_socket_server &&
64909 + in_group_p(grsec_socket_server_gid) &&
64910 + sck && (sck->sk_family != AF_UNIX) &&
64911 + (sck->sk_family != AF_LOCAL)) {
64912 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
64913 + return -EACCES;
64914 + }
64915 +#endif
64916 + return 0;
64917 +}
64918 +
64919 +int
64920 +gr_handle_sock_client(const struct sockaddr *sck)
64921 +{
64922 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
64923 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
64924 + sck && (sck->sa_family != AF_UNIX) &&
64925 + (sck->sa_family != AF_LOCAL)) {
64926 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
64927 + return -EACCES;
64928 + }
64929 +#endif
64930 + return 0;
64931 +}
64932 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
64933 new file mode 100644
64934 index 0000000..f55ef0f
64935 --- /dev/null
64936 +++ b/grsecurity/grsec_sysctl.c
64937 @@ -0,0 +1,469 @@
64938 +#include <linux/kernel.h>
64939 +#include <linux/sched.h>
64940 +#include <linux/sysctl.h>
64941 +#include <linux/grsecurity.h>
64942 +#include <linux/grinternal.h>
64943 +
64944 +int
64945 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
64946 +{
64947 +#ifdef CONFIG_GRKERNSEC_SYSCTL
64948 + if (dirname == NULL || name == NULL)
64949 + return 0;
64950 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
64951 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
64952 + return -EACCES;
64953 + }
64954 +#endif
64955 + return 0;
64956 +}
64957 +
64958 +#ifdef CONFIG_GRKERNSEC_ROFS
64959 +static int __maybe_unused one = 1;
64960 +#endif
64961 +
64962 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
64963 +struct ctl_table grsecurity_table[] = {
64964 +#ifdef CONFIG_GRKERNSEC_SYSCTL
64965 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
64966 +#ifdef CONFIG_GRKERNSEC_IO
64967 + {
64968 + .procname = "disable_priv_io",
64969 + .data = &grsec_disable_privio,
64970 + .maxlen = sizeof(int),
64971 + .mode = 0600,
64972 + .proc_handler = &proc_dointvec,
64973 + },
64974 +#endif
64975 +#endif
64976 +#ifdef CONFIG_GRKERNSEC_LINK
64977 + {
64978 + .procname = "linking_restrictions",
64979 + .data = &grsec_enable_link,
64980 + .maxlen = sizeof(int),
64981 + .mode = 0600,
64982 + .proc_handler = &proc_dointvec,
64983 + },
64984 +#endif
64985 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
64986 + {
64987 + .procname = "enforce_symlinksifowner",
64988 + .data = &grsec_enable_symlinkown,
64989 + .maxlen = sizeof(int),
64990 + .mode = 0600,
64991 + .proc_handler = &proc_dointvec,
64992 + },
64993 + {
64994 + .procname = "symlinkown_gid",
64995 + .data = &grsec_symlinkown_gid,
64996 + .maxlen = sizeof(int),
64997 + .mode = 0600,
64998 + .proc_handler = &proc_dointvec,
64999 + },
65000 +#endif
65001 +#ifdef CONFIG_GRKERNSEC_BRUTE
65002 + {
65003 + .procname = "deter_bruteforce",
65004 + .data = &grsec_enable_brute,
65005 + .maxlen = sizeof(int),
65006 + .mode = 0600,
65007 + .proc_handler = &proc_dointvec,
65008 + },
65009 +#endif
65010 +#ifdef CONFIG_GRKERNSEC_FIFO
65011 + {
65012 + .procname = "fifo_restrictions",
65013 + .data = &grsec_enable_fifo,
65014 + .maxlen = sizeof(int),
65015 + .mode = 0600,
65016 + .proc_handler = &proc_dointvec,
65017 + },
65018 +#endif
65019 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
65020 + {
65021 + .procname = "ptrace_readexec",
65022 + .data = &grsec_enable_ptrace_readexec,
65023 + .maxlen = sizeof(int),
65024 + .mode = 0600,
65025 + .proc_handler = &proc_dointvec,
65026 + },
65027 +#endif
65028 +#ifdef CONFIG_GRKERNSEC_SETXID
65029 + {
65030 + .procname = "consistent_setxid",
65031 + .data = &grsec_enable_setxid,
65032 + .maxlen = sizeof(int),
65033 + .mode = 0600,
65034 + .proc_handler = &proc_dointvec,
65035 + },
65036 +#endif
65037 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
65038 + {
65039 + .procname = "ip_blackhole",
65040 + .data = &grsec_enable_blackhole,
65041 + .maxlen = sizeof(int),
65042 + .mode = 0600,
65043 + .proc_handler = &proc_dointvec,
65044 + },
65045 + {
65046 + .procname = "lastack_retries",
65047 + .data = &grsec_lastack_retries,
65048 + .maxlen = sizeof(int),
65049 + .mode = 0600,
65050 + .proc_handler = &proc_dointvec,
65051 + },
65052 +#endif
65053 +#ifdef CONFIG_GRKERNSEC_EXECLOG
65054 + {
65055 + .procname = "exec_logging",
65056 + .data = &grsec_enable_execlog,
65057 + .maxlen = sizeof(int),
65058 + .mode = 0600,
65059 + .proc_handler = &proc_dointvec,
65060 + },
65061 +#endif
65062 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
65063 + {
65064 + .procname = "rwxmap_logging",
65065 + .data = &grsec_enable_log_rwxmaps,
65066 + .maxlen = sizeof(int),
65067 + .mode = 0600,
65068 + .proc_handler = &proc_dointvec,
65069 + },
65070 +#endif
65071 +#ifdef CONFIG_GRKERNSEC_SIGNAL
65072 + {
65073 + .procname = "signal_logging",
65074 + .data = &grsec_enable_signal,
65075 + .maxlen = sizeof(int),
65076 + .mode = 0600,
65077 + .proc_handler = &proc_dointvec,
65078 + },
65079 +#endif
65080 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
65081 + {
65082 + .procname = "forkfail_logging",
65083 + .data = &grsec_enable_forkfail,
65084 + .maxlen = sizeof(int),
65085 + .mode = 0600,
65086 + .proc_handler = &proc_dointvec,
65087 + },
65088 +#endif
65089 +#ifdef CONFIG_GRKERNSEC_TIME
65090 + {
65091 + .procname = "timechange_logging",
65092 + .data = &grsec_enable_time,
65093 + .maxlen = sizeof(int),
65094 + .mode = 0600,
65095 + .proc_handler = &proc_dointvec,
65096 + },
65097 +#endif
65098 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
65099 + {
65100 + .procname = "chroot_deny_shmat",
65101 + .data = &grsec_enable_chroot_shmat,
65102 + .maxlen = sizeof(int),
65103 + .mode = 0600,
65104 + .proc_handler = &proc_dointvec,
65105 + },
65106 +#endif
65107 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
65108 + {
65109 + .procname = "chroot_deny_unix",
65110 + .data = &grsec_enable_chroot_unix,
65111 + .maxlen = sizeof(int),
65112 + .mode = 0600,
65113 + .proc_handler = &proc_dointvec,
65114 + },
65115 +#endif
65116 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
65117 + {
65118 + .procname = "chroot_deny_mount",
65119 + .data = &grsec_enable_chroot_mount,
65120 + .maxlen = sizeof(int),
65121 + .mode = 0600,
65122 + .proc_handler = &proc_dointvec,
65123 + },
65124 +#endif
65125 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
65126 + {
65127 + .procname = "chroot_deny_fchdir",
65128 + .data = &grsec_enable_chroot_fchdir,
65129 + .maxlen = sizeof(int),
65130 + .mode = 0600,
65131 + .proc_handler = &proc_dointvec,
65132 + },
65133 +#endif
65134 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
65135 + {
65136 + .procname = "chroot_deny_chroot",
65137 + .data = &grsec_enable_chroot_double,
65138 + .maxlen = sizeof(int),
65139 + .mode = 0600,
65140 + .proc_handler = &proc_dointvec,
65141 + },
65142 +#endif
65143 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
65144 + {
65145 + .procname = "chroot_deny_pivot",
65146 + .data = &grsec_enable_chroot_pivot,
65147 + .maxlen = sizeof(int),
65148 + .mode = 0600,
65149 + .proc_handler = &proc_dointvec,
65150 + },
65151 +#endif
65152 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
65153 + {
65154 + .procname = "chroot_enforce_chdir",
65155 + .data = &grsec_enable_chroot_chdir,
65156 + .maxlen = sizeof(int),
65157 + .mode = 0600,
65158 + .proc_handler = &proc_dointvec,
65159 + },
65160 +#endif
65161 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
65162 + {
65163 + .procname = "chroot_deny_chmod",
65164 + .data = &grsec_enable_chroot_chmod,
65165 + .maxlen = sizeof(int),
65166 + .mode = 0600,
65167 + .proc_handler = &proc_dointvec,
65168 + },
65169 +#endif
65170 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
65171 + {
65172 + .procname = "chroot_deny_mknod",
65173 + .data = &grsec_enable_chroot_mknod,
65174 + .maxlen = sizeof(int),
65175 + .mode = 0600,
65176 + .proc_handler = &proc_dointvec,
65177 + },
65178 +#endif
65179 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
65180 + {
65181 + .procname = "chroot_restrict_nice",
65182 + .data = &grsec_enable_chroot_nice,
65183 + .maxlen = sizeof(int),
65184 + .mode = 0600,
65185 + .proc_handler = &proc_dointvec,
65186 + },
65187 +#endif
65188 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
65189 + {
65190 + .procname = "chroot_execlog",
65191 + .data = &grsec_enable_chroot_execlog,
65192 + .maxlen = sizeof(int),
65193 + .mode = 0600,
65194 + .proc_handler = &proc_dointvec,
65195 + },
65196 +#endif
65197 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65198 + {
65199 + .procname = "chroot_caps",
65200 + .data = &grsec_enable_chroot_caps,
65201 + .maxlen = sizeof(int),
65202 + .mode = 0600,
65203 + .proc_handler = &proc_dointvec,
65204 + },
65205 +#endif
65206 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
65207 + {
65208 + .procname = "chroot_deny_sysctl",
65209 + .data = &grsec_enable_chroot_sysctl,
65210 + .maxlen = sizeof(int),
65211 + .mode = 0600,
65212 + .proc_handler = &proc_dointvec,
65213 + },
65214 +#endif
65215 +#ifdef CONFIG_GRKERNSEC_TPE
65216 + {
65217 + .procname = "tpe",
65218 + .data = &grsec_enable_tpe,
65219 + .maxlen = sizeof(int),
65220 + .mode = 0600,
65221 + .proc_handler = &proc_dointvec,
65222 + },
65223 + {
65224 + .procname = "tpe_gid",
65225 + .data = &grsec_tpe_gid,
65226 + .maxlen = sizeof(int),
65227 + .mode = 0600,
65228 + .proc_handler = &proc_dointvec,
65229 + },
65230 +#endif
65231 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65232 + {
65233 + .procname = "tpe_invert",
65234 + .data = &grsec_enable_tpe_invert,
65235 + .maxlen = sizeof(int),
65236 + .mode = 0600,
65237 + .proc_handler = &proc_dointvec,
65238 + },
65239 +#endif
65240 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
65241 + {
65242 + .procname = "tpe_restrict_all",
65243 + .data = &grsec_enable_tpe_all,
65244 + .maxlen = sizeof(int),
65245 + .mode = 0600,
65246 + .proc_handler = &proc_dointvec,
65247 + },
65248 +#endif
65249 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
65250 + {
65251 + .procname = "socket_all",
65252 + .data = &grsec_enable_socket_all,
65253 + .maxlen = sizeof(int),
65254 + .mode = 0600,
65255 + .proc_handler = &proc_dointvec,
65256 + },
65257 + {
65258 + .procname = "socket_all_gid",
65259 + .data = &grsec_socket_all_gid,
65260 + .maxlen = sizeof(int),
65261 + .mode = 0600,
65262 + .proc_handler = &proc_dointvec,
65263 + },
65264 +#endif
65265 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
65266 + {
65267 + .procname = "socket_client",
65268 + .data = &grsec_enable_socket_client,
65269 + .maxlen = sizeof(int),
65270 + .mode = 0600,
65271 + .proc_handler = &proc_dointvec,
65272 + },
65273 + {
65274 + .procname = "socket_client_gid",
65275 + .data = &grsec_socket_client_gid,
65276 + .maxlen = sizeof(int),
65277 + .mode = 0600,
65278 + .proc_handler = &proc_dointvec,
65279 + },
65280 +#endif
65281 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
65282 + {
65283 + .procname = "socket_server",
65284 + .data = &grsec_enable_socket_server,
65285 + .maxlen = sizeof(int),
65286 + .mode = 0600,
65287 + .proc_handler = &proc_dointvec,
65288 + },
65289 + {
65290 + .procname = "socket_server_gid",
65291 + .data = &grsec_socket_server_gid,
65292 + .maxlen = sizeof(int),
65293 + .mode = 0600,
65294 + .proc_handler = &proc_dointvec,
65295 + },
65296 +#endif
65297 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
65298 + {
65299 + .procname = "audit_group",
65300 + .data = &grsec_enable_group,
65301 + .maxlen = sizeof(int),
65302 + .mode = 0600,
65303 + .proc_handler = &proc_dointvec,
65304 + },
65305 + {
65306 + .procname = "audit_gid",
65307 + .data = &grsec_audit_gid,
65308 + .maxlen = sizeof(int),
65309 + .mode = 0600,
65310 + .proc_handler = &proc_dointvec,
65311 + },
65312 +#endif
65313 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
65314 + {
65315 + .procname = "audit_chdir",
65316 + .data = &grsec_enable_chdir,
65317 + .maxlen = sizeof(int),
65318 + .mode = 0600,
65319 + .proc_handler = &proc_dointvec,
65320 + },
65321 +#endif
65322 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
65323 + {
65324 + .procname = "audit_mount",
65325 + .data = &grsec_enable_mount,
65326 + .maxlen = sizeof(int),
65327 + .mode = 0600,
65328 + .proc_handler = &proc_dointvec,
65329 + },
65330 +#endif
65331 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
65332 + {
65333 + .procname = "audit_textrel",
65334 + .data = &grsec_enable_audit_textrel,
65335 + .maxlen = sizeof(int),
65336 + .mode = 0600,
65337 + .proc_handler = &proc_dointvec,
65338 + },
65339 +#endif
65340 +#ifdef CONFIG_GRKERNSEC_DMESG
65341 + {
65342 + .procname = "dmesg",
65343 + .data = &grsec_enable_dmesg,
65344 + .maxlen = sizeof(int),
65345 + .mode = 0600,
65346 + .proc_handler = &proc_dointvec,
65347 + },
65348 +#endif
65349 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
65350 + {
65351 + .procname = "chroot_findtask",
65352 + .data = &grsec_enable_chroot_findtask,
65353 + .maxlen = sizeof(int),
65354 + .mode = 0600,
65355 + .proc_handler = &proc_dointvec,
65356 + },
65357 +#endif
65358 +#ifdef CONFIG_GRKERNSEC_RESLOG
65359 + {
65360 + .procname = "resource_logging",
65361 + .data = &grsec_resource_logging,
65362 + .maxlen = sizeof(int),
65363 + .mode = 0600,
65364 + .proc_handler = &proc_dointvec,
65365 + },
65366 +#endif
65367 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
65368 + {
65369 + .procname = "audit_ptrace",
65370 + .data = &grsec_enable_audit_ptrace,
65371 + .maxlen = sizeof(int),
65372 + .mode = 0600,
65373 + .proc_handler = &proc_dointvec,
65374 + },
65375 +#endif
65376 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
65377 + {
65378 + .procname = "harden_ptrace",
65379 + .data = &grsec_enable_harden_ptrace,
65380 + .maxlen = sizeof(int),
65381 + .mode = 0600,
65382 + .proc_handler = &proc_dointvec,
65383 + },
65384 +#endif
65385 + {
65386 + .procname = "grsec_lock",
65387 + .data = &grsec_lock,
65388 + .maxlen = sizeof(int),
65389 + .mode = 0600,
65390 + .proc_handler = &proc_dointvec,
65391 + },
65392 +#endif
65393 +#ifdef CONFIG_GRKERNSEC_ROFS
65394 + {
65395 + .procname = "romount_protect",
65396 + .data = &grsec_enable_rofs,
65397 + .maxlen = sizeof(int),
65398 + .mode = 0600,
65399 + .proc_handler = &proc_dointvec_minmax,
65400 + .extra1 = &one,
65401 + .extra2 = &one,
65402 + },
65403 +#endif
65404 + { }
65405 +};
65406 +#endif
65407 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
65408 new file mode 100644
65409 index 0000000..0dc13c3
65410 --- /dev/null
65411 +++ b/grsecurity/grsec_time.c
65412 @@ -0,0 +1,16 @@
65413 +#include <linux/kernel.h>
65414 +#include <linux/sched.h>
65415 +#include <linux/grinternal.h>
65416 +#include <linux/module.h>
65417 +
65418 +void
65419 +gr_log_timechange(void)
65420 +{
65421 +#ifdef CONFIG_GRKERNSEC_TIME
65422 + if (grsec_enable_time)
65423 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
65424 +#endif
65425 + return;
65426 +}
65427 +
65428 +EXPORT_SYMBOL(gr_log_timechange);
65429 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
65430 new file mode 100644
65431 index 0000000..ee57dcf
65432 --- /dev/null
65433 +++ b/grsecurity/grsec_tpe.c
65434 @@ -0,0 +1,73 @@
65435 +#include <linux/kernel.h>
65436 +#include <linux/sched.h>
65437 +#include <linux/file.h>
65438 +#include <linux/fs.h>
65439 +#include <linux/grinternal.h>
65440 +
65441 +extern int gr_acl_tpe_check(void);
65442 +
65443 +int
65444 +gr_tpe_allow(const struct file *file)
65445 +{
65446 +#ifdef CONFIG_GRKERNSEC
65447 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
65448 + const struct cred *cred = current_cred();
65449 + char *msg = NULL;
65450 + char *msg2 = NULL;
65451 +
65452 + // never restrict root
65453 + if (gr_is_global_root(cred->uid))
65454 + return 1;
65455 +
65456 + if (grsec_enable_tpe) {
65457 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
65458 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
65459 + msg = "not being in trusted group";
65460 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
65461 + msg = "being in untrusted group";
65462 +#else
65463 + if (in_group_p(grsec_tpe_gid))
65464 + msg = "being in untrusted group";
65465 +#endif
65466 + }
65467 + if (!msg && gr_acl_tpe_check())
65468 + msg = "being in untrusted role";
65469 +
65470 + // not in any affected group/role
65471 + if (!msg)
65472 + goto next_check;
65473 +
65474 + if (gr_is_global_nonroot(inode->i_uid))
65475 + msg2 = "file in non-root-owned directory";
65476 + else if (inode->i_mode & S_IWOTH)
65477 + msg2 = "file in world-writable directory";
65478 + else if (inode->i_mode & S_IWGRP)
65479 + msg2 = "file in group-writable directory";
65480 +
65481 + if (msg && msg2) {
65482 + char fullmsg[70] = {0};
65483 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
65484 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
65485 + return 0;
65486 + }
65487 + msg = NULL;
65488 +next_check:
65489 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
65490 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
65491 + return 1;
65492 +
65493 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
65494 + msg = "directory not owned by user";
65495 + else if (inode->i_mode & S_IWOTH)
65496 + msg = "file in world-writable directory";
65497 + else if (inode->i_mode & S_IWGRP)
65498 + msg = "file in group-writable directory";
65499 +
65500 + if (msg) {
65501 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
65502 + return 0;
65503 + }
65504 +#endif
65505 +#endif
65506 + return 1;
65507 +}
65508 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
65509 new file mode 100644
65510 index 0000000..9f7b1ac
65511 --- /dev/null
65512 +++ b/grsecurity/grsum.c
65513 @@ -0,0 +1,61 @@
65514 +#include <linux/err.h>
65515 +#include <linux/kernel.h>
65516 +#include <linux/sched.h>
65517 +#include <linux/mm.h>
65518 +#include <linux/scatterlist.h>
65519 +#include <linux/crypto.h>
65520 +#include <linux/gracl.h>
65521 +
65522 +
65523 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
65524 +#error "crypto and sha256 must be built into the kernel"
65525 +#endif
65526 +
65527 +int
65528 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
65529 +{
65530 + char *p;
65531 + struct crypto_hash *tfm;
65532 + struct hash_desc desc;
65533 + struct scatterlist sg;
65534 + unsigned char temp_sum[GR_SHA_LEN];
65535 + volatile int retval = 0;
65536 + volatile int dummy = 0;
65537 + unsigned int i;
65538 +
65539 + sg_init_table(&sg, 1);
65540 +
65541 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
65542 + if (IS_ERR(tfm)) {
65543 + /* should never happen, since sha256 should be built in */
65544 + return 1;
65545 + }
65546 +
65547 + desc.tfm = tfm;
65548 + desc.flags = 0;
65549 +
65550 + crypto_hash_init(&desc);
65551 +
65552 + p = salt;
65553 + sg_set_buf(&sg, p, GR_SALT_LEN);
65554 + crypto_hash_update(&desc, &sg, sg.length);
65555 +
65556 + p = entry->pw;
65557 + sg_set_buf(&sg, p, strlen(p));
65558 +
65559 + crypto_hash_update(&desc, &sg, sg.length);
65560 +
65561 + crypto_hash_final(&desc, temp_sum);
65562 +
65563 + memset(entry->pw, 0, GR_PW_LEN);
65564 +
65565 + for (i = 0; i < GR_SHA_LEN; i++)
65566 + if (sum[i] != temp_sum[i])
65567 + retval = 1;
65568 + else
65569 + dummy = 1; // waste a cycle
65570 +
65571 + crypto_free_hash(tfm);
65572 +
65573 + return retval;
65574 +}
65575 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
65576 index 77ff547..181834f 100644
65577 --- a/include/asm-generic/4level-fixup.h
65578 +++ b/include/asm-generic/4level-fixup.h
65579 @@ -13,8 +13,10 @@
65580 #define pmd_alloc(mm, pud, address) \
65581 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
65582 NULL: pmd_offset(pud, address))
65583 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
65584
65585 #define pud_alloc(mm, pgd, address) (pgd)
65586 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
65587 #define pud_offset(pgd, start) (pgd)
65588 #define pud_none(pud) 0
65589 #define pud_bad(pud) 0
65590 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
65591 index b7babf0..04ad282 100644
65592 --- a/include/asm-generic/atomic-long.h
65593 +++ b/include/asm-generic/atomic-long.h
65594 @@ -22,6 +22,12 @@
65595
65596 typedef atomic64_t atomic_long_t;
65597
65598 +#ifdef CONFIG_PAX_REFCOUNT
65599 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
65600 +#else
65601 +typedef atomic64_t atomic_long_unchecked_t;
65602 +#endif
65603 +
65604 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
65605
65606 static inline long atomic_long_read(atomic_long_t *l)
65607 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
65608 return (long)atomic64_read(v);
65609 }
65610
65611 +#ifdef CONFIG_PAX_REFCOUNT
65612 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
65613 +{
65614 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65615 +
65616 + return (long)atomic64_read_unchecked(v);
65617 +}
65618 +#endif
65619 +
65620 static inline void atomic_long_set(atomic_long_t *l, long i)
65621 {
65622 atomic64_t *v = (atomic64_t *)l;
65623 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
65624 atomic64_set(v, i);
65625 }
65626
65627 +#ifdef CONFIG_PAX_REFCOUNT
65628 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
65629 +{
65630 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65631 +
65632 + atomic64_set_unchecked(v, i);
65633 +}
65634 +#endif
65635 +
65636 static inline void atomic_long_inc(atomic_long_t *l)
65637 {
65638 atomic64_t *v = (atomic64_t *)l;
65639 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
65640 atomic64_inc(v);
65641 }
65642
65643 +#ifdef CONFIG_PAX_REFCOUNT
65644 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
65645 +{
65646 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65647 +
65648 + atomic64_inc_unchecked(v);
65649 +}
65650 +#endif
65651 +
65652 static inline void atomic_long_dec(atomic_long_t *l)
65653 {
65654 atomic64_t *v = (atomic64_t *)l;
65655 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
65656 atomic64_dec(v);
65657 }
65658
65659 +#ifdef CONFIG_PAX_REFCOUNT
65660 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
65661 +{
65662 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65663 +
65664 + atomic64_dec_unchecked(v);
65665 +}
65666 +#endif
65667 +
65668 static inline void atomic_long_add(long i, atomic_long_t *l)
65669 {
65670 atomic64_t *v = (atomic64_t *)l;
65671 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
65672 atomic64_add(i, v);
65673 }
65674
65675 +#ifdef CONFIG_PAX_REFCOUNT
65676 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
65677 +{
65678 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65679 +
65680 + atomic64_add_unchecked(i, v);
65681 +}
65682 +#endif
65683 +
65684 static inline void atomic_long_sub(long i, atomic_long_t *l)
65685 {
65686 atomic64_t *v = (atomic64_t *)l;
65687 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
65688 atomic64_sub(i, v);
65689 }
65690
65691 +#ifdef CONFIG_PAX_REFCOUNT
65692 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
65693 +{
65694 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65695 +
65696 + atomic64_sub_unchecked(i, v);
65697 +}
65698 +#endif
65699 +
65700 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
65701 {
65702 atomic64_t *v = (atomic64_t *)l;
65703 @@ -101,6 +161,15 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
65704 return (long)atomic64_add_return(i, v);
65705 }
65706
65707 +#ifdef CONFIG_PAX_REFCOUNT
65708 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
65709 +{
65710 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65711 +
65712 + return (long)atomic64_add_return_unchecked(i, v);
65713 +}
65714 +#endif
65715 +
65716 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
65717 {
65718 atomic64_t *v = (atomic64_t *)l;
65719 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
65720 return (long)atomic64_inc_return(v);
65721 }
65722
65723 +#ifdef CONFIG_PAX_REFCOUNT
65724 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
65725 +{
65726 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
65727 +
65728 + return (long)atomic64_inc_return_unchecked(v);
65729 +}
65730 +#endif
65731 +
65732 static inline long atomic_long_dec_return(atomic_long_t *l)
65733 {
65734 atomic64_t *v = (atomic64_t *)l;
65735 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
65736
65737 typedef atomic_t atomic_long_t;
65738
65739 +#ifdef CONFIG_PAX_REFCOUNT
65740 +typedef atomic_unchecked_t atomic_long_unchecked_t;
65741 +#else
65742 +typedef atomic_t atomic_long_unchecked_t;
65743 +#endif
65744 +
65745 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
65746 static inline long atomic_long_read(atomic_long_t *l)
65747 {
65748 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
65749 return (long)atomic_read(v);
65750 }
65751
65752 +#ifdef CONFIG_PAX_REFCOUNT
65753 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
65754 +{
65755 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65756 +
65757 + return (long)atomic_read_unchecked(v);
65758 +}
65759 +#endif
65760 +
65761 static inline void atomic_long_set(atomic_long_t *l, long i)
65762 {
65763 atomic_t *v = (atomic_t *)l;
65764 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
65765 atomic_set(v, i);
65766 }
65767
65768 +#ifdef CONFIG_PAX_REFCOUNT
65769 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
65770 +{
65771 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65772 +
65773 + atomic_set_unchecked(v, i);
65774 +}
65775 +#endif
65776 +
65777 static inline void atomic_long_inc(atomic_long_t *l)
65778 {
65779 atomic_t *v = (atomic_t *)l;
65780 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
65781 atomic_inc(v);
65782 }
65783
65784 +#ifdef CONFIG_PAX_REFCOUNT
65785 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
65786 +{
65787 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65788 +
65789 + atomic_inc_unchecked(v);
65790 +}
65791 +#endif
65792 +
65793 static inline void atomic_long_dec(atomic_long_t *l)
65794 {
65795 atomic_t *v = (atomic_t *)l;
65796 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
65797 atomic_dec(v);
65798 }
65799
65800 +#ifdef CONFIG_PAX_REFCOUNT
65801 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
65802 +{
65803 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65804 +
65805 + atomic_dec_unchecked(v);
65806 +}
65807 +#endif
65808 +
65809 static inline void atomic_long_add(long i, atomic_long_t *l)
65810 {
65811 atomic_t *v = (atomic_t *)l;
65812 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
65813 atomic_add(i, v);
65814 }
65815
65816 +#ifdef CONFIG_PAX_REFCOUNT
65817 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
65818 +{
65819 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65820 +
65821 + atomic_add_unchecked(i, v);
65822 +}
65823 +#endif
65824 +
65825 static inline void atomic_long_sub(long i, atomic_long_t *l)
65826 {
65827 atomic_t *v = (atomic_t *)l;
65828 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
65829 atomic_sub(i, v);
65830 }
65831
65832 +#ifdef CONFIG_PAX_REFCOUNT
65833 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
65834 +{
65835 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65836 +
65837 + atomic_sub_unchecked(i, v);
65838 +}
65839 +#endif
65840 +
65841 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
65842 {
65843 atomic_t *v = (atomic_t *)l;
65844 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
65845 return (long)atomic_add_return(i, v);
65846 }
65847
65848 +#ifdef CONFIG_PAX_REFCOUNT
65849 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
65850 +{
65851 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65852 +
65853 + return (long)atomic_add_return_unchecked(i, v);
65854 +}
65855 +
65856 +#endif
65857 +
65858 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
65859 {
65860 atomic_t *v = (atomic_t *)l;
65861 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
65862 return (long)atomic_inc_return(v);
65863 }
65864
65865 +#ifdef CONFIG_PAX_REFCOUNT
65866 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
65867 +{
65868 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
65869 +
65870 + return (long)atomic_inc_return_unchecked(v);
65871 +}
65872 +#endif
65873 +
65874 static inline long atomic_long_dec_return(atomic_long_t *l)
65875 {
65876 atomic_t *v = (atomic_t *)l;
65877 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
65878
65879 #endif /* BITS_PER_LONG == 64 */
65880
65881 +#ifdef CONFIG_PAX_REFCOUNT
65882 +static inline void pax_refcount_needs_these_functions(void)
65883 +{
65884 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
65885 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
65886 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
65887 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
65888 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
65889 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
65890 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
65891 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
65892 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
65893 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
65894 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
65895 +#ifdef CONFIG_X86
65896 + atomic_clear_mask_unchecked(0, NULL);
65897 + atomic_set_mask_unchecked(0, NULL);
65898 +#endif
65899 +
65900 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
65901 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
65902 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
65903 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
65904 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
65905 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
65906 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
65907 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
65908 +}
65909 +#else
65910 +#define atomic_read_unchecked(v) atomic_read(v)
65911 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
65912 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
65913 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
65914 +#define atomic_inc_unchecked(v) atomic_inc(v)
65915 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
65916 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
65917 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
65918 +#define atomic_dec_unchecked(v) atomic_dec(v)
65919 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
65920 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
65921 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
65922 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
65923 +
65924 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
65925 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
65926 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
65927 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
65928 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
65929 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
65930 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
65931 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
65932 +#endif
65933 +
65934 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
65935 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
65936 index 1ced641..c896ee8 100644
65937 --- a/include/asm-generic/atomic.h
65938 +++ b/include/asm-generic/atomic.h
65939 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
65940 * Atomically clears the bits set in @mask from @v
65941 */
65942 #ifndef atomic_clear_mask
65943 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
65944 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
65945 {
65946 unsigned long flags;
65947
65948 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
65949 index b18ce4f..2ee2843 100644
65950 --- a/include/asm-generic/atomic64.h
65951 +++ b/include/asm-generic/atomic64.h
65952 @@ -16,6 +16,8 @@ typedef struct {
65953 long long counter;
65954 } atomic64_t;
65955
65956 +typedef atomic64_t atomic64_unchecked_t;
65957 +
65958 #define ATOMIC64_INIT(i) { (i) }
65959
65960 extern long long atomic64_read(const atomic64_t *v);
65961 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
65962 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
65963 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
65964
65965 +#define atomic64_read_unchecked(v) atomic64_read(v)
65966 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
65967 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
65968 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
65969 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
65970 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
65971 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
65972 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
65973 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
65974 +
65975 #endif /* _ASM_GENERIC_ATOMIC64_H */
65976 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
65977 index 1bfcfe5..e04c5c9 100644
65978 --- a/include/asm-generic/cache.h
65979 +++ b/include/asm-generic/cache.h
65980 @@ -6,7 +6,7 @@
65981 * cache lines need to provide their own cache.h.
65982 */
65983
65984 -#define L1_CACHE_SHIFT 5
65985 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
65986 +#define L1_CACHE_SHIFT 5UL
65987 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
65988
65989 #endif /* __ASM_GENERIC_CACHE_H */
65990 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
65991 index 0d68a1e..b74a761 100644
65992 --- a/include/asm-generic/emergency-restart.h
65993 +++ b/include/asm-generic/emergency-restart.h
65994 @@ -1,7 +1,7 @@
65995 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
65996 #define _ASM_GENERIC_EMERGENCY_RESTART_H
65997
65998 -static inline void machine_emergency_restart(void)
65999 +static inline __noreturn void machine_emergency_restart(void)
66000 {
66001 machine_restart(NULL);
66002 }
66003 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
66004 index 90f99c7..00ce236 100644
66005 --- a/include/asm-generic/kmap_types.h
66006 +++ b/include/asm-generic/kmap_types.h
66007 @@ -2,9 +2,9 @@
66008 #define _ASM_GENERIC_KMAP_TYPES_H
66009
66010 #ifdef __WITH_KM_FENCE
66011 -# define KM_TYPE_NR 41
66012 +# define KM_TYPE_NR 42
66013 #else
66014 -# define KM_TYPE_NR 20
66015 +# define KM_TYPE_NR 21
66016 #endif
66017
66018 #endif
66019 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
66020 index 9ceb03b..62b0b8f 100644
66021 --- a/include/asm-generic/local.h
66022 +++ b/include/asm-generic/local.h
66023 @@ -23,24 +23,37 @@ typedef struct
66024 atomic_long_t a;
66025 } local_t;
66026
66027 +typedef struct {
66028 + atomic_long_unchecked_t a;
66029 +} local_unchecked_t;
66030 +
66031 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
66032
66033 #define local_read(l) atomic_long_read(&(l)->a)
66034 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
66035 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
66036 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
66037 #define local_inc(l) atomic_long_inc(&(l)->a)
66038 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
66039 #define local_dec(l) atomic_long_dec(&(l)->a)
66040 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
66041 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
66042 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
66043 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
66044 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
66045
66046 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
66047 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
66048 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
66049 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
66050 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
66051 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
66052 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
66053 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
66054 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
66055
66056 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66057 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
66058 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
66059 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
66060 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
66061 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
66062 index 725612b..9cc513a 100644
66063 --- a/include/asm-generic/pgtable-nopmd.h
66064 +++ b/include/asm-generic/pgtable-nopmd.h
66065 @@ -1,14 +1,19 @@
66066 #ifndef _PGTABLE_NOPMD_H
66067 #define _PGTABLE_NOPMD_H
66068
66069 -#ifndef __ASSEMBLY__
66070 -
66071 #include <asm-generic/pgtable-nopud.h>
66072
66073 -struct mm_struct;
66074 -
66075 #define __PAGETABLE_PMD_FOLDED
66076
66077 +#define PMD_SHIFT PUD_SHIFT
66078 +#define PTRS_PER_PMD 1
66079 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
66080 +#define PMD_MASK (~(PMD_SIZE-1))
66081 +
66082 +#ifndef __ASSEMBLY__
66083 +
66084 +struct mm_struct;
66085 +
66086 /*
66087 * Having the pmd type consist of a pud gets the size right, and allows
66088 * us to conceptually access the pud entry that this pmd is folded into
66089 @@ -16,11 +21,6 @@ struct mm_struct;
66090 */
66091 typedef struct { pud_t pud; } pmd_t;
66092
66093 -#define PMD_SHIFT PUD_SHIFT
66094 -#define PTRS_PER_PMD 1
66095 -#define PMD_SIZE (1UL << PMD_SHIFT)
66096 -#define PMD_MASK (~(PMD_SIZE-1))
66097 -
66098 /*
66099 * The "pud_xxx()" functions here are trivial for a folded two-level
66100 * setup: the pmd is never bad, and a pmd always exists (as it's folded
66101 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
66102 index 810431d..0ec4804f 100644
66103 --- a/include/asm-generic/pgtable-nopud.h
66104 +++ b/include/asm-generic/pgtable-nopud.h
66105 @@ -1,10 +1,15 @@
66106 #ifndef _PGTABLE_NOPUD_H
66107 #define _PGTABLE_NOPUD_H
66108
66109 -#ifndef __ASSEMBLY__
66110 -
66111 #define __PAGETABLE_PUD_FOLDED
66112
66113 +#define PUD_SHIFT PGDIR_SHIFT
66114 +#define PTRS_PER_PUD 1
66115 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
66116 +#define PUD_MASK (~(PUD_SIZE-1))
66117 +
66118 +#ifndef __ASSEMBLY__
66119 +
66120 /*
66121 * Having the pud type consist of a pgd gets the size right, and allows
66122 * us to conceptually access the pgd entry that this pud is folded into
66123 @@ -12,11 +17,6 @@
66124 */
66125 typedef struct { pgd_t pgd; } pud_t;
66126
66127 -#define PUD_SHIFT PGDIR_SHIFT
66128 -#define PTRS_PER_PUD 1
66129 -#define PUD_SIZE (1UL << PUD_SHIFT)
66130 -#define PUD_MASK (~(PUD_SIZE-1))
66131 -
66132 /*
66133 * The "pgd_xxx()" functions here are trivial for a folded two-level
66134 * setup: the pud is never bad, and a pud always exists (as it's folded
66135 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
66136 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
66137
66138 #define pgd_populate(mm, pgd, pud) do { } while (0)
66139 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
66140 /*
66141 * (puds are folded into pgds so this doesn't get actually called,
66142 * but the define is needed for a generic inline function.)
66143 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
66144 index 5cf680a..4b74d62 100644
66145 --- a/include/asm-generic/pgtable.h
66146 +++ b/include/asm-generic/pgtable.h
66147 @@ -688,6 +688,14 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
66148 }
66149 #endif /* CONFIG_NUMA_BALANCING */
66150
66151 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
66152 +static inline unsigned long pax_open_kernel(void) { return 0; }
66153 +#endif
66154 +
66155 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
66156 +static inline unsigned long pax_close_kernel(void) { return 0; }
66157 +#endif
66158 +
66159 #endif /* CONFIG_MMU */
66160
66161 #endif /* !__ASSEMBLY__ */
66162 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
66163 index d1ea7ce..b1ebf2a 100644
66164 --- a/include/asm-generic/vmlinux.lds.h
66165 +++ b/include/asm-generic/vmlinux.lds.h
66166 @@ -218,6 +218,7 @@
66167 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
66168 VMLINUX_SYMBOL(__start_rodata) = .; \
66169 *(.rodata) *(.rodata.*) \
66170 + *(.data..read_only) \
66171 *(__vermagic) /* Kernel version magic */ \
66172 . = ALIGN(8); \
66173 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
66174 @@ -725,17 +726,18 @@
66175 * section in the linker script will go there too. @phdr should have
66176 * a leading colon.
66177 *
66178 - * Note that this macros defines __per_cpu_load as an absolute symbol.
66179 + * Note that this macros defines per_cpu_load as an absolute symbol.
66180 * If there is no need to put the percpu section at a predetermined
66181 * address, use PERCPU_SECTION.
66182 */
66183 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
66184 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
66185 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
66186 + per_cpu_load = .; \
66187 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
66188 - LOAD_OFFSET) { \
66189 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
66190 PERCPU_INPUT(cacheline) \
66191 } phdr \
66192 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
66193 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
66194
66195 /**
66196 * PERCPU_SECTION - define output section for percpu area, simple version
66197 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
66198 index 418d270..bfd2794 100644
66199 --- a/include/crypto/algapi.h
66200 +++ b/include/crypto/algapi.h
66201 @@ -34,7 +34,7 @@ struct crypto_type {
66202 unsigned int maskclear;
66203 unsigned int maskset;
66204 unsigned int tfmsize;
66205 -};
66206 +} __do_const;
66207
66208 struct crypto_instance {
66209 struct crypto_alg alg;
66210 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
66211 index fad21c9..ab858bc 100644
66212 --- a/include/drm/drmP.h
66213 +++ b/include/drm/drmP.h
66214 @@ -72,6 +72,7 @@
66215 #include <linux/workqueue.h>
66216 #include <linux/poll.h>
66217 #include <asm/pgalloc.h>
66218 +#include <asm/local.h>
66219 #include <drm/drm.h>
66220 #include <drm/drm_sarea.h>
66221
66222 @@ -293,10 +294,12 @@ do { \
66223 * \param cmd command.
66224 * \param arg argument.
66225 */
66226 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
66227 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
66228 + struct drm_file *file_priv);
66229 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
66230 struct drm_file *file_priv);
66231
66232 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66233 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
66234 unsigned long arg);
66235
66236 #define DRM_IOCTL_NR(n) _IOC_NR(n)
66237 @@ -311,9 +314,9 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
66238 struct drm_ioctl_desc {
66239 unsigned int cmd;
66240 int flags;
66241 - drm_ioctl_t *func;
66242 + drm_ioctl_t func;
66243 unsigned int cmd_drv;
66244 -};
66245 +} __do_const;
66246
66247 /**
66248 * Creates a driver or general drm_ioctl_desc array entry for the given
66249 @@ -995,7 +998,7 @@ struct drm_info_list {
66250 int (*show)(struct seq_file*, void*); /** show callback */
66251 u32 driver_features; /**< Required driver features for this entry */
66252 void *data;
66253 -};
66254 +} __do_const;
66255
66256 /**
66257 * debugfs node structure. This structure represents a debugfs file.
66258 @@ -1068,7 +1071,7 @@ struct drm_device {
66259
66260 /** \name Usage Counters */
66261 /*@{ */
66262 - int open_count; /**< Outstanding files open */
66263 + local_t open_count; /**< Outstanding files open */
66264 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
66265 atomic_t vma_count; /**< Outstanding vma areas open */
66266 int buf_use; /**< Buffers in use -- cannot alloc */
66267 @@ -1079,7 +1082,7 @@ struct drm_device {
66268 /*@{ */
66269 unsigned long counters;
66270 enum drm_stat_type types[15];
66271 - atomic_t counts[15];
66272 + atomic_unchecked_t counts[15];
66273 /*@} */
66274
66275 struct list_head filelist;
66276 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
66277 index f43d556..94d9343 100644
66278 --- a/include/drm/drm_crtc_helper.h
66279 +++ b/include/drm/drm_crtc_helper.h
66280 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
66281 struct drm_connector *connector);
66282 /* disable encoder when not in use - more explicit than dpms off */
66283 void (*disable)(struct drm_encoder *encoder);
66284 -};
66285 +} __no_const;
66286
66287 /**
66288 * drm_connector_helper_funcs - helper operations for connectors
66289 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
66290 index 72dcbe8..8db58d7 100644
66291 --- a/include/drm/ttm/ttm_memory.h
66292 +++ b/include/drm/ttm/ttm_memory.h
66293 @@ -48,7 +48,7 @@
66294
66295 struct ttm_mem_shrink {
66296 int (*do_shrink) (struct ttm_mem_shrink *);
66297 -};
66298 +} __no_const;
66299
66300 /**
66301 * struct ttm_mem_global - Global memory accounting structure.
66302 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
66303 index 4b840e8..155d235 100644
66304 --- a/include/keys/asymmetric-subtype.h
66305 +++ b/include/keys/asymmetric-subtype.h
66306 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
66307 /* Verify the signature on a key of this subtype (optional) */
66308 int (*verify_signature)(const struct key *key,
66309 const struct public_key_signature *sig);
66310 -};
66311 +} __do_const;
66312
66313 /**
66314 * asymmetric_key_subtype - Get the subtype from an asymmetric key
66315 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
66316 index c1da539..1dcec55 100644
66317 --- a/include/linux/atmdev.h
66318 +++ b/include/linux/atmdev.h
66319 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
66320 #endif
66321
66322 struct k_atm_aal_stats {
66323 -#define __HANDLE_ITEM(i) atomic_t i
66324 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
66325 __AAL_STAT_ITEMS
66326 #undef __HANDLE_ITEM
66327 };
66328 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
66329 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
66330 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
66331 struct module *owner;
66332 -};
66333 +} __do_const ;
66334
66335 struct atmphy_ops {
66336 int (*start)(struct atm_dev *dev);
66337 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
66338 index 0530b98..96a8ac0 100644
66339 --- a/include/linux/binfmts.h
66340 +++ b/include/linux/binfmts.h
66341 @@ -73,8 +73,9 @@ struct linux_binfmt {
66342 int (*load_binary)(struct linux_binprm *);
66343 int (*load_shlib)(struct file *);
66344 int (*core_dump)(struct coredump_params *cprm);
66345 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
66346 unsigned long min_coredump; /* minimal dump size */
66347 -};
66348 +} __do_const;
66349
66350 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
66351
66352 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
66353 index f94bc83..62b9cfe 100644
66354 --- a/include/linux/blkdev.h
66355 +++ b/include/linux/blkdev.h
66356 @@ -1498,7 +1498,7 @@ struct block_device_operations {
66357 /* this callback is with swap_lock and sometimes page table lock held */
66358 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
66359 struct module *owner;
66360 -};
66361 +} __do_const;
66362
66363 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
66364 unsigned long);
66365 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
66366 index 7c2e030..b72475d 100644
66367 --- a/include/linux/blktrace_api.h
66368 +++ b/include/linux/blktrace_api.h
66369 @@ -23,7 +23,7 @@ struct blk_trace {
66370 struct dentry *dir;
66371 struct dentry *dropped_file;
66372 struct dentry *msg_file;
66373 - atomic_t dropped;
66374 + atomic_unchecked_t dropped;
66375 };
66376
66377 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
66378 diff --git a/include/linux/cache.h b/include/linux/cache.h
66379 index 4c57065..4307975 100644
66380 --- a/include/linux/cache.h
66381 +++ b/include/linux/cache.h
66382 @@ -16,6 +16,10 @@
66383 #define __read_mostly
66384 #endif
66385
66386 +#ifndef __read_only
66387 +#define __read_only __read_mostly
66388 +#endif
66389 +
66390 #ifndef ____cacheline_aligned
66391 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
66392 #endif
66393 diff --git a/include/linux/capability.h b/include/linux/capability.h
66394 index 98503b7..cc36d18 100644
66395 --- a/include/linux/capability.h
66396 +++ b/include/linux/capability.h
66397 @@ -211,8 +211,13 @@ extern bool capable(int cap);
66398 extern bool ns_capable(struct user_namespace *ns, int cap);
66399 extern bool nsown_capable(int cap);
66400 extern bool inode_capable(const struct inode *inode, int cap);
66401 +extern bool capable_nolog(int cap);
66402 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
66403 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
66404
66405 /* audit system wants to get cap info from files as well */
66406 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
66407
66408 +extern int is_privileged_binary(const struct dentry *dentry);
66409 +
66410 #endif /* !_LINUX_CAPABILITY_H */
66411 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
66412 index 8609d57..86e4d79 100644
66413 --- a/include/linux/cdrom.h
66414 +++ b/include/linux/cdrom.h
66415 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
66416
66417 /* driver specifications */
66418 const int capability; /* capability flags */
66419 - int n_minors; /* number of active minor devices */
66420 /* handle uniform packets for scsi type devices (scsi,atapi) */
66421 int (*generic_packet) (struct cdrom_device_info *,
66422 struct packet_command *);
66423 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
66424 index 42e55de..1cd0e66 100644
66425 --- a/include/linux/cleancache.h
66426 +++ b/include/linux/cleancache.h
66427 @@ -31,7 +31,7 @@ struct cleancache_ops {
66428 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
66429 void (*invalidate_inode)(int, struct cleancache_filekey);
66430 void (*invalidate_fs)(int);
66431 -};
66432 +} __no_const;
66433
66434 extern struct cleancache_ops
66435 cleancache_register_ops(struct cleancache_ops *ops);
66436 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
66437 index 662fd1b..e801992 100644
66438 --- a/include/linux/compiler-gcc4.h
66439 +++ b/include/linux/compiler-gcc4.h
66440 @@ -34,6 +34,21 @@
66441 #define __UNIQUE_ID(prefix) __PASTE(__PASTE(__UNIQUE_ID_, prefix), __COUNTER__)
66442
66443 #if __GNUC_MINOR__ >= 5
66444 +
66445 +#ifdef CONSTIFY_PLUGIN
66446 +#define __no_const __attribute__((no_const))
66447 +#define __do_const __attribute__((do_const))
66448 +#endif
66449 +
66450 +#ifdef SIZE_OVERFLOW_PLUGIN
66451 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
66452 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
66453 +#endif
66454 +
66455 +#ifdef LATENT_ENTROPY_PLUGIN
66456 +#define __latent_entropy __attribute__((latent_entropy))
66457 +#endif
66458 +
66459 /*
66460 * Mark a position in code as unreachable. This can be used to
66461 * suppress control flow warnings after asm blocks that transfer
66462 @@ -49,6 +64,11 @@
66463 #define __noclone __attribute__((__noclone__))
66464
66465 #endif
66466 +
66467 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
66468 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
66469 +#define __bos0(ptr) __bos((ptr), 0)
66470 +#define __bos1(ptr) __bos((ptr), 1)
66471 #endif
66472
66473 #if __GNUC_MINOR__ >= 6
66474 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
66475 index dd852b7..72924c0 100644
66476 --- a/include/linux/compiler.h
66477 +++ b/include/linux/compiler.h
66478 @@ -5,11 +5,14 @@
66479
66480 #ifdef __CHECKER__
66481 # define __user __attribute__((noderef, address_space(1)))
66482 +# define __force_user __force __user
66483 # define __kernel __attribute__((address_space(0)))
66484 +# define __force_kernel __force __kernel
66485 # define __safe __attribute__((safe))
66486 # define __force __attribute__((force))
66487 # define __nocast __attribute__((nocast))
66488 # define __iomem __attribute__((noderef, address_space(2)))
66489 +# define __force_iomem __force __iomem
66490 # define __must_hold(x) __attribute__((context(x,1,1)))
66491 # define __acquires(x) __attribute__((context(x,0,1)))
66492 # define __releases(x) __attribute__((context(x,1,0)))
66493 @@ -17,20 +20,48 @@
66494 # define __release(x) __context__(x,-1)
66495 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
66496 # define __percpu __attribute__((noderef, address_space(3)))
66497 +# define __force_percpu __force __percpu
66498 #ifdef CONFIG_SPARSE_RCU_POINTER
66499 # define __rcu __attribute__((noderef, address_space(4)))
66500 +# define __force_rcu __force __rcu
66501 #else
66502 # define __rcu
66503 +# define __force_rcu
66504 #endif
66505 extern void __chk_user_ptr(const volatile void __user *);
66506 extern void __chk_io_ptr(const volatile void __iomem *);
66507 +#elif defined(CHECKER_PLUGIN)
66508 +//# define __user
66509 +//# define __force_user
66510 +//# define __kernel
66511 +//# define __force_kernel
66512 +# define __safe
66513 +# define __force
66514 +# define __nocast
66515 +# define __iomem
66516 +# define __force_iomem
66517 +# define __chk_user_ptr(x) (void)0
66518 +# define __chk_io_ptr(x) (void)0
66519 +# define __builtin_warning(x, y...) (1)
66520 +# define __acquires(x)
66521 +# define __releases(x)
66522 +# define __acquire(x) (void)0
66523 +# define __release(x) (void)0
66524 +# define __cond_lock(x,c) (c)
66525 +# define __percpu
66526 +# define __force_percpu
66527 +# define __rcu
66528 +# define __force_rcu
66529 #else
66530 # define __user
66531 +# define __force_user
66532 # define __kernel
66533 +# define __force_kernel
66534 # define __safe
66535 # define __force
66536 # define __nocast
66537 # define __iomem
66538 +# define __force_iomem
66539 # define __chk_user_ptr(x) (void)0
66540 # define __chk_io_ptr(x) (void)0
66541 # define __builtin_warning(x, y...) (1)
66542 @@ -41,7 +72,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
66543 # define __release(x) (void)0
66544 # define __cond_lock(x,c) (c)
66545 # define __percpu
66546 +# define __force_percpu
66547 # define __rcu
66548 +# define __force_rcu
66549 #endif
66550
66551 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
66552 @@ -275,6 +308,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66553 # define __attribute_const__ /* unimplemented */
66554 #endif
66555
66556 +#ifndef __no_const
66557 +# define __no_const
66558 +#endif
66559 +
66560 +#ifndef __do_const
66561 +# define __do_const
66562 +#endif
66563 +
66564 +#ifndef __size_overflow
66565 +# define __size_overflow(...)
66566 +#endif
66567 +
66568 +#ifndef __intentional_overflow
66569 +# define __intentional_overflow(...)
66570 +#endif
66571 +
66572 +#ifndef __latent_entropy
66573 +# define __latent_entropy
66574 +#endif
66575 +
66576 /*
66577 * Tell gcc if a function is cold. The compiler will assume any path
66578 * directly leading to the call is unlikely.
66579 @@ -284,6 +337,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66580 #define __cold
66581 #endif
66582
66583 +#ifndef __alloc_size
66584 +#define __alloc_size(...)
66585 +#endif
66586 +
66587 +#ifndef __bos
66588 +#define __bos(ptr, arg)
66589 +#endif
66590 +
66591 +#ifndef __bos0
66592 +#define __bos0(ptr)
66593 +#endif
66594 +
66595 +#ifndef __bos1
66596 +#define __bos1(ptr)
66597 +#endif
66598 +
66599 /* Simple shorthand for a section definition */
66600 #ifndef __section
66601 # define __section(S) __attribute__ ((__section__(#S)))
66602 @@ -323,6 +392,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
66603 * use is to mediate communication between process-level code and irq/NMI
66604 * handlers, all running on the same CPU.
66605 */
66606 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
66607 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
66608 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
66609
66610 #endif /* __LINUX_COMPILER_H */
66611 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
66612 index 34025df..d94bbbc 100644
66613 --- a/include/linux/configfs.h
66614 +++ b/include/linux/configfs.h
66615 @@ -125,7 +125,7 @@ struct configfs_attribute {
66616 const char *ca_name;
66617 struct module *ca_owner;
66618 umode_t ca_mode;
66619 -};
66620 +} __do_const;
66621
66622 /*
66623 * Users often need to create attribute structures for their configurable
66624 diff --git a/include/linux/cpu.h b/include/linux/cpu.h
66625 index ce7a074..01ab8ac 100644
66626 --- a/include/linux/cpu.h
66627 +++ b/include/linux/cpu.h
66628 @@ -115,7 +115,7 @@ enum {
66629 /* Need to know about CPUs going up/down? */
66630 #if defined(CONFIG_HOTPLUG_CPU) || !defined(MODULE)
66631 #define cpu_notifier(fn, pri) { \
66632 - static struct notifier_block fn##_nb __cpuinitdata = \
66633 + static struct notifier_block fn##_nb = \
66634 { .notifier_call = fn, .priority = pri }; \
66635 register_cpu_notifier(&fn##_nb); \
66636 }
66637 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
66638 index a55b88e..fba90c5 100644
66639 --- a/include/linux/cpufreq.h
66640 +++ b/include/linux/cpufreq.h
66641 @@ -240,7 +240,7 @@ struct cpufreq_driver {
66642 int (*suspend) (struct cpufreq_policy *policy);
66643 int (*resume) (struct cpufreq_policy *policy);
66644 struct freq_attr **attr;
66645 -};
66646 +} __do_const;
66647
66648 /* flags */
66649
66650 @@ -299,6 +299,7 @@ struct global_attr {
66651 ssize_t (*store)(struct kobject *a, struct attribute *b,
66652 const char *c, size_t count);
66653 };
66654 +typedef struct global_attr __no_const global_attr_no_const;
66655
66656 #define define_one_global_ro(_name) \
66657 static struct global_attr _name = \
66658 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
66659 index 24cd1037..20a63aae 100644
66660 --- a/include/linux/cpuidle.h
66661 +++ b/include/linux/cpuidle.h
66662 @@ -54,7 +54,8 @@ struct cpuidle_state {
66663 int index);
66664
66665 int (*enter_dead) (struct cpuidle_device *dev, int index);
66666 -};
66667 +} __do_const;
66668 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
66669
66670 /* Idle State Flags */
66671 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
66672 @@ -216,7 +217,7 @@ struct cpuidle_governor {
66673 void (*reflect) (struct cpuidle_device *dev, int index);
66674
66675 struct module *owner;
66676 -};
66677 +} __do_const;
66678
66679 #ifdef CONFIG_CPU_IDLE
66680
66681 diff --git a/include/linux/cred.h b/include/linux/cred.h
66682 index 04421e8..6bce4ef 100644
66683 --- a/include/linux/cred.h
66684 +++ b/include/linux/cred.h
66685 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
66686 static inline void validate_process_creds(void)
66687 {
66688 }
66689 +static inline void validate_task_creds(struct task_struct *task)
66690 +{
66691 +}
66692 #endif
66693
66694 /**
66695 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
66696 index b92eadf..b4ecdc1 100644
66697 --- a/include/linux/crypto.h
66698 +++ b/include/linux/crypto.h
66699 @@ -373,7 +373,7 @@ struct cipher_tfm {
66700 const u8 *key, unsigned int keylen);
66701 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
66702 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
66703 -};
66704 +} __no_const;
66705
66706 struct hash_tfm {
66707 int (*init)(struct hash_desc *desc);
66708 @@ -394,13 +394,13 @@ struct compress_tfm {
66709 int (*cot_decompress)(struct crypto_tfm *tfm,
66710 const u8 *src, unsigned int slen,
66711 u8 *dst, unsigned int *dlen);
66712 -};
66713 +} __no_const;
66714
66715 struct rng_tfm {
66716 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
66717 unsigned int dlen);
66718 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
66719 -};
66720 +} __no_const;
66721
66722 #define crt_ablkcipher crt_u.ablkcipher
66723 #define crt_aead crt_u.aead
66724 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
66725 index 7925bf0..d5143d2 100644
66726 --- a/include/linux/decompress/mm.h
66727 +++ b/include/linux/decompress/mm.h
66728 @@ -77,7 +77,7 @@ static void free(void *where)
66729 * warnings when not needed (indeed large_malloc / large_free are not
66730 * needed by inflate */
66731
66732 -#define malloc(a) kmalloc(a, GFP_KERNEL)
66733 +#define malloc(a) kmalloc((a), GFP_KERNEL)
66734 #define free(a) kfree(a)
66735
66736 #define large_malloc(a) vmalloc(a)
66737 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
66738 index e83ef39..33e0eb3 100644
66739 --- a/include/linux/devfreq.h
66740 +++ b/include/linux/devfreq.h
66741 @@ -114,7 +114,7 @@ struct devfreq_governor {
66742 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
66743 int (*event_handler)(struct devfreq *devfreq,
66744 unsigned int event, void *data);
66745 -};
66746 +} __do_const;
66747
66748 /**
66749 * struct devfreq - Device devfreq structure
66750 diff --git a/include/linux/device.h b/include/linux/device.h
66751 index 43dcda9..7a1fb65 100644
66752 --- a/include/linux/device.h
66753 +++ b/include/linux/device.h
66754 @@ -294,7 +294,7 @@ struct subsys_interface {
66755 struct list_head node;
66756 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
66757 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
66758 -};
66759 +} __do_const;
66760
66761 int subsys_interface_register(struct subsys_interface *sif);
66762 void subsys_interface_unregister(struct subsys_interface *sif);
66763 @@ -474,7 +474,7 @@ struct device_type {
66764 void (*release)(struct device *dev);
66765
66766 const struct dev_pm_ops *pm;
66767 -};
66768 +} __do_const;
66769
66770 /* interface for exporting device attributes */
66771 struct device_attribute {
66772 @@ -484,11 +484,12 @@ struct device_attribute {
66773 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
66774 const char *buf, size_t count);
66775 };
66776 +typedef struct device_attribute __no_const device_attribute_no_const;
66777
66778 struct dev_ext_attribute {
66779 struct device_attribute attr;
66780 void *var;
66781 -};
66782 +} __do_const;
66783
66784 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
66785 char *buf);
66786 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
66787 index 94af418..b1ca7a2 100644
66788 --- a/include/linux/dma-mapping.h
66789 +++ b/include/linux/dma-mapping.h
66790 @@ -54,7 +54,7 @@ struct dma_map_ops {
66791 u64 (*get_required_mask)(struct device *dev);
66792 #endif
66793 int is_phys;
66794 -};
66795 +} __do_const;
66796
66797 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
66798
66799 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
66800 index d3201e4..8281e63 100644
66801 --- a/include/linux/dmaengine.h
66802 +++ b/include/linux/dmaengine.h
66803 @@ -1018,9 +1018,9 @@ struct dma_pinned_list {
66804 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
66805 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
66806
66807 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
66808 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
66809 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
66810 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
66811 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
66812 struct dma_pinned_list *pinned_list, struct page *page,
66813 unsigned int offset, size_t len);
66814
66815 diff --git a/include/linux/efi.h b/include/linux/efi.h
66816 index 7a9498a..155713d 100644
66817 --- a/include/linux/efi.h
66818 +++ b/include/linux/efi.h
66819 @@ -733,6 +733,7 @@ struct efivar_operations {
66820 efi_set_variable_t *set_variable;
66821 efi_query_variable_info_t *query_variable_info;
66822 };
66823 +typedef struct efivar_operations __no_const efivar_operations_no_const;
66824
66825 struct efivars {
66826 /*
66827 diff --git a/include/linux/elf.h b/include/linux/elf.h
66828 index 8c9048e..16a4665 100644
66829 --- a/include/linux/elf.h
66830 +++ b/include/linux/elf.h
66831 @@ -20,6 +20,7 @@ extern Elf32_Dyn _DYNAMIC [];
66832 #define elf_note elf32_note
66833 #define elf_addr_t Elf32_Off
66834 #define Elf_Half Elf32_Half
66835 +#define elf_dyn Elf32_Dyn
66836
66837 #else
66838
66839 @@ -30,6 +31,7 @@ extern Elf64_Dyn _DYNAMIC [];
66840 #define elf_note elf64_note
66841 #define elf_addr_t Elf64_Off
66842 #define Elf_Half Elf64_Half
66843 +#define elf_dyn Elf64_Dyn
66844
66845 #endif
66846
66847 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
66848 index fcb51c8..bdafcf6 100644
66849 --- a/include/linux/extcon.h
66850 +++ b/include/linux/extcon.h
66851 @@ -134,7 +134,7 @@ struct extcon_dev {
66852 /* /sys/class/extcon/.../mutually_exclusive/... */
66853 struct attribute_group attr_g_muex;
66854 struct attribute **attrs_muex;
66855 - struct device_attribute *d_attrs_muex;
66856 + device_attribute_no_const *d_attrs_muex;
66857 };
66858
66859 /**
66860 diff --git a/include/linux/fb.h b/include/linux/fb.h
66861 index c7a9571..02eeffe 100644
66862 --- a/include/linux/fb.h
66863 +++ b/include/linux/fb.h
66864 @@ -302,7 +302,7 @@ struct fb_ops {
66865 /* called at KDB enter and leave time to prepare the console */
66866 int (*fb_debug_enter)(struct fb_info *info);
66867 int (*fb_debug_leave)(struct fb_info *info);
66868 -};
66869 +} __do_const;
66870
66871 #ifdef CONFIG_FB_TILEBLITTING
66872 #define FB_TILE_CURSOR_NONE 0
66873 diff --git a/include/linux/filter.h b/include/linux/filter.h
66874 index c45eabc..baa0be5 100644
66875 --- a/include/linux/filter.h
66876 +++ b/include/linux/filter.h
66877 @@ -20,6 +20,7 @@ struct compat_sock_fprog {
66878
66879 struct sk_buff;
66880 struct sock;
66881 +struct bpf_jit_work;
66882
66883 struct sk_filter
66884 {
66885 @@ -27,6 +28,9 @@ struct sk_filter
66886 unsigned int len; /* Number of filter blocks */
66887 unsigned int (*bpf_func)(const struct sk_buff *skb,
66888 const struct sock_filter *filter);
66889 +#ifdef CONFIG_BPF_JIT
66890 + struct bpf_jit_work *work;
66891 +#endif
66892 struct rcu_head rcu;
66893 struct sock_filter insns[0];
66894 };
66895 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
66896 index 3044254..9767f41 100644
66897 --- a/include/linux/frontswap.h
66898 +++ b/include/linux/frontswap.h
66899 @@ -11,7 +11,7 @@ struct frontswap_ops {
66900 int (*load)(unsigned, pgoff_t, struct page *);
66901 void (*invalidate_page)(unsigned, pgoff_t);
66902 void (*invalidate_area)(unsigned);
66903 -};
66904 +} __no_const;
66905
66906 extern bool frontswap_enabled;
66907 extern struct frontswap_ops
66908 diff --git a/include/linux/fs.h b/include/linux/fs.h
66909 index 7617ee0..b575199 100644
66910 --- a/include/linux/fs.h
66911 +++ b/include/linux/fs.h
66912 @@ -1541,7 +1541,8 @@ struct file_operations {
66913 long (*fallocate)(struct file *file, int mode, loff_t offset,
66914 loff_t len);
66915 int (*show_fdinfo)(struct seq_file *m, struct file *f);
66916 -};
66917 +} __do_const;
66918 +typedef struct file_operations __no_const file_operations_no_const;
66919
66920 struct inode_operations {
66921 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
66922 @@ -2665,4 +2666,14 @@ static inline void inode_has_no_xattr(struct inode *inode)
66923 inode->i_flags |= S_NOSEC;
66924 }
66925
66926 +static inline bool is_sidechannel_device(const struct inode *inode)
66927 +{
66928 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
66929 + umode_t mode = inode->i_mode;
66930 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
66931 +#else
66932 + return false;
66933 +#endif
66934 +}
66935 +
66936 #endif /* _LINUX_FS_H */
66937 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
66938 index d0ae3a8..0244b34 100644
66939 --- a/include/linux/fs_struct.h
66940 +++ b/include/linux/fs_struct.h
66941 @@ -6,7 +6,7 @@
66942 #include <linux/seqlock.h>
66943
66944 struct fs_struct {
66945 - int users;
66946 + atomic_t users;
66947 spinlock_t lock;
66948 seqcount_t seq;
66949 int umask;
66950 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
66951 index 5dfa0aa..6acf322 100644
66952 --- a/include/linux/fscache-cache.h
66953 +++ b/include/linux/fscache-cache.h
66954 @@ -112,7 +112,7 @@ struct fscache_operation {
66955 fscache_operation_release_t release;
66956 };
66957
66958 -extern atomic_t fscache_op_debug_id;
66959 +extern atomic_unchecked_t fscache_op_debug_id;
66960 extern void fscache_op_work_func(struct work_struct *work);
66961
66962 extern void fscache_enqueue_operation(struct fscache_operation *);
66963 @@ -134,7 +134,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
66964 INIT_WORK(&op->work, fscache_op_work_func);
66965 atomic_set(&op->usage, 1);
66966 op->state = FSCACHE_OP_ST_INITIALISED;
66967 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
66968 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
66969 op->processor = processor;
66970 op->release = release;
66971 INIT_LIST_HEAD(&op->pend_link);
66972 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
66973 index 7a08623..4c07b0f 100644
66974 --- a/include/linux/fscache.h
66975 +++ b/include/linux/fscache.h
66976 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
66977 * - this is mandatory for any object that may have data
66978 */
66979 void (*now_uncached)(void *cookie_netfs_data);
66980 -};
66981 +} __do_const;
66982
66983 /*
66984 * fscache cached network filesystem type
66985 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
66986 index 0fbfb46..508eb0d 100644
66987 --- a/include/linux/fsnotify.h
66988 +++ b/include/linux/fsnotify.h
66989 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
66990 struct inode *inode = path->dentry->d_inode;
66991 __u32 mask = FS_ACCESS;
66992
66993 + if (is_sidechannel_device(inode))
66994 + return;
66995 +
66996 if (S_ISDIR(inode->i_mode))
66997 mask |= FS_ISDIR;
66998
66999 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
67000 struct inode *inode = path->dentry->d_inode;
67001 __u32 mask = FS_MODIFY;
67002
67003 + if (is_sidechannel_device(inode))
67004 + return;
67005 +
67006 if (S_ISDIR(inode->i_mode))
67007 mask |= FS_ISDIR;
67008
67009 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
67010 */
67011 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
67012 {
67013 - return kstrdup(name, GFP_KERNEL);
67014 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
67015 }
67016
67017 /*
67018 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
67019 index a3d4895..ddd2a50 100644
67020 --- a/include/linux/ftrace_event.h
67021 +++ b/include/linux/ftrace_event.h
67022 @@ -272,7 +272,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
67023 extern int trace_add_event_call(struct ftrace_event_call *call);
67024 extern void trace_remove_event_call(struct ftrace_event_call *call);
67025
67026 -#define is_signed_type(type) (((type)(-1)) < 0)
67027 +#define is_signed_type(type) (((type)(-1)) < (type)1)
67028
67029 int trace_set_clr_event(const char *system, const char *event, int set);
67030
67031 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
67032 index 79b8bba..86b539e 100644
67033 --- a/include/linux/genhd.h
67034 +++ b/include/linux/genhd.h
67035 @@ -194,7 +194,7 @@ struct gendisk {
67036 struct kobject *slave_dir;
67037
67038 struct timer_rand_state *random;
67039 - atomic_t sync_io; /* RAID */
67040 + atomic_unchecked_t sync_io; /* RAID */
67041 struct disk_events *ev;
67042 #ifdef CONFIG_BLK_DEV_INTEGRITY
67043 struct blk_integrity *integrity;
67044 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
67045 index 023bc34..b02b46a 100644
67046 --- a/include/linux/genl_magic_func.h
67047 +++ b/include/linux/genl_magic_func.h
67048 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
67049 },
67050
67051 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
67052 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
67053 +static struct genl_ops ZZZ_genl_ops[] = {
67054 #include GENL_MAGIC_INCLUDE_FILE
67055 };
67056
67057 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
67058 index 0f615eb..5c3832f 100644
67059 --- a/include/linux/gfp.h
67060 +++ b/include/linux/gfp.h
67061 @@ -35,6 +35,13 @@ struct vm_area_struct;
67062 #define ___GFP_NO_KSWAPD 0x400000u
67063 #define ___GFP_OTHER_NODE 0x800000u
67064 #define ___GFP_WRITE 0x1000000u
67065 +
67066 +#ifdef CONFIG_PAX_USERCOPY_SLABS
67067 +#define ___GFP_USERCOPY 0x2000000u
67068 +#else
67069 +#define ___GFP_USERCOPY 0
67070 +#endif
67071 +
67072 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
67073
67074 /*
67075 @@ -92,6 +99,7 @@ struct vm_area_struct;
67076 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
67077 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
67078 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
67079 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
67080
67081 /*
67082 * This may seem redundant, but it's a way of annotating false positives vs.
67083 @@ -99,7 +107,7 @@ struct vm_area_struct;
67084 */
67085 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
67086
67087 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
67088 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
67089 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
67090
67091 /* This equals 0, but use constants in case they ever change */
67092 @@ -153,6 +161,8 @@ struct vm_area_struct;
67093 /* 4GB DMA on some platforms */
67094 #define GFP_DMA32 __GFP_DMA32
67095
67096 +#define GFP_USERCOPY __GFP_USERCOPY
67097 +
67098 /* Convert GFP flags to their corresponding migrate type */
67099 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
67100 {
67101 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
67102 new file mode 100644
67103 index 0000000..ebe6d72
67104 --- /dev/null
67105 +++ b/include/linux/gracl.h
67106 @@ -0,0 +1,319 @@
67107 +#ifndef GR_ACL_H
67108 +#define GR_ACL_H
67109 +
67110 +#include <linux/grdefs.h>
67111 +#include <linux/resource.h>
67112 +#include <linux/capability.h>
67113 +#include <linux/dcache.h>
67114 +#include <asm/resource.h>
67115 +
67116 +/* Major status information */
67117 +
67118 +#define GR_VERSION "grsecurity 2.9.1"
67119 +#define GRSECURITY_VERSION 0x2901
67120 +
67121 +enum {
67122 + GR_SHUTDOWN = 0,
67123 + GR_ENABLE = 1,
67124 + GR_SPROLE = 2,
67125 + GR_RELOAD = 3,
67126 + GR_SEGVMOD = 4,
67127 + GR_STATUS = 5,
67128 + GR_UNSPROLE = 6,
67129 + GR_PASSSET = 7,
67130 + GR_SPROLEPAM = 8,
67131 +};
67132 +
67133 +/* Password setup definitions
67134 + * kernel/grhash.c */
67135 +enum {
67136 + GR_PW_LEN = 128,
67137 + GR_SALT_LEN = 16,
67138 + GR_SHA_LEN = 32,
67139 +};
67140 +
67141 +enum {
67142 + GR_SPROLE_LEN = 64,
67143 +};
67144 +
67145 +enum {
67146 + GR_NO_GLOB = 0,
67147 + GR_REG_GLOB,
67148 + GR_CREATE_GLOB
67149 +};
67150 +
67151 +#define GR_NLIMITS 32
67152 +
67153 +/* Begin Data Structures */
67154 +
67155 +struct sprole_pw {
67156 + unsigned char *rolename;
67157 + unsigned char salt[GR_SALT_LEN];
67158 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
67159 +};
67160 +
67161 +struct name_entry {
67162 + __u32 key;
67163 + ino_t inode;
67164 + dev_t device;
67165 + char *name;
67166 + __u16 len;
67167 + __u8 deleted;
67168 + struct name_entry *prev;
67169 + struct name_entry *next;
67170 +};
67171 +
67172 +struct inodev_entry {
67173 + struct name_entry *nentry;
67174 + struct inodev_entry *prev;
67175 + struct inodev_entry *next;
67176 +};
67177 +
67178 +struct acl_role_db {
67179 + struct acl_role_label **r_hash;
67180 + __u32 r_size;
67181 +};
67182 +
67183 +struct inodev_db {
67184 + struct inodev_entry **i_hash;
67185 + __u32 i_size;
67186 +};
67187 +
67188 +struct name_db {
67189 + struct name_entry **n_hash;
67190 + __u32 n_size;
67191 +};
67192 +
67193 +struct crash_uid {
67194 + uid_t uid;
67195 + unsigned long expires;
67196 +};
67197 +
67198 +struct gr_hash_struct {
67199 + void **table;
67200 + void **nametable;
67201 + void *first;
67202 + __u32 table_size;
67203 + __u32 used_size;
67204 + int type;
67205 +};
67206 +
67207 +/* Userspace Grsecurity ACL data structures */
67208 +
67209 +struct acl_subject_label {
67210 + char *filename;
67211 + ino_t inode;
67212 + dev_t device;
67213 + __u32 mode;
67214 + kernel_cap_t cap_mask;
67215 + kernel_cap_t cap_lower;
67216 + kernel_cap_t cap_invert_audit;
67217 +
67218 + struct rlimit res[GR_NLIMITS];
67219 + __u32 resmask;
67220 +
67221 + __u8 user_trans_type;
67222 + __u8 group_trans_type;
67223 + uid_t *user_transitions;
67224 + gid_t *group_transitions;
67225 + __u16 user_trans_num;
67226 + __u16 group_trans_num;
67227 +
67228 + __u32 sock_families[2];
67229 + __u32 ip_proto[8];
67230 + __u32 ip_type;
67231 + struct acl_ip_label **ips;
67232 + __u32 ip_num;
67233 + __u32 inaddr_any_override;
67234 +
67235 + __u32 crashes;
67236 + unsigned long expires;
67237 +
67238 + struct acl_subject_label *parent_subject;
67239 + struct gr_hash_struct *hash;
67240 + struct acl_subject_label *prev;
67241 + struct acl_subject_label *next;
67242 +
67243 + struct acl_object_label **obj_hash;
67244 + __u32 obj_hash_size;
67245 + __u16 pax_flags;
67246 +};
67247 +
67248 +struct role_allowed_ip {
67249 + __u32 addr;
67250 + __u32 netmask;
67251 +
67252 + struct role_allowed_ip *prev;
67253 + struct role_allowed_ip *next;
67254 +};
67255 +
67256 +struct role_transition {
67257 + char *rolename;
67258 +
67259 + struct role_transition *prev;
67260 + struct role_transition *next;
67261 +};
67262 +
67263 +struct acl_role_label {
67264 + char *rolename;
67265 + uid_t uidgid;
67266 + __u16 roletype;
67267 +
67268 + __u16 auth_attempts;
67269 + unsigned long expires;
67270 +
67271 + struct acl_subject_label *root_label;
67272 + struct gr_hash_struct *hash;
67273 +
67274 + struct acl_role_label *prev;
67275 + struct acl_role_label *next;
67276 +
67277 + struct role_transition *transitions;
67278 + struct role_allowed_ip *allowed_ips;
67279 + uid_t *domain_children;
67280 + __u16 domain_child_num;
67281 +
67282 + umode_t umask;
67283 +
67284 + struct acl_subject_label **subj_hash;
67285 + __u32 subj_hash_size;
67286 +};
67287 +
67288 +struct user_acl_role_db {
67289 + struct acl_role_label **r_table;
67290 + __u32 num_pointers; /* Number of allocations to track */
67291 + __u32 num_roles; /* Number of roles */
67292 + __u32 num_domain_children; /* Number of domain children */
67293 + __u32 num_subjects; /* Number of subjects */
67294 + __u32 num_objects; /* Number of objects */
67295 +};
67296 +
67297 +struct acl_object_label {
67298 + char *filename;
67299 + ino_t inode;
67300 + dev_t device;
67301 + __u32 mode;
67302 +
67303 + struct acl_subject_label *nested;
67304 + struct acl_object_label *globbed;
67305 +
67306 + /* next two structures not used */
67307 +
67308 + struct acl_object_label *prev;
67309 + struct acl_object_label *next;
67310 +};
67311 +
67312 +struct acl_ip_label {
67313 + char *iface;
67314 + __u32 addr;
67315 + __u32 netmask;
67316 + __u16 low, high;
67317 + __u8 mode;
67318 + __u32 type;
67319 + __u32 proto[8];
67320 +
67321 + /* next two structures not used */
67322 +
67323 + struct acl_ip_label *prev;
67324 + struct acl_ip_label *next;
67325 +};
67326 +
67327 +struct gr_arg {
67328 + struct user_acl_role_db role_db;
67329 + unsigned char pw[GR_PW_LEN];
67330 + unsigned char salt[GR_SALT_LEN];
67331 + unsigned char sum[GR_SHA_LEN];
67332 + unsigned char sp_role[GR_SPROLE_LEN];
67333 + struct sprole_pw *sprole_pws;
67334 + dev_t segv_device;
67335 + ino_t segv_inode;
67336 + uid_t segv_uid;
67337 + __u16 num_sprole_pws;
67338 + __u16 mode;
67339 +};
67340 +
67341 +struct gr_arg_wrapper {
67342 + struct gr_arg *arg;
67343 + __u32 version;
67344 + __u32 size;
67345 +};
67346 +
67347 +struct subject_map {
67348 + struct acl_subject_label *user;
67349 + struct acl_subject_label *kernel;
67350 + struct subject_map *prev;
67351 + struct subject_map *next;
67352 +};
67353 +
67354 +struct acl_subj_map_db {
67355 + struct subject_map **s_hash;
67356 + __u32 s_size;
67357 +};
67358 +
67359 +/* End Data Structures Section */
67360 +
67361 +/* Hash functions generated by empirical testing by Brad Spengler
67362 + Makes good use of the low bits of the inode. Generally 0-1 times
67363 + in loop for successful match. 0-3 for unsuccessful match.
67364 + Shift/add algorithm with modulus of table size and an XOR*/
67365 +
67366 +static __inline__ unsigned int
67367 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
67368 +{
67369 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
67370 +}
67371 +
67372 + static __inline__ unsigned int
67373 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
67374 +{
67375 + return ((const unsigned long)userp % sz);
67376 +}
67377 +
67378 +static __inline__ unsigned int
67379 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
67380 +{
67381 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
67382 +}
67383 +
67384 +static __inline__ unsigned int
67385 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
67386 +{
67387 + return full_name_hash((const unsigned char *)name, len) % sz;
67388 +}
67389 +
67390 +#define FOR_EACH_ROLE_START(role) \
67391 + role = role_list; \
67392 + while (role) {
67393 +
67394 +#define FOR_EACH_ROLE_END(role) \
67395 + role = role->prev; \
67396 + }
67397 +
67398 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
67399 + subj = NULL; \
67400 + iter = 0; \
67401 + while (iter < role->subj_hash_size) { \
67402 + if (subj == NULL) \
67403 + subj = role->subj_hash[iter]; \
67404 + if (subj == NULL) { \
67405 + iter++; \
67406 + continue; \
67407 + }
67408 +
67409 +#define FOR_EACH_SUBJECT_END(subj,iter) \
67410 + subj = subj->next; \
67411 + if (subj == NULL) \
67412 + iter++; \
67413 + }
67414 +
67415 +
67416 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
67417 + subj = role->hash->first; \
67418 + while (subj != NULL) {
67419 +
67420 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
67421 + subj = subj->next; \
67422 + }
67423 +
67424 +#endif
67425 +
67426 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
67427 new file mode 100644
67428 index 0000000..323ecf2
67429 --- /dev/null
67430 +++ b/include/linux/gralloc.h
67431 @@ -0,0 +1,9 @@
67432 +#ifndef __GRALLOC_H
67433 +#define __GRALLOC_H
67434 +
67435 +void acl_free_all(void);
67436 +int acl_alloc_stack_init(unsigned long size);
67437 +void *acl_alloc(unsigned long len);
67438 +void *acl_alloc_num(unsigned long num, unsigned long len);
67439 +
67440 +#endif
67441 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
67442 new file mode 100644
67443 index 0000000..be66033
67444 --- /dev/null
67445 +++ b/include/linux/grdefs.h
67446 @@ -0,0 +1,140 @@
67447 +#ifndef GRDEFS_H
67448 +#define GRDEFS_H
67449 +
67450 +/* Begin grsecurity status declarations */
67451 +
67452 +enum {
67453 + GR_READY = 0x01,
67454 + GR_STATUS_INIT = 0x00 // disabled state
67455 +};
67456 +
67457 +/* Begin ACL declarations */
67458 +
67459 +/* Role flags */
67460 +
67461 +enum {
67462 + GR_ROLE_USER = 0x0001,
67463 + GR_ROLE_GROUP = 0x0002,
67464 + GR_ROLE_DEFAULT = 0x0004,
67465 + GR_ROLE_SPECIAL = 0x0008,
67466 + GR_ROLE_AUTH = 0x0010,
67467 + GR_ROLE_NOPW = 0x0020,
67468 + GR_ROLE_GOD = 0x0040,
67469 + GR_ROLE_LEARN = 0x0080,
67470 + GR_ROLE_TPE = 0x0100,
67471 + GR_ROLE_DOMAIN = 0x0200,
67472 + GR_ROLE_PAM = 0x0400,
67473 + GR_ROLE_PERSIST = 0x0800
67474 +};
67475 +
67476 +/* ACL Subject and Object mode flags */
67477 +enum {
67478 + GR_DELETED = 0x80000000
67479 +};
67480 +
67481 +/* ACL Object-only mode flags */
67482 +enum {
67483 + GR_READ = 0x00000001,
67484 + GR_APPEND = 0x00000002,
67485 + GR_WRITE = 0x00000004,
67486 + GR_EXEC = 0x00000008,
67487 + GR_FIND = 0x00000010,
67488 + GR_INHERIT = 0x00000020,
67489 + GR_SETID = 0x00000040,
67490 + GR_CREATE = 0x00000080,
67491 + GR_DELETE = 0x00000100,
67492 + GR_LINK = 0x00000200,
67493 + GR_AUDIT_READ = 0x00000400,
67494 + GR_AUDIT_APPEND = 0x00000800,
67495 + GR_AUDIT_WRITE = 0x00001000,
67496 + GR_AUDIT_EXEC = 0x00002000,
67497 + GR_AUDIT_FIND = 0x00004000,
67498 + GR_AUDIT_INHERIT= 0x00008000,
67499 + GR_AUDIT_SETID = 0x00010000,
67500 + GR_AUDIT_CREATE = 0x00020000,
67501 + GR_AUDIT_DELETE = 0x00040000,
67502 + GR_AUDIT_LINK = 0x00080000,
67503 + GR_PTRACERD = 0x00100000,
67504 + GR_NOPTRACE = 0x00200000,
67505 + GR_SUPPRESS = 0x00400000,
67506 + GR_NOLEARN = 0x00800000,
67507 + GR_INIT_TRANSFER= 0x01000000
67508 +};
67509 +
67510 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
67511 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
67512 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
67513 +
67514 +/* ACL subject-only mode flags */
67515 +enum {
67516 + GR_KILL = 0x00000001,
67517 + GR_VIEW = 0x00000002,
67518 + GR_PROTECTED = 0x00000004,
67519 + GR_LEARN = 0x00000008,
67520 + GR_OVERRIDE = 0x00000010,
67521 + /* just a placeholder, this mode is only used in userspace */
67522 + GR_DUMMY = 0x00000020,
67523 + GR_PROTSHM = 0x00000040,
67524 + GR_KILLPROC = 0x00000080,
67525 + GR_KILLIPPROC = 0x00000100,
67526 + /* just a placeholder, this mode is only used in userspace */
67527 + GR_NOTROJAN = 0x00000200,
67528 + GR_PROTPROCFD = 0x00000400,
67529 + GR_PROCACCT = 0x00000800,
67530 + GR_RELAXPTRACE = 0x00001000,
67531 + //GR_NESTED = 0x00002000,
67532 + GR_INHERITLEARN = 0x00004000,
67533 + GR_PROCFIND = 0x00008000,
67534 + GR_POVERRIDE = 0x00010000,
67535 + GR_KERNELAUTH = 0x00020000,
67536 + GR_ATSECURE = 0x00040000,
67537 + GR_SHMEXEC = 0x00080000
67538 +};
67539 +
67540 +enum {
67541 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
67542 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
67543 + GR_PAX_ENABLE_MPROTECT = 0x0004,
67544 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
67545 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
67546 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
67547 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
67548 + GR_PAX_DISABLE_MPROTECT = 0x0400,
67549 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
67550 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
67551 +};
67552 +
67553 +enum {
67554 + GR_ID_USER = 0x01,
67555 + GR_ID_GROUP = 0x02,
67556 +};
67557 +
67558 +enum {
67559 + GR_ID_ALLOW = 0x01,
67560 + GR_ID_DENY = 0x02,
67561 +};
67562 +
67563 +#define GR_CRASH_RES 31
67564 +#define GR_UIDTABLE_MAX 500
67565 +
67566 +/* begin resource learning section */
67567 +enum {
67568 + GR_RLIM_CPU_BUMP = 60,
67569 + GR_RLIM_FSIZE_BUMP = 50000,
67570 + GR_RLIM_DATA_BUMP = 10000,
67571 + GR_RLIM_STACK_BUMP = 1000,
67572 + GR_RLIM_CORE_BUMP = 10000,
67573 + GR_RLIM_RSS_BUMP = 500000,
67574 + GR_RLIM_NPROC_BUMP = 1,
67575 + GR_RLIM_NOFILE_BUMP = 5,
67576 + GR_RLIM_MEMLOCK_BUMP = 50000,
67577 + GR_RLIM_AS_BUMP = 500000,
67578 + GR_RLIM_LOCKS_BUMP = 2,
67579 + GR_RLIM_SIGPENDING_BUMP = 5,
67580 + GR_RLIM_MSGQUEUE_BUMP = 10000,
67581 + GR_RLIM_NICE_BUMP = 1,
67582 + GR_RLIM_RTPRIO_BUMP = 1,
67583 + GR_RLIM_RTTIME_BUMP = 1000000
67584 +};
67585 +
67586 +#endif
67587 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
67588 new file mode 100644
67589 index 0000000..9bb6662
67590 --- /dev/null
67591 +++ b/include/linux/grinternal.h
67592 @@ -0,0 +1,215 @@
67593 +#ifndef __GRINTERNAL_H
67594 +#define __GRINTERNAL_H
67595 +
67596 +#ifdef CONFIG_GRKERNSEC
67597 +
67598 +#include <linux/fs.h>
67599 +#include <linux/mnt_namespace.h>
67600 +#include <linux/nsproxy.h>
67601 +#include <linux/gracl.h>
67602 +#include <linux/grdefs.h>
67603 +#include <linux/grmsg.h>
67604 +
67605 +void gr_add_learn_entry(const char *fmt, ...)
67606 + __attribute__ ((format (printf, 1, 2)));
67607 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
67608 + const struct vfsmount *mnt);
67609 +__u32 gr_check_create(const struct dentry *new_dentry,
67610 + const struct dentry *parent,
67611 + const struct vfsmount *mnt, const __u32 mode);
67612 +int gr_check_protected_task(const struct task_struct *task);
67613 +__u32 to_gr_audit(const __u32 reqmode);
67614 +int gr_set_acls(const int type);
67615 +int gr_apply_subject_to_task(struct task_struct *task);
67616 +int gr_acl_is_enabled(void);
67617 +char gr_roletype_to_char(void);
67618 +
67619 +void gr_handle_alertkill(struct task_struct *task);
67620 +char *gr_to_filename(const struct dentry *dentry,
67621 + const struct vfsmount *mnt);
67622 +char *gr_to_filename1(const struct dentry *dentry,
67623 + const struct vfsmount *mnt);
67624 +char *gr_to_filename2(const struct dentry *dentry,
67625 + const struct vfsmount *mnt);
67626 +char *gr_to_filename3(const struct dentry *dentry,
67627 + const struct vfsmount *mnt);
67628 +
67629 +extern int grsec_enable_ptrace_readexec;
67630 +extern int grsec_enable_harden_ptrace;
67631 +extern int grsec_enable_link;
67632 +extern int grsec_enable_fifo;
67633 +extern int grsec_enable_execve;
67634 +extern int grsec_enable_shm;
67635 +extern int grsec_enable_execlog;
67636 +extern int grsec_enable_signal;
67637 +extern int grsec_enable_audit_ptrace;
67638 +extern int grsec_enable_forkfail;
67639 +extern int grsec_enable_time;
67640 +extern int grsec_enable_rofs;
67641 +extern int grsec_enable_chroot_shmat;
67642 +extern int grsec_enable_chroot_mount;
67643 +extern int grsec_enable_chroot_double;
67644 +extern int grsec_enable_chroot_pivot;
67645 +extern int grsec_enable_chroot_chdir;
67646 +extern int grsec_enable_chroot_chmod;
67647 +extern int grsec_enable_chroot_mknod;
67648 +extern int grsec_enable_chroot_fchdir;
67649 +extern int grsec_enable_chroot_nice;
67650 +extern int grsec_enable_chroot_execlog;
67651 +extern int grsec_enable_chroot_caps;
67652 +extern int grsec_enable_chroot_sysctl;
67653 +extern int grsec_enable_chroot_unix;
67654 +extern int grsec_enable_symlinkown;
67655 +extern kgid_t grsec_symlinkown_gid;
67656 +extern int grsec_enable_tpe;
67657 +extern kgid_t grsec_tpe_gid;
67658 +extern int grsec_enable_tpe_all;
67659 +extern int grsec_enable_tpe_invert;
67660 +extern int grsec_enable_socket_all;
67661 +extern kgid_t grsec_socket_all_gid;
67662 +extern int grsec_enable_socket_client;
67663 +extern kgid_t grsec_socket_client_gid;
67664 +extern int grsec_enable_socket_server;
67665 +extern kgid_t grsec_socket_server_gid;
67666 +extern kgid_t grsec_audit_gid;
67667 +extern int grsec_enable_group;
67668 +extern int grsec_enable_audit_textrel;
67669 +extern int grsec_enable_log_rwxmaps;
67670 +extern int grsec_enable_mount;
67671 +extern int grsec_enable_chdir;
67672 +extern int grsec_resource_logging;
67673 +extern int grsec_enable_blackhole;
67674 +extern int grsec_lastack_retries;
67675 +extern int grsec_enable_brute;
67676 +extern int grsec_lock;
67677 +
67678 +extern spinlock_t grsec_alert_lock;
67679 +extern unsigned long grsec_alert_wtime;
67680 +extern unsigned long grsec_alert_fyet;
67681 +
67682 +extern spinlock_t grsec_audit_lock;
67683 +
67684 +extern rwlock_t grsec_exec_file_lock;
67685 +
67686 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
67687 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
67688 + (tsk)->exec_file->f_vfsmnt) : "/")
67689 +
67690 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
67691 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
67692 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
67693 +
67694 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
67695 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
67696 + (tsk)->exec_file->f_vfsmnt) : "/")
67697 +
67698 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
67699 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
67700 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
67701 +
67702 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
67703 +
67704 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
67705 +
67706 +#define GR_CHROOT_CAPS {{ \
67707 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
67708 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
67709 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
67710 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
67711 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
67712 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
67713 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
67714 +
67715 +#define security_learn(normal_msg,args...) \
67716 +({ \
67717 + read_lock(&grsec_exec_file_lock); \
67718 + gr_add_learn_entry(normal_msg "\n", ## args); \
67719 + read_unlock(&grsec_exec_file_lock); \
67720 +})
67721 +
67722 +enum {
67723 + GR_DO_AUDIT,
67724 + GR_DONT_AUDIT,
67725 + /* used for non-audit messages that we shouldn't kill the task on */
67726 + GR_DONT_AUDIT_GOOD
67727 +};
67728 +
67729 +enum {
67730 + GR_TTYSNIFF,
67731 + GR_RBAC,
67732 + GR_RBAC_STR,
67733 + GR_STR_RBAC,
67734 + GR_RBAC_MODE2,
67735 + GR_RBAC_MODE3,
67736 + GR_FILENAME,
67737 + GR_SYSCTL_HIDDEN,
67738 + GR_NOARGS,
67739 + GR_ONE_INT,
67740 + GR_ONE_INT_TWO_STR,
67741 + GR_ONE_STR,
67742 + GR_STR_INT,
67743 + GR_TWO_STR_INT,
67744 + GR_TWO_INT,
67745 + GR_TWO_U64,
67746 + GR_THREE_INT,
67747 + GR_FIVE_INT_TWO_STR,
67748 + GR_TWO_STR,
67749 + GR_THREE_STR,
67750 + GR_FOUR_STR,
67751 + GR_STR_FILENAME,
67752 + GR_FILENAME_STR,
67753 + GR_FILENAME_TWO_INT,
67754 + GR_FILENAME_TWO_INT_STR,
67755 + GR_TEXTREL,
67756 + GR_PTRACE,
67757 + GR_RESOURCE,
67758 + GR_CAP,
67759 + GR_SIG,
67760 + GR_SIG2,
67761 + GR_CRASH1,
67762 + GR_CRASH2,
67763 + GR_PSACCT,
67764 + GR_RWXMAP
67765 +};
67766 +
67767 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
67768 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
67769 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
67770 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
67771 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
67772 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
67773 +#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)
67774 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
67775 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
67776 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
67777 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
67778 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
67779 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
67780 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
67781 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
67782 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
67783 +#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)
67784 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
67785 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
67786 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
67787 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
67788 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
67789 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
67790 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
67791 +#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)
67792 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
67793 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
67794 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
67795 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
67796 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
67797 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
67798 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
67799 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
67800 +#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)
67801 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
67802 +
67803 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
67804 +
67805 +#endif
67806 +
67807 +#endif
67808 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
67809 new file mode 100644
67810 index 0000000..2bd4c8d
67811 --- /dev/null
67812 +++ b/include/linux/grmsg.h
67813 @@ -0,0 +1,111 @@
67814 +#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"
67815 +#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"
67816 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
67817 +#define GR_STOPMOD_MSG "denied modification of module state by "
67818 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
67819 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
67820 +#define GR_IOPERM_MSG "denied use of ioperm() by "
67821 +#define GR_IOPL_MSG "denied use of iopl() by "
67822 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
67823 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
67824 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
67825 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
67826 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
67827 +#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"
67828 +#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"
67829 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
67830 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
67831 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
67832 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
67833 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
67834 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
67835 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
67836 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
67837 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
67838 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
67839 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
67840 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
67841 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
67842 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
67843 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
67844 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
67845 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
67846 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
67847 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
67848 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
67849 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
67850 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
67851 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
67852 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
67853 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
67854 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
67855 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
67856 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
67857 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
67858 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
67859 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
67860 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
67861 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
67862 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
67863 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
67864 +#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"
67865 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
67866 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
67867 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
67868 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
67869 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
67870 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
67871 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
67872 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
67873 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
67874 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
67875 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
67876 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
67877 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
67878 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
67879 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
67880 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
67881 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
67882 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
67883 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
67884 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
67885 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
67886 +#define GR_NICE_CHROOT_MSG "denied priority change by "
67887 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
67888 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
67889 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
67890 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
67891 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
67892 +#define GR_TIME_MSG "time set by "
67893 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
67894 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
67895 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
67896 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
67897 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
67898 +#define GR_BIND_MSG "denied bind() by "
67899 +#define GR_CONNECT_MSG "denied connect() by "
67900 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
67901 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
67902 +#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"
67903 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
67904 +#define GR_CAP_ACL_MSG "use of %s denied for "
67905 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
67906 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
67907 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
67908 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
67909 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
67910 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
67911 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
67912 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
67913 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
67914 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
67915 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
67916 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
67917 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
67918 +#define GR_VM86_MSG "denied use of vm86 by "
67919 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
67920 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
67921 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
67922 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
67923 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
67924 +#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 "
67925 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
67926 new file mode 100644
67927 index 0000000..1ae241a
67928 --- /dev/null
67929 +++ b/include/linux/grsecurity.h
67930 @@ -0,0 +1,257 @@
67931 +#ifndef GR_SECURITY_H
67932 +#define GR_SECURITY_H
67933 +#include <linux/fs.h>
67934 +#include <linux/fs_struct.h>
67935 +#include <linux/binfmts.h>
67936 +#include <linux/gracl.h>
67937 +
67938 +/* notify of brain-dead configs */
67939 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67940 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
67941 +#endif
67942 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
67943 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
67944 +#endif
67945 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
67946 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
67947 +#endif
67948 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
67949 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
67950 +#endif
67951 +
67952 +#include <linux/compat.h>
67953 +
67954 +struct user_arg_ptr {
67955 +#ifdef CONFIG_COMPAT
67956 + bool is_compat;
67957 +#endif
67958 + union {
67959 + const char __user *const __user *native;
67960 +#ifdef CONFIG_COMPAT
67961 + const compat_uptr_t __user *compat;
67962 +#endif
67963 + } ptr;
67964 +};
67965 +
67966 +void gr_handle_brute_attach(unsigned long mm_flags);
67967 +void gr_handle_brute_check(void);
67968 +void gr_handle_kernel_exploit(void);
67969 +int gr_process_user_ban(void);
67970 +
67971 +char gr_roletype_to_char(void);
67972 +
67973 +int gr_acl_enable_at_secure(void);
67974 +
67975 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
67976 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
67977 +
67978 +void gr_del_task_from_ip_table(struct task_struct *p);
67979 +
67980 +int gr_pid_is_chrooted(struct task_struct *p);
67981 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
67982 +int gr_handle_chroot_nice(void);
67983 +int gr_handle_chroot_sysctl(const int op);
67984 +int gr_handle_chroot_setpriority(struct task_struct *p,
67985 + const int niceval);
67986 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
67987 +int gr_handle_chroot_chroot(const struct dentry *dentry,
67988 + const struct vfsmount *mnt);
67989 +void gr_handle_chroot_chdir(struct path *path);
67990 +int gr_handle_chroot_chmod(const struct dentry *dentry,
67991 + const struct vfsmount *mnt, const int mode);
67992 +int gr_handle_chroot_mknod(const struct dentry *dentry,
67993 + const struct vfsmount *mnt, const int mode);
67994 +int gr_handle_chroot_mount(const struct dentry *dentry,
67995 + const struct vfsmount *mnt,
67996 + const char *dev_name);
67997 +int gr_handle_chroot_pivot(void);
67998 +int gr_handle_chroot_unix(const pid_t pid);
67999 +
68000 +int gr_handle_rawio(const struct inode *inode);
68001 +
68002 +void gr_handle_ioperm(void);
68003 +void gr_handle_iopl(void);
68004 +
68005 +umode_t gr_acl_umask(void);
68006 +
68007 +int gr_tpe_allow(const struct file *file);
68008 +
68009 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
68010 +void gr_clear_chroot_entries(struct task_struct *task);
68011 +
68012 +void gr_log_forkfail(const int retval);
68013 +void gr_log_timechange(void);
68014 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
68015 +void gr_log_chdir(const struct dentry *dentry,
68016 + const struct vfsmount *mnt);
68017 +void gr_log_chroot_exec(const struct dentry *dentry,
68018 + const struct vfsmount *mnt);
68019 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
68020 +void gr_log_remount(const char *devname, const int retval);
68021 +void gr_log_unmount(const char *devname, const int retval);
68022 +void gr_log_mount(const char *from, const char *to, const int retval);
68023 +void gr_log_textrel(struct vm_area_struct *vma);
68024 +void gr_log_rwxmmap(struct file *file);
68025 +void gr_log_rwxmprotect(struct file *file);
68026 +
68027 +int gr_handle_follow_link(const struct inode *parent,
68028 + const struct inode *inode,
68029 + const struct dentry *dentry,
68030 + const struct vfsmount *mnt);
68031 +int gr_handle_fifo(const struct dentry *dentry,
68032 + const struct vfsmount *mnt,
68033 + const struct dentry *dir, const int flag,
68034 + const int acc_mode);
68035 +int gr_handle_hardlink(const struct dentry *dentry,
68036 + const struct vfsmount *mnt,
68037 + struct inode *inode,
68038 + const int mode, const struct filename *to);
68039 +
68040 +int gr_is_capable(const int cap);
68041 +int gr_is_capable_nolog(const int cap);
68042 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
68043 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
68044 +
68045 +void gr_copy_label(struct task_struct *tsk);
68046 +void gr_handle_crash(struct task_struct *task, const int sig);
68047 +int gr_handle_signal(const struct task_struct *p, const int sig);
68048 +int gr_check_crash_uid(const kuid_t uid);
68049 +int gr_check_protected_task(const struct task_struct *task);
68050 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
68051 +int gr_acl_handle_mmap(const struct file *file,
68052 + const unsigned long prot);
68053 +int gr_acl_handle_mprotect(const struct file *file,
68054 + const unsigned long prot);
68055 +int gr_check_hidden_task(const struct task_struct *tsk);
68056 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
68057 + const struct vfsmount *mnt);
68058 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
68059 + const struct vfsmount *mnt);
68060 +__u32 gr_acl_handle_access(const struct dentry *dentry,
68061 + const struct vfsmount *mnt, const int fmode);
68062 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
68063 + const struct vfsmount *mnt, umode_t *mode);
68064 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
68065 + const struct vfsmount *mnt);
68066 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
68067 + const struct vfsmount *mnt);
68068 +int gr_handle_ptrace(struct task_struct *task, const long request);
68069 +int gr_handle_proc_ptrace(struct task_struct *task);
68070 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
68071 + const struct vfsmount *mnt);
68072 +int gr_check_crash_exec(const struct file *filp);
68073 +int gr_acl_is_enabled(void);
68074 +void gr_set_kernel_label(struct task_struct *task);
68075 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
68076 + const kgid_t gid);
68077 +int gr_set_proc_label(const struct dentry *dentry,
68078 + const struct vfsmount *mnt,
68079 + const int unsafe_flags);
68080 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
68081 + const struct vfsmount *mnt);
68082 +__u32 gr_acl_handle_open(const struct dentry *dentry,
68083 + const struct vfsmount *mnt, int acc_mode);
68084 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
68085 + const struct dentry *p_dentry,
68086 + const struct vfsmount *p_mnt,
68087 + int open_flags, int acc_mode, const int imode);
68088 +void gr_handle_create(const struct dentry *dentry,
68089 + const struct vfsmount *mnt);
68090 +void gr_handle_proc_create(const struct dentry *dentry,
68091 + const struct inode *inode);
68092 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
68093 + const struct dentry *parent_dentry,
68094 + const struct vfsmount *parent_mnt,
68095 + const int mode);
68096 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
68097 + const struct dentry *parent_dentry,
68098 + const struct vfsmount *parent_mnt);
68099 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
68100 + const struct vfsmount *mnt);
68101 +void gr_handle_delete(const ino_t ino, const dev_t dev);
68102 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
68103 + const struct vfsmount *mnt);
68104 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
68105 + const struct dentry *parent_dentry,
68106 + const struct vfsmount *parent_mnt,
68107 + const struct filename *from);
68108 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
68109 + const struct dentry *parent_dentry,
68110 + const struct vfsmount *parent_mnt,
68111 + const struct dentry *old_dentry,
68112 + const struct vfsmount *old_mnt, const struct filename *to);
68113 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
68114 +int gr_acl_handle_rename(struct dentry *new_dentry,
68115 + struct dentry *parent_dentry,
68116 + const struct vfsmount *parent_mnt,
68117 + struct dentry *old_dentry,
68118 + struct inode *old_parent_inode,
68119 + struct vfsmount *old_mnt, const struct filename *newname);
68120 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
68121 + struct dentry *old_dentry,
68122 + struct dentry *new_dentry,
68123 + struct vfsmount *mnt, const __u8 replace);
68124 +__u32 gr_check_link(const struct dentry *new_dentry,
68125 + const struct dentry *parent_dentry,
68126 + const struct vfsmount *parent_mnt,
68127 + const struct dentry *old_dentry,
68128 + const struct vfsmount *old_mnt);
68129 +int gr_acl_handle_filldir(const struct file *file, const char *name,
68130 + const unsigned int namelen, const ino_t ino);
68131 +
68132 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
68133 + const struct vfsmount *mnt);
68134 +void gr_acl_handle_exit(void);
68135 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
68136 +int gr_acl_handle_procpidmem(const struct task_struct *task);
68137 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
68138 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
68139 +void gr_audit_ptrace(struct task_struct *task);
68140 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
68141 +void gr_put_exec_file(struct task_struct *task);
68142 +
68143 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
68144 +
68145 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
68146 +extern void gr_learn_resource(const struct task_struct *task, const int res,
68147 + const unsigned long wanted, const int gt);
68148 +#else
68149 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
68150 + const unsigned long wanted, const int gt)
68151 +{
68152 +}
68153 +#endif
68154 +
68155 +#ifdef CONFIG_GRKERNSEC_RESLOG
68156 +extern void gr_log_resource(const struct task_struct *task, const int res,
68157 + const unsigned long wanted, const int gt);
68158 +#else
68159 +static inline void gr_log_resource(const struct task_struct *task, const int res,
68160 + const unsigned long wanted, const int gt)
68161 +{
68162 +}
68163 +#endif
68164 +
68165 +#ifdef CONFIG_GRKERNSEC
68166 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
68167 +void gr_handle_vm86(void);
68168 +void gr_handle_mem_readwrite(u64 from, u64 to);
68169 +
68170 +void gr_log_badprocpid(const char *entry);
68171 +
68172 +extern int grsec_enable_dmesg;
68173 +extern int grsec_disable_privio;
68174 +
68175 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
68176 +extern kgid_t grsec_proc_gid;
68177 +#endif
68178 +
68179 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
68180 +extern int grsec_enable_chroot_findtask;
68181 +#endif
68182 +#ifdef CONFIG_GRKERNSEC_SETXID
68183 +extern int grsec_enable_setxid;
68184 +#endif
68185 +#endif
68186 +
68187 +#endif
68188 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
68189 new file mode 100644
68190 index 0000000..e7ffaaf
68191 --- /dev/null
68192 +++ b/include/linux/grsock.h
68193 @@ -0,0 +1,19 @@
68194 +#ifndef __GRSOCK_H
68195 +#define __GRSOCK_H
68196 +
68197 +extern void gr_attach_curr_ip(const struct sock *sk);
68198 +extern int gr_handle_sock_all(const int family, const int type,
68199 + const int protocol);
68200 +extern int gr_handle_sock_server(const struct sockaddr *sck);
68201 +extern int gr_handle_sock_server_other(const struct sock *sck);
68202 +extern int gr_handle_sock_client(const struct sockaddr *sck);
68203 +extern int gr_search_connect(struct socket * sock,
68204 + struct sockaddr_in * addr);
68205 +extern int gr_search_bind(struct socket * sock,
68206 + struct sockaddr_in * addr);
68207 +extern int gr_search_listen(struct socket * sock);
68208 +extern int gr_search_accept(struct socket * sock);
68209 +extern int gr_search_socket(const int domain, const int type,
68210 + const int protocol);
68211 +
68212 +#endif
68213 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
68214 index ef788b5..ac41b7b 100644
68215 --- a/include/linux/highmem.h
68216 +++ b/include/linux/highmem.h
68217 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
68218 kunmap_atomic(kaddr);
68219 }
68220
68221 +static inline void sanitize_highpage(struct page *page)
68222 +{
68223 + void *kaddr;
68224 + unsigned long flags;
68225 +
68226 + local_irq_save(flags);
68227 + kaddr = kmap_atomic(page);
68228 + clear_page(kaddr);
68229 + kunmap_atomic(kaddr);
68230 + local_irq_restore(flags);
68231 +}
68232 +
68233 static inline void zero_user_segments(struct page *page,
68234 unsigned start1, unsigned end1,
68235 unsigned start2, unsigned end2)
68236 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
68237 index 1c7b89a..7f52502 100644
68238 --- a/include/linux/hwmon-sysfs.h
68239 +++ b/include/linux/hwmon-sysfs.h
68240 @@ -25,7 +25,8 @@
68241 struct sensor_device_attribute{
68242 struct device_attribute dev_attr;
68243 int index;
68244 -};
68245 +} __do_const;
68246 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
68247 #define to_sensor_dev_attr(_dev_attr) \
68248 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
68249
68250 @@ -41,7 +42,7 @@ struct sensor_device_attribute_2 {
68251 struct device_attribute dev_attr;
68252 u8 index;
68253 u8 nr;
68254 -};
68255 +} __do_const;
68256 #define to_sensor_dev_attr_2(_dev_attr) \
68257 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
68258
68259 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
68260 index d0c4db7..61b3577 100644
68261 --- a/include/linux/i2c.h
68262 +++ b/include/linux/i2c.h
68263 @@ -369,6 +369,7 @@ struct i2c_algorithm {
68264 /* To determine what the adapter supports */
68265 u32 (*functionality) (struct i2c_adapter *);
68266 };
68267 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
68268
68269 /*
68270 * i2c_adapter is the structure used to identify a physical i2c bus along
68271 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
68272 index d23c3c2..eb63c81 100644
68273 --- a/include/linux/i2o.h
68274 +++ b/include/linux/i2o.h
68275 @@ -565,7 +565,7 @@ struct i2o_controller {
68276 struct i2o_device *exec; /* Executive */
68277 #if BITS_PER_LONG == 64
68278 spinlock_t context_list_lock; /* lock for context_list */
68279 - atomic_t context_list_counter; /* needed for unique contexts */
68280 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
68281 struct list_head context_list; /* list of context id's
68282 and pointers */
68283 #endif
68284 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
68285 index aff7ad8..3942bbd 100644
68286 --- a/include/linux/if_pppox.h
68287 +++ b/include/linux/if_pppox.h
68288 @@ -76,7 +76,7 @@ struct pppox_proto {
68289 int (*ioctl)(struct socket *sock, unsigned int cmd,
68290 unsigned long arg);
68291 struct module *owner;
68292 -};
68293 +} __do_const;
68294
68295 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
68296 extern void unregister_pppox_proto(int proto_num);
68297 diff --git a/include/linux/init.h b/include/linux/init.h
68298 index 10ed4f4..8e8490d 100644
68299 --- a/include/linux/init.h
68300 +++ b/include/linux/init.h
68301 @@ -39,9 +39,36 @@
68302 * Also note, that this data cannot be "const".
68303 */
68304
68305 +#ifdef MODULE
68306 +#define add_init_latent_entropy
68307 +#define add_devinit_latent_entropy
68308 +#define add_cpuinit_latent_entropy
68309 +#define add_meminit_latent_entropy
68310 +#else
68311 +#define add_init_latent_entropy __latent_entropy
68312 +
68313 +#ifdef CONFIG_HOTPLUG
68314 +#define add_devinit_latent_entropy
68315 +#else
68316 +#define add_devinit_latent_entropy __latent_entropy
68317 +#endif
68318 +
68319 +#ifdef CONFIG_HOTPLUG_CPU
68320 +#define add_cpuinit_latent_entropy
68321 +#else
68322 +#define add_cpuinit_latent_entropy __latent_entropy
68323 +#endif
68324 +
68325 +#ifdef CONFIG_MEMORY_HOTPLUG
68326 +#define add_meminit_latent_entropy
68327 +#else
68328 +#define add_meminit_latent_entropy __latent_entropy
68329 +#endif
68330 +#endif
68331 +
68332 /* These are for everybody (although not all archs will actually
68333 discard it in modules) */
68334 -#define __init __section(.init.text) __cold notrace
68335 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
68336 #define __initdata __section(.init.data)
68337 #define __initconst __constsection(.init.rodata)
68338 #define __exitdata __section(.exit.data)
68339 @@ -94,7 +121,7 @@
68340 #define __exit __section(.exit.text) __exitused __cold notrace
68341
68342 /* Used for HOTPLUG_CPU */
68343 -#define __cpuinit __section(.cpuinit.text) __cold notrace
68344 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_cpuinit_latent_entropy
68345 #define __cpuinitdata __section(.cpuinit.data)
68346 #define __cpuinitconst __constsection(.cpuinit.rodata)
68347 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
68348 @@ -102,7 +129,7 @@
68349 #define __cpuexitconst __constsection(.cpuexit.rodata)
68350
68351 /* Used for MEMORY_HOTPLUG */
68352 -#define __meminit __section(.meminit.text) __cold notrace
68353 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
68354 #define __meminitdata __section(.meminit.data)
68355 #define __meminitconst __constsection(.meminit.rodata)
68356 #define __memexit __section(.memexit.text) __exitused __cold notrace
68357 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
68358 index 6d087c5..401cab8 100644
68359 --- a/include/linux/init_task.h
68360 +++ b/include/linux/init_task.h
68361 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
68362
68363 #define INIT_TASK_COMM "swapper"
68364
68365 +#ifdef CONFIG_X86
68366 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
68367 +#else
68368 +#define INIT_TASK_THREAD_INFO
68369 +#endif
68370 +
68371 /*
68372 * INIT_TASK is used to set up the first task table, touch at
68373 * your own risk!. Base=0, limit=0x1fffff (=2MB)
68374 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
68375 RCU_POINTER_INITIALIZER(cred, &init_cred), \
68376 .comm = INIT_TASK_COMM, \
68377 .thread = INIT_THREAD, \
68378 + INIT_TASK_THREAD_INFO \
68379 .fs = &init_fs, \
68380 .files = &init_files, \
68381 .signal = &init_signals, \
68382 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
68383 index 5fa5afe..ac55b25 100644
68384 --- a/include/linux/interrupt.h
68385 +++ b/include/linux/interrupt.h
68386 @@ -430,7 +430,7 @@ enum
68387 /* map softirq index to softirq name. update 'softirq_to_name' in
68388 * kernel/softirq.c when adding a new softirq.
68389 */
68390 -extern char *softirq_to_name[NR_SOFTIRQS];
68391 +extern const char * const softirq_to_name[NR_SOFTIRQS];
68392
68393 /* softirq mask and active fields moved to irq_cpustat_t in
68394 * asm/hardirq.h to get better cache usage. KAO
68395 @@ -438,12 +438,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
68396
68397 struct softirq_action
68398 {
68399 - void (*action)(struct softirq_action *);
68400 -};
68401 + void (*action)(void);
68402 +} __no_const;
68403
68404 asmlinkage void do_softirq(void);
68405 asmlinkage void __do_softirq(void);
68406 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
68407 +extern void open_softirq(int nr, void (*action)(void));
68408 extern void softirq_init(void);
68409 extern void __raise_softirq_irqoff(unsigned int nr);
68410
68411 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
68412 index f3b99e1..9b73cee 100644
68413 --- a/include/linux/iommu.h
68414 +++ b/include/linux/iommu.h
68415 @@ -101,7 +101,7 @@ struct iommu_ops {
68416 int (*domain_set_attr)(struct iommu_domain *domain,
68417 enum iommu_attr attr, void *data);
68418 unsigned long pgsize_bitmap;
68419 -};
68420 +} __do_const;
68421
68422 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
68423 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
68424 diff --git a/include/linux/irq.h b/include/linux/irq.h
68425 index fdf2c4a..5332486 100644
68426 --- a/include/linux/irq.h
68427 +++ b/include/linux/irq.h
68428 @@ -328,7 +328,8 @@ struct irq_chip {
68429 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
68430
68431 unsigned long flags;
68432 -};
68433 +} __do_const;
68434 +typedef struct irq_chip __no_const irq_chip_no_const;
68435
68436 /*
68437 * irq_chip specific flags
68438 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
68439 index 6883e19..06992b1 100644
68440 --- a/include/linux/kallsyms.h
68441 +++ b/include/linux/kallsyms.h
68442 @@ -15,7 +15,8 @@
68443
68444 struct module;
68445
68446 -#ifdef CONFIG_KALLSYMS
68447 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
68448 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68449 /* Lookup the address for a symbol. Returns 0 if not found. */
68450 unsigned long kallsyms_lookup_name(const char *name);
68451
68452 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
68453 /* Stupid that this does nothing, but I didn't create this mess. */
68454 #define __print_symbol(fmt, addr)
68455 #endif /*CONFIG_KALLSYMS*/
68456 +#else /* when included by kallsyms.c, vsnprintf.c, or
68457 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
68458 +extern void __print_symbol(const char *fmt, unsigned long address);
68459 +extern int sprint_backtrace(char *buffer, unsigned long address);
68460 +extern int sprint_symbol(char *buffer, unsigned long address);
68461 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
68462 +const char *kallsyms_lookup(unsigned long addr,
68463 + unsigned long *symbolsize,
68464 + unsigned long *offset,
68465 + char **modname, char *namebuf);
68466 +#endif
68467
68468 /* This macro allows us to keep printk typechecking */
68469 static __printf(1, 2)
68470 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
68471 index 518a53a..5e28358 100644
68472 --- a/include/linux/key-type.h
68473 +++ b/include/linux/key-type.h
68474 @@ -125,7 +125,7 @@ struct key_type {
68475 /* internal fields */
68476 struct list_head link; /* link in types list */
68477 struct lock_class_key lock_class; /* key->sem lock class */
68478 -};
68479 +} __do_const;
68480
68481 extern struct key_type key_type_keyring;
68482
68483 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
68484 index 4dff0c6..1ca9b72 100644
68485 --- a/include/linux/kgdb.h
68486 +++ b/include/linux/kgdb.h
68487 @@ -53,7 +53,7 @@ extern int kgdb_connected;
68488 extern int kgdb_io_module_registered;
68489
68490 extern atomic_t kgdb_setting_breakpoint;
68491 -extern atomic_t kgdb_cpu_doing_single_step;
68492 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
68493
68494 extern struct task_struct *kgdb_usethread;
68495 extern struct task_struct *kgdb_contthread;
68496 @@ -255,7 +255,7 @@ struct kgdb_arch {
68497 void (*correct_hw_break)(void);
68498
68499 void (*enable_nmi)(bool on);
68500 -};
68501 +} __do_const;
68502
68503 /**
68504 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
68505 @@ -280,7 +280,7 @@ struct kgdb_io {
68506 void (*pre_exception) (void);
68507 void (*post_exception) (void);
68508 int is_console;
68509 -};
68510 +} __do_const;
68511
68512 extern struct kgdb_arch arch_kgdb_ops;
68513
68514 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
68515 index 5398d58..5883a34 100644
68516 --- a/include/linux/kmod.h
68517 +++ b/include/linux/kmod.h
68518 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
68519 * usually useless though. */
68520 extern __printf(2, 3)
68521 int __request_module(bool wait, const char *name, ...);
68522 +extern __printf(3, 4)
68523 +int ___request_module(bool wait, char *param_name, const char *name, ...);
68524 #define request_module(mod...) __request_module(true, mod)
68525 #define request_module_nowait(mod...) __request_module(false, mod)
68526 #define try_then_request_module(x, mod...) \
68527 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
68528 index 939b112..ed6ed51 100644
68529 --- a/include/linux/kobject.h
68530 +++ b/include/linux/kobject.h
68531 @@ -111,7 +111,7 @@ struct kobj_type {
68532 struct attribute **default_attrs;
68533 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
68534 const void *(*namespace)(struct kobject *kobj);
68535 -};
68536 +} __do_const;
68537
68538 struct kobj_uevent_env {
68539 char *envp[UEVENT_NUM_ENVP];
68540 @@ -134,6 +134,7 @@ struct kobj_attribute {
68541 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
68542 const char *buf, size_t count);
68543 };
68544 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
68545
68546 extern const struct sysfs_ops kobj_sysfs_ops;
68547
68548 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
68549 index f66b065..c2c29b4 100644
68550 --- a/include/linux/kobject_ns.h
68551 +++ b/include/linux/kobject_ns.h
68552 @@ -43,7 +43,7 @@ struct kobj_ns_type_operations {
68553 const void *(*netlink_ns)(struct sock *sk);
68554 const void *(*initial_ns)(void);
68555 void (*drop_ns)(void *);
68556 -};
68557 +} __do_const;
68558
68559 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
68560 int kobj_ns_type_registered(enum kobj_ns_type type);
68561 diff --git a/include/linux/kref.h b/include/linux/kref.h
68562 index 4972e6e..de4d19b 100644
68563 --- a/include/linux/kref.h
68564 +++ b/include/linux/kref.h
68565 @@ -64,7 +64,7 @@ static inline void kref_get(struct kref *kref)
68566 static inline int kref_sub(struct kref *kref, unsigned int count,
68567 void (*release)(struct kref *kref))
68568 {
68569 - WARN_ON(release == NULL);
68570 + BUG_ON(release == NULL);
68571
68572 if (atomic_sub_and_test((int) count, &kref->refcount)) {
68573 release(kref);
68574 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
68575 index 2c497ab..afe32f5 100644
68576 --- a/include/linux/kvm_host.h
68577 +++ b/include/linux/kvm_host.h
68578 @@ -418,7 +418,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
68579 int __must_check vcpu_load(struct kvm_vcpu *vcpu);
68580 void vcpu_put(struct kvm_vcpu *vcpu);
68581
68582 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
68583 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
68584 struct module *module);
68585 void kvm_exit(void);
68586
68587 @@ -574,7 +574,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
68588 struct kvm_guest_debug *dbg);
68589 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
68590
68591 -int kvm_arch_init(void *opaque);
68592 +int kvm_arch_init(const void *opaque);
68593 void kvm_arch_exit(void);
68594
68595 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
68596 diff --git a/include/linux/libata.h b/include/linux/libata.h
68597 index 649e5f8..ead5194 100644
68598 --- a/include/linux/libata.h
68599 +++ b/include/linux/libata.h
68600 @@ -915,7 +915,7 @@ struct ata_port_operations {
68601 * fields must be pointers.
68602 */
68603 const struct ata_port_operations *inherits;
68604 -};
68605 +} __do_const;
68606
68607 struct ata_port_info {
68608 unsigned long flags;
68609 diff --git a/include/linux/list.h b/include/linux/list.h
68610 index cc6d2aa..c10ee83 100644
68611 --- a/include/linux/list.h
68612 +++ b/include/linux/list.h
68613 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
68614 extern void list_del(struct list_head *entry);
68615 #endif
68616
68617 +extern void __pax_list_add(struct list_head *new,
68618 + struct list_head *prev,
68619 + struct list_head *next);
68620 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
68621 +{
68622 + __pax_list_add(new, head, head->next);
68623 +}
68624 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
68625 +{
68626 + __pax_list_add(new, head->prev, head);
68627 +}
68628 +extern void pax_list_del(struct list_head *entry);
68629 +
68630 /**
68631 * list_replace - replace old entry by new one
68632 * @old : the element to be replaced
68633 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
68634 INIT_LIST_HEAD(entry);
68635 }
68636
68637 +extern void pax_list_del_init(struct list_head *entry);
68638 +
68639 /**
68640 * list_move - delete from one list and add as another's head
68641 * @list: the entry to move
68642 diff --git a/include/linux/mm.h b/include/linux/mm.h
68643 index 66e2f7c..ea88001 100644
68644 --- a/include/linux/mm.h
68645 +++ b/include/linux/mm.h
68646 @@ -101,6 +101,11 @@ extern unsigned int kobjsize(const void *objp);
68647 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
68648 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
68649 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
68650 +
68651 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
68652 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
68653 +#endif
68654 +
68655 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
68656
68657 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
68658 @@ -231,6 +236,7 @@ struct vm_operations_struct {
68659 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
68660 unsigned long size, pgoff_t pgoff);
68661 };
68662 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
68663
68664 struct mmu_gather;
68665 struct inode;
68666 @@ -1068,34 +1074,6 @@ int set_page_dirty(struct page *page);
68667 int set_page_dirty_lock(struct page *page);
68668 int clear_page_dirty_for_io(struct page *page);
68669
68670 -/* Is the vma a continuation of the stack vma above it? */
68671 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
68672 -{
68673 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
68674 -}
68675 -
68676 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
68677 - unsigned long addr)
68678 -{
68679 - return (vma->vm_flags & VM_GROWSDOWN) &&
68680 - (vma->vm_start == addr) &&
68681 - !vma_growsdown(vma->vm_prev, addr);
68682 -}
68683 -
68684 -/* Is the vma a continuation of the stack vma below it? */
68685 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
68686 -{
68687 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
68688 -}
68689 -
68690 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
68691 - unsigned long addr)
68692 -{
68693 - return (vma->vm_flags & VM_GROWSUP) &&
68694 - (vma->vm_end == addr) &&
68695 - !vma_growsup(vma->vm_next, addr);
68696 -}
68697 -
68698 extern pid_t
68699 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
68700
68701 @@ -1198,6 +1176,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
68702 }
68703 #endif
68704
68705 +#ifdef CONFIG_MMU
68706 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
68707 +#else
68708 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
68709 +{
68710 + return __pgprot(0);
68711 +}
68712 +#endif
68713 +
68714 int vma_wants_writenotify(struct vm_area_struct *vma);
68715
68716 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
68717 @@ -1216,8 +1203,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
68718 {
68719 return 0;
68720 }
68721 +
68722 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
68723 + unsigned long address)
68724 +{
68725 + return 0;
68726 +}
68727 #else
68728 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
68729 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
68730 #endif
68731
68732 #ifdef __PAGETABLE_PMD_FOLDED
68733 @@ -1226,8 +1220,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
68734 {
68735 return 0;
68736 }
68737 +
68738 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
68739 + unsigned long address)
68740 +{
68741 + return 0;
68742 +}
68743 #else
68744 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
68745 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
68746 #endif
68747
68748 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
68749 @@ -1245,11 +1246,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
68750 NULL: pud_offset(pgd, address);
68751 }
68752
68753 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
68754 +{
68755 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
68756 + NULL: pud_offset(pgd, address);
68757 +}
68758 +
68759 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
68760 {
68761 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
68762 NULL: pmd_offset(pud, address);
68763 }
68764 +
68765 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
68766 +{
68767 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
68768 + NULL: pmd_offset(pud, address);
68769 +}
68770 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
68771
68772 #if USE_SPLIT_PTLOCKS
68773 @@ -1479,6 +1492,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
68774 unsigned long, unsigned long,
68775 unsigned long, unsigned long);
68776 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
68777 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
68778
68779 /* These take the mm semaphore themselves */
68780 extern unsigned long vm_brk(unsigned long, unsigned long);
68781 @@ -1573,6 +1587,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
68782 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
68783 struct vm_area_struct **pprev);
68784
68785 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
68786 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
68787 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
68788 +
68789 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
68790 NULL if none. Assume start_addr < end_addr. */
68791 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
68792 @@ -1601,15 +1619,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
68793 return vma;
68794 }
68795
68796 -#ifdef CONFIG_MMU
68797 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
68798 -#else
68799 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
68800 -{
68801 - return __pgprot(0);
68802 -}
68803 -#endif
68804 -
68805 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
68806 unsigned long change_prot_numa(struct vm_area_struct *vma,
68807 unsigned long start, unsigned long end);
68808 @@ -1721,7 +1730,7 @@ extern int unpoison_memory(unsigned long pfn);
68809 extern int sysctl_memory_failure_early_kill;
68810 extern int sysctl_memory_failure_recovery;
68811 extern void shake_page(struct page *p, int access);
68812 -extern atomic_long_t mce_bad_pages;
68813 +extern atomic_long_unchecked_t mce_bad_pages;
68814 extern int soft_offline_page(struct page *page, int flags);
68815
68816 extern void dump_page(struct page *page);
68817 @@ -1752,5 +1761,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
68818 static inline bool page_is_guard(struct page *page) { return false; }
68819 #endif /* CONFIG_DEBUG_PAGEALLOC */
68820
68821 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
68822 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
68823 +#else
68824 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
68825 +#endif
68826 +
68827 #endif /* __KERNEL__ */
68828 #endif /* _LINUX_MM_H */
68829 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
68830 index f8f5162..a039af9 100644
68831 --- a/include/linux/mm_types.h
68832 +++ b/include/linux/mm_types.h
68833 @@ -288,6 +288,8 @@ struct vm_area_struct {
68834 #ifdef CONFIG_NUMA
68835 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
68836 #endif
68837 +
68838 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
68839 };
68840
68841 struct core_thread {
68842 @@ -362,7 +364,7 @@ struct mm_struct {
68843 unsigned long def_flags;
68844 unsigned long nr_ptes; /* Page table pages */
68845 unsigned long start_code, end_code, start_data, end_data;
68846 - unsigned long start_brk, brk, start_stack;
68847 + unsigned long aslr_gap, start_brk, brk, start_stack;
68848 unsigned long arg_start, arg_end, env_start, env_end;
68849
68850 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
68851 @@ -436,6 +438,24 @@ struct mm_struct {
68852 int first_nid;
68853 #endif
68854 struct uprobes_state uprobes_state;
68855 +
68856 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
68857 + unsigned long pax_flags;
68858 +#endif
68859 +
68860 +#ifdef CONFIG_PAX_DLRESOLVE
68861 + unsigned long call_dl_resolve;
68862 +#endif
68863 +
68864 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
68865 + unsigned long call_syscall;
68866 +#endif
68867 +
68868 +#ifdef CONFIG_PAX_ASLR
68869 + unsigned long delta_mmap; /* randomized offset */
68870 + unsigned long delta_stack; /* randomized offset */
68871 +#endif
68872 +
68873 };
68874
68875 /* first nid will either be a valid NID or one of these values */
68876 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
68877 index c5d5278..f0b68c8 100644
68878 --- a/include/linux/mmiotrace.h
68879 +++ b/include/linux/mmiotrace.h
68880 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
68881 /* Called from ioremap.c */
68882 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
68883 void __iomem *addr);
68884 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
68885 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
68886
68887 /* For anyone to insert markers. Remember trailing newline. */
68888 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
68889 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
68890 {
68891 }
68892
68893 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
68894 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
68895 {
68896 }
68897
68898 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
68899 index 73b64a3..6562925 100644
68900 --- a/include/linux/mmzone.h
68901 +++ b/include/linux/mmzone.h
68902 @@ -412,7 +412,7 @@ struct zone {
68903 unsigned long flags; /* zone flags, see below */
68904
68905 /* Zone statistics */
68906 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68907 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
68908
68909 /*
68910 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
68911 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
68912 index fed3def..c933f99 100644
68913 --- a/include/linux/mod_devicetable.h
68914 +++ b/include/linux/mod_devicetable.h
68915 @@ -12,7 +12,7 @@
68916 typedef unsigned long kernel_ulong_t;
68917 #endif
68918
68919 -#define PCI_ANY_ID (~0)
68920 +#define PCI_ANY_ID ((__u16)~0)
68921
68922 struct pci_device_id {
68923 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
68924 @@ -139,7 +139,7 @@ struct usb_device_id {
68925 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
68926 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
68927
68928 -#define HID_ANY_ID (~0)
68929 +#define HID_ANY_ID (~0U)
68930 #define HID_BUS_ANY 0xffff
68931 #define HID_GROUP_ANY 0x0000
68932
68933 @@ -498,7 +498,7 @@ struct dmi_system_id {
68934 const char *ident;
68935 struct dmi_strmatch matches[4];
68936 void *driver_data;
68937 -};
68938 +} __do_const;
68939 /*
68940 * struct dmi_device_id appears during expansion of
68941 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
68942 diff --git a/include/linux/module.h b/include/linux/module.h
68943 index 1375ee3..ced8177 100644
68944 --- a/include/linux/module.h
68945 +++ b/include/linux/module.h
68946 @@ -17,9 +17,11 @@
68947 #include <linux/moduleparam.h>
68948 #include <linux/tracepoint.h>
68949 #include <linux/export.h>
68950 +#include <linux/fs.h>
68951
68952 #include <linux/percpu.h>
68953 #include <asm/module.h>
68954 +#include <asm/pgtable.h>
68955
68956 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
68957 #define MODULE_SIG_STRING "~Module signature appended~\n"
68958 @@ -54,12 +56,13 @@ struct module_attribute {
68959 int (*test)(struct module *);
68960 void (*free)(struct module *);
68961 };
68962 +typedef struct module_attribute __no_const module_attribute_no_const;
68963
68964 struct module_version_attribute {
68965 struct module_attribute mattr;
68966 const char *module_name;
68967 const char *version;
68968 -} __attribute__ ((__aligned__(sizeof(void *))));
68969 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
68970
68971 extern ssize_t __modver_version_show(struct module_attribute *,
68972 struct module_kobject *, char *);
68973 @@ -232,7 +235,7 @@ struct module
68974
68975 /* Sysfs stuff. */
68976 struct module_kobject mkobj;
68977 - struct module_attribute *modinfo_attrs;
68978 + module_attribute_no_const *modinfo_attrs;
68979 const char *version;
68980 const char *srcversion;
68981 struct kobject *holders_dir;
68982 @@ -281,19 +284,16 @@ struct module
68983 int (*init)(void);
68984
68985 /* If this is non-NULL, vfree after init() returns */
68986 - void *module_init;
68987 + void *module_init_rx, *module_init_rw;
68988
68989 /* Here is the actual code + data, vfree'd on unload. */
68990 - void *module_core;
68991 + void *module_core_rx, *module_core_rw;
68992
68993 /* Here are the sizes of the init and core sections */
68994 - unsigned int init_size, core_size;
68995 + unsigned int init_size_rw, core_size_rw;
68996
68997 /* The size of the executable code in each section. */
68998 - unsigned int init_text_size, core_text_size;
68999 -
69000 - /* Size of RO sections of the module (text+rodata) */
69001 - unsigned int init_ro_size, core_ro_size;
69002 + unsigned int init_size_rx, core_size_rx;
69003
69004 /* Arch-specific module values */
69005 struct mod_arch_specific arch;
69006 @@ -349,6 +349,10 @@ struct module
69007 #ifdef CONFIG_EVENT_TRACING
69008 struct ftrace_event_call **trace_events;
69009 unsigned int num_trace_events;
69010 + struct file_operations trace_id;
69011 + struct file_operations trace_enable;
69012 + struct file_operations trace_format;
69013 + struct file_operations trace_filter;
69014 #endif
69015 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
69016 unsigned int num_ftrace_callsites;
69017 @@ -396,16 +400,46 @@ bool is_module_address(unsigned long addr);
69018 bool is_module_percpu_address(unsigned long addr);
69019 bool is_module_text_address(unsigned long addr);
69020
69021 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
69022 +{
69023 +
69024 +#ifdef CONFIG_PAX_KERNEXEC
69025 + if (ktla_ktva(addr) >= (unsigned long)start &&
69026 + ktla_ktva(addr) < (unsigned long)start + size)
69027 + return 1;
69028 +#endif
69029 +
69030 + return ((void *)addr >= start && (void *)addr < start + size);
69031 +}
69032 +
69033 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
69034 +{
69035 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
69036 +}
69037 +
69038 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
69039 +{
69040 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
69041 +}
69042 +
69043 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
69044 +{
69045 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
69046 +}
69047 +
69048 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
69049 +{
69050 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
69051 +}
69052 +
69053 static inline int within_module_core(unsigned long addr, struct module *mod)
69054 {
69055 - return (unsigned long)mod->module_core <= addr &&
69056 - addr < (unsigned long)mod->module_core + mod->core_size;
69057 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
69058 }
69059
69060 static inline int within_module_init(unsigned long addr, struct module *mod)
69061 {
69062 - return (unsigned long)mod->module_init <= addr &&
69063 - addr < (unsigned long)mod->module_init + mod->init_size;
69064 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
69065 }
69066
69067 /* Search for module by name: must hold module_mutex. */
69068 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
69069 index 560ca53..5ee8d73 100644
69070 --- a/include/linux/moduleloader.h
69071 +++ b/include/linux/moduleloader.h
69072 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
69073
69074 /* Allocator used for allocating struct module, core sections and init
69075 sections. Returns NULL on failure. */
69076 -void *module_alloc(unsigned long size);
69077 +void *module_alloc(unsigned long size) __size_overflow(1);
69078 +
69079 +#ifdef CONFIG_PAX_KERNEXEC
69080 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
69081 +#else
69082 +#define module_alloc_exec(x) module_alloc(x)
69083 +#endif
69084
69085 /* Free memory returned from module_alloc. */
69086 void module_free(struct module *mod, void *module_region);
69087
69088 +#ifdef CONFIG_PAX_KERNEXEC
69089 +void module_free_exec(struct module *mod, void *module_region);
69090 +#else
69091 +#define module_free_exec(x, y) module_free((x), (y))
69092 +#endif
69093 +
69094 /*
69095 * Apply the given relocation to the (simplified) ELF. Return -error
69096 * or 0.
69097 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
69098 unsigned int relsec,
69099 struct module *me)
69100 {
69101 +#ifdef CONFIG_MODULES
69102 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69103 +#endif
69104 return -ENOEXEC;
69105 }
69106 #endif
69107 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
69108 unsigned int relsec,
69109 struct module *me)
69110 {
69111 +#ifdef CONFIG_MODULES
69112 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
69113 +#endif
69114 return -ENOEXEC;
69115 }
69116 #endif
69117 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
69118 index 137b419..fe663ec 100644
69119 --- a/include/linux/moduleparam.h
69120 +++ b/include/linux/moduleparam.h
69121 @@ -284,7 +284,7 @@ static inline void __kernel_param_unlock(void)
69122 * @len is usually just sizeof(string).
69123 */
69124 #define module_param_string(name, string, len, perm) \
69125 - static const struct kparam_string __param_string_##name \
69126 + static const struct kparam_string __param_string_##name __used \
69127 = { len, string }; \
69128 __module_param_call(MODULE_PARAM_PREFIX, name, \
69129 &param_ops_string, \
69130 @@ -423,7 +423,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
69131 */
69132 #define module_param_array_named(name, array, type, nump, perm) \
69133 param_check_##type(name, &(array)[0]); \
69134 - static const struct kparam_array __param_arr_##name \
69135 + static const struct kparam_array __param_arr_##name __used \
69136 = { .max = ARRAY_SIZE(array), .num = nump, \
69137 .ops = &param_ops_##type, \
69138 .elemsize = sizeof(array[0]), .elem = array }; \
69139 diff --git a/include/linux/namei.h b/include/linux/namei.h
69140 index 5a5ff57..5ae5070 100644
69141 --- a/include/linux/namei.h
69142 +++ b/include/linux/namei.h
69143 @@ -19,7 +19,7 @@ struct nameidata {
69144 unsigned seq;
69145 int last_type;
69146 unsigned depth;
69147 - char *saved_names[MAX_NESTED_LINKS + 1];
69148 + const char *saved_names[MAX_NESTED_LINKS + 1];
69149 };
69150
69151 /*
69152 @@ -84,12 +84,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
69153
69154 extern void nd_jump_link(struct nameidata *nd, struct path *path);
69155
69156 -static inline void nd_set_link(struct nameidata *nd, char *path)
69157 +static inline void nd_set_link(struct nameidata *nd, const char *path)
69158 {
69159 nd->saved_names[nd->depth] = path;
69160 }
69161
69162 -static inline char *nd_get_link(struct nameidata *nd)
69163 +static inline const char *nd_get_link(const struct nameidata *nd)
69164 {
69165 return nd->saved_names[nd->depth];
69166 }
69167 diff --git a/include/linux/net.h b/include/linux/net.h
69168 index aa16731..514b875 100644
69169 --- a/include/linux/net.h
69170 +++ b/include/linux/net.h
69171 @@ -183,7 +183,7 @@ struct net_proto_family {
69172 int (*create)(struct net *net, struct socket *sock,
69173 int protocol, int kern);
69174 struct module *owner;
69175 -};
69176 +} __do_const;
69177
69178 struct iovec;
69179 struct kvec;
69180 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
69181 index 9ef07d0..130a5d9 100644
69182 --- a/include/linux/netdevice.h
69183 +++ b/include/linux/netdevice.h
69184 @@ -1012,6 +1012,7 @@ struct net_device_ops {
69185 u32 pid, u32 seq,
69186 struct net_device *dev);
69187 };
69188 +typedef struct net_device_ops __no_const net_device_ops_no_const;
69189
69190 /*
69191 * The DEVICE structure.
69192 @@ -1078,7 +1079,7 @@ struct net_device {
69193 int iflink;
69194
69195 struct net_device_stats stats;
69196 - atomic_long_t rx_dropped; /* dropped packets by core network
69197 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
69198 * Do not use this in drivers.
69199 */
69200
69201 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
69202 index ee14284..bc65d63 100644
69203 --- a/include/linux/netfilter.h
69204 +++ b/include/linux/netfilter.h
69205 @@ -82,7 +82,7 @@ struct nf_sockopt_ops {
69206 #endif
69207 /* Use the module struct to lock set/get code in place */
69208 struct module *owner;
69209 -};
69210 +} __do_const;
69211
69212 /* Function to register/unregister hook points. */
69213 int nf_register_hook(struct nf_hook_ops *reg);
69214 diff --git a/include/linux/netfilter/ipset/ip_set.h b/include/linux/netfilter/ipset/ip_set.h
69215 index 7958e84..ed74d7a 100644
69216 --- a/include/linux/netfilter/ipset/ip_set.h
69217 +++ b/include/linux/netfilter/ipset/ip_set.h
69218 @@ -98,7 +98,7 @@ struct ip_set_type_variant {
69219 /* Return true if "b" set is the same as "a"
69220 * according to the create set parameters */
69221 bool (*same_set)(const struct ip_set *a, const struct ip_set *b);
69222 -};
69223 +} __do_const;
69224
69225 /* The core set type structure */
69226 struct ip_set_type {
69227 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
69228 index 4966dde..7d8ce06 100644
69229 --- a/include/linux/netfilter/nfnetlink.h
69230 +++ b/include/linux/netfilter/nfnetlink.h
69231 @@ -16,7 +16,7 @@ struct nfnl_callback {
69232 const struct nlattr * const cda[]);
69233 const struct nla_policy *policy; /* netlink attribute policy */
69234 const u_int16_t attr_count; /* number of nlattr's */
69235 -};
69236 +} __do_const;
69237
69238 struct nfnetlink_subsystem {
69239 const char *name;
69240 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
69241 new file mode 100644
69242 index 0000000..33f4af8
69243 --- /dev/null
69244 +++ b/include/linux/netfilter/xt_gradm.h
69245 @@ -0,0 +1,9 @@
69246 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
69247 +#define _LINUX_NETFILTER_XT_GRADM_H 1
69248 +
69249 +struct xt_gradm_mtinfo {
69250 + __u16 flags;
69251 + __u16 invflags;
69252 +};
69253 +
69254 +#endif
69255 diff --git a/include/linux/nls.h b/include/linux/nls.h
69256 index 5dc635f..35f5e11 100644
69257 --- a/include/linux/nls.h
69258 +++ b/include/linux/nls.h
69259 @@ -31,7 +31,7 @@ struct nls_table {
69260 const unsigned char *charset2upper;
69261 struct module *owner;
69262 struct nls_table *next;
69263 -};
69264 +} __do_const;
69265
69266 /* this value hold the maximum octet of charset */
69267 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
69268 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
69269 index d65746e..62e72c2 100644
69270 --- a/include/linux/notifier.h
69271 +++ b/include/linux/notifier.h
69272 @@ -51,7 +51,8 @@ struct notifier_block {
69273 int (*notifier_call)(struct notifier_block *, unsigned long, void *);
69274 struct notifier_block __rcu *next;
69275 int priority;
69276 -};
69277 +} __do_const;
69278 +typedef struct notifier_block __no_const notifier_block_no_const;
69279
69280 struct atomic_notifier_head {
69281 spinlock_t lock;
69282 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
69283 index a4c5624..79d6d88 100644
69284 --- a/include/linux/oprofile.h
69285 +++ b/include/linux/oprofile.h
69286 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
69287 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
69288 char const * name, ulong * val);
69289
69290 -/** Create a file for read-only access to an atomic_t. */
69291 +/** Create a file for read-only access to an atomic_unchecked_t. */
69292 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
69293 - char const * name, atomic_t * val);
69294 + char const * name, atomic_unchecked_t * val);
69295
69296 /** create a directory */
69297 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
69298 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
69299 index 45fc162..01a4068 100644
69300 --- a/include/linux/pci_hotplug.h
69301 +++ b/include/linux/pci_hotplug.h
69302 @@ -80,7 +80,8 @@ struct hotplug_slot_ops {
69303 int (*get_attention_status) (struct hotplug_slot *slot, u8 *value);
69304 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
69305 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
69306 -};
69307 +} __do_const;
69308 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
69309
69310 /**
69311 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
69312 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
69313 index 6bfb2faa..e5bc5e5 100644
69314 --- a/include/linux/perf_event.h
69315 +++ b/include/linux/perf_event.h
69316 @@ -328,8 +328,8 @@ struct perf_event {
69317
69318 enum perf_event_active_state state;
69319 unsigned int attach_state;
69320 - local64_t count;
69321 - atomic64_t child_count;
69322 + local64_t count; /* PaX: fix it one day */
69323 + atomic64_unchecked_t child_count;
69324
69325 /*
69326 * These are the total time in nanoseconds that the event
69327 @@ -380,8 +380,8 @@ struct perf_event {
69328 * These accumulate total time (in nanoseconds) that children
69329 * events have been enabled and running, respectively.
69330 */
69331 - atomic64_t child_total_time_enabled;
69332 - atomic64_t child_total_time_running;
69333 + atomic64_unchecked_t child_total_time_enabled;
69334 + atomic64_unchecked_t child_total_time_running;
69335
69336 /*
69337 * Protect attach/detach and child_list:
69338 @@ -801,7 +801,7 @@ static inline void perf_event_task_tick(void) { }
69339 */
69340 #define perf_cpu_notifier(fn) \
69341 do { \
69342 - static struct notifier_block fn##_nb __cpuinitdata = \
69343 + static struct notifier_block fn##_nb = \
69344 { .notifier_call = fn, .priority = CPU_PRI_PERF }; \
69345 unsigned long cpu = smp_processor_id(); \
69346 unsigned long flags; \
69347 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
69348 index ad1a427..6419649 100644
69349 --- a/include/linux/pipe_fs_i.h
69350 +++ b/include/linux/pipe_fs_i.h
69351 @@ -45,9 +45,9 @@ struct pipe_buffer {
69352 struct pipe_inode_info {
69353 wait_queue_head_t wait;
69354 unsigned int nrbufs, curbuf, buffers;
69355 - unsigned int readers;
69356 - unsigned int writers;
69357 - unsigned int waiting_writers;
69358 + atomic_t readers;
69359 + atomic_t writers;
69360 + atomic_t waiting_writers;
69361 unsigned int r_counter;
69362 unsigned int w_counter;
69363 struct page *tmp_page;
69364 diff --git a/include/linux/platform_data/usb-ehci-s5p.h b/include/linux/platform_data/usb-ehci-s5p.h
69365 index 5f28cae..3d23723 100644
69366 --- a/include/linux/platform_data/usb-ehci-s5p.h
69367 +++ b/include/linux/platform_data/usb-ehci-s5p.h
69368 @@ -14,7 +14,7 @@
69369 struct s5p_ehci_platdata {
69370 int (*phy_init)(struct platform_device *pdev, int type);
69371 int (*phy_exit)(struct platform_device *pdev, int type);
69372 -};
69373 +} __no_const;
69374
69375 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
69376
69377 diff --git a/include/linux/platform_data/usb-exynos.h b/include/linux/platform_data/usb-exynos.h
69378 index c256c59..8ea94c7 100644
69379 --- a/include/linux/platform_data/usb-exynos.h
69380 +++ b/include/linux/platform_data/usb-exynos.h
69381 @@ -14,7 +14,7 @@
69382 struct exynos4_ohci_platdata {
69383 int (*phy_init)(struct platform_device *pdev, int type);
69384 int (*phy_exit)(struct platform_device *pdev, int type);
69385 -};
69386 +} __no_const;
69387
69388 extern void exynos4_ohci_set_platdata(struct exynos4_ohci_platdata *pd);
69389
69390 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
69391 index 7c1d252..c5c773e 100644
69392 --- a/include/linux/pm_domain.h
69393 +++ b/include/linux/pm_domain.h
69394 @@ -48,7 +48,7 @@ struct gpd_dev_ops {
69395
69396 struct gpd_cpu_data {
69397 unsigned int saved_exit_latency;
69398 - struct cpuidle_state *idle_state;
69399 + cpuidle_state_no_const *idle_state;
69400 };
69401
69402 struct generic_pm_domain {
69403 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
69404 index f271860..6b3bec5 100644
69405 --- a/include/linux/pm_runtime.h
69406 +++ b/include/linux/pm_runtime.h
69407 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
69408
69409 static inline void pm_runtime_mark_last_busy(struct device *dev)
69410 {
69411 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
69412 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
69413 }
69414
69415 #else /* !CONFIG_PM_RUNTIME */
69416 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
69417 index 195aafc..49a7bc2 100644
69418 --- a/include/linux/pnp.h
69419 +++ b/include/linux/pnp.h
69420 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
69421 struct pnp_fixup {
69422 char id[7];
69423 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
69424 -};
69425 +} __do_const;
69426
69427 /* config parameters */
69428 #define PNP_CONFIG_NORMAL 0x0001
69429 diff --git a/include/linux/poison.h b/include/linux/poison.h
69430 index 2110a81..13a11bb 100644
69431 --- a/include/linux/poison.h
69432 +++ b/include/linux/poison.h
69433 @@ -19,8 +19,8 @@
69434 * under normal circumstances, used to verify that nobody uses
69435 * non-initialized list entries.
69436 */
69437 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
69438 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
69439 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
69440 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
69441
69442 /********** include/linux/timer.h **********/
69443 /*
69444 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
69445 index c0f44c2..1572583 100644
69446 --- a/include/linux/power/smartreflex.h
69447 +++ b/include/linux/power/smartreflex.h
69448 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
69449 int (*notify)(struct omap_sr *sr, u32 status);
69450 u8 notify_flags;
69451 u8 class_type;
69452 -};
69453 +} __do_const;
69454
69455 /**
69456 * struct omap_sr_nvalue_table - Smartreflex n-target value info
69457 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
69458 index 4ea1d37..80f4b33 100644
69459 --- a/include/linux/ppp-comp.h
69460 +++ b/include/linux/ppp-comp.h
69461 @@ -84,7 +84,7 @@ struct compressor {
69462 struct module *owner;
69463 /* Extra skb space needed by the compressor algorithm */
69464 unsigned int comp_extra;
69465 -};
69466 +} __do_const;
69467
69468 /*
69469 * The return value from decompress routine is the length of the
69470 diff --git a/include/linux/printk.h b/include/linux/printk.h
69471 index 9afc01e..92c32e8 100644
69472 --- a/include/linux/printk.h
69473 +++ b/include/linux/printk.h
69474 @@ -101,6 +101,8 @@ void early_printk(const char *fmt, ...);
69475 extern int printk_needs_cpu(int cpu);
69476 extern void printk_tick(void);
69477
69478 +extern int kptr_restrict;
69479 +
69480 #ifdef CONFIG_PRINTK
69481 asmlinkage __printf(5, 0)
69482 int vprintk_emit(int facility, int level,
69483 @@ -135,7 +137,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
69484
69485 extern int printk_delay_msec;
69486 extern int dmesg_restrict;
69487 -extern int kptr_restrict;
69488
69489 void log_buf_kexec_setup(void);
69490 void __init setup_log_buf(int early);
69491 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
69492 index 32676b3..8f7a182 100644
69493 --- a/include/linux/proc_fs.h
69494 +++ b/include/linux/proc_fs.h
69495 @@ -159,6 +159,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
69496 return proc_create_data(name, mode, parent, proc_fops, NULL);
69497 }
69498
69499 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
69500 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
69501 +{
69502 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69503 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
69504 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69505 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
69506 +#else
69507 + return proc_create_data(name, mode, parent, proc_fops, NULL);
69508 +#endif
69509 +}
69510 +
69511 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
69512 umode_t mode, struct proc_dir_entry *base,
69513 read_proc_t *read_proc, void * data)
69514 diff --git a/include/linux/random.h b/include/linux/random.h
69515 index d984608..d6f0042 100644
69516 --- a/include/linux/random.h
69517 +++ b/include/linux/random.h
69518 @@ -39,6 +39,11 @@ void prandom_seed(u32 seed);
69519 u32 prandom_u32_state(struct rnd_state *);
69520 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
69521
69522 +static inline unsigned long pax_get_random_long(void)
69523 +{
69524 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
69525 +}
69526 +
69527 /*
69528 * Handle minimum values for seeds
69529 */
69530 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
69531 index c92dd28..08f4eab 100644
69532 --- a/include/linux/rculist.h
69533 +++ b/include/linux/rculist.h
69534 @@ -44,6 +44,9 @@ extern void __list_add_rcu(struct list_head *new,
69535 struct list_head *prev, struct list_head *next);
69536 #endif
69537
69538 +extern void __pax_list_add_rcu(struct list_head *new,
69539 + struct list_head *prev, struct list_head *next);
69540 +
69541 /**
69542 * list_add_rcu - add a new entry to rcu-protected list
69543 * @new: new entry to be added
69544 @@ -65,6 +68,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
69545 __list_add_rcu(new, head, head->next);
69546 }
69547
69548 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
69549 +{
69550 + __pax_list_add_rcu(new, head, head->next);
69551 +}
69552 +
69553 /**
69554 * list_add_tail_rcu - add a new entry to rcu-protected list
69555 * @new: new entry to be added
69556 @@ -87,6 +95,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
69557 __list_add_rcu(new, head->prev, head);
69558 }
69559
69560 +static inline void pax_list_add_tail_rcu(struct list_head *new,
69561 + struct list_head *head)
69562 +{
69563 + __pax_list_add_rcu(new, head->prev, head);
69564 +}
69565 +
69566 /**
69567 * list_del_rcu - deletes entry from list without re-initialization
69568 * @entry: the element to delete from the list.
69569 @@ -117,6 +131,8 @@ static inline void list_del_rcu(struct list_head *entry)
69570 entry->prev = LIST_POISON2;
69571 }
69572
69573 +extern void pax_list_del_rcu(struct list_head *entry);
69574 +
69575 /**
69576 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
69577 * @n: the element to delete from the hash list.
69578 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
69579 index 23b3630..e1bc12b 100644
69580 --- a/include/linux/reboot.h
69581 +++ b/include/linux/reboot.h
69582 @@ -18,9 +18,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
69583 * Architecture-specific implementations of sys_reboot commands.
69584 */
69585
69586 -extern void machine_restart(char *cmd);
69587 -extern void machine_halt(void);
69588 -extern void machine_power_off(void);
69589 +extern void machine_restart(char *cmd) __noreturn;
69590 +extern void machine_halt(void) __noreturn;
69591 +extern void machine_power_off(void) __noreturn;
69592
69593 extern void machine_shutdown(void);
69594 struct pt_regs;
69595 @@ -31,9 +31,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
69596 */
69597
69598 extern void kernel_restart_prepare(char *cmd);
69599 -extern void kernel_restart(char *cmd);
69600 -extern void kernel_halt(void);
69601 -extern void kernel_power_off(void);
69602 +extern void kernel_restart(char *cmd) __noreturn;
69603 +extern void kernel_halt(void) __noreturn;
69604 +extern void kernel_power_off(void) __noreturn;
69605
69606 extern int C_A_D; /* for sysctl */
69607 void ctrl_alt_del(void);
69608 @@ -47,7 +47,7 @@ extern int orderly_poweroff(bool force);
69609 * Emergency restart, callable from an interrupt handler.
69610 */
69611
69612 -extern void emergency_restart(void);
69613 +extern void emergency_restart(void) __noreturn;
69614 #include <asm/emergency-restart.h>
69615
69616 #endif /* _LINUX_REBOOT_H */
69617 diff --git a/include/linux/regset.h b/include/linux/regset.h
69618 index 8e0c9fe..ac4d221 100644
69619 --- a/include/linux/regset.h
69620 +++ b/include/linux/regset.h
69621 @@ -161,7 +161,8 @@ struct user_regset {
69622 unsigned int align;
69623 unsigned int bias;
69624 unsigned int core_note_type;
69625 -};
69626 +} __do_const;
69627 +typedef struct user_regset __no_const user_regset_no_const;
69628
69629 /**
69630 * struct user_regset_view - available regsets
69631 diff --git a/include/linux/relay.h b/include/linux/relay.h
69632 index 91cacc3..b55ff74 100644
69633 --- a/include/linux/relay.h
69634 +++ b/include/linux/relay.h
69635 @@ -160,7 +160,7 @@ struct rchan_callbacks
69636 * The callback should return 0 if successful, negative if not.
69637 */
69638 int (*remove_buf_file)(struct dentry *dentry);
69639 -};
69640 +} __no_const;
69641
69642 /*
69643 * CONFIG_RELAY kernel API, kernel/relay.c
69644 diff --git a/include/linux/rio.h b/include/linux/rio.h
69645 index a3e7842..d973ca6 100644
69646 --- a/include/linux/rio.h
69647 +++ b/include/linux/rio.h
69648 @@ -339,7 +339,7 @@ struct rio_ops {
69649 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
69650 u64 rstart, u32 size, u32 flags);
69651 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
69652 -};
69653 +} __no_const;
69654
69655 #define RIO_RESOURCE_MEM 0x00000100
69656 #define RIO_RESOURCE_DOORBELL 0x00000200
69657 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
69658 index c20635c..2f5def4 100644
69659 --- a/include/linux/rmap.h
69660 +++ b/include/linux/rmap.h
69661 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
69662 void anon_vma_init(void); /* create anon_vma_cachep */
69663 int anon_vma_prepare(struct vm_area_struct *);
69664 void unlink_anon_vmas(struct vm_area_struct *);
69665 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
69666 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
69667 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
69668 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
69669
69670 static inline void anon_vma_merge(struct vm_area_struct *vma,
69671 struct vm_area_struct *next)
69672 diff --git a/include/linux/sched.h b/include/linux/sched.h
69673 index d211247..a5cbf38b 100644
69674 --- a/include/linux/sched.h
69675 +++ b/include/linux/sched.h
69676 @@ -61,6 +61,7 @@ struct bio_list;
69677 struct fs_struct;
69678 struct perf_event_context;
69679 struct blk_plug;
69680 +struct linux_binprm;
69681
69682 /*
69683 * List of flags we want to share for kernel threads,
69684 @@ -354,10 +355,23 @@ struct user_namespace;
69685 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
69686
69687 extern int sysctl_max_map_count;
69688 +extern unsigned long sysctl_heap_stack_gap;
69689
69690 #include <linux/aio.h>
69691
69692 #ifdef CONFIG_MMU
69693 +
69694 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
69695 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
69696 +#else
69697 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
69698 +{
69699 + return 0;
69700 +}
69701 +#endif
69702 +
69703 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
69704 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
69705 extern void arch_pick_mmap_layout(struct mm_struct *mm);
69706 extern unsigned long
69707 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
69708 @@ -639,6 +653,17 @@ struct signal_struct {
69709 #ifdef CONFIG_TASKSTATS
69710 struct taskstats *stats;
69711 #endif
69712 +
69713 +#ifdef CONFIG_GRKERNSEC
69714 + u32 curr_ip;
69715 + u32 saved_ip;
69716 + u32 gr_saddr;
69717 + u32 gr_daddr;
69718 + u16 gr_sport;
69719 + u16 gr_dport;
69720 + u8 used_accept:1;
69721 +#endif
69722 +
69723 #ifdef CONFIG_AUDIT
69724 unsigned audit_tty;
69725 struct tty_audit_buf *tty_audit_buf;
69726 @@ -717,6 +742,11 @@ struct user_struct {
69727 struct key *session_keyring; /* UID's default session keyring */
69728 #endif
69729
69730 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
69731 + unsigned int banned;
69732 + unsigned long ban_expires;
69733 +#endif
69734 +
69735 /* Hash table maintenance information */
69736 struct hlist_node uidhash_node;
69737 kuid_t uid;
69738 @@ -1116,7 +1146,7 @@ struct sched_class {
69739 #ifdef CONFIG_FAIR_GROUP_SCHED
69740 void (*task_move_group) (struct task_struct *p, int on_rq);
69741 #endif
69742 -};
69743 +} __do_const;
69744
69745 struct load_weight {
69746 unsigned long weight, inv_weight;
69747 @@ -1360,8 +1390,8 @@ struct task_struct {
69748 struct list_head thread_group;
69749
69750 struct completion *vfork_done; /* for vfork() */
69751 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
69752 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
69753 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
69754 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
69755
69756 cputime_t utime, stime, utimescaled, stimescaled;
69757 cputime_t gtime;
69758 @@ -1377,11 +1407,6 @@ struct task_struct {
69759 struct task_cputime cputime_expires;
69760 struct list_head cpu_timers[3];
69761
69762 -/* process credentials */
69763 - const struct cred __rcu *real_cred; /* objective and real subjective task
69764 - * credentials (COW) */
69765 - const struct cred __rcu *cred; /* effective (overridable) subjective task
69766 - * credentials (COW) */
69767 char comm[TASK_COMM_LEN]; /* executable name excluding path
69768 - access with [gs]et_task_comm (which lock
69769 it with task_lock())
69770 @@ -1398,6 +1423,10 @@ struct task_struct {
69771 #endif
69772 /* CPU-specific state of this task */
69773 struct thread_struct thread;
69774 +/* thread_info moved to task_struct */
69775 +#ifdef CONFIG_X86
69776 + struct thread_info tinfo;
69777 +#endif
69778 /* filesystem information */
69779 struct fs_struct *fs;
69780 /* open file information */
69781 @@ -1471,6 +1500,10 @@ struct task_struct {
69782 gfp_t lockdep_reclaim_gfp;
69783 #endif
69784
69785 +/* process credentials */
69786 + const struct cred __rcu *real_cred; /* objective and real subjective task
69787 + * credentials (COW) */
69788 +
69789 /* journalling filesystem info */
69790 void *journal_info;
69791
69792 @@ -1509,6 +1542,10 @@ struct task_struct {
69793 /* cg_list protected by css_set_lock and tsk->alloc_lock */
69794 struct list_head cg_list;
69795 #endif
69796 +
69797 + const struct cred __rcu *cred; /* effective (overridable) subjective task
69798 + * credentials (COW) */
69799 +
69800 #ifdef CONFIG_FUTEX
69801 struct robust_list_head __user *robust_list;
69802 #ifdef CONFIG_COMPAT
69803 @@ -1605,8 +1642,74 @@ struct task_struct {
69804 #ifdef CONFIG_UPROBES
69805 struct uprobe_task *utask;
69806 #endif
69807 +
69808 +#ifdef CONFIG_GRKERNSEC
69809 + /* grsecurity */
69810 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69811 + u64 exec_id;
69812 +#endif
69813 +#ifdef CONFIG_GRKERNSEC_SETXID
69814 + const struct cred *delayed_cred;
69815 +#endif
69816 + struct dentry *gr_chroot_dentry;
69817 + struct acl_subject_label *acl;
69818 + struct acl_role_label *role;
69819 + struct file *exec_file;
69820 + unsigned long brute_expires;
69821 + u16 acl_role_id;
69822 + /* is this the task that authenticated to the special role */
69823 + u8 acl_sp_role;
69824 + u8 is_writable;
69825 + u8 brute;
69826 + u8 gr_is_chrooted;
69827 +#endif
69828 +
69829 };
69830
69831 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
69832 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
69833 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
69834 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
69835 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
69836 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
69837 +
69838 +#ifdef CONFIG_PAX_SOFTMODE
69839 +extern int pax_softmode;
69840 +#endif
69841 +
69842 +extern int pax_check_flags(unsigned long *);
69843 +
69844 +/* if tsk != current then task_lock must be held on it */
69845 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
69846 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
69847 +{
69848 + if (likely(tsk->mm))
69849 + return tsk->mm->pax_flags;
69850 + else
69851 + return 0UL;
69852 +}
69853 +
69854 +/* if tsk != current then task_lock must be held on it */
69855 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
69856 +{
69857 + if (likely(tsk->mm)) {
69858 + tsk->mm->pax_flags = flags;
69859 + return 0;
69860 + }
69861 + return -EINVAL;
69862 +}
69863 +#endif
69864 +
69865 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
69866 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
69867 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
69868 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
69869 +#endif
69870 +
69871 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
69872 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
69873 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
69874 +
69875 /* Future-safe accessor for struct task_struct's cpus_allowed. */
69876 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
69877
69878 @@ -1696,7 +1799,7 @@ struct pid_namespace;
69879 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
69880 struct pid_namespace *ns);
69881
69882 -static inline pid_t task_pid_nr(struct task_struct *tsk)
69883 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
69884 {
69885 return tsk->pid;
69886 }
69887 @@ -2155,7 +2258,9 @@ void yield(void);
69888 extern struct exec_domain default_exec_domain;
69889
69890 union thread_union {
69891 +#ifndef CONFIG_X86
69892 struct thread_info thread_info;
69893 +#endif
69894 unsigned long stack[THREAD_SIZE/sizeof(long)];
69895 };
69896
69897 @@ -2188,6 +2293,7 @@ extern struct pid_namespace init_pid_ns;
69898 */
69899
69900 extern struct task_struct *find_task_by_vpid(pid_t nr);
69901 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
69902 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
69903 struct pid_namespace *ns);
69904
69905 @@ -2344,7 +2450,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
69906 extern void exit_itimers(struct signal_struct *);
69907 extern void flush_itimer_signals(void);
69908
69909 -extern void do_group_exit(int);
69910 +extern __noreturn void do_group_exit(int);
69911
69912 extern int allow_signal(int);
69913 extern int disallow_signal(int);
69914 @@ -2545,9 +2651,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
69915
69916 #endif
69917
69918 -static inline int object_is_on_stack(void *obj)
69919 +static inline int object_starts_on_stack(void *obj)
69920 {
69921 - void *stack = task_stack_page(current);
69922 + const void *stack = task_stack_page(current);
69923
69924 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
69925 }
69926 diff --git a/include/linux/security.h b/include/linux/security.h
69927 index eee7478..290f7ba 100644
69928 --- a/include/linux/security.h
69929 +++ b/include/linux/security.h
69930 @@ -26,6 +26,7 @@
69931 #include <linux/capability.h>
69932 #include <linux/slab.h>
69933 #include <linux/err.h>
69934 +#include <linux/grsecurity.h>
69935
69936 struct linux_binprm;
69937 struct cred;
69938 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
69939 index 68a04a3..866e6a1 100644
69940 --- a/include/linux/seq_file.h
69941 +++ b/include/linux/seq_file.h
69942 @@ -26,6 +26,9 @@ struct seq_file {
69943 struct mutex lock;
69944 const struct seq_operations *op;
69945 int poll_event;
69946 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
69947 + u64 exec_id;
69948 +#endif
69949 #ifdef CONFIG_USER_NS
69950 struct user_namespace *user_ns;
69951 #endif
69952 @@ -38,6 +41,7 @@ struct seq_operations {
69953 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
69954 int (*show) (struct seq_file *m, void *v);
69955 };
69956 +typedef struct seq_operations __no_const seq_operations_no_const;
69957
69958 #define SEQ_SKIP 1
69959
69960 diff --git a/include/linux/shm.h b/include/linux/shm.h
69961 index 429c199..4d42e38 100644
69962 --- a/include/linux/shm.h
69963 +++ b/include/linux/shm.h
69964 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
69965
69966 /* The task created the shm object. NULL if the task is dead. */
69967 struct task_struct *shm_creator;
69968 +#ifdef CONFIG_GRKERNSEC
69969 + time_t shm_createtime;
69970 + pid_t shm_lapid;
69971 +#endif
69972 };
69973
69974 /* shm_mode upper byte flags */
69975 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
69976 index 320e976..fd52553 100644
69977 --- a/include/linux/skbuff.h
69978 +++ b/include/linux/skbuff.h
69979 @@ -590,7 +590,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
69980 extern struct sk_buff *__alloc_skb(unsigned int size,
69981 gfp_t priority, int flags, int node);
69982 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
69983 -static inline struct sk_buff *alloc_skb(unsigned int size,
69984 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
69985 gfp_t priority)
69986 {
69987 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
69988 @@ -700,7 +700,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
69989 */
69990 static inline int skb_queue_empty(const struct sk_buff_head *list)
69991 {
69992 - return list->next == (struct sk_buff *)list;
69993 + return list->next == (const struct sk_buff *)list;
69994 }
69995
69996 /**
69997 @@ -713,7 +713,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
69998 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
69999 const struct sk_buff *skb)
70000 {
70001 - return skb->next == (struct sk_buff *)list;
70002 + return skb->next == (const struct sk_buff *)list;
70003 }
70004
70005 /**
70006 @@ -726,7 +726,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
70007 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
70008 const struct sk_buff *skb)
70009 {
70010 - return skb->prev == (struct sk_buff *)list;
70011 + return skb->prev == (const struct sk_buff *)list;
70012 }
70013
70014 /**
70015 @@ -1722,7 +1722,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
70016 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
70017 */
70018 #ifndef NET_SKB_PAD
70019 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
70020 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
70021 #endif
70022
70023 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
70024 @@ -2300,7 +2300,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
70025 int noblock, int *err);
70026 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
70027 struct poll_table_struct *wait);
70028 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
70029 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
70030 int offset, struct iovec *to,
70031 int size);
70032 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
70033 diff --git a/include/linux/slab.h b/include/linux/slab.h
70034 index 5d168d7..720bff3 100644
70035 --- a/include/linux/slab.h
70036 +++ b/include/linux/slab.h
70037 @@ -12,13 +12,20 @@
70038 #include <linux/gfp.h>
70039 #include <linux/types.h>
70040 #include <linux/workqueue.h>
70041 -
70042 +#include <linux/err.h>
70043
70044 /*
70045 * Flags to pass to kmem_cache_create().
70046 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
70047 */
70048 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
70049 +
70050 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70051 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
70052 +#else
70053 +#define SLAB_USERCOPY 0x00000000UL
70054 +#endif
70055 +
70056 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
70057 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
70058 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
70059 @@ -89,10 +96,13 @@
70060 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
70061 * Both make kfree a no-op.
70062 */
70063 -#define ZERO_SIZE_PTR ((void *)16)
70064 +#define ZERO_SIZE_PTR \
70065 +({ \
70066 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
70067 + (void *)(-MAX_ERRNO-1L); \
70068 +})
70069
70070 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
70071 - (unsigned long)ZERO_SIZE_PTR)
70072 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
70073
70074 /*
70075 * Common fields provided in kmem_cache by all slab allocators
70076 @@ -112,7 +122,7 @@ struct kmem_cache {
70077 unsigned int align; /* Alignment as calculated */
70078 unsigned long flags; /* Active flags on the slab */
70079 const char *name; /* Slab name for sysfs */
70080 - int refcount; /* Use counter */
70081 + atomic_t refcount; /* Use counter */
70082 void (*ctor)(void *); /* Called on object slot creation */
70083 struct list_head list; /* List of all slab caches on the system */
70084 };
70085 @@ -232,6 +242,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
70086 void kfree(const void *);
70087 void kzfree(const void *);
70088 size_t ksize(const void *);
70089 +const char *check_heap_object(const void *ptr, unsigned long n);
70090 +bool is_usercopy_object(const void *ptr);
70091
70092 /*
70093 * Allocator specific definitions. These are mainly used to establish optimized
70094 @@ -311,6 +323,7 @@ size_t ksize(const void *);
70095 * for general use, and so are not documented here. For a full list of
70096 * potential flags, always refer to linux/gfp.h.
70097 */
70098 +
70099 static inline void *kmalloc_array(size_t n, size_t size, gfp_t flags)
70100 {
70101 if (size != 0 && n > SIZE_MAX / size)
70102 @@ -370,7 +383,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
70103 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70104 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70105 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70106 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70107 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
70108 #define kmalloc_track_caller(size, flags) \
70109 __kmalloc_track_caller(size, flags, _RET_IP_)
70110 #else
70111 @@ -390,7 +403,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
70112 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
70113 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING)) || \
70114 (defined(CONFIG_SLOB) && defined(CONFIG_TRACING))
70115 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
70116 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
70117 #define kmalloc_node_track_caller(size, flags, node) \
70118 __kmalloc_node_track_caller(size, flags, node, \
70119 _RET_IP_)
70120 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
70121 index 8bb6e0e..8eb0dbe 100644
70122 --- a/include/linux/slab_def.h
70123 +++ b/include/linux/slab_def.h
70124 @@ -52,7 +52,7 @@ struct kmem_cache {
70125 /* 4) cache creation/removal */
70126 const char *name;
70127 struct list_head list;
70128 - int refcount;
70129 + atomic_t refcount;
70130 int object_size;
70131 int align;
70132
70133 @@ -68,10 +68,10 @@ struct kmem_cache {
70134 unsigned long node_allocs;
70135 unsigned long node_frees;
70136 unsigned long node_overflow;
70137 - atomic_t allochit;
70138 - atomic_t allocmiss;
70139 - atomic_t freehit;
70140 - atomic_t freemiss;
70141 + atomic_unchecked_t allochit;
70142 + atomic_unchecked_t allocmiss;
70143 + atomic_unchecked_t freehit;
70144 + atomic_unchecked_t freemiss;
70145
70146 /*
70147 * If debugging is enabled, then the allocator can add additional
70148 @@ -111,11 +111,16 @@ struct cache_sizes {
70149 #ifdef CONFIG_ZONE_DMA
70150 struct kmem_cache *cs_dmacachep;
70151 #endif
70152 +
70153 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70154 + struct kmem_cache *cs_usercopycachep;
70155 +#endif
70156 +
70157 };
70158 extern struct cache_sizes malloc_sizes[];
70159
70160 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70161 -void *__kmalloc(size_t size, gfp_t flags);
70162 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
70163
70164 #ifdef CONFIG_TRACING
70165 extern void *kmem_cache_alloc_trace(struct kmem_cache *, gfp_t, size_t);
70166 @@ -152,6 +157,13 @@ found:
70167 cachep = malloc_sizes[i].cs_dmacachep;
70168 else
70169 #endif
70170 +
70171 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70172 + if (flags & GFP_USERCOPY)
70173 + cachep = malloc_sizes[i].cs_usercopycachep;
70174 + else
70175 +#endif
70176 +
70177 cachep = malloc_sizes[i].cs_cachep;
70178
70179 ret = kmem_cache_alloc_trace(cachep, flags, size);
70180 @@ -162,7 +174,7 @@ found:
70181 }
70182
70183 #ifdef CONFIG_NUMA
70184 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
70185 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70186 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70187
70188 #ifdef CONFIG_TRACING
70189 @@ -205,6 +217,13 @@ found:
70190 cachep = malloc_sizes[i].cs_dmacachep;
70191 else
70192 #endif
70193 +
70194 +#ifdef CONFIG_PAX_USERCOPY_SLABS
70195 + if (flags & GFP_USERCOPY)
70196 + cachep = malloc_sizes[i].cs_usercopycachep;
70197 + else
70198 +#endif
70199 +
70200 cachep = malloc_sizes[i].cs_cachep;
70201
70202 return kmem_cache_alloc_node_trace(cachep, flags, node, size);
70203 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
70204 index f28e14a..7831211 100644
70205 --- a/include/linux/slob_def.h
70206 +++ b/include/linux/slob_def.h
70207 @@ -11,7 +11,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
70208 return kmem_cache_alloc_node(cachep, flags, NUMA_NO_NODE);
70209 }
70210
70211 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
70212 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70213
70214 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
70215 {
70216 @@ -31,7 +31,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70217 return __kmalloc_node(size, flags, NUMA_NO_NODE);
70218 }
70219
70220 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
70221 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
70222 {
70223 return kmalloc(size, flags);
70224 }
70225 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
70226 index 9db4825..ed42fb5 100644
70227 --- a/include/linux/slub_def.h
70228 +++ b/include/linux/slub_def.h
70229 @@ -91,7 +91,7 @@ struct kmem_cache {
70230 struct kmem_cache_order_objects max;
70231 struct kmem_cache_order_objects min;
70232 gfp_t allocflags; /* gfp flags to use on each alloc */
70233 - int refcount; /* Refcount for slab cache destroy */
70234 + atomic_t refcount; /* Refcount for slab cache destroy */
70235 void (*ctor)(void *);
70236 int inuse; /* Offset to metadata */
70237 int align; /* Alignment */
70238 @@ -156,7 +156,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
70239 * Sorry that the following has to be that ugly but some versions of GCC
70240 * have trouble with constant propagation and loops.
70241 */
70242 -static __always_inline int kmalloc_index(size_t size)
70243 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
70244 {
70245 if (!size)
70246 return 0;
70247 @@ -221,7 +221,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
70248 }
70249
70250 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
70251 -void *__kmalloc(size_t size, gfp_t flags);
70252 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
70253
70254 static __always_inline void *
70255 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
70256 @@ -265,7 +265,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
70257 }
70258 #endif
70259
70260 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
70261 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
70262 {
70263 unsigned int order = get_order(size);
70264 return kmalloc_order_trace(size, flags, order);
70265 @@ -290,7 +290,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
70266 }
70267
70268 #ifdef CONFIG_NUMA
70269 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
70270 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
70271 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
70272
70273 #ifdef CONFIG_TRACING
70274 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
70275 index e8d702e..0a56eb4 100644
70276 --- a/include/linux/sock_diag.h
70277 +++ b/include/linux/sock_diag.h
70278 @@ -10,7 +10,7 @@ struct sock;
70279 struct sock_diag_handler {
70280 __u8 family;
70281 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
70282 -};
70283 +} __do_const;
70284
70285 int sock_diag_register(const struct sock_diag_handler *h);
70286 void sock_diag_unregister(const struct sock_diag_handler *h);
70287 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
70288 index 680f9a3..f13aeb0 100644
70289 --- a/include/linux/sonet.h
70290 +++ b/include/linux/sonet.h
70291 @@ -7,7 +7,7 @@
70292 #include <uapi/linux/sonet.h>
70293
70294 struct k_sonet_stats {
70295 -#define __HANDLE_ITEM(i) atomic_t i
70296 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
70297 __SONET_ITEMS
70298 #undef __HANDLE_ITEM
70299 };
70300 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
70301 index 34206b8..3db7f1c 100644
70302 --- a/include/linux/sunrpc/clnt.h
70303 +++ b/include/linux/sunrpc/clnt.h
70304 @@ -96,7 +96,7 @@ struct rpc_procinfo {
70305 unsigned int p_timer; /* Which RTT timer to use */
70306 u32 p_statidx; /* Which procedure to account */
70307 const char * p_name; /* name of procedure */
70308 -};
70309 +} __do_const;
70310
70311 #ifdef __KERNEL__
70312
70313 @@ -176,9 +176,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
70314 {
70315 switch (sap->sa_family) {
70316 case AF_INET:
70317 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
70318 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
70319 case AF_INET6:
70320 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
70321 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
70322 }
70323 return 0;
70324 }
70325 @@ -211,7 +211,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
70326 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
70327 const struct sockaddr *src)
70328 {
70329 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
70330 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
70331 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
70332
70333 dsin->sin_family = ssin->sin_family;
70334 @@ -314,7 +314,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
70335 if (sa->sa_family != AF_INET6)
70336 return 0;
70337
70338 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
70339 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
70340 }
70341
70342 #endif /* __KERNEL__ */
70343 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
70344 index 676ddf5..4c519a1 100644
70345 --- a/include/linux/sunrpc/svc.h
70346 +++ b/include/linux/sunrpc/svc.h
70347 @@ -410,7 +410,7 @@ struct svc_procedure {
70348 unsigned int pc_count; /* call count */
70349 unsigned int pc_cachetype; /* cache info (NFS) */
70350 unsigned int pc_xdrressize; /* maximum size of XDR reply */
70351 -};
70352 +} __do_const;
70353
70354 /*
70355 * Function prototypes.
70356 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
70357 index 0b8e3e6..33e0a01 100644
70358 --- a/include/linux/sunrpc/svc_rdma.h
70359 +++ b/include/linux/sunrpc/svc_rdma.h
70360 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
70361 extern unsigned int svcrdma_max_requests;
70362 extern unsigned int svcrdma_max_req_size;
70363
70364 -extern atomic_t rdma_stat_recv;
70365 -extern atomic_t rdma_stat_read;
70366 -extern atomic_t rdma_stat_write;
70367 -extern atomic_t rdma_stat_sq_starve;
70368 -extern atomic_t rdma_stat_rq_starve;
70369 -extern atomic_t rdma_stat_rq_poll;
70370 -extern atomic_t rdma_stat_rq_prod;
70371 -extern atomic_t rdma_stat_sq_poll;
70372 -extern atomic_t rdma_stat_sq_prod;
70373 +extern atomic_unchecked_t rdma_stat_recv;
70374 +extern atomic_unchecked_t rdma_stat_read;
70375 +extern atomic_unchecked_t rdma_stat_write;
70376 +extern atomic_unchecked_t rdma_stat_sq_starve;
70377 +extern atomic_unchecked_t rdma_stat_rq_starve;
70378 +extern atomic_unchecked_t rdma_stat_rq_poll;
70379 +extern atomic_unchecked_t rdma_stat_rq_prod;
70380 +extern atomic_unchecked_t rdma_stat_sq_poll;
70381 +extern atomic_unchecked_t rdma_stat_sq_prod;
70382
70383 #define RPCRDMA_VERSION 1
70384
70385 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
70386 index dd74084a..7f509d5 100644
70387 --- a/include/linux/sunrpc/svcauth.h
70388 +++ b/include/linux/sunrpc/svcauth.h
70389 @@ -109,7 +109,7 @@ struct auth_ops {
70390 int (*release)(struct svc_rqst *rq);
70391 void (*domain_release)(struct auth_domain *);
70392 int (*set_client)(struct svc_rqst *rq);
70393 -};
70394 +} __do_const;
70395
70396 #define SVC_GARBAGE 1
70397 #define SVC_SYSERR 2
70398 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
70399 index 071d62c..4ccc7ac 100644
70400 --- a/include/linux/swiotlb.h
70401 +++ b/include/linux/swiotlb.h
70402 @@ -59,7 +59,8 @@ extern void
70403
70404 extern void
70405 swiotlb_free_coherent(struct device *hwdev, size_t size,
70406 - void *vaddr, dma_addr_t dma_handle);
70407 + void *vaddr, dma_addr_t dma_handle,
70408 + struct dma_attrs *attrs);
70409
70410 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
70411 unsigned long offset, size_t size,
70412 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
70413 index 27b3b0b..e093dd9 100644
70414 --- a/include/linux/syscore_ops.h
70415 +++ b/include/linux/syscore_ops.h
70416 @@ -16,7 +16,7 @@ struct syscore_ops {
70417 int (*suspend)(void);
70418 void (*resume)(void);
70419 void (*shutdown)(void);
70420 -};
70421 +} __do_const;
70422
70423 extern void register_syscore_ops(struct syscore_ops *ops);
70424 extern void unregister_syscore_ops(struct syscore_ops *ops);
70425 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
70426 index 14a8ff2..af52bad 100644
70427 --- a/include/linux/sysctl.h
70428 +++ b/include/linux/sysctl.h
70429 @@ -34,13 +34,13 @@ struct ctl_table_root;
70430 struct ctl_table_header;
70431 struct ctl_dir;
70432
70433 -typedef struct ctl_table ctl_table;
70434 -
70435 typedef int proc_handler (struct ctl_table *ctl, int write,
70436 void __user *buffer, size_t *lenp, loff_t *ppos);
70437
70438 extern int proc_dostring(struct ctl_table *, int,
70439 void __user *, size_t *, loff_t *);
70440 +extern int proc_dostring_modpriv(struct ctl_table *, int,
70441 + void __user *, size_t *, loff_t *);
70442 extern int proc_dointvec(struct ctl_table *, int,
70443 void __user *, size_t *, loff_t *);
70444 extern int proc_dointvec_minmax(struct ctl_table *, int,
70445 @@ -115,7 +115,9 @@ struct ctl_table
70446 struct ctl_table_poll *poll;
70447 void *extra1;
70448 void *extra2;
70449 -};
70450 +} __do_const;
70451 +typedef struct ctl_table __no_const ctl_table_no_const;
70452 +typedef struct ctl_table ctl_table;
70453
70454 struct ctl_node {
70455 struct rb_node node;
70456 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
70457 index 381f06d..dc16cc7 100644
70458 --- a/include/linux/sysfs.h
70459 +++ b/include/linux/sysfs.h
70460 @@ -31,7 +31,8 @@ struct attribute {
70461 struct lock_class_key *key;
70462 struct lock_class_key skey;
70463 #endif
70464 -};
70465 +} __do_const;
70466 +typedef struct attribute __no_const attribute_no_const;
70467
70468 /**
70469 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
70470 @@ -59,8 +60,8 @@ struct attribute_group {
70471 umode_t (*is_visible)(struct kobject *,
70472 struct attribute *, int);
70473 struct attribute **attrs;
70474 -};
70475 -
70476 +} __do_const;
70477 +typedef struct attribute_group __no_const attribute_group_no_const;
70478
70479
70480 /**
70481 @@ -107,7 +108,8 @@ struct bin_attribute {
70482 char *, loff_t, size_t);
70483 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
70484 struct vm_area_struct *vma);
70485 -};
70486 +} __do_const;
70487 +typedef struct bin_attribute __no_const bin_attribute_no_const;
70488
70489 /**
70490 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
70491 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
70492 index 7faf933..4657127 100644
70493 --- a/include/linux/sysrq.h
70494 +++ b/include/linux/sysrq.h
70495 @@ -15,7 +15,9 @@
70496 #define _LINUX_SYSRQ_H
70497
70498 #include <linux/errno.h>
70499 +#include <linux/compiler.h>
70500 #include <linux/types.h>
70501 +#include <linux/compiler.h>
70502
70503 /* Enable/disable SYSRQ support by default (0==no, 1==yes). */
70504 #define SYSRQ_DEFAULT_ENABLE 1
70505 @@ -36,7 +38,7 @@ struct sysrq_key_op {
70506 char *help_msg;
70507 char *action_msg;
70508 int enable_mask;
70509 -};
70510 +} __do_const;
70511
70512 #ifdef CONFIG_MAGIC_SYSRQ
70513
70514 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
70515 index e7e0473..39b7b52 100644
70516 --- a/include/linux/thread_info.h
70517 +++ b/include/linux/thread_info.h
70518 @@ -148,6 +148,15 @@ static inline bool test_and_clear_restore_sigmask(void)
70519 #error "no set_restore_sigmask() provided and default one won't work"
70520 #endif
70521
70522 +extern void __check_object_size(const void *ptr, unsigned long n, bool to);
70523 +static inline void check_object_size(const void *ptr, unsigned long n, bool to)
70524 +{
70525 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
70526 + if (!__builtin_constant_p(n))
70527 +#endif
70528 + __check_object_size(ptr, n, to);
70529 +}
70530 +
70531 #endif /* __KERNEL__ */
70532
70533 #endif /* _LINUX_THREAD_INFO_H */
70534 diff --git a/include/linux/tty.h b/include/linux/tty.h
70535 index 8db1b56..c16a040 100644
70536 --- a/include/linux/tty.h
70537 +++ b/include/linux/tty.h
70538 @@ -194,7 +194,7 @@ struct tty_port {
70539 const struct tty_port_operations *ops; /* Port operations */
70540 spinlock_t lock; /* Lock protecting tty field */
70541 int blocked_open; /* Waiting to open */
70542 - int count; /* Usage count */
70543 + atomic_t count; /* Usage count */
70544 wait_queue_head_t open_wait; /* Open waiters */
70545 wait_queue_head_t close_wait; /* Close waiters */
70546 wait_queue_head_t delta_msr_wait; /* Modem status change */
70547 @@ -490,7 +490,7 @@ extern int tty_port_open(struct tty_port *port,
70548 struct tty_struct *tty, struct file *filp);
70549 static inline int tty_port_users(struct tty_port *port)
70550 {
70551 - return port->count + port->blocked_open;
70552 + return atomic_read(&port->count) + port->blocked_open;
70553 }
70554
70555 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
70556 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
70557 index dd976cf..e272742 100644
70558 --- a/include/linux/tty_driver.h
70559 +++ b/include/linux/tty_driver.h
70560 @@ -284,7 +284,7 @@ struct tty_operations {
70561 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
70562 #endif
70563 const struct file_operations *proc_fops;
70564 -};
70565 +} __do_const;
70566
70567 struct tty_driver {
70568 int magic; /* magic number for this structure */
70569 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
70570 index fb79dd8d..07d4773 100644
70571 --- a/include/linux/tty_ldisc.h
70572 +++ b/include/linux/tty_ldisc.h
70573 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
70574
70575 struct module *owner;
70576
70577 - int refcount;
70578 + atomic_t refcount;
70579 };
70580
70581 struct tty_ldisc {
70582 diff --git a/include/linux/types.h b/include/linux/types.h
70583 index 4d118ba..c3ee9bf 100644
70584 --- a/include/linux/types.h
70585 +++ b/include/linux/types.h
70586 @@ -176,10 +176,26 @@ typedef struct {
70587 int counter;
70588 } atomic_t;
70589
70590 +#ifdef CONFIG_PAX_REFCOUNT
70591 +typedef struct {
70592 + int counter;
70593 +} atomic_unchecked_t;
70594 +#else
70595 +typedef atomic_t atomic_unchecked_t;
70596 +#endif
70597 +
70598 #ifdef CONFIG_64BIT
70599 typedef struct {
70600 long counter;
70601 } atomic64_t;
70602 +
70603 +#ifdef CONFIG_PAX_REFCOUNT
70604 +typedef struct {
70605 + long counter;
70606 +} atomic64_unchecked_t;
70607 +#else
70608 +typedef atomic64_t atomic64_unchecked_t;
70609 +#endif
70610 #endif
70611
70612 struct list_head {
70613 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
70614 index 5ca0951..ab496a5 100644
70615 --- a/include/linux/uaccess.h
70616 +++ b/include/linux/uaccess.h
70617 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
70618 long ret; \
70619 mm_segment_t old_fs = get_fs(); \
70620 \
70621 - set_fs(KERNEL_DS); \
70622 pagefault_disable(); \
70623 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
70624 - pagefault_enable(); \
70625 + set_fs(KERNEL_DS); \
70626 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
70627 set_fs(old_fs); \
70628 + pagefault_enable(); \
70629 ret; \
70630 })
70631
70632 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
70633 index 8e522cbc..aa8572d 100644
70634 --- a/include/linux/uidgid.h
70635 +++ b/include/linux/uidgid.h
70636 @@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
70637
70638 #endif /* CONFIG_USER_NS */
70639
70640 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
70641 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
70642 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
70643 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
70644 +
70645 #endif /* _LINUX_UIDGID_H */
70646 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
70647 index 99c1b4d..bb94261 100644
70648 --- a/include/linux/unaligned/access_ok.h
70649 +++ b/include/linux/unaligned/access_ok.h
70650 @@ -6,32 +6,32 @@
70651
70652 static inline u16 get_unaligned_le16(const void *p)
70653 {
70654 - return le16_to_cpup((__le16 *)p);
70655 + return le16_to_cpup((const __le16 *)p);
70656 }
70657
70658 static inline u32 get_unaligned_le32(const void *p)
70659 {
70660 - return le32_to_cpup((__le32 *)p);
70661 + return le32_to_cpup((const __le32 *)p);
70662 }
70663
70664 static inline u64 get_unaligned_le64(const void *p)
70665 {
70666 - return le64_to_cpup((__le64 *)p);
70667 + return le64_to_cpup((const __le64 *)p);
70668 }
70669
70670 static inline u16 get_unaligned_be16(const void *p)
70671 {
70672 - return be16_to_cpup((__be16 *)p);
70673 + return be16_to_cpup((const __be16 *)p);
70674 }
70675
70676 static inline u32 get_unaligned_be32(const void *p)
70677 {
70678 - return be32_to_cpup((__be32 *)p);
70679 + return be32_to_cpup((const __be32 *)p);
70680 }
70681
70682 static inline u64 get_unaligned_be64(const void *p)
70683 {
70684 - return be64_to_cpup((__be64 *)p);
70685 + return be64_to_cpup((const __be64 *)p);
70686 }
70687
70688 static inline void put_unaligned_le16(u16 val, void *p)
70689 diff --git a/include/linux/usb.h b/include/linux/usb.h
70690 index 4d22d0f..ac43c2f 100644
70691 --- a/include/linux/usb.h
70692 +++ b/include/linux/usb.h
70693 @@ -554,7 +554,7 @@ struct usb_device {
70694 int maxchild;
70695
70696 u32 quirks;
70697 - atomic_t urbnum;
70698 + atomic_unchecked_t urbnum;
70699
70700 unsigned long active_duration;
70701
70702 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
70703 index c5d36c6..108f4f9 100644
70704 --- a/include/linux/usb/renesas_usbhs.h
70705 +++ b/include/linux/usb/renesas_usbhs.h
70706 @@ -39,7 +39,7 @@ enum {
70707 */
70708 struct renesas_usbhs_driver_callback {
70709 int (*notify_hotplug)(struct platform_device *pdev);
70710 -};
70711 +} __no_const;
70712
70713 /*
70714 * callback functions for platform
70715 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
70716 index b9bd2e6..4ce0093 100644
70717 --- a/include/linux/user_namespace.h
70718 +++ b/include/linux/user_namespace.h
70719 @@ -21,7 +21,7 @@ struct user_namespace {
70720 struct uid_gid_map uid_map;
70721 struct uid_gid_map gid_map;
70722 struct uid_gid_map projid_map;
70723 - struct kref kref;
70724 + atomic_t count;
70725 struct user_namespace *parent;
70726 kuid_t owner;
70727 kgid_t group;
70728 @@ -35,18 +35,18 @@ extern struct user_namespace init_user_ns;
70729 static inline struct user_namespace *get_user_ns(struct user_namespace *ns)
70730 {
70731 if (ns)
70732 - kref_get(&ns->kref);
70733 + atomic_inc(&ns->count);
70734 return ns;
70735 }
70736
70737 extern int create_user_ns(struct cred *new);
70738 extern int unshare_userns(unsigned long unshare_flags, struct cred **new_cred);
70739 -extern void free_user_ns(struct kref *kref);
70740 +extern void free_user_ns(struct user_namespace *ns);
70741
70742 static inline void put_user_ns(struct user_namespace *ns)
70743 {
70744 - if (ns)
70745 - kref_put(&ns->kref, free_user_ns);
70746 + if (ns && atomic_dec_and_test(&ns->count))
70747 + free_user_ns(ns);
70748 }
70749
70750 struct seq_operations;
70751 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
70752 index 6f8fbcf..8259001 100644
70753 --- a/include/linux/vermagic.h
70754 +++ b/include/linux/vermagic.h
70755 @@ -25,9 +25,35 @@
70756 #define MODULE_ARCH_VERMAGIC ""
70757 #endif
70758
70759 +#ifdef CONFIG_PAX_REFCOUNT
70760 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
70761 +#else
70762 +#define MODULE_PAX_REFCOUNT ""
70763 +#endif
70764 +
70765 +#ifdef CONSTIFY_PLUGIN
70766 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
70767 +#else
70768 +#define MODULE_CONSTIFY_PLUGIN ""
70769 +#endif
70770 +
70771 +#ifdef STACKLEAK_PLUGIN
70772 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
70773 +#else
70774 +#define MODULE_STACKLEAK_PLUGIN ""
70775 +#endif
70776 +
70777 +#ifdef CONFIG_GRKERNSEC
70778 +#define MODULE_GRSEC "GRSEC "
70779 +#else
70780 +#define MODULE_GRSEC ""
70781 +#endif
70782 +
70783 #define VERMAGIC_STRING \
70784 UTS_RELEASE " " \
70785 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
70786 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
70787 - MODULE_ARCH_VERMAGIC
70788 + MODULE_ARCH_VERMAGIC \
70789 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
70790 + MODULE_GRSEC
70791
70792 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
70793 index 6071e91..ca6a489 100644
70794 --- a/include/linux/vmalloc.h
70795 +++ b/include/linux/vmalloc.h
70796 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
70797 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
70798 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
70799 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
70800 +
70801 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
70802 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
70803 +#endif
70804 +
70805 /* bits [20..32] reserved for arch specific ioremap internals */
70806
70807 /*
70808 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
70809 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
70810 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
70811 unsigned long start, unsigned long end, gfp_t gfp_mask,
70812 - pgprot_t prot, int node, const void *caller);
70813 + pgprot_t prot, int node, const void *caller) __size_overflow(1);
70814 extern void vfree(const void *addr);
70815
70816 extern void *vmap(struct page **pages, unsigned int count,
70817 @@ -124,8 +129,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
70818 extern void free_vm_area(struct vm_struct *area);
70819
70820 /* for /dev/kmem */
70821 -extern long vread(char *buf, char *addr, unsigned long count);
70822 -extern long vwrite(char *buf, char *addr, unsigned long count);
70823 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
70824 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
70825
70826 /*
70827 * Internals. Dont't use..
70828 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
70829 index a13291f..af51fa3 100644
70830 --- a/include/linux/vmstat.h
70831 +++ b/include/linux/vmstat.h
70832 @@ -95,18 +95,18 @@ static inline void vm_events_fold_cpu(int cpu)
70833 /*
70834 * Zone based page accounting with per cpu differentials.
70835 */
70836 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70837 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
70838
70839 static inline void zone_page_state_add(long x, struct zone *zone,
70840 enum zone_stat_item item)
70841 {
70842 - atomic_long_add(x, &zone->vm_stat[item]);
70843 - atomic_long_add(x, &vm_stat[item]);
70844 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
70845 + atomic_long_add_unchecked(x, &vm_stat[item]);
70846 }
70847
70848 static inline unsigned long global_page_state(enum zone_stat_item item)
70849 {
70850 - long x = atomic_long_read(&vm_stat[item]);
70851 + long x = atomic_long_read_unchecked(&vm_stat[item]);
70852 #ifdef CONFIG_SMP
70853 if (x < 0)
70854 x = 0;
70855 @@ -117,7 +117,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
70856 static inline unsigned long zone_page_state(struct zone *zone,
70857 enum zone_stat_item item)
70858 {
70859 - long x = atomic_long_read(&zone->vm_stat[item]);
70860 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
70861 #ifdef CONFIG_SMP
70862 if (x < 0)
70863 x = 0;
70864 @@ -134,7 +134,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
70865 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
70866 enum zone_stat_item item)
70867 {
70868 - long x = atomic_long_read(&zone->vm_stat[item]);
70869 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
70870
70871 #ifdef CONFIG_SMP
70872 int cpu;
70873 @@ -226,8 +226,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
70874
70875 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
70876 {
70877 - atomic_long_inc(&zone->vm_stat[item]);
70878 - atomic_long_inc(&vm_stat[item]);
70879 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
70880 + atomic_long_inc_unchecked(&vm_stat[item]);
70881 }
70882
70883 static inline void __inc_zone_page_state(struct page *page,
70884 @@ -238,8 +238,8 @@ static inline void __inc_zone_page_state(struct page *page,
70885
70886 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
70887 {
70888 - atomic_long_dec(&zone->vm_stat[item]);
70889 - atomic_long_dec(&vm_stat[item]);
70890 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
70891 + atomic_long_dec_unchecked(&vm_stat[item]);
70892 }
70893
70894 static inline void __dec_zone_page_state(struct page *page,
70895 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
70896 index fdbafc6..b7ffd47 100644
70897 --- a/include/linux/xattr.h
70898 +++ b/include/linux/xattr.h
70899 @@ -28,7 +28,7 @@ struct xattr_handler {
70900 size_t size, int handler_flags);
70901 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
70902 size_t size, int flags, int handler_flags);
70903 -};
70904 +} __do_const;
70905
70906 struct xattr {
70907 char *name;
70908 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
70909 index 95d1c91..6798cca 100644
70910 --- a/include/media/v4l2-dev.h
70911 +++ b/include/media/v4l2-dev.h
70912 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
70913 int (*mmap) (struct file *, struct vm_area_struct *);
70914 int (*open) (struct file *);
70915 int (*release) (struct file *);
70916 -};
70917 +} __do_const;
70918
70919 /*
70920 * Newer version of video_device, handled by videodev2.c
70921 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
70922 index 4118ad1..cb7e25f 100644
70923 --- a/include/media/v4l2-ioctl.h
70924 +++ b/include/media/v4l2-ioctl.h
70925 @@ -284,7 +284,6 @@ struct v4l2_ioctl_ops {
70926 bool valid_prio, int cmd, void *arg);
70927 };
70928
70929 -
70930 /* v4l debugging and diagnostics */
70931
70932 /* Debug bitmask flags to be used on V4L2 */
70933 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
70934 index adcbb20..62c2559 100644
70935 --- a/include/net/9p/transport.h
70936 +++ b/include/net/9p/transport.h
70937 @@ -57,7 +57,7 @@ struct p9_trans_module {
70938 int (*cancel) (struct p9_client *, struct p9_req_t *req);
70939 int (*zc_request)(struct p9_client *, struct p9_req_t *,
70940 char *, char *, int , int, int, int);
70941 -};
70942 +} __do_const;
70943
70944 void v9fs_register_trans(struct p9_trans_module *m);
70945 void v9fs_unregister_trans(struct p9_trans_module *m);
70946 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
70947 index 7588ef4..e62d35f 100644
70948 --- a/include/net/bluetooth/l2cap.h
70949 +++ b/include/net/bluetooth/l2cap.h
70950 @@ -552,7 +552,7 @@ struct l2cap_ops {
70951 void (*defer) (struct l2cap_chan *chan);
70952 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
70953 unsigned long len, int nb);
70954 -};
70955 +} __do_const;
70956
70957 struct l2cap_conn {
70958 struct hci_conn *hcon;
70959 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
70960 index 9e5425b..8136ffc 100644
70961 --- a/include/net/caif/cfctrl.h
70962 +++ b/include/net/caif/cfctrl.h
70963 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
70964 void (*radioset_rsp)(void);
70965 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
70966 struct cflayer *client_layer);
70967 -};
70968 +} __no_const;
70969
70970 /* Link Setup Parameters for CAIF-Links. */
70971 struct cfctrl_link_param {
70972 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
70973 struct cfctrl {
70974 struct cfsrvl serv;
70975 struct cfctrl_rsp res;
70976 - atomic_t req_seq_no;
70977 - atomic_t rsp_seq_no;
70978 + atomic_unchecked_t req_seq_no;
70979 + atomic_unchecked_t rsp_seq_no;
70980 struct list_head list;
70981 /* Protects from simultaneous access to first_req list */
70982 spinlock_t info_list_lock;
70983 diff --git a/include/net/flow.h b/include/net/flow.h
70984 index 628e11b..4c475df 100644
70985 --- a/include/net/flow.h
70986 +++ b/include/net/flow.h
70987 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
70988
70989 extern void flow_cache_flush(void);
70990 extern void flow_cache_flush_deferred(void);
70991 -extern atomic_t flow_cache_genid;
70992 +extern atomic_unchecked_t flow_cache_genid;
70993
70994 #endif
70995 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
70996 index bdfbe68..4402ebe 100644
70997 --- a/include/net/genetlink.h
70998 +++ b/include/net/genetlink.h
70999 @@ -118,7 +118,7 @@ struct genl_ops {
71000 struct netlink_callback *cb);
71001 int (*done)(struct netlink_callback *cb);
71002 struct list_head ops_list;
71003 -};
71004 +} __do_const;
71005
71006 extern int genl_register_family(struct genl_family *family);
71007 extern int genl_register_family_with_ops(struct genl_family *family,
71008 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
71009 index e5062c9..48a9a4b 100644
71010 --- a/include/net/gro_cells.h
71011 +++ b/include/net/gro_cells.h
71012 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
71013 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
71014
71015 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
71016 - atomic_long_inc(&dev->rx_dropped);
71017 + atomic_long_inc_unchecked(&dev->rx_dropped);
71018 kfree_skb(skb);
71019 return;
71020 }
71021 @@ -73,8 +73,8 @@ static inline int gro_cells_init(struct gro_cells *gcells, struct net_device *de
71022 int i;
71023
71024 gcells->gro_cells_mask = roundup_pow_of_two(netif_get_num_default_rss_queues()) - 1;
71025 - gcells->cells = kcalloc(sizeof(struct gro_cell),
71026 - gcells->gro_cells_mask + 1,
71027 + gcells->cells = kcalloc(gcells->gro_cells_mask + 1,
71028 + sizeof(struct gro_cell),
71029 GFP_KERNEL);
71030 if (!gcells->cells)
71031 return -ENOMEM;
71032 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
71033 index 1832927..ce39aea 100644
71034 --- a/include/net/inet_connection_sock.h
71035 +++ b/include/net/inet_connection_sock.h
71036 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
71037 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
71038 int (*bind_conflict)(const struct sock *sk,
71039 const struct inet_bind_bucket *tb, bool relax);
71040 -};
71041 +} __do_const;
71042
71043 /** inet_connection_sock - INET connection oriented sock
71044 *
71045 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
71046 index 53f464d..ba76aaa 100644
71047 --- a/include/net/inetpeer.h
71048 +++ b/include/net/inetpeer.h
71049 @@ -47,8 +47,8 @@ struct inet_peer {
71050 */
71051 union {
71052 struct {
71053 - atomic_t rid; /* Frag reception counter */
71054 - atomic_t ip_id_count; /* IP ID for the next packet */
71055 + atomic_unchecked_t rid; /* Frag reception counter */
71056 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
71057 };
71058 struct rcu_head rcu;
71059 struct inet_peer *gc_next;
71060 @@ -182,11 +182,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
71061 more++;
71062 inet_peer_refcheck(p);
71063 do {
71064 - old = atomic_read(&p->ip_id_count);
71065 + old = atomic_read_unchecked(&p->ip_id_count);
71066 new = old + more;
71067 if (!new)
71068 new = 1;
71069 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
71070 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
71071 return new;
71072 }
71073
71074 diff --git a/include/net/ip.h b/include/net/ip.h
71075 index a68f838..74518ab 100644
71076 --- a/include/net/ip.h
71077 +++ b/include/net/ip.h
71078 @@ -202,7 +202,7 @@ extern struct local_ports {
71079 } sysctl_local_ports;
71080 extern void inet_get_local_port_range(int *low, int *high);
71081
71082 -extern unsigned long *sysctl_local_reserved_ports;
71083 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
71084 static inline int inet_is_reserved_local_port(int port)
71085 {
71086 return test_bit(port, sysctl_local_reserved_ports);
71087 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
71088 index 9497be1..5a4fafe 100644
71089 --- a/include/net/ip_fib.h
71090 +++ b/include/net/ip_fib.h
71091 @@ -169,7 +169,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
71092
71093 #define FIB_RES_SADDR(net, res) \
71094 ((FIB_RES_NH(res).nh_saddr_genid == \
71095 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
71096 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
71097 FIB_RES_NH(res).nh_saddr : \
71098 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
71099 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
71100 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
71101 index 68c69d5..bdab192 100644
71102 --- a/include/net/ip_vs.h
71103 +++ b/include/net/ip_vs.h
71104 @@ -599,7 +599,7 @@ struct ip_vs_conn {
71105 struct ip_vs_conn *control; /* Master control connection */
71106 atomic_t n_control; /* Number of controlled ones */
71107 struct ip_vs_dest *dest; /* real server */
71108 - atomic_t in_pkts; /* incoming packet counter */
71109 + atomic_unchecked_t in_pkts; /* incoming packet counter */
71110
71111 /* packet transmitter for different forwarding methods. If it
71112 mangles the packet, it must return NF_DROP or better NF_STOLEN,
71113 @@ -737,7 +737,7 @@ struct ip_vs_dest {
71114 __be16 port; /* port number of the server */
71115 union nf_inet_addr addr; /* IP address of the server */
71116 volatile unsigned int flags; /* dest status flags */
71117 - atomic_t conn_flags; /* flags to copy to conn */
71118 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
71119 atomic_t weight; /* server weight */
71120
71121 atomic_t refcnt; /* reference counter */
71122 @@ -980,11 +980,11 @@ struct netns_ipvs {
71123 /* ip_vs_lblc */
71124 int sysctl_lblc_expiration;
71125 struct ctl_table_header *lblc_ctl_header;
71126 - struct ctl_table *lblc_ctl_table;
71127 + ctl_table_no_const *lblc_ctl_table;
71128 /* ip_vs_lblcr */
71129 int sysctl_lblcr_expiration;
71130 struct ctl_table_header *lblcr_ctl_header;
71131 - struct ctl_table *lblcr_ctl_table;
71132 + ctl_table_no_const *lblcr_ctl_table;
71133 /* ip_vs_est */
71134 struct list_head est_list; /* estimator list */
71135 spinlock_t est_lock;
71136 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
71137 index 80ffde3..968b0f4 100644
71138 --- a/include/net/irda/ircomm_tty.h
71139 +++ b/include/net/irda/ircomm_tty.h
71140 @@ -35,6 +35,7 @@
71141 #include <linux/termios.h>
71142 #include <linux/timer.h>
71143 #include <linux/tty.h> /* struct tty_struct */
71144 +#include <asm/local.h>
71145
71146 #include <net/irda/irias_object.h>
71147 #include <net/irda/ircomm_core.h>
71148 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
71149 index cc7c197..9f2da2a 100644
71150 --- a/include/net/iucv/af_iucv.h
71151 +++ b/include/net/iucv/af_iucv.h
71152 @@ -141,7 +141,7 @@ struct iucv_sock {
71153 struct iucv_sock_list {
71154 struct hlist_head head;
71155 rwlock_t lock;
71156 - atomic_t autobind_name;
71157 + atomic_unchecked_t autobind_name;
71158 };
71159
71160 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
71161 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
71162 index df83f69..9b640b8 100644
71163 --- a/include/net/llc_c_ac.h
71164 +++ b/include/net/llc_c_ac.h
71165 @@ -87,7 +87,7 @@
71166 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
71167 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
71168
71169 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71170 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
71171
71172 extern int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
71173 extern int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
71174 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
71175 index 6ca3113..f8026dd 100644
71176 --- a/include/net/llc_c_ev.h
71177 +++ b/include/net/llc_c_ev.h
71178 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
71179 return (struct llc_conn_state_ev *)skb->cb;
71180 }
71181
71182 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71183 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71184 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
71185 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
71186
71187 extern int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
71188 extern int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
71189 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
71190 index 0e79cfb..f46db31 100644
71191 --- a/include/net/llc_c_st.h
71192 +++ b/include/net/llc_c_st.h
71193 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
71194 u8 next_state;
71195 llc_conn_ev_qfyr_t *ev_qualifiers;
71196 llc_conn_action_t *ev_actions;
71197 -};
71198 +} __do_const;
71199
71200 struct llc_conn_state {
71201 u8 current_state;
71202 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
71203 index 37a3bbd..55a4241 100644
71204 --- a/include/net/llc_s_ac.h
71205 +++ b/include/net/llc_s_ac.h
71206 @@ -23,7 +23,7 @@
71207 #define SAP_ACT_TEST_IND 9
71208
71209 /* All action functions must look like this */
71210 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71211 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
71212
71213 extern int llc_sap_action_unitdata_ind(struct llc_sap *sap,
71214 struct sk_buff *skb);
71215 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
71216 index 567c681..cd73ac0 100644
71217 --- a/include/net/llc_s_st.h
71218 +++ b/include/net/llc_s_st.h
71219 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
71220 llc_sap_ev_t ev;
71221 u8 next_state;
71222 llc_sap_action_t *ev_actions;
71223 -};
71224 +} __do_const;
71225
71226 struct llc_sap_state {
71227 u8 curr_state;
71228 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
71229 index ee50c5e..1bc3b1a 100644
71230 --- a/include/net/mac80211.h
71231 +++ b/include/net/mac80211.h
71232 @@ -3996,7 +3996,7 @@ struct rate_control_ops {
71233 void (*add_sta_debugfs)(void *priv, void *priv_sta,
71234 struct dentry *dir);
71235 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
71236 -};
71237 +} __do_const;
71238
71239 static inline int rate_supported(struct ieee80211_sta *sta,
71240 enum ieee80211_band band,
71241 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
71242 index 0dab173..1b76af0 100644
71243 --- a/include/net/neighbour.h
71244 +++ b/include/net/neighbour.h
71245 @@ -123,7 +123,7 @@ struct neigh_ops {
71246 void (*error_report)(struct neighbour *, struct sk_buff *);
71247 int (*output)(struct neighbour *, struct sk_buff *);
71248 int (*connected_output)(struct neighbour *, struct sk_buff *);
71249 -};
71250 +} __do_const;
71251
71252 struct pneigh_entry {
71253 struct pneigh_entry *next;
71254 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
71255 index de644bc..351fd4e 100644
71256 --- a/include/net/net_namespace.h
71257 +++ b/include/net/net_namespace.h
71258 @@ -115,7 +115,7 @@ struct net {
71259 #endif
71260 struct netns_ipvs *ipvs;
71261 struct sock *diag_nlsk;
71262 - atomic_t rt_genid;
71263 + atomic_unchecked_t rt_genid;
71264 };
71265
71266 /*
71267 @@ -282,7 +282,7 @@ struct pernet_operations {
71268 void (*exit_batch)(struct list_head *net_exit_list);
71269 int *id;
71270 size_t size;
71271 -};
71272 +} __do_const;
71273
71274 /*
71275 * Use these carefully. If you implement a network device and it
71276 @@ -330,12 +330,12 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
71277
71278 static inline int rt_genid(struct net *net)
71279 {
71280 - return atomic_read(&net->rt_genid);
71281 + return atomic_read_unchecked(&net->rt_genid);
71282 }
71283
71284 static inline void rt_genid_bump(struct net *net)
71285 {
71286 - atomic_inc(&net->rt_genid);
71287 + atomic_inc_unchecked(&net->rt_genid);
71288 }
71289
71290 #endif /* __NET_NET_NAMESPACE_H */
71291 diff --git a/include/net/netdma.h b/include/net/netdma.h
71292 index 8ba8ce2..99b7fff 100644
71293 --- a/include/net/netdma.h
71294 +++ b/include/net/netdma.h
71295 @@ -24,7 +24,7 @@
71296 #include <linux/dmaengine.h>
71297 #include <linux/skbuff.h>
71298
71299 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71300 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
71301 struct sk_buff *skb, int offset, struct iovec *to,
71302 size_t len, struct dma_pinned_list *pinned_list);
71303
71304 diff --git a/include/net/netlink.h b/include/net/netlink.h
71305 index 9690b0f..87aded7 100644
71306 --- a/include/net/netlink.h
71307 +++ b/include/net/netlink.h
71308 @@ -534,7 +534,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
71309 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
71310 {
71311 if (mark)
71312 - skb_trim(skb, (unsigned char *) mark - skb->data);
71313 + skb_trim(skb, (const unsigned char *) mark - skb->data);
71314 }
71315
71316 /**
71317 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
71318 index 923cb20..deae816 100644
71319 --- a/include/net/netns/conntrack.h
71320 +++ b/include/net/netns/conntrack.h
71321 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
71322 struct nf_proto_net {
71323 #ifdef CONFIG_SYSCTL
71324 struct ctl_table_header *ctl_table_header;
71325 - struct ctl_table *ctl_table;
71326 + ctl_table_no_const *ctl_table;
71327 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
71328 struct ctl_table_header *ctl_compat_header;
71329 - struct ctl_table *ctl_compat_table;
71330 + ctl_table_no_const *ctl_compat_table;
71331 #endif
71332 #endif
71333 unsigned int users;
71334 @@ -58,7 +58,7 @@ struct nf_ip_net {
71335 struct nf_icmp_net icmpv6;
71336 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
71337 struct ctl_table_header *ctl_table_header;
71338 - struct ctl_table *ctl_table;
71339 + ctl_table_no_const *ctl_table;
71340 #endif
71341 };
71342
71343 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
71344 index 2ae2b83..dbdc85e 100644
71345 --- a/include/net/netns/ipv4.h
71346 +++ b/include/net/netns/ipv4.h
71347 @@ -64,7 +64,7 @@ struct netns_ipv4 {
71348 kgid_t sysctl_ping_group_range[2];
71349 long sysctl_tcp_mem[3];
71350
71351 - atomic_t dev_addr_genid;
71352 + atomic_unchecked_t dev_addr_genid;
71353
71354 #ifdef CONFIG_IP_MROUTE
71355 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
71356 diff --git a/include/net/protocol.h b/include/net/protocol.h
71357 index 047c047..b9dad15 100644
71358 --- a/include/net/protocol.h
71359 +++ b/include/net/protocol.h
71360 @@ -44,7 +44,7 @@ struct net_protocol {
71361 void (*err_handler)(struct sk_buff *skb, u32 info);
71362 unsigned int no_policy:1,
71363 netns_ok:1;
71364 -};
71365 +} __do_const;
71366
71367 #if IS_ENABLED(CONFIG_IPV6)
71368 struct inet6_protocol {
71369 @@ -57,7 +57,7 @@ struct inet6_protocol {
71370 u8 type, u8 code, int offset,
71371 __be32 info);
71372 unsigned int flags; /* INET6_PROTO_xxx */
71373 -};
71374 +} __do_const;
71375
71376 #define INET6_PROTO_NOPOLICY 0x1
71377 #define INET6_PROTO_FINAL 0x2
71378 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
71379 index 5a15fab..d799ea7 100644
71380 --- a/include/net/rtnetlink.h
71381 +++ b/include/net/rtnetlink.h
71382 @@ -81,7 +81,7 @@ struct rtnl_link_ops {
71383 const struct net_device *dev);
71384 unsigned int (*get_num_tx_queues)(void);
71385 unsigned int (*get_num_rx_queues)(void);
71386 -};
71387 +} __do_const;
71388
71389 extern int __rtnl_link_register(struct rtnl_link_ops *ops);
71390 extern void __rtnl_link_unregister(struct rtnl_link_ops *ops);
71391 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
71392 index 7fdf298..197e9f7 100644
71393 --- a/include/net/sctp/sctp.h
71394 +++ b/include/net/sctp/sctp.h
71395 @@ -330,9 +330,9 @@ do { \
71396
71397 #else /* SCTP_DEBUG */
71398
71399 -#define SCTP_DEBUG_PRINTK(whatever...)
71400 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
71401 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
71402 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
71403 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
71404 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
71405 #define SCTP_ENABLE_DEBUG
71406 #define SCTP_DISABLE_DEBUG
71407 #define SCTP_ASSERT(expr, str, func)
71408 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
71409 index 2a82d13..62a31c2 100644
71410 --- a/include/net/sctp/sm.h
71411 +++ b/include/net/sctp/sm.h
71412 @@ -87,7 +87,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
71413 typedef struct {
71414 sctp_state_fn_t *fn;
71415 const char *name;
71416 -} sctp_sm_table_entry_t;
71417 +} __do_const sctp_sm_table_entry_t;
71418
71419 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
71420 * currently in use.
71421 @@ -299,7 +299,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
71422 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
71423
71424 /* Extern declarations for major data structures. */
71425 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
71426 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
71427
71428
71429 /* Get the size of a DATA chunk payload. */
71430 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
71431 index fdeb85a..1329d95 100644
71432 --- a/include/net/sctp/structs.h
71433 +++ b/include/net/sctp/structs.h
71434 @@ -517,7 +517,7 @@ struct sctp_pf {
71435 struct sctp_association *asoc);
71436 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
71437 struct sctp_af *af;
71438 -};
71439 +} __do_const;
71440
71441
71442 /* Structure to track chunk fragments that have been acked, but peer
71443 diff --git a/include/net/sock.h b/include/net/sock.h
71444 index 25afaa0..8bb0070 100644
71445 --- a/include/net/sock.h
71446 +++ b/include/net/sock.h
71447 @@ -322,7 +322,7 @@ struct sock {
71448 #ifdef CONFIG_RPS
71449 __u32 sk_rxhash;
71450 #endif
71451 - atomic_t sk_drops;
71452 + atomic_unchecked_t sk_drops;
71453 int sk_rcvbuf;
71454
71455 struct sk_filter __rcu *sk_filter;
71456 @@ -1781,7 +1781,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
71457 }
71458
71459 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
71460 - char __user *from, char *to,
71461 + char __user *from, unsigned char *to,
71462 int copy, int offset)
71463 {
71464 if (skb->ip_summed == CHECKSUM_NONE) {
71465 @@ -2040,7 +2040,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
71466 }
71467 }
71468
71469 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
71470 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
71471
71472 /**
71473 * sk_page_frag - return an appropriate page_frag
71474 diff --git a/include/net/tcp.h b/include/net/tcp.h
71475 index aed42c7..43890c6 100644
71476 --- a/include/net/tcp.h
71477 +++ b/include/net/tcp.h
71478 @@ -530,7 +530,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
71479 extern void tcp_xmit_retransmit_queue(struct sock *);
71480 extern void tcp_simple_retransmit(struct sock *);
71481 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
71482 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
71483 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
71484
71485 extern void tcp_send_probe0(struct sock *);
71486 extern void tcp_send_partial(struct sock *);
71487 @@ -701,8 +701,8 @@ struct tcp_skb_cb {
71488 struct inet6_skb_parm h6;
71489 #endif
71490 } header; /* For incoming frames */
71491 - __u32 seq; /* Starting sequence number */
71492 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
71493 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
71494 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
71495 __u32 when; /* used to compute rtt's */
71496 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
71497
71498 @@ -716,7 +716,7 @@ struct tcp_skb_cb {
71499
71500 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
71501 /* 1 byte hole */
71502 - __u32 ack_seq; /* Sequence number ACK'd */
71503 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
71504 };
71505
71506 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
71507 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
71508 index 63445ed..d6fc34f 100644
71509 --- a/include/net/xfrm.h
71510 +++ b/include/net/xfrm.h
71511 @@ -304,7 +304,7 @@ struct xfrm_policy_afinfo {
71512 struct net_device *dev,
71513 const struct flowi *fl);
71514 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
71515 -};
71516 +} __do_const;
71517
71518 extern int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
71519 extern int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
71520 @@ -340,7 +340,7 @@ struct xfrm_state_afinfo {
71521 struct sk_buff *skb);
71522 int (*transport_finish)(struct sk_buff *skb,
71523 int async);
71524 -};
71525 +} __do_const;
71526
71527 extern int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
71528 extern int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
71529 @@ -423,7 +423,7 @@ struct xfrm_mode {
71530 struct module *owner;
71531 unsigned int encap;
71532 int flags;
71533 -};
71534 +} __do_const;
71535
71536 /* Flags for xfrm_mode. */
71537 enum {
71538 @@ -514,7 +514,7 @@ struct xfrm_policy {
71539 struct timer_list timer;
71540
71541 struct flow_cache_object flo;
71542 - atomic_t genid;
71543 + atomic_unchecked_t genid;
71544 u32 priority;
71545 u32 index;
71546 struct xfrm_mark mark;
71547 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
71548 index 1a046b1..ee0bef0 100644
71549 --- a/include/rdma/iw_cm.h
71550 +++ b/include/rdma/iw_cm.h
71551 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
71552 int backlog);
71553
71554 int (*destroy_listen)(struct iw_cm_id *cm_id);
71555 -};
71556 +} __no_const;
71557
71558 /**
71559 * iw_create_cm_id - Create an IW CM identifier.
71560 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
71561 index 399162b..b337f1a 100644
71562 --- a/include/scsi/libfc.h
71563 +++ b/include/scsi/libfc.h
71564 @@ -762,6 +762,7 @@ struct libfc_function_template {
71565 */
71566 void (*disc_stop_final) (struct fc_lport *);
71567 };
71568 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
71569
71570 /**
71571 * struct fc_disc - Discovery context
71572 @@ -866,7 +867,7 @@ struct fc_lport {
71573 struct fc_vport *vport;
71574
71575 /* Operational Information */
71576 - struct libfc_function_template tt;
71577 + libfc_function_template_no_const tt;
71578 u8 link_up;
71579 u8 qfull;
71580 enum fc_lport_state state;
71581 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
71582 index e65c62e..aa2e5a2 100644
71583 --- a/include/scsi/scsi_device.h
71584 +++ b/include/scsi/scsi_device.h
71585 @@ -170,9 +170,9 @@ struct scsi_device {
71586 unsigned int max_device_blocked; /* what device_blocked counts down from */
71587 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
71588
71589 - atomic_t iorequest_cnt;
71590 - atomic_t iodone_cnt;
71591 - atomic_t ioerr_cnt;
71592 + atomic_unchecked_t iorequest_cnt;
71593 + atomic_unchecked_t iodone_cnt;
71594 + atomic_unchecked_t ioerr_cnt;
71595
71596 struct device sdev_gendev,
71597 sdev_dev;
71598 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
71599 index b797e8f..8e2c3aa 100644
71600 --- a/include/scsi/scsi_transport_fc.h
71601 +++ b/include/scsi/scsi_transport_fc.h
71602 @@ -751,7 +751,8 @@ struct fc_function_template {
71603 unsigned long show_host_system_hostname:1;
71604
71605 unsigned long disable_target_scan:1;
71606 -};
71607 +} __do_const;
71608 +typedef struct fc_function_template __no_const fc_function_template_no_const;
71609
71610
71611 /**
71612 diff --git a/include/sound/soc.h b/include/sound/soc.h
71613 index bc56738..a4be132 100644
71614 --- a/include/sound/soc.h
71615 +++ b/include/sound/soc.h
71616 @@ -771,7 +771,7 @@ struct snd_soc_codec_driver {
71617 /* probe ordering - for components with runtime dependencies */
71618 int probe_order;
71619 int remove_order;
71620 -};
71621 +} __do_const;
71622
71623 /* SoC platform interface */
71624 struct snd_soc_platform_driver {
71625 @@ -817,7 +817,7 @@ struct snd_soc_platform_driver {
71626 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
71627 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
71628 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
71629 -};
71630 +} __do_const;
71631
71632 struct snd_soc_platform {
71633 const char *name;
71634 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
71635 index 663e34a..91b306a 100644
71636 --- a/include/target/target_core_base.h
71637 +++ b/include/target/target_core_base.h
71638 @@ -654,7 +654,7 @@ struct se_device {
71639 spinlock_t stats_lock;
71640 /* Active commands on this virtual SE device */
71641 atomic_t simple_cmds;
71642 - atomic_t dev_ordered_id;
71643 + atomic_unchecked_t dev_ordered_id;
71644 atomic_t dev_ordered_sync;
71645 atomic_t dev_qf_count;
71646 int export_count;
71647 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
71648 new file mode 100644
71649 index 0000000..fb634b7
71650 --- /dev/null
71651 +++ b/include/trace/events/fs.h
71652 @@ -0,0 +1,53 @@
71653 +#undef TRACE_SYSTEM
71654 +#define TRACE_SYSTEM fs
71655 +
71656 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
71657 +#define _TRACE_FS_H
71658 +
71659 +#include <linux/fs.h>
71660 +#include <linux/tracepoint.h>
71661 +
71662 +TRACE_EVENT(do_sys_open,
71663 +
71664 + TP_PROTO(const char *filename, int flags, int mode),
71665 +
71666 + TP_ARGS(filename, flags, mode),
71667 +
71668 + TP_STRUCT__entry(
71669 + __string( filename, filename )
71670 + __field( int, flags )
71671 + __field( int, mode )
71672 + ),
71673 +
71674 + TP_fast_assign(
71675 + __assign_str(filename, filename);
71676 + __entry->flags = flags;
71677 + __entry->mode = mode;
71678 + ),
71679 +
71680 + TP_printk("\"%s\" %x %o",
71681 + __get_str(filename), __entry->flags, __entry->mode)
71682 +);
71683 +
71684 +TRACE_EVENT(open_exec,
71685 +
71686 + TP_PROTO(const char *filename),
71687 +
71688 + TP_ARGS(filename),
71689 +
71690 + TP_STRUCT__entry(
71691 + __string( filename, filename )
71692 + ),
71693 +
71694 + TP_fast_assign(
71695 + __assign_str(filename, filename);
71696 + ),
71697 +
71698 + TP_printk("\"%s\"",
71699 + __get_str(filename))
71700 +);
71701 +
71702 +#endif /* _TRACE_FS_H */
71703 +
71704 +/* This part must be outside protection */
71705 +#include <trace/define_trace.h>
71706 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
71707 index 1c09820..7f5ec79 100644
71708 --- a/include/trace/events/irq.h
71709 +++ b/include/trace/events/irq.h
71710 @@ -36,7 +36,7 @@ struct softirq_action;
71711 */
71712 TRACE_EVENT(irq_handler_entry,
71713
71714 - TP_PROTO(int irq, struct irqaction *action),
71715 + TP_PROTO(int irq, const struct irqaction *action),
71716
71717 TP_ARGS(irq, action),
71718
71719 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
71720 */
71721 TRACE_EVENT(irq_handler_exit,
71722
71723 - TP_PROTO(int irq, struct irqaction *action, int ret),
71724 + TP_PROTO(int irq, const struct irqaction *action, int ret),
71725
71726 TP_ARGS(irq, action, ret),
71727
71728 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
71729 index 7caf44c..23c6f27 100644
71730 --- a/include/uapi/linux/a.out.h
71731 +++ b/include/uapi/linux/a.out.h
71732 @@ -39,6 +39,14 @@ enum machine_type {
71733 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
71734 };
71735
71736 +/* Constants for the N_FLAGS field */
71737 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
71738 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
71739 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
71740 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
71741 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
71742 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
71743 +
71744 #if !defined (N_MAGIC)
71745 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
71746 #endif
71747 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
71748 index d876736..b36014e 100644
71749 --- a/include/uapi/linux/byteorder/little_endian.h
71750 +++ b/include/uapi/linux/byteorder/little_endian.h
71751 @@ -42,51 +42,51 @@
71752
71753 static inline __le64 __cpu_to_le64p(const __u64 *p)
71754 {
71755 - return (__force __le64)*p;
71756 + return (__force const __le64)*p;
71757 }
71758 static inline __u64 __le64_to_cpup(const __le64 *p)
71759 {
71760 - return (__force __u64)*p;
71761 + return (__force const __u64)*p;
71762 }
71763 static inline __le32 __cpu_to_le32p(const __u32 *p)
71764 {
71765 - return (__force __le32)*p;
71766 + return (__force const __le32)*p;
71767 }
71768 static inline __u32 __le32_to_cpup(const __le32 *p)
71769 {
71770 - return (__force __u32)*p;
71771 + return (__force const __u32)*p;
71772 }
71773 static inline __le16 __cpu_to_le16p(const __u16 *p)
71774 {
71775 - return (__force __le16)*p;
71776 + return (__force const __le16)*p;
71777 }
71778 static inline __u16 __le16_to_cpup(const __le16 *p)
71779 {
71780 - return (__force __u16)*p;
71781 + return (__force const __u16)*p;
71782 }
71783 static inline __be64 __cpu_to_be64p(const __u64 *p)
71784 {
71785 - return (__force __be64)__swab64p(p);
71786 + return (__force const __be64)__swab64p(p);
71787 }
71788 static inline __u64 __be64_to_cpup(const __be64 *p)
71789 {
71790 - return __swab64p((__u64 *)p);
71791 + return __swab64p((const __u64 *)p);
71792 }
71793 static inline __be32 __cpu_to_be32p(const __u32 *p)
71794 {
71795 - return (__force __be32)__swab32p(p);
71796 + return (__force const __be32)__swab32p(p);
71797 }
71798 static inline __u32 __be32_to_cpup(const __be32 *p)
71799 {
71800 - return __swab32p((__u32 *)p);
71801 + return __swab32p((const __u32 *)p);
71802 }
71803 static inline __be16 __cpu_to_be16p(const __u16 *p)
71804 {
71805 - return (__force __be16)__swab16p(p);
71806 + return (__force const __be16)__swab16p(p);
71807 }
71808 static inline __u16 __be16_to_cpup(const __be16 *p)
71809 {
71810 - return __swab16p((__u16 *)p);
71811 + return __swab16p((const __u16 *)p);
71812 }
71813 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
71814 #define __le64_to_cpus(x) do { (void)(x); } while (0)
71815 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
71816 index 126a817..d522bd1 100644
71817 --- a/include/uapi/linux/elf.h
71818 +++ b/include/uapi/linux/elf.h
71819 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
71820 #define PT_GNU_EH_FRAME 0x6474e550
71821
71822 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
71823 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
71824 +
71825 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
71826 +
71827 +/* Constants for the e_flags field */
71828 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
71829 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
71830 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
71831 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
71832 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
71833 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
71834
71835 /*
71836 * Extended Numbering
71837 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
71838 #define DT_DEBUG 21
71839 #define DT_TEXTREL 22
71840 #define DT_JMPREL 23
71841 +#define DT_FLAGS 30
71842 + #define DF_TEXTREL 0x00000004
71843 #define DT_ENCODING 32
71844 #define OLD_DT_LOOS 0x60000000
71845 #define DT_LOOS 0x6000000d
71846 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
71847 #define PF_W 0x2
71848 #define PF_X 0x1
71849
71850 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
71851 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
71852 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
71853 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
71854 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
71855 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
71856 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
71857 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
71858 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
71859 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
71860 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
71861 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
71862 +
71863 typedef struct elf32_phdr{
71864 Elf32_Word p_type;
71865 Elf32_Off p_offset;
71866 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
71867 #define EI_OSABI 7
71868 #define EI_PAD 8
71869
71870 +#define EI_PAX 14
71871 +
71872 #define ELFMAG0 0x7f /* EI_MAG */
71873 #define ELFMAG1 'E'
71874 #define ELFMAG2 'L'
71875 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
71876 index aa169c4..6a2771d 100644
71877 --- a/include/uapi/linux/personality.h
71878 +++ b/include/uapi/linux/personality.h
71879 @@ -30,6 +30,7 @@ enum {
71880 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
71881 ADDR_NO_RANDOMIZE | \
71882 ADDR_COMPAT_LAYOUT | \
71883 + ADDR_LIMIT_3GB | \
71884 MMAP_PAGE_ZERO)
71885
71886 /*
71887 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
71888 index 7530e74..e714828 100644
71889 --- a/include/uapi/linux/screen_info.h
71890 +++ b/include/uapi/linux/screen_info.h
71891 @@ -43,7 +43,8 @@ struct screen_info {
71892 __u16 pages; /* 0x32 */
71893 __u16 vesa_attributes; /* 0x34 */
71894 __u32 capabilities; /* 0x36 */
71895 - __u8 _reserved[6]; /* 0x3a */
71896 + __u16 vesapm_size; /* 0x3a */
71897 + __u8 _reserved[4]; /* 0x3c */
71898 } __attribute__((packed));
71899
71900 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
71901 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
71902 index 6d67213..8dab561 100644
71903 --- a/include/uapi/linux/sysctl.h
71904 +++ b/include/uapi/linux/sysctl.h
71905 @@ -155,7 +155,11 @@ enum
71906 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
71907 };
71908
71909 -
71910 +#ifdef CONFIG_PAX_SOFTMODE
71911 +enum {
71912 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
71913 +};
71914 +#endif
71915
71916 /* CTL_VM names: */
71917 enum
71918 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
71919 index 26607bd..588b65f 100644
71920 --- a/include/uapi/linux/xattr.h
71921 +++ b/include/uapi/linux/xattr.h
71922 @@ -60,5 +60,9 @@
71923 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
71924 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
71925
71926 +/* User namespace */
71927 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
71928 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
71929 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
71930
71931 #endif /* _UAPI_LINUX_XATTR_H */
71932 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
71933 index f9466fa..f4e2b81 100644
71934 --- a/include/video/udlfb.h
71935 +++ b/include/video/udlfb.h
71936 @@ -53,10 +53,10 @@ struct dlfb_data {
71937 u32 pseudo_palette[256];
71938 int blank_mode; /*one of FB_BLANK_ */
71939 /* blit-only rendering path metrics, exposed through sysfs */
71940 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
71941 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
71942 - atomic_t bytes_sent; /* to usb, after compression including overhead */
71943 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
71944 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
71945 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
71946 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
71947 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
71948 };
71949
71950 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
71951 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
71952 index 0993a22..32ba2fe 100644
71953 --- a/include/video/uvesafb.h
71954 +++ b/include/video/uvesafb.h
71955 @@ -177,6 +177,7 @@ struct uvesafb_par {
71956 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
71957 u8 pmi_setpal; /* PMI for palette changes */
71958 u16 *pmi_base; /* protected mode interface location */
71959 + u8 *pmi_code; /* protected mode code location */
71960 void *pmi_start;
71961 void *pmi_pal;
71962 u8 *vbe_state_orig; /*
71963 diff --git a/init/Kconfig b/init/Kconfig
71964 index be8b7f5..1eeca9b 100644
71965 --- a/init/Kconfig
71966 +++ b/init/Kconfig
71967 @@ -990,6 +990,7 @@ endif # CGROUPS
71968
71969 config CHECKPOINT_RESTORE
71970 bool "Checkpoint/restore support" if EXPERT
71971 + depends on !GRKERNSEC
71972 default n
71973 help
71974 Enables additional kernel features in a sake of checkpoint/restore.
71975 @@ -1468,7 +1469,7 @@ config SLUB_DEBUG
71976
71977 config COMPAT_BRK
71978 bool "Disable heap randomization"
71979 - default y
71980 + default n
71981 help
71982 Randomizing heap placement makes heap exploits harder, but it
71983 also breaks ancient binaries (including anything libc5 based).
71984 @@ -1711,7 +1712,7 @@ config INIT_ALL_POSSIBLE
71985 config STOP_MACHINE
71986 bool
71987 default y
71988 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
71989 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
71990 help
71991 Need stop_machine() primitive.
71992
71993 diff --git a/init/Makefile b/init/Makefile
71994 index 7bc47ee..6da2dc7 100644
71995 --- a/init/Makefile
71996 +++ b/init/Makefile
71997 @@ -2,6 +2,9 @@
71998 # Makefile for the linux kernel.
71999 #
72000
72001 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
72002 +asflags-y := $(GCC_PLUGINS_AFLAGS)
72003 +
72004 obj-y := main.o version.o mounts.o
72005 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
72006 obj-y += noinitramfs.o
72007 diff --git a/init/do_mounts.c b/init/do_mounts.c
72008 index 1d1b634..a1c810f 100644
72009 --- a/init/do_mounts.c
72010 +++ b/init/do_mounts.c
72011 @@ -355,11 +355,11 @@ static void __init get_fs_names(char *page)
72012 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
72013 {
72014 struct super_block *s;
72015 - int err = sys_mount(name, "/root", fs, flags, data);
72016 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
72017 if (err)
72018 return err;
72019
72020 - sys_chdir("/root");
72021 + sys_chdir((const char __force_user *)"/root");
72022 s = current->fs->pwd.dentry->d_sb;
72023 ROOT_DEV = s->s_dev;
72024 printk(KERN_INFO
72025 @@ -480,18 +480,18 @@ void __init change_floppy(char *fmt, ...)
72026 va_start(args, fmt);
72027 vsprintf(buf, fmt, args);
72028 va_end(args);
72029 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
72030 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
72031 if (fd >= 0) {
72032 sys_ioctl(fd, FDEJECT, 0);
72033 sys_close(fd);
72034 }
72035 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
72036 - fd = sys_open("/dev/console", O_RDWR, 0);
72037 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
72038 if (fd >= 0) {
72039 sys_ioctl(fd, TCGETS, (long)&termios);
72040 termios.c_lflag &= ~ICANON;
72041 sys_ioctl(fd, TCSETSF, (long)&termios);
72042 - sys_read(fd, &c, 1);
72043 + sys_read(fd, (char __user *)&c, 1);
72044 termios.c_lflag |= ICANON;
72045 sys_ioctl(fd, TCSETSF, (long)&termios);
72046 sys_close(fd);
72047 @@ -585,6 +585,6 @@ void __init prepare_namespace(void)
72048 mount_root();
72049 out:
72050 devtmpfs_mount("dev");
72051 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
72052 - sys_chroot(".");
72053 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
72054 + sys_chroot((const char __force_user *)".");
72055 }
72056 diff --git a/init/do_mounts.h b/init/do_mounts.h
72057 index f5b978a..69dbfe8 100644
72058 --- a/init/do_mounts.h
72059 +++ b/init/do_mounts.h
72060 @@ -15,15 +15,15 @@ extern int root_mountflags;
72061
72062 static inline int create_dev(char *name, dev_t dev)
72063 {
72064 - sys_unlink(name);
72065 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
72066 + sys_unlink((char __force_user *)name);
72067 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
72068 }
72069
72070 #if BITS_PER_LONG == 32
72071 static inline u32 bstat(char *name)
72072 {
72073 struct stat64 stat;
72074 - if (sys_stat64(name, &stat) != 0)
72075 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
72076 return 0;
72077 if (!S_ISBLK(stat.st_mode))
72078 return 0;
72079 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
72080 static inline u32 bstat(char *name)
72081 {
72082 struct stat stat;
72083 - if (sys_newstat(name, &stat) != 0)
72084 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
72085 return 0;
72086 if (!S_ISBLK(stat.st_mode))
72087 return 0;
72088 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
72089 index f9acf71..1e19144 100644
72090 --- a/init/do_mounts_initrd.c
72091 +++ b/init/do_mounts_initrd.c
72092 @@ -58,8 +58,8 @@ static void __init handle_initrd(void)
72093 create_dev("/dev/root.old", Root_RAM0);
72094 /* mount initrd on rootfs' /root */
72095 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
72096 - sys_mkdir("/old", 0700);
72097 - sys_chdir("/old");
72098 + sys_mkdir((const char __force_user *)"/old", 0700);
72099 + sys_chdir((const char __force_user *)"/old");
72100
72101 /*
72102 * In case that a resume from disk is carried out by linuxrc or one of
72103 @@ -73,31 +73,31 @@ static void __init handle_initrd(void)
72104 current->flags &= ~PF_FREEZER_SKIP;
72105
72106 /* move initrd to rootfs' /old */
72107 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
72108 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
72109 /* switch root and cwd back to / of rootfs */
72110 - sys_chroot("..");
72111 + sys_chroot((const char __force_user *)"..");
72112
72113 if (new_decode_dev(real_root_dev) == Root_RAM0) {
72114 - sys_chdir("/old");
72115 + sys_chdir((const char __force_user *)"/old");
72116 return;
72117 }
72118
72119 - sys_chdir("/");
72120 + sys_chdir((const char __force_user *)"/");
72121 ROOT_DEV = new_decode_dev(real_root_dev);
72122 mount_root();
72123
72124 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
72125 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
72126 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
72127 if (!error)
72128 printk("okay\n");
72129 else {
72130 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
72131 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
72132 if (error == -ENOENT)
72133 printk("/initrd does not exist. Ignored.\n");
72134 else
72135 printk("failed\n");
72136 printk(KERN_NOTICE "Unmounting old root\n");
72137 - sys_umount("/old", MNT_DETACH);
72138 + sys_umount((char __force_user *)"/old", MNT_DETACH);
72139 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
72140 if (fd < 0) {
72141 error = fd;
72142 @@ -120,11 +120,11 @@ int __init initrd_load(void)
72143 * mounted in the normal path.
72144 */
72145 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
72146 - sys_unlink("/initrd.image");
72147 + sys_unlink((const char __force_user *)"/initrd.image");
72148 handle_initrd();
72149 return 1;
72150 }
72151 }
72152 - sys_unlink("/initrd.image");
72153 + sys_unlink((const char __force_user *)"/initrd.image");
72154 return 0;
72155 }
72156 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
72157 index 8cb6db5..d729f50 100644
72158 --- a/init/do_mounts_md.c
72159 +++ b/init/do_mounts_md.c
72160 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
72161 partitioned ? "_d" : "", minor,
72162 md_setup_args[ent].device_names);
72163
72164 - fd = sys_open(name, 0, 0);
72165 + fd = sys_open((char __force_user *)name, 0, 0);
72166 if (fd < 0) {
72167 printk(KERN_ERR "md: open failed - cannot start "
72168 "array %s\n", name);
72169 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
72170 * array without it
72171 */
72172 sys_close(fd);
72173 - fd = sys_open(name, 0, 0);
72174 + fd = sys_open((char __force_user *)name, 0, 0);
72175 sys_ioctl(fd, BLKRRPART, 0);
72176 }
72177 sys_close(fd);
72178 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
72179
72180 wait_for_device_probe();
72181
72182 - fd = sys_open("/dev/md0", 0, 0);
72183 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
72184 if (fd >= 0) {
72185 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
72186 sys_close(fd);
72187 diff --git a/init/init_task.c b/init/init_task.c
72188 index 8b2f399..f0797c9 100644
72189 --- a/init/init_task.c
72190 +++ b/init/init_task.c
72191 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
72192 * Initial thread structure. Alignment of this is handled by a special
72193 * linker map entry.
72194 */
72195 +#ifdef CONFIG_X86
72196 +union thread_union init_thread_union __init_task_data;
72197 +#else
72198 union thread_union init_thread_union __init_task_data =
72199 { INIT_THREAD_INFO(init_task) };
72200 +#endif
72201 diff --git a/init/initramfs.c b/init/initramfs.c
72202 index 84c6bf1..8899338 100644
72203 --- a/init/initramfs.c
72204 +++ b/init/initramfs.c
72205 @@ -84,7 +84,7 @@ static void __init free_hash(void)
72206 }
72207 }
72208
72209 -static long __init do_utime(char *filename, time_t mtime)
72210 +static long __init do_utime(char __force_user *filename, time_t mtime)
72211 {
72212 struct timespec t[2];
72213
72214 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
72215 struct dir_entry *de, *tmp;
72216 list_for_each_entry_safe(de, tmp, &dir_list, list) {
72217 list_del(&de->list);
72218 - do_utime(de->name, de->mtime);
72219 + do_utime((char __force_user *)de->name, de->mtime);
72220 kfree(de->name);
72221 kfree(de);
72222 }
72223 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
72224 if (nlink >= 2) {
72225 char *old = find_link(major, minor, ino, mode, collected);
72226 if (old)
72227 - return (sys_link(old, collected) < 0) ? -1 : 1;
72228 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
72229 }
72230 return 0;
72231 }
72232 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
72233 {
72234 struct stat st;
72235
72236 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
72237 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
72238 if (S_ISDIR(st.st_mode))
72239 - sys_rmdir(path);
72240 + sys_rmdir((char __force_user *)path);
72241 else
72242 - sys_unlink(path);
72243 + sys_unlink((char __force_user *)path);
72244 }
72245 }
72246
72247 @@ -315,7 +315,7 @@ static int __init do_name(void)
72248 int openflags = O_WRONLY|O_CREAT;
72249 if (ml != 1)
72250 openflags |= O_TRUNC;
72251 - wfd = sys_open(collected, openflags, mode);
72252 + wfd = sys_open((char __force_user *)collected, openflags, mode);
72253
72254 if (wfd >= 0) {
72255 sys_fchown(wfd, uid, gid);
72256 @@ -327,17 +327,17 @@ static int __init do_name(void)
72257 }
72258 }
72259 } else if (S_ISDIR(mode)) {
72260 - sys_mkdir(collected, mode);
72261 - sys_chown(collected, uid, gid);
72262 - sys_chmod(collected, mode);
72263 + sys_mkdir((char __force_user *)collected, mode);
72264 + sys_chown((char __force_user *)collected, uid, gid);
72265 + sys_chmod((char __force_user *)collected, mode);
72266 dir_add(collected, mtime);
72267 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
72268 S_ISFIFO(mode) || S_ISSOCK(mode)) {
72269 if (maybe_link() == 0) {
72270 - sys_mknod(collected, mode, rdev);
72271 - sys_chown(collected, uid, gid);
72272 - sys_chmod(collected, mode);
72273 - do_utime(collected, mtime);
72274 + sys_mknod((char __force_user *)collected, mode, rdev);
72275 + sys_chown((char __force_user *)collected, uid, gid);
72276 + sys_chmod((char __force_user *)collected, mode);
72277 + do_utime((char __force_user *)collected, mtime);
72278 }
72279 }
72280 return 0;
72281 @@ -346,15 +346,15 @@ static int __init do_name(void)
72282 static int __init do_copy(void)
72283 {
72284 if (count >= body_len) {
72285 - sys_write(wfd, victim, body_len);
72286 + sys_write(wfd, (char __force_user *)victim, body_len);
72287 sys_close(wfd);
72288 - do_utime(vcollected, mtime);
72289 + do_utime((char __force_user *)vcollected, mtime);
72290 kfree(vcollected);
72291 eat(body_len);
72292 state = SkipIt;
72293 return 0;
72294 } else {
72295 - sys_write(wfd, victim, count);
72296 + sys_write(wfd, (char __force_user *)victim, count);
72297 body_len -= count;
72298 eat(count);
72299 return 1;
72300 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
72301 {
72302 collected[N_ALIGN(name_len) + body_len] = '\0';
72303 clean_path(collected, 0);
72304 - sys_symlink(collected + N_ALIGN(name_len), collected);
72305 - sys_lchown(collected, uid, gid);
72306 - do_utime(collected, mtime);
72307 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
72308 + sys_lchown((char __force_user *)collected, uid, gid);
72309 + do_utime((char __force_user *)collected, mtime);
72310 state = SkipIt;
72311 next_state = Reset;
72312 return 0;
72313 diff --git a/init/main.c b/init/main.c
72314 index cee4b5c..6a3402b 100644
72315 --- a/init/main.c
72316 +++ b/init/main.c
72317 @@ -96,6 +96,8 @@ static inline void mark_rodata_ro(void) { }
72318 extern void tc_init(void);
72319 #endif
72320
72321 +extern void grsecurity_init(void);
72322 +
72323 /*
72324 * Debug helper: via this flag we know that we are in 'early bootup code'
72325 * where only the boot processor is running with IRQ disabled. This means
72326 @@ -149,6 +151,61 @@ static int __init set_reset_devices(char *str)
72327
72328 __setup("reset_devices", set_reset_devices);
72329
72330 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
72331 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
72332 +static int __init setup_grsec_proc_gid(char *str)
72333 +{
72334 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
72335 + return 1;
72336 +}
72337 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
72338 +#endif
72339 +
72340 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
72341 +extern char pax_enter_kernel_user[];
72342 +extern char pax_exit_kernel_user[];
72343 +extern pgdval_t clone_pgd_mask;
72344 +#endif
72345 +
72346 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
72347 +static int __init setup_pax_nouderef(char *str)
72348 +{
72349 +#ifdef CONFIG_X86_32
72350 + unsigned int cpu;
72351 + struct desc_struct *gdt;
72352 +
72353 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
72354 + gdt = get_cpu_gdt_table(cpu);
72355 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
72356 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
72357 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
72358 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
72359 + }
72360 + loadsegment(ds, __KERNEL_DS);
72361 + loadsegment(es, __KERNEL_DS);
72362 + loadsegment(ss, __KERNEL_DS);
72363 +#else
72364 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
72365 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
72366 + clone_pgd_mask = ~(pgdval_t)0UL;
72367 +#endif
72368 +
72369 + return 0;
72370 +}
72371 +early_param("pax_nouderef", setup_pax_nouderef);
72372 +#endif
72373 +
72374 +#ifdef CONFIG_PAX_SOFTMODE
72375 +int pax_softmode;
72376 +
72377 +static int __init setup_pax_softmode(char *str)
72378 +{
72379 + get_option(&str, &pax_softmode);
72380 + return 1;
72381 +}
72382 +__setup("pax_softmode=", setup_pax_softmode);
72383 +#endif
72384 +
72385 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
72386 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
72387 static const char *panic_later, *panic_param;
72388 @@ -681,6 +738,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
72389 {
72390 int count = preempt_count();
72391 int ret;
72392 + const char *msg1 = "", *msg2 = "";
72393
72394 if (initcall_debug)
72395 ret = do_one_initcall_debug(fn);
72396 @@ -693,15 +751,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
72397 sprintf(msgbuf, "error code %d ", ret);
72398
72399 if (preempt_count() != count) {
72400 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
72401 + msg1 = " preemption imbalance";
72402 preempt_count() = count;
72403 }
72404 if (irqs_disabled()) {
72405 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
72406 + msg2 = " disabled interrupts";
72407 local_irq_enable();
72408 }
72409 - if (msgbuf[0]) {
72410 - printk("initcall %pF returned with %s\n", fn, msgbuf);
72411 + if (msgbuf[0] || *msg1 || *msg2) {
72412 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
72413 }
72414
72415 return ret;
72416 @@ -755,8 +813,14 @@ static void __init do_initcall_level(int level)
72417 level, level,
72418 &repair_env_string);
72419
72420 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
72421 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
72422 do_one_initcall(*fn);
72423 +
72424 +#ifdef CONFIG_PAX_LATENT_ENTROPY
72425 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
72426 +#endif
72427 +
72428 + }
72429 }
72430
72431 static void __init do_initcalls(void)
72432 @@ -790,8 +854,14 @@ static void __init do_pre_smp_initcalls(void)
72433 {
72434 initcall_t *fn;
72435
72436 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
72437 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
72438 do_one_initcall(*fn);
72439 +
72440 +#ifdef CONFIG_PAX_LATENT_ENTROPY
72441 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
72442 +#endif
72443 +
72444 + }
72445 }
72446
72447 static int run_init_process(const char *init_filename)
72448 @@ -877,7 +947,7 @@ static noinline void __init kernel_init_freeable(void)
72449 do_basic_setup();
72450
72451 /* Open the /dev/console on the rootfs, this should never fail */
72452 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
72453 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
72454 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
72455
72456 (void) sys_dup(0);
72457 @@ -890,11 +960,13 @@ static noinline void __init kernel_init_freeable(void)
72458 if (!ramdisk_execute_command)
72459 ramdisk_execute_command = "/init";
72460
72461 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
72462 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
72463 ramdisk_execute_command = NULL;
72464 prepare_namespace();
72465 }
72466
72467 + grsecurity_init();
72468 +
72469 /*
72470 * Ok, we have completed the initial bootup, and
72471 * we're essentially up and running. Get rid of the
72472 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
72473 index 130dfec..cc88451 100644
72474 --- a/ipc/ipc_sysctl.c
72475 +++ b/ipc/ipc_sysctl.c
72476 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
72477 static int proc_ipc_dointvec(ctl_table *table, int write,
72478 void __user *buffer, size_t *lenp, loff_t *ppos)
72479 {
72480 - struct ctl_table ipc_table;
72481 + ctl_table_no_const ipc_table;
72482
72483 memcpy(&ipc_table, table, sizeof(ipc_table));
72484 ipc_table.data = get_ipc(table);
72485 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
72486 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
72487 void __user *buffer, size_t *lenp, loff_t *ppos)
72488 {
72489 - struct ctl_table ipc_table;
72490 + ctl_table_no_const ipc_table;
72491
72492 memcpy(&ipc_table, table, sizeof(ipc_table));
72493 ipc_table.data = get_ipc(table);
72494 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
72495 static int proc_ipc_callback_dointvec(ctl_table *table, int write,
72496 void __user *buffer, size_t *lenp, loff_t *ppos)
72497 {
72498 - struct ctl_table ipc_table;
72499 + ctl_table_no_const ipc_table;
72500 size_t lenp_bef = *lenp;
72501 int rc;
72502
72503 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec(ctl_table *table, int write,
72504 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
72505 void __user *buffer, size_t *lenp, loff_t *ppos)
72506 {
72507 - struct ctl_table ipc_table;
72508 + ctl_table_no_const ipc_table;
72509 memcpy(&ipc_table, table, sizeof(ipc_table));
72510 ipc_table.data = get_ipc(table);
72511
72512 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
72513 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
72514 void __user *buffer, size_t *lenp, loff_t *ppos)
72515 {
72516 - struct ctl_table ipc_table;
72517 + ctl_table_no_const ipc_table;
72518 size_t lenp_bef = *lenp;
72519 int oldval;
72520 int rc;
72521 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
72522 index 383d638..943fdbb 100644
72523 --- a/ipc/mq_sysctl.c
72524 +++ b/ipc/mq_sysctl.c
72525 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
72526 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
72527 void __user *buffer, size_t *lenp, loff_t *ppos)
72528 {
72529 - struct ctl_table mq_table;
72530 + ctl_table_no_const mq_table;
72531 memcpy(&mq_table, table, sizeof(mq_table));
72532 mq_table.data = get_mq(table);
72533
72534 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
72535 index 71a3ca1..cc330ee 100644
72536 --- a/ipc/mqueue.c
72537 +++ b/ipc/mqueue.c
72538 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
72539 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
72540 info->attr.mq_msgsize);
72541
72542 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
72543 spin_lock(&mq_lock);
72544 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
72545 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
72546 diff --git a/ipc/msg.c b/ipc/msg.c
72547 index 950572f..362ea07 100644
72548 --- a/ipc/msg.c
72549 +++ b/ipc/msg.c
72550 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
72551 return security_msg_queue_associate(msq, msgflg);
72552 }
72553
72554 +static struct ipc_ops msg_ops = {
72555 + .getnew = newque,
72556 + .associate = msg_security,
72557 + .more_checks = NULL
72558 +};
72559 +
72560 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
72561 {
72562 struct ipc_namespace *ns;
72563 - struct ipc_ops msg_ops;
72564 struct ipc_params msg_params;
72565
72566 ns = current->nsproxy->ipc_ns;
72567
72568 - msg_ops.getnew = newque;
72569 - msg_ops.associate = msg_security;
72570 - msg_ops.more_checks = NULL;
72571 -
72572 msg_params.key = key;
72573 msg_params.flg = msgflg;
72574
72575 @@ -820,15 +821,17 @@ long do_msgrcv(int msqid, void __user *buf, size_t bufsz, long msgtyp,
72576 struct msg_msg *copy = NULL;
72577 unsigned long copy_number = 0;
72578
72579 + ns = current->nsproxy->ipc_ns;
72580 +
72581 if (msqid < 0 || (long) bufsz < 0)
72582 return -EINVAL;
72583 if (msgflg & MSG_COPY) {
72584 - copy = prepare_copy(buf, bufsz, msgflg, &msgtyp, &copy_number);
72585 + copy = prepare_copy(buf, min_t(size_t, bufsz, ns->msg_ctlmax),
72586 + msgflg, &msgtyp, &copy_number);
72587 if (IS_ERR(copy))
72588 return PTR_ERR(copy);
72589 }
72590 mode = convert_mode(&msgtyp, msgflg);
72591 - ns = current->nsproxy->ipc_ns;
72592
72593 msq = msg_lock_check(ns, msqid);
72594 if (IS_ERR(msq)) {
72595 diff --git a/ipc/msgutil.c b/ipc/msgutil.c
72596 index ebfcbfa..5df8e4b 100644
72597 --- a/ipc/msgutil.c
72598 +++ b/ipc/msgutil.c
72599 @@ -117,9 +117,6 @@ struct msg_msg *copy_msg(struct msg_msg *src, struct msg_msg *dst)
72600 if (alen > DATALEN_MSG)
72601 alen = DATALEN_MSG;
72602
72603 - dst->next = NULL;
72604 - dst->security = NULL;
72605 -
72606 memcpy(dst + 1, src + 1, alen);
72607
72608 len -= alen;
72609 diff --git a/ipc/sem.c b/ipc/sem.c
72610 index 58d31f1..cce7a55 100644
72611 --- a/ipc/sem.c
72612 +++ b/ipc/sem.c
72613 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
72614 return 0;
72615 }
72616
72617 +static struct ipc_ops sem_ops = {
72618 + .getnew = newary,
72619 + .associate = sem_security,
72620 + .more_checks = sem_more_checks
72621 +};
72622 +
72623 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
72624 {
72625 struct ipc_namespace *ns;
72626 - struct ipc_ops sem_ops;
72627 struct ipc_params sem_params;
72628
72629 ns = current->nsproxy->ipc_ns;
72630 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
72631 if (nsems < 0 || nsems > ns->sc_semmsl)
72632 return -EINVAL;
72633
72634 - sem_ops.getnew = newary;
72635 - sem_ops.associate = sem_security;
72636 - sem_ops.more_checks = sem_more_checks;
72637 -
72638 sem_params.key = key;
72639 sem_params.flg = semflg;
72640 sem_params.u.nsems = nsems;
72641 diff --git a/ipc/shm.c b/ipc/shm.c
72642 index 4fa6d8f..55cff14 100644
72643 --- a/ipc/shm.c
72644 +++ b/ipc/shm.c
72645 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
72646 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
72647 #endif
72648
72649 +#ifdef CONFIG_GRKERNSEC
72650 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72651 + const time_t shm_createtime, const kuid_t cuid,
72652 + const int shmid);
72653 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72654 + const time_t shm_createtime);
72655 +#endif
72656 +
72657 void shm_init_ns(struct ipc_namespace *ns)
72658 {
72659 ns->shm_ctlmax = SHMMAX;
72660 @@ -521,6 +529,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
72661 shp->shm_lprid = 0;
72662 shp->shm_atim = shp->shm_dtim = 0;
72663 shp->shm_ctim = get_seconds();
72664 +#ifdef CONFIG_GRKERNSEC
72665 + {
72666 + struct timespec timeval;
72667 + do_posix_clock_monotonic_gettime(&timeval);
72668 +
72669 + shp->shm_createtime = timeval.tv_sec;
72670 + }
72671 +#endif
72672 shp->shm_segsz = size;
72673 shp->shm_nattch = 0;
72674 shp->shm_file = file;
72675 @@ -572,18 +588,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
72676 return 0;
72677 }
72678
72679 +static struct ipc_ops shm_ops = {
72680 + .getnew = newseg,
72681 + .associate = shm_security,
72682 + .more_checks = shm_more_checks
72683 +};
72684 +
72685 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
72686 {
72687 struct ipc_namespace *ns;
72688 - struct ipc_ops shm_ops;
72689 struct ipc_params shm_params;
72690
72691 ns = current->nsproxy->ipc_ns;
72692
72693 - shm_ops.getnew = newseg;
72694 - shm_ops.associate = shm_security;
72695 - shm_ops.more_checks = shm_more_checks;
72696 -
72697 shm_params.key = key;
72698 shm_params.flg = shmflg;
72699 shm_params.u.size = size;
72700 @@ -1004,6 +1021,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
72701 f_mode = FMODE_READ | FMODE_WRITE;
72702 }
72703 if (shmflg & SHM_EXEC) {
72704 +
72705 +#ifdef CONFIG_PAX_MPROTECT
72706 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
72707 + goto out;
72708 +#endif
72709 +
72710 prot |= PROT_EXEC;
72711 acc_mode |= S_IXUGO;
72712 }
72713 @@ -1027,9 +1050,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
72714 if (err)
72715 goto out_unlock;
72716
72717 +#ifdef CONFIG_GRKERNSEC
72718 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
72719 + shp->shm_perm.cuid, shmid) ||
72720 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
72721 + err = -EACCES;
72722 + goto out_unlock;
72723 + }
72724 +#endif
72725 +
72726 path = shp->shm_file->f_path;
72727 path_get(&path);
72728 shp->shm_nattch++;
72729 +#ifdef CONFIG_GRKERNSEC
72730 + shp->shm_lapid = current->pid;
72731 +#endif
72732 size = i_size_read(path.dentry->d_inode);
72733 shm_unlock(shp);
72734
72735 diff --git a/kernel/acct.c b/kernel/acct.c
72736 index 051e071..15e0920 100644
72737 --- a/kernel/acct.c
72738 +++ b/kernel/acct.c
72739 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
72740 */
72741 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
72742 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
72743 - file->f_op->write(file, (char *)&ac,
72744 + file->f_op->write(file, (char __force_user *)&ac,
72745 sizeof(acct_t), &file->f_pos);
72746 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
72747 set_fs(fs);
72748 diff --git a/kernel/audit.c b/kernel/audit.c
72749 index d596e53..dbef3c3 100644
72750 --- a/kernel/audit.c
72751 +++ b/kernel/audit.c
72752 @@ -116,7 +116,7 @@ u32 audit_sig_sid = 0;
72753 3) suppressed due to audit_rate_limit
72754 4) suppressed due to audit_backlog_limit
72755 */
72756 -static atomic_t audit_lost = ATOMIC_INIT(0);
72757 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
72758
72759 /* The netlink socket. */
72760 static struct sock *audit_sock;
72761 @@ -238,7 +238,7 @@ void audit_log_lost(const char *message)
72762 unsigned long now;
72763 int print;
72764
72765 - atomic_inc(&audit_lost);
72766 + atomic_inc_unchecked(&audit_lost);
72767
72768 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
72769
72770 @@ -257,7 +257,7 @@ void audit_log_lost(const char *message)
72771 printk(KERN_WARNING
72772 "audit: audit_lost=%d audit_rate_limit=%d "
72773 "audit_backlog_limit=%d\n",
72774 - atomic_read(&audit_lost),
72775 + atomic_read_unchecked(&audit_lost),
72776 audit_rate_limit,
72777 audit_backlog_limit);
72778 audit_panic(message);
72779 @@ -681,7 +681,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
72780 status_set.pid = audit_pid;
72781 status_set.rate_limit = audit_rate_limit;
72782 status_set.backlog_limit = audit_backlog_limit;
72783 - status_set.lost = atomic_read(&audit_lost);
72784 + status_set.lost = atomic_read_unchecked(&audit_lost);
72785 status_set.backlog = skb_queue_len(&audit_skb_queue);
72786 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
72787 &status_set, sizeof(status_set));
72788 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
72789 index a371f85..da826c1 100644
72790 --- a/kernel/auditsc.c
72791 +++ b/kernel/auditsc.c
72792 @@ -2292,7 +2292,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
72793 }
72794
72795 /* global counter which is incremented every time something logs in */
72796 -static atomic_t session_id = ATOMIC_INIT(0);
72797 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
72798
72799 /**
72800 * audit_set_loginuid - set current task's audit_context loginuid
72801 @@ -2316,7 +2316,7 @@ int audit_set_loginuid(kuid_t loginuid)
72802 return -EPERM;
72803 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
72804
72805 - sessionid = atomic_inc_return(&session_id);
72806 + sessionid = atomic_inc_return_unchecked(&session_id);
72807 if (context && context->in_syscall) {
72808 struct audit_buffer *ab;
72809
72810 diff --git a/kernel/capability.c b/kernel/capability.c
72811 index 493d972..f87dfbd 100644
72812 --- a/kernel/capability.c
72813 +++ b/kernel/capability.c
72814 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
72815 * before modification is attempted and the application
72816 * fails.
72817 */
72818 + if (tocopy > ARRAY_SIZE(kdata))
72819 + return -EFAULT;
72820 +
72821 if (copy_to_user(dataptr, kdata, tocopy
72822 * sizeof(struct __user_cap_data_struct))) {
72823 return -EFAULT;
72824 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
72825 int ret;
72826
72827 rcu_read_lock();
72828 - ret = security_capable(__task_cred(t), ns, cap);
72829 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
72830 + gr_task_is_capable(t, __task_cred(t), cap);
72831 rcu_read_unlock();
72832
72833 - return (ret == 0);
72834 + return ret;
72835 }
72836
72837 /**
72838 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
72839 int ret;
72840
72841 rcu_read_lock();
72842 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
72843 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
72844 rcu_read_unlock();
72845
72846 - return (ret == 0);
72847 + return ret;
72848 }
72849
72850 /**
72851 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
72852 BUG();
72853 }
72854
72855 - if (security_capable(current_cred(), ns, cap) == 0) {
72856 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
72857 current->flags |= PF_SUPERPRIV;
72858 return true;
72859 }
72860 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
72861 }
72862 EXPORT_SYMBOL(ns_capable);
72863
72864 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
72865 +{
72866 + if (unlikely(!cap_valid(cap))) {
72867 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
72868 + BUG();
72869 + }
72870 +
72871 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
72872 + current->flags |= PF_SUPERPRIV;
72873 + return true;
72874 + }
72875 + return false;
72876 +}
72877 +EXPORT_SYMBOL(ns_capable_nolog);
72878 +
72879 /**
72880 * capable - Determine if the current task has a superior capability in effect
72881 * @cap: The capability to be tested for
72882 @@ -408,6 +427,12 @@ bool capable(int cap)
72883 }
72884 EXPORT_SYMBOL(capable);
72885
72886 +bool capable_nolog(int cap)
72887 +{
72888 + return ns_capable_nolog(&init_user_ns, cap);
72889 +}
72890 +EXPORT_SYMBOL(capable_nolog);
72891 +
72892 /**
72893 * nsown_capable - Check superior capability to one's own user_ns
72894 * @cap: The capability in question
72895 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
72896
72897 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
72898 }
72899 +
72900 +bool inode_capable_nolog(const struct inode *inode, int cap)
72901 +{
72902 + struct user_namespace *ns = current_user_ns();
72903 +
72904 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
72905 +}
72906 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
72907 index 1e23664..570a83d 100644
72908 --- a/kernel/cgroup.c
72909 +++ b/kernel/cgroup.c
72910 @@ -5543,7 +5543,7 @@ static int cgroup_css_links_read(struct cgroup *cont,
72911 struct css_set *cg = link->cg;
72912 struct task_struct *task;
72913 int count = 0;
72914 - seq_printf(seq, "css_set %p\n", cg);
72915 + seq_printf(seq, "css_set %pK\n", cg);
72916 list_for_each_entry(task, &cg->tasks, cg_list) {
72917 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
72918 seq_puts(seq, " ...\n");
72919 diff --git a/kernel/compat.c b/kernel/compat.c
72920 index 36700e9..73d770c 100644
72921 --- a/kernel/compat.c
72922 +++ b/kernel/compat.c
72923 @@ -13,6 +13,7 @@
72924
72925 #include <linux/linkage.h>
72926 #include <linux/compat.h>
72927 +#include <linux/module.h>
72928 #include <linux/errno.h>
72929 #include <linux/time.h>
72930 #include <linux/signal.h>
72931 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
72932 mm_segment_t oldfs;
72933 long ret;
72934
72935 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
72936 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
72937 oldfs = get_fs();
72938 set_fs(KERNEL_DS);
72939 ret = hrtimer_nanosleep_restart(restart);
72940 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
72941 oldfs = get_fs();
72942 set_fs(KERNEL_DS);
72943 ret = hrtimer_nanosleep(&tu,
72944 - rmtp ? (struct timespec __user *)&rmt : NULL,
72945 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
72946 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
72947 set_fs(oldfs);
72948
72949 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
72950 mm_segment_t old_fs = get_fs();
72951
72952 set_fs(KERNEL_DS);
72953 - ret = sys_sigpending((old_sigset_t __user *) &s);
72954 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
72955 set_fs(old_fs);
72956 if (ret == 0)
72957 ret = put_user(s, set);
72958 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
72959 mm_segment_t old_fs = get_fs();
72960
72961 set_fs(KERNEL_DS);
72962 - ret = sys_old_getrlimit(resource, &r);
72963 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
72964 set_fs(old_fs);
72965
72966 if (!ret) {
72967 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
72968 mm_segment_t old_fs = get_fs();
72969
72970 set_fs(KERNEL_DS);
72971 - ret = sys_getrusage(who, (struct rusage __user *) &r);
72972 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
72973 set_fs(old_fs);
72974
72975 if (ret)
72976 @@ -552,8 +553,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
72977 set_fs (KERNEL_DS);
72978 ret = sys_wait4(pid,
72979 (stat_addr ?
72980 - (unsigned int __user *) &status : NULL),
72981 - options, (struct rusage __user *) &r);
72982 + (unsigned int __force_user *) &status : NULL),
72983 + options, (struct rusage __force_user *) &r);
72984 set_fs (old_fs);
72985
72986 if (ret > 0) {
72987 @@ -579,8 +580,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
72988 memset(&info, 0, sizeof(info));
72989
72990 set_fs(KERNEL_DS);
72991 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
72992 - uru ? (struct rusage __user *)&ru : NULL);
72993 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
72994 + uru ? (struct rusage __force_user *)&ru : NULL);
72995 set_fs(old_fs);
72996
72997 if ((ret < 0) || (info.si_signo == 0))
72998 @@ -714,8 +715,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
72999 oldfs = get_fs();
73000 set_fs(KERNEL_DS);
73001 err = sys_timer_settime(timer_id, flags,
73002 - (struct itimerspec __user *) &newts,
73003 - (struct itimerspec __user *) &oldts);
73004 + (struct itimerspec __force_user *) &newts,
73005 + (struct itimerspec __force_user *) &oldts);
73006 set_fs(oldfs);
73007 if (!err && old && put_compat_itimerspec(old, &oldts))
73008 return -EFAULT;
73009 @@ -732,7 +733,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
73010 oldfs = get_fs();
73011 set_fs(KERNEL_DS);
73012 err = sys_timer_gettime(timer_id,
73013 - (struct itimerspec __user *) &ts);
73014 + (struct itimerspec __force_user *) &ts);
73015 set_fs(oldfs);
73016 if (!err && put_compat_itimerspec(setting, &ts))
73017 return -EFAULT;
73018 @@ -751,7 +752,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
73019 oldfs = get_fs();
73020 set_fs(KERNEL_DS);
73021 err = sys_clock_settime(which_clock,
73022 - (struct timespec __user *) &ts);
73023 + (struct timespec __force_user *) &ts);
73024 set_fs(oldfs);
73025 return err;
73026 }
73027 @@ -766,7 +767,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
73028 oldfs = get_fs();
73029 set_fs(KERNEL_DS);
73030 err = sys_clock_gettime(which_clock,
73031 - (struct timespec __user *) &ts);
73032 + (struct timespec __force_user *) &ts);
73033 set_fs(oldfs);
73034 if (!err && put_compat_timespec(&ts, tp))
73035 return -EFAULT;
73036 @@ -786,7 +787,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
73037
73038 oldfs = get_fs();
73039 set_fs(KERNEL_DS);
73040 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
73041 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
73042 set_fs(oldfs);
73043
73044 err = compat_put_timex(utp, &txc);
73045 @@ -806,7 +807,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
73046 oldfs = get_fs();
73047 set_fs(KERNEL_DS);
73048 err = sys_clock_getres(which_clock,
73049 - (struct timespec __user *) &ts);
73050 + (struct timespec __force_user *) &ts);
73051 set_fs(oldfs);
73052 if (!err && tp && put_compat_timespec(&ts, tp))
73053 return -EFAULT;
73054 @@ -818,9 +819,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
73055 long err;
73056 mm_segment_t oldfs;
73057 struct timespec tu;
73058 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
73059 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
73060
73061 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
73062 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
73063 oldfs = get_fs();
73064 set_fs(KERNEL_DS);
73065 err = clock_nanosleep_restart(restart);
73066 @@ -852,8 +853,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
73067 oldfs = get_fs();
73068 set_fs(KERNEL_DS);
73069 err = sys_clock_nanosleep(which_clock, flags,
73070 - (struct timespec __user *) &in,
73071 - (struct timespec __user *) &out);
73072 + (struct timespec __force_user *) &in,
73073 + (struct timespec __force_user *) &out);
73074 set_fs(oldfs);
73075
73076 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
73077 diff --git a/kernel/configs.c b/kernel/configs.c
73078 index 42e8fa0..9e7406b 100644
73079 --- a/kernel/configs.c
73080 +++ b/kernel/configs.c
73081 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
73082 struct proc_dir_entry *entry;
73083
73084 /* create the current config file */
73085 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
73086 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
73087 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
73088 + &ikconfig_file_ops);
73089 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
73090 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
73091 + &ikconfig_file_ops);
73092 +#endif
73093 +#else
73094 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
73095 &ikconfig_file_ops);
73096 +#endif
73097 +
73098 if (!entry)
73099 return -ENOMEM;
73100
73101 diff --git a/kernel/cred.c b/kernel/cred.c
73102 index e0573a4..3874e41 100644
73103 --- a/kernel/cred.c
73104 +++ b/kernel/cred.c
73105 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
73106 validate_creds(cred);
73107 alter_cred_subscribers(cred, -1);
73108 put_cred(cred);
73109 +
73110 +#ifdef CONFIG_GRKERNSEC_SETXID
73111 + cred = (struct cred *) tsk->delayed_cred;
73112 + if (cred != NULL) {
73113 + tsk->delayed_cred = NULL;
73114 + validate_creds(cred);
73115 + alter_cred_subscribers(cred, -1);
73116 + put_cred(cred);
73117 + }
73118 +#endif
73119 }
73120
73121 /**
73122 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
73123 * Always returns 0 thus allowing this function to be tail-called at the end
73124 * of, say, sys_setgid().
73125 */
73126 -int commit_creds(struct cred *new)
73127 +static int __commit_creds(struct cred *new)
73128 {
73129 struct task_struct *task = current;
73130 const struct cred *old = task->real_cred;
73131 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
73132
73133 get_cred(new); /* we will require a ref for the subj creds too */
73134
73135 + gr_set_role_label(task, new->uid, new->gid);
73136 +
73137 /* dumpability changes */
73138 if (!uid_eq(old->euid, new->euid) ||
73139 !gid_eq(old->egid, new->egid) ||
73140 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
73141 put_cred(old);
73142 return 0;
73143 }
73144 +#ifdef CONFIG_GRKERNSEC_SETXID
73145 +extern int set_user(struct cred *new);
73146 +
73147 +void gr_delayed_cred_worker(void)
73148 +{
73149 + const struct cred *new = current->delayed_cred;
73150 + struct cred *ncred;
73151 +
73152 + current->delayed_cred = NULL;
73153 +
73154 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
73155 + // from doing get_cred on it when queueing this
73156 + put_cred(new);
73157 + return;
73158 + } else if (new == NULL)
73159 + return;
73160 +
73161 + ncred = prepare_creds();
73162 + if (!ncred)
73163 + goto die;
73164 + // uids
73165 + ncred->uid = new->uid;
73166 + ncred->euid = new->euid;
73167 + ncred->suid = new->suid;
73168 + ncred->fsuid = new->fsuid;
73169 + // gids
73170 + ncred->gid = new->gid;
73171 + ncred->egid = new->egid;
73172 + ncred->sgid = new->sgid;
73173 + ncred->fsgid = new->fsgid;
73174 + // groups
73175 + if (set_groups(ncred, new->group_info) < 0) {
73176 + abort_creds(ncred);
73177 + goto die;
73178 + }
73179 + // caps
73180 + ncred->securebits = new->securebits;
73181 + ncred->cap_inheritable = new->cap_inheritable;
73182 + ncred->cap_permitted = new->cap_permitted;
73183 + ncred->cap_effective = new->cap_effective;
73184 + ncred->cap_bset = new->cap_bset;
73185 +
73186 + if (set_user(ncred)) {
73187 + abort_creds(ncred);
73188 + goto die;
73189 + }
73190 +
73191 + // from doing get_cred on it when queueing this
73192 + put_cred(new);
73193 +
73194 + __commit_creds(ncred);
73195 + return;
73196 +die:
73197 + // from doing get_cred on it when queueing this
73198 + put_cred(new);
73199 + do_group_exit(SIGKILL);
73200 +}
73201 +#endif
73202 +
73203 +int commit_creds(struct cred *new)
73204 +{
73205 +#ifdef CONFIG_GRKERNSEC_SETXID
73206 + int ret;
73207 + int schedule_it = 0;
73208 + struct task_struct *t;
73209 +
73210 + /* we won't get called with tasklist_lock held for writing
73211 + and interrupts disabled as the cred struct in that case is
73212 + init_cred
73213 + */
73214 + if (grsec_enable_setxid && !current_is_single_threaded() &&
73215 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
73216 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
73217 + schedule_it = 1;
73218 + }
73219 + ret = __commit_creds(new);
73220 + if (schedule_it) {
73221 + rcu_read_lock();
73222 + read_lock(&tasklist_lock);
73223 + for (t = next_thread(current); t != current;
73224 + t = next_thread(t)) {
73225 + if (t->delayed_cred == NULL) {
73226 + t->delayed_cred = get_cred(new);
73227 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
73228 + set_tsk_need_resched(t);
73229 + }
73230 + }
73231 + read_unlock(&tasklist_lock);
73232 + rcu_read_unlock();
73233 + }
73234 + return ret;
73235 +#else
73236 + return __commit_creds(new);
73237 +#endif
73238 +}
73239 +
73240 EXPORT_SYMBOL(commit_creds);
73241
73242 /**
73243 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
73244 index 9a61738..c5c8f3a 100644
73245 --- a/kernel/debug/debug_core.c
73246 +++ b/kernel/debug/debug_core.c
73247 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
73248 */
73249 static atomic_t masters_in_kgdb;
73250 static atomic_t slaves_in_kgdb;
73251 -static atomic_t kgdb_break_tasklet_var;
73252 +static atomic_unchecked_t kgdb_break_tasklet_var;
73253 atomic_t kgdb_setting_breakpoint;
73254
73255 struct task_struct *kgdb_usethread;
73256 @@ -132,7 +132,7 @@ int kgdb_single_step;
73257 static pid_t kgdb_sstep_pid;
73258
73259 /* to keep track of the CPU which is doing the single stepping*/
73260 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73261 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
73262
73263 /*
73264 * If you are debugging a problem where roundup (the collection of
73265 @@ -540,7 +540,7 @@ return_normal:
73266 * kernel will only try for the value of sstep_tries before
73267 * giving up and continuing on.
73268 */
73269 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
73270 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
73271 (kgdb_info[cpu].task &&
73272 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
73273 atomic_set(&kgdb_active, -1);
73274 @@ -634,8 +634,8 @@ cpu_master_loop:
73275 }
73276
73277 kgdb_restore:
73278 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
73279 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
73280 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
73281 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
73282 if (kgdb_info[sstep_cpu].task)
73283 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
73284 else
73285 @@ -887,18 +887,18 @@ static void kgdb_unregister_callbacks(void)
73286 static void kgdb_tasklet_bpt(unsigned long ing)
73287 {
73288 kgdb_breakpoint();
73289 - atomic_set(&kgdb_break_tasklet_var, 0);
73290 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
73291 }
73292
73293 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
73294
73295 void kgdb_schedule_breakpoint(void)
73296 {
73297 - if (atomic_read(&kgdb_break_tasklet_var) ||
73298 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
73299 atomic_read(&kgdb_active) != -1 ||
73300 atomic_read(&kgdb_setting_breakpoint))
73301 return;
73302 - atomic_inc(&kgdb_break_tasklet_var);
73303 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
73304 tasklet_schedule(&kgdb_tasklet_breakpoint);
73305 }
73306 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
73307 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
73308 index 8875254..7cf4928 100644
73309 --- a/kernel/debug/kdb/kdb_main.c
73310 +++ b/kernel/debug/kdb/kdb_main.c
73311 @@ -1974,7 +1974,7 @@ static int kdb_lsmod(int argc, const char **argv)
73312 continue;
73313
73314 kdb_printf("%-20s%8u 0x%p ", mod->name,
73315 - mod->core_size, (void *)mod);
73316 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
73317 #ifdef CONFIG_MODULE_UNLOAD
73318 kdb_printf("%4ld ", module_refcount(mod));
73319 #endif
73320 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
73321 kdb_printf(" (Loading)");
73322 else
73323 kdb_printf(" (Live)");
73324 - kdb_printf(" 0x%p", mod->module_core);
73325 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
73326
73327 #ifdef CONFIG_MODULE_UNLOAD
73328 {
73329 diff --git a/kernel/events/core.c b/kernel/events/core.c
73330 index 7b6646a..3cb1135 100644
73331 --- a/kernel/events/core.c
73332 +++ b/kernel/events/core.c
73333 @@ -182,7 +182,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
73334 return 0;
73335 }
73336
73337 -static atomic64_t perf_event_id;
73338 +static atomic64_unchecked_t perf_event_id;
73339
73340 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
73341 enum event_type_t event_type);
73342 @@ -2677,7 +2677,7 @@ static void __perf_event_read(void *info)
73343
73344 static inline u64 perf_event_count(struct perf_event *event)
73345 {
73346 - return local64_read(&event->count) + atomic64_read(&event->child_count);
73347 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
73348 }
73349
73350 static u64 perf_event_read(struct perf_event *event)
73351 @@ -3007,9 +3007,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
73352 mutex_lock(&event->child_mutex);
73353 total += perf_event_read(event);
73354 *enabled += event->total_time_enabled +
73355 - atomic64_read(&event->child_total_time_enabled);
73356 + atomic64_read_unchecked(&event->child_total_time_enabled);
73357 *running += event->total_time_running +
73358 - atomic64_read(&event->child_total_time_running);
73359 + atomic64_read_unchecked(&event->child_total_time_running);
73360
73361 list_for_each_entry(child, &event->child_list, child_list) {
73362 total += perf_event_read(child);
73363 @@ -3412,10 +3412,10 @@ void perf_event_update_userpage(struct perf_event *event)
73364 userpg->offset -= local64_read(&event->hw.prev_count);
73365
73366 userpg->time_enabled = enabled +
73367 - atomic64_read(&event->child_total_time_enabled);
73368 + atomic64_read_unchecked(&event->child_total_time_enabled);
73369
73370 userpg->time_running = running +
73371 - atomic64_read(&event->child_total_time_running);
73372 + atomic64_read_unchecked(&event->child_total_time_running);
73373
73374 arch_perf_update_userpage(userpg, now);
73375
73376 @@ -3974,11 +3974,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
73377 values[n++] = perf_event_count(event);
73378 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
73379 values[n++] = enabled +
73380 - atomic64_read(&event->child_total_time_enabled);
73381 + atomic64_read_unchecked(&event->child_total_time_enabled);
73382 }
73383 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
73384 values[n++] = running +
73385 - atomic64_read(&event->child_total_time_running);
73386 + atomic64_read_unchecked(&event->child_total_time_running);
73387 }
73388 if (read_format & PERF_FORMAT_ID)
73389 values[n++] = primary_event_id(event);
73390 @@ -4721,12 +4721,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
73391 * need to add enough zero bytes after the string to handle
73392 * the 64bit alignment we do later.
73393 */
73394 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
73395 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
73396 if (!buf) {
73397 name = strncpy(tmp, "//enomem", sizeof(tmp));
73398 goto got_name;
73399 }
73400 - name = d_path(&file->f_path, buf, PATH_MAX);
73401 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
73402 if (IS_ERR(name)) {
73403 name = strncpy(tmp, "//toolong", sizeof(tmp));
73404 goto got_name;
73405 @@ -6165,7 +6165,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
73406 event->parent = parent_event;
73407
73408 event->ns = get_pid_ns(task_active_pid_ns(current));
73409 - event->id = atomic64_inc_return(&perf_event_id);
73410 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
73411
73412 event->state = PERF_EVENT_STATE_INACTIVE;
73413
73414 @@ -6790,10 +6790,10 @@ static void sync_child_event(struct perf_event *child_event,
73415 /*
73416 * Add back the child's count to the parent's count:
73417 */
73418 - atomic64_add(child_val, &parent_event->child_count);
73419 - atomic64_add(child_event->total_time_enabled,
73420 + atomic64_add_unchecked(child_val, &parent_event->child_count);
73421 + atomic64_add_unchecked(child_event->total_time_enabled,
73422 &parent_event->child_total_time_enabled);
73423 - atomic64_add(child_event->total_time_running,
73424 + atomic64_add_unchecked(child_event->total_time_running,
73425 &parent_event->child_total_time_running);
73426
73427 /*
73428 diff --git a/kernel/exit.c b/kernel/exit.c
73429 index b4df219..f13c02d 100644
73430 --- a/kernel/exit.c
73431 +++ b/kernel/exit.c
73432 @@ -170,6 +170,10 @@ void release_task(struct task_struct * p)
73433 struct task_struct *leader;
73434 int zap_leader;
73435 repeat:
73436 +#ifdef CONFIG_NET
73437 + gr_del_task_from_ip_table(p);
73438 +#endif
73439 +
73440 /* don't need to get the RCU readlock here - the process is dead and
73441 * can't be modifying its own credentials. But shut RCU-lockdep up */
73442 rcu_read_lock();
73443 @@ -338,7 +342,7 @@ int allow_signal(int sig)
73444 * know it'll be handled, so that they don't get converted to
73445 * SIGKILL or just silently dropped.
73446 */
73447 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
73448 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
73449 recalc_sigpending();
73450 spin_unlock_irq(&current->sighand->siglock);
73451 return 0;
73452 @@ -708,6 +712,8 @@ void do_exit(long code)
73453 struct task_struct *tsk = current;
73454 int group_dead;
73455
73456 + set_fs(USER_DS);
73457 +
73458 profile_task_exit(tsk);
73459
73460 WARN_ON(blk_needs_flush_plug(tsk));
73461 @@ -724,7 +730,6 @@ void do_exit(long code)
73462 * mm_release()->clear_child_tid() from writing to a user-controlled
73463 * kernel address.
73464 */
73465 - set_fs(USER_DS);
73466
73467 ptrace_event(PTRACE_EVENT_EXIT, code);
73468
73469 @@ -783,6 +788,9 @@ void do_exit(long code)
73470 tsk->exit_code = code;
73471 taskstats_exit(tsk, group_dead);
73472
73473 + gr_acl_handle_psacct(tsk, code);
73474 + gr_acl_handle_exit();
73475 +
73476 exit_mm(tsk);
73477
73478 if (group_dead)
73479 @@ -903,7 +911,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
73480 * Take down every thread in the group. This is called by fatal signals
73481 * as well as by sys_exit_group (below).
73482 */
73483 -void
73484 +__noreturn void
73485 do_group_exit(int exit_code)
73486 {
73487 struct signal_struct *sig = current->signal;
73488 diff --git a/kernel/fork.c b/kernel/fork.c
73489 index c535f33..1d768f9 100644
73490 --- a/kernel/fork.c
73491 +++ b/kernel/fork.c
73492 @@ -318,7 +318,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
73493 *stackend = STACK_END_MAGIC; /* for overflow detection */
73494
73495 #ifdef CONFIG_CC_STACKPROTECTOR
73496 - tsk->stack_canary = get_random_int();
73497 + tsk->stack_canary = pax_get_random_long();
73498 #endif
73499
73500 /*
73501 @@ -344,13 +344,81 @@ free_tsk:
73502 }
73503
73504 #ifdef CONFIG_MMU
73505 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
73506 +{
73507 + struct vm_area_struct *tmp;
73508 + unsigned long charge;
73509 + struct mempolicy *pol;
73510 + struct file *file;
73511 +
73512 + charge = 0;
73513 + if (mpnt->vm_flags & VM_ACCOUNT) {
73514 + unsigned long len = vma_pages(mpnt);
73515 +
73516 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
73517 + goto fail_nomem;
73518 + charge = len;
73519 + }
73520 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73521 + if (!tmp)
73522 + goto fail_nomem;
73523 + *tmp = *mpnt;
73524 + tmp->vm_mm = mm;
73525 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
73526 + pol = mpol_dup(vma_policy(mpnt));
73527 + if (IS_ERR(pol))
73528 + goto fail_nomem_policy;
73529 + vma_set_policy(tmp, pol);
73530 + if (anon_vma_fork(tmp, mpnt))
73531 + goto fail_nomem_anon_vma_fork;
73532 + tmp->vm_flags &= ~VM_LOCKED;
73533 + tmp->vm_next = tmp->vm_prev = NULL;
73534 + tmp->vm_mirror = NULL;
73535 + file = tmp->vm_file;
73536 + if (file) {
73537 + struct inode *inode = file->f_path.dentry->d_inode;
73538 + struct address_space *mapping = file->f_mapping;
73539 +
73540 + get_file(file);
73541 + if (tmp->vm_flags & VM_DENYWRITE)
73542 + atomic_dec(&inode->i_writecount);
73543 + mutex_lock(&mapping->i_mmap_mutex);
73544 + if (tmp->vm_flags & VM_SHARED)
73545 + mapping->i_mmap_writable++;
73546 + flush_dcache_mmap_lock(mapping);
73547 + /* insert tmp into the share list, just after mpnt */
73548 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
73549 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
73550 + else
73551 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
73552 + flush_dcache_mmap_unlock(mapping);
73553 + mutex_unlock(&mapping->i_mmap_mutex);
73554 + }
73555 +
73556 + /*
73557 + * Clear hugetlb-related page reserves for children. This only
73558 + * affects MAP_PRIVATE mappings. Faults generated by the child
73559 + * are not guaranteed to succeed, even if read-only
73560 + */
73561 + if (is_vm_hugetlb_page(tmp))
73562 + reset_vma_resv_huge_pages(tmp);
73563 +
73564 + return tmp;
73565 +
73566 +fail_nomem_anon_vma_fork:
73567 + mpol_put(pol);
73568 +fail_nomem_policy:
73569 + kmem_cache_free(vm_area_cachep, tmp);
73570 +fail_nomem:
73571 + vm_unacct_memory(charge);
73572 + return NULL;
73573 +}
73574 +
73575 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73576 {
73577 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
73578 struct rb_node **rb_link, *rb_parent;
73579 int retval;
73580 - unsigned long charge;
73581 - struct mempolicy *pol;
73582
73583 uprobe_start_dup_mmap();
73584 down_write(&oldmm->mmap_sem);
73585 @@ -364,8 +432,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73586 mm->locked_vm = 0;
73587 mm->mmap = NULL;
73588 mm->mmap_cache = NULL;
73589 - mm->free_area_cache = oldmm->mmap_base;
73590 - mm->cached_hole_size = ~0UL;
73591 + mm->free_area_cache = oldmm->free_area_cache;
73592 + mm->cached_hole_size = oldmm->cached_hole_size;
73593 mm->map_count = 0;
73594 cpumask_clear(mm_cpumask(mm));
73595 mm->mm_rb = RB_ROOT;
73596 @@ -381,57 +449,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73597
73598 prev = NULL;
73599 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
73600 - struct file *file;
73601 -
73602 if (mpnt->vm_flags & VM_DONTCOPY) {
73603 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
73604 -vma_pages(mpnt));
73605 continue;
73606 }
73607 - charge = 0;
73608 - if (mpnt->vm_flags & VM_ACCOUNT) {
73609 - unsigned long len = vma_pages(mpnt);
73610 -
73611 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
73612 - goto fail_nomem;
73613 - charge = len;
73614 - }
73615 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73616 - if (!tmp)
73617 - goto fail_nomem;
73618 - *tmp = *mpnt;
73619 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
73620 - pol = mpol_dup(vma_policy(mpnt));
73621 - retval = PTR_ERR(pol);
73622 - if (IS_ERR(pol))
73623 - goto fail_nomem_policy;
73624 - vma_set_policy(tmp, pol);
73625 - tmp->vm_mm = mm;
73626 - if (anon_vma_fork(tmp, mpnt))
73627 - goto fail_nomem_anon_vma_fork;
73628 - tmp->vm_flags &= ~VM_LOCKED;
73629 - tmp->vm_next = tmp->vm_prev = NULL;
73630 - file = tmp->vm_file;
73631 - if (file) {
73632 - struct inode *inode = file->f_path.dentry->d_inode;
73633 - struct address_space *mapping = file->f_mapping;
73634 -
73635 - get_file(file);
73636 - if (tmp->vm_flags & VM_DENYWRITE)
73637 - atomic_dec(&inode->i_writecount);
73638 - mutex_lock(&mapping->i_mmap_mutex);
73639 - if (tmp->vm_flags & VM_SHARED)
73640 - mapping->i_mmap_writable++;
73641 - flush_dcache_mmap_lock(mapping);
73642 - /* insert tmp into the share list, just after mpnt */
73643 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
73644 - vma_nonlinear_insert(tmp,
73645 - &mapping->i_mmap_nonlinear);
73646 - else
73647 - vma_interval_tree_insert_after(tmp, mpnt,
73648 - &mapping->i_mmap);
73649 - flush_dcache_mmap_unlock(mapping);
73650 - mutex_unlock(&mapping->i_mmap_mutex);
73651 + tmp = dup_vma(mm, oldmm, mpnt);
73652 + if (!tmp) {
73653 + retval = -ENOMEM;
73654 + goto out;
73655 }
73656
73657 /*
73658 @@ -463,6 +489,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
73659 if (retval)
73660 goto out;
73661 }
73662 +
73663 +#ifdef CONFIG_PAX_SEGMEXEC
73664 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
73665 + struct vm_area_struct *mpnt_m;
73666 +
73667 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
73668 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
73669 +
73670 + if (!mpnt->vm_mirror)
73671 + continue;
73672 +
73673 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
73674 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
73675 + mpnt->vm_mirror = mpnt_m;
73676 + } else {
73677 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
73678 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
73679 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
73680 + mpnt->vm_mirror->vm_mirror = mpnt;
73681 + }
73682 + }
73683 + BUG_ON(mpnt_m);
73684 + }
73685 +#endif
73686 +
73687 /* a new mm has just been created */
73688 arch_dup_mmap(oldmm, mm);
73689 retval = 0;
73690 @@ -472,14 +523,6 @@ out:
73691 up_write(&oldmm->mmap_sem);
73692 uprobe_end_dup_mmap();
73693 return retval;
73694 -fail_nomem_anon_vma_fork:
73695 - mpol_put(pol);
73696 -fail_nomem_policy:
73697 - kmem_cache_free(vm_area_cachep, tmp);
73698 -fail_nomem:
73699 - retval = -ENOMEM;
73700 - vm_unacct_memory(charge);
73701 - goto out;
73702 }
73703
73704 static inline int mm_alloc_pgd(struct mm_struct *mm)
73705 @@ -694,8 +737,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
73706 return ERR_PTR(err);
73707
73708 mm = get_task_mm(task);
73709 - if (mm && mm != current->mm &&
73710 - !ptrace_may_access(task, mode)) {
73711 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
73712 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
73713 mmput(mm);
73714 mm = ERR_PTR(-EACCES);
73715 }
73716 @@ -917,13 +960,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
73717 spin_unlock(&fs->lock);
73718 return -EAGAIN;
73719 }
73720 - fs->users++;
73721 + atomic_inc(&fs->users);
73722 spin_unlock(&fs->lock);
73723 return 0;
73724 }
73725 tsk->fs = copy_fs_struct(fs);
73726 if (!tsk->fs)
73727 return -ENOMEM;
73728 + /* Carry through gr_chroot_dentry and is_chrooted instead
73729 + of recomputing it here. Already copied when the task struct
73730 + is duplicated. This allows pivot_root to not be treated as
73731 + a chroot
73732 + */
73733 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
73734 +
73735 return 0;
73736 }
73737
73738 @@ -1193,6 +1243,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
73739 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
73740 #endif
73741 retval = -EAGAIN;
73742 +
73743 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
73744 +
73745 if (atomic_read(&p->real_cred->user->processes) >=
73746 task_rlimit(p, RLIMIT_NPROC)) {
73747 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
73748 @@ -1432,6 +1485,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
73749 goto bad_fork_free_pid;
73750 }
73751
73752 + /* synchronizes with gr_set_acls()
73753 + we need to call this past the point of no return for fork()
73754 + */
73755 + gr_copy_label(p);
73756 +
73757 if (clone_flags & CLONE_THREAD) {
73758 current->signal->nr_threads++;
73759 atomic_inc(&current->signal->live);
73760 @@ -1515,6 +1573,8 @@ bad_fork_cleanup_count:
73761 bad_fork_free:
73762 free_task(p);
73763 fork_out:
73764 + gr_log_forkfail(retval);
73765 +
73766 return ERR_PTR(retval);
73767 }
73768
73769 @@ -1565,6 +1625,23 @@ long do_fork(unsigned long clone_flags,
73770 return -EINVAL;
73771 }
73772
73773 +#ifdef CONFIG_GRKERNSEC
73774 + if (clone_flags & CLONE_NEWUSER) {
73775 + /*
73776 + * This doesn't really inspire confidence:
73777 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
73778 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
73779 + * Increases kernel attack surface in areas developers
73780 + * previously cared little about ("low importance due
73781 + * to requiring "root" capability")
73782 + * To be removed when this code receives *proper* review
73783 + */
73784 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
73785 + !capable(CAP_SETGID))
73786 + return -EPERM;
73787 + }
73788 +#endif
73789 +
73790 /*
73791 * Determine whether and which event to report to ptracer. When
73792 * called from kernel_thread or CLONE_UNTRACED is explicitly
73793 @@ -1599,6 +1676,8 @@ long do_fork(unsigned long clone_flags,
73794 if (clone_flags & CLONE_PARENT_SETTID)
73795 put_user(nr, parent_tidptr);
73796
73797 + gr_handle_brute_check();
73798 +
73799 if (clone_flags & CLONE_VFORK) {
73800 p->vfork_done = &vfork;
73801 init_completion(&vfork);
73802 @@ -1752,7 +1831,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
73803 return 0;
73804
73805 /* don't need lock here; in the worst case we'll do useless copy */
73806 - if (fs->users == 1)
73807 + if (atomic_read(&fs->users) == 1)
73808 return 0;
73809
73810 *new_fsp = copy_fs_struct(fs);
73811 @@ -1866,7 +1945,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
73812 fs = current->fs;
73813 spin_lock(&fs->lock);
73814 current->fs = new_fs;
73815 - if (--fs->users)
73816 + gr_set_chroot_entries(current, &current->fs->root);
73817 + if (atomic_dec_return(&fs->users))
73818 new_fs = NULL;
73819 else
73820 new_fs = fs;
73821 diff --git a/kernel/futex.c b/kernel/futex.c
73822 index 8879430..31696f1 100644
73823 --- a/kernel/futex.c
73824 +++ b/kernel/futex.c
73825 @@ -54,6 +54,7 @@
73826 #include <linux/mount.h>
73827 #include <linux/pagemap.h>
73828 #include <linux/syscalls.h>
73829 +#include <linux/ptrace.h>
73830 #include <linux/signal.h>
73831 #include <linux/export.h>
73832 #include <linux/magic.h>
73833 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
73834 struct page *page, *page_head;
73835 int err, ro = 0;
73836
73837 +#ifdef CONFIG_PAX_SEGMEXEC
73838 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
73839 + return -EFAULT;
73840 +#endif
73841 +
73842 /*
73843 * The futex address must be "naturally" aligned.
73844 */
73845 @@ -2731,6 +2737,7 @@ static int __init futex_init(void)
73846 {
73847 u32 curval;
73848 int i;
73849 + mm_segment_t oldfs;
73850
73851 /*
73852 * This will fail and we want it. Some arch implementations do
73853 @@ -2742,8 +2749,11 @@ static int __init futex_init(void)
73854 * implementation, the non-functional ones will return
73855 * -ENOSYS.
73856 */
73857 + oldfs = get_fs();
73858 + set_fs(USER_DS);
73859 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
73860 futex_cmpxchg_enabled = 1;
73861 + set_fs(oldfs);
73862
73863 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
73864 plist_head_init(&futex_queues[i].chain);
73865 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
73866 index 9b22d03..6295b62 100644
73867 --- a/kernel/gcov/base.c
73868 +++ b/kernel/gcov/base.c
73869 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
73870 }
73871
73872 #ifdef CONFIG_MODULES
73873 -static inline int within(void *addr, void *start, unsigned long size)
73874 -{
73875 - return ((addr >= start) && (addr < start + size));
73876 -}
73877 -
73878 /* Update list and generate events when modules are unloaded. */
73879 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
73880 void *data)
73881 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
73882 prev = NULL;
73883 /* Remove entries located in module from linked list. */
73884 for (info = gcov_info_head; info; info = info->next) {
73885 - if (within(info, mod->module_core, mod->core_size)) {
73886 + if (within_module_core_rw((unsigned long)info, mod)) {
73887 if (prev)
73888 prev->next = info->next;
73889 else
73890 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
73891 index cdd5607..c3fc919 100644
73892 --- a/kernel/hrtimer.c
73893 +++ b/kernel/hrtimer.c
73894 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
73895 local_irq_restore(flags);
73896 }
73897
73898 -static void run_hrtimer_softirq(struct softirq_action *h)
73899 +static void run_hrtimer_softirq(void)
73900 {
73901 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
73902
73903 @@ -1751,7 +1751,7 @@ static int __cpuinit hrtimer_cpu_notify(struct notifier_block *self,
73904 return NOTIFY_OK;
73905 }
73906
73907 -static struct notifier_block __cpuinitdata hrtimers_nb = {
73908 +static struct notifier_block hrtimers_nb = {
73909 .notifier_call = hrtimer_cpu_notify,
73910 };
73911
73912 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
73913 index 60f48fa..7f3a770 100644
73914 --- a/kernel/jump_label.c
73915 +++ b/kernel/jump_label.c
73916 @@ -13,6 +13,7 @@
73917 #include <linux/sort.h>
73918 #include <linux/err.h>
73919 #include <linux/static_key.h>
73920 +#include <linux/mm.h>
73921
73922 #ifdef HAVE_JUMP_LABEL
73923
73924 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
73925
73926 size = (((unsigned long)stop - (unsigned long)start)
73927 / sizeof(struct jump_entry));
73928 + pax_open_kernel();
73929 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
73930 + pax_close_kernel();
73931 }
73932
73933 static void jump_label_update(struct static_key *key, int enable);
73934 @@ -357,10 +360,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
73935 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
73936 struct jump_entry *iter;
73937
73938 + pax_open_kernel();
73939 for (iter = iter_start; iter < iter_stop; iter++) {
73940 if (within_module_init(iter->code, mod))
73941 iter->code = 0;
73942 }
73943 + pax_close_kernel();
73944 }
73945
73946 static int
73947 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
73948 index 2169fee..706ccca 100644
73949 --- a/kernel/kallsyms.c
73950 +++ b/kernel/kallsyms.c
73951 @@ -11,6 +11,9 @@
73952 * Changed the compression method from stem compression to "table lookup"
73953 * compression (see scripts/kallsyms.c for a more complete description)
73954 */
73955 +#ifdef CONFIG_GRKERNSEC_HIDESYM
73956 +#define __INCLUDED_BY_HIDESYM 1
73957 +#endif
73958 #include <linux/kallsyms.h>
73959 #include <linux/module.h>
73960 #include <linux/init.h>
73961 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
73962
73963 static inline int is_kernel_inittext(unsigned long addr)
73964 {
73965 + if (system_state != SYSTEM_BOOTING)
73966 + return 0;
73967 +
73968 if (addr >= (unsigned long)_sinittext
73969 && addr <= (unsigned long)_einittext)
73970 return 1;
73971 return 0;
73972 }
73973
73974 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
73975 +#ifdef CONFIG_MODULES
73976 +static inline int is_module_text(unsigned long addr)
73977 +{
73978 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
73979 + return 1;
73980 +
73981 + addr = ktla_ktva(addr);
73982 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
73983 +}
73984 +#else
73985 +static inline int is_module_text(unsigned long addr)
73986 +{
73987 + return 0;
73988 +}
73989 +#endif
73990 +#endif
73991 +
73992 static inline int is_kernel_text(unsigned long addr)
73993 {
73994 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
73995 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
73996
73997 static inline int is_kernel(unsigned long addr)
73998 {
73999 +
74000 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74001 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
74002 + return 1;
74003 +
74004 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
74005 +#else
74006 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
74007 +#endif
74008 +
74009 return 1;
74010 return in_gate_area_no_mm(addr);
74011 }
74012
74013 static int is_ksym_addr(unsigned long addr)
74014 {
74015 +
74016 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
74017 + if (is_module_text(addr))
74018 + return 0;
74019 +#endif
74020 +
74021 if (all_var)
74022 return is_kernel(addr);
74023
74024 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
74025
74026 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
74027 {
74028 - iter->name[0] = '\0';
74029 iter->nameoff = get_symbol_offset(new_pos);
74030 iter->pos = new_pos;
74031 }
74032 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
74033 {
74034 struct kallsym_iter *iter = m->private;
74035
74036 +#ifdef CONFIG_GRKERNSEC_HIDESYM
74037 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
74038 + return 0;
74039 +#endif
74040 +
74041 /* Some debugging symbols have no name. Ignore them. */
74042 if (!iter->name[0])
74043 return 0;
74044 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
74045 */
74046 type = iter->exported ? toupper(iter->type) :
74047 tolower(iter->type);
74048 +
74049 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
74050 type, iter->name, iter->module_name);
74051 } else
74052 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
74053 struct kallsym_iter *iter;
74054 int ret;
74055
74056 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
74057 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
74058 if (!iter)
74059 return -ENOMEM;
74060 reset_iter(iter, 0);
74061 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
74062 index e30ac0f..3528cac 100644
74063 --- a/kernel/kcmp.c
74064 +++ b/kernel/kcmp.c
74065 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
74066 struct task_struct *task1, *task2;
74067 int ret;
74068
74069 +#ifdef CONFIG_GRKERNSEC
74070 + return -ENOSYS;
74071 +#endif
74072 +
74073 rcu_read_lock();
74074
74075 /*
74076 diff --git a/kernel/kexec.c b/kernel/kexec.c
74077 index 5e4bd78..00c5b91 100644
74078 --- a/kernel/kexec.c
74079 +++ b/kernel/kexec.c
74080 @@ -1045,7 +1045,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
74081 unsigned long flags)
74082 {
74083 struct compat_kexec_segment in;
74084 - struct kexec_segment out, __user *ksegments;
74085 + struct kexec_segment out;
74086 + struct kexec_segment __user *ksegments;
74087 unsigned long i, result;
74088
74089 /* Don't allow clients that don't understand the native
74090 diff --git a/kernel/kmod.c b/kernel/kmod.c
74091 index 0023a87..9c0c068 100644
74092 --- a/kernel/kmod.c
74093 +++ b/kernel/kmod.c
74094 @@ -74,7 +74,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
74095 kfree(info->argv);
74096 }
74097
74098 -static int call_modprobe(char *module_name, int wait)
74099 +static int call_modprobe(char *module_name, char *module_param, int wait)
74100 {
74101 static char *envp[] = {
74102 "HOME=/",
74103 @@ -83,7 +83,7 @@ static int call_modprobe(char *module_name, int wait)
74104 NULL
74105 };
74106
74107 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
74108 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
74109 if (!argv)
74110 goto out;
74111
74112 @@ -95,7 +95,8 @@ static int call_modprobe(char *module_name, int wait)
74113 argv[1] = "-q";
74114 argv[2] = "--";
74115 argv[3] = module_name; /* check free_modprobe_argv() */
74116 - argv[4] = NULL;
74117 + argv[4] = module_param;
74118 + argv[5] = NULL;
74119
74120 return call_usermodehelper_fns(modprobe_path, argv, envp,
74121 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
74122 @@ -120,9 +121,8 @@ out:
74123 * If module auto-loading support is disabled then this function
74124 * becomes a no-operation.
74125 */
74126 -int __request_module(bool wait, const char *fmt, ...)
74127 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
74128 {
74129 - va_list args;
74130 char module_name[MODULE_NAME_LEN];
74131 unsigned int max_modprobes;
74132 int ret;
74133 @@ -130,9 +130,7 @@ int __request_module(bool wait, const char *fmt, ...)
74134 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
74135 static int kmod_loop_msg;
74136
74137 - va_start(args, fmt);
74138 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
74139 - va_end(args);
74140 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
74141 if (ret >= MODULE_NAME_LEN)
74142 return -ENAMETOOLONG;
74143
74144 @@ -140,6 +138,20 @@ int __request_module(bool wait, const char *fmt, ...)
74145 if (ret)
74146 return ret;
74147
74148 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74149 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74150 + /* hack to workaround consolekit/udisks stupidity */
74151 + read_lock(&tasklist_lock);
74152 + if (!strcmp(current->comm, "mount") &&
74153 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
74154 + read_unlock(&tasklist_lock);
74155 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
74156 + return -EPERM;
74157 + }
74158 + read_unlock(&tasklist_lock);
74159 + }
74160 +#endif
74161 +
74162 /* If modprobe needs a service that is in a module, we get a recursive
74163 * loop. Limit the number of running kmod threads to max_threads/2 or
74164 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
74165 @@ -168,11 +180,52 @@ int __request_module(bool wait, const char *fmt, ...)
74166
74167 trace_module_request(module_name, wait, _RET_IP_);
74168
74169 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74170 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
74171
74172 atomic_dec(&kmod_concurrent);
74173 return ret;
74174 }
74175 +
74176 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
74177 +{
74178 + va_list args;
74179 + int ret;
74180 +
74181 + va_start(args, fmt);
74182 + ret = ____request_module(wait, module_param, fmt, args);
74183 + va_end(args);
74184 +
74185 + return ret;
74186 +}
74187 +
74188 +int __request_module(bool wait, const char *fmt, ...)
74189 +{
74190 + va_list args;
74191 + int ret;
74192 +
74193 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74194 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
74195 + char module_param[MODULE_NAME_LEN];
74196 +
74197 + memset(module_param, 0, sizeof(module_param));
74198 +
74199 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
74200 +
74201 + va_start(args, fmt);
74202 + ret = ____request_module(wait, module_param, fmt, args);
74203 + va_end(args);
74204 +
74205 + return ret;
74206 + }
74207 +#endif
74208 +
74209 + va_start(args, fmt);
74210 + ret = ____request_module(wait, NULL, fmt, args);
74211 + va_end(args);
74212 +
74213 + return ret;
74214 +}
74215 +
74216 EXPORT_SYMBOL(__request_module);
74217 #endif /* CONFIG_MODULES */
74218
74219 @@ -283,7 +336,7 @@ static int wait_for_helper(void *data)
74220 *
74221 * Thus the __user pointer cast is valid here.
74222 */
74223 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
74224 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
74225
74226 /*
74227 * If ret is 0, either ____call_usermodehelper failed and the
74228 @@ -635,7 +688,7 @@ EXPORT_SYMBOL(call_usermodehelper_fns);
74229 static int proc_cap_handler(struct ctl_table *table, int write,
74230 void __user *buffer, size_t *lenp, loff_t *ppos)
74231 {
74232 - struct ctl_table t;
74233 + ctl_table_no_const t;
74234 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
74235 kernel_cap_t new_cap;
74236 int err, i;
74237 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
74238 index 098f396..fe85ff1 100644
74239 --- a/kernel/kprobes.c
74240 +++ b/kernel/kprobes.c
74241 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
74242 * kernel image and loaded module images reside. This is required
74243 * so x86_64 can correctly handle the %rip-relative fixups.
74244 */
74245 - kip->insns = module_alloc(PAGE_SIZE);
74246 + kip->insns = module_alloc_exec(PAGE_SIZE);
74247 if (!kip->insns) {
74248 kfree(kip);
74249 return NULL;
74250 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
74251 */
74252 if (!list_is_singular(&kip->list)) {
74253 list_del(&kip->list);
74254 - module_free(NULL, kip->insns);
74255 + module_free_exec(NULL, kip->insns);
74256 kfree(kip);
74257 }
74258 return 1;
74259 @@ -2063,7 +2063,7 @@ static int __init init_kprobes(void)
74260 {
74261 int i, err = 0;
74262 unsigned long offset = 0, size = 0;
74263 - char *modname, namebuf[128];
74264 + char *modname, namebuf[KSYM_NAME_LEN];
74265 const char *symbol_name;
74266 void *addr;
74267 struct kprobe_blackpoint *kb;
74268 @@ -2148,11 +2148,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
74269 kprobe_type = "k";
74270
74271 if (sym)
74272 - seq_printf(pi, "%p %s %s+0x%x %s ",
74273 + seq_printf(pi, "%pK %s %s+0x%x %s ",
74274 p->addr, kprobe_type, sym, offset,
74275 (modname ? modname : " "));
74276 else
74277 - seq_printf(pi, "%p %s %p ",
74278 + seq_printf(pi, "%pK %s %pK ",
74279 p->addr, kprobe_type, p->addr);
74280
74281 if (!pp)
74282 @@ -2190,7 +2190,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
74283 const char *sym = NULL;
74284 unsigned int i = *(loff_t *) v;
74285 unsigned long offset = 0;
74286 - char *modname, namebuf[128];
74287 + char *modname, namebuf[KSYM_NAME_LEN];
74288
74289 head = &kprobe_table[i];
74290 preempt_disable();
74291 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
74292 index 6ada93c..dce7d5d 100644
74293 --- a/kernel/ksysfs.c
74294 +++ b/kernel/ksysfs.c
74295 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
74296 {
74297 if (count+1 > UEVENT_HELPER_PATH_LEN)
74298 return -ENOENT;
74299 + if (!capable(CAP_SYS_ADMIN))
74300 + return -EPERM;
74301 memcpy(uevent_helper, buf, count);
74302 uevent_helper[count] = '\0';
74303 if (count && uevent_helper[count-1] == '\n')
74304 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
74305 return count;
74306 }
74307
74308 -static struct bin_attribute notes_attr = {
74309 +static bin_attribute_no_const notes_attr __read_only = {
74310 .attr = {
74311 .name = "notes",
74312 .mode = S_IRUGO,
74313 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
74314 index 7981e5b..7f2105c 100644
74315 --- a/kernel/lockdep.c
74316 +++ b/kernel/lockdep.c
74317 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
74318 end = (unsigned long) &_end,
74319 addr = (unsigned long) obj;
74320
74321 +#ifdef CONFIG_PAX_KERNEXEC
74322 + start = ktla_ktva(start);
74323 +#endif
74324 +
74325 /*
74326 * static variable?
74327 */
74328 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
74329 if (!static_obj(lock->key)) {
74330 debug_locks_off();
74331 printk("INFO: trying to register non-static key.\n");
74332 + printk("lock:%pS key:%pS.\n", lock, lock->key);
74333 printk("the code is fine but needs lockdep annotation.\n");
74334 printk("turning off the locking correctness validator.\n");
74335 dump_stack();
74336 @@ -3078,7 +3083,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
74337 if (!class)
74338 return 0;
74339 }
74340 - atomic_inc((atomic_t *)&class->ops);
74341 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
74342 if (very_verbose(class)) {
74343 printk("\nacquire class [%p] %s", class->key, class->name);
74344 if (class->name_version > 1)
74345 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
74346 index b2c71c5..7b88d63 100644
74347 --- a/kernel/lockdep_proc.c
74348 +++ b/kernel/lockdep_proc.c
74349 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
74350 return 0;
74351 }
74352
74353 - seq_printf(m, "%p", class->key);
74354 + seq_printf(m, "%pK", class->key);
74355 #ifdef CONFIG_DEBUG_LOCKDEP
74356 seq_printf(m, " OPS:%8ld", class->ops);
74357 #endif
74358 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
74359
74360 list_for_each_entry(entry, &class->locks_after, entry) {
74361 if (entry->distance == 1) {
74362 - seq_printf(m, " -> [%p] ", entry->class->key);
74363 + seq_printf(m, " -> [%pK] ", entry->class->key);
74364 print_name(m, entry->class);
74365 seq_puts(m, "\n");
74366 }
74367 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
74368 if (!class->key)
74369 continue;
74370
74371 - seq_printf(m, "[%p] ", class->key);
74372 + seq_printf(m, "[%pK] ", class->key);
74373 print_name(m, class);
74374 seq_puts(m, "\n");
74375 }
74376 @@ -495,7 +495,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74377 if (!i)
74378 seq_line(m, '-', 40-namelen, namelen);
74379
74380 - snprintf(ip, sizeof(ip), "[<%p>]",
74381 + snprintf(ip, sizeof(ip), "[<%pK>]",
74382 (void *)class->contention_point[i]);
74383 seq_printf(m, "%40s %14lu %29s %pS\n",
74384 name, stats->contention_point[i],
74385 @@ -510,7 +510,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
74386 if (!i)
74387 seq_line(m, '-', 40-namelen, namelen);
74388
74389 - snprintf(ip, sizeof(ip), "[<%p>]",
74390 + snprintf(ip, sizeof(ip), "[<%pK>]",
74391 (void *)class->contending_point[i]);
74392 seq_printf(m, "%40s %14lu %29s %pS\n",
74393 name, stats->contending_point[i],
74394 diff --git a/kernel/module.c b/kernel/module.c
74395 index eab0827..f488603 100644
74396 --- a/kernel/module.c
74397 +++ b/kernel/module.c
74398 @@ -61,6 +61,7 @@
74399 #include <linux/pfn.h>
74400 #include <linux/bsearch.h>
74401 #include <linux/fips.h>
74402 +#include <linux/grsecurity.h>
74403 #include <uapi/linux/module.h>
74404 #include "module-internal.h"
74405
74406 @@ -156,7 +157,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
74407
74408 /* Bounds of module allocation, for speeding __module_address.
74409 * Protected by module_mutex. */
74410 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
74411 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
74412 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
74413
74414 int register_module_notifier(struct notifier_block * nb)
74415 {
74416 @@ -322,7 +324,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
74417 return true;
74418
74419 list_for_each_entry_rcu(mod, &modules, list) {
74420 - struct symsearch arr[] = {
74421 + struct symsearch modarr[] = {
74422 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
74423 NOT_GPL_ONLY, false },
74424 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
74425 @@ -347,7 +349,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
74426 if (mod->state == MODULE_STATE_UNFORMED)
74427 continue;
74428
74429 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
74430 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
74431 return true;
74432 }
74433 return false;
74434 @@ -484,7 +486,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
74435 static int percpu_modalloc(struct module *mod,
74436 unsigned long size, unsigned long align)
74437 {
74438 - if (align > PAGE_SIZE) {
74439 + if (align-1 >= PAGE_SIZE) {
74440 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
74441 mod->name, align, PAGE_SIZE);
74442 align = PAGE_SIZE;
74443 @@ -1088,7 +1090,7 @@ struct module_attribute module_uevent =
74444 static ssize_t show_coresize(struct module_attribute *mattr,
74445 struct module_kobject *mk, char *buffer)
74446 {
74447 - return sprintf(buffer, "%u\n", mk->mod->core_size);
74448 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
74449 }
74450
74451 static struct module_attribute modinfo_coresize =
74452 @@ -1097,7 +1099,7 @@ static struct module_attribute modinfo_coresize =
74453 static ssize_t show_initsize(struct module_attribute *mattr,
74454 struct module_kobject *mk, char *buffer)
74455 {
74456 - return sprintf(buffer, "%u\n", mk->mod->init_size);
74457 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
74458 }
74459
74460 static struct module_attribute modinfo_initsize =
74461 @@ -1311,7 +1313,7 @@ resolve_symbol_wait(struct module *mod,
74462 */
74463 #ifdef CONFIG_SYSFS
74464
74465 -#ifdef CONFIG_KALLSYMS
74466 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
74467 static inline bool sect_empty(const Elf_Shdr *sect)
74468 {
74469 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
74470 @@ -1451,7 +1453,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
74471 {
74472 unsigned int notes, loaded, i;
74473 struct module_notes_attrs *notes_attrs;
74474 - struct bin_attribute *nattr;
74475 + bin_attribute_no_const *nattr;
74476
74477 /* failed to create section attributes, so can't create notes */
74478 if (!mod->sect_attrs)
74479 @@ -1563,7 +1565,7 @@ static void del_usage_links(struct module *mod)
74480 static int module_add_modinfo_attrs(struct module *mod)
74481 {
74482 struct module_attribute *attr;
74483 - struct module_attribute *temp_attr;
74484 + module_attribute_no_const *temp_attr;
74485 int error = 0;
74486 int i;
74487
74488 @@ -1777,21 +1779,21 @@ static void set_section_ro_nx(void *base,
74489
74490 static void unset_module_core_ro_nx(struct module *mod)
74491 {
74492 - set_page_attributes(mod->module_core + mod->core_text_size,
74493 - mod->module_core + mod->core_size,
74494 + set_page_attributes(mod->module_core_rw,
74495 + mod->module_core_rw + mod->core_size_rw,
74496 set_memory_x);
74497 - set_page_attributes(mod->module_core,
74498 - mod->module_core + mod->core_ro_size,
74499 + set_page_attributes(mod->module_core_rx,
74500 + mod->module_core_rx + mod->core_size_rx,
74501 set_memory_rw);
74502 }
74503
74504 static void unset_module_init_ro_nx(struct module *mod)
74505 {
74506 - set_page_attributes(mod->module_init + mod->init_text_size,
74507 - mod->module_init + mod->init_size,
74508 + set_page_attributes(mod->module_init_rw,
74509 + mod->module_init_rw + mod->init_size_rw,
74510 set_memory_x);
74511 - set_page_attributes(mod->module_init,
74512 - mod->module_init + mod->init_ro_size,
74513 + set_page_attributes(mod->module_init_rx,
74514 + mod->module_init_rx + mod->init_size_rx,
74515 set_memory_rw);
74516 }
74517
74518 @@ -1804,14 +1806,14 @@ void set_all_modules_text_rw(void)
74519 list_for_each_entry_rcu(mod, &modules, list) {
74520 if (mod->state == MODULE_STATE_UNFORMED)
74521 continue;
74522 - if ((mod->module_core) && (mod->core_text_size)) {
74523 - set_page_attributes(mod->module_core,
74524 - mod->module_core + mod->core_text_size,
74525 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
74526 + set_page_attributes(mod->module_core_rx,
74527 + mod->module_core_rx + mod->core_size_rx,
74528 set_memory_rw);
74529 }
74530 - if ((mod->module_init) && (mod->init_text_size)) {
74531 - set_page_attributes(mod->module_init,
74532 - mod->module_init + mod->init_text_size,
74533 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
74534 + set_page_attributes(mod->module_init_rx,
74535 + mod->module_init_rx + mod->init_size_rx,
74536 set_memory_rw);
74537 }
74538 }
74539 @@ -1827,14 +1829,14 @@ void set_all_modules_text_ro(void)
74540 list_for_each_entry_rcu(mod, &modules, list) {
74541 if (mod->state == MODULE_STATE_UNFORMED)
74542 continue;
74543 - if ((mod->module_core) && (mod->core_text_size)) {
74544 - set_page_attributes(mod->module_core,
74545 - mod->module_core + mod->core_text_size,
74546 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
74547 + set_page_attributes(mod->module_core_rx,
74548 + mod->module_core_rx + mod->core_size_rx,
74549 set_memory_ro);
74550 }
74551 - if ((mod->module_init) && (mod->init_text_size)) {
74552 - set_page_attributes(mod->module_init,
74553 - mod->module_init + mod->init_text_size,
74554 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
74555 + set_page_attributes(mod->module_init_rx,
74556 + mod->module_init_rx + mod->init_size_rx,
74557 set_memory_ro);
74558 }
74559 }
74560 @@ -1880,16 +1882,19 @@ static void free_module(struct module *mod)
74561
74562 /* This may be NULL, but that's OK */
74563 unset_module_init_ro_nx(mod);
74564 - module_free(mod, mod->module_init);
74565 + module_free(mod, mod->module_init_rw);
74566 + module_free_exec(mod, mod->module_init_rx);
74567 kfree(mod->args);
74568 percpu_modfree(mod);
74569
74570 /* Free lock-classes: */
74571 - lockdep_free_key_range(mod->module_core, mod->core_size);
74572 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
74573 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
74574
74575 /* Finally, free the core (containing the module structure) */
74576 unset_module_core_ro_nx(mod);
74577 - module_free(mod, mod->module_core);
74578 + module_free_exec(mod, mod->module_core_rx);
74579 + module_free(mod, mod->module_core_rw);
74580
74581 #ifdef CONFIG_MPU
74582 update_protections(current->mm);
74583 @@ -1959,9 +1964,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74584 int ret = 0;
74585 const struct kernel_symbol *ksym;
74586
74587 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74588 + int is_fs_load = 0;
74589 + int register_filesystem_found = 0;
74590 + char *p;
74591 +
74592 + p = strstr(mod->args, "grsec_modharden_fs");
74593 + if (p) {
74594 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
74595 + /* copy \0 as well */
74596 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
74597 + is_fs_load = 1;
74598 + }
74599 +#endif
74600 +
74601 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
74602 const char *name = info->strtab + sym[i].st_name;
74603
74604 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74605 + /* it's a real shame this will never get ripped and copied
74606 + upstream! ;(
74607 + */
74608 + if (is_fs_load && !strcmp(name, "register_filesystem"))
74609 + register_filesystem_found = 1;
74610 +#endif
74611 +
74612 switch (sym[i].st_shndx) {
74613 case SHN_COMMON:
74614 /* We compiled with -fno-common. These are not
74615 @@ -1982,7 +2009,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74616 ksym = resolve_symbol_wait(mod, info, name);
74617 /* Ok if resolved. */
74618 if (ksym && !IS_ERR(ksym)) {
74619 + pax_open_kernel();
74620 sym[i].st_value = ksym->value;
74621 + pax_close_kernel();
74622 break;
74623 }
74624
74625 @@ -2001,11 +2030,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
74626 secbase = (unsigned long)mod_percpu(mod);
74627 else
74628 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
74629 + pax_open_kernel();
74630 sym[i].st_value += secbase;
74631 + pax_close_kernel();
74632 break;
74633 }
74634 }
74635
74636 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
74637 + if (is_fs_load && !register_filesystem_found) {
74638 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
74639 + ret = -EPERM;
74640 + }
74641 +#endif
74642 +
74643 return ret;
74644 }
74645
74646 @@ -2089,22 +2127,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
74647 || s->sh_entsize != ~0UL
74648 || strstarts(sname, ".init"))
74649 continue;
74650 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
74651 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
74652 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
74653 + else
74654 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
74655 pr_debug("\t%s\n", sname);
74656 }
74657 - switch (m) {
74658 - case 0: /* executable */
74659 - mod->core_size = debug_align(mod->core_size);
74660 - mod->core_text_size = mod->core_size;
74661 - break;
74662 - case 1: /* RO: text and ro-data */
74663 - mod->core_size = debug_align(mod->core_size);
74664 - mod->core_ro_size = mod->core_size;
74665 - break;
74666 - case 3: /* whole core */
74667 - mod->core_size = debug_align(mod->core_size);
74668 - break;
74669 - }
74670 }
74671
74672 pr_debug("Init section allocation order:\n");
74673 @@ -2118,23 +2146,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
74674 || s->sh_entsize != ~0UL
74675 || !strstarts(sname, ".init"))
74676 continue;
74677 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
74678 - | INIT_OFFSET_MASK);
74679 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
74680 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
74681 + else
74682 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
74683 + s->sh_entsize |= INIT_OFFSET_MASK;
74684 pr_debug("\t%s\n", sname);
74685 }
74686 - switch (m) {
74687 - case 0: /* executable */
74688 - mod->init_size = debug_align(mod->init_size);
74689 - mod->init_text_size = mod->init_size;
74690 - break;
74691 - case 1: /* RO: text and ro-data */
74692 - mod->init_size = debug_align(mod->init_size);
74693 - mod->init_ro_size = mod->init_size;
74694 - break;
74695 - case 3: /* whole init */
74696 - mod->init_size = debug_align(mod->init_size);
74697 - break;
74698 - }
74699 }
74700 }
74701
74702 @@ -2306,7 +2324,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
74703
74704 /* Put symbol section at end of init part of module. */
74705 symsect->sh_flags |= SHF_ALLOC;
74706 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
74707 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
74708 info->index.sym) | INIT_OFFSET_MASK;
74709 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
74710
74711 @@ -2323,13 +2341,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
74712 }
74713
74714 /* Append room for core symbols at end of core part. */
74715 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
74716 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
74717 - mod->core_size += strtab_size;
74718 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
74719 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
74720 + mod->core_size_rx += strtab_size;
74721
74722 /* Put string table section at end of init part of module. */
74723 strsect->sh_flags |= SHF_ALLOC;
74724 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
74725 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
74726 info->index.str) | INIT_OFFSET_MASK;
74727 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
74728 }
74729 @@ -2347,12 +2365,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
74730 /* Make sure we get permanent strtab: don't use info->strtab. */
74731 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
74732
74733 + pax_open_kernel();
74734 +
74735 /* Set types up while we still have access to sections. */
74736 for (i = 0; i < mod->num_symtab; i++)
74737 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
74738
74739 - mod->core_symtab = dst = mod->module_core + info->symoffs;
74740 - mod->core_strtab = s = mod->module_core + info->stroffs;
74741 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
74742 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
74743 src = mod->symtab;
74744 for (ndst = i = 0; i < mod->num_symtab; i++) {
74745 if (i == 0 ||
74746 @@ -2364,6 +2384,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
74747 }
74748 }
74749 mod->core_num_syms = ndst;
74750 +
74751 + pax_close_kernel();
74752 }
74753 #else
74754 static inline void layout_symtab(struct module *mod, struct load_info *info)
74755 @@ -2397,17 +2419,33 @@ void * __weak module_alloc(unsigned long size)
74756 return vmalloc_exec(size);
74757 }
74758
74759 -static void *module_alloc_update_bounds(unsigned long size)
74760 +static void *module_alloc_update_bounds_rw(unsigned long size)
74761 {
74762 void *ret = module_alloc(size);
74763
74764 if (ret) {
74765 mutex_lock(&module_mutex);
74766 /* Update module bounds. */
74767 - if ((unsigned long)ret < module_addr_min)
74768 - module_addr_min = (unsigned long)ret;
74769 - if ((unsigned long)ret + size > module_addr_max)
74770 - module_addr_max = (unsigned long)ret + size;
74771 + if ((unsigned long)ret < module_addr_min_rw)
74772 + module_addr_min_rw = (unsigned long)ret;
74773 + if ((unsigned long)ret + size > module_addr_max_rw)
74774 + module_addr_max_rw = (unsigned long)ret + size;
74775 + mutex_unlock(&module_mutex);
74776 + }
74777 + return ret;
74778 +}
74779 +
74780 +static void *module_alloc_update_bounds_rx(unsigned long size)
74781 +{
74782 + void *ret = module_alloc_exec(size);
74783 +
74784 + if (ret) {
74785 + mutex_lock(&module_mutex);
74786 + /* Update module bounds. */
74787 + if ((unsigned long)ret < module_addr_min_rx)
74788 + module_addr_min_rx = (unsigned long)ret;
74789 + if ((unsigned long)ret + size > module_addr_max_rx)
74790 + module_addr_max_rx = (unsigned long)ret + size;
74791 mutex_unlock(&module_mutex);
74792 }
74793 return ret;
74794 @@ -2683,8 +2721,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
74795 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
74796 {
74797 const char *modmagic = get_modinfo(info, "vermagic");
74798 + const char *license = get_modinfo(info, "license");
74799 int err;
74800
74801 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
74802 + if (!license || !license_is_gpl_compatible(license))
74803 + return -ENOEXEC;
74804 +#endif
74805 +
74806 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
74807 modmagic = NULL;
74808
74809 @@ -2710,7 +2754,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
74810 }
74811
74812 /* Set up license info based on the info section */
74813 - set_license(mod, get_modinfo(info, "license"));
74814 + set_license(mod, license);
74815
74816 return 0;
74817 }
74818 @@ -2804,7 +2848,7 @@ static int move_module(struct module *mod, struct load_info *info)
74819 void *ptr;
74820
74821 /* Do the allocs. */
74822 - ptr = module_alloc_update_bounds(mod->core_size);
74823 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
74824 /*
74825 * The pointer to this block is stored in the module structure
74826 * which is inside the block. Just mark it as not being a
74827 @@ -2814,11 +2858,11 @@ static int move_module(struct module *mod, struct load_info *info)
74828 if (!ptr)
74829 return -ENOMEM;
74830
74831 - memset(ptr, 0, mod->core_size);
74832 - mod->module_core = ptr;
74833 + memset(ptr, 0, mod->core_size_rw);
74834 + mod->module_core_rw = ptr;
74835
74836 - if (mod->init_size) {
74837 - ptr = module_alloc_update_bounds(mod->init_size);
74838 + if (mod->init_size_rw) {
74839 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
74840 /*
74841 * The pointer to this block is stored in the module structure
74842 * which is inside the block. This block doesn't need to be
74843 @@ -2827,13 +2871,45 @@ static int move_module(struct module *mod, struct load_info *info)
74844 */
74845 kmemleak_ignore(ptr);
74846 if (!ptr) {
74847 - module_free(mod, mod->module_core);
74848 + module_free(mod, mod->module_core_rw);
74849 return -ENOMEM;
74850 }
74851 - memset(ptr, 0, mod->init_size);
74852 - mod->module_init = ptr;
74853 + memset(ptr, 0, mod->init_size_rw);
74854 + mod->module_init_rw = ptr;
74855 } else
74856 - mod->module_init = NULL;
74857 + mod->module_init_rw = NULL;
74858 +
74859 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
74860 + kmemleak_not_leak(ptr);
74861 + if (!ptr) {
74862 + if (mod->module_init_rw)
74863 + module_free(mod, mod->module_init_rw);
74864 + module_free(mod, mod->module_core_rw);
74865 + return -ENOMEM;
74866 + }
74867 +
74868 + pax_open_kernel();
74869 + memset(ptr, 0, mod->core_size_rx);
74870 + pax_close_kernel();
74871 + mod->module_core_rx = ptr;
74872 +
74873 + if (mod->init_size_rx) {
74874 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
74875 + kmemleak_ignore(ptr);
74876 + if (!ptr && mod->init_size_rx) {
74877 + module_free_exec(mod, mod->module_core_rx);
74878 + if (mod->module_init_rw)
74879 + module_free(mod, mod->module_init_rw);
74880 + module_free(mod, mod->module_core_rw);
74881 + return -ENOMEM;
74882 + }
74883 +
74884 + pax_open_kernel();
74885 + memset(ptr, 0, mod->init_size_rx);
74886 + pax_close_kernel();
74887 + mod->module_init_rx = ptr;
74888 + } else
74889 + mod->module_init_rx = NULL;
74890
74891 /* Transfer each section which specifies SHF_ALLOC */
74892 pr_debug("final section addresses:\n");
74893 @@ -2844,16 +2920,45 @@ static int move_module(struct module *mod, struct load_info *info)
74894 if (!(shdr->sh_flags & SHF_ALLOC))
74895 continue;
74896
74897 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
74898 - dest = mod->module_init
74899 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74900 - else
74901 - dest = mod->module_core + shdr->sh_entsize;
74902 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
74903 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
74904 + dest = mod->module_init_rw
74905 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74906 + else
74907 + dest = mod->module_init_rx
74908 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
74909 + } else {
74910 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
74911 + dest = mod->module_core_rw + shdr->sh_entsize;
74912 + else
74913 + dest = mod->module_core_rx + shdr->sh_entsize;
74914 + }
74915 +
74916 + if (shdr->sh_type != SHT_NOBITS) {
74917 +
74918 +#ifdef CONFIG_PAX_KERNEXEC
74919 +#ifdef CONFIG_X86_64
74920 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
74921 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
74922 +#endif
74923 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
74924 + pax_open_kernel();
74925 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
74926 + pax_close_kernel();
74927 + } else
74928 +#endif
74929
74930 - if (shdr->sh_type != SHT_NOBITS)
74931 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
74932 + }
74933 /* Update sh_addr to point to copy in image. */
74934 - shdr->sh_addr = (unsigned long)dest;
74935 +
74936 +#ifdef CONFIG_PAX_KERNEXEC
74937 + if (shdr->sh_flags & SHF_EXECINSTR)
74938 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
74939 + else
74940 +#endif
74941 +
74942 + shdr->sh_addr = (unsigned long)dest;
74943 pr_debug("\t0x%lx %s\n",
74944 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
74945 }
74946 @@ -2908,12 +3013,12 @@ static void flush_module_icache(const struct module *mod)
74947 * Do it before processing of module parameters, so the module
74948 * can provide parameter accessor functions of its own.
74949 */
74950 - if (mod->module_init)
74951 - flush_icache_range((unsigned long)mod->module_init,
74952 - (unsigned long)mod->module_init
74953 - + mod->init_size);
74954 - flush_icache_range((unsigned long)mod->module_core,
74955 - (unsigned long)mod->module_core + mod->core_size);
74956 + if (mod->module_init_rx)
74957 + flush_icache_range((unsigned long)mod->module_init_rx,
74958 + (unsigned long)mod->module_init_rx
74959 + + mod->init_size_rx);
74960 + flush_icache_range((unsigned long)mod->module_core_rx,
74961 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
74962
74963 set_fs(old_fs);
74964 }
74965 @@ -2983,8 +3088,10 @@ out:
74966 static void module_deallocate(struct module *mod, struct load_info *info)
74967 {
74968 percpu_modfree(mod);
74969 - module_free(mod, mod->module_init);
74970 - module_free(mod, mod->module_core);
74971 + module_free_exec(mod, mod->module_init_rx);
74972 + module_free_exec(mod, mod->module_core_rx);
74973 + module_free(mod, mod->module_init_rw);
74974 + module_free(mod, mod->module_core_rw);
74975 }
74976
74977 int __weak module_finalize(const Elf_Ehdr *hdr,
74978 @@ -2997,7 +3104,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
74979 static int post_relocation(struct module *mod, const struct load_info *info)
74980 {
74981 /* Sort exception table now relocations are done. */
74982 + pax_open_kernel();
74983 sort_extable(mod->extable, mod->extable + mod->num_exentries);
74984 + pax_close_kernel();
74985
74986 /* Copy relocated percpu area over. */
74987 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
74988 @@ -3051,16 +3160,16 @@ static int do_init_module(struct module *mod)
74989 MODULE_STATE_COMING, mod);
74990
74991 /* Set RO and NX regions for core */
74992 - set_section_ro_nx(mod->module_core,
74993 - mod->core_text_size,
74994 - mod->core_ro_size,
74995 - mod->core_size);
74996 + set_section_ro_nx(mod->module_core_rx,
74997 + mod->core_size_rx,
74998 + mod->core_size_rx,
74999 + mod->core_size_rx);
75000
75001 /* Set RO and NX regions for init */
75002 - set_section_ro_nx(mod->module_init,
75003 - mod->init_text_size,
75004 - mod->init_ro_size,
75005 - mod->init_size);
75006 + set_section_ro_nx(mod->module_init_rx,
75007 + mod->init_size_rx,
75008 + mod->init_size_rx,
75009 + mod->init_size_rx);
75010
75011 do_mod_ctors(mod);
75012 /* Start the module */
75013 @@ -3122,11 +3231,12 @@ static int do_init_module(struct module *mod)
75014 mod->strtab = mod->core_strtab;
75015 #endif
75016 unset_module_init_ro_nx(mod);
75017 - module_free(mod, mod->module_init);
75018 - mod->module_init = NULL;
75019 - mod->init_size = 0;
75020 - mod->init_ro_size = 0;
75021 - mod->init_text_size = 0;
75022 + module_free(mod, mod->module_init_rw);
75023 + module_free_exec(mod, mod->module_init_rx);
75024 + mod->module_init_rw = NULL;
75025 + mod->module_init_rx = NULL;
75026 + mod->init_size_rw = 0;
75027 + mod->init_size_rx = 0;
75028 mutex_unlock(&module_mutex);
75029 wake_up_all(&module_wq);
75030
75031 @@ -3209,9 +3319,38 @@ again:
75032 if (err)
75033 goto free_unload;
75034
75035 + /* Now copy in args */
75036 + mod->args = strndup_user(uargs, ~0UL >> 1);
75037 + if (IS_ERR(mod->args)) {
75038 + err = PTR_ERR(mod->args);
75039 + goto free_unload;
75040 + }
75041 +
75042 /* Set up MODINFO_ATTR fields */
75043 setup_modinfo(mod, info);
75044
75045 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
75046 + {
75047 + char *p, *p2;
75048 +
75049 + if (strstr(mod->args, "grsec_modharden_netdev")) {
75050 + 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);
75051 + err = -EPERM;
75052 + goto free_modinfo;
75053 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
75054 + p += sizeof("grsec_modharden_normal") - 1;
75055 + p2 = strstr(p, "_");
75056 + if (p2) {
75057 + *p2 = '\0';
75058 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
75059 + *p2 = '_';
75060 + }
75061 + err = -EPERM;
75062 + goto free_modinfo;
75063 + }
75064 + }
75065 +#endif
75066 +
75067 /* Fix up syms, so that st_value is a pointer to location. */
75068 err = simplify_symbols(mod, info);
75069 if (err < 0)
75070 @@ -3227,13 +3366,6 @@ again:
75071
75072 flush_module_icache(mod);
75073
75074 - /* Now copy in args */
75075 - mod->args = strndup_user(uargs, ~0UL >> 1);
75076 - if (IS_ERR(mod->args)) {
75077 - err = PTR_ERR(mod->args);
75078 - goto free_arch_cleanup;
75079 - }
75080 -
75081 dynamic_debug_setup(info->debug, info->num_debug);
75082
75083 mutex_lock(&module_mutex);
75084 @@ -3278,11 +3410,10 @@ again:
75085 mutex_unlock(&module_mutex);
75086 dynamic_debug_remove(info->debug);
75087 synchronize_sched();
75088 - kfree(mod->args);
75089 - free_arch_cleanup:
75090 module_arch_cleanup(mod);
75091 free_modinfo:
75092 free_modinfo(mod);
75093 + kfree(mod->args);
75094 free_unload:
75095 module_unload_free(mod);
75096 unlink_mod:
75097 @@ -3365,10 +3496,16 @@ static const char *get_ksymbol(struct module *mod,
75098 unsigned long nextval;
75099
75100 /* At worse, next value is at end of module */
75101 - if (within_module_init(addr, mod))
75102 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
75103 + if (within_module_init_rx(addr, mod))
75104 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
75105 + else if (within_module_init_rw(addr, mod))
75106 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
75107 + else if (within_module_core_rx(addr, mod))
75108 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
75109 + else if (within_module_core_rw(addr, mod))
75110 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
75111 else
75112 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
75113 + return NULL;
75114
75115 /* Scan for closest preceding symbol, and next symbol. (ELF
75116 starts real symbols at 1). */
75117 @@ -3621,7 +3758,7 @@ static int m_show(struct seq_file *m, void *p)
75118 return 0;
75119
75120 seq_printf(m, "%s %u",
75121 - mod->name, mod->init_size + mod->core_size);
75122 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
75123 print_unload_info(m, mod);
75124
75125 /* Informative for users. */
75126 @@ -3630,7 +3767,7 @@ static int m_show(struct seq_file *m, void *p)
75127 mod->state == MODULE_STATE_COMING ? "Loading":
75128 "Live");
75129 /* Used by oprofile and other similar tools. */
75130 - seq_printf(m, " 0x%pK", mod->module_core);
75131 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
75132
75133 /* Taints info */
75134 if (mod->taints)
75135 @@ -3666,7 +3803,17 @@ static const struct file_operations proc_modules_operations = {
75136
75137 static int __init proc_modules_init(void)
75138 {
75139 +#ifndef CONFIG_GRKERNSEC_HIDESYM
75140 +#ifdef CONFIG_GRKERNSEC_PROC_USER
75141 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75142 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
75143 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
75144 +#else
75145 proc_create("modules", 0, NULL, &proc_modules_operations);
75146 +#endif
75147 +#else
75148 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
75149 +#endif
75150 return 0;
75151 }
75152 module_init(proc_modules_init);
75153 @@ -3727,14 +3874,14 @@ struct module *__module_address(unsigned long addr)
75154 {
75155 struct module *mod;
75156
75157 - if (addr < module_addr_min || addr > module_addr_max)
75158 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
75159 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
75160 return NULL;
75161
75162 list_for_each_entry_rcu(mod, &modules, list) {
75163 if (mod->state == MODULE_STATE_UNFORMED)
75164 continue;
75165 - if (within_module_core(addr, mod)
75166 - || within_module_init(addr, mod))
75167 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
75168 return mod;
75169 }
75170 return NULL;
75171 @@ -3769,11 +3916,20 @@ bool is_module_text_address(unsigned long addr)
75172 */
75173 struct module *__module_text_address(unsigned long addr)
75174 {
75175 - struct module *mod = __module_address(addr);
75176 + struct module *mod;
75177 +
75178 +#ifdef CONFIG_X86_32
75179 + addr = ktla_ktva(addr);
75180 +#endif
75181 +
75182 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
75183 + return NULL;
75184 +
75185 + mod = __module_address(addr);
75186 +
75187 if (mod) {
75188 /* Make sure it's within the text section. */
75189 - if (!within(addr, mod->module_init, mod->init_text_size)
75190 - && !within(addr, mod->module_core, mod->core_text_size))
75191 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
75192 mod = NULL;
75193 }
75194 return mod;
75195 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
75196 index 7e3443f..b2a1e6b 100644
75197 --- a/kernel/mutex-debug.c
75198 +++ b/kernel/mutex-debug.c
75199 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
75200 }
75201
75202 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75203 - struct thread_info *ti)
75204 + struct task_struct *task)
75205 {
75206 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
75207
75208 /* Mark the current thread as blocked on the lock: */
75209 - ti->task->blocked_on = waiter;
75210 + task->blocked_on = waiter;
75211 }
75212
75213 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75214 - struct thread_info *ti)
75215 + struct task_struct *task)
75216 {
75217 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
75218 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
75219 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
75220 - ti->task->blocked_on = NULL;
75221 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
75222 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
75223 + task->blocked_on = NULL;
75224
75225 list_del_init(&waiter->list);
75226 waiter->task = NULL;
75227 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
75228 index 0799fd3..d06ae3b 100644
75229 --- a/kernel/mutex-debug.h
75230 +++ b/kernel/mutex-debug.h
75231 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
75232 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
75233 extern void debug_mutex_add_waiter(struct mutex *lock,
75234 struct mutex_waiter *waiter,
75235 - struct thread_info *ti);
75236 + struct task_struct *task);
75237 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
75238 - struct thread_info *ti);
75239 + struct task_struct *task);
75240 extern void debug_mutex_unlock(struct mutex *lock);
75241 extern void debug_mutex_init(struct mutex *lock, const char *name,
75242 struct lock_class_key *key);
75243 diff --git a/kernel/mutex.c b/kernel/mutex.c
75244 index a307cc9..27fd2e9 100644
75245 --- a/kernel/mutex.c
75246 +++ b/kernel/mutex.c
75247 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75248 spin_lock_mutex(&lock->wait_lock, flags);
75249
75250 debug_mutex_lock_common(lock, &waiter);
75251 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
75252 + debug_mutex_add_waiter(lock, &waiter, task);
75253
75254 /* add waiting tasks to the end of the waitqueue (FIFO): */
75255 list_add_tail(&waiter.list, &lock->wait_list);
75256 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75257 * TASK_UNINTERRUPTIBLE case.)
75258 */
75259 if (unlikely(signal_pending_state(state, task))) {
75260 - mutex_remove_waiter(lock, &waiter,
75261 - task_thread_info(task));
75262 + mutex_remove_waiter(lock, &waiter, task);
75263 mutex_release(&lock->dep_map, 1, ip);
75264 spin_unlock_mutex(&lock->wait_lock, flags);
75265
75266 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
75267 done:
75268 lock_acquired(&lock->dep_map, ip);
75269 /* got the lock - rejoice! */
75270 - mutex_remove_waiter(lock, &waiter, current_thread_info());
75271 + mutex_remove_waiter(lock, &waiter, task);
75272 mutex_set_owner(lock);
75273
75274 /* set it to 0 if there are no waiters left: */
75275 diff --git a/kernel/notifier.c b/kernel/notifier.c
75276 index 2d5cc4c..d9ea600 100644
75277 --- a/kernel/notifier.c
75278 +++ b/kernel/notifier.c
75279 @@ -5,6 +5,7 @@
75280 #include <linux/rcupdate.h>
75281 #include <linux/vmalloc.h>
75282 #include <linux/reboot.h>
75283 +#include <linux/mm.h>
75284
75285 /*
75286 * Notifier list for kernel code which wants to be called
75287 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
75288 while ((*nl) != NULL) {
75289 if (n->priority > (*nl)->priority)
75290 break;
75291 - nl = &((*nl)->next);
75292 + nl = (struct notifier_block **)&((*nl)->next);
75293 }
75294 - n->next = *nl;
75295 + pax_open_kernel();
75296 + *(const void **)&n->next = *nl;
75297 rcu_assign_pointer(*nl, n);
75298 + pax_close_kernel();
75299 return 0;
75300 }
75301
75302 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
75303 return 0;
75304 if (n->priority > (*nl)->priority)
75305 break;
75306 - nl = &((*nl)->next);
75307 + nl = (struct notifier_block **)&((*nl)->next);
75308 }
75309 - n->next = *nl;
75310 + pax_open_kernel();
75311 + *(const void **)&n->next = *nl;
75312 rcu_assign_pointer(*nl, n);
75313 + pax_close_kernel();
75314 return 0;
75315 }
75316
75317 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
75318 {
75319 while ((*nl) != NULL) {
75320 if ((*nl) == n) {
75321 + pax_open_kernel();
75322 rcu_assign_pointer(*nl, n->next);
75323 + pax_close_kernel();
75324 return 0;
75325 }
75326 - nl = &((*nl)->next);
75327 + nl = (struct notifier_block **)&((*nl)->next);
75328 }
75329 return -ENOENT;
75330 }
75331 diff --git a/kernel/panic.c b/kernel/panic.c
75332 index e1b2822..5edc1d9 100644
75333 --- a/kernel/panic.c
75334 +++ b/kernel/panic.c
75335 @@ -410,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
75336 const char *board;
75337
75338 printk(KERN_WARNING "------------[ cut here ]------------\n");
75339 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
75340 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
75341 board = dmi_get_system_info(DMI_PRODUCT_NAME);
75342 if (board)
75343 printk(KERN_WARNING "Hardware name: %s\n", board);
75344 @@ -465,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
75345 */
75346 void __stack_chk_fail(void)
75347 {
75348 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
75349 + dump_stack();
75350 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
75351 __builtin_return_address(0));
75352 }
75353 EXPORT_SYMBOL(__stack_chk_fail);
75354 diff --git a/kernel/pid.c b/kernel/pid.c
75355 index f2c6a68..4922d97 100644
75356 --- a/kernel/pid.c
75357 +++ b/kernel/pid.c
75358 @@ -33,6 +33,7 @@
75359 #include <linux/rculist.h>
75360 #include <linux/bootmem.h>
75361 #include <linux/hash.h>
75362 +#include <linux/security.h>
75363 #include <linux/pid_namespace.h>
75364 #include <linux/init_task.h>
75365 #include <linux/syscalls.h>
75366 @@ -46,7 +47,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
75367
75368 int pid_max = PID_MAX_DEFAULT;
75369
75370 -#define RESERVED_PIDS 300
75371 +#define RESERVED_PIDS 500
75372
75373 int pid_max_min = RESERVED_PIDS + 1;
75374 int pid_max_max = PID_MAX_LIMIT;
75375 @@ -441,10 +442,18 @@ EXPORT_SYMBOL(pid_task);
75376 */
75377 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
75378 {
75379 + struct task_struct *task;
75380 +
75381 rcu_lockdep_assert(rcu_read_lock_held(),
75382 "find_task_by_pid_ns() needs rcu_read_lock()"
75383 " protection");
75384 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75385 +
75386 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
75387 +
75388 + if (gr_pid_is_chrooted(task))
75389 + return NULL;
75390 +
75391 + return task;
75392 }
75393
75394 struct task_struct *find_task_by_vpid(pid_t vnr)
75395 @@ -452,6 +461,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
75396 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
75397 }
75398
75399 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
75400 +{
75401 + rcu_lockdep_assert(rcu_read_lock_held(),
75402 + "find_task_by_pid_ns() needs rcu_read_lock()"
75403 + " protection");
75404 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
75405 +}
75406 +
75407 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
75408 {
75409 struct pid *pid;
75410 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
75411 index c1c3dc1..bbeaf31 100644
75412 --- a/kernel/pid_namespace.c
75413 +++ b/kernel/pid_namespace.c
75414 @@ -248,7 +248,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
75415 void __user *buffer, size_t *lenp, loff_t *ppos)
75416 {
75417 struct pid_namespace *pid_ns = task_active_pid_ns(current);
75418 - struct ctl_table tmp = *table;
75419 + ctl_table_no_const tmp = *table;
75420
75421 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
75422 return -EPERM;
75423 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
75424 index 942ca27..111e609 100644
75425 --- a/kernel/posix-cpu-timers.c
75426 +++ b/kernel/posix-cpu-timers.c
75427 @@ -1576,14 +1576,14 @@ struct k_clock clock_posix_cpu = {
75428
75429 static __init int init_posix_cpu_timers(void)
75430 {
75431 - struct k_clock process = {
75432 + static struct k_clock process = {
75433 .clock_getres = process_cpu_clock_getres,
75434 .clock_get = process_cpu_clock_get,
75435 .timer_create = process_cpu_timer_create,
75436 .nsleep = process_cpu_nsleep,
75437 .nsleep_restart = process_cpu_nsleep_restart,
75438 };
75439 - struct k_clock thread = {
75440 + static struct k_clock thread = {
75441 .clock_getres = thread_cpu_clock_getres,
75442 .clock_get = thread_cpu_clock_get,
75443 .timer_create = thread_cpu_timer_create,
75444 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
75445 index e885be1..380fe76 100644
75446 --- a/kernel/posix-timers.c
75447 +++ b/kernel/posix-timers.c
75448 @@ -43,6 +43,7 @@
75449 #include <linux/idr.h>
75450 #include <linux/posix-clock.h>
75451 #include <linux/posix-timers.h>
75452 +#include <linux/grsecurity.h>
75453 #include <linux/syscalls.h>
75454 #include <linux/wait.h>
75455 #include <linux/workqueue.h>
75456 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
75457 * which we beg off on and pass to do_sys_settimeofday().
75458 */
75459
75460 -static struct k_clock posix_clocks[MAX_CLOCKS];
75461 +static struct k_clock *posix_clocks[MAX_CLOCKS];
75462
75463 /*
75464 * These ones are defined below.
75465 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
75466 */
75467 static __init int init_posix_timers(void)
75468 {
75469 - struct k_clock clock_realtime = {
75470 + static struct k_clock clock_realtime = {
75471 .clock_getres = hrtimer_get_res,
75472 .clock_get = posix_clock_realtime_get,
75473 .clock_set = posix_clock_realtime_set,
75474 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
75475 .timer_get = common_timer_get,
75476 .timer_del = common_timer_del,
75477 };
75478 - struct k_clock clock_monotonic = {
75479 + static struct k_clock clock_monotonic = {
75480 .clock_getres = hrtimer_get_res,
75481 .clock_get = posix_ktime_get_ts,
75482 .nsleep = common_nsleep,
75483 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
75484 .timer_get = common_timer_get,
75485 .timer_del = common_timer_del,
75486 };
75487 - struct k_clock clock_monotonic_raw = {
75488 + static struct k_clock clock_monotonic_raw = {
75489 .clock_getres = hrtimer_get_res,
75490 .clock_get = posix_get_monotonic_raw,
75491 };
75492 - struct k_clock clock_realtime_coarse = {
75493 + static struct k_clock clock_realtime_coarse = {
75494 .clock_getres = posix_get_coarse_res,
75495 .clock_get = posix_get_realtime_coarse,
75496 };
75497 - struct k_clock clock_monotonic_coarse = {
75498 + static struct k_clock clock_monotonic_coarse = {
75499 .clock_getres = posix_get_coarse_res,
75500 .clock_get = posix_get_monotonic_coarse,
75501 };
75502 - struct k_clock clock_boottime = {
75503 + static struct k_clock clock_boottime = {
75504 .clock_getres = hrtimer_get_res,
75505 .clock_get = posix_get_boottime,
75506 .nsleep = common_nsleep,
75507 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
75508 return;
75509 }
75510
75511 - posix_clocks[clock_id] = *new_clock;
75512 + posix_clocks[clock_id] = new_clock;
75513 }
75514 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
75515
75516 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
75517 return (id & CLOCKFD_MASK) == CLOCKFD ?
75518 &clock_posix_dynamic : &clock_posix_cpu;
75519
75520 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
75521 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
75522 return NULL;
75523 - return &posix_clocks[id];
75524 + return posix_clocks[id];
75525 }
75526
75527 static int common_timer_create(struct k_itimer *new_timer)
75528 @@ -966,6 +967,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
75529 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
75530 return -EFAULT;
75531
75532 + /* only the CLOCK_REALTIME clock can be set, all other clocks
75533 + have their clock_set fptr set to a nosettime dummy function
75534 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
75535 + call common_clock_set, which calls do_sys_settimeofday, which
75536 + we hook
75537 + */
75538 +
75539 return kc->clock_set(which_clock, &new_tp);
75540 }
75541
75542 diff --git a/kernel/power/process.c b/kernel/power/process.c
75543 index d5a258b..4271191 100644
75544 --- a/kernel/power/process.c
75545 +++ b/kernel/power/process.c
75546 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
75547 u64 elapsed_csecs64;
75548 unsigned int elapsed_csecs;
75549 bool wakeup = false;
75550 + bool timedout = false;
75551
75552 do_gettimeofday(&start);
75553
75554 @@ -43,13 +44,20 @@ static int try_to_freeze_tasks(bool user_only)
75555
75556 while (true) {
75557 todo = 0;
75558 + if (time_after(jiffies, end_time))
75559 + timedout = true;
75560 read_lock(&tasklist_lock);
75561 do_each_thread(g, p) {
75562 if (p == current || !freeze_task(p))
75563 continue;
75564
75565 - if (!freezer_should_skip(p))
75566 + if (!freezer_should_skip(p)) {
75567 todo++;
75568 + if (timedout) {
75569 + printk(KERN_ERR "Task refusing to freeze:\n");
75570 + sched_show_task(p);
75571 + }
75572 + }
75573 } while_each_thread(g, p);
75574 read_unlock(&tasklist_lock);
75575
75576 @@ -58,7 +66,7 @@ static int try_to_freeze_tasks(bool user_only)
75577 todo += wq_busy;
75578 }
75579
75580 - if (!todo || time_after(jiffies, end_time))
75581 + if (!todo || timedout)
75582 break;
75583
75584 if (pm_wakeup_pending()) {
75585 diff --git a/kernel/printk.c b/kernel/printk.c
75586 index 267ce78..2487112 100644
75587 --- a/kernel/printk.c
75588 +++ b/kernel/printk.c
75589 @@ -609,11 +609,17 @@ static unsigned int devkmsg_poll(struct file *file, poll_table *wait)
75590 return ret;
75591 }
75592
75593 +static int check_syslog_permissions(int type, bool from_file);
75594 +
75595 static int devkmsg_open(struct inode *inode, struct file *file)
75596 {
75597 struct devkmsg_user *user;
75598 int err;
75599
75600 + err = check_syslog_permissions(SYSLOG_ACTION_OPEN, SYSLOG_FROM_FILE);
75601 + if (err)
75602 + return err;
75603 +
75604 /* write-only does not need any file context */
75605 if ((file->f_flags & O_ACCMODE) == O_WRONLY)
75606 return 0;
75607 @@ -822,7 +828,7 @@ static int syslog_action_restricted(int type)
75608 if (dmesg_restrict)
75609 return 1;
75610 /* Unless restricted, we allow "read all" and "get buffer size" for everybody */
75611 - return type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
75612 + return type != SYSLOG_ACTION_OPEN && type != SYSLOG_ACTION_READ_ALL && type != SYSLOG_ACTION_SIZE_BUFFER;
75613 }
75614
75615 static int check_syslog_permissions(int type, bool from_file)
75616 @@ -834,6 +840,11 @@ static int check_syslog_permissions(int type, bool from_file)
75617 if (from_file && type != SYSLOG_ACTION_OPEN)
75618 return 0;
75619
75620 +#ifdef CONFIG_GRKERNSEC_DMESG
75621 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
75622 + return -EPERM;
75623 +#endif
75624 +
75625 if (syslog_action_restricted(type)) {
75626 if (capable(CAP_SYSLOG))
75627 return 0;
75628 diff --git a/kernel/profile.c b/kernel/profile.c
75629 index 1f39181..86093471 100644
75630 --- a/kernel/profile.c
75631 +++ b/kernel/profile.c
75632 @@ -40,7 +40,7 @@ struct profile_hit {
75633 /* Oprofile timer tick hook */
75634 static int (*timer_hook)(struct pt_regs *) __read_mostly;
75635
75636 -static atomic_t *prof_buffer;
75637 +static atomic_unchecked_t *prof_buffer;
75638 static unsigned long prof_len, prof_shift;
75639
75640 int prof_on __read_mostly;
75641 @@ -282,7 +282,7 @@ static void profile_flip_buffers(void)
75642 hits[i].pc = 0;
75643 continue;
75644 }
75645 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
75646 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
75647 hits[i].hits = hits[i].pc = 0;
75648 }
75649 }
75650 @@ -343,9 +343,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
75651 * Add the current hit(s) and flush the write-queue out
75652 * to the global buffer:
75653 */
75654 - atomic_add(nr_hits, &prof_buffer[pc]);
75655 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
75656 for (i = 0; i < NR_PROFILE_HIT; ++i) {
75657 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
75658 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
75659 hits[i].pc = hits[i].hits = 0;
75660 }
75661 out:
75662 @@ -420,7 +420,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
75663 {
75664 unsigned long pc;
75665 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
75666 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
75667 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
75668 }
75669 #endif /* !CONFIG_SMP */
75670
75671 @@ -518,7 +518,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
75672 return -EFAULT;
75673 buf++; p++; count--; read++;
75674 }
75675 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
75676 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
75677 if (copy_to_user(buf, (void *)pnt, count))
75678 return -EFAULT;
75679 read += count;
75680 @@ -549,7 +549,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
75681 }
75682 #endif
75683 profile_discard_flip_buffers();
75684 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
75685 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
75686 return count;
75687 }
75688
75689 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
75690 index 6cbeaae..363c48a 100644
75691 --- a/kernel/ptrace.c
75692 +++ b/kernel/ptrace.c
75693 @@ -324,7 +324,7 @@ static int ptrace_attach(struct task_struct *task, long request,
75694 if (seize)
75695 flags |= PT_SEIZED;
75696 rcu_read_lock();
75697 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
75698 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
75699 flags |= PT_PTRACE_CAP;
75700 rcu_read_unlock();
75701 task->ptrace = flags;
75702 @@ -535,7 +535,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
75703 break;
75704 return -EIO;
75705 }
75706 - if (copy_to_user(dst, buf, retval))
75707 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
75708 return -EFAULT;
75709 copied += retval;
75710 src += retval;
75711 @@ -720,7 +720,7 @@ int ptrace_request(struct task_struct *child, long request,
75712 bool seized = child->ptrace & PT_SEIZED;
75713 int ret = -EIO;
75714 siginfo_t siginfo, *si;
75715 - void __user *datavp = (void __user *) data;
75716 + void __user *datavp = (__force void __user *) data;
75717 unsigned long __user *datalp = datavp;
75718 unsigned long flags;
75719
75720 @@ -922,14 +922,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
75721 goto out;
75722 }
75723
75724 + if (gr_handle_ptrace(child, request)) {
75725 + ret = -EPERM;
75726 + goto out_put_task_struct;
75727 + }
75728 +
75729 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
75730 ret = ptrace_attach(child, request, addr, data);
75731 /*
75732 * Some architectures need to do book-keeping after
75733 * a ptrace attach.
75734 */
75735 - if (!ret)
75736 + if (!ret) {
75737 arch_ptrace_attach(child);
75738 + gr_audit_ptrace(child);
75739 + }
75740 goto out_put_task_struct;
75741 }
75742
75743 @@ -957,7 +964,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
75744 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
75745 if (copied != sizeof(tmp))
75746 return -EIO;
75747 - return put_user(tmp, (unsigned long __user *)data);
75748 + return put_user(tmp, (__force unsigned long __user *)data);
75749 }
75750
75751 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
75752 @@ -1067,14 +1074,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
75753 goto out;
75754 }
75755
75756 + if (gr_handle_ptrace(child, request)) {
75757 + ret = -EPERM;
75758 + goto out_put_task_struct;
75759 + }
75760 +
75761 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
75762 ret = ptrace_attach(child, request, addr, data);
75763 /*
75764 * Some architectures need to do book-keeping after
75765 * a ptrace attach.
75766 */
75767 - if (!ret)
75768 + if (!ret) {
75769 arch_ptrace_attach(child);
75770 + gr_audit_ptrace(child);
75771 + }
75772 goto out_put_task_struct;
75773 }
75774
75775 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
75776 index e7dce58..ad0d7b7 100644
75777 --- a/kernel/rcutiny.c
75778 +++ b/kernel/rcutiny.c
75779 @@ -46,7 +46,7 @@
75780 struct rcu_ctrlblk;
75781 static void invoke_rcu_callbacks(void);
75782 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
75783 -static void rcu_process_callbacks(struct softirq_action *unused);
75784 +static void rcu_process_callbacks(void);
75785 static void __call_rcu(struct rcu_head *head,
75786 void (*func)(struct rcu_head *rcu),
75787 struct rcu_ctrlblk *rcp);
75788 @@ -310,7 +310,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
75789 rcu_is_callbacks_kthread()));
75790 }
75791
75792 -static void rcu_process_callbacks(struct softirq_action *unused)
75793 +static void rcu_process_callbacks(void)
75794 {
75795 __rcu_process_callbacks(&rcu_sched_ctrlblk);
75796 __rcu_process_callbacks(&rcu_bh_ctrlblk);
75797 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
75798 index f85016a..91cb03b 100644
75799 --- a/kernel/rcutiny_plugin.h
75800 +++ b/kernel/rcutiny_plugin.h
75801 @@ -896,7 +896,7 @@ static int rcu_kthread(void *arg)
75802 have_rcu_kthread_work = morework;
75803 local_irq_restore(flags);
75804 if (work)
75805 - rcu_process_callbacks(NULL);
75806 + rcu_process_callbacks();
75807 schedule_timeout_interruptible(1); /* Leave CPU for others. */
75808 }
75809
75810 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
75811 index 31dea01..ad91ffb 100644
75812 --- a/kernel/rcutorture.c
75813 +++ b/kernel/rcutorture.c
75814 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
75815 { 0 };
75816 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
75817 { 0 };
75818 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
75819 -static atomic_t n_rcu_torture_alloc;
75820 -static atomic_t n_rcu_torture_alloc_fail;
75821 -static atomic_t n_rcu_torture_free;
75822 -static atomic_t n_rcu_torture_mberror;
75823 -static atomic_t n_rcu_torture_error;
75824 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
75825 +static atomic_unchecked_t n_rcu_torture_alloc;
75826 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
75827 +static atomic_unchecked_t n_rcu_torture_free;
75828 +static atomic_unchecked_t n_rcu_torture_mberror;
75829 +static atomic_unchecked_t n_rcu_torture_error;
75830 static long n_rcu_torture_barrier_error;
75831 static long n_rcu_torture_boost_ktrerror;
75832 static long n_rcu_torture_boost_rterror;
75833 @@ -272,11 +272,11 @@ rcu_torture_alloc(void)
75834
75835 spin_lock_bh(&rcu_torture_lock);
75836 if (list_empty(&rcu_torture_freelist)) {
75837 - atomic_inc(&n_rcu_torture_alloc_fail);
75838 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
75839 spin_unlock_bh(&rcu_torture_lock);
75840 return NULL;
75841 }
75842 - atomic_inc(&n_rcu_torture_alloc);
75843 + atomic_inc_unchecked(&n_rcu_torture_alloc);
75844 p = rcu_torture_freelist.next;
75845 list_del_init(p);
75846 spin_unlock_bh(&rcu_torture_lock);
75847 @@ -289,7 +289,7 @@ rcu_torture_alloc(void)
75848 static void
75849 rcu_torture_free(struct rcu_torture *p)
75850 {
75851 - atomic_inc(&n_rcu_torture_free);
75852 + atomic_inc_unchecked(&n_rcu_torture_free);
75853 spin_lock_bh(&rcu_torture_lock);
75854 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
75855 spin_unlock_bh(&rcu_torture_lock);
75856 @@ -409,7 +409,7 @@ rcu_torture_cb(struct rcu_head *p)
75857 i = rp->rtort_pipe_count;
75858 if (i > RCU_TORTURE_PIPE_LEN)
75859 i = RCU_TORTURE_PIPE_LEN;
75860 - atomic_inc(&rcu_torture_wcount[i]);
75861 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75862 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
75863 rp->rtort_mbtest = 0;
75864 rcu_torture_free(rp);
75865 @@ -457,7 +457,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
75866 i = rp->rtort_pipe_count;
75867 if (i > RCU_TORTURE_PIPE_LEN)
75868 i = RCU_TORTURE_PIPE_LEN;
75869 - atomic_inc(&rcu_torture_wcount[i]);
75870 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75871 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
75872 rp->rtort_mbtest = 0;
75873 list_del(&rp->rtort_free);
75874 @@ -975,7 +975,7 @@ rcu_torture_writer(void *arg)
75875 i = old_rp->rtort_pipe_count;
75876 if (i > RCU_TORTURE_PIPE_LEN)
75877 i = RCU_TORTURE_PIPE_LEN;
75878 - atomic_inc(&rcu_torture_wcount[i]);
75879 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
75880 old_rp->rtort_pipe_count++;
75881 cur_ops->deferred_free(old_rp);
75882 }
75883 @@ -1060,7 +1060,7 @@ static void rcu_torture_timer(unsigned long unused)
75884 }
75885 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
75886 if (p->rtort_mbtest == 0)
75887 - atomic_inc(&n_rcu_torture_mberror);
75888 + atomic_inc_unchecked(&n_rcu_torture_mberror);
75889 spin_lock(&rand_lock);
75890 cur_ops->read_delay(&rand);
75891 n_rcu_torture_timers++;
75892 @@ -1124,7 +1124,7 @@ rcu_torture_reader(void *arg)
75893 }
75894 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
75895 if (p->rtort_mbtest == 0)
75896 - atomic_inc(&n_rcu_torture_mberror);
75897 + atomic_inc_unchecked(&n_rcu_torture_mberror);
75898 cur_ops->read_delay(&rand);
75899 preempt_disable();
75900 pipe_count = p->rtort_pipe_count;
75901 @@ -1183,11 +1183,11 @@ rcu_torture_printk(char *page)
75902 rcu_torture_current,
75903 rcu_torture_current_version,
75904 list_empty(&rcu_torture_freelist),
75905 - atomic_read(&n_rcu_torture_alloc),
75906 - atomic_read(&n_rcu_torture_alloc_fail),
75907 - atomic_read(&n_rcu_torture_free));
75908 + atomic_read_unchecked(&n_rcu_torture_alloc),
75909 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
75910 + atomic_read_unchecked(&n_rcu_torture_free));
75911 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
75912 - atomic_read(&n_rcu_torture_mberror),
75913 + atomic_read_unchecked(&n_rcu_torture_mberror),
75914 n_rcu_torture_boost_ktrerror,
75915 n_rcu_torture_boost_rterror);
75916 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
75917 @@ -1206,14 +1206,14 @@ rcu_torture_printk(char *page)
75918 n_barrier_attempts,
75919 n_rcu_torture_barrier_error);
75920 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
75921 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
75922 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
75923 n_rcu_torture_barrier_error != 0 ||
75924 n_rcu_torture_boost_ktrerror != 0 ||
75925 n_rcu_torture_boost_rterror != 0 ||
75926 n_rcu_torture_boost_failure != 0 ||
75927 i > 1) {
75928 cnt += sprintf(&page[cnt], "!!! ");
75929 - atomic_inc(&n_rcu_torture_error);
75930 + atomic_inc_unchecked(&n_rcu_torture_error);
75931 WARN_ON_ONCE(1);
75932 }
75933 cnt += sprintf(&page[cnt], "Reader Pipe: ");
75934 @@ -1227,7 +1227,7 @@ rcu_torture_printk(char *page)
75935 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
75936 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
75937 cnt += sprintf(&page[cnt], " %d",
75938 - atomic_read(&rcu_torture_wcount[i]));
75939 + atomic_read_unchecked(&rcu_torture_wcount[i]));
75940 }
75941 cnt += sprintf(&page[cnt], "\n");
75942 if (cur_ops->stats)
75943 @@ -1920,7 +1920,7 @@ rcu_torture_cleanup(void)
75944
75945 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
75946
75947 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
75948 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
75949 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
75950 else if (n_online_successes != n_online_attempts ||
75951 n_offline_successes != n_offline_attempts)
75952 @@ -1989,18 +1989,18 @@ rcu_torture_init(void)
75953
75954 rcu_torture_current = NULL;
75955 rcu_torture_current_version = 0;
75956 - atomic_set(&n_rcu_torture_alloc, 0);
75957 - atomic_set(&n_rcu_torture_alloc_fail, 0);
75958 - atomic_set(&n_rcu_torture_free, 0);
75959 - atomic_set(&n_rcu_torture_mberror, 0);
75960 - atomic_set(&n_rcu_torture_error, 0);
75961 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
75962 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
75963 + atomic_set_unchecked(&n_rcu_torture_free, 0);
75964 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
75965 + atomic_set_unchecked(&n_rcu_torture_error, 0);
75966 n_rcu_torture_barrier_error = 0;
75967 n_rcu_torture_boost_ktrerror = 0;
75968 n_rcu_torture_boost_rterror = 0;
75969 n_rcu_torture_boost_failure = 0;
75970 n_rcu_torture_boosts = 0;
75971 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
75972 - atomic_set(&rcu_torture_wcount[i], 0);
75973 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
75974 for_each_possible_cpu(cpu) {
75975 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
75976 per_cpu(rcu_torture_count, cpu)[i] = 0;
75977 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
75978 index e441b77..dd54f17 100644
75979 --- a/kernel/rcutree.c
75980 +++ b/kernel/rcutree.c
75981 @@ -349,9 +349,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
75982 rcu_prepare_for_idle(smp_processor_id());
75983 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
75984 smp_mb__before_atomic_inc(); /* See above. */
75985 - atomic_inc(&rdtp->dynticks);
75986 + atomic_inc_unchecked(&rdtp->dynticks);
75987 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
75988 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
75989 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
75990
75991 /*
75992 * It is illegal to enter an extended quiescent state while
75993 @@ -487,10 +487,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
75994 int user)
75995 {
75996 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
75997 - atomic_inc(&rdtp->dynticks);
75998 + atomic_inc_unchecked(&rdtp->dynticks);
75999 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76000 smp_mb__after_atomic_inc(); /* See above. */
76001 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76002 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76003 rcu_cleanup_after_idle(smp_processor_id());
76004 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
76005 if (!user && !is_idle_task(current)) {
76006 @@ -629,14 +629,14 @@ void rcu_nmi_enter(void)
76007 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
76008
76009 if (rdtp->dynticks_nmi_nesting == 0 &&
76010 - (atomic_read(&rdtp->dynticks) & 0x1))
76011 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
76012 return;
76013 rdtp->dynticks_nmi_nesting++;
76014 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
76015 - atomic_inc(&rdtp->dynticks);
76016 + atomic_inc_unchecked(&rdtp->dynticks);
76017 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
76018 smp_mb__after_atomic_inc(); /* See above. */
76019 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
76020 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
76021 }
76022
76023 /**
76024 @@ -655,9 +655,9 @@ void rcu_nmi_exit(void)
76025 return;
76026 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
76027 smp_mb__before_atomic_inc(); /* See above. */
76028 - atomic_inc(&rdtp->dynticks);
76029 + atomic_inc_unchecked(&rdtp->dynticks);
76030 smp_mb__after_atomic_inc(); /* Force delay to next write. */
76031 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
76032 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
76033 }
76034
76035 /**
76036 @@ -671,7 +671,7 @@ int rcu_is_cpu_idle(void)
76037 int ret;
76038
76039 preempt_disable();
76040 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76041 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
76042 preempt_enable();
76043 return ret;
76044 }
76045 @@ -739,7 +739,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
76046 */
76047 static int dyntick_save_progress_counter(struct rcu_data *rdp)
76048 {
76049 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
76050 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76051 return (rdp->dynticks_snap & 0x1) == 0;
76052 }
76053
76054 @@ -754,7 +754,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
76055 unsigned int curr;
76056 unsigned int snap;
76057
76058 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
76059 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
76060 snap = (unsigned int)rdp->dynticks_snap;
76061
76062 /*
76063 @@ -802,10 +802,10 @@ static int jiffies_till_stall_check(void)
76064 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
76065 */
76066 if (till_stall_check < 3) {
76067 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
76068 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
76069 till_stall_check = 3;
76070 } else if (till_stall_check > 300) {
76071 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
76072 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
76073 till_stall_check = 300;
76074 }
76075 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
76076 @@ -1592,7 +1592,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
76077 rsp->qlen += rdp->qlen;
76078 rdp->n_cbs_orphaned += rdp->qlen;
76079 rdp->qlen_lazy = 0;
76080 - ACCESS_ONCE(rdp->qlen) = 0;
76081 + ACCESS_ONCE_RW(rdp->qlen) = 0;
76082 }
76083
76084 /*
76085 @@ -1838,7 +1838,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
76086 }
76087 smp_mb(); /* List handling before counting for rcu_barrier(). */
76088 rdp->qlen_lazy -= count_lazy;
76089 - ACCESS_ONCE(rdp->qlen) -= count;
76090 + ACCESS_ONCE_RW(rdp->qlen) -= count;
76091 rdp->n_cbs_invoked += count;
76092
76093 /* Reinstate batch limit if we have worked down the excess. */
76094 @@ -2031,7 +2031,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
76095 /*
76096 * Do RCU core processing for the current CPU.
76097 */
76098 -static void rcu_process_callbacks(struct softirq_action *unused)
76099 +static void rcu_process_callbacks(void)
76100 {
76101 struct rcu_state *rsp;
76102
76103 @@ -2154,7 +2154,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
76104 local_irq_restore(flags);
76105 return;
76106 }
76107 - ACCESS_ONCE(rdp->qlen)++;
76108 + ACCESS_ONCE_RW(rdp->qlen)++;
76109 if (lazy)
76110 rdp->qlen_lazy++;
76111 else
76112 @@ -2363,11 +2363,11 @@ void synchronize_sched_expedited(void)
76113 * counter wrap on a 32-bit system. Quite a few more CPUs would of
76114 * course be required on a 64-bit system.
76115 */
76116 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
76117 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
76118 (ulong)atomic_long_read(&rsp->expedited_done) +
76119 ULONG_MAX / 8)) {
76120 synchronize_sched();
76121 - atomic_long_inc(&rsp->expedited_wrap);
76122 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
76123 return;
76124 }
76125
76126 @@ -2375,7 +2375,7 @@ void synchronize_sched_expedited(void)
76127 * Take a ticket. Note that atomic_inc_return() implies a
76128 * full memory barrier.
76129 */
76130 - snap = atomic_long_inc_return(&rsp->expedited_start);
76131 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
76132 firstsnap = snap;
76133 get_online_cpus();
76134 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
76135 @@ -2388,14 +2388,14 @@ void synchronize_sched_expedited(void)
76136 synchronize_sched_expedited_cpu_stop,
76137 NULL) == -EAGAIN) {
76138 put_online_cpus();
76139 - atomic_long_inc(&rsp->expedited_tryfail);
76140 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
76141
76142 /* Check to see if someone else did our work for us. */
76143 s = atomic_long_read(&rsp->expedited_done);
76144 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76145 /* ensure test happens before caller kfree */
76146 smp_mb__before_atomic_inc(); /* ^^^ */
76147 - atomic_long_inc(&rsp->expedited_workdone1);
76148 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
76149 return;
76150 }
76151
76152 @@ -2404,7 +2404,7 @@ void synchronize_sched_expedited(void)
76153 udelay(trycount * num_online_cpus());
76154 } else {
76155 wait_rcu_gp(call_rcu_sched);
76156 - atomic_long_inc(&rsp->expedited_normal);
76157 + atomic_long_inc_unchecked(&rsp->expedited_normal);
76158 return;
76159 }
76160
76161 @@ -2413,7 +2413,7 @@ void synchronize_sched_expedited(void)
76162 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
76163 /* ensure test happens before caller kfree */
76164 smp_mb__before_atomic_inc(); /* ^^^ */
76165 - atomic_long_inc(&rsp->expedited_workdone2);
76166 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
76167 return;
76168 }
76169
76170 @@ -2425,10 +2425,10 @@ void synchronize_sched_expedited(void)
76171 * period works for us.
76172 */
76173 get_online_cpus();
76174 - snap = atomic_long_read(&rsp->expedited_start);
76175 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
76176 smp_mb(); /* ensure read is before try_stop_cpus(). */
76177 }
76178 - atomic_long_inc(&rsp->expedited_stoppedcpus);
76179 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
76180
76181 /*
76182 * Everyone up to our most recent fetch is covered by our grace
76183 @@ -2437,16 +2437,16 @@ void synchronize_sched_expedited(void)
76184 * than we did already did their update.
76185 */
76186 do {
76187 - atomic_long_inc(&rsp->expedited_done_tries);
76188 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
76189 s = atomic_long_read(&rsp->expedited_done);
76190 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
76191 /* ensure test happens before caller kfree */
76192 smp_mb__before_atomic_inc(); /* ^^^ */
76193 - atomic_long_inc(&rsp->expedited_done_lost);
76194 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
76195 break;
76196 }
76197 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
76198 - atomic_long_inc(&rsp->expedited_done_exit);
76199 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
76200
76201 put_online_cpus();
76202 }
76203 @@ -2620,7 +2620,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76204 * ACCESS_ONCE() to prevent the compiler from speculating
76205 * the increment to precede the early-exit check.
76206 */
76207 - ACCESS_ONCE(rsp->n_barrier_done)++;
76208 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76209 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
76210 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
76211 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
76212 @@ -2670,7 +2670,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
76213
76214 /* Increment ->n_barrier_done to prevent duplicate work. */
76215 smp_mb(); /* Keep increment after above mechanism. */
76216 - ACCESS_ONCE(rsp->n_barrier_done)++;
76217 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
76218 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
76219 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
76220 smp_mb(); /* Keep increment before caller's subsequent code. */
76221 @@ -2715,10 +2715,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
76222 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
76223 init_callback_list(rdp);
76224 rdp->qlen_lazy = 0;
76225 - ACCESS_ONCE(rdp->qlen) = 0;
76226 + ACCESS_ONCE_RW(rdp->qlen) = 0;
76227 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
76228 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
76229 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
76230 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
76231 #ifdef CONFIG_RCU_USER_QS
76232 WARN_ON_ONCE(rdp->dynticks->in_user);
76233 #endif
76234 @@ -2754,8 +2754,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
76235 rdp->blimit = blimit;
76236 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
76237 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
76238 - atomic_set(&rdp->dynticks->dynticks,
76239 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
76240 + atomic_set_unchecked(&rdp->dynticks->dynticks,
76241 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
76242 rcu_prepare_for_idle_init(cpu);
76243 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
76244
76245 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
76246 index 4b69291..704c92e 100644
76247 --- a/kernel/rcutree.h
76248 +++ b/kernel/rcutree.h
76249 @@ -86,7 +86,7 @@ struct rcu_dynticks {
76250 long long dynticks_nesting; /* Track irq/process nesting level. */
76251 /* Process level is worth LLONG_MAX/2. */
76252 int dynticks_nmi_nesting; /* Track NMI nesting level. */
76253 - atomic_t dynticks; /* Even value for idle, else odd. */
76254 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
76255 #ifdef CONFIG_RCU_FAST_NO_HZ
76256 int dyntick_drain; /* Prepare-for-idle state variable. */
76257 unsigned long dyntick_holdoff;
76258 @@ -423,17 +423,17 @@ struct rcu_state {
76259 /* _rcu_barrier(). */
76260 /* End of fields guarded by barrier_mutex. */
76261
76262 - atomic_long_t expedited_start; /* Starting ticket. */
76263 - atomic_long_t expedited_done; /* Done ticket. */
76264 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
76265 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
76266 - atomic_long_t expedited_workdone1; /* # done by others #1. */
76267 - atomic_long_t expedited_workdone2; /* # done by others #2. */
76268 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
76269 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
76270 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
76271 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
76272 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
76273 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
76274 + atomic_long_t expedited_done; /* Done ticket. */
76275 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
76276 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
76277 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
76278 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
76279 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
76280 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
76281 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
76282 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
76283 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
76284
76285 unsigned long jiffies_force_qs; /* Time at which to invoke */
76286 /* force_quiescent_state(). */
76287 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
76288 index c1cc7e1..f62e436 100644
76289 --- a/kernel/rcutree_plugin.h
76290 +++ b/kernel/rcutree_plugin.h
76291 @@ -892,7 +892,7 @@ void synchronize_rcu_expedited(void)
76292
76293 /* Clean up and exit. */
76294 smp_mb(); /* ensure expedited GP seen before counter increment. */
76295 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
76296 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
76297 unlock_mb_ret:
76298 mutex_unlock(&sync_rcu_preempt_exp_mutex);
76299 mb_ret:
76300 @@ -1440,7 +1440,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
76301 free_cpumask_var(cm);
76302 }
76303
76304 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
76305 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
76306 .store = &rcu_cpu_kthread_task,
76307 .thread_should_run = rcu_cpu_kthread_should_run,
76308 .thread_fn = rcu_cpu_kthread,
76309 @@ -2072,7 +2072,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
76310 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
76311 printk(KERN_ERR "\t%d: (%lu %s) idle=%03x/%llx/%d %s\n",
76312 cpu, ticks_value, ticks_title,
76313 - atomic_read(&rdtp->dynticks) & 0xfff,
76314 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
76315 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
76316 fast_no_hz);
76317 }
76318 @@ -2192,7 +2192,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
76319
76320 /* Enqueue the callback on the nocb list and update counts. */
76321 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
76322 - ACCESS_ONCE(*old_rhpp) = rhp;
76323 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
76324 atomic_long_add(rhcount, &rdp->nocb_q_count);
76325 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
76326
76327 @@ -2384,12 +2384,12 @@ static int rcu_nocb_kthread(void *arg)
76328 * Extract queued callbacks, update counts, and wait
76329 * for a grace period to elapse.
76330 */
76331 - ACCESS_ONCE(rdp->nocb_head) = NULL;
76332 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
76333 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
76334 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
76335 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
76336 - ACCESS_ONCE(rdp->nocb_p_count) += c;
76337 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
76338 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
76339 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
76340 wait_rcu_gp(rdp->rsp->call_remote);
76341
76342 /* Each pass through the following loop invokes a callback. */
76343 @@ -2411,8 +2411,8 @@ static int rcu_nocb_kthread(void *arg)
76344 list = next;
76345 }
76346 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
76347 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
76348 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
76349 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
76350 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
76351 rdp->n_nocbs_invoked += c;
76352 }
76353 return 0;
76354 @@ -2438,7 +2438,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
76355 rdp = per_cpu_ptr(rsp->rda, cpu);
76356 t = kthread_run(rcu_nocb_kthread, rdp, "rcuo%d", cpu);
76357 BUG_ON(IS_ERR(t));
76358 - ACCESS_ONCE(rdp->nocb_kthread) = t;
76359 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
76360 }
76361 }
76362
76363 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
76364 index 0d095dc..1985b19 100644
76365 --- a/kernel/rcutree_trace.c
76366 +++ b/kernel/rcutree_trace.c
76367 @@ -123,7 +123,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
76368 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
76369 rdp->passed_quiesce, rdp->qs_pending);
76370 seq_printf(m, " dt=%d/%llx/%d df=%lu",
76371 - atomic_read(&rdp->dynticks->dynticks),
76372 + atomic_read_unchecked(&rdp->dynticks->dynticks),
76373 rdp->dynticks->dynticks_nesting,
76374 rdp->dynticks->dynticks_nmi_nesting,
76375 rdp->dynticks_fqs);
76376 @@ -184,17 +184,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
76377 struct rcu_state *rsp = (struct rcu_state *)m->private;
76378
76379 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",
76380 - atomic_long_read(&rsp->expedited_start),
76381 + atomic_long_read_unchecked(&rsp->expedited_start),
76382 atomic_long_read(&rsp->expedited_done),
76383 - atomic_long_read(&rsp->expedited_wrap),
76384 - atomic_long_read(&rsp->expedited_tryfail),
76385 - atomic_long_read(&rsp->expedited_workdone1),
76386 - atomic_long_read(&rsp->expedited_workdone2),
76387 - atomic_long_read(&rsp->expedited_normal),
76388 - atomic_long_read(&rsp->expedited_stoppedcpus),
76389 - atomic_long_read(&rsp->expedited_done_tries),
76390 - atomic_long_read(&rsp->expedited_done_lost),
76391 - atomic_long_read(&rsp->expedited_done_exit));
76392 + atomic_long_read_unchecked(&rsp->expedited_wrap),
76393 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
76394 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
76395 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
76396 + atomic_long_read_unchecked(&rsp->expedited_normal),
76397 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
76398 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
76399 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
76400 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
76401 return 0;
76402 }
76403
76404 diff --git a/kernel/resource.c b/kernel/resource.c
76405 index 73f35d4..4684fc4 100644
76406 --- a/kernel/resource.c
76407 +++ b/kernel/resource.c
76408 @@ -143,8 +143,18 @@ static const struct file_operations proc_iomem_operations = {
76409
76410 static int __init ioresources_init(void)
76411 {
76412 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
76413 +#ifdef CONFIG_GRKERNSEC_PROC_USER
76414 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
76415 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
76416 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
76417 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
76418 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
76419 +#endif
76420 +#else
76421 proc_create("ioports", 0, NULL, &proc_ioports_operations);
76422 proc_create("iomem", 0, NULL, &proc_iomem_operations);
76423 +#endif
76424 return 0;
76425 }
76426 __initcall(ioresources_init);
76427 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
76428 index 98ec494..4241d6d 100644
76429 --- a/kernel/rtmutex-tester.c
76430 +++ b/kernel/rtmutex-tester.c
76431 @@ -20,7 +20,7 @@
76432 #define MAX_RT_TEST_MUTEXES 8
76433
76434 static spinlock_t rttest_lock;
76435 -static atomic_t rttest_event;
76436 +static atomic_unchecked_t rttest_event;
76437
76438 struct test_thread_data {
76439 int opcode;
76440 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76441
76442 case RTTEST_LOCKCONT:
76443 td->mutexes[td->opdata] = 1;
76444 - td->event = atomic_add_return(1, &rttest_event);
76445 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76446 return 0;
76447
76448 case RTTEST_RESET:
76449 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76450 return 0;
76451
76452 case RTTEST_RESETEVENT:
76453 - atomic_set(&rttest_event, 0);
76454 + atomic_set_unchecked(&rttest_event, 0);
76455 return 0;
76456
76457 default:
76458 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76459 return ret;
76460
76461 td->mutexes[id] = 1;
76462 - td->event = atomic_add_return(1, &rttest_event);
76463 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76464 rt_mutex_lock(&mutexes[id]);
76465 - td->event = atomic_add_return(1, &rttest_event);
76466 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76467 td->mutexes[id] = 4;
76468 return 0;
76469
76470 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76471 return ret;
76472
76473 td->mutexes[id] = 1;
76474 - td->event = atomic_add_return(1, &rttest_event);
76475 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76476 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
76477 - td->event = atomic_add_return(1, &rttest_event);
76478 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76479 td->mutexes[id] = ret ? 0 : 4;
76480 return ret ? -EINTR : 0;
76481
76482 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
76483 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
76484 return ret;
76485
76486 - td->event = atomic_add_return(1, &rttest_event);
76487 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76488 rt_mutex_unlock(&mutexes[id]);
76489 - td->event = atomic_add_return(1, &rttest_event);
76490 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76491 td->mutexes[id] = 0;
76492 return 0;
76493
76494 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76495 break;
76496
76497 td->mutexes[dat] = 2;
76498 - td->event = atomic_add_return(1, &rttest_event);
76499 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76500 break;
76501
76502 default:
76503 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76504 return;
76505
76506 td->mutexes[dat] = 3;
76507 - td->event = atomic_add_return(1, &rttest_event);
76508 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76509 break;
76510
76511 case RTTEST_LOCKNOWAIT:
76512 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
76513 return;
76514
76515 td->mutexes[dat] = 1;
76516 - td->event = atomic_add_return(1, &rttest_event);
76517 + td->event = atomic_add_return_unchecked(1, &rttest_event);
76518 return;
76519
76520 default:
76521 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
76522 index 0984a21..939f183 100644
76523 --- a/kernel/sched/auto_group.c
76524 +++ b/kernel/sched/auto_group.c
76525 @@ -11,7 +11,7 @@
76526
76527 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
76528 static struct autogroup autogroup_default;
76529 -static atomic_t autogroup_seq_nr;
76530 +static atomic_unchecked_t autogroup_seq_nr;
76531
76532 void __init autogroup_init(struct task_struct *init_task)
76533 {
76534 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
76535
76536 kref_init(&ag->kref);
76537 init_rwsem(&ag->lock);
76538 - ag->id = atomic_inc_return(&autogroup_seq_nr);
76539 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
76540 ag->tg = tg;
76541 #ifdef CONFIG_RT_GROUP_SCHED
76542 /*
76543 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
76544 index 26058d0..f9d3c76 100644
76545 --- a/kernel/sched/core.c
76546 +++ b/kernel/sched/core.c
76547 @@ -3631,6 +3631,8 @@ int can_nice(const struct task_struct *p, const int nice)
76548 /* convert nice value [19,-20] to rlimit style value [1,40] */
76549 int nice_rlim = 20 - nice;
76550
76551 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
76552 +
76553 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
76554 capable(CAP_SYS_NICE));
76555 }
76556 @@ -3664,7 +3666,8 @@ SYSCALL_DEFINE1(nice, int, increment)
76557 if (nice > 19)
76558 nice = 19;
76559
76560 - if (increment < 0 && !can_nice(current, nice))
76561 + if (increment < 0 && (!can_nice(current, nice) ||
76562 + gr_handle_chroot_nice()))
76563 return -EPERM;
76564
76565 retval = security_task_setnice(current, nice);
76566 @@ -3818,6 +3821,7 @@ recheck:
76567 unsigned long rlim_rtprio =
76568 task_rlimit(p, RLIMIT_RTPRIO);
76569
76570 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
76571 /* can't set/change the rt policy */
76572 if (policy != p->policy && !rlim_rtprio)
76573 return -EPERM;
76574 @@ -4901,7 +4905,7 @@ static void migrate_tasks(unsigned int dead_cpu)
76575
76576 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
76577
76578 -static struct ctl_table sd_ctl_dir[] = {
76579 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
76580 {
76581 .procname = "sched_domain",
76582 .mode = 0555,
76583 @@ -4918,17 +4922,17 @@ static struct ctl_table sd_ctl_root[] = {
76584 {}
76585 };
76586
76587 -static struct ctl_table *sd_alloc_ctl_entry(int n)
76588 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
76589 {
76590 - struct ctl_table *entry =
76591 + ctl_table_no_const *entry =
76592 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
76593
76594 return entry;
76595 }
76596
76597 -static void sd_free_ctl_entry(struct ctl_table **tablep)
76598 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
76599 {
76600 - struct ctl_table *entry;
76601 + ctl_table_no_const *entry;
76602
76603 /*
76604 * In the intermediate directories, both the child directory and
76605 @@ -4936,22 +4940,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
76606 * will always be set. In the lowest directory the names are
76607 * static strings and all have proc handlers.
76608 */
76609 - for (entry = *tablep; entry->mode; entry++) {
76610 - if (entry->child)
76611 - sd_free_ctl_entry(&entry->child);
76612 + for (entry = tablep; entry->mode; entry++) {
76613 + if (entry->child) {
76614 + sd_free_ctl_entry(entry->child);
76615 + pax_open_kernel();
76616 + entry->child = NULL;
76617 + pax_close_kernel();
76618 + }
76619 if (entry->proc_handler == NULL)
76620 kfree(entry->procname);
76621 }
76622
76623 - kfree(*tablep);
76624 - *tablep = NULL;
76625 + kfree(tablep);
76626 }
76627
76628 static int min_load_idx = 0;
76629 static int max_load_idx = CPU_LOAD_IDX_MAX;
76630
76631 static void
76632 -set_table_entry(struct ctl_table *entry,
76633 +set_table_entry(ctl_table_no_const *entry,
76634 const char *procname, void *data, int maxlen,
76635 umode_t mode, proc_handler *proc_handler,
76636 bool load_idx)
76637 @@ -4971,7 +4978,7 @@ set_table_entry(struct ctl_table *entry,
76638 static struct ctl_table *
76639 sd_alloc_ctl_domain_table(struct sched_domain *sd)
76640 {
76641 - struct ctl_table *table = sd_alloc_ctl_entry(13);
76642 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
76643
76644 if (table == NULL)
76645 return NULL;
76646 @@ -5006,9 +5013,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
76647 return table;
76648 }
76649
76650 -static ctl_table *sd_alloc_ctl_cpu_table(int cpu)
76651 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
76652 {
76653 - struct ctl_table *entry, *table;
76654 + ctl_table_no_const *entry, *table;
76655 struct sched_domain *sd;
76656 int domain_num = 0, i;
76657 char buf[32];
76658 @@ -5035,11 +5042,13 @@ static struct ctl_table_header *sd_sysctl_header;
76659 static void register_sched_domain_sysctl(void)
76660 {
76661 int i, cpu_num = num_possible_cpus();
76662 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
76663 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
76664 char buf[32];
76665
76666 WARN_ON(sd_ctl_dir[0].child);
76667 + pax_open_kernel();
76668 sd_ctl_dir[0].child = entry;
76669 + pax_close_kernel();
76670
76671 if (entry == NULL)
76672 return;
76673 @@ -5062,8 +5071,12 @@ static void unregister_sched_domain_sysctl(void)
76674 if (sd_sysctl_header)
76675 unregister_sysctl_table(sd_sysctl_header);
76676 sd_sysctl_header = NULL;
76677 - if (sd_ctl_dir[0].child)
76678 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
76679 + if (sd_ctl_dir[0].child) {
76680 + sd_free_ctl_entry(sd_ctl_dir[0].child);
76681 + pax_open_kernel();
76682 + sd_ctl_dir[0].child = NULL;
76683 + pax_close_kernel();
76684 + }
76685 }
76686 #else
76687 static void register_sched_domain_sysctl(void)
76688 @@ -5162,7 +5175,7 @@ migration_call(struct notifier_block *nfb, unsigned long action, void *hcpu)
76689 * happens before everything else. This has to be lower priority than
76690 * the notifier in the perf_event subsystem, though.
76691 */
76692 -static struct notifier_block __cpuinitdata migration_notifier = {
76693 +static struct notifier_block migration_notifier = {
76694 .notifier_call = migration_call,
76695 .priority = CPU_PRI_MIGRATION,
76696 };
76697 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
76698 index 81fa536..6ccf96a 100644
76699 --- a/kernel/sched/fair.c
76700 +++ b/kernel/sched/fair.c
76701 @@ -830,7 +830,7 @@ void task_numa_fault(int node, int pages, bool migrated)
76702
76703 static void reset_ptenuma_scan(struct task_struct *p)
76704 {
76705 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
76706 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
76707 p->mm->numa_scan_offset = 0;
76708 }
76709
76710 @@ -3254,25 +3254,18 @@ find_idlest_cpu(struct sched_group *group, struct task_struct *p, int this_cpu)
76711 */
76712 static int select_idle_sibling(struct task_struct *p, int target)
76713 {
76714 - int cpu = smp_processor_id();
76715 - int prev_cpu = task_cpu(p);
76716 struct sched_domain *sd;
76717 struct sched_group *sg;
76718 - int i;
76719 + int i = task_cpu(p);
76720
76721 - /*
76722 - * If the task is going to be woken-up on this cpu and if it is
76723 - * already idle, then it is the right target.
76724 - */
76725 - if (target == cpu && idle_cpu(cpu))
76726 - return cpu;
76727 + if (idle_cpu(target))
76728 + return target;
76729
76730 /*
76731 - * If the task is going to be woken-up on the cpu where it previously
76732 - * ran and if it is currently idle, then it the right target.
76733 + * If the prevous cpu is cache affine and idle, don't be stupid.
76734 */
76735 - if (target == prev_cpu && idle_cpu(prev_cpu))
76736 - return prev_cpu;
76737 + if (i != target && cpus_share_cache(i, target) && idle_cpu(i))
76738 + return i;
76739
76740 /*
76741 * Otherwise, iterate the domains and find an elegible idle cpu.
76742 @@ -3286,7 +3279,7 @@ static int select_idle_sibling(struct task_struct *p, int target)
76743 goto next;
76744
76745 for_each_cpu(i, sched_group_cpus(sg)) {
76746 - if (!idle_cpu(i))
76747 + if (i == target || !idle_cpu(i))
76748 goto next;
76749 }
76750
76751 @@ -5663,7 +5656,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
76752 * run_rebalance_domains is triggered when needed from the scheduler tick.
76753 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
76754 */
76755 -static void run_rebalance_domains(struct softirq_action *h)
76756 +static void run_rebalance_domains(void)
76757 {
76758 int this_cpu = smp_processor_id();
76759 struct rq *this_rq = cpu_rq(this_cpu);
76760 diff --git a/kernel/signal.c b/kernel/signal.c
76761 index 3d09cf6..a67d2c6 100644
76762 --- a/kernel/signal.c
76763 +++ b/kernel/signal.c
76764 @@ -50,12 +50,12 @@ static struct kmem_cache *sigqueue_cachep;
76765
76766 int print_fatal_signals __read_mostly;
76767
76768 -static void __user *sig_handler(struct task_struct *t, int sig)
76769 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
76770 {
76771 return t->sighand->action[sig - 1].sa.sa_handler;
76772 }
76773
76774 -static int sig_handler_ignored(void __user *handler, int sig)
76775 +static int sig_handler_ignored(__sighandler_t handler, int sig)
76776 {
76777 /* Is it explicitly or implicitly ignored? */
76778 return handler == SIG_IGN ||
76779 @@ -64,7 +64,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
76780
76781 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
76782 {
76783 - void __user *handler;
76784 + __sighandler_t handler;
76785
76786 handler = sig_handler(t, sig);
76787
76788 @@ -368,6 +368,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
76789 atomic_inc(&user->sigpending);
76790 rcu_read_unlock();
76791
76792 + if (!override_rlimit)
76793 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
76794 +
76795 if (override_rlimit ||
76796 atomic_read(&user->sigpending) <=
76797 task_rlimit(t, RLIMIT_SIGPENDING)) {
76798 @@ -492,7 +495,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
76799
76800 int unhandled_signal(struct task_struct *tsk, int sig)
76801 {
76802 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
76803 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
76804 if (is_global_init(tsk))
76805 return 1;
76806 if (handler != SIG_IGN && handler != SIG_DFL)
76807 @@ -812,6 +815,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
76808 }
76809 }
76810
76811 + /* allow glibc communication via tgkill to other threads in our
76812 + thread group */
76813 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
76814 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
76815 + && gr_handle_signal(t, sig))
76816 + return -EPERM;
76817 +
76818 return security_task_kill(t, info, sig, 0);
76819 }
76820
76821 @@ -1194,7 +1204,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
76822 return send_signal(sig, info, p, 1);
76823 }
76824
76825 -static int
76826 +int
76827 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76828 {
76829 return send_signal(sig, info, t, 0);
76830 @@ -1231,6 +1241,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76831 unsigned long int flags;
76832 int ret, blocked, ignored;
76833 struct k_sigaction *action;
76834 + int is_unhandled = 0;
76835
76836 spin_lock_irqsave(&t->sighand->siglock, flags);
76837 action = &t->sighand->action[sig-1];
76838 @@ -1245,9 +1256,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
76839 }
76840 if (action->sa.sa_handler == SIG_DFL)
76841 t->signal->flags &= ~SIGNAL_UNKILLABLE;
76842 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
76843 + is_unhandled = 1;
76844 ret = specific_send_sig_info(sig, info, t);
76845 spin_unlock_irqrestore(&t->sighand->siglock, flags);
76846
76847 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
76848 + normal operation */
76849 + if (is_unhandled) {
76850 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
76851 + gr_handle_crash(t, sig);
76852 + }
76853 +
76854 return ret;
76855 }
76856
76857 @@ -1314,8 +1334,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
76858 ret = check_kill_permission(sig, info, p);
76859 rcu_read_unlock();
76860
76861 - if (!ret && sig)
76862 + if (!ret && sig) {
76863 ret = do_send_sig_info(sig, info, p, true);
76864 + if (!ret)
76865 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
76866 + }
76867
76868 return ret;
76869 }
76870 @@ -2852,7 +2875,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
76871 int error = -ESRCH;
76872
76873 rcu_read_lock();
76874 - p = find_task_by_vpid(pid);
76875 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
76876 + /* allow glibc communication via tgkill to other threads in our
76877 + thread group */
76878 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
76879 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
76880 + p = find_task_by_vpid_unrestricted(pid);
76881 + else
76882 +#endif
76883 + p = find_task_by_vpid(pid);
76884 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
76885 error = check_kill_permission(sig, info, p);
76886 /*
76887 @@ -3135,8 +3166,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
76888 }
76889 seg = get_fs();
76890 set_fs(KERNEL_DS);
76891 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
76892 - (stack_t __force __user *) &uoss,
76893 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
76894 + (stack_t __force_user *) &uoss,
76895 compat_user_stack_pointer());
76896 set_fs(seg);
76897 if (ret >= 0 && uoss_ptr) {
76898 diff --git a/kernel/smp.c b/kernel/smp.c
76899 index 69f38bd..77bbf12 100644
76900 --- a/kernel/smp.c
76901 +++ b/kernel/smp.c
76902 @@ -77,7 +77,7 @@ hotplug_cfd(struct notifier_block *nfb, unsigned long action, void *hcpu)
76903 return NOTIFY_OK;
76904 }
76905
76906 -static struct notifier_block __cpuinitdata hotplug_cfd_notifier = {
76907 +static struct notifier_block hotplug_cfd_notifier = {
76908 .notifier_call = hotplug_cfd,
76909 };
76910
76911 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
76912 index d6c5fc0..530560c 100644
76913 --- a/kernel/smpboot.c
76914 +++ b/kernel/smpboot.c
76915 @@ -275,7 +275,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
76916 }
76917 smpboot_unpark_thread(plug_thread, cpu);
76918 }
76919 - list_add(&plug_thread->list, &hotplug_threads);
76920 + pax_list_add(&plug_thread->list, &hotplug_threads);
76921 out:
76922 mutex_unlock(&smpboot_threads_lock);
76923 return ret;
76924 @@ -292,7 +292,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
76925 {
76926 get_online_cpus();
76927 mutex_lock(&smpboot_threads_lock);
76928 - list_del(&plug_thread->list);
76929 + pax_list_del(&plug_thread->list);
76930 smpboot_destroy_threads(plug_thread);
76931 mutex_unlock(&smpboot_threads_lock);
76932 put_online_cpus();
76933 diff --git a/kernel/softirq.c b/kernel/softirq.c
76934 index ed567ba..e71dabf 100644
76935 --- a/kernel/softirq.c
76936 +++ b/kernel/softirq.c
76937 @@ -53,11 +53,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
76938 EXPORT_SYMBOL(irq_stat);
76939 #endif
76940
76941 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
76942 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
76943
76944 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
76945
76946 -char *softirq_to_name[NR_SOFTIRQS] = {
76947 +const char * const softirq_to_name[NR_SOFTIRQS] = {
76948 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
76949 "TASKLET", "SCHED", "HRTIMER", "RCU"
76950 };
76951 @@ -244,7 +244,7 @@ restart:
76952 kstat_incr_softirqs_this_cpu(vec_nr);
76953
76954 trace_softirq_entry(vec_nr);
76955 - h->action(h);
76956 + h->action();
76957 trace_softirq_exit(vec_nr);
76958 if (unlikely(prev_count != preempt_count())) {
76959 printk(KERN_ERR "huh, entered softirq %u %s %p"
76960 @@ -391,7 +391,7 @@ void __raise_softirq_irqoff(unsigned int nr)
76961 or_softirq_pending(1UL << nr);
76962 }
76963
76964 -void open_softirq(int nr, void (*action)(struct softirq_action *))
76965 +void __init open_softirq(int nr, void (*action)(void))
76966 {
76967 softirq_vec[nr].action = action;
76968 }
76969 @@ -447,7 +447,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
76970
76971 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
76972
76973 -static void tasklet_action(struct softirq_action *a)
76974 +static void tasklet_action(void)
76975 {
76976 struct tasklet_struct *list;
76977
76978 @@ -482,7 +482,7 @@ static void tasklet_action(struct softirq_action *a)
76979 }
76980 }
76981
76982 -static void tasklet_hi_action(struct softirq_action *a)
76983 +static void tasklet_hi_action(void)
76984 {
76985 struct tasklet_struct *list;
76986
76987 @@ -718,7 +718,7 @@ static int __cpuinit remote_softirq_cpu_notify(struct notifier_block *self,
76988 return NOTIFY_OK;
76989 }
76990
76991 -static struct notifier_block __cpuinitdata remote_softirq_cpu_notifier = {
76992 +static struct notifier_block remote_softirq_cpu_notifier = {
76993 .notifier_call = remote_softirq_cpu_notify,
76994 };
76995
76996 @@ -835,11 +835,11 @@ static int __cpuinit cpu_callback(struct notifier_block *nfb,
76997 return NOTIFY_OK;
76998 }
76999
77000 -static struct notifier_block __cpuinitdata cpu_nfb = {
77001 +static struct notifier_block cpu_nfb = {
77002 .notifier_call = cpu_callback
77003 };
77004
77005 -static struct smp_hotplug_thread softirq_threads = {
77006 +static struct smp_hotplug_thread softirq_threads __read_only = {
77007 .store = &ksoftirqd,
77008 .thread_should_run = ksoftirqd_should_run,
77009 .thread_fn = run_ksoftirqd,
77010 diff --git a/kernel/srcu.c b/kernel/srcu.c
77011 index 2b85982..d52ab26 100644
77012 --- a/kernel/srcu.c
77013 +++ b/kernel/srcu.c
77014 @@ -305,9 +305,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
77015 preempt_disable();
77016 idx = rcu_dereference_index_check(sp->completed,
77017 rcu_read_lock_sched_held()) & 0x1;
77018 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77019 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
77020 smp_mb(); /* B */ /* Avoid leaking the critical section. */
77021 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77022 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
77023 preempt_enable();
77024 return idx;
77025 }
77026 @@ -323,7 +323,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
77027 {
77028 preempt_disable();
77029 smp_mb(); /* C */ /* Avoid leaking the critical section. */
77030 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77031 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
77032 preempt_enable();
77033 }
77034 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
77035 diff --git a/kernel/stop_machine.c b/kernel/stop_machine.c
77036 index 2f194e9..2c05ea9 100644
77037 --- a/kernel/stop_machine.c
77038 +++ b/kernel/stop_machine.c
77039 @@ -362,7 +362,7 @@ static int __cpuinit cpu_stop_cpu_callback(struct notifier_block *nfb,
77040 * cpu notifiers. It currently shares the same priority as sched
77041 * migration_notifier.
77042 */
77043 -static struct notifier_block __cpuinitdata cpu_stop_cpu_notifier = {
77044 +static struct notifier_block cpu_stop_cpu_notifier = {
77045 .notifier_call = cpu_stop_cpu_callback,
77046 .priority = 10,
77047 };
77048 diff --git a/kernel/sys.c b/kernel/sys.c
77049 index 265b376..4e42ef5 100644
77050 --- a/kernel/sys.c
77051 +++ b/kernel/sys.c
77052 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
77053 error = -EACCES;
77054 goto out;
77055 }
77056 +
77057 + if (gr_handle_chroot_setpriority(p, niceval)) {
77058 + error = -EACCES;
77059 + goto out;
77060 + }
77061 +
77062 no_nice = security_task_setnice(p, niceval);
77063 if (no_nice) {
77064 error = no_nice;
77065 @@ -595,6 +601,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
77066 goto error;
77067 }
77068
77069 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
77070 + goto error;
77071 +
77072 if (rgid != (gid_t) -1 ||
77073 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
77074 new->sgid = new->egid;
77075 @@ -630,6 +639,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
77076 old = current_cred();
77077
77078 retval = -EPERM;
77079 +
77080 + if (gr_check_group_change(kgid, kgid, kgid))
77081 + goto error;
77082 +
77083 if (nsown_capable(CAP_SETGID))
77084 new->gid = new->egid = new->sgid = new->fsgid = kgid;
77085 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
77086 @@ -647,7 +660,7 @@ error:
77087 /*
77088 * change the user struct in a credentials set to match the new UID
77089 */
77090 -static int set_user(struct cred *new)
77091 +int set_user(struct cred *new)
77092 {
77093 struct user_struct *new_user;
77094
77095 @@ -727,6 +740,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
77096 goto error;
77097 }
77098
77099 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
77100 + goto error;
77101 +
77102 if (!uid_eq(new->uid, old->uid)) {
77103 retval = set_user(new);
77104 if (retval < 0)
77105 @@ -777,6 +793,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
77106 old = current_cred();
77107
77108 retval = -EPERM;
77109 +
77110 + if (gr_check_crash_uid(kuid))
77111 + goto error;
77112 + if (gr_check_user_change(kuid, kuid, kuid))
77113 + goto error;
77114 +
77115 if (nsown_capable(CAP_SETUID)) {
77116 new->suid = new->uid = kuid;
77117 if (!uid_eq(kuid, old->uid)) {
77118 @@ -846,6 +868,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
77119 goto error;
77120 }
77121
77122 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
77123 + goto error;
77124 +
77125 if (ruid != (uid_t) -1) {
77126 new->uid = kruid;
77127 if (!uid_eq(kruid, old->uid)) {
77128 @@ -928,6 +953,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
77129 goto error;
77130 }
77131
77132 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
77133 + goto error;
77134 +
77135 if (rgid != (gid_t) -1)
77136 new->gid = krgid;
77137 if (egid != (gid_t) -1)
77138 @@ -981,6 +1009,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77139 if (!uid_valid(kuid))
77140 return old_fsuid;
77141
77142 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
77143 + goto error;
77144 +
77145 new = prepare_creds();
77146 if (!new)
77147 return old_fsuid;
77148 @@ -995,6 +1026,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
77149 }
77150 }
77151
77152 +error:
77153 abort_creds(new);
77154 return old_fsuid;
77155
77156 @@ -1027,12 +1059,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
77157 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
77158 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
77159 nsown_capable(CAP_SETGID)) {
77160 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
77161 + goto error;
77162 +
77163 if (!gid_eq(kgid, old->fsgid)) {
77164 new->fsgid = kgid;
77165 goto change_okay;
77166 }
77167 }
77168
77169 +error:
77170 abort_creds(new);
77171 return old_fsgid;
77172
77173 @@ -1340,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
77174 return -EFAULT;
77175
77176 down_read(&uts_sem);
77177 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
77178 + error = __copy_to_user(name->sysname, &utsname()->sysname,
77179 __OLD_UTS_LEN);
77180 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
77181 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
77182 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
77183 __OLD_UTS_LEN);
77184 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
77185 - error |= __copy_to_user(&name->release, &utsname()->release,
77186 + error |= __copy_to_user(name->release, &utsname()->release,
77187 __OLD_UTS_LEN);
77188 error |= __put_user(0, name->release + __OLD_UTS_LEN);
77189 - error |= __copy_to_user(&name->version, &utsname()->version,
77190 + error |= __copy_to_user(name->version, &utsname()->version,
77191 __OLD_UTS_LEN);
77192 error |= __put_user(0, name->version + __OLD_UTS_LEN);
77193 - error |= __copy_to_user(&name->machine, &utsname()->machine,
77194 + error |= __copy_to_user(name->machine, &utsname()->machine,
77195 __OLD_UTS_LEN);
77196 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
77197 up_read(&uts_sem);
77198 @@ -2026,7 +2062,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
77199 error = get_dumpable(me->mm);
77200 break;
77201 case PR_SET_DUMPABLE:
77202 - if (arg2 < 0 || arg2 > 1) {
77203 + if (arg2 > 1) {
77204 error = -EINVAL;
77205 break;
77206 }
77207 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
77208 index c88878d..e4fa5d1 100644
77209 --- a/kernel/sysctl.c
77210 +++ b/kernel/sysctl.c
77211 @@ -92,7 +92,6 @@
77212
77213
77214 #if defined(CONFIG_SYSCTL)
77215 -
77216 /* External variables not in a header file. */
77217 extern int sysctl_overcommit_memory;
77218 extern int sysctl_overcommit_ratio;
77219 @@ -172,10 +171,8 @@ static int proc_taint(struct ctl_table *table, int write,
77220 void __user *buffer, size_t *lenp, loff_t *ppos);
77221 #endif
77222
77223 -#ifdef CONFIG_PRINTK
77224 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77225 void __user *buffer, size_t *lenp, loff_t *ppos);
77226 -#endif
77227
77228 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
77229 void __user *buffer, size_t *lenp, loff_t *ppos);
77230 @@ -206,6 +203,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
77231
77232 #endif
77233
77234 +extern struct ctl_table grsecurity_table[];
77235 +
77236 static struct ctl_table kern_table[];
77237 static struct ctl_table vm_table[];
77238 static struct ctl_table fs_table[];
77239 @@ -220,6 +219,20 @@ extern struct ctl_table epoll_table[];
77240 int sysctl_legacy_va_layout;
77241 #endif
77242
77243 +#ifdef CONFIG_PAX_SOFTMODE
77244 +static ctl_table pax_table[] = {
77245 + {
77246 + .procname = "softmode",
77247 + .data = &pax_softmode,
77248 + .maxlen = sizeof(unsigned int),
77249 + .mode = 0600,
77250 + .proc_handler = &proc_dointvec,
77251 + },
77252 +
77253 + { }
77254 +};
77255 +#endif
77256 +
77257 /* The default sysctl tables: */
77258
77259 static struct ctl_table sysctl_base_table[] = {
77260 @@ -268,6 +281,22 @@ static int max_extfrag_threshold = 1000;
77261 #endif
77262
77263 static struct ctl_table kern_table[] = {
77264 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
77265 + {
77266 + .procname = "grsecurity",
77267 + .mode = 0500,
77268 + .child = grsecurity_table,
77269 + },
77270 +#endif
77271 +
77272 +#ifdef CONFIG_PAX_SOFTMODE
77273 + {
77274 + .procname = "pax",
77275 + .mode = 0500,
77276 + .child = pax_table,
77277 + },
77278 +#endif
77279 +
77280 {
77281 .procname = "sched_child_runs_first",
77282 .data = &sysctl_sched_child_runs_first,
77283 @@ -593,7 +622,7 @@ static struct ctl_table kern_table[] = {
77284 .data = &modprobe_path,
77285 .maxlen = KMOD_PATH_LEN,
77286 .mode = 0644,
77287 - .proc_handler = proc_dostring,
77288 + .proc_handler = proc_dostring_modpriv,
77289 },
77290 {
77291 .procname = "modules_disabled",
77292 @@ -760,16 +789,20 @@ static struct ctl_table kern_table[] = {
77293 .extra1 = &zero,
77294 .extra2 = &one,
77295 },
77296 +#endif
77297 {
77298 .procname = "kptr_restrict",
77299 .data = &kptr_restrict,
77300 .maxlen = sizeof(int),
77301 .mode = 0644,
77302 .proc_handler = proc_dointvec_minmax_sysadmin,
77303 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77304 + .extra1 = &two,
77305 +#else
77306 .extra1 = &zero,
77307 +#endif
77308 .extra2 = &two,
77309 },
77310 -#endif
77311 {
77312 .procname = "ngroups_max",
77313 .data = &ngroups_max,
77314 @@ -1266,6 +1299,13 @@ static struct ctl_table vm_table[] = {
77315 .proc_handler = proc_dointvec_minmax,
77316 .extra1 = &zero,
77317 },
77318 + {
77319 + .procname = "heap_stack_gap",
77320 + .data = &sysctl_heap_stack_gap,
77321 + .maxlen = sizeof(sysctl_heap_stack_gap),
77322 + .mode = 0644,
77323 + .proc_handler = proc_doulongvec_minmax,
77324 + },
77325 #else
77326 {
77327 .procname = "nr_trim_pages",
77328 @@ -1716,6 +1756,16 @@ int proc_dostring(struct ctl_table *table, int write,
77329 buffer, lenp, ppos);
77330 }
77331
77332 +int proc_dostring_modpriv(struct ctl_table *table, int write,
77333 + void __user *buffer, size_t *lenp, loff_t *ppos)
77334 +{
77335 + if (write && !capable(CAP_SYS_MODULE))
77336 + return -EPERM;
77337 +
77338 + return _proc_do_string(table->data, table->maxlen, write,
77339 + buffer, lenp, ppos);
77340 +}
77341 +
77342 static size_t proc_skip_spaces(char **buf)
77343 {
77344 size_t ret;
77345 @@ -1821,6 +1871,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
77346 len = strlen(tmp);
77347 if (len > *size)
77348 len = *size;
77349 + if (len > sizeof(tmp))
77350 + len = sizeof(tmp);
77351 if (copy_to_user(*buf, tmp, len))
77352 return -EFAULT;
77353 *size -= len;
77354 @@ -1985,7 +2037,7 @@ int proc_dointvec(struct ctl_table *table, int write,
77355 static int proc_taint(struct ctl_table *table, int write,
77356 void __user *buffer, size_t *lenp, loff_t *ppos)
77357 {
77358 - struct ctl_table t;
77359 + ctl_table_no_const t;
77360 unsigned long tmptaint = get_taint();
77361 int err;
77362
77363 @@ -2013,7 +2065,6 @@ static int proc_taint(struct ctl_table *table, int write,
77364 return err;
77365 }
77366
77367 -#ifdef CONFIG_PRINTK
77368 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77369 void __user *buffer, size_t *lenp, loff_t *ppos)
77370 {
77371 @@ -2022,7 +2073,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
77372
77373 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
77374 }
77375 -#endif
77376
77377 struct do_proc_dointvec_minmax_conv_param {
77378 int *min;
77379 @@ -2169,8 +2219,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
77380 *i = val;
77381 } else {
77382 val = convdiv * (*i) / convmul;
77383 - if (!first)
77384 + if (!first) {
77385 err = proc_put_char(&buffer, &left, '\t');
77386 + if (err)
77387 + break;
77388 + }
77389 err = proc_put_long(&buffer, &left, val, false);
77390 if (err)
77391 break;
77392 @@ -2562,6 +2615,12 @@ int proc_dostring(struct ctl_table *table, int write,
77393 return -ENOSYS;
77394 }
77395
77396 +int proc_dostring_modpriv(struct ctl_table *table, int write,
77397 + void __user *buffer, size_t *lenp, loff_t *ppos)
77398 +{
77399 + return -ENOSYS;
77400 +}
77401 +
77402 int proc_dointvec(struct ctl_table *table, int write,
77403 void __user *buffer, size_t *lenp, loff_t *ppos)
77404 {
77405 @@ -2618,5 +2677,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
77406 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
77407 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
77408 EXPORT_SYMBOL(proc_dostring);
77409 +EXPORT_SYMBOL(proc_dostring_modpriv);
77410 EXPORT_SYMBOL(proc_doulongvec_minmax);
77411 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
77412 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
77413 index 0ddf3a0..a199f50 100644
77414 --- a/kernel/sysctl_binary.c
77415 +++ b/kernel/sysctl_binary.c
77416 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
77417 int i;
77418
77419 set_fs(KERNEL_DS);
77420 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
77421 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
77422 set_fs(old_fs);
77423 if (result < 0)
77424 goto out_kfree;
77425 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
77426 }
77427
77428 set_fs(KERNEL_DS);
77429 - result = vfs_write(file, buffer, str - buffer, &pos);
77430 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
77431 set_fs(old_fs);
77432 if (result < 0)
77433 goto out_kfree;
77434 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
77435 int i;
77436
77437 set_fs(KERNEL_DS);
77438 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
77439 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
77440 set_fs(old_fs);
77441 if (result < 0)
77442 goto out_kfree;
77443 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
77444 }
77445
77446 set_fs(KERNEL_DS);
77447 - result = vfs_write(file, buffer, str - buffer, &pos);
77448 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
77449 set_fs(old_fs);
77450 if (result < 0)
77451 goto out_kfree;
77452 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
77453 int i;
77454
77455 set_fs(KERNEL_DS);
77456 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
77457 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
77458 set_fs(old_fs);
77459 if (result < 0)
77460 goto out;
77461 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
77462 __le16 dnaddr;
77463
77464 set_fs(KERNEL_DS);
77465 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
77466 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
77467 set_fs(old_fs);
77468 if (result < 0)
77469 goto out;
77470 @@ -1234,7 +1234,7 @@ static ssize_t bin_dn_node_address(struct file *file,
77471 le16_to_cpu(dnaddr) & 0x3ff);
77472
77473 set_fs(KERNEL_DS);
77474 - result = vfs_write(file, buf, len, &pos);
77475 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
77476 set_fs(old_fs);
77477 if (result < 0)
77478 goto out;
77479 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
77480 index 145bb4d..b2aa969 100644
77481 --- a/kernel/taskstats.c
77482 +++ b/kernel/taskstats.c
77483 @@ -28,9 +28,12 @@
77484 #include <linux/fs.h>
77485 #include <linux/file.h>
77486 #include <linux/pid_namespace.h>
77487 +#include <linux/grsecurity.h>
77488 #include <net/genetlink.h>
77489 #include <linux/atomic.h>
77490
77491 +extern int gr_is_taskstats_denied(int pid);
77492 +
77493 /*
77494 * Maximum length of a cpumask that can be specified in
77495 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
77496 @@ -570,6 +573,9 @@ err:
77497
77498 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
77499 {
77500 + if (gr_is_taskstats_denied(current->pid))
77501 + return -EACCES;
77502 +
77503 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
77504 return cmd_attr_register_cpumask(info);
77505 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
77506 diff --git a/kernel/time.c b/kernel/time.c
77507 index d226c6a..c7c0960 100644
77508 --- a/kernel/time.c
77509 +++ b/kernel/time.c
77510 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
77511 return error;
77512
77513 if (tz) {
77514 + /* we log in do_settimeofday called below, so don't log twice
77515 + */
77516 + if (!tv)
77517 + gr_log_timechange();
77518 +
77519 sys_tz = *tz;
77520 update_vsyscall_tz();
77521 if (firsttime) {
77522 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
77523 index f11d83b..d016d91 100644
77524 --- a/kernel/time/alarmtimer.c
77525 +++ b/kernel/time/alarmtimer.c
77526 @@ -750,7 +750,7 @@ static int __init alarmtimer_init(void)
77527 struct platform_device *pdev;
77528 int error = 0;
77529 int i;
77530 - struct k_clock alarm_clock = {
77531 + static struct k_clock alarm_clock = {
77532 .clock_getres = alarm_clock_getres,
77533 .clock_get = alarm_clock_get,
77534 .timer_create = alarm_timer_create,
77535 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
77536 index f113755..ec24223 100644
77537 --- a/kernel/time/tick-broadcast.c
77538 +++ b/kernel/time/tick-broadcast.c
77539 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
77540 * then clear the broadcast bit.
77541 */
77542 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
77543 - int cpu = smp_processor_id();
77544 + cpu = smp_processor_id();
77545
77546 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
77547 tick_broadcast_clear_oneshot(cpu);
77548 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
77549 index cbc6acb..3a77191 100644
77550 --- a/kernel/time/timekeeping.c
77551 +++ b/kernel/time/timekeeping.c
77552 @@ -15,6 +15,7 @@
77553 #include <linux/init.h>
77554 #include <linux/mm.h>
77555 #include <linux/sched.h>
77556 +#include <linux/grsecurity.h>
77557 #include <linux/syscore_ops.h>
77558 #include <linux/clocksource.h>
77559 #include <linux/jiffies.h>
77560 @@ -412,6 +413,8 @@ int do_settimeofday(const struct timespec *tv)
77561 if (!timespec_valid_strict(tv))
77562 return -EINVAL;
77563
77564 + gr_log_timechange();
77565 +
77566 write_seqlock_irqsave(&tk->lock, flags);
77567
77568 timekeeping_forward_now(tk);
77569 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
77570 index af5a7e9..715611a 100644
77571 --- a/kernel/time/timer_list.c
77572 +++ b/kernel/time/timer_list.c
77573 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
77574
77575 static void print_name_offset(struct seq_file *m, void *sym)
77576 {
77577 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77578 + SEQ_printf(m, "<%p>", NULL);
77579 +#else
77580 char symname[KSYM_NAME_LEN];
77581
77582 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
77583 SEQ_printf(m, "<%pK>", sym);
77584 else
77585 SEQ_printf(m, "%s", symname);
77586 +#endif
77587 }
77588
77589 static void
77590 @@ -112,7 +116,11 @@ next_one:
77591 static void
77592 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
77593 {
77594 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77595 + SEQ_printf(m, " .base: %p\n", NULL);
77596 +#else
77597 SEQ_printf(m, " .base: %pK\n", base);
77598 +#endif
77599 SEQ_printf(m, " .index: %d\n",
77600 base->index);
77601 SEQ_printf(m, " .resolution: %Lu nsecs\n",
77602 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
77603 {
77604 struct proc_dir_entry *pe;
77605
77606 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
77607 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
77608 +#else
77609 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
77610 +#endif
77611 if (!pe)
77612 return -ENOMEM;
77613 return 0;
77614 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
77615 index 0b537f2..40d6c20 100644
77616 --- a/kernel/time/timer_stats.c
77617 +++ b/kernel/time/timer_stats.c
77618 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
77619 static unsigned long nr_entries;
77620 static struct entry entries[MAX_ENTRIES];
77621
77622 -static atomic_t overflow_count;
77623 +static atomic_unchecked_t overflow_count;
77624
77625 /*
77626 * The entries are in a hash-table, for fast lookup:
77627 @@ -140,7 +140,7 @@ static void reset_entries(void)
77628 nr_entries = 0;
77629 memset(entries, 0, sizeof(entries));
77630 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
77631 - atomic_set(&overflow_count, 0);
77632 + atomic_set_unchecked(&overflow_count, 0);
77633 }
77634
77635 static struct entry *alloc_entry(void)
77636 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
77637 if (likely(entry))
77638 entry->count++;
77639 else
77640 - atomic_inc(&overflow_count);
77641 + atomic_inc_unchecked(&overflow_count);
77642
77643 out_unlock:
77644 raw_spin_unlock_irqrestore(lock, flags);
77645 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
77646
77647 static void print_name_offset(struct seq_file *m, unsigned long addr)
77648 {
77649 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77650 + seq_printf(m, "<%p>", NULL);
77651 +#else
77652 char symname[KSYM_NAME_LEN];
77653
77654 if (lookup_symbol_name(addr, symname) < 0)
77655 - seq_printf(m, "<%p>", (void *)addr);
77656 + seq_printf(m, "<%pK>", (void *)addr);
77657 else
77658 seq_printf(m, "%s", symname);
77659 +#endif
77660 }
77661
77662 static int tstats_show(struct seq_file *m, void *v)
77663 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
77664
77665 seq_puts(m, "Timer Stats Version: v0.2\n");
77666 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
77667 - if (atomic_read(&overflow_count))
77668 + if (atomic_read_unchecked(&overflow_count))
77669 seq_printf(m, "Overflow: %d entries\n",
77670 - atomic_read(&overflow_count));
77671 + atomic_read_unchecked(&overflow_count));
77672
77673 for (i = 0; i < nr_entries; i++) {
77674 entry = entries + i;
77675 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
77676 {
77677 struct proc_dir_entry *pe;
77678
77679 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
77680 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
77681 +#else
77682 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
77683 +#endif
77684 if (!pe)
77685 return -ENOMEM;
77686 return 0;
77687 diff --git a/kernel/timer.c b/kernel/timer.c
77688 index 367d008..1ee9ed9 100644
77689 --- a/kernel/timer.c
77690 +++ b/kernel/timer.c
77691 @@ -1363,7 +1363,7 @@ void update_process_times(int user_tick)
77692 /*
77693 * This function runs timers and the timer-tq in bottom half context.
77694 */
77695 -static void run_timer_softirq(struct softirq_action *h)
77696 +static void run_timer_softirq(void)
77697 {
77698 struct tvec_base *base = __this_cpu_read(tvec_bases);
77699
77700 @@ -1772,7 +1772,7 @@ static int __cpuinit timer_cpu_notify(struct notifier_block *self,
77701 return NOTIFY_OK;
77702 }
77703
77704 -static struct notifier_block __cpuinitdata timers_nb = {
77705 +static struct notifier_block timers_nb = {
77706 .notifier_call = timer_cpu_notify,
77707 };
77708
77709 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
77710 index c0bd030..62a1927 100644
77711 --- a/kernel/trace/blktrace.c
77712 +++ b/kernel/trace/blktrace.c
77713 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
77714 struct blk_trace *bt = filp->private_data;
77715 char buf[16];
77716
77717 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
77718 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
77719
77720 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
77721 }
77722 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
77723 return 1;
77724
77725 bt = buf->chan->private_data;
77726 - atomic_inc(&bt->dropped);
77727 + atomic_inc_unchecked(&bt->dropped);
77728 return 0;
77729 }
77730
77731 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
77732
77733 bt->dir = dir;
77734 bt->dev = dev;
77735 - atomic_set(&bt->dropped, 0);
77736 + atomic_set_unchecked(&bt->dropped, 0);
77737
77738 ret = -EIO;
77739 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
77740 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
77741 index 43defd1..76da436 100644
77742 --- a/kernel/trace/ftrace.c
77743 +++ b/kernel/trace/ftrace.c
77744 @@ -1874,12 +1874,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
77745 if (unlikely(ftrace_disabled))
77746 return 0;
77747
77748 + ret = ftrace_arch_code_modify_prepare();
77749 + FTRACE_WARN_ON(ret);
77750 + if (ret)
77751 + return 0;
77752 +
77753 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
77754 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
77755 if (ret) {
77756 ftrace_bug(ret, ip);
77757 - return 0;
77758 }
77759 - return 1;
77760 + return ret ? 0 : 1;
77761 }
77762
77763 /*
77764 @@ -2965,7 +2970,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
77765
77766 int
77767 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
77768 - void *data)
77769 + void *data)
77770 {
77771 struct ftrace_func_probe *entry;
77772 struct ftrace_page *pg;
77773 @@ -3832,8 +3837,10 @@ static int ftrace_process_locs(struct module *mod,
77774 if (!count)
77775 return 0;
77776
77777 + pax_open_kernel();
77778 sort(start, count, sizeof(*start),
77779 ftrace_cmp_ips, ftrace_swap_ips);
77780 + pax_close_kernel();
77781
77782 start_pg = ftrace_allocate_pages(count);
77783 if (!start_pg)
77784 @@ -4559,8 +4566,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
77785 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
77786
77787 static int ftrace_graph_active;
77788 -static struct notifier_block ftrace_suspend_notifier;
77789 -
77790 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
77791 {
77792 return 0;
77793 @@ -4704,6 +4709,10 @@ ftrace_suspend_notifier_call(struct notifier_block *bl, unsigned long state,
77794 return NOTIFY_DONE;
77795 }
77796
77797 +static struct notifier_block ftrace_suspend_notifier = {
77798 + .notifier_call = ftrace_suspend_notifier_call
77799 +};
77800 +
77801 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
77802 trace_func_graph_ent_t entryfunc)
77803 {
77804 @@ -4717,7 +4726,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
77805 goto out;
77806 }
77807
77808 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
77809 register_pm_notifier(&ftrace_suspend_notifier);
77810
77811 ftrace_graph_active++;
77812 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
77813 index ce8514f..8233573 100644
77814 --- a/kernel/trace/ring_buffer.c
77815 +++ b/kernel/trace/ring_buffer.c
77816 @@ -346,9 +346,9 @@ struct buffer_data_page {
77817 */
77818 struct buffer_page {
77819 struct list_head list; /* list of buffer pages */
77820 - local_t write; /* index for next write */
77821 + local_unchecked_t write; /* index for next write */
77822 unsigned read; /* index for next read */
77823 - local_t entries; /* entries on this page */
77824 + local_unchecked_t entries; /* entries on this page */
77825 unsigned long real_end; /* real end of data */
77826 struct buffer_data_page *page; /* Actual data page */
77827 };
77828 @@ -461,8 +461,8 @@ struct ring_buffer_per_cpu {
77829 unsigned long last_overrun;
77830 local_t entries_bytes;
77831 local_t entries;
77832 - local_t overrun;
77833 - local_t commit_overrun;
77834 + local_unchecked_t overrun;
77835 + local_unchecked_t commit_overrun;
77836 local_t dropped_events;
77837 local_t committing;
77838 local_t commits;
77839 @@ -861,8 +861,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
77840 *
77841 * We add a counter to the write field to denote this.
77842 */
77843 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
77844 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
77845 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
77846 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
77847
77848 /*
77849 * Just make sure we have seen our old_write and synchronize
77850 @@ -890,8 +890,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
77851 * cmpxchg to only update if an interrupt did not already
77852 * do it for us. If the cmpxchg fails, we don't care.
77853 */
77854 - (void)local_cmpxchg(&next_page->write, old_write, val);
77855 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
77856 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
77857 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
77858
77859 /*
77860 * No need to worry about races with clearing out the commit.
77861 @@ -1250,12 +1250,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
77862
77863 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
77864 {
77865 - return local_read(&bpage->entries) & RB_WRITE_MASK;
77866 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
77867 }
77868
77869 static inline unsigned long rb_page_write(struct buffer_page *bpage)
77870 {
77871 - return local_read(&bpage->write) & RB_WRITE_MASK;
77872 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
77873 }
77874
77875 static int
77876 @@ -1350,7 +1350,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
77877 * bytes consumed in ring buffer from here.
77878 * Increment overrun to account for the lost events.
77879 */
77880 - local_add(page_entries, &cpu_buffer->overrun);
77881 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
77882 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
77883 }
77884
77885 @@ -1906,7 +1906,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
77886 * it is our responsibility to update
77887 * the counters.
77888 */
77889 - local_add(entries, &cpu_buffer->overrun);
77890 + local_add_unchecked(entries, &cpu_buffer->overrun);
77891 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
77892
77893 /*
77894 @@ -2056,7 +2056,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77895 if (tail == BUF_PAGE_SIZE)
77896 tail_page->real_end = 0;
77897
77898 - local_sub(length, &tail_page->write);
77899 + local_sub_unchecked(length, &tail_page->write);
77900 return;
77901 }
77902
77903 @@ -2091,7 +2091,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77904 rb_event_set_padding(event);
77905
77906 /* Set the write back to the previous setting */
77907 - local_sub(length, &tail_page->write);
77908 + local_sub_unchecked(length, &tail_page->write);
77909 return;
77910 }
77911
77912 @@ -2103,7 +2103,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
77913
77914 /* Set write to end of buffer */
77915 length = (tail + length) - BUF_PAGE_SIZE;
77916 - local_sub(length, &tail_page->write);
77917 + local_sub_unchecked(length, &tail_page->write);
77918 }
77919
77920 /*
77921 @@ -2129,7 +2129,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
77922 * about it.
77923 */
77924 if (unlikely(next_page == commit_page)) {
77925 - local_inc(&cpu_buffer->commit_overrun);
77926 + local_inc_unchecked(&cpu_buffer->commit_overrun);
77927 goto out_reset;
77928 }
77929
77930 @@ -2185,7 +2185,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
77931 cpu_buffer->tail_page) &&
77932 (cpu_buffer->commit_page ==
77933 cpu_buffer->reader_page))) {
77934 - local_inc(&cpu_buffer->commit_overrun);
77935 + local_inc_unchecked(&cpu_buffer->commit_overrun);
77936 goto out_reset;
77937 }
77938 }
77939 @@ -2233,7 +2233,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
77940 length += RB_LEN_TIME_EXTEND;
77941
77942 tail_page = cpu_buffer->tail_page;
77943 - write = local_add_return(length, &tail_page->write);
77944 + write = local_add_return_unchecked(length, &tail_page->write);
77945
77946 /* set write to only the index of the write */
77947 write &= RB_WRITE_MASK;
77948 @@ -2250,7 +2250,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
77949 kmemcheck_annotate_bitfield(event, bitfield);
77950 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
77951
77952 - local_inc(&tail_page->entries);
77953 + local_inc_unchecked(&tail_page->entries);
77954
77955 /*
77956 * If this is the first commit on the page, then update
77957 @@ -2283,7 +2283,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
77958
77959 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
77960 unsigned long write_mask =
77961 - local_read(&bpage->write) & ~RB_WRITE_MASK;
77962 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
77963 unsigned long event_length = rb_event_length(event);
77964 /*
77965 * This is on the tail page. It is possible that
77966 @@ -2293,7 +2293,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
77967 */
77968 old_index += write_mask;
77969 new_index += write_mask;
77970 - index = local_cmpxchg(&bpage->write, old_index, new_index);
77971 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
77972 if (index == old_index) {
77973 /* update counters */
77974 local_sub(event_length, &cpu_buffer->entries_bytes);
77975 @@ -2632,7 +2632,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
77976
77977 /* Do the likely case first */
77978 if (likely(bpage->page == (void *)addr)) {
77979 - local_dec(&bpage->entries);
77980 + local_dec_unchecked(&bpage->entries);
77981 return;
77982 }
77983
77984 @@ -2644,7 +2644,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
77985 start = bpage;
77986 do {
77987 if (bpage->page == (void *)addr) {
77988 - local_dec(&bpage->entries);
77989 + local_dec_unchecked(&bpage->entries);
77990 return;
77991 }
77992 rb_inc_page(cpu_buffer, &bpage);
77993 @@ -2926,7 +2926,7 @@ static inline unsigned long
77994 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
77995 {
77996 return local_read(&cpu_buffer->entries) -
77997 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
77998 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
77999 }
78000
78001 /**
78002 @@ -3015,7 +3015,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
78003 return 0;
78004
78005 cpu_buffer = buffer->buffers[cpu];
78006 - ret = local_read(&cpu_buffer->overrun);
78007 + ret = local_read_unchecked(&cpu_buffer->overrun);
78008
78009 return ret;
78010 }
78011 @@ -3038,7 +3038,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
78012 return 0;
78013
78014 cpu_buffer = buffer->buffers[cpu];
78015 - ret = local_read(&cpu_buffer->commit_overrun);
78016 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
78017
78018 return ret;
78019 }
78020 @@ -3105,7 +3105,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
78021 /* if you care about this being correct, lock the buffer */
78022 for_each_buffer_cpu(buffer, cpu) {
78023 cpu_buffer = buffer->buffers[cpu];
78024 - overruns += local_read(&cpu_buffer->overrun);
78025 + overruns += local_read_unchecked(&cpu_buffer->overrun);
78026 }
78027
78028 return overruns;
78029 @@ -3281,8 +3281,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78030 /*
78031 * Reset the reader page to size zero.
78032 */
78033 - local_set(&cpu_buffer->reader_page->write, 0);
78034 - local_set(&cpu_buffer->reader_page->entries, 0);
78035 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78036 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78037 local_set(&cpu_buffer->reader_page->page->commit, 0);
78038 cpu_buffer->reader_page->real_end = 0;
78039
78040 @@ -3316,7 +3316,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
78041 * want to compare with the last_overrun.
78042 */
78043 smp_mb();
78044 - overwrite = local_read(&(cpu_buffer->overrun));
78045 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
78046
78047 /*
78048 * Here's the tricky part.
78049 @@ -3886,8 +3886,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78050
78051 cpu_buffer->head_page
78052 = list_entry(cpu_buffer->pages, struct buffer_page, list);
78053 - local_set(&cpu_buffer->head_page->write, 0);
78054 - local_set(&cpu_buffer->head_page->entries, 0);
78055 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
78056 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
78057 local_set(&cpu_buffer->head_page->page->commit, 0);
78058
78059 cpu_buffer->head_page->read = 0;
78060 @@ -3897,14 +3897,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
78061
78062 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
78063 INIT_LIST_HEAD(&cpu_buffer->new_pages);
78064 - local_set(&cpu_buffer->reader_page->write, 0);
78065 - local_set(&cpu_buffer->reader_page->entries, 0);
78066 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
78067 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
78068 local_set(&cpu_buffer->reader_page->page->commit, 0);
78069 cpu_buffer->reader_page->read = 0;
78070
78071 local_set(&cpu_buffer->entries_bytes, 0);
78072 - local_set(&cpu_buffer->overrun, 0);
78073 - local_set(&cpu_buffer->commit_overrun, 0);
78074 + local_set_unchecked(&cpu_buffer->overrun, 0);
78075 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
78076 local_set(&cpu_buffer->dropped_events, 0);
78077 local_set(&cpu_buffer->entries, 0);
78078 local_set(&cpu_buffer->committing, 0);
78079 @@ -4308,8 +4308,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
78080 rb_init_page(bpage);
78081 bpage = reader->page;
78082 reader->page = *data_page;
78083 - local_set(&reader->write, 0);
78084 - local_set(&reader->entries, 0);
78085 + local_set_unchecked(&reader->write, 0);
78086 + local_set_unchecked(&reader->entries, 0);
78087 reader->read = 0;
78088 *data_page = bpage;
78089
78090 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
78091 index 3c13e46..883d039 100644
78092 --- a/kernel/trace/trace.c
78093 +++ b/kernel/trace/trace.c
78094 @@ -4465,10 +4465,9 @@ static const struct file_operations tracing_dyn_info_fops = {
78095 };
78096 #endif
78097
78098 -static struct dentry *d_tracer;
78099 -
78100 struct dentry *tracing_init_dentry(void)
78101 {
78102 + static struct dentry *d_tracer;
78103 static int once;
78104
78105 if (d_tracer)
78106 @@ -4488,10 +4487,9 @@ struct dentry *tracing_init_dentry(void)
78107 return d_tracer;
78108 }
78109
78110 -static struct dentry *d_percpu;
78111 -
78112 struct dentry *tracing_dentry_percpu(void)
78113 {
78114 + static struct dentry *d_percpu;
78115 static int once;
78116 struct dentry *d_tracer;
78117
78118 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
78119 index 880073d..42db7c3 100644
78120 --- a/kernel/trace/trace_events.c
78121 +++ b/kernel/trace/trace_events.c
78122 @@ -1330,10 +1330,6 @@ static LIST_HEAD(ftrace_module_file_list);
78123 struct ftrace_module_file_ops {
78124 struct list_head list;
78125 struct module *mod;
78126 - struct file_operations id;
78127 - struct file_operations enable;
78128 - struct file_operations format;
78129 - struct file_operations filter;
78130 };
78131
78132 static struct ftrace_module_file_ops *
78133 @@ -1354,17 +1350,12 @@ trace_create_file_ops(struct module *mod)
78134
78135 file_ops->mod = mod;
78136
78137 - file_ops->id = ftrace_event_id_fops;
78138 - file_ops->id.owner = mod;
78139 -
78140 - file_ops->enable = ftrace_enable_fops;
78141 - file_ops->enable.owner = mod;
78142 -
78143 - file_ops->filter = ftrace_event_filter_fops;
78144 - file_ops->filter.owner = mod;
78145 -
78146 - file_ops->format = ftrace_event_format_fops;
78147 - file_ops->format.owner = mod;
78148 + pax_open_kernel();
78149 + mod->trace_id.owner = mod;
78150 + mod->trace_enable.owner = mod;
78151 + mod->trace_filter.owner = mod;
78152 + mod->trace_format.owner = mod;
78153 + pax_close_kernel();
78154
78155 list_add(&file_ops->list, &ftrace_module_file_list);
78156
78157 @@ -1388,8 +1379,8 @@ static void trace_module_add_events(struct module *mod)
78158
78159 for_each_event(call, start, end) {
78160 __trace_add_event_call(*call, mod,
78161 - &file_ops->id, &file_ops->enable,
78162 - &file_ops->filter, &file_ops->format);
78163 + &mod->trace_id, &mod->trace_enable,
78164 + &mod->trace_filter, &mod->trace_format);
78165 }
78166 }
78167
78168 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
78169 index fd3c8aa..5f324a6 100644
78170 --- a/kernel/trace/trace_mmiotrace.c
78171 +++ b/kernel/trace/trace_mmiotrace.c
78172 @@ -24,7 +24,7 @@ struct header_iter {
78173 static struct trace_array *mmio_trace_array;
78174 static bool overrun_detected;
78175 static unsigned long prev_overruns;
78176 -static atomic_t dropped_count;
78177 +static atomic_unchecked_t dropped_count;
78178
78179 static void mmio_reset_data(struct trace_array *tr)
78180 {
78181 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
78182
78183 static unsigned long count_overruns(struct trace_iterator *iter)
78184 {
78185 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
78186 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
78187 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
78188
78189 if (over > prev_overruns)
78190 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
78191 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
78192 sizeof(*entry), 0, pc);
78193 if (!event) {
78194 - atomic_inc(&dropped_count);
78195 + atomic_inc_unchecked(&dropped_count);
78196 return;
78197 }
78198 entry = ring_buffer_event_data(event);
78199 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
78200 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
78201 sizeof(*entry), 0, pc);
78202 if (!event) {
78203 - atomic_inc(&dropped_count);
78204 + atomic_inc_unchecked(&dropped_count);
78205 return;
78206 }
78207 entry = ring_buffer_event_data(event);
78208 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
78209 index 194d796..76edb8f 100644
78210 --- a/kernel/trace/trace_output.c
78211 +++ b/kernel/trace/trace_output.c
78212 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
78213
78214 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
78215 if (!IS_ERR(p)) {
78216 - p = mangle_path(s->buffer + s->len, p, "\n");
78217 + p = mangle_path(s->buffer + s->len, p, "\n\\");
78218 if (p) {
78219 s->len = p - s->buffer;
78220 return 1;
78221 @@ -852,14 +852,16 @@ int register_ftrace_event(struct trace_event *event)
78222 goto out;
78223 }
78224
78225 + pax_open_kernel();
78226 if (event->funcs->trace == NULL)
78227 - event->funcs->trace = trace_nop_print;
78228 + *(void **)&event->funcs->trace = trace_nop_print;
78229 if (event->funcs->raw == NULL)
78230 - event->funcs->raw = trace_nop_print;
78231 + *(void **)&event->funcs->raw = trace_nop_print;
78232 if (event->funcs->hex == NULL)
78233 - event->funcs->hex = trace_nop_print;
78234 + *(void **)&event->funcs->hex = trace_nop_print;
78235 if (event->funcs->binary == NULL)
78236 - event->funcs->binary = trace_nop_print;
78237 + *(void **)&event->funcs->binary = trace_nop_print;
78238 + pax_close_kernel();
78239
78240 key = event->type & (EVENT_HASHSIZE - 1);
78241
78242 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
78243 index 42ca822..cdcacc6 100644
78244 --- a/kernel/trace/trace_stack.c
78245 +++ b/kernel/trace/trace_stack.c
78246 @@ -52,7 +52,7 @@ static inline void check_stack(void)
78247 return;
78248
78249 /* we do not handle interrupt stacks yet */
78250 - if (!object_is_on_stack(&this_size))
78251 + if (!object_starts_on_stack(&this_size))
78252 return;
78253
78254 local_irq_save(flags);
78255 diff --git a/kernel/user.c b/kernel/user.c
78256 index 33acb5e..57ebfd4 100644
78257 --- a/kernel/user.c
78258 +++ b/kernel/user.c
78259 @@ -47,9 +47,7 @@ struct user_namespace init_user_ns = {
78260 .count = 4294967295U,
78261 },
78262 },
78263 - .kref = {
78264 - .refcount = ATOMIC_INIT(3),
78265 - },
78266 + .count = ATOMIC_INIT(3),
78267 .owner = GLOBAL_ROOT_UID,
78268 .group = GLOBAL_ROOT_GID,
78269 .proc_inum = PROC_USER_INIT_INO,
78270 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
78271 index 2b042c4..24f8ec3 100644
78272 --- a/kernel/user_namespace.c
78273 +++ b/kernel/user_namespace.c
78274 @@ -78,7 +78,7 @@ int create_user_ns(struct cred *new)
78275 return ret;
78276 }
78277
78278 - kref_init(&ns->kref);
78279 + atomic_set(&ns->count, 1);
78280 /* Leave the new->user_ns reference with the new user namespace. */
78281 ns->parent = parent_ns;
78282 ns->owner = owner;
78283 @@ -104,15 +104,16 @@ int unshare_userns(unsigned long unshare_flags, struct cred **new_cred)
78284 return create_user_ns(cred);
78285 }
78286
78287 -void free_user_ns(struct kref *kref)
78288 +void free_user_ns(struct user_namespace *ns)
78289 {
78290 - struct user_namespace *parent, *ns =
78291 - container_of(kref, struct user_namespace, kref);
78292 + struct user_namespace *parent;
78293
78294 - parent = ns->parent;
78295 - proc_free_inum(ns->proc_inum);
78296 - kmem_cache_free(user_ns_cachep, ns);
78297 - put_user_ns(parent);
78298 + do {
78299 + parent = ns->parent;
78300 + proc_free_inum(ns->proc_inum);
78301 + kmem_cache_free(user_ns_cachep, ns);
78302 + ns = parent;
78303 + } while (atomic_dec_and_test(&parent->count));
78304 }
78305 EXPORT_SYMBOL(free_user_ns);
78306
78307 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
78308 index 63da38c..639904e 100644
78309 --- a/kernel/utsname_sysctl.c
78310 +++ b/kernel/utsname_sysctl.c
78311 @@ -46,7 +46,7 @@ static void put_uts(ctl_table *table, int write, void *which)
78312 static int proc_do_uts_string(ctl_table *table, int write,
78313 void __user *buffer, size_t *lenp, loff_t *ppos)
78314 {
78315 - struct ctl_table uts_table;
78316 + ctl_table_no_const uts_table;
78317 int r;
78318 memcpy(&uts_table, table, sizeof(uts_table));
78319 uts_table.data = get_uts(table, write);
78320 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
78321 index 75a2ab3..5961da7 100644
78322 --- a/kernel/watchdog.c
78323 +++ b/kernel/watchdog.c
78324 @@ -527,7 +527,7 @@ int proc_dowatchdog(struct ctl_table *table, int write,
78325 }
78326 #endif /* CONFIG_SYSCTL */
78327
78328 -static struct smp_hotplug_thread watchdog_threads = {
78329 +static struct smp_hotplug_thread watchdog_threads __read_only = {
78330 .store = &softlockup_watchdog,
78331 .thread_should_run = watchdog_should_run,
78332 .thread_fn = watchdog,
78333 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
78334 index 67604e5..fe94fb1 100644
78335 --- a/lib/Kconfig.debug
78336 +++ b/lib/Kconfig.debug
78337 @@ -550,7 +550,7 @@ config DEBUG_MUTEXES
78338
78339 config DEBUG_LOCK_ALLOC
78340 bool "Lock debugging: detect incorrect freeing of live locks"
78341 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78342 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78343 select DEBUG_SPINLOCK
78344 select DEBUG_MUTEXES
78345 select LOCKDEP
78346 @@ -564,7 +564,7 @@ config DEBUG_LOCK_ALLOC
78347
78348 config PROVE_LOCKING
78349 bool "Lock debugging: prove locking correctness"
78350 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78351 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78352 select LOCKDEP
78353 select DEBUG_SPINLOCK
78354 select DEBUG_MUTEXES
78355 @@ -670,7 +670,7 @@ config LOCKDEP
78356
78357 config LOCK_STAT
78358 bool "Lock usage statistics"
78359 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
78360 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
78361 select LOCKDEP
78362 select DEBUG_SPINLOCK
78363 select DEBUG_MUTEXES
78364 @@ -1278,6 +1278,7 @@ config LATENCYTOP
78365 depends on DEBUG_KERNEL
78366 depends on STACKTRACE_SUPPORT
78367 depends on PROC_FS
78368 + depends on !GRKERNSEC_HIDESYM
78369 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
78370 select KALLSYMS
78371 select KALLSYMS_ALL
78372 @@ -1306,7 +1307,7 @@ config INTERVAL_TREE_TEST
78373
78374 config PROVIDE_OHCI1394_DMA_INIT
78375 bool "Remote debugging over FireWire early on boot"
78376 - depends on PCI && X86
78377 + depends on PCI && X86 && !GRKERNSEC
78378 help
78379 If you want to debug problems which hang or crash the kernel early
78380 on boot and the crashing machine has a FireWire port, you can use
78381 @@ -1335,7 +1336,7 @@ config PROVIDE_OHCI1394_DMA_INIT
78382
78383 config FIREWIRE_OHCI_REMOTE_DMA
78384 bool "Remote debugging over FireWire with firewire-ohci"
78385 - depends on FIREWIRE_OHCI
78386 + depends on FIREWIRE_OHCI && !GRKERNSEC
78387 help
78388 This option lets you use the FireWire bus for remote debugging
78389 with help of the firewire-ohci driver. It enables unfiltered
78390 diff --git a/lib/Makefile b/lib/Makefile
78391 index 02ed6c0..bd243da 100644
78392 --- a/lib/Makefile
78393 +++ b/lib/Makefile
78394 @@ -47,7 +47,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
78395
78396 obj-$(CONFIG_BTREE) += btree.o
78397 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
78398 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
78399 +obj-y += list_debug.o
78400 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
78401
78402 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
78403 diff --git a/lib/bitmap.c b/lib/bitmap.c
78404 index 06f7e4f..f3cf2b0 100644
78405 --- a/lib/bitmap.c
78406 +++ b/lib/bitmap.c
78407 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
78408 {
78409 int c, old_c, totaldigits, ndigits, nchunks, nbits;
78410 u32 chunk;
78411 - const char __user __force *ubuf = (const char __user __force *)buf;
78412 + const char __user *ubuf = (const char __force_user *)buf;
78413
78414 bitmap_zero(maskp, nmaskbits);
78415
78416 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
78417 {
78418 if (!access_ok(VERIFY_READ, ubuf, ulen))
78419 return -EFAULT;
78420 - return __bitmap_parse((const char __force *)ubuf,
78421 + return __bitmap_parse((const char __force_kernel *)ubuf,
78422 ulen, 1, maskp, nmaskbits);
78423
78424 }
78425 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
78426 {
78427 unsigned a, b;
78428 int c, old_c, totaldigits;
78429 - const char __user __force *ubuf = (const char __user __force *)buf;
78430 + const char __user *ubuf = (const char __force_user *)buf;
78431 int exp_digit, in_range;
78432
78433 totaldigits = c = 0;
78434 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
78435 {
78436 if (!access_ok(VERIFY_READ, ubuf, ulen))
78437 return -EFAULT;
78438 - return __bitmap_parselist((const char __force *)ubuf,
78439 + return __bitmap_parselist((const char __force_kernel *)ubuf,
78440 ulen, 1, maskp, nmaskbits);
78441 }
78442 EXPORT_SYMBOL(bitmap_parselist_user);
78443 diff --git a/lib/bug.c b/lib/bug.c
78444 index d0cdf14..4d07bd2 100644
78445 --- a/lib/bug.c
78446 +++ b/lib/bug.c
78447 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
78448 return BUG_TRAP_TYPE_NONE;
78449
78450 bug = find_bug(bugaddr);
78451 + if (!bug)
78452 + return BUG_TRAP_TYPE_NONE;
78453
78454 file = NULL;
78455 line = 0;
78456 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
78457 index d11808c..dc2d6f8 100644
78458 --- a/lib/debugobjects.c
78459 +++ b/lib/debugobjects.c
78460 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
78461 if (limit > 4)
78462 return;
78463
78464 - is_on_stack = object_is_on_stack(addr);
78465 + is_on_stack = object_starts_on_stack(addr);
78466 if (is_on_stack == onstack)
78467 return;
78468
78469 diff --git a/lib/devres.c b/lib/devres.c
78470 index 80b9c76..9e32279 100644
78471 --- a/lib/devres.c
78472 +++ b/lib/devres.c
78473 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
78474 void devm_iounmap(struct device *dev, void __iomem *addr)
78475 {
78476 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
78477 - (void *)addr));
78478 + (void __force *)addr));
78479 iounmap(addr);
78480 }
78481 EXPORT_SYMBOL(devm_iounmap);
78482 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
78483 {
78484 ioport_unmap(addr);
78485 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
78486 - devm_ioport_map_match, (void *)addr));
78487 + devm_ioport_map_match, (void __force *)addr));
78488 }
78489 EXPORT_SYMBOL(devm_ioport_unmap);
78490
78491 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
78492 index 5e396ac..58d5de1 100644
78493 --- a/lib/dma-debug.c
78494 +++ b/lib/dma-debug.c
78495 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
78496
78497 void dma_debug_add_bus(struct bus_type *bus)
78498 {
78499 - struct notifier_block *nb;
78500 + notifier_block_no_const *nb;
78501
78502 if (global_disable)
78503 return;
78504 @@ -942,7 +942,7 @@ out:
78505
78506 static void check_for_stack(struct device *dev, void *addr)
78507 {
78508 - if (object_is_on_stack(addr))
78509 + if (object_starts_on_stack(addr))
78510 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
78511 "stack [addr=%p]\n", addr);
78512 }
78513 diff --git a/lib/inflate.c b/lib/inflate.c
78514 index 013a761..c28f3fc 100644
78515 --- a/lib/inflate.c
78516 +++ b/lib/inflate.c
78517 @@ -269,7 +269,7 @@ static void free(void *where)
78518 malloc_ptr = free_mem_ptr;
78519 }
78520 #else
78521 -#define malloc(a) kmalloc(a, GFP_KERNEL)
78522 +#define malloc(a) kmalloc((a), GFP_KERNEL)
78523 #define free(a) kfree(a)
78524 #endif
78525
78526 diff --git a/lib/ioremap.c b/lib/ioremap.c
78527 index 0c9216c..863bd89 100644
78528 --- a/lib/ioremap.c
78529 +++ b/lib/ioremap.c
78530 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
78531 unsigned long next;
78532
78533 phys_addr -= addr;
78534 - pmd = pmd_alloc(&init_mm, pud, addr);
78535 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
78536 if (!pmd)
78537 return -ENOMEM;
78538 do {
78539 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
78540 unsigned long next;
78541
78542 phys_addr -= addr;
78543 - pud = pud_alloc(&init_mm, pgd, addr);
78544 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
78545 if (!pud)
78546 return -ENOMEM;
78547 do {
78548 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
78549 index bd2bea9..6b3c95e 100644
78550 --- a/lib/is_single_threaded.c
78551 +++ b/lib/is_single_threaded.c
78552 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
78553 struct task_struct *p, *t;
78554 bool ret;
78555
78556 + if (!mm)
78557 + return true;
78558 +
78559 if (atomic_read(&task->signal->live) != 1)
78560 return false;
78561
78562 diff --git a/lib/kobject.c b/lib/kobject.c
78563 index e07ee1f..998489d 100644
78564 --- a/lib/kobject.c
78565 +++ b/lib/kobject.c
78566 @@ -852,9 +852,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
78567
78568
78569 static DEFINE_SPINLOCK(kobj_ns_type_lock);
78570 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
78571 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
78572
78573 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
78574 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
78575 {
78576 enum kobj_ns_type type = ops->type;
78577 int error;
78578 diff --git a/lib/list_debug.c b/lib/list_debug.c
78579 index c24c2f7..0475b78 100644
78580 --- a/lib/list_debug.c
78581 +++ b/lib/list_debug.c
78582 @@ -11,7 +11,9 @@
78583 #include <linux/bug.h>
78584 #include <linux/kernel.h>
78585 #include <linux/rculist.h>
78586 +#include <linux/mm.h>
78587
78588 +#ifdef CONFIG_DEBUG_LIST
78589 /*
78590 * Insert a new entry between two known consecutive entries.
78591 *
78592 @@ -19,21 +21,32 @@
78593 * the prev/next entries already!
78594 */
78595
78596 -void __list_add(struct list_head *new,
78597 - struct list_head *prev,
78598 - struct list_head *next)
78599 +static bool __list_add_debug(struct list_head *new,
78600 + struct list_head *prev,
78601 + struct list_head *next)
78602 {
78603 - WARN(next->prev != prev,
78604 + if (WARN(next->prev != prev,
78605 "list_add corruption. next->prev should be "
78606 "prev (%p), but was %p. (next=%p).\n",
78607 - prev, next->prev, next);
78608 - WARN(prev->next != next,
78609 + prev, next->prev, next) ||
78610 + WARN(prev->next != next,
78611 "list_add corruption. prev->next should be "
78612 "next (%p), but was %p. (prev=%p).\n",
78613 - next, prev->next, prev);
78614 - WARN(new == prev || new == next,
78615 + next, prev->next, prev) ||
78616 + WARN(new == prev || new == next,
78617 "list_add double add: new=%p, prev=%p, next=%p.\n",
78618 - new, prev, next);
78619 + new, prev, next))
78620 + return false;
78621 + return true;
78622 +}
78623 +
78624 +void __list_add(struct list_head *new,
78625 + struct list_head *prev,
78626 + struct list_head *next)
78627 +{
78628 + if (!__list_add_debug(new, prev, next))
78629 + return;
78630 +
78631 next->prev = new;
78632 new->next = next;
78633 new->prev = prev;
78634 @@ -41,7 +54,7 @@ void __list_add(struct list_head *new,
78635 }
78636 EXPORT_SYMBOL(__list_add);
78637
78638 -void __list_del_entry(struct list_head *entry)
78639 +static bool __list_del_entry_debug(struct list_head *entry)
78640 {
78641 struct list_head *prev, *next;
78642
78643 @@ -60,9 +73,16 @@ void __list_del_entry(struct list_head *entry)
78644 WARN(next->prev != entry,
78645 "list_del corruption. next->prev should be %p, "
78646 "but was %p\n", entry, next->prev))
78647 + return false;
78648 + return true;
78649 +}
78650 +
78651 +void __list_del_entry(struct list_head *entry)
78652 +{
78653 + if (!__list_del_entry_debug(entry))
78654 return;
78655
78656 - __list_del(prev, next);
78657 + __list_del(entry->prev, entry->next);
78658 }
78659 EXPORT_SYMBOL(__list_del_entry);
78660
78661 @@ -86,15 +106,85 @@ EXPORT_SYMBOL(list_del);
78662 void __list_add_rcu(struct list_head *new,
78663 struct list_head *prev, struct list_head *next)
78664 {
78665 - WARN(next->prev != prev,
78666 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
78667 - prev, next->prev, next);
78668 - WARN(prev->next != next,
78669 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
78670 - next, prev->next, prev);
78671 + if (!__list_add_debug(new, prev, next))
78672 + return;
78673 +
78674 new->next = next;
78675 new->prev = prev;
78676 rcu_assign_pointer(list_next_rcu(prev), new);
78677 next->prev = new;
78678 }
78679 EXPORT_SYMBOL(__list_add_rcu);
78680 +#endif
78681 +
78682 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
78683 +{
78684 +#ifdef CONFIG_DEBUG_LIST
78685 + if (!__list_add_debug(new, prev, next))
78686 + return;
78687 +#endif
78688 +
78689 + pax_open_kernel();
78690 + next->prev = new;
78691 + new->next = next;
78692 + new->prev = prev;
78693 + prev->next = new;
78694 + pax_close_kernel();
78695 +}
78696 +EXPORT_SYMBOL(__pax_list_add);
78697 +
78698 +void pax_list_del(struct list_head *entry)
78699 +{
78700 +#ifdef CONFIG_DEBUG_LIST
78701 + if (!__list_del_entry_debug(entry))
78702 + return;
78703 +#endif
78704 +
78705 + pax_open_kernel();
78706 + __list_del(entry->prev, entry->next);
78707 + entry->next = LIST_POISON1;
78708 + entry->prev = LIST_POISON2;
78709 + pax_close_kernel();
78710 +}
78711 +EXPORT_SYMBOL(pax_list_del);
78712 +
78713 +void pax_list_del_init(struct list_head *entry)
78714 +{
78715 + pax_open_kernel();
78716 + __list_del(entry->prev, entry->next);
78717 + INIT_LIST_HEAD(entry);
78718 + pax_close_kernel();
78719 +}
78720 +EXPORT_SYMBOL(pax_list_del_init);
78721 +
78722 +void __pax_list_add_rcu(struct list_head *new,
78723 + struct list_head *prev, struct list_head *next)
78724 +{
78725 +#ifdef CONFIG_DEBUG_LIST
78726 + if (!__list_add_debug(new, prev, next))
78727 + return;
78728 +#endif
78729 +
78730 + pax_open_kernel();
78731 + new->next = next;
78732 + new->prev = prev;
78733 + rcu_assign_pointer(list_next_rcu(prev), new);
78734 + next->prev = new;
78735 + pax_close_kernel();
78736 +}
78737 +EXPORT_SYMBOL(__pax_list_add_rcu);
78738 +
78739 +void pax_list_del_rcu(struct list_head *entry)
78740 +{
78741 +#ifdef CONFIG_DEBUG_LIST
78742 + if (!__list_del_entry_debug(entry))
78743 + return;
78744 +#endif
78745 +
78746 + pax_open_kernel();
78747 + __list_del(entry->prev, entry->next);
78748 + entry->next = LIST_POISON1;
78749 + entry->prev = LIST_POISON2;
78750 + pax_close_kernel();
78751 +}
78752 +EXPORT_SYMBOL(pax_list_del_rcu);
78753 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
78754 index e796429..6e38f9f 100644
78755 --- a/lib/radix-tree.c
78756 +++ b/lib/radix-tree.c
78757 @@ -92,7 +92,7 @@ struct radix_tree_preload {
78758 int nr;
78759 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
78760 };
78761 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
78762 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
78763
78764 static inline void *ptr_to_indirect(void *ptr)
78765 {
78766 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
78767 index bb2b201..46abaf9 100644
78768 --- a/lib/strncpy_from_user.c
78769 +++ b/lib/strncpy_from_user.c
78770 @@ -21,7 +21,7 @@
78771 */
78772 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
78773 {
78774 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78775 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78776 long res = 0;
78777
78778 /*
78779 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
78780 index a28df52..3d55877 100644
78781 --- a/lib/strnlen_user.c
78782 +++ b/lib/strnlen_user.c
78783 @@ -26,7 +26,7 @@
78784 */
78785 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
78786 {
78787 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78788 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
78789 long align, res = 0;
78790 unsigned long c;
78791
78792 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
78793 index 196b069..358f342 100644
78794 --- a/lib/swiotlb.c
78795 +++ b/lib/swiotlb.c
78796 @@ -642,7 +642,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
78797
78798 void
78799 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
78800 - dma_addr_t dev_addr)
78801 + dma_addr_t dev_addr, struct dma_attrs *attrs)
78802 {
78803 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
78804
78805 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
78806 index fab33a9..3b5fe68 100644
78807 --- a/lib/vsprintf.c
78808 +++ b/lib/vsprintf.c
78809 @@ -16,6 +16,9 @@
78810 * - scnprintf and vscnprintf
78811 */
78812
78813 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78814 +#define __INCLUDED_BY_HIDESYM 1
78815 +#endif
78816 #include <stdarg.h>
78817 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
78818 #include <linux/types.h>
78819 @@ -541,7 +544,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
78820 char sym[KSYM_SYMBOL_LEN];
78821 if (ext == 'B')
78822 sprint_backtrace(sym, value);
78823 - else if (ext != 'f' && ext != 's')
78824 + else if (ext != 'f' && ext != 's' && ext != 'a')
78825 sprint_symbol(sym, value);
78826 else
78827 sprint_symbol_no_offset(sym, value);
78828 @@ -974,7 +977,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
78829 return number(buf, end, *(const netdev_features_t *)addr, spec);
78830 }
78831
78832 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78833 +int kptr_restrict __read_mostly = 2;
78834 +#else
78835 int kptr_restrict __read_mostly;
78836 +#endif
78837
78838 /*
78839 * Show a '%p' thing. A kernel extension is that the '%p' is followed
78840 @@ -988,6 +995,8 @@ int kptr_restrict __read_mostly;
78841 * - 'S' For symbolic direct pointers with offset
78842 * - 's' For symbolic direct pointers without offset
78843 * - 'B' For backtraced symbolic direct pointers with offset
78844 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
78845 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
78846 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
78847 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
78848 * - 'M' For a 6-byte MAC address, it prints the address in the
78849 @@ -1043,12 +1052,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78850
78851 if (!ptr && *fmt != 'K') {
78852 /*
78853 - * Print (null) with the same width as a pointer so it makes
78854 + * Print (nil) with the same width as a pointer so it makes
78855 * tabular output look nice.
78856 */
78857 if (spec.field_width == -1)
78858 spec.field_width = default_width;
78859 - return string(buf, end, "(null)", spec);
78860 + return string(buf, end, "(nil)", spec);
78861 }
78862
78863 switch (*fmt) {
78864 @@ -1058,6 +1067,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78865 /* Fallthrough */
78866 case 'S':
78867 case 's':
78868 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78869 + break;
78870 +#else
78871 + return symbol_string(buf, end, ptr, spec, *fmt);
78872 +#endif
78873 + case 'A':
78874 + case 'a':
78875 case 'B':
78876 return symbol_string(buf, end, ptr, spec, *fmt);
78877 case 'R':
78878 @@ -1098,6 +1114,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78879 va_end(va);
78880 return buf;
78881 }
78882 + case 'P':
78883 + break;
78884 case 'K':
78885 /*
78886 * %pK cannot be used in IRQ context because its test
78887 @@ -1121,6 +1139,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
78888 }
78889 break;
78890 }
78891 +
78892 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78893 + /* 'P' = approved pointers to copy to userland,
78894 + as in the /proc/kallsyms case, as we make it display nothing
78895 + for non-root users, and the real contents for root users
78896 + Also ignore 'K' pointers, since we force their NULLing for non-root users
78897 + above
78898 + */
78899 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
78900 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
78901 + dump_stack();
78902 + ptr = NULL;
78903 + }
78904 +#endif
78905 +
78906 spec.flags |= SMALL;
78907 if (spec.field_width == -1) {
78908 spec.field_width = default_width;
78909 @@ -1842,11 +1875,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
78910 typeof(type) value; \
78911 if (sizeof(type) == 8) { \
78912 args = PTR_ALIGN(args, sizeof(u32)); \
78913 - *(u32 *)&value = *(u32 *)args; \
78914 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
78915 + *(u32 *)&value = *(const u32 *)args; \
78916 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
78917 } else { \
78918 args = PTR_ALIGN(args, sizeof(type)); \
78919 - value = *(typeof(type) *)args; \
78920 + value = *(const typeof(type) *)args; \
78921 } \
78922 args += sizeof(type); \
78923 value; \
78924 @@ -1909,7 +1942,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
78925 case FORMAT_TYPE_STR: {
78926 const char *str_arg = args;
78927 args += strlen(str_arg) + 1;
78928 - str = string(str, end, (char *)str_arg, spec);
78929 + str = string(str, end, str_arg, spec);
78930 break;
78931 }
78932
78933 diff --git a/localversion-grsec b/localversion-grsec
78934 new file mode 100644
78935 index 0000000..7cd6065
78936 --- /dev/null
78937 +++ b/localversion-grsec
78938 @@ -0,0 +1 @@
78939 +-grsec
78940 diff --git a/mm/Kconfig b/mm/Kconfig
78941 index 278e3ab..87c384d 100644
78942 --- a/mm/Kconfig
78943 +++ b/mm/Kconfig
78944 @@ -286,10 +286,10 @@ config KSM
78945 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
78946
78947 config DEFAULT_MMAP_MIN_ADDR
78948 - int "Low address space to protect from user allocation"
78949 + int "Low address space to protect from user allocation"
78950 depends on MMU
78951 - default 4096
78952 - help
78953 + default 65536
78954 + help
78955 This is the portion of low virtual memory which should be protected
78956 from userspace allocation. Keeping a user from writing to low pages
78957 can help reduce the impact of kernel NULL pointer bugs.
78958 @@ -320,7 +320,7 @@ config MEMORY_FAILURE
78959
78960 config HWPOISON_INJECT
78961 tristate "HWPoison pages injector"
78962 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
78963 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
78964 select PROC_PAGE_MONITOR
78965
78966 config NOMMU_INITIAL_TRIM_EXCESS
78967 diff --git a/mm/filemap.c b/mm/filemap.c
78968 index 83efee7..3f99381 100644
78969 --- a/mm/filemap.c
78970 +++ b/mm/filemap.c
78971 @@ -1747,7 +1747,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
78972 struct address_space *mapping = file->f_mapping;
78973
78974 if (!mapping->a_ops->readpage)
78975 - return -ENOEXEC;
78976 + return -ENODEV;
78977 file_accessed(file);
78978 vma->vm_ops = &generic_file_vm_ops;
78979 return 0;
78980 @@ -2087,6 +2087,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
78981 *pos = i_size_read(inode);
78982
78983 if (limit != RLIM_INFINITY) {
78984 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
78985 if (*pos >= limit) {
78986 send_sig(SIGXFSZ, current, 0);
78987 return -EFBIG;
78988 diff --git a/mm/fremap.c b/mm/fremap.c
78989 index a0aaf0e..20325c3 100644
78990 --- a/mm/fremap.c
78991 +++ b/mm/fremap.c
78992 @@ -157,6 +157,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
78993 retry:
78994 vma = find_vma(mm, start);
78995
78996 +#ifdef CONFIG_PAX_SEGMEXEC
78997 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
78998 + goto out;
78999 +#endif
79000 +
79001 /*
79002 * Make sure the vma is shared, that it supports prefaulting,
79003 * and that the remapped range is valid and fully within
79004 diff --git a/mm/highmem.c b/mm/highmem.c
79005 index b32b70c..e512eb0 100644
79006 --- a/mm/highmem.c
79007 +++ b/mm/highmem.c
79008 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
79009 * So no dangers, even with speculative execution.
79010 */
79011 page = pte_page(pkmap_page_table[i]);
79012 + pax_open_kernel();
79013 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
79014 -
79015 + pax_close_kernel();
79016 set_page_address(page, NULL);
79017 need_flush = 1;
79018 }
79019 @@ -198,9 +199,11 @@ start:
79020 }
79021 }
79022 vaddr = PKMAP_ADDR(last_pkmap_nr);
79023 +
79024 + pax_open_kernel();
79025 set_pte_at(&init_mm, vaddr,
79026 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
79027 -
79028 + pax_close_kernel();
79029 pkmap_count[last_pkmap_nr] = 1;
79030 set_page_address(page, (void *)vaddr);
79031
79032 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
79033 index 546db81..34830af 100644
79034 --- a/mm/hugetlb.c
79035 +++ b/mm/hugetlb.c
79036 @@ -2008,15 +2008,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
79037 struct hstate *h = &default_hstate;
79038 unsigned long tmp;
79039 int ret;
79040 + ctl_table_no_const hugetlb_table;
79041
79042 tmp = h->max_huge_pages;
79043
79044 if (write && h->order >= MAX_ORDER)
79045 return -EINVAL;
79046
79047 - table->data = &tmp;
79048 - table->maxlen = sizeof(unsigned long);
79049 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79050 + hugetlb_table = *table;
79051 + hugetlb_table.data = &tmp;
79052 + hugetlb_table.maxlen = sizeof(unsigned long);
79053 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79054 if (ret)
79055 goto out;
79056
79057 @@ -2073,15 +2075,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
79058 struct hstate *h = &default_hstate;
79059 unsigned long tmp;
79060 int ret;
79061 + ctl_table_no_const hugetlb_table;
79062
79063 tmp = h->nr_overcommit_huge_pages;
79064
79065 if (write && h->order >= MAX_ORDER)
79066 return -EINVAL;
79067
79068 - table->data = &tmp;
79069 - table->maxlen = sizeof(unsigned long);
79070 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
79071 + hugetlb_table = *table;
79072 + hugetlb_table.data = &tmp;
79073 + hugetlb_table.maxlen = sizeof(unsigned long);
79074 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
79075 if (ret)
79076 goto out;
79077
79078 @@ -2511,6 +2515,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
79079 return 1;
79080 }
79081
79082 +#ifdef CONFIG_PAX_SEGMEXEC
79083 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
79084 +{
79085 + struct mm_struct *mm = vma->vm_mm;
79086 + struct vm_area_struct *vma_m;
79087 + unsigned long address_m;
79088 + pte_t *ptep_m;
79089 +
79090 + vma_m = pax_find_mirror_vma(vma);
79091 + if (!vma_m)
79092 + return;
79093 +
79094 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79095 + address_m = address + SEGMEXEC_TASK_SIZE;
79096 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
79097 + get_page(page_m);
79098 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
79099 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
79100 +}
79101 +#endif
79102 +
79103 /*
79104 * Hugetlb_cow() should be called with page lock of the original hugepage held.
79105 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
79106 @@ -2629,6 +2654,11 @@ retry_avoidcopy:
79107 make_huge_pte(vma, new_page, 1));
79108 page_remove_rmap(old_page);
79109 hugepage_add_new_anon_rmap(new_page, vma, address);
79110 +
79111 +#ifdef CONFIG_PAX_SEGMEXEC
79112 + pax_mirror_huge_pte(vma, address, new_page);
79113 +#endif
79114 +
79115 /* Make the old page be freed below */
79116 new_page = old_page;
79117 }
79118 @@ -2788,6 +2818,10 @@ retry:
79119 && (vma->vm_flags & VM_SHARED)));
79120 set_huge_pte_at(mm, address, ptep, new_pte);
79121
79122 +#ifdef CONFIG_PAX_SEGMEXEC
79123 + pax_mirror_huge_pte(vma, address, page);
79124 +#endif
79125 +
79126 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
79127 /* Optimization, do the COW without a second fault */
79128 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
79129 @@ -2817,6 +2851,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79130 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
79131 struct hstate *h = hstate_vma(vma);
79132
79133 +#ifdef CONFIG_PAX_SEGMEXEC
79134 + struct vm_area_struct *vma_m;
79135 +#endif
79136 +
79137 address &= huge_page_mask(h);
79138
79139 ptep = huge_pte_offset(mm, address);
79140 @@ -2830,6 +2868,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79141 VM_FAULT_SET_HINDEX(hstate_index(h));
79142 }
79143
79144 +#ifdef CONFIG_PAX_SEGMEXEC
79145 + vma_m = pax_find_mirror_vma(vma);
79146 + if (vma_m) {
79147 + unsigned long address_m;
79148 +
79149 + if (vma->vm_start > vma_m->vm_start) {
79150 + address_m = address;
79151 + address -= SEGMEXEC_TASK_SIZE;
79152 + vma = vma_m;
79153 + h = hstate_vma(vma);
79154 + } else
79155 + address_m = address + SEGMEXEC_TASK_SIZE;
79156 +
79157 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
79158 + return VM_FAULT_OOM;
79159 + address_m &= HPAGE_MASK;
79160 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
79161 + }
79162 +#endif
79163 +
79164 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
79165 if (!ptep)
79166 return VM_FAULT_OOM;
79167 diff --git a/mm/internal.h b/mm/internal.h
79168 index 9ba2110..eaf0674 100644
79169 --- a/mm/internal.h
79170 +++ b/mm/internal.h
79171 @@ -100,6 +100,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
79172 * in mm/page_alloc.c
79173 */
79174 extern void __free_pages_bootmem(struct page *page, unsigned int order);
79175 +extern void free_compound_page(struct page *page);
79176 extern void prep_compound_page(struct page *page, unsigned long order);
79177 #ifdef CONFIG_MEMORY_FAILURE
79178 extern bool is_free_buddy_page(struct page *page);
79179 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
79180 index 752a705..6c3102e 100644
79181 --- a/mm/kmemleak.c
79182 +++ b/mm/kmemleak.c
79183 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
79184
79185 for (i = 0; i < object->trace_len; i++) {
79186 void *ptr = (void *)object->trace[i];
79187 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
79188 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
79189 }
79190 }
79191
79192 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
79193 return -ENOMEM;
79194 }
79195
79196 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
79197 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
79198 &kmemleak_fops);
79199 if (!dentry)
79200 pr_warning("Failed to create the debugfs kmemleak file\n");
79201 diff --git a/mm/maccess.c b/mm/maccess.c
79202 index d53adf9..03a24bf 100644
79203 --- a/mm/maccess.c
79204 +++ b/mm/maccess.c
79205 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
79206 set_fs(KERNEL_DS);
79207 pagefault_disable();
79208 ret = __copy_from_user_inatomic(dst,
79209 - (__force const void __user *)src, size);
79210 + (const void __force_user *)src, size);
79211 pagefault_enable();
79212 set_fs(old_fs);
79213
79214 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
79215
79216 set_fs(KERNEL_DS);
79217 pagefault_disable();
79218 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
79219 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
79220 pagefault_enable();
79221 set_fs(old_fs);
79222
79223 diff --git a/mm/madvise.c b/mm/madvise.c
79224 index 03dfa5c..b032917 100644
79225 --- a/mm/madvise.c
79226 +++ b/mm/madvise.c
79227 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
79228 pgoff_t pgoff;
79229 unsigned long new_flags = vma->vm_flags;
79230
79231 +#ifdef CONFIG_PAX_SEGMEXEC
79232 + struct vm_area_struct *vma_m;
79233 +#endif
79234 +
79235 switch (behavior) {
79236 case MADV_NORMAL:
79237 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
79238 @@ -123,6 +127,13 @@ success:
79239 /*
79240 * vm_flags is protected by the mmap_sem held in write mode.
79241 */
79242 +
79243 +#ifdef CONFIG_PAX_SEGMEXEC
79244 + vma_m = pax_find_mirror_vma(vma);
79245 + if (vma_m)
79246 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
79247 +#endif
79248 +
79249 vma->vm_flags = new_flags;
79250
79251 out:
79252 @@ -181,6 +192,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79253 struct vm_area_struct ** prev,
79254 unsigned long start, unsigned long end)
79255 {
79256 +
79257 +#ifdef CONFIG_PAX_SEGMEXEC
79258 + struct vm_area_struct *vma_m;
79259 +#endif
79260 +
79261 *prev = vma;
79262 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
79263 return -EINVAL;
79264 @@ -193,6 +209,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
79265 zap_page_range(vma, start, end - start, &details);
79266 } else
79267 zap_page_range(vma, start, end - start, NULL);
79268 +
79269 +#ifdef CONFIG_PAX_SEGMEXEC
79270 + vma_m = pax_find_mirror_vma(vma);
79271 + if (vma_m) {
79272 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
79273 + struct zap_details details = {
79274 + .nonlinear_vma = vma_m,
79275 + .last_index = ULONG_MAX,
79276 + };
79277 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
79278 + } else
79279 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
79280 + }
79281 +#endif
79282 +
79283 return 0;
79284 }
79285
79286 @@ -397,6 +428,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
79287 if (end < start)
79288 goto out;
79289
79290 +#ifdef CONFIG_PAX_SEGMEXEC
79291 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
79292 + if (end > SEGMEXEC_TASK_SIZE)
79293 + goto out;
79294 + } else
79295 +#endif
79296 +
79297 + if (end > TASK_SIZE)
79298 + goto out;
79299 +
79300 error = 0;
79301 if (end == start)
79302 goto out;
79303 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
79304 index c6e4dd3..1f41988 100644
79305 --- a/mm/memory-failure.c
79306 +++ b/mm/memory-failure.c
79307 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
79308
79309 int sysctl_memory_failure_recovery __read_mostly = 1;
79310
79311 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79312 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
79313
79314 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
79315
79316 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
79317 pfn, t->comm, t->pid);
79318 si.si_signo = SIGBUS;
79319 si.si_errno = 0;
79320 - si.si_addr = (void *)addr;
79321 + si.si_addr = (void __user *)addr;
79322 #ifdef __ARCH_SI_TRAPNO
79323 si.si_trapno = trapno;
79324 #endif
79325 @@ -760,7 +760,7 @@ static struct page_state {
79326 unsigned long res;
79327 char *msg;
79328 int (*action)(struct page *p, unsigned long pfn);
79329 -} error_states[] = {
79330 +} __do_const error_states[] = {
79331 { reserved, reserved, "reserved kernel", me_kernel },
79332 /*
79333 * free pages are specially detected outside this table:
79334 @@ -1040,7 +1040,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79335 }
79336
79337 nr_pages = 1 << compound_trans_order(hpage);
79338 - atomic_long_add(nr_pages, &mce_bad_pages);
79339 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
79340
79341 /*
79342 * We need/can do nothing about count=0 pages.
79343 @@ -1070,7 +1070,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79344 if (!PageHWPoison(hpage)
79345 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
79346 || (p != hpage && TestSetPageHWPoison(hpage))) {
79347 - atomic_long_sub(nr_pages, &mce_bad_pages);
79348 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79349 return 0;
79350 }
79351 set_page_hwpoison_huge_page(hpage);
79352 @@ -1128,7 +1128,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
79353 }
79354 if (hwpoison_filter(p)) {
79355 if (TestClearPageHWPoison(p))
79356 - atomic_long_sub(nr_pages, &mce_bad_pages);
79357 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79358 unlock_page(hpage);
79359 put_page(hpage);
79360 return 0;
79361 @@ -1323,7 +1323,7 @@ int unpoison_memory(unsigned long pfn)
79362 return 0;
79363 }
79364 if (TestClearPageHWPoison(p))
79365 - atomic_long_sub(nr_pages, &mce_bad_pages);
79366 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79367 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
79368 return 0;
79369 }
79370 @@ -1337,7 +1337,7 @@ int unpoison_memory(unsigned long pfn)
79371 */
79372 if (TestClearPageHWPoison(page)) {
79373 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
79374 - atomic_long_sub(nr_pages, &mce_bad_pages);
79375 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
79376 freeit = 1;
79377 if (PageHuge(page))
79378 clear_page_hwpoison_huge_page(page);
79379 @@ -1442,7 +1442,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
79380 }
79381 done:
79382 if (!PageHWPoison(hpage))
79383 - atomic_long_add(1 << compound_trans_order(hpage),
79384 + atomic_long_add_unchecked(1 << compound_trans_order(hpage),
79385 &mce_bad_pages);
79386 set_page_hwpoison_huge_page(hpage);
79387 dequeue_hwpoisoned_huge_page(hpage);
79388 @@ -1583,7 +1583,7 @@ int soft_offline_page(struct page *page, int flags)
79389 return ret;
79390
79391 done:
79392 - atomic_long_add(1, &mce_bad_pages);
79393 + atomic_long_add_unchecked(1, &mce_bad_pages);
79394 SetPageHWPoison(page);
79395 /* keep elevated page count for bad page */
79396 return ret;
79397 diff --git a/mm/memory.c b/mm/memory.c
79398 index bb1369f..efb96b5 100644
79399 --- a/mm/memory.c
79400 +++ b/mm/memory.c
79401 @@ -433,6 +433,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
79402 free_pte_range(tlb, pmd, addr);
79403 } while (pmd++, addr = next, addr != end);
79404
79405 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
79406 start &= PUD_MASK;
79407 if (start < floor)
79408 return;
79409 @@ -447,6 +448,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
79410 pmd = pmd_offset(pud, start);
79411 pud_clear(pud);
79412 pmd_free_tlb(tlb, pmd, start);
79413 +#endif
79414 +
79415 }
79416
79417 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79418 @@ -466,6 +469,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79419 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
79420 } while (pud++, addr = next, addr != end);
79421
79422 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
79423 start &= PGDIR_MASK;
79424 if (start < floor)
79425 return;
79426 @@ -480,6 +484,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
79427 pud = pud_offset(pgd, start);
79428 pgd_clear(pgd);
79429 pud_free_tlb(tlb, pud, start);
79430 +#endif
79431 +
79432 }
79433
79434 /*
79435 @@ -1618,12 +1624,6 @@ no_page_table:
79436 return page;
79437 }
79438
79439 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
79440 -{
79441 - return stack_guard_page_start(vma, addr) ||
79442 - stack_guard_page_end(vma, addr+PAGE_SIZE);
79443 -}
79444 -
79445 /**
79446 * __get_user_pages() - pin user pages in memory
79447 * @tsk: task_struct of target task
79448 @@ -1709,10 +1709,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79449
79450 i = 0;
79451
79452 - do {
79453 + while (nr_pages) {
79454 struct vm_area_struct *vma;
79455
79456 - vma = find_extend_vma(mm, start);
79457 + vma = find_vma(mm, start);
79458 if (!vma && in_gate_area(mm, start)) {
79459 unsigned long pg = start & PAGE_MASK;
79460 pgd_t *pgd;
79461 @@ -1760,7 +1760,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79462 goto next_page;
79463 }
79464
79465 - if (!vma ||
79466 + if (!vma || start < vma->vm_start ||
79467 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
79468 !(vm_flags & vma->vm_flags))
79469 return i ? : -EFAULT;
79470 @@ -1787,11 +1787,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
79471 int ret;
79472 unsigned int fault_flags = 0;
79473
79474 - /* For mlock, just skip the stack guard page. */
79475 - if (foll_flags & FOLL_MLOCK) {
79476 - if (stack_guard_page(vma, start))
79477 - goto next_page;
79478 - }
79479 if (foll_flags & FOLL_WRITE)
79480 fault_flags |= FAULT_FLAG_WRITE;
79481 if (nonblocking)
79482 @@ -1865,7 +1860,7 @@ next_page:
79483 start += PAGE_SIZE;
79484 nr_pages--;
79485 } while (nr_pages && start < vma->vm_end);
79486 - } while (nr_pages);
79487 + }
79488 return i;
79489 }
79490 EXPORT_SYMBOL(__get_user_pages);
79491 @@ -2072,6 +2067,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
79492 page_add_file_rmap(page);
79493 set_pte_at(mm, addr, pte, mk_pte(page, prot));
79494
79495 +#ifdef CONFIG_PAX_SEGMEXEC
79496 + pax_mirror_file_pte(vma, addr, page, ptl);
79497 +#endif
79498 +
79499 retval = 0;
79500 pte_unmap_unlock(pte, ptl);
79501 return retval;
79502 @@ -2116,9 +2115,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
79503 if (!page_count(page))
79504 return -EINVAL;
79505 if (!(vma->vm_flags & VM_MIXEDMAP)) {
79506 +
79507 +#ifdef CONFIG_PAX_SEGMEXEC
79508 + struct vm_area_struct *vma_m;
79509 +#endif
79510 +
79511 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
79512 BUG_ON(vma->vm_flags & VM_PFNMAP);
79513 vma->vm_flags |= VM_MIXEDMAP;
79514 +
79515 +#ifdef CONFIG_PAX_SEGMEXEC
79516 + vma_m = pax_find_mirror_vma(vma);
79517 + if (vma_m)
79518 + vma_m->vm_flags |= VM_MIXEDMAP;
79519 +#endif
79520 +
79521 }
79522 return insert_page(vma, addr, page, vma->vm_page_prot);
79523 }
79524 @@ -2201,6 +2212,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
79525 unsigned long pfn)
79526 {
79527 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
79528 + BUG_ON(vma->vm_mirror);
79529
79530 if (addr < vma->vm_start || addr >= vma->vm_end)
79531 return -EFAULT;
79532 @@ -2401,7 +2413,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
79533
79534 BUG_ON(pud_huge(*pud));
79535
79536 - pmd = pmd_alloc(mm, pud, addr);
79537 + pmd = (mm == &init_mm) ?
79538 + pmd_alloc_kernel(mm, pud, addr) :
79539 + pmd_alloc(mm, pud, addr);
79540 if (!pmd)
79541 return -ENOMEM;
79542 do {
79543 @@ -2421,7 +2435,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
79544 unsigned long next;
79545 int err;
79546
79547 - pud = pud_alloc(mm, pgd, addr);
79548 + pud = (mm == &init_mm) ?
79549 + pud_alloc_kernel(mm, pgd, addr) :
79550 + pud_alloc(mm, pgd, addr);
79551 if (!pud)
79552 return -ENOMEM;
79553 do {
79554 @@ -2509,6 +2525,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
79555 copy_user_highpage(dst, src, va, vma);
79556 }
79557
79558 +#ifdef CONFIG_PAX_SEGMEXEC
79559 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
79560 +{
79561 + struct mm_struct *mm = vma->vm_mm;
79562 + spinlock_t *ptl;
79563 + pte_t *pte, entry;
79564 +
79565 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
79566 + entry = *pte;
79567 + if (!pte_present(entry)) {
79568 + if (!pte_none(entry)) {
79569 + BUG_ON(pte_file(entry));
79570 + free_swap_and_cache(pte_to_swp_entry(entry));
79571 + pte_clear_not_present_full(mm, address, pte, 0);
79572 + }
79573 + } else {
79574 + struct page *page;
79575 +
79576 + flush_cache_page(vma, address, pte_pfn(entry));
79577 + entry = ptep_clear_flush(vma, address, pte);
79578 + BUG_ON(pte_dirty(entry));
79579 + page = vm_normal_page(vma, address, entry);
79580 + if (page) {
79581 + update_hiwater_rss(mm);
79582 + if (PageAnon(page))
79583 + dec_mm_counter_fast(mm, MM_ANONPAGES);
79584 + else
79585 + dec_mm_counter_fast(mm, MM_FILEPAGES);
79586 + page_remove_rmap(page);
79587 + page_cache_release(page);
79588 + }
79589 + }
79590 + pte_unmap_unlock(pte, ptl);
79591 +}
79592 +
79593 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
79594 + *
79595 + * the ptl of the lower mapped page is held on entry and is not released on exit
79596 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
79597 + */
79598 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
79599 +{
79600 + struct mm_struct *mm = vma->vm_mm;
79601 + unsigned long address_m;
79602 + spinlock_t *ptl_m;
79603 + struct vm_area_struct *vma_m;
79604 + pmd_t *pmd_m;
79605 + pte_t *pte_m, entry_m;
79606 +
79607 + BUG_ON(!page_m || !PageAnon(page_m));
79608 +
79609 + vma_m = pax_find_mirror_vma(vma);
79610 + if (!vma_m)
79611 + return;
79612 +
79613 + BUG_ON(!PageLocked(page_m));
79614 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79615 + address_m = address + SEGMEXEC_TASK_SIZE;
79616 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79617 + pte_m = pte_offset_map(pmd_m, address_m);
79618 + ptl_m = pte_lockptr(mm, pmd_m);
79619 + if (ptl != ptl_m) {
79620 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79621 + if (!pte_none(*pte_m))
79622 + goto out;
79623 + }
79624 +
79625 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
79626 + page_cache_get(page_m);
79627 + page_add_anon_rmap(page_m, vma_m, address_m);
79628 + inc_mm_counter_fast(mm, MM_ANONPAGES);
79629 + set_pte_at(mm, address_m, pte_m, entry_m);
79630 + update_mmu_cache(vma_m, address_m, entry_m);
79631 +out:
79632 + if (ptl != ptl_m)
79633 + spin_unlock(ptl_m);
79634 + pte_unmap(pte_m);
79635 + unlock_page(page_m);
79636 +}
79637 +
79638 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
79639 +{
79640 + struct mm_struct *mm = vma->vm_mm;
79641 + unsigned long address_m;
79642 + spinlock_t *ptl_m;
79643 + struct vm_area_struct *vma_m;
79644 + pmd_t *pmd_m;
79645 + pte_t *pte_m, entry_m;
79646 +
79647 + BUG_ON(!page_m || PageAnon(page_m));
79648 +
79649 + vma_m = pax_find_mirror_vma(vma);
79650 + if (!vma_m)
79651 + return;
79652 +
79653 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79654 + address_m = address + SEGMEXEC_TASK_SIZE;
79655 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79656 + pte_m = pte_offset_map(pmd_m, address_m);
79657 + ptl_m = pte_lockptr(mm, pmd_m);
79658 + if (ptl != ptl_m) {
79659 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79660 + if (!pte_none(*pte_m))
79661 + goto out;
79662 + }
79663 +
79664 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
79665 + page_cache_get(page_m);
79666 + page_add_file_rmap(page_m);
79667 + inc_mm_counter_fast(mm, MM_FILEPAGES);
79668 + set_pte_at(mm, address_m, pte_m, entry_m);
79669 + update_mmu_cache(vma_m, address_m, entry_m);
79670 +out:
79671 + if (ptl != ptl_m)
79672 + spin_unlock(ptl_m);
79673 + pte_unmap(pte_m);
79674 +}
79675 +
79676 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
79677 +{
79678 + struct mm_struct *mm = vma->vm_mm;
79679 + unsigned long address_m;
79680 + spinlock_t *ptl_m;
79681 + struct vm_area_struct *vma_m;
79682 + pmd_t *pmd_m;
79683 + pte_t *pte_m, entry_m;
79684 +
79685 + vma_m = pax_find_mirror_vma(vma);
79686 + if (!vma_m)
79687 + return;
79688 +
79689 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
79690 + address_m = address + SEGMEXEC_TASK_SIZE;
79691 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
79692 + pte_m = pte_offset_map(pmd_m, address_m);
79693 + ptl_m = pte_lockptr(mm, pmd_m);
79694 + if (ptl != ptl_m) {
79695 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
79696 + if (!pte_none(*pte_m))
79697 + goto out;
79698 + }
79699 +
79700 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
79701 + set_pte_at(mm, address_m, pte_m, entry_m);
79702 +out:
79703 + if (ptl != ptl_m)
79704 + spin_unlock(ptl_m);
79705 + pte_unmap(pte_m);
79706 +}
79707 +
79708 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
79709 +{
79710 + struct page *page_m;
79711 + pte_t entry;
79712 +
79713 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
79714 + goto out;
79715 +
79716 + entry = *pte;
79717 + page_m = vm_normal_page(vma, address, entry);
79718 + if (!page_m)
79719 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
79720 + else if (PageAnon(page_m)) {
79721 + if (pax_find_mirror_vma(vma)) {
79722 + pte_unmap_unlock(pte, ptl);
79723 + lock_page(page_m);
79724 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
79725 + if (pte_same(entry, *pte))
79726 + pax_mirror_anon_pte(vma, address, page_m, ptl);
79727 + else
79728 + unlock_page(page_m);
79729 + }
79730 + } else
79731 + pax_mirror_file_pte(vma, address, page_m, ptl);
79732 +
79733 +out:
79734 + pte_unmap_unlock(pte, ptl);
79735 +}
79736 +#endif
79737 +
79738 /*
79739 * This routine handles present pages, when users try to write
79740 * to a shared page. It is done by copying the page to a new address
79741 @@ -2725,6 +2921,12 @@ gotten:
79742 */
79743 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
79744 if (likely(pte_same(*page_table, orig_pte))) {
79745 +
79746 +#ifdef CONFIG_PAX_SEGMEXEC
79747 + if (pax_find_mirror_vma(vma))
79748 + BUG_ON(!trylock_page(new_page));
79749 +#endif
79750 +
79751 if (old_page) {
79752 if (!PageAnon(old_page)) {
79753 dec_mm_counter_fast(mm, MM_FILEPAGES);
79754 @@ -2776,6 +2978,10 @@ gotten:
79755 page_remove_rmap(old_page);
79756 }
79757
79758 +#ifdef CONFIG_PAX_SEGMEXEC
79759 + pax_mirror_anon_pte(vma, address, new_page, ptl);
79760 +#endif
79761 +
79762 /* Free the old page.. */
79763 new_page = old_page;
79764 ret |= VM_FAULT_WRITE;
79765 @@ -3051,6 +3257,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
79766 swap_free(entry);
79767 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
79768 try_to_free_swap(page);
79769 +
79770 +#ifdef CONFIG_PAX_SEGMEXEC
79771 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
79772 +#endif
79773 +
79774 unlock_page(page);
79775 if (swapcache) {
79776 /*
79777 @@ -3074,6 +3285,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
79778
79779 /* No need to invalidate - it was non-present before */
79780 update_mmu_cache(vma, address, page_table);
79781 +
79782 +#ifdef CONFIG_PAX_SEGMEXEC
79783 + pax_mirror_anon_pte(vma, address, page, ptl);
79784 +#endif
79785 +
79786 unlock:
79787 pte_unmap_unlock(page_table, ptl);
79788 out:
79789 @@ -3093,40 +3309,6 @@ out_release:
79790 }
79791
79792 /*
79793 - * This is like a special single-page "expand_{down|up}wards()",
79794 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
79795 - * doesn't hit another vma.
79796 - */
79797 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
79798 -{
79799 - address &= PAGE_MASK;
79800 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
79801 - struct vm_area_struct *prev = vma->vm_prev;
79802 -
79803 - /*
79804 - * Is there a mapping abutting this one below?
79805 - *
79806 - * That's only ok if it's the same stack mapping
79807 - * that has gotten split..
79808 - */
79809 - if (prev && prev->vm_end == address)
79810 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
79811 -
79812 - expand_downwards(vma, address - PAGE_SIZE);
79813 - }
79814 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
79815 - struct vm_area_struct *next = vma->vm_next;
79816 -
79817 - /* As VM_GROWSDOWN but s/below/above/ */
79818 - if (next && next->vm_start == address + PAGE_SIZE)
79819 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
79820 -
79821 - expand_upwards(vma, address + PAGE_SIZE);
79822 - }
79823 - return 0;
79824 -}
79825 -
79826 -/*
79827 * We enter with non-exclusive mmap_sem (to exclude vma changes,
79828 * but allow concurrent faults), and pte mapped but not yet locked.
79829 * We return with mmap_sem still held, but pte unmapped and unlocked.
79830 @@ -3135,27 +3317,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
79831 unsigned long address, pte_t *page_table, pmd_t *pmd,
79832 unsigned int flags)
79833 {
79834 - struct page *page;
79835 + struct page *page = NULL;
79836 spinlock_t *ptl;
79837 pte_t entry;
79838
79839 - pte_unmap(page_table);
79840 -
79841 - /* Check if we need to add a guard page to the stack */
79842 - if (check_stack_guard_page(vma, address) < 0)
79843 - return VM_FAULT_SIGBUS;
79844 -
79845 - /* Use the zero-page for reads */
79846 if (!(flags & FAULT_FLAG_WRITE)) {
79847 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
79848 vma->vm_page_prot));
79849 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
79850 + ptl = pte_lockptr(mm, pmd);
79851 + spin_lock(ptl);
79852 if (!pte_none(*page_table))
79853 goto unlock;
79854 goto setpte;
79855 }
79856
79857 /* Allocate our own private page. */
79858 + pte_unmap(page_table);
79859 +
79860 if (unlikely(anon_vma_prepare(vma)))
79861 goto oom;
79862 page = alloc_zeroed_user_highpage_movable(vma, address);
79863 @@ -3174,6 +3352,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
79864 if (!pte_none(*page_table))
79865 goto release;
79866
79867 +#ifdef CONFIG_PAX_SEGMEXEC
79868 + if (pax_find_mirror_vma(vma))
79869 + BUG_ON(!trylock_page(page));
79870 +#endif
79871 +
79872 inc_mm_counter_fast(mm, MM_ANONPAGES);
79873 page_add_new_anon_rmap(page, vma, address);
79874 setpte:
79875 @@ -3181,6 +3364,12 @@ setpte:
79876
79877 /* No need to invalidate - it was non-present before */
79878 update_mmu_cache(vma, address, page_table);
79879 +
79880 +#ifdef CONFIG_PAX_SEGMEXEC
79881 + if (page)
79882 + pax_mirror_anon_pte(vma, address, page, ptl);
79883 +#endif
79884 +
79885 unlock:
79886 pte_unmap_unlock(page_table, ptl);
79887 return 0;
79888 @@ -3324,6 +3513,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79889 */
79890 /* Only go through if we didn't race with anybody else... */
79891 if (likely(pte_same(*page_table, orig_pte))) {
79892 +
79893 +#ifdef CONFIG_PAX_SEGMEXEC
79894 + if (anon && pax_find_mirror_vma(vma))
79895 + BUG_ON(!trylock_page(page));
79896 +#endif
79897 +
79898 flush_icache_page(vma, page);
79899 entry = mk_pte(page, vma->vm_page_prot);
79900 if (flags & FAULT_FLAG_WRITE)
79901 @@ -3343,6 +3538,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79902
79903 /* no need to invalidate: a not-present page won't be cached */
79904 update_mmu_cache(vma, address, page_table);
79905 +
79906 +#ifdef CONFIG_PAX_SEGMEXEC
79907 + if (anon)
79908 + pax_mirror_anon_pte(vma, address, page, ptl);
79909 + else
79910 + pax_mirror_file_pte(vma, address, page, ptl);
79911 +#endif
79912 +
79913 } else {
79914 if (cow_page)
79915 mem_cgroup_uncharge_page(cow_page);
79916 @@ -3664,6 +3867,12 @@ int handle_pte_fault(struct mm_struct *mm,
79917 if (flags & FAULT_FLAG_WRITE)
79918 flush_tlb_fix_spurious_fault(vma, address);
79919 }
79920 +
79921 +#ifdef CONFIG_PAX_SEGMEXEC
79922 + pax_mirror_pte(vma, address, pte, pmd, ptl);
79923 + return 0;
79924 +#endif
79925 +
79926 unlock:
79927 pte_unmap_unlock(pte, ptl);
79928 return 0;
79929 @@ -3680,6 +3889,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79930 pmd_t *pmd;
79931 pte_t *pte;
79932
79933 +#ifdef CONFIG_PAX_SEGMEXEC
79934 + struct vm_area_struct *vma_m;
79935 +#endif
79936 +
79937 __set_current_state(TASK_RUNNING);
79938
79939 count_vm_event(PGFAULT);
79940 @@ -3691,6 +3904,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
79941 if (unlikely(is_vm_hugetlb_page(vma)))
79942 return hugetlb_fault(mm, vma, address, flags);
79943
79944 +#ifdef CONFIG_PAX_SEGMEXEC
79945 + vma_m = pax_find_mirror_vma(vma);
79946 + if (vma_m) {
79947 + unsigned long address_m;
79948 + pgd_t *pgd_m;
79949 + pud_t *pud_m;
79950 + pmd_t *pmd_m;
79951 +
79952 + if (vma->vm_start > vma_m->vm_start) {
79953 + address_m = address;
79954 + address -= SEGMEXEC_TASK_SIZE;
79955 + vma = vma_m;
79956 + } else
79957 + address_m = address + SEGMEXEC_TASK_SIZE;
79958 +
79959 + pgd_m = pgd_offset(mm, address_m);
79960 + pud_m = pud_alloc(mm, pgd_m, address_m);
79961 + if (!pud_m)
79962 + return VM_FAULT_OOM;
79963 + pmd_m = pmd_alloc(mm, pud_m, address_m);
79964 + if (!pmd_m)
79965 + return VM_FAULT_OOM;
79966 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
79967 + return VM_FAULT_OOM;
79968 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
79969 + }
79970 +#endif
79971 +
79972 retry:
79973 pgd = pgd_offset(mm, address);
79974 pud = pud_alloc(mm, pgd, address);
79975 @@ -3789,6 +4030,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79976 spin_unlock(&mm->page_table_lock);
79977 return 0;
79978 }
79979 +
79980 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79981 +{
79982 + pud_t *new = pud_alloc_one(mm, address);
79983 + if (!new)
79984 + return -ENOMEM;
79985 +
79986 + smp_wmb(); /* See comment in __pte_alloc */
79987 +
79988 + spin_lock(&mm->page_table_lock);
79989 + if (pgd_present(*pgd)) /* Another has populated it */
79990 + pud_free(mm, new);
79991 + else
79992 + pgd_populate_kernel(mm, pgd, new);
79993 + spin_unlock(&mm->page_table_lock);
79994 + return 0;
79995 +}
79996 #endif /* __PAGETABLE_PUD_FOLDED */
79997
79998 #ifndef __PAGETABLE_PMD_FOLDED
79999 @@ -3819,6 +4077,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
80000 spin_unlock(&mm->page_table_lock);
80001 return 0;
80002 }
80003 +
80004 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
80005 +{
80006 + pmd_t *new = pmd_alloc_one(mm, address);
80007 + if (!new)
80008 + return -ENOMEM;
80009 +
80010 + smp_wmb(); /* See comment in __pte_alloc */
80011 +
80012 + spin_lock(&mm->page_table_lock);
80013 +#ifndef __ARCH_HAS_4LEVEL_HACK
80014 + if (pud_present(*pud)) /* Another has populated it */
80015 + pmd_free(mm, new);
80016 + else
80017 + pud_populate_kernel(mm, pud, new);
80018 +#else
80019 + if (pgd_present(*pud)) /* Another has populated it */
80020 + pmd_free(mm, new);
80021 + else
80022 + pgd_populate_kernel(mm, pud, new);
80023 +#endif /* __ARCH_HAS_4LEVEL_HACK */
80024 + spin_unlock(&mm->page_table_lock);
80025 + return 0;
80026 +}
80027 #endif /* __PAGETABLE_PMD_FOLDED */
80028
80029 int make_pages_present(unsigned long addr, unsigned long end)
80030 @@ -3856,7 +4138,7 @@ static int __init gate_vma_init(void)
80031 gate_vma.vm_start = FIXADDR_USER_START;
80032 gate_vma.vm_end = FIXADDR_USER_END;
80033 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
80034 - gate_vma.vm_page_prot = __P101;
80035 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
80036
80037 return 0;
80038 }
80039 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
80040 index e2df1c1..1e31d57 100644
80041 --- a/mm/mempolicy.c
80042 +++ b/mm/mempolicy.c
80043 @@ -721,6 +721,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80044 unsigned long vmstart;
80045 unsigned long vmend;
80046
80047 +#ifdef CONFIG_PAX_SEGMEXEC
80048 + struct vm_area_struct *vma_m;
80049 +#endif
80050 +
80051 vma = find_vma(mm, start);
80052 if (!vma || vma->vm_start > start)
80053 return -EFAULT;
80054 @@ -757,9 +761,20 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
80055 if (err)
80056 goto out;
80057 }
80058 +
80059 err = vma_replace_policy(vma, new_pol);
80060 if (err)
80061 goto out;
80062 +
80063 +#ifdef CONFIG_PAX_SEGMEXEC
80064 + vma_m = pax_find_mirror_vma(vma);
80065 + if (vma_m) {
80066 + err = vma_replace_policy(vma_m, new_pol);
80067 + if (err)
80068 + goto out;
80069 + }
80070 +#endif
80071 +
80072 }
80073
80074 out:
80075 @@ -1216,6 +1231,17 @@ static long do_mbind(unsigned long start, unsigned long len,
80076
80077 if (end < start)
80078 return -EINVAL;
80079 +
80080 +#ifdef CONFIG_PAX_SEGMEXEC
80081 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
80082 + if (end > SEGMEXEC_TASK_SIZE)
80083 + return -EINVAL;
80084 + } else
80085 +#endif
80086 +
80087 + if (end > TASK_SIZE)
80088 + return -EINVAL;
80089 +
80090 if (end == start)
80091 return 0;
80092
80093 @@ -1445,8 +1471,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80094 */
80095 tcred = __task_cred(task);
80096 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80097 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80098 - !capable(CAP_SYS_NICE)) {
80099 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80100 rcu_read_unlock();
80101 err = -EPERM;
80102 goto out_put;
80103 @@ -1477,6 +1502,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
80104 goto out;
80105 }
80106
80107 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80108 + if (mm != current->mm &&
80109 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
80110 + mmput(mm);
80111 + err = -EPERM;
80112 + goto out;
80113 + }
80114 +#endif
80115 +
80116 err = do_migrate_pages(mm, old, new,
80117 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
80118
80119 diff --git a/mm/migrate.c b/mm/migrate.c
80120 index 2fd8b4a..d70358f 100644
80121 --- a/mm/migrate.c
80122 +++ b/mm/migrate.c
80123 @@ -1401,8 +1401,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
80124 */
80125 tcred = __task_cred(task);
80126 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
80127 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
80128 - !capable(CAP_SYS_NICE)) {
80129 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
80130 rcu_read_unlock();
80131 err = -EPERM;
80132 goto out;
80133 diff --git a/mm/mlock.c b/mm/mlock.c
80134 index c9bd528..da8d069 100644
80135 --- a/mm/mlock.c
80136 +++ b/mm/mlock.c
80137 @@ -13,6 +13,7 @@
80138 #include <linux/pagemap.h>
80139 #include <linux/mempolicy.h>
80140 #include <linux/syscalls.h>
80141 +#include <linux/security.h>
80142 #include <linux/sched.h>
80143 #include <linux/export.h>
80144 #include <linux/rmap.h>
80145 @@ -369,7 +370,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
80146 {
80147 unsigned long nstart, end, tmp;
80148 struct vm_area_struct * vma, * prev;
80149 - int error;
80150 + int error = 0;
80151
80152 VM_BUG_ON(start & ~PAGE_MASK);
80153 VM_BUG_ON(len != PAGE_ALIGN(len));
80154 @@ -378,6 +379,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
80155 return -EINVAL;
80156 if (end == start)
80157 return 0;
80158 + if (end > TASK_SIZE)
80159 + return -EINVAL;
80160 +
80161 vma = find_vma(current->mm, start);
80162 if (!vma || vma->vm_start > start)
80163 return -ENOMEM;
80164 @@ -389,6 +393,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
80165 for (nstart = start ; ; ) {
80166 vm_flags_t newflags;
80167
80168 +#ifdef CONFIG_PAX_SEGMEXEC
80169 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80170 + break;
80171 +#endif
80172 +
80173 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
80174
80175 newflags = vma->vm_flags | VM_LOCKED;
80176 @@ -494,6 +503,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
80177 lock_limit >>= PAGE_SHIFT;
80178
80179 /* check against resource limits */
80180 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
80181 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
80182 error = do_mlock(start, len, 1);
80183 up_write(&current->mm->mmap_sem);
80184 @@ -528,6 +538,12 @@ static int do_mlockall(int flags)
80185 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
80186 vm_flags_t newflags;
80187
80188 +#ifdef CONFIG_PAX_SEGMEXEC
80189 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
80190 + break;
80191 +#endif
80192 +
80193 + BUG_ON(vma->vm_end > TASK_SIZE);
80194 newflags = vma->vm_flags | VM_LOCKED;
80195 if (!(flags & MCL_CURRENT))
80196 newflags &= ~VM_LOCKED;
80197 @@ -560,6 +576,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
80198 lock_limit >>= PAGE_SHIFT;
80199
80200 ret = -ENOMEM;
80201 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
80202 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
80203 capable(CAP_IPC_LOCK))
80204 ret = do_mlockall(flags);
80205 diff --git a/mm/mmap.c b/mm/mmap.c
80206 index 8832b87..20500c1 100644
80207 --- a/mm/mmap.c
80208 +++ b/mm/mmap.c
80209 @@ -32,6 +32,7 @@
80210 #include <linux/khugepaged.h>
80211 #include <linux/uprobes.h>
80212 #include <linux/rbtree_augmented.h>
80213 +#include <linux/random.h>
80214
80215 #include <asm/uaccess.h>
80216 #include <asm/cacheflush.h>
80217 @@ -48,6 +49,16 @@
80218 #define arch_rebalance_pgtables(addr, len) (addr)
80219 #endif
80220
80221 +static inline void verify_mm_writelocked(struct mm_struct *mm)
80222 +{
80223 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
80224 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
80225 + up_read(&mm->mmap_sem);
80226 + BUG();
80227 + }
80228 +#endif
80229 +}
80230 +
80231 static void unmap_region(struct mm_struct *mm,
80232 struct vm_area_struct *vma, struct vm_area_struct *prev,
80233 unsigned long start, unsigned long end);
80234 @@ -67,22 +78,32 @@ static void unmap_region(struct mm_struct *mm,
80235 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
80236 *
80237 */
80238 -pgprot_t protection_map[16] = {
80239 +pgprot_t protection_map[16] __read_only = {
80240 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
80241 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
80242 };
80243
80244 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
80245 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
80246 {
80247 - return __pgprot(pgprot_val(protection_map[vm_flags &
80248 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
80249 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
80250 pgprot_val(arch_vm_get_page_prot(vm_flags)));
80251 +
80252 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80253 + if (!(__supported_pte_mask & _PAGE_NX) &&
80254 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
80255 + (vm_flags & (VM_READ | VM_WRITE)))
80256 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
80257 +#endif
80258 +
80259 + return prot;
80260 }
80261 EXPORT_SYMBOL(vm_get_page_prot);
80262
80263 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
80264 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
80265 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
80266 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
80267 /*
80268 * Make sure vm_committed_as in one cacheline and not cacheline shared with
80269 * other variables. It can be updated by several CPUs frequently.
80270 @@ -238,6 +259,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
80271 struct vm_area_struct *next = vma->vm_next;
80272
80273 might_sleep();
80274 + BUG_ON(vma->vm_mirror);
80275 if (vma->vm_ops && vma->vm_ops->close)
80276 vma->vm_ops->close(vma);
80277 if (vma->vm_file)
80278 @@ -281,6 +303,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
80279 * not page aligned -Ram Gupta
80280 */
80281 rlim = rlimit(RLIMIT_DATA);
80282 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
80283 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
80284 (mm->end_data - mm->start_data) > rlim)
80285 goto out;
80286 @@ -888,6 +911,12 @@ static int
80287 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
80288 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80289 {
80290 +
80291 +#ifdef CONFIG_PAX_SEGMEXEC
80292 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
80293 + return 0;
80294 +#endif
80295 +
80296 if (is_mergeable_vma(vma, file, vm_flags) &&
80297 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80298 if (vma->vm_pgoff == vm_pgoff)
80299 @@ -907,6 +936,12 @@ static int
80300 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80301 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
80302 {
80303 +
80304 +#ifdef CONFIG_PAX_SEGMEXEC
80305 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
80306 + return 0;
80307 +#endif
80308 +
80309 if (is_mergeable_vma(vma, file, vm_flags) &&
80310 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
80311 pgoff_t vm_pglen;
80312 @@ -949,13 +984,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
80313 struct vm_area_struct *vma_merge(struct mm_struct *mm,
80314 struct vm_area_struct *prev, unsigned long addr,
80315 unsigned long end, unsigned long vm_flags,
80316 - struct anon_vma *anon_vma, struct file *file,
80317 + struct anon_vma *anon_vma, struct file *file,
80318 pgoff_t pgoff, struct mempolicy *policy)
80319 {
80320 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
80321 struct vm_area_struct *area, *next;
80322 int err;
80323
80324 +#ifdef CONFIG_PAX_SEGMEXEC
80325 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
80326 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
80327 +
80328 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
80329 +#endif
80330 +
80331 /*
80332 * We later require that vma->vm_flags == vm_flags,
80333 * so this tests vma->vm_flags & VM_SPECIAL, too.
80334 @@ -971,6 +1013,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80335 if (next && next->vm_end == end) /* cases 6, 7, 8 */
80336 next = next->vm_next;
80337
80338 +#ifdef CONFIG_PAX_SEGMEXEC
80339 + if (prev)
80340 + prev_m = pax_find_mirror_vma(prev);
80341 + if (area)
80342 + area_m = pax_find_mirror_vma(area);
80343 + if (next)
80344 + next_m = pax_find_mirror_vma(next);
80345 +#endif
80346 +
80347 /*
80348 * Can it merge with the predecessor?
80349 */
80350 @@ -990,9 +1041,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80351 /* cases 1, 6 */
80352 err = vma_adjust(prev, prev->vm_start,
80353 next->vm_end, prev->vm_pgoff, NULL);
80354 - } else /* cases 2, 5, 7 */
80355 +
80356 +#ifdef CONFIG_PAX_SEGMEXEC
80357 + if (!err && prev_m)
80358 + err = vma_adjust(prev_m, prev_m->vm_start,
80359 + next_m->vm_end, prev_m->vm_pgoff, NULL);
80360 +#endif
80361 +
80362 + } else { /* cases 2, 5, 7 */
80363 err = vma_adjust(prev, prev->vm_start,
80364 end, prev->vm_pgoff, NULL);
80365 +
80366 +#ifdef CONFIG_PAX_SEGMEXEC
80367 + if (!err && prev_m)
80368 + err = vma_adjust(prev_m, prev_m->vm_start,
80369 + end_m, prev_m->vm_pgoff, NULL);
80370 +#endif
80371 +
80372 + }
80373 if (err)
80374 return NULL;
80375 khugepaged_enter_vma_merge(prev);
80376 @@ -1006,12 +1072,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
80377 mpol_equal(policy, vma_policy(next)) &&
80378 can_vma_merge_before(next, vm_flags,
80379 anon_vma, file, pgoff+pglen)) {
80380 - if (prev && addr < prev->vm_end) /* case 4 */
80381 + if (prev && addr < prev->vm_end) { /* case 4 */
80382 err = vma_adjust(prev, prev->vm_start,
80383 addr, prev->vm_pgoff, NULL);
80384 - else /* cases 3, 8 */
80385 +
80386 +#ifdef CONFIG_PAX_SEGMEXEC
80387 + if (!err && prev_m)
80388 + err = vma_adjust(prev_m, prev_m->vm_start,
80389 + addr_m, prev_m->vm_pgoff, NULL);
80390 +#endif
80391 +
80392 + } else { /* cases 3, 8 */
80393 err = vma_adjust(area, addr, next->vm_end,
80394 next->vm_pgoff - pglen, NULL);
80395 +
80396 +#ifdef CONFIG_PAX_SEGMEXEC
80397 + if (!err && area_m)
80398 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
80399 + next_m->vm_pgoff - pglen, NULL);
80400 +#endif
80401 +
80402 + }
80403 if (err)
80404 return NULL;
80405 khugepaged_enter_vma_merge(area);
80406 @@ -1120,16 +1201,13 @@ none:
80407 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
80408 struct file *file, long pages)
80409 {
80410 - const unsigned long stack_flags
80411 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
80412 -
80413 mm->total_vm += pages;
80414
80415 if (file) {
80416 mm->shared_vm += pages;
80417 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
80418 mm->exec_vm += pages;
80419 - } else if (flags & stack_flags)
80420 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
80421 mm->stack_vm += pages;
80422 }
80423 #endif /* CONFIG_PROC_FS */
80424 @@ -1165,7 +1243,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80425 * (the exception is when the underlying filesystem is noexec
80426 * mounted, in which case we dont add PROT_EXEC.)
80427 */
80428 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
80429 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
80430 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
80431 prot |= PROT_EXEC;
80432
80433 @@ -1191,7 +1269,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80434 /* Obtain the address to map to. we verify (or select) it and ensure
80435 * that it represents a valid section of the address space.
80436 */
80437 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
80438 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
80439 if (addr & ~PAGE_MASK)
80440 return addr;
80441
80442 @@ -1202,6 +1280,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80443 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
80444 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
80445
80446 +#ifdef CONFIG_PAX_MPROTECT
80447 + if (mm->pax_flags & MF_PAX_MPROTECT) {
80448 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
80449 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
80450 + gr_log_rwxmmap(file);
80451 +
80452 +#ifdef CONFIG_PAX_EMUPLT
80453 + vm_flags &= ~VM_EXEC;
80454 +#else
80455 + return -EPERM;
80456 +#endif
80457 +
80458 + }
80459 +
80460 + if (!(vm_flags & VM_EXEC))
80461 + vm_flags &= ~VM_MAYEXEC;
80462 +#else
80463 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
80464 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
80465 +#endif
80466 + else
80467 + vm_flags &= ~VM_MAYWRITE;
80468 + }
80469 +#endif
80470 +
80471 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80472 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
80473 + vm_flags &= ~VM_PAGEEXEC;
80474 +#endif
80475 +
80476 if (flags & MAP_LOCKED)
80477 if (!can_do_mlock())
80478 return -EPERM;
80479 @@ -1213,6 +1321,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80480 locked += mm->locked_vm;
80481 lock_limit = rlimit(RLIMIT_MEMLOCK);
80482 lock_limit >>= PAGE_SHIFT;
80483 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
80484 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
80485 return -EAGAIN;
80486 }
80487 @@ -1279,6 +1388,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
80488 }
80489 }
80490
80491 + if (!gr_acl_handle_mmap(file, prot))
80492 + return -EACCES;
80493 +
80494 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
80495 }
80496
80497 @@ -1356,7 +1468,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
80498 vm_flags_t vm_flags = vma->vm_flags;
80499
80500 /* If it was private or non-writable, the write bit is already clear */
80501 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
80502 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
80503 return 0;
80504
80505 /* The backer wishes to know when pages are first written to? */
80506 @@ -1405,13 +1517,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
80507 unsigned long charged = 0;
80508 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
80509
80510 +#ifdef CONFIG_PAX_SEGMEXEC
80511 + struct vm_area_struct *vma_m = NULL;
80512 +#endif
80513 +
80514 + /*
80515 + * mm->mmap_sem is required to protect against another thread
80516 + * changing the mappings in case we sleep.
80517 + */
80518 + verify_mm_writelocked(mm);
80519 +
80520 /* Clear old maps */
80521 error = -ENOMEM;
80522 -munmap_back:
80523 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
80524 if (do_munmap(mm, addr, len))
80525 return -ENOMEM;
80526 - goto munmap_back;
80527 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
80528 }
80529
80530 /* Check against address space limit. */
80531 @@ -1460,6 +1581,16 @@ munmap_back:
80532 goto unacct_error;
80533 }
80534
80535 +#ifdef CONFIG_PAX_SEGMEXEC
80536 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
80537 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
80538 + if (!vma_m) {
80539 + error = -ENOMEM;
80540 + goto free_vma;
80541 + }
80542 + }
80543 +#endif
80544 +
80545 vma->vm_mm = mm;
80546 vma->vm_start = addr;
80547 vma->vm_end = addr + len;
80548 @@ -1484,6 +1615,13 @@ munmap_back:
80549 if (error)
80550 goto unmap_and_free_vma;
80551
80552 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
80553 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
80554 + vma->vm_flags |= VM_PAGEEXEC;
80555 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
80556 + }
80557 +#endif
80558 +
80559 /* Can addr have changed??
80560 *
80561 * Answer: Yes, several device drivers can do it in their
80562 @@ -1522,6 +1660,11 @@ munmap_back:
80563 vma_link(mm, vma, prev, rb_link, rb_parent);
80564 file = vma->vm_file;
80565
80566 +#ifdef CONFIG_PAX_SEGMEXEC
80567 + if (vma_m)
80568 + BUG_ON(pax_mirror_vma(vma_m, vma));
80569 +#endif
80570 +
80571 /* Once vma denies write, undo our temporary denial count */
80572 if (correct_wcount)
80573 atomic_inc(&inode->i_writecount);
80574 @@ -1529,6 +1672,7 @@ out:
80575 perf_event_mmap(vma);
80576
80577 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
80578 + track_exec_limit(mm, addr, addr + len, vm_flags);
80579 if (vm_flags & VM_LOCKED) {
80580 if (!mlock_vma_pages_range(vma, addr, addr + len))
80581 mm->locked_vm += (len >> PAGE_SHIFT);
80582 @@ -1550,6 +1694,12 @@ unmap_and_free_vma:
80583 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
80584 charged = 0;
80585 free_vma:
80586 +
80587 +#ifdef CONFIG_PAX_SEGMEXEC
80588 + if (vma_m)
80589 + kmem_cache_free(vm_area_cachep, vma_m);
80590 +#endif
80591 +
80592 kmem_cache_free(vm_area_cachep, vma);
80593 unacct_error:
80594 if (charged)
80595 @@ -1557,6 +1707,62 @@ unacct_error:
80596 return error;
80597 }
80598
80599 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
80600 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
80601 +{
80602 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
80603 + return (random32() & 0xFF) << PAGE_SHIFT;
80604 +
80605 + return 0;
80606 +}
80607 +#endif
80608 +
80609 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
80610 +{
80611 + if (!vma) {
80612 +#ifdef CONFIG_STACK_GROWSUP
80613 + if (addr > sysctl_heap_stack_gap)
80614 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
80615 + else
80616 + vma = find_vma(current->mm, 0);
80617 + if (vma && (vma->vm_flags & VM_GROWSUP))
80618 + return false;
80619 +#endif
80620 + return true;
80621 + }
80622 +
80623 + if (addr + len > vma->vm_start)
80624 + return false;
80625 +
80626 + if (vma->vm_flags & VM_GROWSDOWN)
80627 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
80628 +#ifdef CONFIG_STACK_GROWSUP
80629 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
80630 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
80631 +#endif
80632 + else if (offset)
80633 + return offset <= vma->vm_start - addr - len;
80634 +
80635 + return true;
80636 +}
80637 +
80638 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
80639 +{
80640 + if (vma->vm_start < len)
80641 + return -ENOMEM;
80642 +
80643 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
80644 + if (offset <= vma->vm_start - len)
80645 + return vma->vm_start - len - offset;
80646 + else
80647 + return -ENOMEM;
80648 + }
80649 +
80650 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
80651 + return vma->vm_start - len - sysctl_heap_stack_gap;
80652 + return -ENOMEM;
80653 +}
80654 +
80655 unsigned long unmapped_area(struct vm_unmapped_area_info *info)
80656 {
80657 /*
80658 @@ -1776,6 +1982,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80659 struct mm_struct *mm = current->mm;
80660 struct vm_area_struct *vma;
80661 struct vm_unmapped_area_info info;
80662 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
80663
80664 if (len > TASK_SIZE)
80665 return -ENOMEM;
80666 @@ -1783,17 +1990,26 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80667 if (flags & MAP_FIXED)
80668 return addr;
80669
80670 +#ifdef CONFIG_PAX_RANDMMAP
80671 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
80672 +#endif
80673 +
80674 if (addr) {
80675 addr = PAGE_ALIGN(addr);
80676 vma = find_vma(mm, addr);
80677 - if (TASK_SIZE - len >= addr &&
80678 - (!vma || addr + len <= vma->vm_start))
80679 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
80680 return addr;
80681 }
80682
80683 info.flags = 0;
80684 info.length = len;
80685 info.low_limit = TASK_UNMAPPED_BASE;
80686 +
80687 +#ifdef CONFIG_PAX_RANDMMAP
80688 + if (mm->pax_flags & MF_PAX_RANDMMAP)
80689 + info.low_limit += mm->delta_mmap;
80690 +#endif
80691 +
80692 info.high_limit = TASK_SIZE;
80693 info.align_mask = 0;
80694 return vm_unmapped_area(&info);
80695 @@ -1802,10 +2018,16 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
80696
80697 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
80698 {
80699 +
80700 +#ifdef CONFIG_PAX_SEGMEXEC
80701 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
80702 + return;
80703 +#endif
80704 +
80705 /*
80706 * Is this a new hole at the lowest possible address?
80707 */
80708 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
80709 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
80710 mm->free_area_cache = addr;
80711 }
80712
80713 @@ -1823,6 +2045,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80714 struct mm_struct *mm = current->mm;
80715 unsigned long addr = addr0;
80716 struct vm_unmapped_area_info info;
80717 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
80718
80719 /* requested length too big for entire address space */
80720 if (len > TASK_SIZE)
80721 @@ -1831,12 +2054,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80722 if (flags & MAP_FIXED)
80723 return addr;
80724
80725 +#ifdef CONFIG_PAX_RANDMMAP
80726 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
80727 +#endif
80728 +
80729 /* requesting a specific address */
80730 if (addr) {
80731 addr = PAGE_ALIGN(addr);
80732 vma = find_vma(mm, addr);
80733 - if (TASK_SIZE - len >= addr &&
80734 - (!vma || addr + len <= vma->vm_start))
80735 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
80736 return addr;
80737 }
80738
80739 @@ -1857,6 +2083,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80740 VM_BUG_ON(addr != -ENOMEM);
80741 info.flags = 0;
80742 info.low_limit = TASK_UNMAPPED_BASE;
80743 +
80744 +#ifdef CONFIG_PAX_RANDMMAP
80745 + if (mm->pax_flags & MF_PAX_RANDMMAP)
80746 + info.low_limit += mm->delta_mmap;
80747 +#endif
80748 +
80749 info.high_limit = TASK_SIZE;
80750 addr = vm_unmapped_area(&info);
80751 }
80752 @@ -1867,6 +2099,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
80753
80754 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
80755 {
80756 +
80757 +#ifdef CONFIG_PAX_SEGMEXEC
80758 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
80759 + return;
80760 +#endif
80761 +
80762 /*
80763 * Is this a new hole at the highest possible address?
80764 */
80765 @@ -1874,8 +2112,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
80766 mm->free_area_cache = addr;
80767
80768 /* dont allow allocations above current base */
80769 - if (mm->free_area_cache > mm->mmap_base)
80770 + if (mm->free_area_cache > mm->mmap_base) {
80771 mm->free_area_cache = mm->mmap_base;
80772 + mm->cached_hole_size = ~0UL;
80773 + }
80774 }
80775
80776 unsigned long
80777 @@ -1974,6 +2214,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
80778 return vma;
80779 }
80780
80781 +#ifdef CONFIG_PAX_SEGMEXEC
80782 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
80783 +{
80784 + struct vm_area_struct *vma_m;
80785 +
80786 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
80787 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
80788 + BUG_ON(vma->vm_mirror);
80789 + return NULL;
80790 + }
80791 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
80792 + vma_m = vma->vm_mirror;
80793 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
80794 + BUG_ON(vma->vm_file != vma_m->vm_file);
80795 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
80796 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
80797 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
80798 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
80799 + return vma_m;
80800 +}
80801 +#endif
80802 +
80803 /*
80804 * Verify that the stack growth is acceptable and
80805 * update accounting. This is shared with both the
80806 @@ -1990,6 +2252,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80807 return -ENOMEM;
80808
80809 /* Stack limit test */
80810 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
80811 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
80812 return -ENOMEM;
80813
80814 @@ -2000,6 +2263,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80815 locked = mm->locked_vm + grow;
80816 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
80817 limit >>= PAGE_SHIFT;
80818 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
80819 if (locked > limit && !capable(CAP_IPC_LOCK))
80820 return -ENOMEM;
80821 }
80822 @@ -2029,37 +2293,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
80823 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
80824 * vma is the last one with address > vma->vm_end. Have to extend vma.
80825 */
80826 +#ifndef CONFIG_IA64
80827 +static
80828 +#endif
80829 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
80830 {
80831 int error;
80832 + bool locknext;
80833
80834 if (!(vma->vm_flags & VM_GROWSUP))
80835 return -EFAULT;
80836
80837 + /* Also guard against wrapping around to address 0. */
80838 + if (address < PAGE_ALIGN(address+1))
80839 + address = PAGE_ALIGN(address+1);
80840 + else
80841 + return -ENOMEM;
80842 +
80843 /*
80844 * We must make sure the anon_vma is allocated
80845 * so that the anon_vma locking is not a noop.
80846 */
80847 if (unlikely(anon_vma_prepare(vma)))
80848 return -ENOMEM;
80849 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
80850 + if (locknext && anon_vma_prepare(vma->vm_next))
80851 + return -ENOMEM;
80852 vma_lock_anon_vma(vma);
80853 + if (locknext)
80854 + vma_lock_anon_vma(vma->vm_next);
80855
80856 /*
80857 * vma->vm_start/vm_end cannot change under us because the caller
80858 * is required to hold the mmap_sem in read mode. We need the
80859 - * anon_vma lock to serialize against concurrent expand_stacks.
80860 - * Also guard against wrapping around to address 0.
80861 + * anon_vma locks to serialize against concurrent expand_stacks
80862 + * and expand_upwards.
80863 */
80864 - if (address < PAGE_ALIGN(address+4))
80865 - address = PAGE_ALIGN(address+4);
80866 - else {
80867 - vma_unlock_anon_vma(vma);
80868 - return -ENOMEM;
80869 - }
80870 error = 0;
80871
80872 /* Somebody else might have raced and expanded it already */
80873 - if (address > vma->vm_end) {
80874 + 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)
80875 + error = -ENOMEM;
80876 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
80877 unsigned long size, grow;
80878
80879 size = address - vma->vm_start;
80880 @@ -2094,6 +2369,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
80881 }
80882 }
80883 }
80884 + if (locknext)
80885 + vma_unlock_anon_vma(vma->vm_next);
80886 vma_unlock_anon_vma(vma);
80887 khugepaged_enter_vma_merge(vma);
80888 validate_mm(vma->vm_mm);
80889 @@ -2108,6 +2385,8 @@ int expand_downwards(struct vm_area_struct *vma,
80890 unsigned long address)
80891 {
80892 int error;
80893 + bool lockprev = false;
80894 + struct vm_area_struct *prev;
80895
80896 /*
80897 * We must make sure the anon_vma is allocated
80898 @@ -2121,6 +2400,15 @@ int expand_downwards(struct vm_area_struct *vma,
80899 if (error)
80900 return error;
80901
80902 + prev = vma->vm_prev;
80903 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
80904 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
80905 +#endif
80906 + if (lockprev && anon_vma_prepare(prev))
80907 + return -ENOMEM;
80908 + if (lockprev)
80909 + vma_lock_anon_vma(prev);
80910 +
80911 vma_lock_anon_vma(vma);
80912
80913 /*
80914 @@ -2130,9 +2418,17 @@ int expand_downwards(struct vm_area_struct *vma,
80915 */
80916
80917 /* Somebody else might have raced and expanded it already */
80918 - if (address < vma->vm_start) {
80919 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
80920 + error = -ENOMEM;
80921 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
80922 unsigned long size, grow;
80923
80924 +#ifdef CONFIG_PAX_SEGMEXEC
80925 + struct vm_area_struct *vma_m;
80926 +
80927 + vma_m = pax_find_mirror_vma(vma);
80928 +#endif
80929 +
80930 size = vma->vm_end - address;
80931 grow = (vma->vm_start - address) >> PAGE_SHIFT;
80932
80933 @@ -2157,6 +2453,18 @@ int expand_downwards(struct vm_area_struct *vma,
80934 vma->vm_pgoff -= grow;
80935 anon_vma_interval_tree_post_update_vma(vma);
80936 vma_gap_update(vma);
80937 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
80938 +
80939 +#ifdef CONFIG_PAX_SEGMEXEC
80940 + if (vma_m) {
80941 + anon_vma_interval_tree_pre_update_vma(vma_m);
80942 + vma_m->vm_start -= grow << PAGE_SHIFT;
80943 + vma_m->vm_pgoff -= grow;
80944 + anon_vma_interval_tree_post_update_vma(vma_m);
80945 + vma_gap_update(vma_m);
80946 + }
80947 +#endif
80948 +
80949 spin_unlock(&vma->vm_mm->page_table_lock);
80950
80951 perf_event_mmap(vma);
80952 @@ -2263,6 +2571,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
80953 do {
80954 long nrpages = vma_pages(vma);
80955
80956 +#ifdef CONFIG_PAX_SEGMEXEC
80957 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
80958 + vma = remove_vma(vma);
80959 + continue;
80960 + }
80961 +#endif
80962 +
80963 if (vma->vm_flags & VM_ACCOUNT)
80964 nr_accounted += nrpages;
80965 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
80966 @@ -2308,6 +2623,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
80967 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
80968 vma->vm_prev = NULL;
80969 do {
80970 +
80971 +#ifdef CONFIG_PAX_SEGMEXEC
80972 + if (vma->vm_mirror) {
80973 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
80974 + vma->vm_mirror->vm_mirror = NULL;
80975 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
80976 + vma->vm_mirror = NULL;
80977 + }
80978 +#endif
80979 +
80980 vma_rb_erase(vma, &mm->mm_rb);
80981 mm->map_count--;
80982 tail_vma = vma;
80983 @@ -2339,14 +2664,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
80984 struct vm_area_struct *new;
80985 int err = -ENOMEM;
80986
80987 +#ifdef CONFIG_PAX_SEGMEXEC
80988 + struct vm_area_struct *vma_m, *new_m = NULL;
80989 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
80990 +#endif
80991 +
80992 if (is_vm_hugetlb_page(vma) && (addr &
80993 ~(huge_page_mask(hstate_vma(vma)))))
80994 return -EINVAL;
80995
80996 +#ifdef CONFIG_PAX_SEGMEXEC
80997 + vma_m = pax_find_mirror_vma(vma);
80998 +#endif
80999 +
81000 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81001 if (!new)
81002 goto out_err;
81003
81004 +#ifdef CONFIG_PAX_SEGMEXEC
81005 + if (vma_m) {
81006 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
81007 + if (!new_m) {
81008 + kmem_cache_free(vm_area_cachep, new);
81009 + goto out_err;
81010 + }
81011 + }
81012 +#endif
81013 +
81014 /* most fields are the same, copy all, and then fixup */
81015 *new = *vma;
81016
81017 @@ -2359,6 +2703,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81018 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
81019 }
81020
81021 +#ifdef CONFIG_PAX_SEGMEXEC
81022 + if (vma_m) {
81023 + *new_m = *vma_m;
81024 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
81025 + new_m->vm_mirror = new;
81026 + new->vm_mirror = new_m;
81027 +
81028 + if (new_below)
81029 + new_m->vm_end = addr_m;
81030 + else {
81031 + new_m->vm_start = addr_m;
81032 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
81033 + }
81034 + }
81035 +#endif
81036 +
81037 pol = mpol_dup(vma_policy(vma));
81038 if (IS_ERR(pol)) {
81039 err = PTR_ERR(pol);
81040 @@ -2381,6 +2741,36 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81041 else
81042 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
81043
81044 +#ifdef CONFIG_PAX_SEGMEXEC
81045 + if (!err && vma_m) {
81046 + if (anon_vma_clone(new_m, vma_m))
81047 + goto out_free_mpol;
81048 +
81049 + mpol_get(pol);
81050 + vma_set_policy(new_m, pol);
81051 +
81052 + if (new_m->vm_file)
81053 + get_file(new_m->vm_file);
81054 +
81055 + if (new_m->vm_ops && new_m->vm_ops->open)
81056 + new_m->vm_ops->open(new_m);
81057 +
81058 + if (new_below)
81059 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
81060 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
81061 + else
81062 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
81063 +
81064 + if (err) {
81065 + if (new_m->vm_ops && new_m->vm_ops->close)
81066 + new_m->vm_ops->close(new_m);
81067 + if (new_m->vm_file)
81068 + fput(new_m->vm_file);
81069 + mpol_put(pol);
81070 + }
81071 + }
81072 +#endif
81073 +
81074 /* Success. */
81075 if (!err)
81076 return 0;
81077 @@ -2390,10 +2780,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81078 new->vm_ops->close(new);
81079 if (new->vm_file)
81080 fput(new->vm_file);
81081 - unlink_anon_vmas(new);
81082 out_free_mpol:
81083 mpol_put(pol);
81084 out_free_vma:
81085 +
81086 +#ifdef CONFIG_PAX_SEGMEXEC
81087 + if (new_m) {
81088 + unlink_anon_vmas(new_m);
81089 + kmem_cache_free(vm_area_cachep, new_m);
81090 + }
81091 +#endif
81092 +
81093 + unlink_anon_vmas(new);
81094 kmem_cache_free(vm_area_cachep, new);
81095 out_err:
81096 return err;
81097 @@ -2406,6 +2804,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
81098 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81099 unsigned long addr, int new_below)
81100 {
81101 +
81102 +#ifdef CONFIG_PAX_SEGMEXEC
81103 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
81104 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
81105 + if (mm->map_count >= sysctl_max_map_count-1)
81106 + return -ENOMEM;
81107 + } else
81108 +#endif
81109 +
81110 if (mm->map_count >= sysctl_max_map_count)
81111 return -ENOMEM;
81112
81113 @@ -2417,11 +2824,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81114 * work. This now handles partial unmappings.
81115 * Jeremy Fitzhardinge <jeremy@goop.org>
81116 */
81117 +#ifdef CONFIG_PAX_SEGMEXEC
81118 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81119 {
81120 + int ret = __do_munmap(mm, start, len);
81121 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
81122 + return ret;
81123 +
81124 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
81125 +}
81126 +
81127 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81128 +#else
81129 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81130 +#endif
81131 +{
81132 unsigned long end;
81133 struct vm_area_struct *vma, *prev, *last;
81134
81135 + /*
81136 + * mm->mmap_sem is required to protect against another thread
81137 + * changing the mappings in case we sleep.
81138 + */
81139 + verify_mm_writelocked(mm);
81140 +
81141 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
81142 return -EINVAL;
81143
81144 @@ -2496,6 +2922,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
81145 /* Fix up all other VM information */
81146 remove_vma_list(mm, vma);
81147
81148 + track_exec_limit(mm, start, end, 0UL);
81149 +
81150 return 0;
81151 }
81152
81153 @@ -2504,6 +2932,13 @@ int vm_munmap(unsigned long start, size_t len)
81154 int ret;
81155 struct mm_struct *mm = current->mm;
81156
81157 +
81158 +#ifdef CONFIG_PAX_SEGMEXEC
81159 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
81160 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
81161 + return -EINVAL;
81162 +#endif
81163 +
81164 down_write(&mm->mmap_sem);
81165 ret = do_munmap(mm, start, len);
81166 up_write(&mm->mmap_sem);
81167 @@ -2517,16 +2952,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
81168 return vm_munmap(addr, len);
81169 }
81170
81171 -static inline void verify_mm_writelocked(struct mm_struct *mm)
81172 -{
81173 -#ifdef CONFIG_DEBUG_VM
81174 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
81175 - WARN_ON(1);
81176 - up_read(&mm->mmap_sem);
81177 - }
81178 -#endif
81179 -}
81180 -
81181 /*
81182 * this is really a simplified "do_mmap". it only handles
81183 * anonymous maps. eventually we may be able to do some
81184 @@ -2540,6 +2965,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81185 struct rb_node ** rb_link, * rb_parent;
81186 pgoff_t pgoff = addr >> PAGE_SHIFT;
81187 int error;
81188 + unsigned long charged;
81189
81190 len = PAGE_ALIGN(len);
81191 if (!len)
81192 @@ -2547,16 +2973,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81193
81194 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
81195
81196 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
81197 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
81198 + flags &= ~VM_EXEC;
81199 +
81200 +#ifdef CONFIG_PAX_MPROTECT
81201 + if (mm->pax_flags & MF_PAX_MPROTECT)
81202 + flags &= ~VM_MAYEXEC;
81203 +#endif
81204 +
81205 + }
81206 +#endif
81207 +
81208 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
81209 if (error & ~PAGE_MASK)
81210 return error;
81211
81212 + charged = len >> PAGE_SHIFT;
81213 +
81214 /*
81215 * mlock MCL_FUTURE?
81216 */
81217 if (mm->def_flags & VM_LOCKED) {
81218 unsigned long locked, lock_limit;
81219 - locked = len >> PAGE_SHIFT;
81220 + locked = charged;
81221 locked += mm->locked_vm;
81222 lock_limit = rlimit(RLIMIT_MEMLOCK);
81223 lock_limit >>= PAGE_SHIFT;
81224 @@ -2573,21 +3013,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81225 /*
81226 * Clear old maps. this also does some error checking for us
81227 */
81228 - munmap_back:
81229 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
81230 if (do_munmap(mm, addr, len))
81231 return -ENOMEM;
81232 - goto munmap_back;
81233 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
81234 }
81235
81236 /* Check against address space limits *after* clearing old maps... */
81237 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
81238 + if (!may_expand_vm(mm, charged))
81239 return -ENOMEM;
81240
81241 if (mm->map_count > sysctl_max_map_count)
81242 return -ENOMEM;
81243
81244 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
81245 + if (security_vm_enough_memory_mm(mm, charged))
81246 return -ENOMEM;
81247
81248 /* Can we just expand an old private anonymous mapping? */
81249 @@ -2601,7 +3040,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81250 */
81251 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81252 if (!vma) {
81253 - vm_unacct_memory(len >> PAGE_SHIFT);
81254 + vm_unacct_memory(charged);
81255 return -ENOMEM;
81256 }
81257
81258 @@ -2615,11 +3054,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
81259 vma_link(mm, vma, prev, rb_link, rb_parent);
81260 out:
81261 perf_event_mmap(vma);
81262 - mm->total_vm += len >> PAGE_SHIFT;
81263 + mm->total_vm += charged;
81264 if (flags & VM_LOCKED) {
81265 if (!mlock_vma_pages_range(vma, addr, addr + len))
81266 - mm->locked_vm += (len >> PAGE_SHIFT);
81267 + mm->locked_vm += charged;
81268 }
81269 + track_exec_limit(mm, addr, addr + len, flags);
81270 return addr;
81271 }
81272
81273 @@ -2677,6 +3117,7 @@ void exit_mmap(struct mm_struct *mm)
81274 while (vma) {
81275 if (vma->vm_flags & VM_ACCOUNT)
81276 nr_accounted += vma_pages(vma);
81277 + vma->vm_mirror = NULL;
81278 vma = remove_vma(vma);
81279 }
81280 vm_unacct_memory(nr_accounted);
81281 @@ -2693,6 +3134,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81282 struct vm_area_struct *prev;
81283 struct rb_node **rb_link, *rb_parent;
81284
81285 +#ifdef CONFIG_PAX_SEGMEXEC
81286 + struct vm_area_struct *vma_m = NULL;
81287 +#endif
81288 +
81289 + if (security_mmap_addr(vma->vm_start))
81290 + return -EPERM;
81291 +
81292 /*
81293 * The vm_pgoff of a purely anonymous vma should be irrelevant
81294 * until its first write fault, when page's anon_vma and index
81295 @@ -2716,7 +3164,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
81296 security_vm_enough_memory_mm(mm, vma_pages(vma)))
81297 return -ENOMEM;
81298
81299 +#ifdef CONFIG_PAX_SEGMEXEC
81300 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
81301 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81302 + if (!vma_m)
81303 + return -ENOMEM;
81304 + }
81305 +#endif
81306 +
81307 vma_link(mm, vma, prev, rb_link, rb_parent);
81308 +
81309 +#ifdef CONFIG_PAX_SEGMEXEC
81310 + if (vma_m)
81311 + BUG_ON(pax_mirror_vma(vma_m, vma));
81312 +#endif
81313 +
81314 return 0;
81315 }
81316
81317 @@ -2736,6 +3198,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
81318 struct mempolicy *pol;
81319 bool faulted_in_anon_vma = true;
81320
81321 + BUG_ON(vma->vm_mirror);
81322 +
81323 /*
81324 * If anonymous vma has not yet been faulted, update new pgoff
81325 * to match new location, to increase its chance of merging.
81326 @@ -2802,6 +3266,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
81327 return NULL;
81328 }
81329
81330 +#ifdef CONFIG_PAX_SEGMEXEC
81331 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
81332 +{
81333 + struct vm_area_struct *prev_m;
81334 + struct rb_node **rb_link_m, *rb_parent_m;
81335 + struct mempolicy *pol_m;
81336 +
81337 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
81338 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
81339 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
81340 + *vma_m = *vma;
81341 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
81342 + if (anon_vma_clone(vma_m, vma))
81343 + return -ENOMEM;
81344 + pol_m = vma_policy(vma_m);
81345 + mpol_get(pol_m);
81346 + vma_set_policy(vma_m, pol_m);
81347 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
81348 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
81349 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
81350 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
81351 + if (vma_m->vm_file)
81352 + get_file(vma_m->vm_file);
81353 + if (vma_m->vm_ops && vma_m->vm_ops->open)
81354 + vma_m->vm_ops->open(vma_m);
81355 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
81356 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
81357 + vma_m->vm_mirror = vma;
81358 + vma->vm_mirror = vma_m;
81359 + return 0;
81360 +}
81361 +#endif
81362 +
81363 /*
81364 * Return true if the calling process may expand its vm space by the passed
81365 * number of pages
81366 @@ -2813,6 +3310,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
81367
81368 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
81369
81370 +#ifdef CONFIG_PAX_RANDMMAP
81371 + if (mm->pax_flags & MF_PAX_RANDMMAP)
81372 + cur -= mm->aslr_gap;
81373 +#endif
81374 +
81375 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
81376 if (cur + npages > lim)
81377 return 0;
81378 return 1;
81379 @@ -2883,6 +3386,22 @@ int install_special_mapping(struct mm_struct *mm,
81380 vma->vm_start = addr;
81381 vma->vm_end = addr + len;
81382
81383 +#ifdef CONFIG_PAX_MPROTECT
81384 + if (mm->pax_flags & MF_PAX_MPROTECT) {
81385 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
81386 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
81387 + return -EPERM;
81388 + if (!(vm_flags & VM_EXEC))
81389 + vm_flags &= ~VM_MAYEXEC;
81390 +#else
81391 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
81392 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
81393 +#endif
81394 + else
81395 + vm_flags &= ~VM_MAYWRITE;
81396 + }
81397 +#endif
81398 +
81399 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
81400 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
81401
81402 diff --git a/mm/mprotect.c b/mm/mprotect.c
81403 index 94722a4..9837984 100644
81404 --- a/mm/mprotect.c
81405 +++ b/mm/mprotect.c
81406 @@ -23,10 +23,17 @@
81407 #include <linux/mmu_notifier.h>
81408 #include <linux/migrate.h>
81409 #include <linux/perf_event.h>
81410 +
81411 +#ifdef CONFIG_PAX_MPROTECT
81412 +#include <linux/elf.h>
81413 +#include <linux/binfmts.h>
81414 +#endif
81415 +
81416 #include <asm/uaccess.h>
81417 #include <asm/pgtable.h>
81418 #include <asm/cacheflush.h>
81419 #include <asm/tlbflush.h>
81420 +#include <asm/mmu_context.h>
81421
81422 #ifndef pgprot_modify
81423 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
81424 @@ -233,6 +240,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
81425 return pages;
81426 }
81427
81428 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81429 +/* called while holding the mmap semaphor for writing except stack expansion */
81430 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
81431 +{
81432 + unsigned long oldlimit, newlimit = 0UL;
81433 +
81434 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
81435 + return;
81436 +
81437 + spin_lock(&mm->page_table_lock);
81438 + oldlimit = mm->context.user_cs_limit;
81439 + if ((prot & VM_EXEC) && oldlimit < end)
81440 + /* USER_CS limit moved up */
81441 + newlimit = end;
81442 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
81443 + /* USER_CS limit moved down */
81444 + newlimit = start;
81445 +
81446 + if (newlimit) {
81447 + mm->context.user_cs_limit = newlimit;
81448 +
81449 +#ifdef CONFIG_SMP
81450 + wmb();
81451 + cpus_clear(mm->context.cpu_user_cs_mask);
81452 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
81453 +#endif
81454 +
81455 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
81456 + }
81457 + spin_unlock(&mm->page_table_lock);
81458 + if (newlimit == end) {
81459 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
81460 +
81461 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
81462 + if (is_vm_hugetlb_page(vma))
81463 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
81464 + else
81465 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
81466 + }
81467 +}
81468 +#endif
81469 +
81470 int
81471 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81472 unsigned long start, unsigned long end, unsigned long newflags)
81473 @@ -245,11 +294,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81474 int error;
81475 int dirty_accountable = 0;
81476
81477 +#ifdef CONFIG_PAX_SEGMEXEC
81478 + struct vm_area_struct *vma_m = NULL;
81479 + unsigned long start_m, end_m;
81480 +
81481 + start_m = start + SEGMEXEC_TASK_SIZE;
81482 + end_m = end + SEGMEXEC_TASK_SIZE;
81483 +#endif
81484 +
81485 if (newflags == oldflags) {
81486 *pprev = vma;
81487 return 0;
81488 }
81489
81490 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
81491 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
81492 +
81493 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
81494 + return -ENOMEM;
81495 +
81496 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
81497 + return -ENOMEM;
81498 + }
81499 +
81500 /*
81501 * If we make a private mapping writable we increase our commit;
81502 * but (without finer accounting) cannot reduce our commit if we
81503 @@ -266,6 +333,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
81504 }
81505 }
81506
81507 +#ifdef CONFIG_PAX_SEGMEXEC
81508 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
81509 + if (start != vma->vm_start) {
81510 + error = split_vma(mm, vma, start, 1);
81511 + if (error)
81512 + goto fail;
81513 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
81514 + *pprev = (*pprev)->vm_next;
81515 + }
81516 +
81517 + if (end != vma->vm_end) {
81518 + error = split_vma(mm, vma, end, 0);
81519 + if (error)
81520 + goto fail;
81521 + }
81522 +
81523 + if (pax_find_mirror_vma(vma)) {
81524 + error = __do_munmap(mm, start_m, end_m - start_m);
81525 + if (error)
81526 + goto fail;
81527 + } else {
81528 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
81529 + if (!vma_m) {
81530 + error = -ENOMEM;
81531 + goto fail;
81532 + }
81533 + vma->vm_flags = newflags;
81534 + error = pax_mirror_vma(vma_m, vma);
81535 + if (error) {
81536 + vma->vm_flags = oldflags;
81537 + goto fail;
81538 + }
81539 + }
81540 + }
81541 +#endif
81542 +
81543 /*
81544 * First try to merge with previous and/or next vma.
81545 */
81546 @@ -296,9 +399,21 @@ success:
81547 * vm_flags and vm_page_prot are protected by the mmap_sem
81548 * held in write mode.
81549 */
81550 +
81551 +#ifdef CONFIG_PAX_SEGMEXEC
81552 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
81553 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
81554 +#endif
81555 +
81556 vma->vm_flags = newflags;
81557 +
81558 +#ifdef CONFIG_PAX_MPROTECT
81559 + if (mm->binfmt && mm->binfmt->handle_mprotect)
81560 + mm->binfmt->handle_mprotect(vma, newflags);
81561 +#endif
81562 +
81563 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
81564 - vm_get_page_prot(newflags));
81565 + vm_get_page_prot(vma->vm_flags));
81566
81567 if (vma_wants_writenotify(vma)) {
81568 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
81569 @@ -337,6 +452,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81570 end = start + len;
81571 if (end <= start)
81572 return -ENOMEM;
81573 +
81574 +#ifdef CONFIG_PAX_SEGMEXEC
81575 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
81576 + if (end > SEGMEXEC_TASK_SIZE)
81577 + return -EINVAL;
81578 + } else
81579 +#endif
81580 +
81581 + if (end > TASK_SIZE)
81582 + return -EINVAL;
81583 +
81584 if (!arch_validate_prot(prot))
81585 return -EINVAL;
81586
81587 @@ -344,7 +470,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81588 /*
81589 * Does the application expect PROT_READ to imply PROT_EXEC:
81590 */
81591 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
81592 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
81593 prot |= PROT_EXEC;
81594
81595 vm_flags = calc_vm_prot_bits(prot);
81596 @@ -376,6 +502,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81597 if (start > vma->vm_start)
81598 prev = vma;
81599
81600 +#ifdef CONFIG_PAX_MPROTECT
81601 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
81602 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
81603 +#endif
81604 +
81605 for (nstart = start ; ; ) {
81606 unsigned long newflags;
81607
81608 @@ -386,6 +517,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81609
81610 /* newflags >> 4 shift VM_MAY% in place of VM_% */
81611 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
81612 + if (prot & (PROT_WRITE | PROT_EXEC))
81613 + gr_log_rwxmprotect(vma->vm_file);
81614 +
81615 + error = -EACCES;
81616 + goto out;
81617 + }
81618 +
81619 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
81620 error = -EACCES;
81621 goto out;
81622 }
81623 @@ -400,6 +539,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
81624 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
81625 if (error)
81626 goto out;
81627 +
81628 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
81629 +
81630 nstart = tmp;
81631
81632 if (nstart < prev->vm_end)
81633 diff --git a/mm/mremap.c b/mm/mremap.c
81634 index e1031e1..1f2a0a1 100644
81635 --- a/mm/mremap.c
81636 +++ b/mm/mremap.c
81637 @@ -125,6 +125,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
81638 continue;
81639 pte = ptep_get_and_clear(mm, old_addr, old_pte);
81640 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
81641 +
81642 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
81643 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
81644 + pte = pte_exprotect(pte);
81645 +#endif
81646 +
81647 set_pte_at(mm, new_addr, new_pte, pte);
81648 }
81649
81650 @@ -319,6 +325,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
81651 if (is_vm_hugetlb_page(vma))
81652 goto Einval;
81653
81654 +#ifdef CONFIG_PAX_SEGMEXEC
81655 + if (pax_find_mirror_vma(vma))
81656 + goto Einval;
81657 +#endif
81658 +
81659 /* We can't remap across vm area boundaries */
81660 if (old_len > vma->vm_end - addr)
81661 goto Efault;
81662 @@ -375,20 +386,25 @@ static unsigned long mremap_to(unsigned long addr,
81663 unsigned long ret = -EINVAL;
81664 unsigned long charged = 0;
81665 unsigned long map_flags;
81666 + unsigned long pax_task_size = TASK_SIZE;
81667
81668 if (new_addr & ~PAGE_MASK)
81669 goto out;
81670
81671 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
81672 +#ifdef CONFIG_PAX_SEGMEXEC
81673 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
81674 + pax_task_size = SEGMEXEC_TASK_SIZE;
81675 +#endif
81676 +
81677 + pax_task_size -= PAGE_SIZE;
81678 +
81679 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
81680 goto out;
81681
81682 /* Check if the location we're moving into overlaps the
81683 * old location at all, and fail if it does.
81684 */
81685 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
81686 - goto out;
81687 -
81688 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
81689 + if (addr + old_len > new_addr && new_addr + new_len > addr)
81690 goto out;
81691
81692 ret = do_munmap(mm, new_addr, new_len);
81693 @@ -456,6 +472,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81694 struct vm_area_struct *vma;
81695 unsigned long ret = -EINVAL;
81696 unsigned long charged = 0;
81697 + unsigned long pax_task_size = TASK_SIZE;
81698
81699 down_write(&current->mm->mmap_sem);
81700
81701 @@ -476,6 +493,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81702 if (!new_len)
81703 goto out;
81704
81705 +#ifdef CONFIG_PAX_SEGMEXEC
81706 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
81707 + pax_task_size = SEGMEXEC_TASK_SIZE;
81708 +#endif
81709 +
81710 + pax_task_size -= PAGE_SIZE;
81711 +
81712 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
81713 + old_len > pax_task_size || addr > pax_task_size-old_len)
81714 + goto out;
81715 +
81716 if (flags & MREMAP_FIXED) {
81717 if (flags & MREMAP_MAYMOVE)
81718 ret = mremap_to(addr, old_len, new_addr, new_len);
81719 @@ -524,6 +552,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81720 addr + new_len);
81721 }
81722 ret = addr;
81723 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
81724 goto out;
81725 }
81726 }
81727 @@ -547,7 +576,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
81728 goto out;
81729 }
81730
81731 + map_flags = vma->vm_flags;
81732 ret = move_vma(vma, addr, old_len, new_len, new_addr);
81733 + if (!(ret & ~PAGE_MASK)) {
81734 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
81735 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
81736 + }
81737 }
81738 out:
81739 if (ret & ~PAGE_MASK)
81740 diff --git a/mm/nommu.c b/mm/nommu.c
81741 index 79c3cac..4d357e0 100644
81742 --- a/mm/nommu.c
81743 +++ b/mm/nommu.c
81744 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
81745 int sysctl_overcommit_ratio = 50; /* default is 50% */
81746 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
81747 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
81748 -int heap_stack_gap = 0;
81749
81750 atomic_long_t mmap_pages_allocated;
81751
81752 @@ -839,15 +838,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
81753 EXPORT_SYMBOL(find_vma);
81754
81755 /*
81756 - * find a VMA
81757 - * - we don't extend stack VMAs under NOMMU conditions
81758 - */
81759 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
81760 -{
81761 - return find_vma(mm, addr);
81762 -}
81763 -
81764 -/*
81765 * expand a stack to a given address
81766 * - not supported under NOMMU conditions
81767 */
81768 @@ -1555,6 +1545,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
81769
81770 /* most fields are the same, copy all, and then fixup */
81771 *new = *vma;
81772 + INIT_LIST_HEAD(&new->anon_vma_chain);
81773 *region = *vma->vm_region;
81774 new->vm_region = region;
81775
81776 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
81777 index 0713bfb..e3774e0 100644
81778 --- a/mm/page-writeback.c
81779 +++ b/mm/page-writeback.c
81780 @@ -1630,7 +1630,7 @@ ratelimit_handler(struct notifier_block *self, unsigned long action,
81781 }
81782 }
81783
81784 -static struct notifier_block __cpuinitdata ratelimit_nb = {
81785 +static struct notifier_block ratelimit_nb = {
81786 .notifier_call = ratelimit_handler,
81787 .next = NULL,
81788 };
81789 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
81790 index 6a83cd3..3ab04ef 100644
81791 --- a/mm/page_alloc.c
81792 +++ b/mm/page_alloc.c
81793 @@ -58,6 +58,7 @@
81794 #include <linux/prefetch.h>
81795 #include <linux/migrate.h>
81796 #include <linux/page-debug-flags.h>
81797 +#include <linux/random.h>
81798
81799 #include <asm/tlbflush.h>
81800 #include <asm/div64.h>
81801 @@ -338,7 +339,7 @@ out:
81802 * This usage means that zero-order pages may not be compound.
81803 */
81804
81805 -static void free_compound_page(struct page *page)
81806 +void free_compound_page(struct page *page)
81807 {
81808 __free_pages_ok(page, compound_order(page));
81809 }
81810 @@ -693,6 +694,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
81811 int i;
81812 int bad = 0;
81813
81814 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81815 + unsigned long index = 1UL << order;
81816 +#endif
81817 +
81818 trace_mm_page_free(page, order);
81819 kmemcheck_free_shadow(page, order);
81820
81821 @@ -708,6 +713,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
81822 debug_check_no_obj_freed(page_address(page),
81823 PAGE_SIZE << order);
81824 }
81825 +
81826 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
81827 + for (; index; --index)
81828 + sanitize_highpage(page + index - 1);
81829 +#endif
81830 +
81831 arch_free_page(page, order);
81832 kernel_map_pages(page, 1 << order, 0);
81833
81834 @@ -730,6 +741,19 @@ static void __free_pages_ok(struct page *page, unsigned int order)
81835 local_irq_restore(flags);
81836 }
81837
81838 +#ifdef CONFIG_PAX_LATENT_ENTROPY
81839 +bool __meminitdata extra_latent_entropy;
81840 +
81841 +static int __init setup_pax_extra_latent_entropy(char *str)
81842 +{
81843 + extra_latent_entropy = true;
81844 + return 0;
81845 +}
81846 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
81847 +
81848 +volatile u64 latent_entropy;
81849 +#endif
81850 +
81851 /*
81852 * Read access to zone->managed_pages is safe because it's unsigned long,
81853 * but we still need to serialize writers. Currently all callers of
81854 @@ -752,6 +776,19 @@ void __meminit __free_pages_bootmem(struct page *page, unsigned int order)
81855 set_page_count(p, 0);
81856 }
81857
81858 +#ifdef CONFIG_PAX_LATENT_ENTROPY
81859 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
81860 + u64 hash = 0;
81861 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
81862 + const u64 *data = lowmem_page_address(page);
81863 +
81864 + for (index = 0; index < end; index++)
81865 + hash ^= hash + data[index];
81866 + latent_entropy ^= hash;
81867 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
81868 + }
81869 +#endif
81870 +
81871 page_zone(page)->managed_pages += 1 << order;
81872 set_page_refcounted(page);
81873 __free_pages(page, order);
81874 @@ -861,8 +898,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
81875 arch_alloc_page(page, order);
81876 kernel_map_pages(page, 1 << order, 1);
81877
81878 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
81879 if (gfp_flags & __GFP_ZERO)
81880 prep_zero_page(page, order, gfp_flags);
81881 +#endif
81882
81883 if (order && (gfp_flags & __GFP_COMP))
81884 prep_compound_page(page, order);
81885 @@ -3752,7 +3791,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
81886 unsigned long pfn;
81887
81888 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
81889 +#ifdef CONFIG_X86_32
81890 + /* boot failures in VMware 8 on 32bit vanilla since
81891 + this change */
81892 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
81893 +#else
81894 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
81895 +#endif
81896 return 1;
81897 }
81898 return 0;
81899 diff --git a/mm/percpu.c b/mm/percpu.c
81900 index 8c8e08f..73a5cda 100644
81901 --- a/mm/percpu.c
81902 +++ b/mm/percpu.c
81903 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
81904 static unsigned int pcpu_high_unit_cpu __read_mostly;
81905
81906 /* the address of the first chunk which starts with the kernel static area */
81907 -void *pcpu_base_addr __read_mostly;
81908 +void *pcpu_base_addr __read_only;
81909 EXPORT_SYMBOL_GPL(pcpu_base_addr);
81910
81911 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
81912 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
81913 index 926b466..b23df53 100644
81914 --- a/mm/process_vm_access.c
81915 +++ b/mm/process_vm_access.c
81916 @@ -13,6 +13,7 @@
81917 #include <linux/uio.h>
81918 #include <linux/sched.h>
81919 #include <linux/highmem.h>
81920 +#include <linux/security.h>
81921 #include <linux/ptrace.h>
81922 #include <linux/slab.h>
81923 #include <linux/syscalls.h>
81924 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
81925 size_t iov_l_curr_offset = 0;
81926 ssize_t iov_len;
81927
81928 + return -ENOSYS; // PaX: until properly audited
81929 +
81930 /*
81931 * Work out how many pages of struct pages we're going to need
81932 * when eventually calling get_user_pages
81933 */
81934 for (i = 0; i < riovcnt; i++) {
81935 iov_len = rvec[i].iov_len;
81936 - if (iov_len > 0) {
81937 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
81938 - + iov_len)
81939 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
81940 - / PAGE_SIZE + 1;
81941 - nr_pages = max(nr_pages, nr_pages_iov);
81942 - }
81943 + if (iov_len <= 0)
81944 + continue;
81945 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
81946 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
81947 + nr_pages = max(nr_pages, nr_pages_iov);
81948 }
81949
81950 if (nr_pages == 0)
81951 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
81952 goto free_proc_pages;
81953 }
81954
81955 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
81956 + rc = -EPERM;
81957 + goto put_task_struct;
81958 + }
81959 +
81960 mm = mm_access(task, PTRACE_MODE_ATTACH);
81961 if (!mm || IS_ERR(mm)) {
81962 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
81963 diff --git a/mm/rmap.c b/mm/rmap.c
81964 index 2c78f8c..9e9c624 100644
81965 --- a/mm/rmap.c
81966 +++ b/mm/rmap.c
81967 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81968 struct anon_vma *anon_vma = vma->anon_vma;
81969 struct anon_vma_chain *avc;
81970
81971 +#ifdef CONFIG_PAX_SEGMEXEC
81972 + struct anon_vma_chain *avc_m = NULL;
81973 +#endif
81974 +
81975 might_sleep();
81976 if (unlikely(!anon_vma)) {
81977 struct mm_struct *mm = vma->vm_mm;
81978 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81979 if (!avc)
81980 goto out_enomem;
81981
81982 +#ifdef CONFIG_PAX_SEGMEXEC
81983 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
81984 + if (!avc_m)
81985 + goto out_enomem_free_avc;
81986 +#endif
81987 +
81988 anon_vma = find_mergeable_anon_vma(vma);
81989 allocated = NULL;
81990 if (!anon_vma) {
81991 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
81992 /* page_table_lock to protect against threads */
81993 spin_lock(&mm->page_table_lock);
81994 if (likely(!vma->anon_vma)) {
81995 +
81996 +#ifdef CONFIG_PAX_SEGMEXEC
81997 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
81998 +
81999 + if (vma_m) {
82000 + BUG_ON(vma_m->anon_vma);
82001 + vma_m->anon_vma = anon_vma;
82002 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
82003 + avc_m = NULL;
82004 + }
82005 +#endif
82006 +
82007 vma->anon_vma = anon_vma;
82008 anon_vma_chain_link(vma, avc, anon_vma);
82009 allocated = NULL;
82010 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
82011
82012 if (unlikely(allocated))
82013 put_anon_vma(allocated);
82014 +
82015 +#ifdef CONFIG_PAX_SEGMEXEC
82016 + if (unlikely(avc_m))
82017 + anon_vma_chain_free(avc_m);
82018 +#endif
82019 +
82020 if (unlikely(avc))
82021 anon_vma_chain_free(avc);
82022 }
82023 return 0;
82024
82025 out_enomem_free_avc:
82026 +
82027 +#ifdef CONFIG_PAX_SEGMEXEC
82028 + if (avc_m)
82029 + anon_vma_chain_free(avc_m);
82030 +#endif
82031 +
82032 anon_vma_chain_free(avc);
82033 out_enomem:
82034 return -ENOMEM;
82035 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
82036 * Attach the anon_vmas from src to dst.
82037 * Returns 0 on success, -ENOMEM on failure.
82038 */
82039 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82040 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
82041 {
82042 struct anon_vma_chain *avc, *pavc;
82043 struct anon_vma *root = NULL;
82044 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
82045 * the corresponding VMA in the parent process is attached to.
82046 * Returns 0 on success, non-zero on failure.
82047 */
82048 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
82049 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
82050 {
82051 struct anon_vma_chain *avc;
82052 struct anon_vma *anon_vma;
82053 diff --git a/mm/shmem.c b/mm/shmem.c
82054 index efd0b3a..994b702 100644
82055 --- a/mm/shmem.c
82056 +++ b/mm/shmem.c
82057 @@ -31,7 +31,7 @@
82058 #include <linux/export.h>
82059 #include <linux/swap.h>
82060
82061 -static struct vfsmount *shm_mnt;
82062 +struct vfsmount *shm_mnt;
82063
82064 #ifdef CONFIG_SHMEM
82065 /*
82066 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
82067 #define BOGO_DIRENT_SIZE 20
82068
82069 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
82070 -#define SHORT_SYMLINK_LEN 128
82071 +#define SHORT_SYMLINK_LEN 64
82072
82073 /*
82074 * shmem_fallocate and shmem_writepage communicate via inode->i_private
82075 @@ -2202,6 +2202,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
82076 static int shmem_xattr_validate(const char *name)
82077 {
82078 struct { const char *prefix; size_t len; } arr[] = {
82079 +
82080 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82081 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
82082 +#endif
82083 +
82084 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
82085 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
82086 };
82087 @@ -2257,6 +2262,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
82088 if (err)
82089 return err;
82090
82091 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
82092 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
82093 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
82094 + return -EOPNOTSUPP;
82095 + if (size > 8)
82096 + return -EINVAL;
82097 + }
82098 +#endif
82099 +
82100 return simple_xattr_set(&info->xattrs, name, value, size, flags);
82101 }
82102
82103 @@ -2562,8 +2576,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
82104 int err = -ENOMEM;
82105
82106 /* Round up to L1_CACHE_BYTES to resist false sharing */
82107 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
82108 - L1_CACHE_BYTES), GFP_KERNEL);
82109 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
82110 if (!sbinfo)
82111 return -ENOMEM;
82112
82113 diff --git a/mm/slab.c b/mm/slab.c
82114 index e7667a3..b62c169 100644
82115 --- a/mm/slab.c
82116 +++ b/mm/slab.c
82117 @@ -306,7 +306,7 @@ struct kmem_list3 {
82118 * Need this for bootstrapping a per node allocator.
82119 */
82120 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
82121 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
82122 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
82123 #define CACHE_CACHE 0
82124 #define SIZE_AC MAX_NUMNODES
82125 #define SIZE_L3 (2 * MAX_NUMNODES)
82126 @@ -407,10 +407,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
82127 if ((x)->max_freeable < i) \
82128 (x)->max_freeable = i; \
82129 } while (0)
82130 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
82131 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
82132 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
82133 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
82134 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
82135 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
82136 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
82137 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
82138 #else
82139 #define STATS_INC_ACTIVE(x) do { } while (0)
82140 #define STATS_DEC_ACTIVE(x) do { } while (0)
82141 @@ -518,7 +518,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
82142 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
82143 */
82144 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
82145 - const struct slab *slab, void *obj)
82146 + const struct slab *slab, const void *obj)
82147 {
82148 u32 offset = (obj - slab->s_mem);
82149 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
82150 @@ -539,12 +539,13 @@ EXPORT_SYMBOL(malloc_sizes);
82151 struct cache_names {
82152 char *name;
82153 char *name_dma;
82154 + char *name_usercopy;
82155 };
82156
82157 static struct cache_names __initdata cache_names[] = {
82158 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
82159 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
82160 #include <linux/kmalloc_sizes.h>
82161 - {NULL,}
82162 + {NULL}
82163 #undef CACHE
82164 };
82165
82166 @@ -729,6 +730,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
82167 if (unlikely(gfpflags & GFP_DMA))
82168 return csizep->cs_dmacachep;
82169 #endif
82170 +
82171 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82172 + if (unlikely(gfpflags & GFP_USERCOPY))
82173 + return csizep->cs_usercopycachep;
82174 +#endif
82175 +
82176 return csizep->cs_cachep;
82177 }
82178
82179 @@ -1482,7 +1489,7 @@ static int __cpuinit cpuup_callback(struct notifier_block *nfb,
82180 return notifier_from_errno(err);
82181 }
82182
82183 -static struct notifier_block __cpuinitdata cpucache_notifier = {
82184 +static struct notifier_block cpucache_notifier = {
82185 &cpuup_callback, NULL, 0
82186 };
82187
82188 @@ -1667,12 +1674,12 @@ void __init kmem_cache_init(void)
82189 */
82190
82191 sizes[INDEX_AC].cs_cachep = create_kmalloc_cache(names[INDEX_AC].name,
82192 - sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS);
82193 + sizes[INDEX_AC].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82194
82195 if (INDEX_AC != INDEX_L3)
82196 sizes[INDEX_L3].cs_cachep =
82197 create_kmalloc_cache(names[INDEX_L3].name,
82198 - sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS);
82199 + sizes[INDEX_L3].cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82200
82201 slab_early_init = 0;
82202
82203 @@ -1686,13 +1693,20 @@ void __init kmem_cache_init(void)
82204 */
82205 if (!sizes->cs_cachep)
82206 sizes->cs_cachep = create_kmalloc_cache(names->name,
82207 - sizes->cs_size, ARCH_KMALLOC_FLAGS);
82208 + sizes->cs_size, ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82209
82210 #ifdef CONFIG_ZONE_DMA
82211 sizes->cs_dmacachep = create_kmalloc_cache(
82212 names->name_dma, sizes->cs_size,
82213 SLAB_CACHE_DMA|ARCH_KMALLOC_FLAGS);
82214 #endif
82215 +
82216 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82217 + sizes->cs_usercopycachep = create_kmalloc_cache(
82218 + names->name_usercopy, sizes->cs_size,
82219 + ARCH_KMALLOC_FLAGS|SLAB_USERCOPY);
82220 +#endif
82221 +
82222 sizes++;
82223 names++;
82224 }
82225 @@ -4365,10 +4379,10 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
82226 }
82227 /* cpu stats */
82228 {
82229 - unsigned long allochit = atomic_read(&cachep->allochit);
82230 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
82231 - unsigned long freehit = atomic_read(&cachep->freehit);
82232 - unsigned long freemiss = atomic_read(&cachep->freemiss);
82233 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
82234 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
82235 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
82236 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
82237
82238 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
82239 allochit, allocmiss, freehit, freemiss);
82240 @@ -4600,13 +4614,71 @@ static const struct file_operations proc_slabstats_operations = {
82241 static int __init slab_proc_init(void)
82242 {
82243 #ifdef CONFIG_DEBUG_SLAB_LEAK
82244 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
82245 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
82246 #endif
82247 return 0;
82248 }
82249 module_init(slab_proc_init);
82250 #endif
82251
82252 +bool is_usercopy_object(const void *ptr)
82253 +{
82254 + struct page *page;
82255 + struct kmem_cache *cachep;
82256 +
82257 + if (ZERO_OR_NULL_PTR(ptr))
82258 + return false;
82259 +
82260 + if (!slab_is_available())
82261 + return false;
82262 +
82263 + if (!virt_addr_valid(ptr))
82264 + return false;
82265 +
82266 + page = virt_to_head_page(ptr);
82267 +
82268 + if (!PageSlab(page))
82269 + return false;
82270 +
82271 + cachep = page->slab_cache;
82272 + return cachep->flags & SLAB_USERCOPY;
82273 +}
82274 +
82275 +#ifdef CONFIG_PAX_USERCOPY
82276 +const char *check_heap_object(const void *ptr, unsigned long n)
82277 +{
82278 + struct page *page;
82279 + struct kmem_cache *cachep;
82280 + struct slab *slabp;
82281 + unsigned int objnr;
82282 + unsigned long offset;
82283 +
82284 + if (ZERO_OR_NULL_PTR(ptr))
82285 + return "<null>";
82286 +
82287 + if (!virt_addr_valid(ptr))
82288 + return NULL;
82289 +
82290 + page = virt_to_head_page(ptr);
82291 +
82292 + if (!PageSlab(page))
82293 + return NULL;
82294 +
82295 + cachep = page->slab_cache;
82296 + if (!(cachep->flags & SLAB_USERCOPY))
82297 + return cachep->name;
82298 +
82299 + slabp = page->slab_page;
82300 + objnr = obj_to_index(cachep, slabp, ptr);
82301 + BUG_ON(objnr >= cachep->num);
82302 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
82303 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
82304 + return NULL;
82305 +
82306 + return cachep->name;
82307 +}
82308 +#endif
82309 +
82310 /**
82311 * ksize - get the actual amount of memory allocated for a given object
82312 * @objp: Pointer to the object
82313 diff --git a/mm/slab.h b/mm/slab.h
82314 index 34a98d6..73633d1 100644
82315 --- a/mm/slab.h
82316 +++ b/mm/slab.h
82317 @@ -58,7 +58,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82318
82319 /* Legal flag mask for kmem_cache_create(), for various configurations */
82320 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
82321 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
82322 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | SLAB_USERCOPY)
82323
82324 #if defined(CONFIG_DEBUG_SLAB)
82325 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
82326 @@ -220,6 +220,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
82327 return s;
82328
82329 page = virt_to_head_page(x);
82330 +
82331 + BUG_ON(!PageSlab(page));
82332 +
82333 cachep = page->slab_cache;
82334 if (slab_equal_or_root(cachep, s))
82335 return cachep;
82336 diff --git a/mm/slab_common.c b/mm/slab_common.c
82337 index 3f3cd97..93b0236 100644
82338 --- a/mm/slab_common.c
82339 +++ b/mm/slab_common.c
82340 @@ -22,7 +22,7 @@
82341
82342 #include "slab.h"
82343
82344 -enum slab_state slab_state;
82345 +enum slab_state slab_state __read_only;
82346 LIST_HEAD(slab_caches);
82347 DEFINE_MUTEX(slab_mutex);
82348 struct kmem_cache *kmem_cache;
82349 @@ -209,7 +209,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
82350
82351 err = __kmem_cache_create(s, flags);
82352 if (!err) {
82353 - s->refcount = 1;
82354 + atomic_set(&s->refcount, 1);
82355 list_add(&s->list, &slab_caches);
82356 memcg_cache_list_add(memcg, s);
82357 } else {
82358 @@ -255,8 +255,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
82359
82360 get_online_cpus();
82361 mutex_lock(&slab_mutex);
82362 - s->refcount--;
82363 - if (!s->refcount) {
82364 + if (atomic_dec_and_test(&s->refcount)) {
82365 list_del(&s->list);
82366
82367 if (!__kmem_cache_shutdown(s)) {
82368 @@ -302,7 +301,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
82369 panic("Creation of kmalloc slab %s size=%zd failed. Reason %d\n",
82370 name, size, err);
82371
82372 - s->refcount = -1; /* Exempt from merging for now */
82373 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
82374 }
82375
82376 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
82377 @@ -315,7 +314,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
82378
82379 create_boot_cache(s, name, size, flags);
82380 list_add(&s->list, &slab_caches);
82381 - s->refcount = 1;
82382 + atomic_set(&s->refcount, 1);
82383 return s;
82384 }
82385
82386 diff --git a/mm/slob.c b/mm/slob.c
82387 index a99fdf7..f5b6577 100644
82388 --- a/mm/slob.c
82389 +++ b/mm/slob.c
82390 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
82391 /*
82392 * Return the size of a slob block.
82393 */
82394 -static slobidx_t slob_units(slob_t *s)
82395 +static slobidx_t slob_units(const slob_t *s)
82396 {
82397 if (s->units > 0)
82398 return s->units;
82399 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
82400 /*
82401 * Return the next free slob block pointer after this one.
82402 */
82403 -static slob_t *slob_next(slob_t *s)
82404 +static slob_t *slob_next(const slob_t *s)
82405 {
82406 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
82407 slobidx_t next;
82408 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
82409 /*
82410 * Returns true if s is the last free block in its page.
82411 */
82412 -static int slob_last(slob_t *s)
82413 +static int slob_last(const slob_t *s)
82414 {
82415 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
82416 }
82417
82418 -static void *slob_new_pages(gfp_t gfp, int order, int node)
82419 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
82420 {
82421 - void *page;
82422 + struct page *page;
82423
82424 #ifdef CONFIG_NUMA
82425 if (node != NUMA_NO_NODE)
82426 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
82427 if (!page)
82428 return NULL;
82429
82430 - return page_address(page);
82431 + __SetPageSlab(page);
82432 + return page;
82433 }
82434
82435 -static void slob_free_pages(void *b, int order)
82436 +static void slob_free_pages(struct page *sp, int order)
82437 {
82438 if (current->reclaim_state)
82439 current->reclaim_state->reclaimed_slab += 1 << order;
82440 - free_pages((unsigned long)b, order);
82441 + __ClearPageSlab(sp);
82442 + reset_page_mapcount(sp);
82443 + sp->private = 0;
82444 + __free_pages(sp, order);
82445 }
82446
82447 /*
82448 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
82449
82450 /* Not enough space: must allocate a new page */
82451 if (!b) {
82452 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
82453 - if (!b)
82454 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
82455 + if (!sp)
82456 return NULL;
82457 - sp = virt_to_page(b);
82458 - __SetPageSlab(sp);
82459 + b = page_address(sp);
82460
82461 spin_lock_irqsave(&slob_lock, flags);
82462 sp->units = SLOB_UNITS(PAGE_SIZE);
82463 sp->freelist = b;
82464 + sp->private = 0;
82465 INIT_LIST_HEAD(&sp->list);
82466 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
82467 set_slob_page_free(sp, slob_list);
82468 @@ -359,9 +363,7 @@ static void slob_free(void *block, int size)
82469 if (slob_page_free(sp))
82470 clear_slob_page_free(sp);
82471 spin_unlock_irqrestore(&slob_lock, flags);
82472 - __ClearPageSlab(sp);
82473 - reset_page_mapcount(sp);
82474 - slob_free_pages(b, 0);
82475 + slob_free_pages(sp, 0);
82476 return;
82477 }
82478
82479 @@ -424,11 +426,10 @@ out:
82480 */
82481
82482 static __always_inline void *
82483 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82484 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
82485 {
82486 - unsigned int *m;
82487 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82488 - void *ret;
82489 + slob_t *m;
82490 + void *ret = NULL;
82491
82492 gfp &= gfp_allowed_mask;
82493
82494 @@ -442,23 +443,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82495
82496 if (!m)
82497 return NULL;
82498 - *m = size;
82499 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
82500 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
82501 + m[0].units = size;
82502 + m[1].units = align;
82503 ret = (void *)m + align;
82504
82505 trace_kmalloc_node(caller, ret,
82506 size, size + align, gfp, node);
82507 } else {
82508 unsigned int order = get_order(size);
82509 + struct page *page;
82510
82511 if (likely(order))
82512 gfp |= __GFP_COMP;
82513 - ret = slob_new_pages(gfp, order, node);
82514 + page = slob_new_pages(gfp, order, node);
82515 + if (page) {
82516 + ret = page_address(page);
82517 + page->private = size;
82518 + }
82519
82520 trace_kmalloc_node(caller, ret,
82521 size, PAGE_SIZE << order, gfp, node);
82522 }
82523
82524 - kmemleak_alloc(ret, size, 1, gfp);
82525 + return ret;
82526 +}
82527 +
82528 +static __always_inline void *
82529 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
82530 +{
82531 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82532 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
82533 +
82534 + if (!ZERO_OR_NULL_PTR(ret))
82535 + kmemleak_alloc(ret, size, 1, gfp);
82536 return ret;
82537 }
82538
82539 @@ -494,33 +513,110 @@ void kfree(const void *block)
82540 kmemleak_free(block);
82541
82542 sp = virt_to_page(block);
82543 - if (PageSlab(sp)) {
82544 + VM_BUG_ON(!PageSlab(sp));
82545 + if (!sp->private) {
82546 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82547 - unsigned int *m = (unsigned int *)(block - align);
82548 - slob_free(m, *m + align);
82549 - } else
82550 + slob_t *m = (slob_t *)(block - align);
82551 + slob_free(m, m[0].units + align);
82552 + } else {
82553 + __ClearPageSlab(sp);
82554 + reset_page_mapcount(sp);
82555 + sp->private = 0;
82556 __free_pages(sp, compound_order(sp));
82557 + }
82558 }
82559 EXPORT_SYMBOL(kfree);
82560
82561 +bool is_usercopy_object(const void *ptr)
82562 +{
82563 + if (!slab_is_available())
82564 + return false;
82565 +
82566 + // PAX: TODO
82567 +
82568 + return false;
82569 +}
82570 +
82571 +#ifdef CONFIG_PAX_USERCOPY
82572 +const char *check_heap_object(const void *ptr, unsigned long n)
82573 +{
82574 + struct page *page;
82575 + const slob_t *free;
82576 + const void *base;
82577 + unsigned long flags;
82578 +
82579 + if (ZERO_OR_NULL_PTR(ptr))
82580 + return "<null>";
82581 +
82582 + if (!virt_addr_valid(ptr))
82583 + return NULL;
82584 +
82585 + page = virt_to_head_page(ptr);
82586 + if (!PageSlab(page))
82587 + return NULL;
82588 +
82589 + if (page->private) {
82590 + base = page;
82591 + if (base <= ptr && n <= page->private - (ptr - base))
82592 + return NULL;
82593 + return "<slob>";
82594 + }
82595 +
82596 + /* some tricky double walking to find the chunk */
82597 + spin_lock_irqsave(&slob_lock, flags);
82598 + base = (void *)((unsigned long)ptr & PAGE_MASK);
82599 + free = page->freelist;
82600 +
82601 + while (!slob_last(free) && (void *)free <= ptr) {
82602 + base = free + slob_units(free);
82603 + free = slob_next(free);
82604 + }
82605 +
82606 + while (base < (void *)free) {
82607 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
82608 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
82609 + int offset;
82610 +
82611 + if (ptr < base + align)
82612 + break;
82613 +
82614 + offset = ptr - base - align;
82615 + if (offset >= m) {
82616 + base += size;
82617 + continue;
82618 + }
82619 +
82620 + if (n > m - offset)
82621 + break;
82622 +
82623 + spin_unlock_irqrestore(&slob_lock, flags);
82624 + return NULL;
82625 + }
82626 +
82627 + spin_unlock_irqrestore(&slob_lock, flags);
82628 + return "<slob>";
82629 +}
82630 +#endif
82631 +
82632 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
82633 size_t ksize(const void *block)
82634 {
82635 struct page *sp;
82636 int align;
82637 - unsigned int *m;
82638 + slob_t *m;
82639
82640 BUG_ON(!block);
82641 if (unlikely(block == ZERO_SIZE_PTR))
82642 return 0;
82643
82644 sp = virt_to_page(block);
82645 - if (unlikely(!PageSlab(sp)))
82646 - return PAGE_SIZE << compound_order(sp);
82647 + VM_BUG_ON(!PageSlab(sp));
82648 + if (sp->private)
82649 + return sp->private;
82650
82651 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
82652 - m = (unsigned int *)(block - align);
82653 - return SLOB_UNITS(*m) * SLOB_UNIT;
82654 + m = (slob_t *)(block - align);
82655 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
82656 }
82657 EXPORT_SYMBOL(ksize);
82658
82659 @@ -536,23 +632,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
82660
82661 void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
82662 {
82663 - void *b;
82664 + void *b = NULL;
82665
82666 flags &= gfp_allowed_mask;
82667
82668 lockdep_trace_alloc(flags);
82669
82670 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82671 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
82672 +#else
82673 if (c->size < PAGE_SIZE) {
82674 b = slob_alloc(c->size, flags, c->align, node);
82675 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
82676 SLOB_UNITS(c->size) * SLOB_UNIT,
82677 flags, node);
82678 } else {
82679 - b = slob_new_pages(flags, get_order(c->size), node);
82680 + struct page *sp;
82681 +
82682 + sp = slob_new_pages(flags, get_order(c->size), node);
82683 + if (sp) {
82684 + b = page_address(sp);
82685 + sp->private = c->size;
82686 + }
82687 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
82688 PAGE_SIZE << get_order(c->size),
82689 flags, node);
82690 }
82691 +#endif
82692
82693 if (c->ctor)
82694 c->ctor(b);
82695 @@ -564,10 +670,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
82696
82697 static void __kmem_cache_free(void *b, int size)
82698 {
82699 - if (size < PAGE_SIZE)
82700 + struct page *sp;
82701 +
82702 + sp = virt_to_page(b);
82703 + BUG_ON(!PageSlab(sp));
82704 + if (!sp->private)
82705 slob_free(b, size);
82706 else
82707 - slob_free_pages(b, get_order(size));
82708 + slob_free_pages(sp, get_order(size));
82709 }
82710
82711 static void kmem_rcu_free(struct rcu_head *head)
82712 @@ -580,17 +690,31 @@ static void kmem_rcu_free(struct rcu_head *head)
82713
82714 void kmem_cache_free(struct kmem_cache *c, void *b)
82715 {
82716 + int size = c->size;
82717 +
82718 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82719 + if (size + c->align < PAGE_SIZE) {
82720 + size += c->align;
82721 + b -= c->align;
82722 + }
82723 +#endif
82724 +
82725 kmemleak_free_recursive(b, c->flags);
82726 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
82727 struct slob_rcu *slob_rcu;
82728 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
82729 - slob_rcu->size = c->size;
82730 + slob_rcu = b + (size - sizeof(struct slob_rcu));
82731 + slob_rcu->size = size;
82732 call_rcu(&slob_rcu->head, kmem_rcu_free);
82733 } else {
82734 - __kmem_cache_free(b, c->size);
82735 + __kmem_cache_free(b, size);
82736 }
82737
82738 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82739 + trace_kfree(_RET_IP_, b);
82740 +#else
82741 trace_kmem_cache_free(_RET_IP_, b);
82742 +#endif
82743 +
82744 }
82745 EXPORT_SYMBOL(kmem_cache_free);
82746
82747 diff --git a/mm/slub.c b/mm/slub.c
82748 index ba2ca53..00b1f4e 100644
82749 --- a/mm/slub.c
82750 +++ b/mm/slub.c
82751 @@ -197,7 +197,7 @@ struct track {
82752
82753 enum track_item { TRACK_ALLOC, TRACK_FREE };
82754
82755 -#ifdef CONFIG_SYSFS
82756 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82757 static int sysfs_slab_add(struct kmem_cache *);
82758 static int sysfs_slab_alias(struct kmem_cache *, const char *);
82759 static void sysfs_slab_remove(struct kmem_cache *);
82760 @@ -518,7 +518,7 @@ static void print_track(const char *s, struct track *t)
82761 if (!t->addr)
82762 return;
82763
82764 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
82765 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
82766 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
82767 #ifdef CONFIG_STACKTRACE
82768 {
82769 @@ -2653,7 +2653,7 @@ static int slub_min_objects;
82770 * Merge control. If this is set then no merging of slab caches will occur.
82771 * (Could be removed. This was introduced to pacify the merge skeptics.)
82772 */
82773 -static int slub_nomerge;
82774 +static int slub_nomerge = 1;
82775
82776 /*
82777 * Calculate the order of allocation given an slab object size.
82778 @@ -3181,6 +3181,10 @@ EXPORT_SYMBOL(kmalloc_caches);
82779 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
82780 #endif
82781
82782 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82783 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
82784 +#endif
82785 +
82786 static int __init setup_slub_min_order(char *str)
82787 {
82788 get_option(&str, &slub_min_order);
82789 @@ -3272,6 +3276,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
82790 return kmalloc_dma_caches[index];
82791
82792 #endif
82793 +
82794 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82795 + if (flags & SLAB_USERCOPY)
82796 + return kmalloc_usercopy_caches[index];
82797 +
82798 +#endif
82799 +
82800 return kmalloc_caches[index];
82801 }
82802
82803 @@ -3340,6 +3351,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
82804 EXPORT_SYMBOL(__kmalloc_node);
82805 #endif
82806
82807 +bool is_usercopy_object(const void *ptr)
82808 +{
82809 + struct page *page;
82810 + struct kmem_cache *s;
82811 +
82812 + if (ZERO_OR_NULL_PTR(ptr))
82813 + return false;
82814 +
82815 + if (!slab_is_available())
82816 + return false;
82817 +
82818 + if (!virt_addr_valid(ptr))
82819 + return false;
82820 +
82821 + page = virt_to_head_page(ptr);
82822 +
82823 + if (!PageSlab(page))
82824 + return false;
82825 +
82826 + s = page->slab_cache;
82827 + return s->flags & SLAB_USERCOPY;
82828 +}
82829 +
82830 +#ifdef CONFIG_PAX_USERCOPY
82831 +const char *check_heap_object(const void *ptr, unsigned long n)
82832 +{
82833 + struct page *page;
82834 + struct kmem_cache *s;
82835 + unsigned long offset;
82836 +
82837 + if (ZERO_OR_NULL_PTR(ptr))
82838 + return "<null>";
82839 +
82840 + if (!virt_addr_valid(ptr))
82841 + return NULL;
82842 +
82843 + page = virt_to_head_page(ptr);
82844 +
82845 + if (!PageSlab(page))
82846 + return NULL;
82847 +
82848 + s = page->slab_cache;
82849 + if (!(s->flags & SLAB_USERCOPY))
82850 + return s->name;
82851 +
82852 + offset = (ptr - page_address(page)) % s->size;
82853 + if (offset <= s->object_size && n <= s->object_size - offset)
82854 + return NULL;
82855 +
82856 + return s->name;
82857 +}
82858 +#endif
82859 +
82860 size_t ksize(const void *object)
82861 {
82862 struct page *page;
82863 @@ -3712,17 +3776,17 @@ void __init kmem_cache_init(void)
82864
82865 /* Caches that are not of the two-to-the-power-of size */
82866 if (KMALLOC_MIN_SIZE <= 32) {
82867 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
82868 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
82869 caches++;
82870 }
82871
82872 if (KMALLOC_MIN_SIZE <= 64) {
82873 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
82874 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
82875 caches++;
82876 }
82877
82878 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
82879 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
82880 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
82881 caches++;
82882 }
82883
82884 @@ -3764,6 +3828,22 @@ void __init kmem_cache_init(void)
82885 }
82886 }
82887 #endif
82888 +
82889 +#ifdef CONFIG_PAX_USERCOPY_SLABS
82890 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
82891 + struct kmem_cache *s = kmalloc_caches[i];
82892 +
82893 + if (s && s->size) {
82894 + char *name = kasprintf(GFP_NOWAIT,
82895 + "usercopy-kmalloc-%d", s->object_size);
82896 +
82897 + BUG_ON(!name);
82898 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
82899 + s->object_size, SLAB_USERCOPY);
82900 + }
82901 + }
82902 +#endif
82903 +
82904 printk(KERN_INFO
82905 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
82906 " CPUs=%d, Nodes=%d\n",
82907 @@ -3790,7 +3870,7 @@ static int slab_unmergeable(struct kmem_cache *s)
82908 /*
82909 * We may have set a slab to be unmergeable during bootstrap.
82910 */
82911 - if (s->refcount < 0)
82912 + if (atomic_read(&s->refcount) < 0)
82913 return 1;
82914
82915 return 0;
82916 @@ -3848,7 +3928,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82917
82918 s = find_mergeable(memcg, size, align, flags, name, ctor);
82919 if (s) {
82920 - s->refcount++;
82921 + atomic_inc(&s->refcount);
82922 /*
82923 * Adjust the object sizes so that we clear
82924 * the complete object on kzalloc.
82925 @@ -3857,7 +3937,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
82926 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
82927
82928 if (sysfs_slab_alias(s, name)) {
82929 - s->refcount--;
82930 + atomic_dec(&s->refcount);
82931 s = NULL;
82932 }
82933 }
82934 @@ -3919,7 +3999,7 @@ static int __cpuinit slab_cpuup_callback(struct notifier_block *nfb,
82935 return NOTIFY_OK;
82936 }
82937
82938 -static struct notifier_block __cpuinitdata slab_notifier = {
82939 +static struct notifier_block slab_notifier = {
82940 .notifier_call = slab_cpuup_callback
82941 };
82942
82943 @@ -3977,7 +4057,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
82944 }
82945 #endif
82946
82947 -#ifdef CONFIG_SYSFS
82948 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82949 static int count_inuse(struct page *page)
82950 {
82951 return page->inuse;
82952 @@ -4364,12 +4444,12 @@ static void resiliency_test(void)
82953 validate_slab_cache(kmalloc_caches[9]);
82954 }
82955 #else
82956 -#ifdef CONFIG_SYSFS
82957 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82958 static void resiliency_test(void) {};
82959 #endif
82960 #endif
82961
82962 -#ifdef CONFIG_SYSFS
82963 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82964 enum slab_stat_type {
82965 SL_ALL, /* All slabs */
82966 SL_PARTIAL, /* Only partially allocated slabs */
82967 @@ -4613,7 +4693,7 @@ SLAB_ATTR_RO(ctor);
82968
82969 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
82970 {
82971 - return sprintf(buf, "%d\n", s->refcount - 1);
82972 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
82973 }
82974 SLAB_ATTR_RO(aliases);
82975
82976 @@ -5266,6 +5346,7 @@ static char *create_unique_id(struct kmem_cache *s)
82977 return name;
82978 }
82979
82980 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82981 static int sysfs_slab_add(struct kmem_cache *s)
82982 {
82983 int err;
82984 @@ -5323,6 +5404,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
82985 kobject_del(&s->kobj);
82986 kobject_put(&s->kobj);
82987 }
82988 +#endif
82989
82990 /*
82991 * Need to buffer aliases during bootup until sysfs becomes
82992 @@ -5336,6 +5418,7 @@ struct saved_alias {
82993
82994 static struct saved_alias *alias_list;
82995
82996 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
82997 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
82998 {
82999 struct saved_alias *al;
83000 @@ -5358,6 +5441,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
83001 alias_list = al;
83002 return 0;
83003 }
83004 +#endif
83005
83006 static int __init slab_sysfs_init(void)
83007 {
83008 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
83009 index 1b7e22a..3fcd4f3 100644
83010 --- a/mm/sparse-vmemmap.c
83011 +++ b/mm/sparse-vmemmap.c
83012 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
83013 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83014 if (!p)
83015 return NULL;
83016 - pud_populate(&init_mm, pud, p);
83017 + pud_populate_kernel(&init_mm, pud, p);
83018 }
83019 return pud;
83020 }
83021 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
83022 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
83023 if (!p)
83024 return NULL;
83025 - pgd_populate(&init_mm, pgd, p);
83026 + pgd_populate_kernel(&init_mm, pgd, p);
83027 }
83028 return pgd;
83029 }
83030 diff --git a/mm/sparse.c b/mm/sparse.c
83031 index 6b5fb76..db0c190 100644
83032 --- a/mm/sparse.c
83033 +++ b/mm/sparse.c
83034 @@ -782,7 +782,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
83035
83036 for (i = 0; i < PAGES_PER_SECTION; i++) {
83037 if (PageHWPoison(&memmap[i])) {
83038 - atomic_long_sub(1, &mce_bad_pages);
83039 + atomic_long_sub_unchecked(1, &mce_bad_pages);
83040 ClearPageHWPoison(&memmap[i]);
83041 }
83042 }
83043 diff --git a/mm/swap.c b/mm/swap.c
83044 index 6310dc2..3662b3f 100644
83045 --- a/mm/swap.c
83046 +++ b/mm/swap.c
83047 @@ -30,6 +30,7 @@
83048 #include <linux/backing-dev.h>
83049 #include <linux/memcontrol.h>
83050 #include <linux/gfp.h>
83051 +#include <linux/hugetlb.h>
83052
83053 #include "internal.h"
83054
83055 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
83056
83057 __page_cache_release(page);
83058 dtor = get_compound_page_dtor(page);
83059 + if (!PageHuge(page))
83060 + BUG_ON(dtor != free_compound_page);
83061 (*dtor)(page);
83062 }
83063
83064 diff --git a/mm/swapfile.c b/mm/swapfile.c
83065 index e97a0e5..b50e796 100644
83066 --- a/mm/swapfile.c
83067 +++ b/mm/swapfile.c
83068 @@ -64,7 +64,7 @@ static DEFINE_MUTEX(swapon_mutex);
83069
83070 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
83071 /* Activity counter to indicate that a swapon or swapoff has occurred */
83072 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
83073 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
83074
83075 static inline unsigned char swap_count(unsigned char ent)
83076 {
83077 @@ -1608,7 +1608,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
83078 }
83079 filp_close(swap_file, NULL);
83080 err = 0;
83081 - atomic_inc(&proc_poll_event);
83082 + atomic_inc_unchecked(&proc_poll_event);
83083 wake_up_interruptible(&proc_poll_wait);
83084
83085 out_dput:
83086 @@ -1625,8 +1625,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
83087
83088 poll_wait(file, &proc_poll_wait, wait);
83089
83090 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
83091 - seq->poll_event = atomic_read(&proc_poll_event);
83092 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
83093 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83094 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
83095 }
83096
83097 @@ -1724,7 +1724,7 @@ static int swaps_open(struct inode *inode, struct file *file)
83098 return ret;
83099
83100 seq = file->private_data;
83101 - seq->poll_event = atomic_read(&proc_poll_event);
83102 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
83103 return 0;
83104 }
83105
83106 @@ -2066,7 +2066,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
83107 (frontswap_map) ? "FS" : "");
83108
83109 mutex_unlock(&swapon_mutex);
83110 - atomic_inc(&proc_poll_event);
83111 + atomic_inc_unchecked(&proc_poll_event);
83112 wake_up_interruptible(&proc_poll_wait);
83113
83114 if (S_ISREG(inode->i_mode))
83115 diff --git a/mm/util.c b/mm/util.c
83116 index c55e26b..3f913a9 100644
83117 --- a/mm/util.c
83118 +++ b/mm/util.c
83119 @@ -292,6 +292,12 @@ done:
83120 void arch_pick_mmap_layout(struct mm_struct *mm)
83121 {
83122 mm->mmap_base = TASK_UNMAPPED_BASE;
83123 +
83124 +#ifdef CONFIG_PAX_RANDMMAP
83125 + if (mm->pax_flags & MF_PAX_RANDMMAP)
83126 + mm->mmap_base += mm->delta_mmap;
83127 +#endif
83128 +
83129 mm->get_unmapped_area = arch_get_unmapped_area;
83130 mm->unmap_area = arch_unmap_area;
83131 }
83132 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
83133 index 5123a16..f234a48 100644
83134 --- a/mm/vmalloc.c
83135 +++ b/mm/vmalloc.c
83136 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
83137
83138 pte = pte_offset_kernel(pmd, addr);
83139 do {
83140 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83141 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83142 +
83143 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83144 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
83145 + BUG_ON(!pte_exec(*pte));
83146 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
83147 + continue;
83148 + }
83149 +#endif
83150 +
83151 + {
83152 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
83153 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
83154 + }
83155 } while (pte++, addr += PAGE_SIZE, addr != end);
83156 }
83157
83158 @@ -100,16 +111,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
83159 pte = pte_alloc_kernel(pmd, addr);
83160 if (!pte)
83161 return -ENOMEM;
83162 +
83163 + pax_open_kernel();
83164 do {
83165 struct page *page = pages[*nr];
83166
83167 - if (WARN_ON(!pte_none(*pte)))
83168 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83169 + if (pgprot_val(prot) & _PAGE_NX)
83170 +#endif
83171 +
83172 + if (!pte_none(*pte)) {
83173 + pax_close_kernel();
83174 + WARN_ON(1);
83175 return -EBUSY;
83176 - if (WARN_ON(!page))
83177 + }
83178 + if (!page) {
83179 + pax_close_kernel();
83180 + WARN_ON(1);
83181 return -ENOMEM;
83182 + }
83183 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
83184 (*nr)++;
83185 } while (pte++, addr += PAGE_SIZE, addr != end);
83186 + pax_close_kernel();
83187 return 0;
83188 }
83189
83190 @@ -119,7 +143,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
83191 pmd_t *pmd;
83192 unsigned long next;
83193
83194 - pmd = pmd_alloc(&init_mm, pud, addr);
83195 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
83196 if (!pmd)
83197 return -ENOMEM;
83198 do {
83199 @@ -136,7 +160,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
83200 pud_t *pud;
83201 unsigned long next;
83202
83203 - pud = pud_alloc(&init_mm, pgd, addr);
83204 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
83205 if (!pud)
83206 return -ENOMEM;
83207 do {
83208 @@ -191,11 +215,20 @@ int is_vmalloc_or_module_addr(const void *x)
83209 * and fall back on vmalloc() if that fails. Others
83210 * just put it in the vmalloc space.
83211 */
83212 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
83213 +#ifdef CONFIG_MODULES
83214 +#ifdef MODULES_VADDR
83215 unsigned long addr = (unsigned long)x;
83216 if (addr >= MODULES_VADDR && addr < MODULES_END)
83217 return 1;
83218 #endif
83219 +
83220 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
83221 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
83222 + return 1;
83223 +#endif
83224 +
83225 +#endif
83226 +
83227 return is_vmalloc_addr(x);
83228 }
83229
83230 @@ -216,8 +249,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
83231
83232 if (!pgd_none(*pgd)) {
83233 pud_t *pud = pud_offset(pgd, addr);
83234 +#ifdef CONFIG_X86
83235 + if (!pud_large(*pud))
83236 +#endif
83237 if (!pud_none(*pud)) {
83238 pmd_t *pmd = pmd_offset(pud, addr);
83239 +#ifdef CONFIG_X86
83240 + if (!pmd_large(*pmd))
83241 +#endif
83242 if (!pmd_none(*pmd)) {
83243 pte_t *ptep, pte;
83244
83245 @@ -329,7 +368,7 @@ static void purge_vmap_area_lazy(void);
83246 * Allocate a region of KVA of the specified size and alignment, within the
83247 * vstart and vend.
83248 */
83249 -static struct vmap_area *alloc_vmap_area(unsigned long size,
83250 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
83251 unsigned long align,
83252 unsigned long vstart, unsigned long vend,
83253 int node, gfp_t gfp_mask)
83254 @@ -1328,6 +1367,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
83255 struct vm_struct *area;
83256
83257 BUG_ON(in_interrupt());
83258 +
83259 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83260 + if (flags & VM_KERNEXEC) {
83261 + if (start != VMALLOC_START || end != VMALLOC_END)
83262 + return NULL;
83263 + start = (unsigned long)MODULES_EXEC_VADDR;
83264 + end = (unsigned long)MODULES_EXEC_END;
83265 + }
83266 +#endif
83267 +
83268 if (flags & VM_IOREMAP) {
83269 int bit = fls(size);
83270
83271 @@ -1568,6 +1617,11 @@ void *vmap(struct page **pages, unsigned int count,
83272 if (count > totalram_pages)
83273 return NULL;
83274
83275 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83276 + if (!(pgprot_val(prot) & _PAGE_NX))
83277 + flags |= VM_KERNEXEC;
83278 +#endif
83279 +
83280 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
83281 __builtin_return_address(0));
83282 if (!area)
83283 @@ -1669,6 +1723,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
83284 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
83285 goto fail;
83286
83287 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
83288 + if (!(pgprot_val(prot) & _PAGE_NX))
83289 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
83290 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
83291 + else
83292 +#endif
83293 +
83294 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
83295 start, end, node, gfp_mask, caller);
83296 if (!area)
83297 @@ -1842,10 +1903,9 @@ EXPORT_SYMBOL(vzalloc_node);
83298 * For tight control over page level allocator and protection flags
83299 * use __vmalloc() instead.
83300 */
83301 -
83302 void *vmalloc_exec(unsigned long size)
83303 {
83304 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
83305 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
83306 -1, __builtin_return_address(0));
83307 }
83308
83309 @@ -2136,6 +2196,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
83310 unsigned long uaddr = vma->vm_start;
83311 unsigned long usize = vma->vm_end - vma->vm_start;
83312
83313 + BUG_ON(vma->vm_mirror);
83314 +
83315 if ((PAGE_SIZE-1) & (unsigned long)addr)
83316 return -EINVAL;
83317
83318 @@ -2575,7 +2637,11 @@ static int s_show(struct seq_file *m, void *p)
83319 v->addr, v->addr + v->size, v->size);
83320
83321 if (v->caller)
83322 +#ifdef CONFIG_GRKERNSEC_HIDESYM
83323 + seq_printf(m, " %pK", v->caller);
83324 +#else
83325 seq_printf(m, " %pS", v->caller);
83326 +#endif
83327
83328 if (v->nr_pages)
83329 seq_printf(m, " pages=%d", v->nr_pages);
83330 diff --git a/mm/vmstat.c b/mm/vmstat.c
83331 index 9800306..76b4b27 100644
83332 --- a/mm/vmstat.c
83333 +++ b/mm/vmstat.c
83334 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
83335 *
83336 * vm_stat contains the global counters
83337 */
83338 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
83339 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
83340 EXPORT_SYMBOL(vm_stat);
83341
83342 #ifdef CONFIG_SMP
83343 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
83344 v = p->vm_stat_diff[i];
83345 p->vm_stat_diff[i] = 0;
83346 local_irq_restore(flags);
83347 - atomic_long_add(v, &zone->vm_stat[i]);
83348 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
83349 global_diff[i] += v;
83350 #ifdef CONFIG_NUMA
83351 /* 3 seconds idle till flush */
83352 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
83353
83354 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
83355 if (global_diff[i])
83356 - atomic_long_add(global_diff[i], &vm_stat[i]);
83357 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
83358 }
83359
83360 void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
83361 @@ -503,8 +503,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
83362 if (pset->vm_stat_diff[i]) {
83363 int v = pset->vm_stat_diff[i];
83364 pset->vm_stat_diff[i] = 0;
83365 - atomic_long_add(v, &zone->vm_stat[i]);
83366 - atomic_long_add(v, &vm_stat[i]);
83367 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
83368 + atomic_long_add_unchecked(v, &vm_stat[i]);
83369 }
83370 }
83371 #endif
83372 @@ -1223,7 +1223,7 @@ static int __cpuinit vmstat_cpuup_callback(struct notifier_block *nfb,
83373 return NOTIFY_OK;
83374 }
83375
83376 -static struct notifier_block __cpuinitdata vmstat_notifier =
83377 +static struct notifier_block vmstat_notifier =
83378 { &vmstat_cpuup_callback, NULL, 0 };
83379 #endif
83380
83381 @@ -1238,10 +1238,20 @@ static int __init setup_vmstat(void)
83382 start_cpu_timer(cpu);
83383 #endif
83384 #ifdef CONFIG_PROC_FS
83385 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
83386 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
83387 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
83388 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
83389 + {
83390 + mode_t gr_mode = S_IRUGO;
83391 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
83392 + gr_mode = S_IRUSR;
83393 +#endif
83394 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
83395 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
83396 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83397 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
83398 +#else
83399 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
83400 +#endif
83401 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
83402 + }
83403 #endif
83404 return 0;
83405 }
83406 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
83407 index a292e80..785ee68 100644
83408 --- a/net/8021q/vlan.c
83409 +++ b/net/8021q/vlan.c
83410 @@ -485,7 +485,7 @@ out:
83411 return NOTIFY_DONE;
83412 }
83413
83414 -static struct notifier_block vlan_notifier_block __read_mostly = {
83415 +static struct notifier_block vlan_notifier_block = {
83416 .notifier_call = vlan_device_event,
83417 };
83418
83419 @@ -560,8 +560,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
83420 err = -EPERM;
83421 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
83422 break;
83423 - if ((args.u.name_type >= 0) &&
83424 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
83425 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
83426 struct vlan_net *vn;
83427
83428 vn = net_generic(net, vlan_net_id);
83429 diff --git a/net/9p/mod.c b/net/9p/mod.c
83430 index 6ab36ae..6f1841b 100644
83431 --- a/net/9p/mod.c
83432 +++ b/net/9p/mod.c
83433 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
83434 void v9fs_register_trans(struct p9_trans_module *m)
83435 {
83436 spin_lock(&v9fs_trans_lock);
83437 - list_add_tail(&m->list, &v9fs_trans_list);
83438 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
83439 spin_unlock(&v9fs_trans_lock);
83440 }
83441 EXPORT_SYMBOL(v9fs_register_trans);
83442 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
83443 void v9fs_unregister_trans(struct p9_trans_module *m)
83444 {
83445 spin_lock(&v9fs_trans_lock);
83446 - list_del_init(&m->list);
83447 + pax_list_del_init((struct list_head *)&m->list);
83448 spin_unlock(&v9fs_trans_lock);
83449 }
83450 EXPORT_SYMBOL(v9fs_unregister_trans);
83451 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
83452 index 02efb25..41541a9 100644
83453 --- a/net/9p/trans_fd.c
83454 +++ b/net/9p/trans_fd.c
83455 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
83456 oldfs = get_fs();
83457 set_fs(get_ds());
83458 /* The cast to a user pointer is valid due to the set_fs() */
83459 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
83460 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
83461 set_fs(oldfs);
83462
83463 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
83464 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
83465 index 876fbe8..8bbea9f 100644
83466 --- a/net/atm/atm_misc.c
83467 +++ b/net/atm/atm_misc.c
83468 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
83469 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
83470 return 1;
83471 atm_return(vcc, truesize);
83472 - atomic_inc(&vcc->stats->rx_drop);
83473 + atomic_inc_unchecked(&vcc->stats->rx_drop);
83474 return 0;
83475 }
83476 EXPORT_SYMBOL(atm_charge);
83477 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
83478 }
83479 }
83480 atm_return(vcc, guess);
83481 - atomic_inc(&vcc->stats->rx_drop);
83482 + atomic_inc_unchecked(&vcc->stats->rx_drop);
83483 return NULL;
83484 }
83485 EXPORT_SYMBOL(atm_alloc_charge);
83486 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
83487
83488 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
83489 {
83490 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
83491 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
83492 __SONET_ITEMS
83493 #undef __HANDLE_ITEM
83494 }
83495 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
83496
83497 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
83498 {
83499 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
83500 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
83501 __SONET_ITEMS
83502 #undef __HANDLE_ITEM
83503 }
83504 diff --git a/net/atm/lec.h b/net/atm/lec.h
83505 index a86aff9..3a0d6f6 100644
83506 --- a/net/atm/lec.h
83507 +++ b/net/atm/lec.h
83508 @@ -48,7 +48,7 @@ struct lane2_ops {
83509 const u8 *tlvs, u32 sizeoftlvs);
83510 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
83511 const u8 *tlvs, u32 sizeoftlvs);
83512 -};
83513 +} __no_const;
83514
83515 /*
83516 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
83517 diff --git a/net/atm/proc.c b/net/atm/proc.c
83518 index 0d020de..011c7bb 100644
83519 --- a/net/atm/proc.c
83520 +++ b/net/atm/proc.c
83521 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
83522 const struct k_atm_aal_stats *stats)
83523 {
83524 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
83525 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
83526 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
83527 - atomic_read(&stats->rx_drop));
83528 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
83529 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
83530 + atomic_read_unchecked(&stats->rx_drop));
83531 }
83532
83533 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
83534 diff --git a/net/atm/resources.c b/net/atm/resources.c
83535 index 0447d5d..3cf4728 100644
83536 --- a/net/atm/resources.c
83537 +++ b/net/atm/resources.c
83538 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
83539 static void copy_aal_stats(struct k_atm_aal_stats *from,
83540 struct atm_aal_stats *to)
83541 {
83542 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
83543 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
83544 __AAL_STAT_ITEMS
83545 #undef __HANDLE_ITEM
83546 }
83547 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
83548 static void subtract_aal_stats(struct k_atm_aal_stats *from,
83549 struct atm_aal_stats *to)
83550 {
83551 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
83552 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
83553 __AAL_STAT_ITEMS
83554 #undef __HANDLE_ITEM
83555 }
83556 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
83557 index d5744b7..506bae3 100644
83558 --- a/net/ax25/sysctl_net_ax25.c
83559 +++ b/net/ax25/sysctl_net_ax25.c
83560 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
83561 {
83562 char path[sizeof("net/ax25/") + IFNAMSIZ];
83563 int k;
83564 - struct ctl_table *table;
83565 + ctl_table_no_const *table;
83566
83567 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
83568 if (!table)
83569 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
83570 index 7d02ebd..4d4cc01 100644
83571 --- a/net/batman-adv/bat_iv_ogm.c
83572 +++ b/net/batman-adv/bat_iv_ogm.c
83573 @@ -63,7 +63,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
83574
83575 /* randomize initial seqno to avoid collision */
83576 get_random_bytes(&random_seqno, sizeof(random_seqno));
83577 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
83578 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
83579
83580 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
83581 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
83582 @@ -615,9 +615,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
83583 batadv_ogm_packet = (struct batadv_ogm_packet *)(*ogm_buff);
83584
83585 /* change sequence number to network order */
83586 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
83587 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
83588 batadv_ogm_packet->seqno = htonl(seqno);
83589 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
83590 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
83591
83592 batadv_ogm_packet->ttvn = atomic_read(&bat_priv->tt.vn);
83593 batadv_ogm_packet->tt_crc = htons(bat_priv->tt.local_crc);
83594 @@ -1022,7 +1022,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
83595 return;
83596
83597 /* could be changed by schedule_own_packet() */
83598 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
83599 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
83600
83601 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
83602 has_directlink_flag = 1;
83603 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
83604 index f1d37cd..4190879 100644
83605 --- a/net/batman-adv/hard-interface.c
83606 +++ b/net/batman-adv/hard-interface.c
83607 @@ -370,7 +370,7 @@ int batadv_hardif_enable_interface(struct batadv_hard_iface *hard_iface,
83608 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
83609 dev_add_pack(&hard_iface->batman_adv_ptype);
83610
83611 - atomic_set(&hard_iface->frag_seqno, 1);
83612 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
83613 batadv_info(hard_iface->soft_iface, "Adding interface: %s\n",
83614 hard_iface->net_dev->name);
83615
83616 @@ -493,7 +493,7 @@ batadv_hardif_add_interface(struct net_device *net_dev)
83617 /* This can't be called via a bat_priv callback because
83618 * we have no bat_priv yet.
83619 */
83620 - atomic_set(&hard_iface->bat_iv.ogm_seqno, 1);
83621 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, 1);
83622 hard_iface->bat_iv.ogm_buff = NULL;
83623
83624 return hard_iface;
83625 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
83626 index 6b548fd..fc32c8d 100644
83627 --- a/net/batman-adv/soft-interface.c
83628 +++ b/net/batman-adv/soft-interface.c
83629 @@ -252,7 +252,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
83630 primary_if->net_dev->dev_addr, ETH_ALEN);
83631
83632 /* set broadcast sequence number */
83633 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
83634 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
83635 bcast_packet->seqno = htonl(seqno);
83636
83637 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
83638 @@ -497,7 +497,7 @@ struct net_device *batadv_softif_create(const char *name)
83639 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
83640
83641 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
83642 - atomic_set(&bat_priv->bcast_seqno, 1);
83643 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
83644 atomic_set(&bat_priv->tt.vn, 0);
83645 atomic_set(&bat_priv->tt.local_changes, 0);
83646 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
83647 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
83648 index ae9ac9a..11e0fe7 100644
83649 --- a/net/batman-adv/types.h
83650 +++ b/net/batman-adv/types.h
83651 @@ -48,7 +48,7 @@
83652 struct batadv_hard_iface_bat_iv {
83653 unsigned char *ogm_buff;
83654 int ogm_buff_len;
83655 - atomic_t ogm_seqno;
83656 + atomic_unchecked_t ogm_seqno;
83657 };
83658
83659 struct batadv_hard_iface {
83660 @@ -56,7 +56,7 @@ struct batadv_hard_iface {
83661 int16_t if_num;
83662 char if_status;
83663 struct net_device *net_dev;
83664 - atomic_t frag_seqno;
83665 + atomic_unchecked_t frag_seqno;
83666 struct kobject *hardif_obj;
83667 atomic_t refcount;
83668 struct packet_type batman_adv_ptype;
83669 @@ -284,7 +284,7 @@ struct batadv_priv {
83670 atomic_t orig_interval; /* uint */
83671 atomic_t hop_penalty; /* uint */
83672 atomic_t log_level; /* uint */
83673 - atomic_t bcast_seqno;
83674 + atomic_unchecked_t bcast_seqno;
83675 atomic_t bcast_queue_left;
83676 atomic_t batman_queue_left;
83677 char num_ifaces;
83678 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
83679 index 10aff49..ea8e021 100644
83680 --- a/net/batman-adv/unicast.c
83681 +++ b/net/batman-adv/unicast.c
83682 @@ -272,7 +272,7 @@ int batadv_frag_send_skb(struct sk_buff *skb, struct batadv_priv *bat_priv,
83683 frag1->flags = BATADV_UNI_FRAG_HEAD | large_tail;
83684 frag2->flags = large_tail;
83685
83686 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
83687 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
83688 frag1->seqno = htons(seqno - 1);
83689 frag2->seqno = htons(seqno);
83690
83691 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
83692 index 07f0739..3c42e34 100644
83693 --- a/net/bluetooth/hci_sock.c
83694 +++ b/net/bluetooth/hci_sock.c
83695 @@ -934,7 +934,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
83696 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
83697 }
83698
83699 - len = min_t(unsigned int, len, sizeof(uf));
83700 + len = min((size_t)len, sizeof(uf));
83701 if (copy_from_user(&uf, optval, len)) {
83702 err = -EFAULT;
83703 break;
83704 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
83705 index 22e6583..426e2f3 100644
83706 --- a/net/bluetooth/l2cap_core.c
83707 +++ b/net/bluetooth/l2cap_core.c
83708 @@ -3400,8 +3400,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
83709 break;
83710
83711 case L2CAP_CONF_RFC:
83712 - if (olen == sizeof(rfc))
83713 - memcpy(&rfc, (void *)val, olen);
83714 + if (olen != sizeof(rfc))
83715 + break;
83716 +
83717 + memcpy(&rfc, (void *)val, olen);
83718
83719 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
83720 rfc.mode != chan->mode)
83721 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
83722 index 1bcfb84..dad9f98 100644
83723 --- a/net/bluetooth/l2cap_sock.c
83724 +++ b/net/bluetooth/l2cap_sock.c
83725 @@ -479,7 +479,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
83726 struct sock *sk = sock->sk;
83727 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
83728 struct l2cap_options opts;
83729 - int len, err = 0;
83730 + int err = 0;
83731 + size_t len = optlen;
83732 u32 opt;
83733
83734 BT_DBG("sk %p", sk);
83735 @@ -501,7 +502,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
83736 opts.max_tx = chan->max_tx;
83737 opts.txwin_size = chan->tx_win;
83738
83739 - len = min_t(unsigned int, sizeof(opts), optlen);
83740 + len = min(sizeof(opts), len);
83741 if (copy_from_user((char *) &opts, optval, len)) {
83742 err = -EFAULT;
83743 break;
83744 @@ -581,7 +582,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83745 struct bt_security sec;
83746 struct bt_power pwr;
83747 struct l2cap_conn *conn;
83748 - int len, err = 0;
83749 + int err = 0;
83750 + size_t len = optlen;
83751 u32 opt;
83752
83753 BT_DBG("sk %p", sk);
83754 @@ -604,7 +606,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83755
83756 sec.level = BT_SECURITY_LOW;
83757
83758 - len = min_t(unsigned int, sizeof(sec), optlen);
83759 + len = min(sizeof(sec), len);
83760 if (copy_from_user((char *) &sec, optval, len)) {
83761 err = -EFAULT;
83762 break;
83763 @@ -701,7 +703,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
83764
83765 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
83766
83767 - len = min_t(unsigned int, sizeof(pwr), optlen);
83768 + len = min(sizeof(pwr), len);
83769 if (copy_from_user((char *) &pwr, optval, len)) {
83770 err = -EFAULT;
83771 break;
83772 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
83773 index ce3f665..2c7d08f 100644
83774 --- a/net/bluetooth/rfcomm/sock.c
83775 +++ b/net/bluetooth/rfcomm/sock.c
83776 @@ -667,7 +667,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
83777 struct sock *sk = sock->sk;
83778 struct bt_security sec;
83779 int err = 0;
83780 - size_t len;
83781 + size_t len = optlen;
83782 u32 opt;
83783
83784 BT_DBG("sk %p", sk);
83785 @@ -689,7 +689,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
83786
83787 sec.level = BT_SECURITY_LOW;
83788
83789 - len = min_t(unsigned int, sizeof(sec), optlen);
83790 + len = min(sizeof(sec), len);
83791 if (copy_from_user((char *) &sec, optval, len)) {
83792 err = -EFAULT;
83793 break;
83794 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
83795 index bd6fd0f..6492cba 100644
83796 --- a/net/bluetooth/rfcomm/tty.c
83797 +++ b/net/bluetooth/rfcomm/tty.c
83798 @@ -309,7 +309,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
83799 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
83800
83801 spin_lock_irqsave(&dev->port.lock, flags);
83802 - if (dev->port.count > 0) {
83803 + if (atomic_read(&dev->port.count) > 0) {
83804 spin_unlock_irqrestore(&dev->port.lock, flags);
83805 return;
83806 }
83807 @@ -664,10 +664,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
83808 return -ENODEV;
83809
83810 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
83811 - dev->channel, dev->port.count);
83812 + dev->channel, atomic_read(&dev->port.count));
83813
83814 spin_lock_irqsave(&dev->port.lock, flags);
83815 - if (++dev->port.count > 1) {
83816 + if (atomic_inc_return(&dev->port.count) > 1) {
83817 spin_unlock_irqrestore(&dev->port.lock, flags);
83818 return 0;
83819 }
83820 @@ -732,10 +732,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
83821 return;
83822
83823 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
83824 - dev->port.count);
83825 + atomic_read(&dev->port.count));
83826
83827 spin_lock_irqsave(&dev->port.lock, flags);
83828 - if (!--dev->port.count) {
83829 + if (!atomic_dec_return(&dev->port.count)) {
83830 spin_unlock_irqrestore(&dev->port.lock, flags);
83831 if (dev->tty_dev->parent)
83832 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
83833 diff --git a/net/bridge/br_mdb.c b/net/bridge/br_mdb.c
83834 index acc9f4c..2897e40 100644
83835 --- a/net/bridge/br_mdb.c
83836 +++ b/net/bridge/br_mdb.c
83837 @@ -82,6 +82,7 @@ static int br_mdb_fill_info(struct sk_buff *skb, struct netlink_callback *cb,
83838 port = p->port;
83839 if (port) {
83840 struct br_mdb_entry e;
83841 + memset(&e, 0, sizeof(e));
83842 e.ifindex = port->dev->ifindex;
83843 e.state = p->state;
83844 if (p->addr.proto == htons(ETH_P_IP))
83845 @@ -138,6 +139,7 @@ static int br_mdb_dump(struct sk_buff *skb, struct netlink_callback *cb)
83846 break;
83847
83848 bpm = nlmsg_data(nlh);
83849 + memset(bpm, 0, sizeof(*bpm));
83850 bpm->ifindex = dev->ifindex;
83851 if (br_mdb_fill_info(skb, cb, dev) < 0)
83852 goto out;
83853 @@ -173,6 +175,7 @@ static int nlmsg_populate_mdb_fill(struct sk_buff *skb,
83854 return -EMSGSIZE;
83855
83856 bpm = nlmsg_data(nlh);
83857 + memset(bpm, 0, sizeof(*bpm));
83858 bpm->family = AF_BRIDGE;
83859 bpm->ifindex = dev->ifindex;
83860 nest = nla_nest_start(skb, MDBA_MDB);
83861 @@ -230,6 +233,7 @@ void br_mdb_notify(struct net_device *dev, struct net_bridge_port *port,
83862 {
83863 struct br_mdb_entry entry;
83864
83865 + memset(&entry, 0, sizeof(entry));
83866 entry.ifindex = port->dev->ifindex;
83867 entry.addr.proto = group->proto;
83868 entry.addr.u.ip4 = group->u.ip4;
83869 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
83870 index 5fe2ff3..121d696 100644
83871 --- a/net/bridge/netfilter/ebtables.c
83872 +++ b/net/bridge/netfilter/ebtables.c
83873 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
83874 tmp.valid_hooks = t->table->valid_hooks;
83875 }
83876 mutex_unlock(&ebt_mutex);
83877 - if (copy_to_user(user, &tmp, *len) != 0){
83878 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
83879 BUGPRINT("c2u Didn't work\n");
83880 ret = -EFAULT;
83881 break;
83882 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
83883 goto out;
83884 tmp.valid_hooks = t->valid_hooks;
83885
83886 - if (copy_to_user(user, &tmp, *len) != 0) {
83887 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
83888 ret = -EFAULT;
83889 break;
83890 }
83891 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
83892 tmp.entries_size = t->table->entries_size;
83893 tmp.valid_hooks = t->table->valid_hooks;
83894
83895 - if (copy_to_user(user, &tmp, *len) != 0) {
83896 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
83897 ret = -EFAULT;
83898 break;
83899 }
83900 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
83901 index a376ec1..1fbd6be 100644
83902 --- a/net/caif/cfctrl.c
83903 +++ b/net/caif/cfctrl.c
83904 @@ -10,6 +10,7 @@
83905 #include <linux/spinlock.h>
83906 #include <linux/slab.h>
83907 #include <linux/pkt_sched.h>
83908 +#include <linux/sched.h>
83909 #include <net/caif/caif_layer.h>
83910 #include <net/caif/cfpkt.h>
83911 #include <net/caif/cfctrl.h>
83912 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
83913 memset(&dev_info, 0, sizeof(dev_info));
83914 dev_info.id = 0xff;
83915 cfsrvl_init(&this->serv, 0, &dev_info, false);
83916 - atomic_set(&this->req_seq_no, 1);
83917 - atomic_set(&this->rsp_seq_no, 1);
83918 + atomic_set_unchecked(&this->req_seq_no, 1);
83919 + atomic_set_unchecked(&this->rsp_seq_no, 1);
83920 this->serv.layer.receive = cfctrl_recv;
83921 sprintf(this->serv.layer.name, "ctrl");
83922 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
83923 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
83924 struct cfctrl_request_info *req)
83925 {
83926 spin_lock_bh(&ctrl->info_list_lock);
83927 - atomic_inc(&ctrl->req_seq_no);
83928 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
83929 + atomic_inc_unchecked(&ctrl->req_seq_no);
83930 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
83931 list_add_tail(&req->list, &ctrl->list);
83932 spin_unlock_bh(&ctrl->info_list_lock);
83933 }
83934 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
83935 if (p != first)
83936 pr_warn("Requests are not received in order\n");
83937
83938 - atomic_set(&ctrl->rsp_seq_no,
83939 + atomic_set_unchecked(&ctrl->rsp_seq_no,
83940 p->sequence_no);
83941 list_del(&p->list);
83942 goto out;
83943 diff --git a/net/can/af_can.c b/net/can/af_can.c
83944 index ddac1ee..3ee0a78 100644
83945 --- a/net/can/af_can.c
83946 +++ b/net/can/af_can.c
83947 @@ -872,7 +872,7 @@ static const struct net_proto_family can_family_ops = {
83948 };
83949
83950 /* notifier block for netdevice event */
83951 -static struct notifier_block can_netdev_notifier __read_mostly = {
83952 +static struct notifier_block can_netdev_notifier = {
83953 .notifier_call = can_notifier,
83954 };
83955
83956 diff --git a/net/can/gw.c b/net/can/gw.c
83957 index 574dda78e..3d2b3da 100644
83958 --- a/net/can/gw.c
83959 +++ b/net/can/gw.c
83960 @@ -67,7 +67,6 @@ MODULE_AUTHOR("Oliver Hartkopp <oliver.hartkopp@volkswagen.de>");
83961 MODULE_ALIAS("can-gw");
83962
83963 static HLIST_HEAD(cgw_list);
83964 -static struct notifier_block notifier;
83965
83966 static struct kmem_cache *cgw_cache __read_mostly;
83967
83968 @@ -893,6 +892,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
83969 return err;
83970 }
83971
83972 +static struct notifier_block notifier = {
83973 + .notifier_call = cgw_notifier
83974 +};
83975 +
83976 static __init int cgw_module_init(void)
83977 {
83978 printk(banner);
83979 @@ -904,7 +907,6 @@ static __init int cgw_module_init(void)
83980 return -ENOMEM;
83981
83982 /* set notifier */
83983 - notifier.notifier_call = cgw_notifier;
83984 register_netdevice_notifier(&notifier);
83985
83986 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
83987 diff --git a/net/compat.c b/net/compat.c
83988 index 79ae884..17c5c09 100644
83989 --- a/net/compat.c
83990 +++ b/net/compat.c
83991 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
83992 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
83993 __get_user(kmsg->msg_flags, &umsg->msg_flags))
83994 return -EFAULT;
83995 - kmsg->msg_name = compat_ptr(tmp1);
83996 - kmsg->msg_iov = compat_ptr(tmp2);
83997 - kmsg->msg_control = compat_ptr(tmp3);
83998 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
83999 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
84000 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
84001 return 0;
84002 }
84003
84004 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84005
84006 if (kern_msg->msg_namelen) {
84007 if (mode == VERIFY_READ) {
84008 - int err = move_addr_to_kernel(kern_msg->msg_name,
84009 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
84010 kern_msg->msg_namelen,
84011 kern_address);
84012 if (err < 0)
84013 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84014 kern_msg->msg_name = NULL;
84015
84016 tot_len = iov_from_user_compat_to_kern(kern_iov,
84017 - (struct compat_iovec __user *)kern_msg->msg_iov,
84018 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
84019 kern_msg->msg_iovlen);
84020 if (tot_len >= 0)
84021 kern_msg->msg_iov = kern_iov;
84022 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
84023
84024 #define CMSG_COMPAT_FIRSTHDR(msg) \
84025 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
84026 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
84027 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
84028 (struct compat_cmsghdr __user *)NULL)
84029
84030 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
84031 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
84032 (ucmlen) <= (unsigned long) \
84033 ((mhdr)->msg_controllen - \
84034 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
84035 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
84036
84037 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
84038 struct compat_cmsghdr __user *cmsg, int cmsg_len)
84039 {
84040 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
84041 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
84042 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
84043 msg->msg_controllen)
84044 return NULL;
84045 return (struct compat_cmsghdr __user *)ptr;
84046 @@ -219,7 +219,7 @@ Efault:
84047
84048 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
84049 {
84050 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84051 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84052 struct compat_cmsghdr cmhdr;
84053 struct compat_timeval ctv;
84054 struct compat_timespec cts[3];
84055 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
84056
84057 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
84058 {
84059 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
84060 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
84061 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
84062 int fdnum = scm->fp->count;
84063 struct file **fp = scm->fp->fp;
84064 @@ -363,7 +363,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
84065 return -EFAULT;
84066 old_fs = get_fs();
84067 set_fs(KERNEL_DS);
84068 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
84069 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
84070 set_fs(old_fs);
84071
84072 return err;
84073 @@ -424,7 +424,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
84074 len = sizeof(ktime);
84075 old_fs = get_fs();
84076 set_fs(KERNEL_DS);
84077 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
84078 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
84079 set_fs(old_fs);
84080
84081 if (!err) {
84082 @@ -567,7 +567,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84083 case MCAST_JOIN_GROUP:
84084 case MCAST_LEAVE_GROUP:
84085 {
84086 - struct compat_group_req __user *gr32 = (void *)optval;
84087 + struct compat_group_req __user *gr32 = (void __user *)optval;
84088 struct group_req __user *kgr =
84089 compat_alloc_user_space(sizeof(struct group_req));
84090 u32 interface;
84091 @@ -588,7 +588,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84092 case MCAST_BLOCK_SOURCE:
84093 case MCAST_UNBLOCK_SOURCE:
84094 {
84095 - struct compat_group_source_req __user *gsr32 = (void *)optval;
84096 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
84097 struct group_source_req __user *kgsr = compat_alloc_user_space(
84098 sizeof(struct group_source_req));
84099 u32 interface;
84100 @@ -609,7 +609,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
84101 }
84102 case MCAST_MSFILTER:
84103 {
84104 - struct compat_group_filter __user *gf32 = (void *)optval;
84105 + struct compat_group_filter __user *gf32 = (void __user *)optval;
84106 struct group_filter __user *kgf;
84107 u32 interface, fmode, numsrc;
84108
84109 @@ -647,7 +647,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
84110 char __user *optval, int __user *optlen,
84111 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
84112 {
84113 - struct compat_group_filter __user *gf32 = (void *)optval;
84114 + struct compat_group_filter __user *gf32 = (void __user *)optval;
84115 struct group_filter __user *kgf;
84116 int __user *koptlen;
84117 u32 interface, fmode, numsrc;
84118 @@ -796,7 +796,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
84119
84120 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
84121 return -EINVAL;
84122 - if (copy_from_user(a, args, nas[call]))
84123 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
84124 return -EFAULT;
84125 a0 = a[0];
84126 a1 = a[1];
84127 diff --git a/net/core/datagram.c b/net/core/datagram.c
84128 index 368f9c3..f82d4a3 100644
84129 --- a/net/core/datagram.c
84130 +++ b/net/core/datagram.c
84131 @@ -289,7 +289,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
84132 }
84133
84134 kfree_skb(skb);
84135 - atomic_inc(&sk->sk_drops);
84136 + atomic_inc_unchecked(&sk->sk_drops);
84137 sk_mem_reclaim_partial(sk);
84138
84139 return err;
84140 diff --git a/net/core/dev.c b/net/core/dev.c
84141 index f64e439..8f959e6 100644
84142 --- a/net/core/dev.c
84143 +++ b/net/core/dev.c
84144 @@ -1250,9 +1250,13 @@ void dev_load(struct net *net, const char *name)
84145 if (no_module && capable(CAP_NET_ADMIN))
84146 no_module = request_module("netdev-%s", name);
84147 if (no_module && capable(CAP_SYS_MODULE)) {
84148 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
84149 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
84150 +#else
84151 if (!request_module("%s", name))
84152 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
84153 name);
84154 +#endif
84155 }
84156 }
84157 EXPORT_SYMBOL(dev_load);
84158 @@ -1715,7 +1719,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84159 {
84160 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
84161 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
84162 - atomic_long_inc(&dev->rx_dropped);
84163 + atomic_long_inc_unchecked(&dev->rx_dropped);
84164 kfree_skb(skb);
84165 return NET_RX_DROP;
84166 }
84167 @@ -1725,7 +1729,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
84168 nf_reset(skb);
84169
84170 if (unlikely(!is_skb_forwardable(dev, skb))) {
84171 - atomic_long_inc(&dev->rx_dropped);
84172 + atomic_long_inc_unchecked(&dev->rx_dropped);
84173 kfree_skb(skb);
84174 return NET_RX_DROP;
84175 }
84176 @@ -2180,7 +2184,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
84177
84178 struct dev_gso_cb {
84179 void (*destructor)(struct sk_buff *skb);
84180 -};
84181 +} __no_const;
84182
84183 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
84184
84185 @@ -3053,7 +3057,7 @@ enqueue:
84186
84187 local_irq_restore(flags);
84188
84189 - atomic_long_inc(&skb->dev->rx_dropped);
84190 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84191 kfree_skb(skb);
84192 return NET_RX_DROP;
84193 }
84194 @@ -3125,7 +3129,7 @@ int netif_rx_ni(struct sk_buff *skb)
84195 }
84196 EXPORT_SYMBOL(netif_rx_ni);
84197
84198 -static void net_tx_action(struct softirq_action *h)
84199 +static void net_tx_action(void)
84200 {
84201 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84202
84203 @@ -3456,7 +3460,7 @@ ncls:
84204 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
84205 } else {
84206 drop:
84207 - atomic_long_inc(&skb->dev->rx_dropped);
84208 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
84209 kfree_skb(skb);
84210 /* Jamal, now you will not able to escape explaining
84211 * me how you were going to use this. :-)
84212 @@ -4039,7 +4043,7 @@ void netif_napi_del(struct napi_struct *napi)
84213 }
84214 EXPORT_SYMBOL(netif_napi_del);
84215
84216 -static void net_rx_action(struct softirq_action *h)
84217 +static void net_rx_action(void)
84218 {
84219 struct softnet_data *sd = &__get_cpu_var(softnet_data);
84220 unsigned long time_limit = jiffies + 2;
84221 @@ -4523,8 +4527,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
84222 else
84223 seq_printf(seq, "%04x", ntohs(pt->type));
84224
84225 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84226 + seq_printf(seq, " %-8s %p\n",
84227 + pt->dev ? pt->dev->name : "", NULL);
84228 +#else
84229 seq_printf(seq, " %-8s %pF\n",
84230 pt->dev ? pt->dev->name : "", pt->func);
84231 +#endif
84232 }
84233
84234 return 0;
84235 @@ -6096,7 +6105,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
84236 } else {
84237 netdev_stats_to_stats64(storage, &dev->stats);
84238 }
84239 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
84240 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
84241 return storage;
84242 }
84243 EXPORT_SYMBOL(dev_get_stats);
84244 diff --git a/net/core/flow.c b/net/core/flow.c
84245 index b0901ee..7d3c2ca 100644
84246 --- a/net/core/flow.c
84247 +++ b/net/core/flow.c
84248 @@ -61,7 +61,7 @@ struct flow_cache {
84249 struct timer_list rnd_timer;
84250 };
84251
84252 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
84253 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
84254 EXPORT_SYMBOL(flow_cache_genid);
84255 static struct flow_cache flow_cache_global;
84256 static struct kmem_cache *flow_cachep __read_mostly;
84257 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
84258
84259 static int flow_entry_valid(struct flow_cache_entry *fle)
84260 {
84261 - if (atomic_read(&flow_cache_genid) != fle->genid)
84262 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
84263 return 0;
84264 if (fle->object && !fle->object->ops->check(fle->object))
84265 return 0;
84266 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
84267 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
84268 fcp->hash_count++;
84269 }
84270 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
84271 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
84272 flo = fle->object;
84273 if (!flo)
84274 goto ret_object;
84275 @@ -280,7 +280,7 @@ nocache:
84276 }
84277 flo = resolver(net, key, family, dir, flo, ctx);
84278 if (fle) {
84279 - fle->genid = atomic_read(&flow_cache_genid);
84280 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
84281 if (!IS_ERR(flo))
84282 fle->object = flo;
84283 else
84284 diff --git a/net/core/iovec.c b/net/core/iovec.c
84285 index 7e7aeb0..2a998cb 100644
84286 --- a/net/core/iovec.c
84287 +++ b/net/core/iovec.c
84288 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84289 if (m->msg_namelen) {
84290 if (mode == VERIFY_READ) {
84291 void __user *namep;
84292 - namep = (void __user __force *) m->msg_name;
84293 + namep = (void __force_user *) m->msg_name;
84294 err = move_addr_to_kernel(namep, m->msg_namelen,
84295 address);
84296 if (err < 0)
84297 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
84298 }
84299
84300 size = m->msg_iovlen * sizeof(struct iovec);
84301 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
84302 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
84303 return -EFAULT;
84304
84305 m->msg_iov = iov;
84306 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
84307 index c815f28..e6403f2 100644
84308 --- a/net/core/neighbour.c
84309 +++ b/net/core/neighbour.c
84310 @@ -2776,7 +2776,7 @@ static int proc_unres_qlen(ctl_table *ctl, int write, void __user *buffer,
84311 size_t *lenp, loff_t *ppos)
84312 {
84313 int size, ret;
84314 - ctl_table tmp = *ctl;
84315 + ctl_table_no_const tmp = *ctl;
84316
84317 tmp.extra1 = &zero;
84318 tmp.extra2 = &unres_qlen_max;
84319 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
84320 index 28c5f5a..7edf2e2 100644
84321 --- a/net/core/net-sysfs.c
84322 +++ b/net/core/net-sysfs.c
84323 @@ -1455,7 +1455,7 @@ void netdev_class_remove_file(struct class_attribute *class_attr)
84324 }
84325 EXPORT_SYMBOL(netdev_class_remove_file);
84326
84327 -int netdev_kobject_init(void)
84328 +int __init netdev_kobject_init(void)
84329 {
84330 kobj_ns_type_register(&net_ns_type_operations);
84331 return class_register(&net_class);
84332 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
84333 index 8acce01..2e306bb 100644
84334 --- a/net/core/net_namespace.c
84335 +++ b/net/core/net_namespace.c
84336 @@ -442,7 +442,7 @@ static int __register_pernet_operations(struct list_head *list,
84337 int error;
84338 LIST_HEAD(net_exit_list);
84339
84340 - list_add_tail(&ops->list, list);
84341 + pax_list_add_tail((struct list_head *)&ops->list, list);
84342 if (ops->init || (ops->id && ops->size)) {
84343 for_each_net(net) {
84344 error = ops_init(ops, net);
84345 @@ -455,7 +455,7 @@ static int __register_pernet_operations(struct list_head *list,
84346
84347 out_undo:
84348 /* If I have an error cleanup all namespaces I initialized */
84349 - list_del(&ops->list);
84350 + pax_list_del((struct list_head *)&ops->list);
84351 ops_exit_list(ops, &net_exit_list);
84352 ops_free_list(ops, &net_exit_list);
84353 return error;
84354 @@ -466,7 +466,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
84355 struct net *net;
84356 LIST_HEAD(net_exit_list);
84357
84358 - list_del(&ops->list);
84359 + pax_list_del((struct list_head *)&ops->list);
84360 for_each_net(net)
84361 list_add_tail(&net->exit_list, &net_exit_list);
84362 ops_exit_list(ops, &net_exit_list);
84363 @@ -600,7 +600,7 @@ int register_pernet_device(struct pernet_operations *ops)
84364 mutex_lock(&net_mutex);
84365 error = register_pernet_operations(&pernet_list, ops);
84366 if (!error && (first_device == &pernet_list))
84367 - first_device = &ops->list;
84368 + first_device = (struct list_head *)&ops->list;
84369 mutex_unlock(&net_mutex);
84370 return error;
84371 }
84372 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
84373 index 1868625..e2261f5 100644
84374 --- a/net/core/rtnetlink.c
84375 +++ b/net/core/rtnetlink.c
84376 @@ -58,7 +58,7 @@ struct rtnl_link {
84377 rtnl_doit_func doit;
84378 rtnl_dumpit_func dumpit;
84379 rtnl_calcit_func calcit;
84380 -};
84381 +} __no_const;
84382
84383 static DEFINE_MUTEX(rtnl_mutex);
84384
84385 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
84386 if (rtnl_link_ops_get(ops->kind))
84387 return -EEXIST;
84388
84389 - if (!ops->dellink)
84390 - ops->dellink = unregister_netdevice_queue;
84391 + if (!ops->dellink) {
84392 + pax_open_kernel();
84393 + *(void **)&ops->dellink = unregister_netdevice_queue;
84394 + pax_close_kernel();
84395 + }
84396
84397 - list_add_tail(&ops->list, &link_ops);
84398 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
84399 return 0;
84400 }
84401 EXPORT_SYMBOL_GPL(__rtnl_link_register);
84402 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
84403 for_each_net(net) {
84404 __rtnl_kill_links(net, ops);
84405 }
84406 - list_del(&ops->list);
84407 + pax_list_del((struct list_head *)&ops->list);
84408 }
84409 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
84410
84411 @@ -976,6 +979,7 @@ static int rtnl_fill_ifinfo(struct sk_buff *skb, struct net_device *dev,
84412 * report anything.
84413 */
84414 ivi.spoofchk = -1;
84415 + memset(ivi.mac, 0, sizeof(ivi.mac));
84416 if (dev->netdev_ops->ndo_get_vf_config(dev, i, &ivi))
84417 break;
84418 vf_mac.vf =
84419 diff --git a/net/core/scm.c b/net/core/scm.c
84420 index 905dcc6..14ee2d6 100644
84421 --- a/net/core/scm.c
84422 +++ b/net/core/scm.c
84423 @@ -224,7 +224,7 @@ EXPORT_SYMBOL(__scm_send);
84424 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
84425 {
84426 struct cmsghdr __user *cm
84427 - = (__force struct cmsghdr __user *)msg->msg_control;
84428 + = (struct cmsghdr __force_user *)msg->msg_control;
84429 struct cmsghdr cmhdr;
84430 int cmlen = CMSG_LEN(len);
84431 int err;
84432 @@ -247,7 +247,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
84433 err = -EFAULT;
84434 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
84435 goto out;
84436 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
84437 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
84438 goto out;
84439 cmlen = CMSG_SPACE(len);
84440 if (msg->msg_controllen < cmlen)
84441 @@ -263,7 +263,7 @@ EXPORT_SYMBOL(put_cmsg);
84442 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
84443 {
84444 struct cmsghdr __user *cm
84445 - = (__force struct cmsghdr __user*)msg->msg_control;
84446 + = (struct cmsghdr __force_user *)msg->msg_control;
84447
84448 int fdmax = 0;
84449 int fdnum = scm->fp->count;
84450 @@ -283,7 +283,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
84451 if (fdnum < fdmax)
84452 fdmax = fdnum;
84453
84454 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
84455 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
84456 i++, cmfptr++)
84457 {
84458 struct socket *sock;
84459 diff --git a/net/core/sock.c b/net/core/sock.c
84460 index bc131d4..029e378 100644
84461 --- a/net/core/sock.c
84462 +++ b/net/core/sock.c
84463 @@ -388,7 +388,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84464 struct sk_buff_head *list = &sk->sk_receive_queue;
84465
84466 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
84467 - atomic_inc(&sk->sk_drops);
84468 + atomic_inc_unchecked(&sk->sk_drops);
84469 trace_sock_rcvqueue_full(sk, skb);
84470 return -ENOMEM;
84471 }
84472 @@ -398,7 +398,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84473 return err;
84474
84475 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
84476 - atomic_inc(&sk->sk_drops);
84477 + atomic_inc_unchecked(&sk->sk_drops);
84478 return -ENOBUFS;
84479 }
84480
84481 @@ -418,7 +418,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
84482 skb_dst_force(skb);
84483
84484 spin_lock_irqsave(&list->lock, flags);
84485 - skb->dropcount = atomic_read(&sk->sk_drops);
84486 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
84487 __skb_queue_tail(list, skb);
84488 spin_unlock_irqrestore(&list->lock, flags);
84489
84490 @@ -438,7 +438,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
84491 skb->dev = NULL;
84492
84493 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
84494 - atomic_inc(&sk->sk_drops);
84495 + atomic_inc_unchecked(&sk->sk_drops);
84496 goto discard_and_relse;
84497 }
84498 if (nested)
84499 @@ -456,7 +456,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
84500 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
84501 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
84502 bh_unlock_sock(sk);
84503 - atomic_inc(&sk->sk_drops);
84504 + atomic_inc_unchecked(&sk->sk_drops);
84505 goto discard_and_relse;
84506 }
84507
84508 @@ -930,12 +930,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84509 struct timeval tm;
84510 } v;
84511
84512 - int lv = sizeof(int);
84513 - int len;
84514 + unsigned int lv = sizeof(int);
84515 + unsigned int len;
84516
84517 if (get_user(len, optlen))
84518 return -EFAULT;
84519 - if (len < 0)
84520 + if (len > INT_MAX)
84521 return -EINVAL;
84522
84523 memset(&v, 0, sizeof(v));
84524 @@ -1083,11 +1083,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84525
84526 case SO_PEERNAME:
84527 {
84528 - char address[128];
84529 + char address[_K_SS_MAXSIZE];
84530
84531 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
84532 return -ENOTCONN;
84533 - if (lv < len)
84534 + if (lv < len || sizeof address < len)
84535 return -EINVAL;
84536 if (copy_to_user(optval, address, len))
84537 return -EFAULT;
84538 @@ -1146,7 +1146,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
84539
84540 if (len > lv)
84541 len = lv;
84542 - if (copy_to_user(optval, &v, len))
84543 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
84544 return -EFAULT;
84545 lenout:
84546 if (put_user(len, optlen))
84547 @@ -2276,7 +2276,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
84548 */
84549 smp_wmb();
84550 atomic_set(&sk->sk_refcnt, 1);
84551 - atomic_set(&sk->sk_drops, 0);
84552 + atomic_set_unchecked(&sk->sk_drops, 0);
84553 }
84554 EXPORT_SYMBOL(sock_init_data);
84555
84556 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
84557 index 750f44f..922399c 100644
84558 --- a/net/core/sock_diag.c
84559 +++ b/net/core/sock_diag.c
84560 @@ -9,26 +9,33 @@
84561 #include <linux/inet_diag.h>
84562 #include <linux/sock_diag.h>
84563
84564 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
84565 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
84566 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
84567 static DEFINE_MUTEX(sock_diag_table_mutex);
84568
84569 int sock_diag_check_cookie(void *sk, __u32 *cookie)
84570 {
84571 +#ifndef CONFIG_GRKERNSEC_HIDESYM
84572 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
84573 cookie[1] != INET_DIAG_NOCOOKIE) &&
84574 ((u32)(unsigned long)sk != cookie[0] ||
84575 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
84576 return -ESTALE;
84577 else
84578 +#endif
84579 return 0;
84580 }
84581 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
84582
84583 void sock_diag_save_cookie(void *sk, __u32 *cookie)
84584 {
84585 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84586 + cookie[0] = 0;
84587 + cookie[1] = 0;
84588 +#else
84589 cookie[0] = (u32)(unsigned long)sk;
84590 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
84591 +#endif
84592 }
84593 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
84594
84595 @@ -75,8 +82,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
84596 mutex_lock(&sock_diag_table_mutex);
84597 if (sock_diag_handlers[hndl->family])
84598 err = -EBUSY;
84599 - else
84600 + else {
84601 + pax_open_kernel();
84602 sock_diag_handlers[hndl->family] = hndl;
84603 + pax_close_kernel();
84604 + }
84605 mutex_unlock(&sock_diag_table_mutex);
84606
84607 return err;
84608 @@ -92,26 +102,13 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
84609
84610 mutex_lock(&sock_diag_table_mutex);
84611 BUG_ON(sock_diag_handlers[family] != hnld);
84612 + pax_open_kernel();
84613 sock_diag_handlers[family] = NULL;
84614 + pax_close_kernel();
84615 mutex_unlock(&sock_diag_table_mutex);
84616 }
84617 EXPORT_SYMBOL_GPL(sock_diag_unregister);
84618
84619 -static const inline struct sock_diag_handler *sock_diag_lock_handler(int family)
84620 -{
84621 - if (sock_diag_handlers[family] == NULL)
84622 - request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
84623 - NETLINK_SOCK_DIAG, family);
84624 -
84625 - mutex_lock(&sock_diag_table_mutex);
84626 - return sock_diag_handlers[family];
84627 -}
84628 -
84629 -static inline void sock_diag_unlock_handler(const struct sock_diag_handler *h)
84630 -{
84631 - mutex_unlock(&sock_diag_table_mutex);
84632 -}
84633 -
84634 static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84635 {
84636 int err;
84637 @@ -124,12 +121,17 @@ static int __sock_diag_rcv_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
84638 if (req->sdiag_family >= AF_MAX)
84639 return -EINVAL;
84640
84641 - hndl = sock_diag_lock_handler(req->sdiag_family);
84642 + if (sock_diag_handlers[req->sdiag_family] == NULL)
84643 + request_module("net-pf-%d-proto-%d-type-%d", PF_NETLINK,
84644 + NETLINK_SOCK_DIAG, req->sdiag_family);
84645 +
84646 + mutex_lock(&sock_diag_table_mutex);
84647 + hndl = sock_diag_handlers[req->sdiag_family];
84648 if (hndl == NULL)
84649 err = -ENOENT;
84650 else
84651 err = hndl->dump(skb, nlh);
84652 - sock_diag_unlock_handler(hndl);
84653 + mutex_unlock(&sock_diag_table_mutex);
84654
84655 return err;
84656 }
84657 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
84658 index d1b0804..4aed0a5 100644
84659 --- a/net/core/sysctl_net_core.c
84660 +++ b/net/core/sysctl_net_core.c
84661 @@ -26,7 +26,7 @@ static int rps_sock_flow_sysctl(ctl_table *table, int write,
84662 {
84663 unsigned int orig_size, size;
84664 int ret, i;
84665 - ctl_table tmp = {
84666 + ctl_table_no_const tmp = {
84667 .data = &size,
84668 .maxlen = sizeof(size),
84669 .mode = table->mode
84670 @@ -205,13 +205,12 @@ static struct ctl_table netns_core_table[] = {
84671
84672 static __net_init int sysctl_core_net_init(struct net *net)
84673 {
84674 - struct ctl_table *tbl;
84675 + ctl_table_no_const *tbl = NULL;
84676
84677 net->core.sysctl_somaxconn = SOMAXCONN;
84678
84679 - tbl = netns_core_table;
84680 if (!net_eq(net, &init_net)) {
84681 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
84682 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
84683 if (tbl == NULL)
84684 goto err_dup;
84685
84686 @@ -221,16 +220,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
84687 if (net->user_ns != &init_user_ns) {
84688 tbl[0].procname = NULL;
84689 }
84690 - }
84691 -
84692 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
84693 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
84694 + } else
84695 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
84696 if (net->core.sysctl_hdr == NULL)
84697 goto err_reg;
84698
84699 return 0;
84700
84701 err_reg:
84702 - if (tbl != netns_core_table)
84703 + if (tbl)
84704 kfree(tbl);
84705 err_dup:
84706 return -ENOMEM;
84707 @@ -246,7 +245,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
84708 kfree(tbl);
84709 }
84710
84711 -static __net_initdata struct pernet_operations sysctl_core_ops = {
84712 +static __net_initconst struct pernet_operations sysctl_core_ops = {
84713 .init = sysctl_core_net_init,
84714 .exit = sysctl_core_net_exit,
84715 };
84716 diff --git a/net/dcb/dcbnl.c b/net/dcb/dcbnl.c
84717 index 1b588e2..21291f1 100644
84718 --- a/net/dcb/dcbnl.c
84719 +++ b/net/dcb/dcbnl.c
84720 @@ -284,6 +284,7 @@ static int dcbnl_getperm_hwaddr(struct net_device *netdev, struct nlmsghdr *nlh,
84721 if (!netdev->dcbnl_ops->getpermhwaddr)
84722 return -EOPNOTSUPP;
84723
84724 + memset(perm_addr, 0, sizeof(perm_addr));
84725 netdev->dcbnl_ops->getpermhwaddr(netdev, perm_addr);
84726
84727 return nla_put(skb, DCB_ATTR_PERM_HWADDR, sizeof(perm_addr), perm_addr);
84728 @@ -1042,6 +1043,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84729
84730 if (ops->ieee_getets) {
84731 struct ieee_ets ets;
84732 + memset(&ets, 0, sizeof(ets));
84733 err = ops->ieee_getets(netdev, &ets);
84734 if (!err &&
84735 nla_put(skb, DCB_ATTR_IEEE_ETS, sizeof(ets), &ets))
84736 @@ -1050,6 +1052,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84737
84738 if (ops->ieee_getmaxrate) {
84739 struct ieee_maxrate maxrate;
84740 + memset(&maxrate, 0, sizeof(maxrate));
84741 err = ops->ieee_getmaxrate(netdev, &maxrate);
84742 if (!err) {
84743 err = nla_put(skb, DCB_ATTR_IEEE_MAXRATE,
84744 @@ -1061,6 +1064,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84745
84746 if (ops->ieee_getpfc) {
84747 struct ieee_pfc pfc;
84748 + memset(&pfc, 0, sizeof(pfc));
84749 err = ops->ieee_getpfc(netdev, &pfc);
84750 if (!err &&
84751 nla_put(skb, DCB_ATTR_IEEE_PFC, sizeof(pfc), &pfc))
84752 @@ -1094,6 +1098,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84753 /* get peer info if available */
84754 if (ops->ieee_peer_getets) {
84755 struct ieee_ets ets;
84756 + memset(&ets, 0, sizeof(ets));
84757 err = ops->ieee_peer_getets(netdev, &ets);
84758 if (!err &&
84759 nla_put(skb, DCB_ATTR_IEEE_PEER_ETS, sizeof(ets), &ets))
84760 @@ -1102,6 +1107,7 @@ static int dcbnl_ieee_fill(struct sk_buff *skb, struct net_device *netdev)
84761
84762 if (ops->ieee_peer_getpfc) {
84763 struct ieee_pfc pfc;
84764 + memset(&pfc, 0, sizeof(pfc));
84765 err = ops->ieee_peer_getpfc(netdev, &pfc);
84766 if (!err &&
84767 nla_put(skb, DCB_ATTR_IEEE_PEER_PFC, sizeof(pfc), &pfc))
84768 @@ -1280,6 +1286,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
84769 /* peer info if available */
84770 if (ops->cee_peer_getpg) {
84771 struct cee_pg pg;
84772 + memset(&pg, 0, sizeof(pg));
84773 err = ops->cee_peer_getpg(netdev, &pg);
84774 if (!err &&
84775 nla_put(skb, DCB_ATTR_CEE_PEER_PG, sizeof(pg), &pg))
84776 @@ -1288,6 +1295,7 @@ static int dcbnl_cee_fill(struct sk_buff *skb, struct net_device *netdev)
84777
84778 if (ops->cee_peer_getpfc) {
84779 struct cee_pfc pfc;
84780 + memset(&pfc, 0, sizeof(pfc));
84781 err = ops->cee_peer_getpfc(netdev, &pfc);
84782 if (!err &&
84783 nla_put(skb, DCB_ATTR_CEE_PEER_PFC, sizeof(pfc), &pfc))
84784 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
84785 index 307c322..78a4c6f 100644
84786 --- a/net/decnet/af_decnet.c
84787 +++ b/net/decnet/af_decnet.c
84788 @@ -468,6 +468,7 @@ static struct proto dn_proto = {
84789 .sysctl_rmem = sysctl_decnet_rmem,
84790 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
84791 .obj_size = sizeof(struct dn_sock),
84792 + .slab_flags = SLAB_USERCOPY,
84793 };
84794
84795 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
84796 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
84797 index a55eecc..dd8428c 100644
84798 --- a/net/decnet/sysctl_net_decnet.c
84799 +++ b/net/decnet/sysctl_net_decnet.c
84800 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
84801
84802 if (len > *lenp) len = *lenp;
84803
84804 - if (copy_to_user(buffer, addr, len))
84805 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
84806 return -EFAULT;
84807
84808 *lenp = len;
84809 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
84810
84811 if (len > *lenp) len = *lenp;
84812
84813 - if (copy_to_user(buffer, devname, len))
84814 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
84815 return -EFAULT;
84816
84817 *lenp = len;
84818 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
84819 index fcf104e..95552d4 100644
84820 --- a/net/ipv4/af_inet.c
84821 +++ b/net/ipv4/af_inet.c
84822 @@ -1717,13 +1717,9 @@ static int __init inet_init(void)
84823
84824 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > sizeof(dummy_skb->cb));
84825
84826 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
84827 - if (!sysctl_local_reserved_ports)
84828 - goto out;
84829 -
84830 rc = proto_register(&tcp_prot, 1);
84831 if (rc)
84832 - goto out_free_reserved_ports;
84833 + goto out;
84834
84835 rc = proto_register(&udp_prot, 1);
84836 if (rc)
84837 @@ -1832,8 +1828,6 @@ out_unregister_udp_proto:
84838 proto_unregister(&udp_prot);
84839 out_unregister_tcp_proto:
84840 proto_unregister(&tcp_prot);
84841 -out_free_reserved_ports:
84842 - kfree(sysctl_local_reserved_ports);
84843 goto out;
84844 }
84845
84846 diff --git a/net/ipv4/ah4.c b/net/ipv4/ah4.c
84847 index a69b4e4..dbccba5 100644
84848 --- a/net/ipv4/ah4.c
84849 +++ b/net/ipv4/ah4.c
84850 @@ -421,7 +421,7 @@ static void ah4_err(struct sk_buff *skb, u32 info)
84851 return;
84852
84853 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
84854 - atomic_inc(&flow_cache_genid);
84855 + atomic_inc_unchecked(&flow_cache_genid);
84856 rt_genid_bump(net);
84857
84858 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_AH, 0);
84859 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
84860 index a8e4f26..25e5f40 100644
84861 --- a/net/ipv4/devinet.c
84862 +++ b/net/ipv4/devinet.c
84863 @@ -1763,7 +1763,7 @@ static int ipv4_doint_and_flush(ctl_table *ctl, int write,
84864 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
84865 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
84866
84867 -static struct devinet_sysctl_table {
84868 +static const struct devinet_sysctl_table {
84869 struct ctl_table_header *sysctl_header;
84870 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
84871 } devinet_sysctl = {
84872 @@ -1881,7 +1881,7 @@ static __net_init int devinet_init_net(struct net *net)
84873 int err;
84874 struct ipv4_devconf *all, *dflt;
84875 #ifdef CONFIG_SYSCTL
84876 - struct ctl_table *tbl = ctl_forward_entry;
84877 + ctl_table_no_const *tbl = NULL;
84878 struct ctl_table_header *forw_hdr;
84879 #endif
84880
84881 @@ -1899,7 +1899,7 @@ static __net_init int devinet_init_net(struct net *net)
84882 goto err_alloc_dflt;
84883
84884 #ifdef CONFIG_SYSCTL
84885 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
84886 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
84887 if (tbl == NULL)
84888 goto err_alloc_ctl;
84889
84890 @@ -1919,7 +1919,10 @@ static __net_init int devinet_init_net(struct net *net)
84891 goto err_reg_dflt;
84892
84893 err = -ENOMEM;
84894 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
84895 + if (!net_eq(net, &init_net))
84896 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
84897 + else
84898 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
84899 if (forw_hdr == NULL)
84900 goto err_reg_ctl;
84901 net->ipv4.forw_hdr = forw_hdr;
84902 @@ -1935,8 +1938,7 @@ err_reg_ctl:
84903 err_reg_dflt:
84904 __devinet_sysctl_unregister(all);
84905 err_reg_all:
84906 - if (tbl != ctl_forward_entry)
84907 - kfree(tbl);
84908 + kfree(tbl);
84909 err_alloc_ctl:
84910 #endif
84911 if (dflt != &ipv4_devconf_dflt)
84912 diff --git a/net/ipv4/esp4.c b/net/ipv4/esp4.c
84913 index 3b4f0cd..8cb864c 100644
84914 --- a/net/ipv4/esp4.c
84915 +++ b/net/ipv4/esp4.c
84916 @@ -503,7 +503,7 @@ static void esp4_err(struct sk_buff *skb, u32 info)
84917 return;
84918
84919 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
84920 - atomic_inc(&flow_cache_genid);
84921 + atomic_inc_unchecked(&flow_cache_genid);
84922 rt_genid_bump(net);
84923
84924 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_ESP, 0);
84925 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
84926 index 5cd75e2..f57ef39 100644
84927 --- a/net/ipv4/fib_frontend.c
84928 +++ b/net/ipv4/fib_frontend.c
84929 @@ -1020,12 +1020,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
84930 #ifdef CONFIG_IP_ROUTE_MULTIPATH
84931 fib_sync_up(dev);
84932 #endif
84933 - atomic_inc(&net->ipv4.dev_addr_genid);
84934 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84935 rt_cache_flush(dev_net(dev));
84936 break;
84937 case NETDEV_DOWN:
84938 fib_del_ifaddr(ifa, NULL);
84939 - atomic_inc(&net->ipv4.dev_addr_genid);
84940 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84941 if (ifa->ifa_dev->ifa_list == NULL) {
84942 /* Last address was deleted from this interface.
84943 * Disable IP.
84944 @@ -1061,7 +1061,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
84945 #ifdef CONFIG_IP_ROUTE_MULTIPATH
84946 fib_sync_up(dev);
84947 #endif
84948 - atomic_inc(&net->ipv4.dev_addr_genid);
84949 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
84950 rt_cache_flush(net);
84951 break;
84952 case NETDEV_DOWN:
84953 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
84954 index 4797a80..2bd54e9 100644
84955 --- a/net/ipv4/fib_semantics.c
84956 +++ b/net/ipv4/fib_semantics.c
84957 @@ -767,7 +767,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
84958 nh->nh_saddr = inet_select_addr(nh->nh_dev,
84959 nh->nh_gw,
84960 nh->nh_parent->fib_scope);
84961 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
84962 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
84963
84964 return nh->nh_saddr;
84965 }
84966 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
84967 index d0670f0..744ac80 100644
84968 --- a/net/ipv4/inet_connection_sock.c
84969 +++ b/net/ipv4/inet_connection_sock.c
84970 @@ -37,7 +37,7 @@ struct local_ports sysctl_local_ports __read_mostly = {
84971 .range = { 32768, 61000 },
84972 };
84973
84974 -unsigned long *sysctl_local_reserved_ports;
84975 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
84976 EXPORT_SYMBOL(sysctl_local_reserved_ports);
84977
84978 void inet_get_local_port_range(int *low, int *high)
84979 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
84980 index fa3ae81..0dbe6b8 100644
84981 --- a/net/ipv4/inet_hashtables.c
84982 +++ b/net/ipv4/inet_hashtables.c
84983 @@ -18,12 +18,15 @@
84984 #include <linux/sched.h>
84985 #include <linux/slab.h>
84986 #include <linux/wait.h>
84987 +#include <linux/security.h>
84988
84989 #include <net/inet_connection_sock.h>
84990 #include <net/inet_hashtables.h>
84991 #include <net/secure_seq.h>
84992 #include <net/ip.h>
84993
84994 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
84995 +
84996 /*
84997 * Allocate and initialize a new local port bind bucket.
84998 * The bindhash mutex for snum's hash chain must be held here.
84999 @@ -540,6 +543,8 @@ ok:
85000 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
85001 spin_unlock(&head->lock);
85002
85003 + gr_update_task_in_ip_table(current, inet_sk(sk));
85004 +
85005 if (tw) {
85006 inet_twsk_deschedule(tw, death_row);
85007 while (twrefcnt) {
85008 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
85009 index 000e3d2..5472da3 100644
85010 --- a/net/ipv4/inetpeer.c
85011 +++ b/net/ipv4/inetpeer.c
85012 @@ -503,8 +503,8 @@ relookup:
85013 if (p) {
85014 p->daddr = *daddr;
85015 atomic_set(&p->refcnt, 1);
85016 - atomic_set(&p->rid, 0);
85017 - atomic_set(&p->ip_id_count,
85018 + atomic_set_unchecked(&p->rid, 0);
85019 + atomic_set_unchecked(&p->ip_id_count,
85020 (daddr->family == AF_INET) ?
85021 secure_ip_id(daddr->addr.a4) :
85022 secure_ipv6_id(daddr->addr.a6));
85023 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
85024 index eb9d63a..31c5372 100644
85025 --- a/net/ipv4/ip_fragment.c
85026 +++ b/net/ipv4/ip_fragment.c
85027 @@ -322,7 +322,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
85028 return 0;
85029
85030 start = qp->rid;
85031 - end = atomic_inc_return(&peer->rid);
85032 + end = atomic_inc_return_unchecked(&peer->rid);
85033 qp->rid = end;
85034
85035 rc = qp->q.fragments && (end - start) > max;
85036 @@ -789,12 +789,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
85037
85038 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85039 {
85040 - struct ctl_table *table;
85041 + ctl_table_no_const *table = NULL;
85042 struct ctl_table_header *hdr;
85043
85044 - table = ip4_frags_ns_ctl_table;
85045 if (!net_eq(net, &init_net)) {
85046 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85047 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
85048 if (table == NULL)
85049 goto err_alloc;
85050
85051 @@ -805,9 +804,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85052 /* Don't export sysctls to unprivileged users */
85053 if (net->user_ns != &init_user_ns)
85054 table[0].procname = NULL;
85055 - }
85056 + hdr = register_net_sysctl(net, "net/ipv4", table);
85057 + } else
85058 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
85059
85060 - hdr = register_net_sysctl(net, "net/ipv4", table);
85061 if (hdr == NULL)
85062 goto err_reg;
85063
85064 @@ -815,8 +815,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
85065 return 0;
85066
85067 err_reg:
85068 - if (!net_eq(net, &init_net))
85069 - kfree(table);
85070 + kfree(table);
85071 err_alloc:
85072 return -ENOMEM;
85073 }
85074 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
85075 index e81b1ca..6f3b5b9 100644
85076 --- a/net/ipv4/ip_gre.c
85077 +++ b/net/ipv4/ip_gre.c
85078 @@ -124,7 +124,7 @@ static bool log_ecn_error = true;
85079 module_param(log_ecn_error, bool, 0644);
85080 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
85081
85082 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
85083 +static struct rtnl_link_ops ipgre_link_ops;
85084 static int ipgre_tunnel_init(struct net_device *dev);
85085 static void ipgre_tunnel_setup(struct net_device *dev);
85086 static int ipgre_tunnel_bind_dev(struct net_device *dev);
85087 @@ -1756,7 +1756,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
85088 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
85089 };
85090
85091 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85092 +static struct rtnl_link_ops ipgre_link_ops = {
85093 .kind = "gre",
85094 .maxtype = IFLA_GRE_MAX,
85095 .policy = ipgre_policy,
85096 @@ -1769,7 +1769,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
85097 .fill_info = ipgre_fill_info,
85098 };
85099
85100 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
85101 +static struct rtnl_link_ops ipgre_tap_ops = {
85102 .kind = "gretap",
85103 .maxtype = IFLA_GRE_MAX,
85104 .policy = ipgre_policy,
85105 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
85106 index d9c4f11..02b82db 100644
85107 --- a/net/ipv4/ip_sockglue.c
85108 +++ b/net/ipv4/ip_sockglue.c
85109 @@ -1152,7 +1152,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85110 len = min_t(unsigned int, len, opt->optlen);
85111 if (put_user(len, optlen))
85112 return -EFAULT;
85113 - if (copy_to_user(optval, opt->__data, len))
85114 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
85115 + copy_to_user(optval, opt->__data, len))
85116 return -EFAULT;
85117 return 0;
85118 }
85119 @@ -1283,7 +1284,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
85120 if (sk->sk_type != SOCK_STREAM)
85121 return -ENOPROTOOPT;
85122
85123 - msg.msg_control = optval;
85124 + msg.msg_control = (void __force_kernel *)optval;
85125 msg.msg_controllen = len;
85126 msg.msg_flags = flags;
85127
85128 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
85129 index c3a4233..1412161 100644
85130 --- a/net/ipv4/ip_vti.c
85131 +++ b/net/ipv4/ip_vti.c
85132 @@ -47,7 +47,7 @@
85133 #define HASH_SIZE 16
85134 #define HASH(addr) (((__force u32)addr^((__force u32)addr>>4))&(HASH_SIZE-1))
85135
85136 -static struct rtnl_link_ops vti_link_ops __read_mostly;
85137 +static struct rtnl_link_ops vti_link_ops;
85138
85139 static int vti_net_id __read_mostly;
85140 struct vti_net {
85141 @@ -886,7 +886,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
85142 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
85143 };
85144
85145 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
85146 +static struct rtnl_link_ops vti_link_ops = {
85147 .kind = "vti",
85148 .maxtype = IFLA_VTI_MAX,
85149 .policy = vti_policy,
85150 diff --git a/net/ipv4/ipcomp.c b/net/ipv4/ipcomp.c
85151 index 9a46dae..5f793a0 100644
85152 --- a/net/ipv4/ipcomp.c
85153 +++ b/net/ipv4/ipcomp.c
85154 @@ -48,7 +48,7 @@ static void ipcomp4_err(struct sk_buff *skb, u32 info)
85155 return;
85156
85157 if (icmp_hdr(skb)->type == ICMP_DEST_UNREACH) {
85158 - atomic_inc(&flow_cache_genid);
85159 + atomic_inc_unchecked(&flow_cache_genid);
85160 rt_genid_bump(net);
85161
85162 ipv4_update_pmtu(skb, net, info, 0, 0, IPPROTO_COMP, 0);
85163 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
85164 index a2e50ae..e152b7c 100644
85165 --- a/net/ipv4/ipconfig.c
85166 +++ b/net/ipv4/ipconfig.c
85167 @@ -323,7 +323,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
85168
85169 mm_segment_t oldfs = get_fs();
85170 set_fs(get_ds());
85171 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85172 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85173 set_fs(oldfs);
85174 return res;
85175 }
85176 @@ -334,7 +334,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
85177
85178 mm_segment_t oldfs = get_fs();
85179 set_fs(get_ds());
85180 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
85181 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
85182 set_fs(oldfs);
85183 return res;
85184 }
85185 @@ -345,7 +345,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
85186
85187 mm_segment_t oldfs = get_fs();
85188 set_fs(get_ds());
85189 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
85190 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
85191 set_fs(oldfs);
85192 return res;
85193 }
85194 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
85195 index 191fc24..1b3b804 100644
85196 --- a/net/ipv4/ipip.c
85197 +++ b/net/ipv4/ipip.c
85198 @@ -138,7 +138,7 @@ struct ipip_net {
85199 static int ipip_tunnel_init(struct net_device *dev);
85200 static void ipip_tunnel_setup(struct net_device *dev);
85201 static void ipip_dev_free(struct net_device *dev);
85202 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
85203 +static struct rtnl_link_ops ipip_link_ops;
85204
85205 static struct rtnl_link_stats64 *ipip_get_stats64(struct net_device *dev,
85206 struct rtnl_link_stats64 *tot)
85207 @@ -972,7 +972,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
85208 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
85209 };
85210
85211 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
85212 +static struct rtnl_link_ops ipip_link_ops = {
85213 .kind = "ipip",
85214 .maxtype = IFLA_IPTUN_MAX,
85215 .policy = ipip_policy,
85216 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
85217 index 3ea4127..849297b 100644
85218 --- a/net/ipv4/netfilter/arp_tables.c
85219 +++ b/net/ipv4/netfilter/arp_tables.c
85220 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
85221 #endif
85222
85223 static int get_info(struct net *net, void __user *user,
85224 - const int *len, int compat)
85225 + int len, int compat)
85226 {
85227 char name[XT_TABLE_MAXNAMELEN];
85228 struct xt_table *t;
85229 int ret;
85230
85231 - if (*len != sizeof(struct arpt_getinfo)) {
85232 - duprintf("length %u != %Zu\n", *len,
85233 + if (len != sizeof(struct arpt_getinfo)) {
85234 + duprintf("length %u != %Zu\n", len,
85235 sizeof(struct arpt_getinfo));
85236 return -EINVAL;
85237 }
85238 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
85239 info.size = private->size;
85240 strcpy(info.name, name);
85241
85242 - if (copy_to_user(user, &info, *len) != 0)
85243 + if (copy_to_user(user, &info, len) != 0)
85244 ret = -EFAULT;
85245 else
85246 ret = 0;
85247 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
85248
85249 switch (cmd) {
85250 case ARPT_SO_GET_INFO:
85251 - ret = get_info(sock_net(sk), user, len, 1);
85252 + ret = get_info(sock_net(sk), user, *len, 1);
85253 break;
85254 case ARPT_SO_GET_ENTRIES:
85255 ret = compat_get_entries(sock_net(sk), user, len);
85256 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
85257
85258 switch (cmd) {
85259 case ARPT_SO_GET_INFO:
85260 - ret = get_info(sock_net(sk), user, len, 0);
85261 + ret = get_info(sock_net(sk), user, *len, 0);
85262 break;
85263
85264 case ARPT_SO_GET_ENTRIES:
85265 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
85266 index 17c5e06..1b91206 100644
85267 --- a/net/ipv4/netfilter/ip_tables.c
85268 +++ b/net/ipv4/netfilter/ip_tables.c
85269 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
85270 #endif
85271
85272 static int get_info(struct net *net, void __user *user,
85273 - const int *len, int compat)
85274 + int len, int compat)
85275 {
85276 char name[XT_TABLE_MAXNAMELEN];
85277 struct xt_table *t;
85278 int ret;
85279
85280 - if (*len != sizeof(struct ipt_getinfo)) {
85281 - duprintf("length %u != %zu\n", *len,
85282 + if (len != sizeof(struct ipt_getinfo)) {
85283 + duprintf("length %u != %zu\n", len,
85284 sizeof(struct ipt_getinfo));
85285 return -EINVAL;
85286 }
85287 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
85288 info.size = private->size;
85289 strcpy(info.name, name);
85290
85291 - if (copy_to_user(user, &info, *len) != 0)
85292 + if (copy_to_user(user, &info, len) != 0)
85293 ret = -EFAULT;
85294 else
85295 ret = 0;
85296 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85297
85298 switch (cmd) {
85299 case IPT_SO_GET_INFO:
85300 - ret = get_info(sock_net(sk), user, len, 1);
85301 + ret = get_info(sock_net(sk), user, *len, 1);
85302 break;
85303 case IPT_SO_GET_ENTRIES:
85304 ret = compat_get_entries(sock_net(sk), user, len);
85305 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
85306
85307 switch (cmd) {
85308 case IPT_SO_GET_INFO:
85309 - ret = get_info(sock_net(sk), user, len, 0);
85310 + ret = get_info(sock_net(sk), user, *len, 0);
85311 break;
85312
85313 case IPT_SO_GET_ENTRIES:
85314 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
85315 index dc454cc..5bb917f 100644
85316 --- a/net/ipv4/ping.c
85317 +++ b/net/ipv4/ping.c
85318 @@ -844,7 +844,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
85319 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
85320 0, sock_i_ino(sp),
85321 atomic_read(&sp->sk_refcnt), sp,
85322 - atomic_read(&sp->sk_drops), len);
85323 + atomic_read_unchecked(&sp->sk_drops), len);
85324 }
85325
85326 static int ping_seq_show(struct seq_file *seq, void *v)
85327 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
85328 index 6f08991..55867ad 100644
85329 --- a/net/ipv4/raw.c
85330 +++ b/net/ipv4/raw.c
85331 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
85332 int raw_rcv(struct sock *sk, struct sk_buff *skb)
85333 {
85334 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
85335 - atomic_inc(&sk->sk_drops);
85336 + atomic_inc_unchecked(&sk->sk_drops);
85337 kfree_skb(skb);
85338 return NET_RX_DROP;
85339 }
85340 @@ -747,16 +747,20 @@ static int raw_init(struct sock *sk)
85341
85342 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
85343 {
85344 + struct icmp_filter filter;
85345 +
85346 if (optlen > sizeof(struct icmp_filter))
85347 optlen = sizeof(struct icmp_filter);
85348 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
85349 + if (copy_from_user(&filter, optval, optlen))
85350 return -EFAULT;
85351 + raw_sk(sk)->filter = filter;
85352 return 0;
85353 }
85354
85355 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
85356 {
85357 int len, ret = -EFAULT;
85358 + struct icmp_filter filter;
85359
85360 if (get_user(len, optlen))
85361 goto out;
85362 @@ -766,8 +770,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
85363 if (len > sizeof(struct icmp_filter))
85364 len = sizeof(struct icmp_filter);
85365 ret = -EFAULT;
85366 - if (put_user(len, optlen) ||
85367 - copy_to_user(optval, &raw_sk(sk)->filter, len))
85368 + filter = raw_sk(sk)->filter;
85369 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
85370 goto out;
85371 ret = 0;
85372 out: return ret;
85373 @@ -998,7 +1002,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
85374 0, 0L, 0,
85375 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
85376 0, sock_i_ino(sp),
85377 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
85378 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
85379 }
85380
85381 static int raw_seq_show(struct seq_file *seq, void *v)
85382 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
85383 index a0fcc47..32e2c89 100644
85384 --- a/net/ipv4/route.c
85385 +++ b/net/ipv4/route.c
85386 @@ -2552,34 +2552,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
85387 .maxlen = sizeof(int),
85388 .mode = 0200,
85389 .proc_handler = ipv4_sysctl_rtcache_flush,
85390 + .extra1 = &init_net,
85391 },
85392 { },
85393 };
85394
85395 static __net_init int sysctl_route_net_init(struct net *net)
85396 {
85397 - struct ctl_table *tbl;
85398 + ctl_table_no_const *tbl = NULL;
85399
85400 - tbl = ipv4_route_flush_table;
85401 if (!net_eq(net, &init_net)) {
85402 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
85403 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
85404 if (tbl == NULL)
85405 goto err_dup;
85406
85407 /* Don't export sysctls to unprivileged users */
85408 if (net->user_ns != &init_user_ns)
85409 tbl[0].procname = NULL;
85410 - }
85411 - tbl[0].extra1 = net;
85412 + tbl[0].extra1 = net;
85413 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
85414 + } else
85415 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
85416
85417 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
85418 if (net->ipv4.route_hdr == NULL)
85419 goto err_reg;
85420 return 0;
85421
85422 err_reg:
85423 - if (tbl != ipv4_route_flush_table)
85424 - kfree(tbl);
85425 + kfree(tbl);
85426 err_dup:
85427 return -ENOMEM;
85428 }
85429 @@ -2602,7 +2602,7 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
85430
85431 static __net_init int rt_genid_init(struct net *net)
85432 {
85433 - atomic_set(&net->rt_genid, 0);
85434 + atomic_set_unchecked(&net->rt_genid, 0);
85435 get_random_bytes(&net->ipv4.dev_addr_genid,
85436 sizeof(net->ipv4.dev_addr_genid));
85437 return 0;
85438 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
85439 index d84400b..62e066e 100644
85440 --- a/net/ipv4/sysctl_net_ipv4.c
85441 +++ b/net/ipv4/sysctl_net_ipv4.c
85442 @@ -54,7 +54,7 @@ static int ipv4_local_port_range(ctl_table *table, int write,
85443 {
85444 int ret;
85445 int range[2];
85446 - ctl_table tmp = {
85447 + ctl_table_no_const tmp = {
85448 .data = &range,
85449 .maxlen = sizeof(range),
85450 .mode = table->mode,
85451 @@ -107,7 +107,7 @@ static int ipv4_ping_group_range(ctl_table *table, int write,
85452 int ret;
85453 gid_t urange[2];
85454 kgid_t low, high;
85455 - ctl_table tmp = {
85456 + ctl_table_no_const tmp = {
85457 .data = &urange,
85458 .maxlen = sizeof(urange),
85459 .mode = table->mode,
85460 @@ -138,7 +138,7 @@ static int proc_tcp_congestion_control(ctl_table *ctl, int write,
85461 void __user *buffer, size_t *lenp, loff_t *ppos)
85462 {
85463 char val[TCP_CA_NAME_MAX];
85464 - ctl_table tbl = {
85465 + ctl_table_no_const tbl = {
85466 .data = val,
85467 .maxlen = TCP_CA_NAME_MAX,
85468 };
85469 @@ -157,7 +157,7 @@ static int proc_tcp_available_congestion_control(ctl_table *ctl,
85470 void __user *buffer, size_t *lenp,
85471 loff_t *ppos)
85472 {
85473 - ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
85474 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
85475 int ret;
85476
85477 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
85478 @@ -174,7 +174,7 @@ static int proc_allowed_congestion_control(ctl_table *ctl,
85479 void __user *buffer, size_t *lenp,
85480 loff_t *ppos)
85481 {
85482 - ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
85483 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
85484 int ret;
85485
85486 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
85487 @@ -200,15 +200,17 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
85488 struct mem_cgroup *memcg;
85489 #endif
85490
85491 - ctl_table tmp = {
85492 + ctl_table_no_const tmp = {
85493 .data = &vec,
85494 .maxlen = sizeof(vec),
85495 .mode = ctl->mode,
85496 };
85497
85498 if (!write) {
85499 - ctl->data = &net->ipv4.sysctl_tcp_mem;
85500 - return proc_doulongvec_minmax(ctl, write, buffer, lenp, ppos);
85501 + ctl_table_no_const tcp_mem = *ctl;
85502 +
85503 + tcp_mem.data = &net->ipv4.sysctl_tcp_mem;
85504 + return proc_doulongvec_minmax(&tcp_mem, write, buffer, lenp, ppos);
85505 }
85506
85507 ret = proc_doulongvec_minmax(&tmp, write, buffer, lenp, ppos);
85508 @@ -235,7 +237,7 @@ static int ipv4_tcp_mem(ctl_table *ctl, int write,
85509 int proc_tcp_fastopen_key(ctl_table *ctl, int write, void __user *buffer,
85510 size_t *lenp, loff_t *ppos)
85511 {
85512 - ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
85513 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
85514 struct tcp_fastopen_context *ctxt;
85515 int ret;
85516 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
85517 @@ -476,7 +478,7 @@ static struct ctl_table ipv4_table[] = {
85518 },
85519 {
85520 .procname = "ip_local_reserved_ports",
85521 - .data = NULL, /* initialized in sysctl_ipv4_init */
85522 + .data = sysctl_local_reserved_ports,
85523 .maxlen = 65536,
85524 .mode = 0644,
85525 .proc_handler = proc_do_large_bitmap,
85526 @@ -860,11 +862,10 @@ static struct ctl_table ipv4_net_table[] = {
85527
85528 static __net_init int ipv4_sysctl_init_net(struct net *net)
85529 {
85530 - struct ctl_table *table;
85531 + ctl_table_no_const *table = NULL;
85532
85533 - table = ipv4_net_table;
85534 if (!net_eq(net, &init_net)) {
85535 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
85536 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
85537 if (table == NULL)
85538 goto err_alloc;
85539
85540 @@ -897,15 +898,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
85541
85542 tcp_init_mem(net);
85543
85544 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
85545 + if (!net_eq(net, &init_net))
85546 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
85547 + else
85548 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
85549 if (net->ipv4.ipv4_hdr == NULL)
85550 goto err_reg;
85551
85552 return 0;
85553
85554 err_reg:
85555 - if (!net_eq(net, &init_net))
85556 - kfree(table);
85557 + kfree(table);
85558 err_alloc:
85559 return -ENOMEM;
85560 }
85561 @@ -927,16 +930,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
85562 static __init int sysctl_ipv4_init(void)
85563 {
85564 struct ctl_table_header *hdr;
85565 - struct ctl_table *i;
85566 -
85567 - for (i = ipv4_table; i->procname; i++) {
85568 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
85569 - i->data = sysctl_local_reserved_ports;
85570 - break;
85571 - }
85572 - }
85573 - if (!i->procname)
85574 - return -EINVAL;
85575
85576 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
85577 if (hdr == NULL)
85578 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
85579 index ad70a96..50cb55b 100644
85580 --- a/net/ipv4/tcp_input.c
85581 +++ b/net/ipv4/tcp_input.c
85582 @@ -4733,7 +4733,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
85583 * simplifies code)
85584 */
85585 static void
85586 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
85587 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
85588 struct sk_buff *head, struct sk_buff *tail,
85589 u32 start, u32 end)
85590 {
85591 @@ -5850,6 +5850,7 @@ discard:
85592 tcp_paws_reject(&tp->rx_opt, 0))
85593 goto discard_and_undo;
85594
85595 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
85596 if (th->syn) {
85597 /* We see SYN without ACK. It is attempt of
85598 * simultaneous connect with crossed SYNs.
85599 @@ -5900,6 +5901,7 @@ discard:
85600 goto discard;
85601 #endif
85602 }
85603 +#endif
85604 /* "fifth, if neither of the SYN or RST bits is set then
85605 * drop the segment and return."
85606 */
85607 @@ -5944,7 +5946,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
85608 goto discard;
85609
85610 if (th->syn) {
85611 - if (th->fin)
85612 + if (th->fin || th->urg || th->psh)
85613 goto discard;
85614 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
85615 return 1;
85616 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
85617 index eadb693..e8f7251 100644
85618 --- a/net/ipv4/tcp_ipv4.c
85619 +++ b/net/ipv4/tcp_ipv4.c
85620 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
85621 EXPORT_SYMBOL(sysctl_tcp_low_latency);
85622
85623
85624 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85625 +extern int grsec_enable_blackhole;
85626 +#endif
85627 +
85628 #ifdef CONFIG_TCP_MD5SIG
85629 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
85630 __be32 daddr, __be32 saddr, const struct tcphdr *th);
85631 @@ -1895,6 +1899,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
85632 return 0;
85633
85634 reset:
85635 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85636 + if (!grsec_enable_blackhole)
85637 +#endif
85638 tcp_v4_send_reset(rsk, skb);
85639 discard:
85640 kfree_skb(skb);
85641 @@ -1994,12 +2001,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
85642 TCP_SKB_CB(skb)->sacked = 0;
85643
85644 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
85645 - if (!sk)
85646 + if (!sk) {
85647 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85648 + ret = 1;
85649 +#endif
85650 goto no_tcp_socket;
85651 -
85652 + }
85653 process:
85654 - if (sk->sk_state == TCP_TIME_WAIT)
85655 + if (sk->sk_state == TCP_TIME_WAIT) {
85656 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85657 + ret = 2;
85658 +#endif
85659 goto do_time_wait;
85660 + }
85661
85662 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
85663 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
85664 @@ -2050,6 +2064,10 @@ no_tcp_socket:
85665 bad_packet:
85666 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
85667 } else {
85668 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85669 + if (!grsec_enable_blackhole || (ret == 1 &&
85670 + (skb->dev->flags & IFF_LOOPBACK)))
85671 +#endif
85672 tcp_v4_send_reset(NULL, skb);
85673 }
85674
85675 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
85676 index f35f2df..ccb5ca6 100644
85677 --- a/net/ipv4/tcp_minisocks.c
85678 +++ b/net/ipv4/tcp_minisocks.c
85679 @@ -27,6 +27,10 @@
85680 #include <net/inet_common.h>
85681 #include <net/xfrm.h>
85682
85683 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85684 +extern int grsec_enable_blackhole;
85685 +#endif
85686 +
85687 int sysctl_tcp_syncookies __read_mostly = 1;
85688 EXPORT_SYMBOL(sysctl_tcp_syncookies);
85689
85690 @@ -742,7 +746,10 @@ embryonic_reset:
85691 * avoid becoming vulnerable to outside attack aiming at
85692 * resetting legit local connections.
85693 */
85694 - req->rsk_ops->send_reset(sk, skb);
85695 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85696 + if (!grsec_enable_blackhole)
85697 +#endif
85698 + req->rsk_ops->send_reset(sk, skb);
85699 } else if (fastopen) { /* received a valid RST pkt */
85700 reqsk_fastopen_remove(sk, req, true);
85701 tcp_reset(sk);
85702 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
85703 index 4526fe6..1a34e43 100644
85704 --- a/net/ipv4/tcp_probe.c
85705 +++ b/net/ipv4/tcp_probe.c
85706 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
85707 if (cnt + width >= len)
85708 break;
85709
85710 - if (copy_to_user(buf + cnt, tbuf, width))
85711 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
85712 return -EFAULT;
85713 cnt += width;
85714 }
85715 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
85716 index b78aac3..e18230b 100644
85717 --- a/net/ipv4/tcp_timer.c
85718 +++ b/net/ipv4/tcp_timer.c
85719 @@ -22,6 +22,10 @@
85720 #include <linux/gfp.h>
85721 #include <net/tcp.h>
85722
85723 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85724 +extern int grsec_lastack_retries;
85725 +#endif
85726 +
85727 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
85728 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
85729 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
85730 @@ -185,6 +189,13 @@ static int tcp_write_timeout(struct sock *sk)
85731 }
85732 }
85733
85734 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85735 + if ((sk->sk_state == TCP_LAST_ACK) &&
85736 + (grsec_lastack_retries > 0) &&
85737 + (grsec_lastack_retries < retry_until))
85738 + retry_until = grsec_lastack_retries;
85739 +#endif
85740 +
85741 if (retransmits_timed_out(sk, retry_until,
85742 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
85743 /* Has it gone just too far? */
85744 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
85745 index 1f4d405..3524677 100644
85746 --- a/net/ipv4/udp.c
85747 +++ b/net/ipv4/udp.c
85748 @@ -87,6 +87,7 @@
85749 #include <linux/types.h>
85750 #include <linux/fcntl.h>
85751 #include <linux/module.h>
85752 +#include <linux/security.h>
85753 #include <linux/socket.h>
85754 #include <linux/sockios.h>
85755 #include <linux/igmp.h>
85756 @@ -111,6 +112,10 @@
85757 #include <trace/events/skb.h>
85758 #include "udp_impl.h"
85759
85760 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85761 +extern int grsec_enable_blackhole;
85762 +#endif
85763 +
85764 struct udp_table udp_table __read_mostly;
85765 EXPORT_SYMBOL(udp_table);
85766
85767 @@ -569,6 +574,9 @@ found:
85768 return s;
85769 }
85770
85771 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
85772 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
85773 +
85774 /*
85775 * This routine is called by the ICMP module when it gets some
85776 * sort of error condition. If err < 0 then the socket should
85777 @@ -864,9 +872,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
85778 dport = usin->sin_port;
85779 if (dport == 0)
85780 return -EINVAL;
85781 +
85782 + err = gr_search_udp_sendmsg(sk, usin);
85783 + if (err)
85784 + return err;
85785 } else {
85786 if (sk->sk_state != TCP_ESTABLISHED)
85787 return -EDESTADDRREQ;
85788 +
85789 + err = gr_search_udp_sendmsg(sk, NULL);
85790 + if (err)
85791 + return err;
85792 +
85793 daddr = inet->inet_daddr;
85794 dport = inet->inet_dport;
85795 /* Open fast path for connected socket.
85796 @@ -1108,7 +1125,7 @@ static unsigned int first_packet_length(struct sock *sk)
85797 udp_lib_checksum_complete(skb)) {
85798 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
85799 IS_UDPLITE(sk));
85800 - atomic_inc(&sk->sk_drops);
85801 + atomic_inc_unchecked(&sk->sk_drops);
85802 __skb_unlink(skb, rcvq);
85803 __skb_queue_tail(&list_kill, skb);
85804 }
85805 @@ -1194,6 +1211,10 @@ try_again:
85806 if (!skb)
85807 goto out;
85808
85809 + err = gr_search_udp_recvmsg(sk, skb);
85810 + if (err)
85811 + goto out_free;
85812 +
85813 ulen = skb->len - sizeof(struct udphdr);
85814 copied = len;
85815 if (copied > ulen)
85816 @@ -1227,7 +1248,7 @@ try_again:
85817 if (unlikely(err)) {
85818 trace_kfree_skb(skb, udp_recvmsg);
85819 if (!peeked) {
85820 - atomic_inc(&sk->sk_drops);
85821 + atomic_inc_unchecked(&sk->sk_drops);
85822 UDP_INC_STATS_USER(sock_net(sk),
85823 UDP_MIB_INERRORS, is_udplite);
85824 }
85825 @@ -1510,7 +1531,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
85826
85827 drop:
85828 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
85829 - atomic_inc(&sk->sk_drops);
85830 + atomic_inc_unchecked(&sk->sk_drops);
85831 kfree_skb(skb);
85832 return -1;
85833 }
85834 @@ -1529,7 +1550,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
85835 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
85836
85837 if (!skb1) {
85838 - atomic_inc(&sk->sk_drops);
85839 + atomic_inc_unchecked(&sk->sk_drops);
85840 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
85841 IS_UDPLITE(sk));
85842 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
85843 @@ -1698,6 +1719,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
85844 goto csum_error;
85845
85846 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
85847 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
85848 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
85849 +#endif
85850 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
85851
85852 /*
85853 @@ -2120,7 +2144,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
85854 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
85855 0, sock_i_ino(sp),
85856 atomic_read(&sp->sk_refcnt), sp,
85857 - atomic_read(&sp->sk_drops), len);
85858 + atomic_read_unchecked(&sp->sk_drops), len);
85859 }
85860
85861 int udp4_seq_show(struct seq_file *seq, void *v)
85862 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
85863 index 1b5d8cb..ffb0833 100644
85864 --- a/net/ipv6/addrconf.c
85865 +++ b/net/ipv6/addrconf.c
85866 @@ -2272,7 +2272,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
85867 p.iph.ihl = 5;
85868 p.iph.protocol = IPPROTO_IPV6;
85869 p.iph.ttl = 64;
85870 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
85871 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
85872
85873 if (ops->ndo_do_ioctl) {
85874 mm_segment_t oldfs = get_fs();
85875 @@ -4388,7 +4388,7 @@ int addrconf_sysctl_forward(ctl_table *ctl, int write,
85876 int *valp = ctl->data;
85877 int val = *valp;
85878 loff_t pos = *ppos;
85879 - ctl_table lctl;
85880 + ctl_table_no_const lctl;
85881 int ret;
85882
85883 /*
85884 @@ -4470,7 +4470,7 @@ int addrconf_sysctl_disable(ctl_table *ctl, int write,
85885 int *valp = ctl->data;
85886 int val = *valp;
85887 loff_t pos = *ppos;
85888 - ctl_table lctl;
85889 + ctl_table_no_const lctl;
85890 int ret;
85891
85892 /*
85893 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
85894 index fff5bdd..15194fb 100644
85895 --- a/net/ipv6/icmp.c
85896 +++ b/net/ipv6/icmp.c
85897 @@ -973,7 +973,7 @@ ctl_table ipv6_icmp_table_template[] = {
85898
85899 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
85900 {
85901 - struct ctl_table *table;
85902 + ctl_table_no_const *table;
85903
85904 table = kmemdup(ipv6_icmp_table_template,
85905 sizeof(ipv6_icmp_table_template),
85906 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
85907 index 131dd09..f7ed64f 100644
85908 --- a/net/ipv6/ip6_gre.c
85909 +++ b/net/ipv6/ip6_gre.c
85910 @@ -73,7 +73,7 @@ struct ip6gre_net {
85911 struct net_device *fb_tunnel_dev;
85912 };
85913
85914 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
85915 +static struct rtnl_link_ops ip6gre_link_ops;
85916 static int ip6gre_tunnel_init(struct net_device *dev);
85917 static void ip6gre_tunnel_setup(struct net_device *dev);
85918 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
85919 @@ -1337,7 +1337,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
85920 }
85921
85922
85923 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
85924 +static struct inet6_protocol ip6gre_protocol = {
85925 .handler = ip6gre_rcv,
85926 .err_handler = ip6gre_err,
85927 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
85928 @@ -1671,7 +1671,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
85929 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
85930 };
85931
85932 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
85933 +static struct rtnl_link_ops ip6gre_link_ops = {
85934 .kind = "ip6gre",
85935 .maxtype = IFLA_GRE_MAX,
85936 .policy = ip6gre_policy,
85937 @@ -1684,7 +1684,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
85938 .fill_info = ip6gre_fill_info,
85939 };
85940
85941 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
85942 +static struct rtnl_link_ops ip6gre_tap_ops = {
85943 .kind = "ip6gretap",
85944 .maxtype = IFLA_GRE_MAX,
85945 .policy = ip6gre_policy,
85946 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
85947 index a14f28b..b4b8956 100644
85948 --- a/net/ipv6/ip6_tunnel.c
85949 +++ b/net/ipv6/ip6_tunnel.c
85950 @@ -87,7 +87,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
85951
85952 static int ip6_tnl_dev_init(struct net_device *dev);
85953 static void ip6_tnl_dev_setup(struct net_device *dev);
85954 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
85955 +static struct rtnl_link_ops ip6_link_ops;
85956
85957 static int ip6_tnl_net_id __read_mostly;
85958 struct ip6_tnl_net {
85959 @@ -1686,7 +1686,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
85960 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
85961 };
85962
85963 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
85964 +static struct rtnl_link_ops ip6_link_ops = {
85965 .kind = "ip6tnl",
85966 .maxtype = IFLA_IPTUN_MAX,
85967 .policy = ip6_tnl_policy,
85968 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
85969 index d1e2e8e..51c19ae 100644
85970 --- a/net/ipv6/ipv6_sockglue.c
85971 +++ b/net/ipv6/ipv6_sockglue.c
85972 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
85973 if (sk->sk_type != SOCK_STREAM)
85974 return -ENOPROTOOPT;
85975
85976 - msg.msg_control = optval;
85977 + msg.msg_control = (void __force_kernel *)optval;
85978 msg.msg_controllen = len;
85979 msg.msg_flags = flags;
85980
85981 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
85982 index 125a90d..2a11f36 100644
85983 --- a/net/ipv6/netfilter/ip6_tables.c
85984 +++ b/net/ipv6/netfilter/ip6_tables.c
85985 @@ -1076,14 +1076,14 @@ static int compat_table_info(const struct xt_table_info *info,
85986 #endif
85987
85988 static int get_info(struct net *net, void __user *user,
85989 - const int *len, int compat)
85990 + int len, int compat)
85991 {
85992 char name[XT_TABLE_MAXNAMELEN];
85993 struct xt_table *t;
85994 int ret;
85995
85996 - if (*len != sizeof(struct ip6t_getinfo)) {
85997 - duprintf("length %u != %zu\n", *len,
85998 + if (len != sizeof(struct ip6t_getinfo)) {
85999 + duprintf("length %u != %zu\n", len,
86000 sizeof(struct ip6t_getinfo));
86001 return -EINVAL;
86002 }
86003 @@ -1120,7 +1120,7 @@ static int get_info(struct net *net, void __user *user,
86004 info.size = private->size;
86005 strcpy(info.name, name);
86006
86007 - if (copy_to_user(user, &info, *len) != 0)
86008 + if (copy_to_user(user, &info, len) != 0)
86009 ret = -EFAULT;
86010 else
86011 ret = 0;
86012 @@ -1974,7 +1974,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86013
86014 switch (cmd) {
86015 case IP6T_SO_GET_INFO:
86016 - ret = get_info(sock_net(sk), user, len, 1);
86017 + ret = get_info(sock_net(sk), user, *len, 1);
86018 break;
86019 case IP6T_SO_GET_ENTRIES:
86020 ret = compat_get_entries(sock_net(sk), user, len);
86021 @@ -2021,7 +2021,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
86022
86023 switch (cmd) {
86024 case IP6T_SO_GET_INFO:
86025 - ret = get_info(sock_net(sk), user, len, 0);
86026 + ret = get_info(sock_net(sk), user, *len, 0);
86027 break;
86028
86029 case IP6T_SO_GET_ENTRIES:
86030 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
86031 index 3dacecc..2939087 100644
86032 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
86033 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
86034 @@ -87,12 +87,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
86035
86036 static int nf_ct_frag6_sysctl_register(struct net *net)
86037 {
86038 - struct ctl_table *table;
86039 + ctl_table_no_const *table = NULL;
86040 struct ctl_table_header *hdr;
86041
86042 - table = nf_ct_frag6_sysctl_table;
86043 if (!net_eq(net, &init_net)) {
86044 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
86045 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
86046 GFP_KERNEL);
86047 if (table == NULL)
86048 goto err_alloc;
86049 @@ -100,9 +99,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86050 table[0].data = &net->ipv6.frags.high_thresh;
86051 table[1].data = &net->ipv6.frags.low_thresh;
86052 table[2].data = &net->ipv6.frags.timeout;
86053 - }
86054 -
86055 - hdr = register_net_sysctl(net, "net/netfilter", table);
86056 + hdr = register_net_sysctl(net, "net/netfilter", table);
86057 + } else
86058 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
86059 if (hdr == NULL)
86060 goto err_reg;
86061
86062 @@ -110,8 +109,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
86063 return 0;
86064
86065 err_reg:
86066 - if (!net_eq(net, &init_net))
86067 - kfree(table);
86068 + kfree(table);
86069 err_alloc:
86070 return -ENOMEM;
86071 }
86072 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
86073 index 70fa814..d70c28c 100644
86074 --- a/net/ipv6/raw.c
86075 +++ b/net/ipv6/raw.c
86076 @@ -379,7 +379,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
86077 {
86078 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
86079 skb_checksum_complete(skb)) {
86080 - atomic_inc(&sk->sk_drops);
86081 + atomic_inc_unchecked(&sk->sk_drops);
86082 kfree_skb(skb);
86083 return NET_RX_DROP;
86084 }
86085 @@ -407,7 +407,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86086 struct raw6_sock *rp = raw6_sk(sk);
86087
86088 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
86089 - atomic_inc(&sk->sk_drops);
86090 + atomic_inc_unchecked(&sk->sk_drops);
86091 kfree_skb(skb);
86092 return NET_RX_DROP;
86093 }
86094 @@ -431,7 +431,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
86095
86096 if (inet->hdrincl) {
86097 if (skb_checksum_complete(skb)) {
86098 - atomic_inc(&sk->sk_drops);
86099 + atomic_inc_unchecked(&sk->sk_drops);
86100 kfree_skb(skb);
86101 return NET_RX_DROP;
86102 }
86103 @@ -604,7 +604,7 @@ out:
86104 return err;
86105 }
86106
86107 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
86108 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
86109 struct flowi6 *fl6, struct dst_entry **dstp,
86110 unsigned int flags)
86111 {
86112 @@ -916,12 +916,15 @@ do_confirm:
86113 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
86114 char __user *optval, int optlen)
86115 {
86116 + struct icmp6_filter filter;
86117 +
86118 switch (optname) {
86119 case ICMPV6_FILTER:
86120 if (optlen > sizeof(struct icmp6_filter))
86121 optlen = sizeof(struct icmp6_filter);
86122 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
86123 + if (copy_from_user(&filter, optval, optlen))
86124 return -EFAULT;
86125 + raw6_sk(sk)->filter = filter;
86126 return 0;
86127 default:
86128 return -ENOPROTOOPT;
86129 @@ -934,6 +937,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86130 char __user *optval, int __user *optlen)
86131 {
86132 int len;
86133 + struct icmp6_filter filter;
86134
86135 switch (optname) {
86136 case ICMPV6_FILTER:
86137 @@ -945,7 +949,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
86138 len = sizeof(struct icmp6_filter);
86139 if (put_user(len, optlen))
86140 return -EFAULT;
86141 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
86142 + filter = raw6_sk(sk)->filter;
86143 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
86144 return -EFAULT;
86145 return 0;
86146 default:
86147 @@ -1253,7 +1258,7 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
86148 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
86149 0,
86150 sock_i_ino(sp),
86151 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
86152 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
86153 }
86154
86155 static int raw6_seq_show(struct seq_file *seq, void *v)
86156 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
86157 index e5253ec..0410257 100644
86158 --- a/net/ipv6/reassembly.c
86159 +++ b/net/ipv6/reassembly.c
86160 @@ -604,12 +604,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
86161
86162 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86163 {
86164 - struct ctl_table *table;
86165 + ctl_table_no_const *table = NULL;
86166 struct ctl_table_header *hdr;
86167
86168 - table = ip6_frags_ns_ctl_table;
86169 if (!net_eq(net, &init_net)) {
86170 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86171 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
86172 if (table == NULL)
86173 goto err_alloc;
86174
86175 @@ -620,9 +619,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86176 /* Don't export sysctls to unprivileged users */
86177 if (net->user_ns != &init_user_ns)
86178 table[0].procname = NULL;
86179 - }
86180 + hdr = register_net_sysctl(net, "net/ipv6", table);
86181 + } else
86182 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
86183
86184 - hdr = register_net_sysctl(net, "net/ipv6", table);
86185 if (hdr == NULL)
86186 goto err_reg;
86187
86188 @@ -630,8 +630,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
86189 return 0;
86190
86191 err_reg:
86192 - if (!net_eq(net, &init_net))
86193 - kfree(table);
86194 + kfree(table);
86195 err_alloc:
86196 return -ENOMEM;
86197 }
86198 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
86199 index 6f9f7b6..2306d63 100644
86200 --- a/net/ipv6/route.c
86201 +++ b/net/ipv6/route.c
86202 @@ -2965,7 +2965,7 @@ ctl_table ipv6_route_table_template[] = {
86203
86204 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
86205 {
86206 - struct ctl_table *table;
86207 + ctl_table_no_const *table;
86208
86209 table = kmemdup(ipv6_route_table_template,
86210 sizeof(ipv6_route_table_template),
86211 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
86212 index cfba99b..20ca511 100644
86213 --- a/net/ipv6/sit.c
86214 +++ b/net/ipv6/sit.c
86215 @@ -72,7 +72,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
86216 static int ipip6_tunnel_init(struct net_device *dev);
86217 static void ipip6_tunnel_setup(struct net_device *dev);
86218 static void ipip6_dev_free(struct net_device *dev);
86219 -static struct rtnl_link_ops sit_link_ops __read_mostly;
86220 +static struct rtnl_link_ops sit_link_ops;
86221
86222 static int sit_net_id __read_mostly;
86223 struct sit_net {
86224 @@ -1463,7 +1463,7 @@ static const struct nla_policy ipip6_policy[IFLA_IPTUN_MAX + 1] = {
86225 #endif
86226 };
86227
86228 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
86229 +static struct rtnl_link_ops sit_link_ops = {
86230 .kind = "sit",
86231 .maxtype = IFLA_IPTUN_MAX,
86232 .policy = ipip6_policy,
86233 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
86234 index e85c48b..b8268d3 100644
86235 --- a/net/ipv6/sysctl_net_ipv6.c
86236 +++ b/net/ipv6/sysctl_net_ipv6.c
86237 @@ -40,7 +40,7 @@ static ctl_table ipv6_rotable[] = {
86238
86239 static int __net_init ipv6_sysctl_net_init(struct net *net)
86240 {
86241 - struct ctl_table *ipv6_table;
86242 + ctl_table_no_const *ipv6_table;
86243 struct ctl_table *ipv6_route_table;
86244 struct ctl_table *ipv6_icmp_table;
86245 int err;
86246 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
86247 index 4f435371..5de9da7 100644
86248 --- a/net/ipv6/tcp_ipv6.c
86249 +++ b/net/ipv6/tcp_ipv6.c
86250 @@ -103,6 +103,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
86251 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
86252 }
86253
86254 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86255 +extern int grsec_enable_blackhole;
86256 +#endif
86257 +
86258 static void tcp_v6_hash(struct sock *sk)
86259 {
86260 if (sk->sk_state != TCP_CLOSE) {
86261 @@ -1433,6 +1437,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
86262 return 0;
86263
86264 reset:
86265 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86266 + if (!grsec_enable_blackhole)
86267 +#endif
86268 tcp_v6_send_reset(sk, skb);
86269 discard:
86270 if (opt_skb)
86271 @@ -1514,12 +1521,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
86272 TCP_SKB_CB(skb)->sacked = 0;
86273
86274 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
86275 - if (!sk)
86276 + if (!sk) {
86277 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86278 + ret = 1;
86279 +#endif
86280 goto no_tcp_socket;
86281 + }
86282
86283 process:
86284 - if (sk->sk_state == TCP_TIME_WAIT)
86285 + if (sk->sk_state == TCP_TIME_WAIT) {
86286 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86287 + ret = 2;
86288 +#endif
86289 goto do_time_wait;
86290 + }
86291
86292 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
86293 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
86294 @@ -1568,6 +1583,10 @@ no_tcp_socket:
86295 bad_packet:
86296 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
86297 } else {
86298 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86299 + if (!grsec_enable_blackhole || (ret == 1 &&
86300 + (skb->dev->flags & IFF_LOOPBACK)))
86301 +#endif
86302 tcp_v6_send_reset(NULL, skb);
86303 }
86304
86305 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
86306 index fb08329..2d6919e 100644
86307 --- a/net/ipv6/udp.c
86308 +++ b/net/ipv6/udp.c
86309 @@ -51,6 +51,10 @@
86310 #include <trace/events/skb.h>
86311 #include "udp_impl.h"
86312
86313 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86314 +extern int grsec_enable_blackhole;
86315 +#endif
86316 +
86317 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
86318 {
86319 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
86320 @@ -395,7 +399,7 @@ try_again:
86321 if (unlikely(err)) {
86322 trace_kfree_skb(skb, udpv6_recvmsg);
86323 if (!peeked) {
86324 - atomic_inc(&sk->sk_drops);
86325 + atomic_inc_unchecked(&sk->sk_drops);
86326 if (is_udp4)
86327 UDP_INC_STATS_USER(sock_net(sk),
86328 UDP_MIB_INERRORS,
86329 @@ -633,7 +637,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
86330 return rc;
86331 drop:
86332 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
86333 - atomic_inc(&sk->sk_drops);
86334 + atomic_inc_unchecked(&sk->sk_drops);
86335 kfree_skb(skb);
86336 return -1;
86337 }
86338 @@ -691,7 +695,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
86339 if (likely(skb1 == NULL))
86340 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
86341 if (!skb1) {
86342 - atomic_inc(&sk->sk_drops);
86343 + atomic_inc_unchecked(&sk->sk_drops);
86344 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
86345 IS_UDPLITE(sk));
86346 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
86347 @@ -862,6 +866,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
86348 goto discard;
86349
86350 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
86351 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
86352 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
86353 +#endif
86354 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
86355
86356 kfree_skb(skb);
86357 @@ -1379,7 +1386,7 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
86358 0,
86359 sock_i_ino(sp),
86360 atomic_read(&sp->sk_refcnt), sp,
86361 - atomic_read(&sp->sk_drops));
86362 + atomic_read_unchecked(&sp->sk_drops));
86363 }
86364
86365 int udp6_seq_show(struct seq_file *seq, void *v)
86366 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
86367 index a68c88c..d55b0c5 100644
86368 --- a/net/irda/ircomm/ircomm_tty.c
86369 +++ b/net/irda/ircomm/ircomm_tty.c
86370 @@ -312,12 +312,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86371 add_wait_queue(&port->open_wait, &wait);
86372
86373 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
86374 - __FILE__, __LINE__, tty->driver->name, port->count);
86375 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86376
86377 spin_lock_irqsave(&port->lock, flags);
86378 if (!tty_hung_up_p(filp)) {
86379 extra_count = 1;
86380 - port->count--;
86381 + atomic_dec(&port->count);
86382 }
86383 spin_unlock_irqrestore(&port->lock, flags);
86384 port->blocked_open++;
86385 @@ -353,7 +353,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86386 }
86387
86388 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
86389 - __FILE__, __LINE__, tty->driver->name, port->count);
86390 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86391
86392 schedule();
86393 }
86394 @@ -364,13 +364,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
86395 if (extra_count) {
86396 /* ++ is not atomic, so this should be protected - Jean II */
86397 spin_lock_irqsave(&port->lock, flags);
86398 - port->count++;
86399 + atomic_inc(&port->count);
86400 spin_unlock_irqrestore(&port->lock, flags);
86401 }
86402 port->blocked_open--;
86403
86404 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
86405 - __FILE__, __LINE__, tty->driver->name, port->count);
86406 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
86407
86408 if (!retval)
86409 port->flags |= ASYNC_NORMAL_ACTIVE;
86410 @@ -444,12 +444,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
86411
86412 /* ++ is not atomic, so this should be protected - Jean II */
86413 spin_lock_irqsave(&self->port.lock, flags);
86414 - self->port.count++;
86415 + atomic_inc(&self->port.count);
86416 spin_unlock_irqrestore(&self->port.lock, flags);
86417 tty_port_tty_set(&self->port, tty);
86418
86419 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
86420 - self->line, self->port.count);
86421 + self->line, atomic_read(&self->port.count));
86422
86423 /* Not really used by us, but lets do it anyway */
86424 tty->low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
86425 @@ -986,7 +986,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
86426 tty_kref_put(port->tty);
86427 }
86428 port->tty = NULL;
86429 - port->count = 0;
86430 + atomic_set(&port->count, 0);
86431 spin_unlock_irqrestore(&port->lock, flags);
86432
86433 wake_up_interruptible(&port->open_wait);
86434 @@ -1343,7 +1343,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
86435 seq_putc(m, '\n');
86436
86437 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
86438 - seq_printf(m, "Open count: %d\n", self->port.count);
86439 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
86440 seq_printf(m, "Max data size: %d\n", self->max_data_size);
86441 seq_printf(m, "Max header size: %d\n", self->max_header_size);
86442
86443 diff --git a/net/irda/iriap.c b/net/irda/iriap.c
86444 index e71e85b..29340a9 100644
86445 --- a/net/irda/iriap.c
86446 +++ b/net/irda/iriap.c
86447 @@ -495,8 +495,11 @@ static void iriap_getvaluebyclass_confirm(struct iriap_cb *self,
86448 /* case CS_ISO_8859_9: */
86449 /* case CS_UNICODE: */
86450 default:
86451 - IRDA_DEBUG(0, "%s(), charset %s, not supported\n",
86452 - __func__, ias_charset_types[charset]);
86453 + IRDA_DEBUG(0, "%s(), charset [%d] %s, not supported\n",
86454 + __func__, charset,
86455 + charset < ARRAY_SIZE(ias_charset_types) ?
86456 + ias_charset_types[charset] :
86457 + "(unknown)");
86458
86459 /* Aborting, close connection! */
86460 iriap_disconnect_request(self);
86461 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
86462 index cd6f7a9..e63fe89 100644
86463 --- a/net/iucv/af_iucv.c
86464 +++ b/net/iucv/af_iucv.c
86465 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
86466
86467 write_lock_bh(&iucv_sk_list.lock);
86468
86469 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
86470 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
86471 while (__iucv_get_sock_by_name(name)) {
86472 sprintf(name, "%08x",
86473 - atomic_inc_return(&iucv_sk_list.autobind_name));
86474 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
86475 }
86476
86477 write_unlock_bh(&iucv_sk_list.lock);
86478 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
86479 index df08250..02021fe 100644
86480 --- a/net/iucv/iucv.c
86481 +++ b/net/iucv/iucv.c
86482 @@ -690,7 +690,7 @@ static int __cpuinit iucv_cpu_notify(struct notifier_block *self,
86483 return NOTIFY_OK;
86484 }
86485
86486 -static struct notifier_block __refdata iucv_cpu_notifier = {
86487 +static struct notifier_block iucv_cpu_notifier = {
86488 .notifier_call = iucv_cpu_notify,
86489 };
86490
86491 diff --git a/net/key/af_key.c b/net/key/af_key.c
86492 index 5b426a6..970032b 100644
86493 --- a/net/key/af_key.c
86494 +++ b/net/key/af_key.c
86495 @@ -3019,10 +3019,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
86496 static u32 get_acqseq(void)
86497 {
86498 u32 res;
86499 - static atomic_t acqseq;
86500 + static atomic_unchecked_t acqseq;
86501
86502 do {
86503 - res = atomic_inc_return(&acqseq);
86504 + res = atomic_inc_return_unchecked(&acqseq);
86505 } while (!res);
86506 return res;
86507 }
86508 diff --git a/net/l2tp/l2tp_ppp.c b/net/l2tp/l2tp_ppp.c
86509 index 716605c..044e9e1 100644
86510 --- a/net/l2tp/l2tp_ppp.c
86511 +++ b/net/l2tp/l2tp_ppp.c
86512 @@ -355,6 +355,7 @@ static int pppol2tp_sendmsg(struct kiocb *iocb, struct socket *sock, struct msgh
86513 l2tp_xmit_skb(session, skb, session->hdr_len);
86514
86515 sock_put(ps->tunnel_sock);
86516 + sock_put(sk);
86517
86518 return error;
86519
86520 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
86521 index 0479c64..d031db6 100644
86522 --- a/net/mac80211/cfg.c
86523 +++ b/net/mac80211/cfg.c
86524 @@ -790,7 +790,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
86525 ret = ieee80211_vif_use_channel(sdata, chandef,
86526 IEEE80211_CHANCTX_EXCLUSIVE);
86527 }
86528 - } else if (local->open_count == local->monitors) {
86529 + } else if (local_read(&local->open_count) == local->monitors) {
86530 local->_oper_channel = chandef->chan;
86531 local->_oper_channel_type = cfg80211_get_chandef_type(chandef);
86532 ieee80211_hw_config(local, 0);
86533 @@ -2716,7 +2716,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
86534 else
86535 local->probe_req_reg--;
86536
86537 - if (!local->open_count)
86538 + if (!local_read(&local->open_count))
86539 break;
86540
86541 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
86542 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
86543 index 2ed065c..948177f 100644
86544 --- a/net/mac80211/ieee80211_i.h
86545 +++ b/net/mac80211/ieee80211_i.h
86546 @@ -28,6 +28,7 @@
86547 #include <net/ieee80211_radiotap.h>
86548 #include <net/cfg80211.h>
86549 #include <net/mac80211.h>
86550 +#include <asm/local.h>
86551 #include "key.h"
86552 #include "sta_info.h"
86553 #include "debug.h"
86554 @@ -909,7 +910,7 @@ struct ieee80211_local {
86555 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
86556 spinlock_t queue_stop_reason_lock;
86557
86558 - int open_count;
86559 + local_t open_count;
86560 int monitors, cooked_mntrs;
86561 /* number of interfaces with corresponding FIF_ flags */
86562 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
86563 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
86564 index 8be854e..ad72a69 100644
86565 --- a/net/mac80211/iface.c
86566 +++ b/net/mac80211/iface.c
86567 @@ -546,7 +546,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86568 break;
86569 }
86570
86571 - if (local->open_count == 0) {
86572 + if (local_read(&local->open_count) == 0) {
86573 res = drv_start(local);
86574 if (res)
86575 goto err_del_bss;
86576 @@ -591,7 +591,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86577 break;
86578 }
86579
86580 - if (local->monitors == 0 && local->open_count == 0) {
86581 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
86582 res = ieee80211_add_virtual_monitor(local);
86583 if (res)
86584 goto err_stop;
86585 @@ -699,7 +699,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86586 mutex_unlock(&local->mtx);
86587
86588 if (coming_up)
86589 - local->open_count++;
86590 + local_inc(&local->open_count);
86591
86592 if (hw_reconf_flags)
86593 ieee80211_hw_config(local, hw_reconf_flags);
86594 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
86595 err_del_interface:
86596 drv_remove_interface(local, sdata);
86597 err_stop:
86598 - if (!local->open_count)
86599 + if (!local_read(&local->open_count))
86600 drv_stop(local);
86601 err_del_bss:
86602 sdata->bss = NULL;
86603 @@ -827,7 +827,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86604 }
86605
86606 if (going_down)
86607 - local->open_count--;
86608 + local_dec(&local->open_count);
86609
86610 switch (sdata->vif.type) {
86611 case NL80211_IFTYPE_AP_VLAN:
86612 @@ -884,7 +884,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86613
86614 ieee80211_recalc_ps(local, -1);
86615
86616 - if (local->open_count == 0) {
86617 + if (local_read(&local->open_count) == 0) {
86618 if (local->ops->napi_poll)
86619 napi_disable(&local->napi);
86620 ieee80211_clear_tx_pending(local);
86621 @@ -910,7 +910,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
86622 }
86623 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
86624
86625 - if (local->monitors == local->open_count && local->monitors > 0)
86626 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
86627 ieee80211_add_virtual_monitor(local);
86628 }
86629
86630 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
86631 index 1b087ff..bf600e9 100644
86632 --- a/net/mac80211/main.c
86633 +++ b/net/mac80211/main.c
86634 @@ -181,7 +181,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
86635 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
86636 IEEE80211_CONF_CHANGE_POWER);
86637
86638 - if (changed && local->open_count) {
86639 + if (changed && local_read(&local->open_count)) {
86640 ret = drv_config(local, changed);
86641 /*
86642 * Goal:
86643 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
86644 index 79a48f3..5e185c9 100644
86645 --- a/net/mac80211/pm.c
86646 +++ b/net/mac80211/pm.c
86647 @@ -35,7 +35,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86648 struct sta_info *sta;
86649 struct ieee80211_chanctx *ctx;
86650
86651 - if (!local->open_count)
86652 + if (!local_read(&local->open_count))
86653 goto suspend;
86654
86655 ieee80211_scan_cancel(local);
86656 @@ -73,7 +73,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86657 cancel_work_sync(&local->dynamic_ps_enable_work);
86658 del_timer_sync(&local->dynamic_ps_timer);
86659
86660 - local->wowlan = wowlan && local->open_count;
86661 + local->wowlan = wowlan && local_read(&local->open_count);
86662 if (local->wowlan) {
86663 int err = drv_suspend(local, wowlan);
86664 if (err < 0) {
86665 @@ -187,7 +187,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
86666 mutex_unlock(&local->chanctx_mtx);
86667
86668 /* stop hardware - this must stop RX */
86669 - if (local->open_count)
86670 + if (local_read(&local->open_count))
86671 ieee80211_stop_device(local);
86672
86673 suspend:
86674 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
86675 index dd88381..eef4dd6 100644
86676 --- a/net/mac80211/rate.c
86677 +++ b/net/mac80211/rate.c
86678 @@ -493,7 +493,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
86679
86680 ASSERT_RTNL();
86681
86682 - if (local->open_count)
86683 + if (local_read(&local->open_count))
86684 return -EBUSY;
86685
86686 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
86687 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
86688 index c97a065..ff61928 100644
86689 --- a/net/mac80211/rc80211_pid_debugfs.c
86690 +++ b/net/mac80211/rc80211_pid_debugfs.c
86691 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
86692
86693 spin_unlock_irqrestore(&events->lock, status);
86694
86695 - if (copy_to_user(buf, pb, p))
86696 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
86697 return -EFAULT;
86698
86699 return p;
86700 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
86701 index f11e8c5..08d0013 100644
86702 --- a/net/mac80211/util.c
86703 +++ b/net/mac80211/util.c
86704 @@ -1380,7 +1380,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
86705 }
86706 #endif
86707 /* everything else happens only if HW was up & running */
86708 - if (!local->open_count)
86709 + if (!local_read(&local->open_count))
86710 goto wake_up;
86711
86712 /*
86713 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
86714 index 49e96df..63a51c3 100644
86715 --- a/net/netfilter/Kconfig
86716 +++ b/net/netfilter/Kconfig
86717 @@ -936,6 +936,16 @@ config NETFILTER_XT_MATCH_ESP
86718
86719 To compile it as a module, choose M here. If unsure, say N.
86720
86721 +config NETFILTER_XT_MATCH_GRADM
86722 + tristate '"gradm" match support'
86723 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
86724 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
86725 + ---help---
86726 + The gradm match allows to match on grsecurity RBAC being enabled.
86727 + It is useful when iptables rules are applied early on bootup to
86728 + prevent connections to the machine (except from a trusted host)
86729 + while the RBAC system is disabled.
86730 +
86731 config NETFILTER_XT_MATCH_HASHLIMIT
86732 tristate '"hashlimit" match support'
86733 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
86734 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
86735 index 3259697..54d5393 100644
86736 --- a/net/netfilter/Makefile
86737 +++ b/net/netfilter/Makefile
86738 @@ -109,6 +109,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
86739 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
86740 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
86741 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
86742 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
86743 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
86744 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
86745 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
86746 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
86747 index 6d6d8f2..a676749 100644
86748 --- a/net/netfilter/ipset/ip_set_core.c
86749 +++ b/net/netfilter/ipset/ip_set_core.c
86750 @@ -1800,7 +1800,7 @@ done:
86751 return ret;
86752 }
86753
86754 -static struct nf_sockopt_ops so_set __read_mostly = {
86755 +static struct nf_sockopt_ops so_set = {
86756 .pf = PF_INET,
86757 .get_optmin = SO_IP_SET,
86758 .get_optmax = SO_IP_SET + 1,
86759 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
86760 index 30e764a..c3b6a9d 100644
86761 --- a/net/netfilter/ipvs/ip_vs_conn.c
86762 +++ b/net/netfilter/ipvs/ip_vs_conn.c
86763 @@ -554,7 +554,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
86764 /* Increase the refcnt counter of the dest */
86765 atomic_inc(&dest->refcnt);
86766
86767 - conn_flags = atomic_read(&dest->conn_flags);
86768 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
86769 if (cp->protocol != IPPROTO_UDP)
86770 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
86771 flags = cp->flags;
86772 @@ -899,7 +899,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
86773 atomic_set(&cp->refcnt, 1);
86774
86775 atomic_set(&cp->n_control, 0);
86776 - atomic_set(&cp->in_pkts, 0);
86777 + atomic_set_unchecked(&cp->in_pkts, 0);
86778
86779 atomic_inc(&ipvs->conn_count);
86780 if (flags & IP_VS_CONN_F_NO_CPORT)
86781 @@ -1180,7 +1180,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
86782
86783 /* Don't drop the entry if its number of incoming packets is not
86784 located in [0, 8] */
86785 - i = atomic_read(&cp->in_pkts);
86786 + i = atomic_read_unchecked(&cp->in_pkts);
86787 if (i > 8 || i < 0) return 0;
86788
86789 if (!todrop_rate[i]) return 0;
86790 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
86791 index 47edf5a..235b07d 100644
86792 --- a/net/netfilter/ipvs/ip_vs_core.c
86793 +++ b/net/netfilter/ipvs/ip_vs_core.c
86794 @@ -559,7 +559,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
86795 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
86796 /* do not touch skb anymore */
86797
86798 - atomic_inc(&cp->in_pkts);
86799 + atomic_inc_unchecked(&cp->in_pkts);
86800 ip_vs_conn_put(cp);
86801 return ret;
86802 }
86803 @@ -1691,7 +1691,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
86804 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
86805 pkts = sysctl_sync_threshold(ipvs);
86806 else
86807 - pkts = atomic_add_return(1, &cp->in_pkts);
86808 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86809
86810 if (ipvs->sync_state & IP_VS_STATE_MASTER)
86811 ip_vs_sync_conn(net, cp, pkts);
86812 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
86813 index ec664cb..7f34a77 100644
86814 --- a/net/netfilter/ipvs/ip_vs_ctl.c
86815 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
86816 @@ -787,7 +787,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
86817 ip_vs_rs_hash(ipvs, dest);
86818 write_unlock_bh(&ipvs->rs_lock);
86819 }
86820 - atomic_set(&dest->conn_flags, conn_flags);
86821 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
86822
86823 /* bind the service */
86824 if (!dest->svc) {
86825 @@ -1688,7 +1688,7 @@ proc_do_sync_ports(ctl_table *table, int write,
86826 * align with netns init in ip_vs_control_net_init()
86827 */
86828
86829 -static struct ctl_table vs_vars[] = {
86830 +static ctl_table_no_const vs_vars[] __read_only = {
86831 {
86832 .procname = "amemthresh",
86833 .maxlen = sizeof(int),
86834 @@ -2081,7 +2081,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
86835 " %-7s %-6d %-10d %-10d\n",
86836 &dest->addr.in6,
86837 ntohs(dest->port),
86838 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
86839 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
86840 atomic_read(&dest->weight),
86841 atomic_read(&dest->activeconns),
86842 atomic_read(&dest->inactconns));
86843 @@ -2092,7 +2092,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
86844 "%-7s %-6d %-10d %-10d\n",
86845 ntohl(dest->addr.ip),
86846 ntohs(dest->port),
86847 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
86848 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
86849 atomic_read(&dest->weight),
86850 atomic_read(&dest->activeconns),
86851 atomic_read(&dest->inactconns));
86852 @@ -2562,7 +2562,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
86853
86854 entry.addr = dest->addr.ip;
86855 entry.port = dest->port;
86856 - entry.conn_flags = atomic_read(&dest->conn_flags);
86857 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
86858 entry.weight = atomic_read(&dest->weight);
86859 entry.u_threshold = dest->u_threshold;
86860 entry.l_threshold = dest->l_threshold;
86861 @@ -3098,7 +3098,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
86862 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
86863 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
86864 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
86865 - (atomic_read(&dest->conn_flags) &
86866 + (atomic_read_unchecked(&dest->conn_flags) &
86867 IP_VS_CONN_F_FWD_MASK)) ||
86868 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
86869 atomic_read(&dest->weight)) ||
86870 @@ -3688,7 +3688,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
86871 {
86872 int idx;
86873 struct netns_ipvs *ipvs = net_ipvs(net);
86874 - struct ctl_table *tbl;
86875 + ctl_table_no_const *tbl;
86876
86877 atomic_set(&ipvs->dropentry, 0);
86878 spin_lock_init(&ipvs->dropentry_lock);
86879 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
86880 index fdd89b9..bd96aa9 100644
86881 --- a/net/netfilter/ipvs/ip_vs_lblc.c
86882 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
86883 @@ -115,7 +115,7 @@ struct ip_vs_lblc_table {
86884 * IPVS LBLC sysctl table
86885 */
86886 #ifdef CONFIG_SYSCTL
86887 -static ctl_table vs_vars_table[] = {
86888 +static ctl_table_no_const vs_vars_table[] __read_only = {
86889 {
86890 .procname = "lblc_expiration",
86891 .data = NULL,
86892 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
86893 index c03b6a3..8ce3681 100644
86894 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
86895 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
86896 @@ -288,7 +288,7 @@ struct ip_vs_lblcr_table {
86897 * IPVS LBLCR sysctl table
86898 */
86899
86900 -static ctl_table vs_vars_table[] = {
86901 +static ctl_table_no_const vs_vars_table[] __read_only = {
86902 {
86903 .procname = "lblcr_expiration",
86904 .data = NULL,
86905 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
86906 index 44fd10c..2a163b3 100644
86907 --- a/net/netfilter/ipvs/ip_vs_sync.c
86908 +++ b/net/netfilter/ipvs/ip_vs_sync.c
86909 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
86910 cp = cp->control;
86911 if (cp) {
86912 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
86913 - pkts = atomic_add_return(1, &cp->in_pkts);
86914 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86915 else
86916 pkts = sysctl_sync_threshold(ipvs);
86917 ip_vs_sync_conn(net, cp->control, pkts);
86918 @@ -758,7 +758,7 @@ control:
86919 if (!cp)
86920 return;
86921 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
86922 - pkts = atomic_add_return(1, &cp->in_pkts);
86923 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
86924 else
86925 pkts = sysctl_sync_threshold(ipvs);
86926 goto sloop;
86927 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
86928
86929 if (opt)
86930 memcpy(&cp->in_seq, opt, sizeof(*opt));
86931 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
86932 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
86933 cp->state = state;
86934 cp->old_state = cp->state;
86935 /*
86936 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
86937 index ee6b7a9..f9a89f6 100644
86938 --- a/net/netfilter/ipvs/ip_vs_xmit.c
86939 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
86940 @@ -1210,7 +1210,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
86941 else
86942 rc = NF_ACCEPT;
86943 /* do not touch skb anymore */
86944 - atomic_inc(&cp->in_pkts);
86945 + atomic_inc_unchecked(&cp->in_pkts);
86946 goto out;
86947 }
86948
86949 @@ -1332,7 +1332,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
86950 else
86951 rc = NF_ACCEPT;
86952 /* do not touch skb anymore */
86953 - atomic_inc(&cp->in_pkts);
86954 + atomic_inc_unchecked(&cp->in_pkts);
86955 goto out;
86956 }
86957
86958 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
86959 index 7df424e..a527b02 100644
86960 --- a/net/netfilter/nf_conntrack_acct.c
86961 +++ b/net/netfilter/nf_conntrack_acct.c
86962 @@ -60,7 +60,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
86963 #ifdef CONFIG_SYSCTL
86964 static int nf_conntrack_acct_init_sysctl(struct net *net)
86965 {
86966 - struct ctl_table *table;
86967 + ctl_table_no_const *table;
86968
86969 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
86970 GFP_KERNEL);
86971 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
86972 index e4a0c4f..c263f28 100644
86973 --- a/net/netfilter/nf_conntrack_core.c
86974 +++ b/net/netfilter/nf_conntrack_core.c
86975 @@ -1529,6 +1529,10 @@ err_extend:
86976 #define DYING_NULLS_VAL ((1<<30)+1)
86977 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
86978
86979 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86980 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
86981 +#endif
86982 +
86983 static int nf_conntrack_init_net(struct net *net)
86984 {
86985 int ret;
86986 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
86987 goto err_stat;
86988 }
86989
86990 +#ifdef CONFIG_GRKERNSEC_HIDESYM
86991 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
86992 +#else
86993 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
86994 +#endif
86995 if (!net->ct.slabname) {
86996 ret = -ENOMEM;
86997 goto err_slabname;
86998 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
86999 index faa978f..1afb18f 100644
87000 --- a/net/netfilter/nf_conntrack_ecache.c
87001 +++ b/net/netfilter/nf_conntrack_ecache.c
87002 @@ -186,7 +186,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
87003 #ifdef CONFIG_SYSCTL
87004 static int nf_conntrack_event_init_sysctl(struct net *net)
87005 {
87006 - struct ctl_table *table;
87007 + ctl_table_no_const *table;
87008
87009 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
87010 GFP_KERNEL);
87011 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
87012 index 884f2b3..d53b33a 100644
87013 --- a/net/netfilter/nf_conntrack_helper.c
87014 +++ b/net/netfilter/nf_conntrack_helper.c
87015 @@ -55,7 +55,7 @@ static struct ctl_table helper_sysctl_table[] = {
87016
87017 static int nf_conntrack_helper_init_sysctl(struct net *net)
87018 {
87019 - struct ctl_table *table;
87020 + ctl_table_no_const *table;
87021
87022 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
87023 GFP_KERNEL);
87024 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
87025 index 51e928d..72a413a 100644
87026 --- a/net/netfilter/nf_conntrack_proto.c
87027 +++ b/net/netfilter/nf_conntrack_proto.c
87028 @@ -51,7 +51,7 @@ nf_ct_register_sysctl(struct net *net,
87029
87030 static void
87031 nf_ct_unregister_sysctl(struct ctl_table_header **header,
87032 - struct ctl_table **table,
87033 + ctl_table_no_const **table,
87034 unsigned int users)
87035 {
87036 if (users > 0)
87037 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
87038 index e7185c6..4ad6c9c 100644
87039 --- a/net/netfilter/nf_conntrack_standalone.c
87040 +++ b/net/netfilter/nf_conntrack_standalone.c
87041 @@ -470,7 +470,7 @@ static ctl_table nf_ct_netfilter_table[] = {
87042
87043 static int nf_conntrack_standalone_init_sysctl(struct net *net)
87044 {
87045 - struct ctl_table *table;
87046 + ctl_table_no_const *table;
87047
87048 if (net_eq(net, &init_net)) {
87049 nf_ct_netfilter_header =
87050 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
87051 index 7ea8026..bc9512d 100644
87052 --- a/net/netfilter/nf_conntrack_timestamp.c
87053 +++ b/net/netfilter/nf_conntrack_timestamp.c
87054 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
87055 #ifdef CONFIG_SYSCTL
87056 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
87057 {
87058 - struct ctl_table *table;
87059 + ctl_table_no_const *table;
87060
87061 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
87062 GFP_KERNEL);
87063 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
87064 index 9e31269..bc4c1b7 100644
87065 --- a/net/netfilter/nf_log.c
87066 +++ b/net/netfilter/nf_log.c
87067 @@ -215,7 +215,7 @@ static const struct file_operations nflog_file_ops = {
87068
87069 #ifdef CONFIG_SYSCTL
87070 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
87071 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
87072 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
87073 static struct ctl_table_header *nf_log_dir_header;
87074
87075 static int nf_log_proc_dostring(ctl_table *table, int write,
87076 @@ -246,14 +246,16 @@ static int nf_log_proc_dostring(ctl_table *table, int write,
87077 rcu_assign_pointer(nf_loggers[tindex], logger);
87078 mutex_unlock(&nf_log_mutex);
87079 } else {
87080 + ctl_table_no_const nf_log_table = *table;
87081 +
87082 mutex_lock(&nf_log_mutex);
87083 logger = rcu_dereference_protected(nf_loggers[tindex],
87084 lockdep_is_held(&nf_log_mutex));
87085 if (!logger)
87086 - table->data = "NONE";
87087 + nf_log_table.data = "NONE";
87088 else
87089 - table->data = logger->name;
87090 - r = proc_dostring(table, write, buffer, lenp, ppos);
87091 + nf_log_table.data = logger->name;
87092 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
87093 mutex_unlock(&nf_log_mutex);
87094 }
87095
87096 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
87097 index f042ae5..30ea486 100644
87098 --- a/net/netfilter/nf_sockopt.c
87099 +++ b/net/netfilter/nf_sockopt.c
87100 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
87101 }
87102 }
87103
87104 - list_add(&reg->list, &nf_sockopts);
87105 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
87106 out:
87107 mutex_unlock(&nf_sockopt_mutex);
87108 return ret;
87109 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
87110 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
87111 {
87112 mutex_lock(&nf_sockopt_mutex);
87113 - list_del(&reg->list);
87114 + pax_list_del((struct list_head *)&reg->list);
87115 mutex_unlock(&nf_sockopt_mutex);
87116 }
87117 EXPORT_SYMBOL(nf_unregister_sockopt);
87118 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
87119 index 92fd8ec..3f6ea4b 100644
87120 --- a/net/netfilter/nfnetlink_log.c
87121 +++ b/net/netfilter/nfnetlink_log.c
87122 @@ -72,7 +72,7 @@ struct nfulnl_instance {
87123 };
87124
87125 static DEFINE_SPINLOCK(instances_lock);
87126 -static atomic_t global_seq;
87127 +static atomic_unchecked_t global_seq;
87128
87129 #define INSTANCE_BUCKETS 16
87130 static struct hlist_head instance_table[INSTANCE_BUCKETS];
87131 @@ -537,7 +537,7 @@ __build_packet_message(struct nfulnl_instance *inst,
87132 /* global sequence number */
87133 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
87134 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
87135 - htonl(atomic_inc_return(&global_seq))))
87136 + htonl(atomic_inc_return_unchecked(&global_seq))))
87137 goto nla_put_failure;
87138
87139 if (data_len) {
87140 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
87141 new file mode 100644
87142 index 0000000..c566332
87143 --- /dev/null
87144 +++ b/net/netfilter/xt_gradm.c
87145 @@ -0,0 +1,51 @@
87146 +/*
87147 + * gradm match for netfilter
87148 + * Copyright © Zbigniew Krzystolik, 2010
87149 + *
87150 + * This program is free software; you can redistribute it and/or modify
87151 + * it under the terms of the GNU General Public License; either version
87152 + * 2 or 3 as published by the Free Software Foundation.
87153 + */
87154 +#include <linux/module.h>
87155 +#include <linux/moduleparam.h>
87156 +#include <linux/skbuff.h>
87157 +#include <linux/netfilter/x_tables.h>
87158 +#include <linux/grsecurity.h>
87159 +#include <linux/netfilter/xt_gradm.h>
87160 +
87161 +static bool
87162 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
87163 +{
87164 + const struct xt_gradm_mtinfo *info = par->matchinfo;
87165 + bool retval = false;
87166 + if (gr_acl_is_enabled())
87167 + retval = true;
87168 + return retval ^ info->invflags;
87169 +}
87170 +
87171 +static struct xt_match gradm_mt_reg __read_mostly = {
87172 + .name = "gradm",
87173 + .revision = 0,
87174 + .family = NFPROTO_UNSPEC,
87175 + .match = gradm_mt,
87176 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
87177 + .me = THIS_MODULE,
87178 +};
87179 +
87180 +static int __init gradm_mt_init(void)
87181 +{
87182 + return xt_register_match(&gradm_mt_reg);
87183 +}
87184 +
87185 +static void __exit gradm_mt_exit(void)
87186 +{
87187 + xt_unregister_match(&gradm_mt_reg);
87188 +}
87189 +
87190 +module_init(gradm_mt_init);
87191 +module_exit(gradm_mt_exit);
87192 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
87193 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
87194 +MODULE_LICENSE("GPL");
87195 +MODULE_ALIAS("ipt_gradm");
87196 +MODULE_ALIAS("ip6t_gradm");
87197 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
87198 index 4fe4fb4..87a89e5 100644
87199 --- a/net/netfilter/xt_statistic.c
87200 +++ b/net/netfilter/xt_statistic.c
87201 @@ -19,7 +19,7 @@
87202 #include <linux/module.h>
87203
87204 struct xt_statistic_priv {
87205 - atomic_t count;
87206 + atomic_unchecked_t count;
87207 } ____cacheline_aligned_in_smp;
87208
87209 MODULE_LICENSE("GPL");
87210 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
87211 break;
87212 case XT_STATISTIC_MODE_NTH:
87213 do {
87214 - oval = atomic_read(&info->master->count);
87215 + oval = atomic_read_unchecked(&info->master->count);
87216 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
87217 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
87218 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
87219 if (nval == 0)
87220 ret = !ret;
87221 break;
87222 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
87223 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
87224 if (info->master == NULL)
87225 return -ENOMEM;
87226 - atomic_set(&info->master->count, info->u.nth.count);
87227 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
87228
87229 return 0;
87230 }
87231 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
87232 index c0353d5..fcb0270 100644
87233 --- a/net/netlink/af_netlink.c
87234 +++ b/net/netlink/af_netlink.c
87235 @@ -785,7 +785,7 @@ static void netlink_overrun(struct sock *sk)
87236 sk->sk_error_report(sk);
87237 }
87238 }
87239 - atomic_inc(&sk->sk_drops);
87240 + atomic_inc_unchecked(&sk->sk_drops);
87241 }
87242
87243 static struct sock *netlink_getsockbyportid(struct sock *ssk, u32 portid)
87244 @@ -2071,7 +2071,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
87245 sk_wmem_alloc_get(s),
87246 nlk->cb,
87247 atomic_read(&s->sk_refcnt),
87248 - atomic_read(&s->sk_drops),
87249 + atomic_read_unchecked(&s->sk_drops),
87250 sock_i_ino(s)
87251 );
87252
87253 diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
87254 index f2aabb6..2e5e66e 100644
87255 --- a/net/netlink/genetlink.c
87256 +++ b/net/netlink/genetlink.c
87257 @@ -295,18 +295,20 @@ int genl_register_ops(struct genl_family *family, struct genl_ops *ops)
87258 goto errout;
87259 }
87260
87261 + pax_open_kernel();
87262 if (ops->dumpit)
87263 - ops->flags |= GENL_CMD_CAP_DUMP;
87264 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_DUMP;
87265 if (ops->doit)
87266 - ops->flags |= GENL_CMD_CAP_DO;
87267 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_DO;
87268 if (ops->policy)
87269 - ops->flags |= GENL_CMD_CAP_HASPOL;
87270 + *(unsigned int *)&ops->flags |= GENL_CMD_CAP_HASPOL;
87271 + pax_close_kernel();
87272
87273 genl_lock();
87274 - list_add_tail(&ops->ops_list, &family->ops_list);
87275 + pax_list_add_tail((struct list_head *)&ops->ops_list, &family->ops_list);
87276 genl_unlock();
87277
87278 - genl_ctrl_event(CTRL_CMD_NEWOPS, ops);
87279 + genl_ctrl_event(CTRL_CMD_NEWOPS, (void *)ops);
87280 err = 0;
87281 errout:
87282 return err;
87283 @@ -336,9 +338,9 @@ int genl_unregister_ops(struct genl_family *family, struct genl_ops *ops)
87284 genl_lock();
87285 list_for_each_entry(rc, &family->ops_list, ops_list) {
87286 if (rc == ops) {
87287 - list_del(&ops->ops_list);
87288 + pax_list_del((struct list_head *)&ops->ops_list);
87289 genl_unlock();
87290 - genl_ctrl_event(CTRL_CMD_DELOPS, ops);
87291 + genl_ctrl_event(CTRL_CMD_DELOPS, (void *)ops);
87292 return 0;
87293 }
87294 }
87295 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
87296 index 7261eb8..44e8ac6 100644
87297 --- a/net/netrom/af_netrom.c
87298 +++ b/net/netrom/af_netrom.c
87299 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
87300 struct sock *sk = sock->sk;
87301 struct nr_sock *nr = nr_sk(sk);
87302
87303 + memset(sax, 0, sizeof(*sax));
87304 lock_sock(sk);
87305 if (peer != 0) {
87306 if (sk->sk_state != TCP_ESTABLISHED) {
87307 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
87308 *uaddr_len = sizeof(struct full_sockaddr_ax25);
87309 } else {
87310 sax->fsa_ax25.sax25_family = AF_NETROM;
87311 - sax->fsa_ax25.sax25_ndigis = 0;
87312 sax->fsa_ax25.sax25_call = nr->source_addr;
87313 *uaddr_len = sizeof(struct sockaddr_ax25);
87314 }
87315 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
87316 index c111bd0..7788ff7 100644
87317 --- a/net/packet/af_packet.c
87318 +++ b/net/packet/af_packet.c
87319 @@ -1578,7 +1578,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
87320
87321 spin_lock(&sk->sk_receive_queue.lock);
87322 po->stats.tp_packets++;
87323 - skb->dropcount = atomic_read(&sk->sk_drops);
87324 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
87325 __skb_queue_tail(&sk->sk_receive_queue, skb);
87326 spin_unlock(&sk->sk_receive_queue.lock);
87327 sk->sk_data_ready(sk, skb->len);
87328 @@ -1587,7 +1587,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
87329 drop_n_acct:
87330 spin_lock(&sk->sk_receive_queue.lock);
87331 po->stats.tp_drops++;
87332 - atomic_inc(&sk->sk_drops);
87333 + atomic_inc_unchecked(&sk->sk_drops);
87334 spin_unlock(&sk->sk_receive_queue.lock);
87335
87336 drop_n_restore:
87337 @@ -2565,6 +2565,7 @@ out:
87338
87339 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
87340 {
87341 + struct sock_extended_err ee;
87342 struct sock_exterr_skb *serr;
87343 struct sk_buff *skb, *skb2;
87344 int copied, err;
87345 @@ -2586,8 +2587,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
87346 sock_recv_timestamp(msg, sk, skb);
87347
87348 serr = SKB_EXT_ERR(skb);
87349 + ee = serr->ee;
87350 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
87351 - sizeof(serr->ee), &serr->ee);
87352 + sizeof ee, &ee);
87353
87354 msg->msg_flags |= MSG_ERRQUEUE;
87355 err = copied;
87356 @@ -3212,7 +3214,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
87357 case PACKET_HDRLEN:
87358 if (len > sizeof(int))
87359 len = sizeof(int);
87360 - if (copy_from_user(&val, optval, len))
87361 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
87362 return -EFAULT;
87363 switch (val) {
87364 case TPACKET_V1:
87365 @@ -3254,7 +3256,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
87366 len = lv;
87367 if (put_user(len, optlen))
87368 return -EFAULT;
87369 - if (copy_to_user(optval, data, len))
87370 + if (len > sizeof(st) || copy_to_user(optval, data, len))
87371 return -EFAULT;
87372 return 0;
87373 }
87374 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
87375 index 5a940db..f0b9c12 100644
87376 --- a/net/phonet/af_phonet.c
87377 +++ b/net/phonet/af_phonet.c
87378 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
87379 {
87380 struct phonet_protocol *pp;
87381
87382 - if (protocol >= PHONET_NPROTO)
87383 + if (protocol < 0 || protocol >= PHONET_NPROTO)
87384 return NULL;
87385
87386 rcu_read_lock();
87387 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
87388 {
87389 int err = 0;
87390
87391 - if (protocol >= PHONET_NPROTO)
87392 + if (protocol < 0 || protocol >= PHONET_NPROTO)
87393 return -EINVAL;
87394
87395 err = proto_register(pp->prot, 1);
87396 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
87397 index 576f22c..bc7a71b 100644
87398 --- a/net/phonet/pep.c
87399 +++ b/net/phonet/pep.c
87400 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
87401
87402 case PNS_PEP_CTRL_REQ:
87403 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
87404 - atomic_inc(&sk->sk_drops);
87405 + atomic_inc_unchecked(&sk->sk_drops);
87406 break;
87407 }
87408 __skb_pull(skb, 4);
87409 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
87410 }
87411
87412 if (pn->rx_credits == 0) {
87413 - atomic_inc(&sk->sk_drops);
87414 + atomic_inc_unchecked(&sk->sk_drops);
87415 err = -ENOBUFS;
87416 break;
87417 }
87418 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
87419 }
87420
87421 if (pn->rx_credits == 0) {
87422 - atomic_inc(&sk->sk_drops);
87423 + atomic_inc_unchecked(&sk->sk_drops);
87424 err = NET_RX_DROP;
87425 break;
87426 }
87427 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
87428 index b7e9827..c264c85 100644
87429 --- a/net/phonet/socket.c
87430 +++ b/net/phonet/socket.c
87431 @@ -615,7 +615,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
87432 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
87433 sock_i_ino(sk),
87434 atomic_read(&sk->sk_refcnt), sk,
87435 - atomic_read(&sk->sk_drops), &len);
87436 + atomic_read_unchecked(&sk->sk_drops), &len);
87437 }
87438 seq_printf(seq, "%*s\n", 127 - len, "");
87439 return 0;
87440 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
87441 index d6bbbbd..61561e4 100644
87442 --- a/net/phonet/sysctl.c
87443 +++ b/net/phonet/sysctl.c
87444 @@ -67,7 +67,7 @@ static int proc_local_port_range(ctl_table *table, int write,
87445 {
87446 int ret;
87447 int range[2] = {local_port_range[0], local_port_range[1]};
87448 - ctl_table tmp = {
87449 + ctl_table_no_const tmp = {
87450 .data = &range,
87451 .maxlen = sizeof(range),
87452 .mode = table->mode,
87453 diff --git a/net/rds/cong.c b/net/rds/cong.c
87454 index e5b65ac..f3b6fb7 100644
87455 --- a/net/rds/cong.c
87456 +++ b/net/rds/cong.c
87457 @@ -78,7 +78,7 @@
87458 * finds that the saved generation number is smaller than the global generation
87459 * number, it wakes up the process.
87460 */
87461 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
87462 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
87463
87464 /*
87465 * Congestion monitoring
87466 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
87467 rdsdebug("waking map %p for %pI4\n",
87468 map, &map->m_addr);
87469 rds_stats_inc(s_cong_update_received);
87470 - atomic_inc(&rds_cong_generation);
87471 + atomic_inc_unchecked(&rds_cong_generation);
87472 if (waitqueue_active(&map->m_waitq))
87473 wake_up(&map->m_waitq);
87474 if (waitqueue_active(&rds_poll_waitq))
87475 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
87476
87477 int rds_cong_updated_since(unsigned long *recent)
87478 {
87479 - unsigned long gen = atomic_read(&rds_cong_generation);
87480 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
87481
87482 if (likely(*recent == gen))
87483 return 0;
87484 diff --git a/net/rds/ib.h b/net/rds/ib.h
87485 index 7280ab8..e04f4ea 100644
87486 --- a/net/rds/ib.h
87487 +++ b/net/rds/ib.h
87488 @@ -128,7 +128,7 @@ struct rds_ib_connection {
87489 /* sending acks */
87490 unsigned long i_ack_flags;
87491 #ifdef KERNEL_HAS_ATOMIC64
87492 - atomic64_t i_ack_next; /* next ACK to send */
87493 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
87494 #else
87495 spinlock_t i_ack_lock; /* protect i_ack_next */
87496 u64 i_ack_next; /* next ACK to send */
87497 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
87498 index 31b74f5..dc1fbfa 100644
87499 --- a/net/rds/ib_cm.c
87500 +++ b/net/rds/ib_cm.c
87501 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
87502 /* Clear the ACK state */
87503 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
87504 #ifdef KERNEL_HAS_ATOMIC64
87505 - atomic64_set(&ic->i_ack_next, 0);
87506 + atomic64_set_unchecked(&ic->i_ack_next, 0);
87507 #else
87508 ic->i_ack_next = 0;
87509 #endif
87510 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
87511 index 8eb9501..0c386ff 100644
87512 --- a/net/rds/ib_recv.c
87513 +++ b/net/rds/ib_recv.c
87514 @@ -597,7 +597,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
87515 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
87516 int ack_required)
87517 {
87518 - atomic64_set(&ic->i_ack_next, seq);
87519 + atomic64_set_unchecked(&ic->i_ack_next, seq);
87520 if (ack_required) {
87521 smp_mb__before_clear_bit();
87522 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87523 @@ -609,7 +609,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
87524 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87525 smp_mb__after_clear_bit();
87526
87527 - return atomic64_read(&ic->i_ack_next);
87528 + return atomic64_read_unchecked(&ic->i_ack_next);
87529 }
87530 #endif
87531
87532 diff --git a/net/rds/iw.h b/net/rds/iw.h
87533 index 04ce3b1..48119a6 100644
87534 --- a/net/rds/iw.h
87535 +++ b/net/rds/iw.h
87536 @@ -134,7 +134,7 @@ struct rds_iw_connection {
87537 /* sending acks */
87538 unsigned long i_ack_flags;
87539 #ifdef KERNEL_HAS_ATOMIC64
87540 - atomic64_t i_ack_next; /* next ACK to send */
87541 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
87542 #else
87543 spinlock_t i_ack_lock; /* protect i_ack_next */
87544 u64 i_ack_next; /* next ACK to send */
87545 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
87546 index a91e1db..cf3053f 100644
87547 --- a/net/rds/iw_cm.c
87548 +++ b/net/rds/iw_cm.c
87549 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
87550 /* Clear the ACK state */
87551 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
87552 #ifdef KERNEL_HAS_ATOMIC64
87553 - atomic64_set(&ic->i_ack_next, 0);
87554 + atomic64_set_unchecked(&ic->i_ack_next, 0);
87555 #else
87556 ic->i_ack_next = 0;
87557 #endif
87558 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
87559 index 4503335..db566b4 100644
87560 --- a/net/rds/iw_recv.c
87561 +++ b/net/rds/iw_recv.c
87562 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
87563 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
87564 int ack_required)
87565 {
87566 - atomic64_set(&ic->i_ack_next, seq);
87567 + atomic64_set_unchecked(&ic->i_ack_next, seq);
87568 if (ack_required) {
87569 smp_mb__before_clear_bit();
87570 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87571 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
87572 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
87573 smp_mb__after_clear_bit();
87574
87575 - return atomic64_read(&ic->i_ack_next);
87576 + return atomic64_read_unchecked(&ic->i_ack_next);
87577 }
87578 #endif
87579
87580 diff --git a/net/rds/message.c b/net/rds/message.c
87581 index f0a4658..aff589c 100644
87582 --- a/net/rds/message.c
87583 +++ b/net/rds/message.c
87584 @@ -197,6 +197,9 @@ struct rds_message *rds_message_alloc(unsigned int extra_len, gfp_t gfp)
87585 {
87586 struct rds_message *rm;
87587
87588 + if (extra_len > KMALLOC_MAX_SIZE - sizeof(struct rds_message))
87589 + return NULL;
87590 +
87591 rm = kzalloc(sizeof(struct rds_message) + extra_len, gfp);
87592 if (!rm)
87593 goto out;
87594 diff --git a/net/rds/rds.h b/net/rds/rds.h
87595 index ec1d731..90a3a8d 100644
87596 --- a/net/rds/rds.h
87597 +++ b/net/rds/rds.h
87598 @@ -449,7 +449,7 @@ struct rds_transport {
87599 void (*sync_mr)(void *trans_private, int direction);
87600 void (*free_mr)(void *trans_private, int invalidate);
87601 void (*flush_mrs)(void);
87602 -};
87603 +} __do_const;
87604
87605 struct rds_sock {
87606 struct sock rs_sk;
87607 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
87608 index edac9ef..16bcb98 100644
87609 --- a/net/rds/tcp.c
87610 +++ b/net/rds/tcp.c
87611 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
87612 int val = 1;
87613
87614 set_fs(KERNEL_DS);
87615 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
87616 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
87617 sizeof(val));
87618 set_fs(oldfs);
87619 }
87620 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
87621 index 81cf5a4..b5826ff 100644
87622 --- a/net/rds/tcp_send.c
87623 +++ b/net/rds/tcp_send.c
87624 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
87625
87626 oldfs = get_fs();
87627 set_fs(KERNEL_DS);
87628 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
87629 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
87630 sizeof(val));
87631 set_fs(oldfs);
87632 }
87633 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
87634 index 05996d0..5a1dfe0 100644
87635 --- a/net/rxrpc/af_rxrpc.c
87636 +++ b/net/rxrpc/af_rxrpc.c
87637 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
87638 __be32 rxrpc_epoch;
87639
87640 /* current debugging ID */
87641 -atomic_t rxrpc_debug_id;
87642 +atomic_unchecked_t rxrpc_debug_id;
87643
87644 /* count of skbs currently in use */
87645 atomic_t rxrpc_n_skbs;
87646 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
87647 index e4d9cbc..b229649 100644
87648 --- a/net/rxrpc/ar-ack.c
87649 +++ b/net/rxrpc/ar-ack.c
87650 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
87651
87652 _enter("{%d,%d,%d,%d},",
87653 call->acks_hard, call->acks_unacked,
87654 - atomic_read(&call->sequence),
87655 + atomic_read_unchecked(&call->sequence),
87656 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
87657
87658 stop = 0;
87659 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
87660
87661 /* each Tx packet has a new serial number */
87662 sp->hdr.serial =
87663 - htonl(atomic_inc_return(&call->conn->serial));
87664 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
87665
87666 hdr = (struct rxrpc_header *) txb->head;
87667 hdr->serial = sp->hdr.serial;
87668 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
87669 */
87670 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
87671 {
87672 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
87673 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
87674 }
87675
87676 /*
87677 @@ -629,7 +629,7 @@ process_further:
87678
87679 latest = ntohl(sp->hdr.serial);
87680 hard = ntohl(ack.firstPacket);
87681 - tx = atomic_read(&call->sequence);
87682 + tx = atomic_read_unchecked(&call->sequence);
87683
87684 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
87685 latest,
87686 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
87687 goto maybe_reschedule;
87688
87689 send_ACK_with_skew:
87690 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
87691 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
87692 ntohl(ack.serial));
87693 send_ACK:
87694 mtu = call->conn->trans->peer->if_mtu;
87695 @@ -1173,7 +1173,7 @@ send_ACK:
87696 ackinfo.rxMTU = htonl(5692);
87697 ackinfo.jumbo_max = htonl(4);
87698
87699 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
87700 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
87701 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
87702 ntohl(hdr.serial),
87703 ntohs(ack.maxSkew),
87704 @@ -1191,7 +1191,7 @@ send_ACK:
87705 send_message:
87706 _debug("send message");
87707
87708 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
87709 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
87710 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
87711 send_message_2:
87712
87713 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
87714 index a3bbb36..3341fb9 100644
87715 --- a/net/rxrpc/ar-call.c
87716 +++ b/net/rxrpc/ar-call.c
87717 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
87718 spin_lock_init(&call->lock);
87719 rwlock_init(&call->state_lock);
87720 atomic_set(&call->usage, 1);
87721 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
87722 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87723 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
87724
87725 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
87726 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
87727 index 4106ca9..a338d7a 100644
87728 --- a/net/rxrpc/ar-connection.c
87729 +++ b/net/rxrpc/ar-connection.c
87730 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
87731 rwlock_init(&conn->lock);
87732 spin_lock_init(&conn->state_lock);
87733 atomic_set(&conn->usage, 1);
87734 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
87735 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87736 conn->avail_calls = RXRPC_MAXCALLS;
87737 conn->size_align = 4;
87738 conn->header_size = sizeof(struct rxrpc_header);
87739 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
87740 index e7ed43a..6afa140 100644
87741 --- a/net/rxrpc/ar-connevent.c
87742 +++ b/net/rxrpc/ar-connevent.c
87743 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
87744
87745 len = iov[0].iov_len + iov[1].iov_len;
87746
87747 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
87748 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87749 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
87750
87751 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
87752 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
87753 index 529572f..c758ca7 100644
87754 --- a/net/rxrpc/ar-input.c
87755 +++ b/net/rxrpc/ar-input.c
87756 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
87757 /* track the latest serial number on this connection for ACK packet
87758 * information */
87759 serial = ntohl(sp->hdr.serial);
87760 - hi_serial = atomic_read(&call->conn->hi_serial);
87761 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
87762 while (serial > hi_serial)
87763 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
87764 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
87765 serial);
87766
87767 /* request ACK generation for any ACK or DATA packet that requests
87768 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
87769 index a693aca..81e7293 100644
87770 --- a/net/rxrpc/ar-internal.h
87771 +++ b/net/rxrpc/ar-internal.h
87772 @@ -272,8 +272,8 @@ struct rxrpc_connection {
87773 int error; /* error code for local abort */
87774 int debug_id; /* debug ID for printks */
87775 unsigned int call_counter; /* call ID counter */
87776 - atomic_t serial; /* packet serial number counter */
87777 - atomic_t hi_serial; /* highest serial number received */
87778 + atomic_unchecked_t serial; /* packet serial number counter */
87779 + atomic_unchecked_t hi_serial; /* highest serial number received */
87780 u8 avail_calls; /* number of calls available */
87781 u8 size_align; /* data size alignment (for security) */
87782 u8 header_size; /* rxrpc + security header size */
87783 @@ -346,7 +346,7 @@ struct rxrpc_call {
87784 spinlock_t lock;
87785 rwlock_t state_lock; /* lock for state transition */
87786 atomic_t usage;
87787 - atomic_t sequence; /* Tx data packet sequence counter */
87788 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
87789 u32 abort_code; /* local/remote abort code */
87790 enum { /* current state of call */
87791 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
87792 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
87793 */
87794 extern atomic_t rxrpc_n_skbs;
87795 extern __be32 rxrpc_epoch;
87796 -extern atomic_t rxrpc_debug_id;
87797 +extern atomic_unchecked_t rxrpc_debug_id;
87798 extern struct workqueue_struct *rxrpc_workqueue;
87799
87800 /*
87801 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
87802 index 87f7135..74d3703 100644
87803 --- a/net/rxrpc/ar-local.c
87804 +++ b/net/rxrpc/ar-local.c
87805 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
87806 spin_lock_init(&local->lock);
87807 rwlock_init(&local->services_lock);
87808 atomic_set(&local->usage, 1);
87809 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
87810 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87811 memcpy(&local->srx, srx, sizeof(*srx));
87812 }
87813
87814 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
87815 index e1ac183..b43e10e 100644
87816 --- a/net/rxrpc/ar-output.c
87817 +++ b/net/rxrpc/ar-output.c
87818 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
87819 sp->hdr.cid = call->cid;
87820 sp->hdr.callNumber = call->call_id;
87821 sp->hdr.seq =
87822 - htonl(atomic_inc_return(&call->sequence));
87823 + htonl(atomic_inc_return_unchecked(&call->sequence));
87824 sp->hdr.serial =
87825 - htonl(atomic_inc_return(&conn->serial));
87826 + htonl(atomic_inc_return_unchecked(&conn->serial));
87827 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
87828 sp->hdr.userStatus = 0;
87829 sp->hdr.securityIndex = conn->security_ix;
87830 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
87831 index bebaa43..2644591 100644
87832 --- a/net/rxrpc/ar-peer.c
87833 +++ b/net/rxrpc/ar-peer.c
87834 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
87835 INIT_LIST_HEAD(&peer->error_targets);
87836 spin_lock_init(&peer->lock);
87837 atomic_set(&peer->usage, 1);
87838 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
87839 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87840 memcpy(&peer->srx, srx, sizeof(*srx));
87841
87842 rxrpc_assess_MTU_size(peer);
87843 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
87844 index 38047f7..9f48511 100644
87845 --- a/net/rxrpc/ar-proc.c
87846 +++ b/net/rxrpc/ar-proc.c
87847 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
87848 atomic_read(&conn->usage),
87849 rxrpc_conn_states[conn->state],
87850 key_serial(conn->key),
87851 - atomic_read(&conn->serial),
87852 - atomic_read(&conn->hi_serial));
87853 + atomic_read_unchecked(&conn->serial),
87854 + atomic_read_unchecked(&conn->hi_serial));
87855
87856 return 0;
87857 }
87858 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
87859 index 92df566..87ec1bf 100644
87860 --- a/net/rxrpc/ar-transport.c
87861 +++ b/net/rxrpc/ar-transport.c
87862 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
87863 spin_lock_init(&trans->client_lock);
87864 rwlock_init(&trans->conn_lock);
87865 atomic_set(&trans->usage, 1);
87866 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
87867 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
87868
87869 if (peer->srx.transport.family == AF_INET) {
87870 switch (peer->srx.transport_type) {
87871 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
87872 index f226709..0e735a8 100644
87873 --- a/net/rxrpc/rxkad.c
87874 +++ b/net/rxrpc/rxkad.c
87875 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
87876
87877 len = iov[0].iov_len + iov[1].iov_len;
87878
87879 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
87880 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87881 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
87882
87883 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
87884 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
87885
87886 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
87887
87888 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
87889 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
87890 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
87891
87892 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
87893 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
87894 index 391a245..296b3d7 100644
87895 --- a/net/sctp/ipv6.c
87896 +++ b/net/sctp/ipv6.c
87897 @@ -981,7 +981,7 @@ static const struct inet6_protocol sctpv6_protocol = {
87898 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
87899 };
87900
87901 -static struct sctp_af sctp_af_inet6 = {
87902 +static struct sctp_af sctp_af_inet6 __read_only = {
87903 .sa_family = AF_INET6,
87904 .sctp_xmit = sctp_v6_xmit,
87905 .setsockopt = ipv6_setsockopt,
87906 @@ -1013,7 +1013,7 @@ static struct sctp_af sctp_af_inet6 = {
87907 #endif
87908 };
87909
87910 -static struct sctp_pf sctp_pf_inet6 = {
87911 +static struct sctp_pf sctp_pf_inet6 __read_only = {
87912 .event_msgname = sctp_inet6_event_msgname,
87913 .skb_msgname = sctp_inet6_skb_msgname,
87914 .af_supported = sctp_inet6_af_supported,
87915 @@ -1038,7 +1038,7 @@ void sctp_v6_pf_init(void)
87916
87917 void sctp_v6_pf_exit(void)
87918 {
87919 - list_del(&sctp_af_inet6.list);
87920 + pax_list_del(&sctp_af_inet6.list);
87921 }
87922
87923 /* Initialize IPv6 support and register with socket layer. */
87924 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
87925 index 8c19e97..16264b8 100644
87926 --- a/net/sctp/proc.c
87927 +++ b/net/sctp/proc.c
87928 @@ -338,7 +338,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
87929 seq_printf(seq,
87930 "%8pK %8pK %-3d %-3d %-2d %-4d "
87931 "%4d %8d %8d %7d %5lu %-5d %5d ",
87932 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
87933 + assoc, sk,
87934 + sctp_sk(sk)->type, sk->sk_state,
87935 assoc->state, hash,
87936 assoc->assoc_id,
87937 assoc->sndbuf_used,
87938 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
87939 index f898b1c..a2d0fe8 100644
87940 --- a/net/sctp/protocol.c
87941 +++ b/net/sctp/protocol.c
87942 @@ -834,8 +834,10 @@ int sctp_register_af(struct sctp_af *af)
87943 return 0;
87944 }
87945
87946 + pax_open_kernel();
87947 INIT_LIST_HEAD(&af->list);
87948 - list_add_tail(&af->list, &sctp_address_families);
87949 + pax_close_kernel();
87950 + pax_list_add_tail(&af->list, &sctp_address_families);
87951 return 1;
87952 }
87953
87954 @@ -966,7 +968,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
87955
87956 static struct sctp_af sctp_af_inet;
87957
87958 -static struct sctp_pf sctp_pf_inet = {
87959 +static struct sctp_pf sctp_pf_inet __read_only = {
87960 .event_msgname = sctp_inet_event_msgname,
87961 .skb_msgname = sctp_inet_skb_msgname,
87962 .af_supported = sctp_inet_af_supported,
87963 @@ -1037,7 +1039,7 @@ static const struct net_protocol sctp_protocol = {
87964 };
87965
87966 /* IPv4 address related functions. */
87967 -static struct sctp_af sctp_af_inet = {
87968 +static struct sctp_af sctp_af_inet __read_only = {
87969 .sa_family = AF_INET,
87970 .sctp_xmit = sctp_v4_xmit,
87971 .setsockopt = ip_setsockopt,
87972 @@ -1122,7 +1124,7 @@ static void sctp_v4_pf_init(void)
87973
87974 static void sctp_v4_pf_exit(void)
87975 {
87976 - list_del(&sctp_af_inet.list);
87977 + pax_list_del(&sctp_af_inet.list);
87978 }
87979
87980 static int sctp_v4_protosw_init(void)
87981 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
87982 index c957775..6d4593a 100644
87983 --- a/net/sctp/sm_sideeffect.c
87984 +++ b/net/sctp/sm_sideeffect.c
87985 @@ -447,7 +447,7 @@ static void sctp_generate_sack_event(unsigned long data)
87986 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
87987 }
87988
87989 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
87990 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
87991 NULL,
87992 sctp_generate_t1_cookie_event,
87993 sctp_generate_t1_init_event,
87994 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
87995 index cedd9bf..d577d71 100644
87996 --- a/net/sctp/socket.c
87997 +++ b/net/sctp/socket.c
87998 @@ -4665,6 +4665,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
87999 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
88000 if (space_left < addrlen)
88001 return -ENOMEM;
88002 + if (addrlen > sizeof(temp) || addrlen < 0)
88003 + return -EFAULT;
88004 if (copy_to_user(to, &temp, addrlen))
88005 return -EFAULT;
88006 to += addrlen;
88007 @@ -5653,6 +5655,9 @@ static int sctp_getsockopt_assoc_stats(struct sock *sk, int len,
88008 if (len < sizeof(sctp_assoc_t))
88009 return -EINVAL;
88010
88011 + /* Allow the struct to grow and fill in as much as possible */
88012 + len = min_t(size_t, len, sizeof(sas));
88013 +
88014 if (copy_from_user(&sas, optval, len))
88015 return -EFAULT;
88016
88017 @@ -5686,9 +5691,6 @@ static int sctp_getsockopt_assoc_stats(struct sock *sk, int len,
88018 /* Mark beginning of a new observation period */
88019 asoc->stats.max_obs_rto = asoc->rto_min;
88020
88021 - /* Allow the struct to grow and fill in as much as possible */
88022 - len = min_t(size_t, len, sizeof(sas));
88023 -
88024 if (put_user(len, optlen))
88025 return -EFAULT;
88026
88027 diff --git a/net/sctp/ssnmap.c b/net/sctp/ssnmap.c
88028 index 442ad4e..825ea94 100644
88029 --- a/net/sctp/ssnmap.c
88030 +++ b/net/sctp/ssnmap.c
88031 @@ -41,8 +41,6 @@
88032 #include <net/sctp/sctp.h>
88033 #include <net/sctp/sm.h>
88034
88035 -#define MAX_KMALLOC_SIZE 131072
88036 -
88037 static struct sctp_ssnmap *sctp_ssnmap_init(struct sctp_ssnmap *map, __u16 in,
88038 __u16 out);
88039
88040 @@ -65,7 +63,7 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
88041 int size;
88042
88043 size = sctp_ssnmap_size(in, out);
88044 - if (size <= MAX_KMALLOC_SIZE)
88045 + if (size <= KMALLOC_MAX_SIZE)
88046 retval = kmalloc(size, gfp);
88047 else
88048 retval = (struct sctp_ssnmap *)
88049 @@ -82,7 +80,7 @@ struct sctp_ssnmap *sctp_ssnmap_new(__u16 in, __u16 out,
88050 return retval;
88051
88052 fail_map:
88053 - if (size <= MAX_KMALLOC_SIZE)
88054 + if (size <= KMALLOC_MAX_SIZE)
88055 kfree(retval);
88056 else
88057 free_pages((unsigned long)retval, get_order(size));
88058 @@ -124,7 +122,7 @@ void sctp_ssnmap_free(struct sctp_ssnmap *map)
88059 int size;
88060
88061 size = sctp_ssnmap_size(map->in.len, map->out.len);
88062 - if (size <= MAX_KMALLOC_SIZE)
88063 + if (size <= KMALLOC_MAX_SIZE)
88064 kfree(map);
88065 else
88066 free_pages((unsigned long)map, get_order(size));
88067 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
88068 index bf3c6e8..376d8d0 100644
88069 --- a/net/sctp/sysctl.c
88070 +++ b/net/sctp/sysctl.c
88071 @@ -307,7 +307,7 @@ static int proc_sctp_do_hmac_alg(ctl_table *ctl,
88072 {
88073 struct net *net = current->nsproxy->net_ns;
88074 char tmp[8];
88075 - ctl_table tbl;
88076 + ctl_table_no_const tbl;
88077 int ret;
88078 int changed = 0;
88079 char *none = "none";
88080 @@ -350,7 +350,7 @@ static int proc_sctp_do_hmac_alg(ctl_table *ctl,
88081
88082 int sctp_sysctl_net_register(struct net *net)
88083 {
88084 - struct ctl_table *table;
88085 + ctl_table_no_const *table;
88086 int i;
88087
88088 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
88089 diff --git a/net/socket.c b/net/socket.c
88090 index 2ca51c7..45d0b31 100644
88091 --- a/net/socket.c
88092 +++ b/net/socket.c
88093 @@ -89,6 +89,7 @@
88094 #include <linux/magic.h>
88095 #include <linux/slab.h>
88096 #include <linux/xattr.h>
88097 +#include <linux/in.h>
88098
88099 #include <asm/uaccess.h>
88100 #include <asm/unistd.h>
88101 @@ -106,6 +107,8 @@
88102 #include <linux/sockios.h>
88103 #include <linux/atalk.h>
88104
88105 +#include <linux/grsock.h>
88106 +
88107 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
88108 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
88109 unsigned long nr_segs, loff_t pos);
88110 @@ -322,7 +325,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
88111 &sockfs_dentry_operations, SOCKFS_MAGIC);
88112 }
88113
88114 -static struct vfsmount *sock_mnt __read_mostly;
88115 +struct vfsmount *sock_mnt __read_mostly;
88116
88117 static struct file_system_type sock_fs_type = {
88118 .name = "sockfs",
88119 @@ -1270,6 +1273,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
88120 return -EAFNOSUPPORT;
88121 if (type < 0 || type >= SOCK_MAX)
88122 return -EINVAL;
88123 + if (protocol < 0)
88124 + return -EINVAL;
88125
88126 /* Compatibility.
88127
88128 @@ -1401,6 +1406,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
88129 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
88130 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
88131
88132 + if(!gr_search_socket(family, type, protocol)) {
88133 + retval = -EACCES;
88134 + goto out;
88135 + }
88136 +
88137 + if (gr_handle_sock_all(family, type, protocol)) {
88138 + retval = -EACCES;
88139 + goto out;
88140 + }
88141 +
88142 retval = sock_create(family, type, protocol, &sock);
88143 if (retval < 0)
88144 goto out;
88145 @@ -1528,6 +1543,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
88146 if (sock) {
88147 err = move_addr_to_kernel(umyaddr, addrlen, &address);
88148 if (err >= 0) {
88149 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
88150 + err = -EACCES;
88151 + goto error;
88152 + }
88153 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
88154 + if (err)
88155 + goto error;
88156 +
88157 err = security_socket_bind(sock,
88158 (struct sockaddr *)&address,
88159 addrlen);
88160 @@ -1536,6 +1559,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
88161 (struct sockaddr *)
88162 &address, addrlen);
88163 }
88164 +error:
88165 fput_light(sock->file, fput_needed);
88166 }
88167 return err;
88168 @@ -1559,10 +1583,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
88169 if ((unsigned int)backlog > somaxconn)
88170 backlog = somaxconn;
88171
88172 + if (gr_handle_sock_server_other(sock->sk)) {
88173 + err = -EPERM;
88174 + goto error;
88175 + }
88176 +
88177 + err = gr_search_listen(sock);
88178 + if (err)
88179 + goto error;
88180 +
88181 err = security_socket_listen(sock, backlog);
88182 if (!err)
88183 err = sock->ops->listen(sock, backlog);
88184
88185 +error:
88186 fput_light(sock->file, fput_needed);
88187 }
88188 return err;
88189 @@ -1606,6 +1640,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
88190 newsock->type = sock->type;
88191 newsock->ops = sock->ops;
88192
88193 + if (gr_handle_sock_server_other(sock->sk)) {
88194 + err = -EPERM;
88195 + sock_release(newsock);
88196 + goto out_put;
88197 + }
88198 +
88199 + err = gr_search_accept(sock);
88200 + if (err) {
88201 + sock_release(newsock);
88202 + goto out_put;
88203 + }
88204 +
88205 /*
88206 * We don't need try_module_get here, as the listening socket (sock)
88207 * has the protocol module (sock->ops->owner) held.
88208 @@ -1651,6 +1697,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
88209 fd_install(newfd, newfile);
88210 err = newfd;
88211
88212 + gr_attach_curr_ip(newsock->sk);
88213 +
88214 out_put:
88215 fput_light(sock->file, fput_needed);
88216 out:
88217 @@ -1683,6 +1731,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
88218 int, addrlen)
88219 {
88220 struct socket *sock;
88221 + struct sockaddr *sck;
88222 struct sockaddr_storage address;
88223 int err, fput_needed;
88224
88225 @@ -1693,6 +1742,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
88226 if (err < 0)
88227 goto out_put;
88228
88229 + sck = (struct sockaddr *)&address;
88230 +
88231 + if (gr_handle_sock_client(sck)) {
88232 + err = -EACCES;
88233 + goto out_put;
88234 + }
88235 +
88236 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
88237 + if (err)
88238 + goto out_put;
88239 +
88240 err =
88241 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
88242 if (err)
88243 @@ -2047,7 +2107,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
88244 * checking falls down on this.
88245 */
88246 if (copy_from_user(ctl_buf,
88247 - (void __user __force *)msg_sys->msg_control,
88248 + (void __force_user *)msg_sys->msg_control,
88249 ctl_len))
88250 goto out_freectl;
88251 msg_sys->msg_control = ctl_buf;
88252 @@ -2215,7 +2275,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
88253 * kernel msghdr to use the kernel address space)
88254 */
88255
88256 - uaddr = (__force void __user *)msg_sys->msg_name;
88257 + uaddr = (void __force_user *)msg_sys->msg_name;
88258 uaddr_len = COMPAT_NAMELEN(msg);
88259 if (MSG_CMSG_COMPAT & flags) {
88260 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
88261 @@ -2838,7 +2898,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
88262 }
88263
88264 ifr = compat_alloc_user_space(buf_size);
88265 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
88266 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
88267
88268 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
88269 return -EFAULT;
88270 @@ -2862,12 +2922,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
88271 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
88272
88273 if (copy_in_user(rxnfc, compat_rxnfc,
88274 - (void *)(&rxnfc->fs.m_ext + 1) -
88275 - (void *)rxnfc) ||
88276 + (void __user *)(&rxnfc->fs.m_ext + 1) -
88277 + (void __user *)rxnfc) ||
88278 copy_in_user(&rxnfc->fs.ring_cookie,
88279 &compat_rxnfc->fs.ring_cookie,
88280 - (void *)(&rxnfc->fs.location + 1) -
88281 - (void *)&rxnfc->fs.ring_cookie) ||
88282 + (void __user *)(&rxnfc->fs.location + 1) -
88283 + (void __user *)&rxnfc->fs.ring_cookie) ||
88284 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
88285 sizeof(rxnfc->rule_cnt)))
88286 return -EFAULT;
88287 @@ -2879,12 +2939,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
88288
88289 if (convert_out) {
88290 if (copy_in_user(compat_rxnfc, rxnfc,
88291 - (const void *)(&rxnfc->fs.m_ext + 1) -
88292 - (const void *)rxnfc) ||
88293 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
88294 + (const void __user *)rxnfc) ||
88295 copy_in_user(&compat_rxnfc->fs.ring_cookie,
88296 &rxnfc->fs.ring_cookie,
88297 - (const void *)(&rxnfc->fs.location + 1) -
88298 - (const void *)&rxnfc->fs.ring_cookie) ||
88299 + (const void __user *)(&rxnfc->fs.location + 1) -
88300 + (const void __user *)&rxnfc->fs.ring_cookie) ||
88301 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
88302 sizeof(rxnfc->rule_cnt)))
88303 return -EFAULT;
88304 @@ -2954,7 +3014,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
88305 old_fs = get_fs();
88306 set_fs(KERNEL_DS);
88307 err = dev_ioctl(net, cmd,
88308 - (struct ifreq __user __force *) &kifr);
88309 + (struct ifreq __force_user *) &kifr);
88310 set_fs(old_fs);
88311
88312 return err;
88313 @@ -3063,7 +3123,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
88314
88315 old_fs = get_fs();
88316 set_fs(KERNEL_DS);
88317 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
88318 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
88319 set_fs(old_fs);
88320
88321 if (cmd == SIOCGIFMAP && !err) {
88322 @@ -3168,7 +3228,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
88323 ret |= __get_user(rtdev, &(ur4->rt_dev));
88324 if (rtdev) {
88325 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
88326 - r4.rt_dev = (char __user __force *)devname;
88327 + r4.rt_dev = (char __force_user *)devname;
88328 devname[15] = 0;
88329 } else
88330 r4.rt_dev = NULL;
88331 @@ -3394,8 +3454,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
88332 int __user *uoptlen;
88333 int err;
88334
88335 - uoptval = (char __user __force *) optval;
88336 - uoptlen = (int __user __force *) optlen;
88337 + uoptval = (char __force_user *) optval;
88338 + uoptlen = (int __force_user *) optlen;
88339
88340 set_fs(KERNEL_DS);
88341 if (level == SOL_SOCKET)
88342 @@ -3415,7 +3475,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
88343 char __user *uoptval;
88344 int err;
88345
88346 - uoptval = (char __user __force *) optval;
88347 + uoptval = (char __force_user *) optval;
88348
88349 set_fs(KERNEL_DS);
88350 if (level == SOL_SOCKET)
88351 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
88352 index 507b5e8..049e64a 100644
88353 --- a/net/sunrpc/clnt.c
88354 +++ b/net/sunrpc/clnt.c
88355 @@ -1272,7 +1272,9 @@ call_start(struct rpc_task *task)
88356 (RPC_IS_ASYNC(task) ? "async" : "sync"));
88357
88358 /* Increment call count */
88359 - task->tk_msg.rpc_proc->p_count++;
88360 + pax_open_kernel();
88361 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
88362 + pax_close_kernel();
88363 clnt->cl_stats->rpccnt++;
88364 task->tk_action = call_reserve;
88365 }
88366 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
88367 index fb20f25..e3ba316 100644
88368 --- a/net/sunrpc/sched.c
88369 +++ b/net/sunrpc/sched.c
88370 @@ -259,9 +259,9 @@ static int rpc_wait_bit_killable(void *word)
88371 #ifdef RPC_DEBUG
88372 static void rpc_task_set_debuginfo(struct rpc_task *task)
88373 {
88374 - static atomic_t rpc_pid;
88375 + static atomic_unchecked_t rpc_pid;
88376
88377 - task->tk_pid = atomic_inc_return(&rpc_pid);
88378 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
88379 }
88380 #else
88381 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
88382 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
88383 index 2d34b6b..e2d584d 100644
88384 --- a/net/sunrpc/svc.c
88385 +++ b/net/sunrpc/svc.c
88386 @@ -1156,7 +1156,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
88387 svc_putnl(resv, RPC_SUCCESS);
88388
88389 /* Bump per-procedure stats counter */
88390 - procp->pc_count++;
88391 + pax_open_kernel();
88392 + (*(unsigned int *)&procp->pc_count)++;
88393 + pax_close_kernel();
88394
88395 /* Initialize storage for argp and resp */
88396 memset(rqstp->rq_argp, 0, procp->pc_argsize);
88397 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
88398 index 8343737..677025e 100644
88399 --- a/net/sunrpc/xprtrdma/svc_rdma.c
88400 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
88401 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
88402 static unsigned int min_max_inline = 4096;
88403 static unsigned int max_max_inline = 65536;
88404
88405 -atomic_t rdma_stat_recv;
88406 -atomic_t rdma_stat_read;
88407 -atomic_t rdma_stat_write;
88408 -atomic_t rdma_stat_sq_starve;
88409 -atomic_t rdma_stat_rq_starve;
88410 -atomic_t rdma_stat_rq_poll;
88411 -atomic_t rdma_stat_rq_prod;
88412 -atomic_t rdma_stat_sq_poll;
88413 -atomic_t rdma_stat_sq_prod;
88414 +atomic_unchecked_t rdma_stat_recv;
88415 +atomic_unchecked_t rdma_stat_read;
88416 +atomic_unchecked_t rdma_stat_write;
88417 +atomic_unchecked_t rdma_stat_sq_starve;
88418 +atomic_unchecked_t rdma_stat_rq_starve;
88419 +atomic_unchecked_t rdma_stat_rq_poll;
88420 +atomic_unchecked_t rdma_stat_rq_prod;
88421 +atomic_unchecked_t rdma_stat_sq_poll;
88422 +atomic_unchecked_t rdma_stat_sq_prod;
88423
88424 /* Temporary NFS request map and context caches */
88425 struct kmem_cache *svc_rdma_map_cachep;
88426 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
88427 len -= *ppos;
88428 if (len > *lenp)
88429 len = *lenp;
88430 - if (len && copy_to_user(buffer, str_buf, len))
88431 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
88432 return -EFAULT;
88433 *lenp = len;
88434 *ppos += len;
88435 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
88436 {
88437 .procname = "rdma_stat_read",
88438 .data = &rdma_stat_read,
88439 - .maxlen = sizeof(atomic_t),
88440 + .maxlen = sizeof(atomic_unchecked_t),
88441 .mode = 0644,
88442 .proc_handler = read_reset_stat,
88443 },
88444 {
88445 .procname = "rdma_stat_recv",
88446 .data = &rdma_stat_recv,
88447 - .maxlen = sizeof(atomic_t),
88448 + .maxlen = sizeof(atomic_unchecked_t),
88449 .mode = 0644,
88450 .proc_handler = read_reset_stat,
88451 },
88452 {
88453 .procname = "rdma_stat_write",
88454 .data = &rdma_stat_write,
88455 - .maxlen = sizeof(atomic_t),
88456 + .maxlen = sizeof(atomic_unchecked_t),
88457 .mode = 0644,
88458 .proc_handler = read_reset_stat,
88459 },
88460 {
88461 .procname = "rdma_stat_sq_starve",
88462 .data = &rdma_stat_sq_starve,
88463 - .maxlen = sizeof(atomic_t),
88464 + .maxlen = sizeof(atomic_unchecked_t),
88465 .mode = 0644,
88466 .proc_handler = read_reset_stat,
88467 },
88468 {
88469 .procname = "rdma_stat_rq_starve",
88470 .data = &rdma_stat_rq_starve,
88471 - .maxlen = sizeof(atomic_t),
88472 + .maxlen = sizeof(atomic_unchecked_t),
88473 .mode = 0644,
88474 .proc_handler = read_reset_stat,
88475 },
88476 {
88477 .procname = "rdma_stat_rq_poll",
88478 .data = &rdma_stat_rq_poll,
88479 - .maxlen = sizeof(atomic_t),
88480 + .maxlen = sizeof(atomic_unchecked_t),
88481 .mode = 0644,
88482 .proc_handler = read_reset_stat,
88483 },
88484 {
88485 .procname = "rdma_stat_rq_prod",
88486 .data = &rdma_stat_rq_prod,
88487 - .maxlen = sizeof(atomic_t),
88488 + .maxlen = sizeof(atomic_unchecked_t),
88489 .mode = 0644,
88490 .proc_handler = read_reset_stat,
88491 },
88492 {
88493 .procname = "rdma_stat_sq_poll",
88494 .data = &rdma_stat_sq_poll,
88495 - .maxlen = sizeof(atomic_t),
88496 + .maxlen = sizeof(atomic_unchecked_t),
88497 .mode = 0644,
88498 .proc_handler = read_reset_stat,
88499 },
88500 {
88501 .procname = "rdma_stat_sq_prod",
88502 .data = &rdma_stat_sq_prod,
88503 - .maxlen = sizeof(atomic_t),
88504 + .maxlen = sizeof(atomic_unchecked_t),
88505 .mode = 0644,
88506 .proc_handler = read_reset_stat,
88507 },
88508 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88509 index 0ce7552..d074459 100644
88510 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88511 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
88512 @@ -501,7 +501,7 @@ next_sge:
88513 svc_rdma_put_context(ctxt, 0);
88514 goto out;
88515 }
88516 - atomic_inc(&rdma_stat_read);
88517 + atomic_inc_unchecked(&rdma_stat_read);
88518
88519 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
88520 chl_map->ch[ch_no].count -= read_wr.num_sge;
88521 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
88522 dto_q);
88523 list_del_init(&ctxt->dto_q);
88524 } else {
88525 - atomic_inc(&rdma_stat_rq_starve);
88526 + atomic_inc_unchecked(&rdma_stat_rq_starve);
88527 clear_bit(XPT_DATA, &xprt->xpt_flags);
88528 ctxt = NULL;
88529 }
88530 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
88531 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
88532 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
88533 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
88534 - atomic_inc(&rdma_stat_recv);
88535 + atomic_inc_unchecked(&rdma_stat_recv);
88536
88537 /* Build up the XDR from the receive buffers. */
88538 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
88539 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88540 index c1d124d..acfc59e 100644
88541 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88542 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
88543 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
88544 write_wr.wr.rdma.remote_addr = to;
88545
88546 /* Post It */
88547 - atomic_inc(&rdma_stat_write);
88548 + atomic_inc_unchecked(&rdma_stat_write);
88549 if (svc_rdma_send(xprt, &write_wr))
88550 goto err;
88551 return 0;
88552 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
88553 index 62e4f9b..dd3f2d7 100644
88554 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
88555 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
88556 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
88557 return;
88558
88559 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
88560 - atomic_inc(&rdma_stat_rq_poll);
88561 + atomic_inc_unchecked(&rdma_stat_rq_poll);
88562
88563 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
88564 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
88565 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
88566 }
88567
88568 if (ctxt)
88569 - atomic_inc(&rdma_stat_rq_prod);
88570 + atomic_inc_unchecked(&rdma_stat_rq_prod);
88571
88572 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
88573 /*
88574 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
88575 return;
88576
88577 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
88578 - atomic_inc(&rdma_stat_sq_poll);
88579 + atomic_inc_unchecked(&rdma_stat_sq_poll);
88580 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
88581 if (wc.status != IB_WC_SUCCESS)
88582 /* Close the transport */
88583 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
88584 }
88585
88586 if (ctxt)
88587 - atomic_inc(&rdma_stat_sq_prod);
88588 + atomic_inc_unchecked(&rdma_stat_sq_prod);
88589 }
88590
88591 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
88592 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
88593 spin_lock_bh(&xprt->sc_lock);
88594 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
88595 spin_unlock_bh(&xprt->sc_lock);
88596 - atomic_inc(&rdma_stat_sq_starve);
88597 + atomic_inc_unchecked(&rdma_stat_sq_starve);
88598
88599 /* See if we can opportunistically reap SQ WR to make room */
88600 sq_cq_reap(xprt);
88601 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
88602 index 9bc6db0..47ac8c0 100644
88603 --- a/net/sysctl_net.c
88604 +++ b/net/sysctl_net.c
88605 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
88606 kgid_t root_gid = make_kgid(net->user_ns, 0);
88607
88608 /* Allow network administrator to have same access as root. */
88609 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
88610 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
88611 uid_eq(root_uid, current_uid())) {
88612 int mode = (table->mode >> 6) & 7;
88613 return (mode << 6) | (mode << 3) | mode;
88614 diff --git a/net/tipc/link.c b/net/tipc/link.c
88615 index daa6080..02d357f 100644
88616 --- a/net/tipc/link.c
88617 +++ b/net/tipc/link.c
88618 @@ -1201,7 +1201,7 @@ static int link_send_sections_long(struct tipc_port *sender,
88619 struct tipc_msg fragm_hdr;
88620 struct sk_buff *buf, *buf_chain, *prev;
88621 u32 fragm_crs, fragm_rest, hsz, sect_rest;
88622 - const unchar *sect_crs;
88623 + const unchar __user *sect_crs;
88624 int curr_sect;
88625 u32 fragm_no;
88626
88627 @@ -1242,7 +1242,7 @@ again:
88628
88629 if (!sect_rest) {
88630 sect_rest = msg_sect[++curr_sect].iov_len;
88631 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
88632 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
88633 }
88634
88635 if (sect_rest < fragm_rest)
88636 @@ -1261,7 +1261,7 @@ error:
88637 }
88638 } else
88639 skb_copy_to_linear_data_offset(buf, fragm_crs,
88640 - sect_crs, sz);
88641 + (const void __force_kernel *)sect_crs, sz);
88642 sect_crs += sz;
88643 sect_rest -= sz;
88644 fragm_crs += sz;
88645 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
88646 index f2db8a8..9245aa4 100644
88647 --- a/net/tipc/msg.c
88648 +++ b/net/tipc/msg.c
88649 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
88650 msg_sect[cnt].iov_len);
88651 else
88652 skb_copy_to_linear_data_offset(*buf, pos,
88653 - msg_sect[cnt].iov_base,
88654 + (const void __force_kernel *)msg_sect[cnt].iov_base,
88655 msg_sect[cnt].iov_len);
88656 pos += msg_sect[cnt].iov_len;
88657 }
88658 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
88659 index 6b42d47..2ac24d5 100644
88660 --- a/net/tipc/subscr.c
88661 +++ b/net/tipc/subscr.c
88662 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
88663 {
88664 struct iovec msg_sect;
88665
88666 - msg_sect.iov_base = (void *)&sub->evt;
88667 + msg_sect.iov_base = (void __force_user *)&sub->evt;
88668 msg_sect.iov_len = sizeof(struct tipc_event);
88669
88670 sub->evt.event = htohl(event, sub->swap);
88671 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
88672 index 5b5c876..3127bf7 100644
88673 --- a/net/unix/af_unix.c
88674 +++ b/net/unix/af_unix.c
88675 @@ -786,6 +786,12 @@ static struct sock *unix_find_other(struct net *net,
88676 err = -ECONNREFUSED;
88677 if (!S_ISSOCK(inode->i_mode))
88678 goto put_fail;
88679 +
88680 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
88681 + err = -EACCES;
88682 + goto put_fail;
88683 + }
88684 +
88685 u = unix_find_socket_byinode(inode);
88686 if (!u)
88687 goto put_fail;
88688 @@ -806,6 +812,13 @@ static struct sock *unix_find_other(struct net *net,
88689 if (u) {
88690 struct dentry *dentry;
88691 dentry = unix_sk(u)->path.dentry;
88692 +
88693 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
88694 + err = -EPERM;
88695 + sock_put(u);
88696 + goto fail;
88697 + }
88698 +
88699 if (dentry)
88700 touch_atime(&unix_sk(u)->path);
88701 } else
88702 @@ -839,12 +852,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
88703 */
88704 err = security_path_mknod(&path, dentry, mode, 0);
88705 if (!err) {
88706 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
88707 + err = -EACCES;
88708 + goto out;
88709 + }
88710 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
88711 if (!err) {
88712 res->mnt = mntget(path.mnt);
88713 res->dentry = dget(dentry);
88714 + gr_handle_create(dentry, path.mnt);
88715 }
88716 }
88717 +out:
88718 done_path_create(&path, dentry);
88719 return err;
88720 }
88721 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
88722 index 8800604..0526440 100644
88723 --- a/net/unix/sysctl_net_unix.c
88724 +++ b/net/unix/sysctl_net_unix.c
88725 @@ -28,7 +28,7 @@ static ctl_table unix_table[] = {
88726
88727 int __net_init unix_sysctl_register(struct net *net)
88728 {
88729 - struct ctl_table *table;
88730 + ctl_table_no_const *table;
88731
88732 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
88733 if (table == NULL)
88734 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
88735 index c8717c1..08539f5 100644
88736 --- a/net/wireless/wext-core.c
88737 +++ b/net/wireless/wext-core.c
88738 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
88739 */
88740
88741 /* Support for very large requests */
88742 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
88743 - (user_length > descr->max_tokens)) {
88744 + if (user_length > descr->max_tokens) {
88745 /* Allow userspace to GET more than max so
88746 * we can support any size GET requests.
88747 * There is still a limit : -ENOMEM.
88748 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
88749 }
88750 }
88751
88752 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
88753 - /*
88754 - * If this is a GET, but not NOMAX, it means that the extra
88755 - * data is not bounded by userspace, but by max_tokens. Thus
88756 - * set the length to max_tokens. This matches the extra data
88757 - * allocation.
88758 - * The driver should fill it with the number of tokens it
88759 - * provided, and it may check iwp->length rather than having
88760 - * knowledge of max_tokens. If the driver doesn't change the
88761 - * iwp->length, this ioctl just copies back max_token tokens
88762 - * filled with zeroes. Hopefully the driver isn't claiming
88763 - * them to be valid data.
88764 - */
88765 - iwp->length = descr->max_tokens;
88766 - }
88767 -
88768 err = handler(dev, info, (union iwreq_data *) iwp, extra);
88769
88770 iwp->length += essid_compat;
88771 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
88772 index 07c5857..fde4018 100644
88773 --- a/net/xfrm/xfrm_policy.c
88774 +++ b/net/xfrm/xfrm_policy.c
88775 @@ -317,7 +317,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
88776 {
88777 policy->walk.dead = 1;
88778
88779 - atomic_inc(&policy->genid);
88780 + atomic_inc_unchecked(&policy->genid);
88781
88782 if (del_timer(&policy->timer))
88783 xfrm_pol_put(policy);
88784 @@ -601,7 +601,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
88785 hlist_add_head(&policy->bydst, chain);
88786 xfrm_pol_hold(policy);
88787 net->xfrm.policy_count[dir]++;
88788 - atomic_inc(&flow_cache_genid);
88789 + atomic_inc_unchecked(&flow_cache_genid);
88790 rt_genid_bump(net);
88791 if (delpol)
88792 __xfrm_policy_unlink(delpol, dir);
88793 @@ -1550,7 +1550,7 @@ free_dst:
88794 goto out;
88795 }
88796
88797 -static int inline
88798 +static inline int
88799 xfrm_dst_alloc_copy(void **target, const void *src, int size)
88800 {
88801 if (!*target) {
88802 @@ -1562,7 +1562,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
88803 return 0;
88804 }
88805
88806 -static int inline
88807 +static inline int
88808 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
88809 {
88810 #ifdef CONFIG_XFRM_SUB_POLICY
88811 @@ -1574,7 +1574,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
88812 #endif
88813 }
88814
88815 -static int inline
88816 +static inline int
88817 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
88818 {
88819 #ifdef CONFIG_XFRM_SUB_POLICY
88820 @@ -1668,7 +1668,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
88821
88822 xdst->num_pols = num_pols;
88823 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
88824 - xdst->policy_genid = atomic_read(&pols[0]->genid);
88825 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
88826
88827 return xdst;
88828 }
88829 @@ -2369,7 +2369,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
88830 if (xdst->xfrm_genid != dst->xfrm->genid)
88831 return 0;
88832 if (xdst->num_pols > 0 &&
88833 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
88834 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
88835 return 0;
88836
88837 mtu = dst_mtu(dst->child);
88838 @@ -2457,8 +2457,11 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
88839 dst_ops->link_failure = xfrm_link_failure;
88840 if (likely(dst_ops->neigh_lookup == NULL))
88841 dst_ops->neigh_lookup = xfrm_neigh_lookup;
88842 - if (likely(afinfo->garbage_collect == NULL))
88843 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
88844 + if (likely(afinfo->garbage_collect == NULL)) {
88845 + pax_open_kernel();
88846 + *(void **)&afinfo->garbage_collect = xfrm_garbage_collect_deferred;
88847 + pax_close_kernel();
88848 + }
88849 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
88850 }
88851 spin_unlock(&xfrm_policy_afinfo_lock);
88852 @@ -2512,7 +2515,9 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
88853 dst_ops->check = NULL;
88854 dst_ops->negative_advice = NULL;
88855 dst_ops->link_failure = NULL;
88856 - afinfo->garbage_collect = NULL;
88857 + pax_open_kernel();
88858 + *(void **)&afinfo->garbage_collect = NULL;
88859 + pax_close_kernel();
88860 }
88861 return err;
88862 }
88863 @@ -2896,7 +2901,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
88864 sizeof(pol->xfrm_vec[i].saddr));
88865 pol->xfrm_vec[i].encap_family = mp->new_family;
88866 /* flush bundles */
88867 - atomic_inc(&pol->genid);
88868 + atomic_inc_unchecked(&pol->genid);
88869 }
88870 }
88871
88872 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
88873 index 3459692..e7cdb1a 100644
88874 --- a/net/xfrm/xfrm_state.c
88875 +++ b/net/xfrm/xfrm_state.c
88876 @@ -194,11 +194,13 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
88877
88878 if (unlikely(afinfo == NULL))
88879 return -EAFNOSUPPORT;
88880 - typemap = afinfo->type_map;
88881 + typemap = (const struct xfrm_type **)afinfo->type_map;
88882
88883 - if (likely(typemap[type->proto] == NULL))
88884 + if (likely(typemap[type->proto] == NULL)) {
88885 + pax_open_kernel();
88886 typemap[type->proto] = type;
88887 - else
88888 + pax_close_kernel();
88889 + } else
88890 err = -EEXIST;
88891 xfrm_state_unlock_afinfo(afinfo);
88892 return err;
88893 @@ -213,12 +215,15 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
88894
88895 if (unlikely(afinfo == NULL))
88896 return -EAFNOSUPPORT;
88897 - typemap = afinfo->type_map;
88898 + typemap = (const struct xfrm_type **)afinfo->type_map;
88899
88900 if (unlikely(typemap[type->proto] != type))
88901 err = -ENOENT;
88902 - else
88903 + else {
88904 + pax_open_kernel();
88905 typemap[type->proto] = NULL;
88906 + pax_close_kernel();
88907 + }
88908 xfrm_state_unlock_afinfo(afinfo);
88909 return err;
88910 }
88911 @@ -227,7 +232,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
88912 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
88913 {
88914 struct xfrm_state_afinfo *afinfo;
88915 - const struct xfrm_type **typemap;
88916 const struct xfrm_type *type;
88917 int modload_attempted = 0;
88918
88919 @@ -235,9 +239,8 @@ retry:
88920 afinfo = xfrm_state_get_afinfo(family);
88921 if (unlikely(afinfo == NULL))
88922 return NULL;
88923 - typemap = afinfo->type_map;
88924
88925 - type = typemap[proto];
88926 + type = afinfo->type_map[proto];
88927 if (unlikely(type && !try_module_get(type->owner)))
88928 type = NULL;
88929 if (!type && !modload_attempted) {
88930 @@ -270,7 +273,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
88931 return -EAFNOSUPPORT;
88932
88933 err = -EEXIST;
88934 - modemap = afinfo->mode_map;
88935 + modemap = (struct xfrm_mode **)afinfo->mode_map;
88936 if (modemap[mode->encap])
88937 goto out;
88938
88939 @@ -278,8 +281,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
88940 if (!try_module_get(afinfo->owner))
88941 goto out;
88942
88943 - mode->afinfo = afinfo;
88944 + pax_open_kernel();
88945 + *(const void **)&mode->afinfo = afinfo;
88946 modemap[mode->encap] = mode;
88947 + pax_close_kernel();
88948 err = 0;
88949
88950 out:
88951 @@ -302,9 +307,11 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
88952 return -EAFNOSUPPORT;
88953
88954 err = -ENOENT;
88955 - modemap = afinfo->mode_map;
88956 + modemap = (struct xfrm_mode **)afinfo->mode_map;
88957 if (likely(modemap[mode->encap] == mode)) {
88958 + pax_open_kernel();
88959 modemap[mode->encap] = NULL;
88960 + pax_close_kernel();
88961 module_put(mode->afinfo->owner);
88962 err = 0;
88963 }
88964 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
88965 index 05a6e3d..6716ec9 100644
88966 --- a/net/xfrm/xfrm_sysctl.c
88967 +++ b/net/xfrm/xfrm_sysctl.c
88968 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
88969
88970 int __net_init xfrm_sysctl_init(struct net *net)
88971 {
88972 - struct ctl_table *table;
88973 + ctl_table_no_const *table;
88974
88975 __xfrm_sysctl_init(net);
88976
88977 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
88978 index 0e801c3..5c8ad3b 100644
88979 --- a/scripts/Makefile.build
88980 +++ b/scripts/Makefile.build
88981 @@ -111,7 +111,7 @@ endif
88982 endif
88983
88984 # Do not include host rules unless needed
88985 -ifneq ($(hostprogs-y)$(hostprogs-m),)
88986 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
88987 include scripts/Makefile.host
88988 endif
88989
88990 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
88991 index 686cb0d..9d653bf 100644
88992 --- a/scripts/Makefile.clean
88993 +++ b/scripts/Makefile.clean
88994 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
88995 __clean-files := $(extra-y) $(always) \
88996 $(targets) $(clean-files) \
88997 $(host-progs) \
88998 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
88999 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
89000 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
89001
89002 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
89003
89004 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
89005 index 1ac414f..38575f7 100644
89006 --- a/scripts/Makefile.host
89007 +++ b/scripts/Makefile.host
89008 @@ -31,6 +31,8 @@
89009 # Note: Shared libraries consisting of C++ files are not supported
89010
89011 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
89012 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
89013 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
89014
89015 # C code
89016 # Executables compiled from a single .c file
89017 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
89018 # Shared libaries (only .c supported)
89019 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
89020 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
89021 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
89022 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
89023 # Remove .so files from "xxx-objs"
89024 host-cobjs := $(filter-out %.so,$(host-cobjs))
89025 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
89026
89027 -#Object (.o) files used by the shared libaries
89028 +# Object (.o) files used by the shared libaries
89029 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
89030 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
89031
89032 # output directory for programs/.o files
89033 # hostprogs-y := tools/build may have been specified. Retrieve directory
89034 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
89035 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
89036 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
89037 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
89038 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
89039 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
89040 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
89041 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
89042
89043 obj-dirs += $(host-objdirs)
89044 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
89045 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
89046 $(call if_changed_dep,host-cshobjs)
89047
89048 +# Compile .c file, create position independent .o file
89049 +# host-cxxshobjs -> .o
89050 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
89051 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
89052 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
89053 + $(call if_changed_dep,host-cxxshobjs)
89054 +
89055 # Link a shared library, based on position independent .o files
89056 # *.o -> .so shared library (host-cshlib)
89057 quiet_cmd_host-cshlib = HOSTLLD -shared $@
89058 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
89059 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
89060 $(call if_changed,host-cshlib)
89061
89062 +# Link a shared library, based on position independent .o files
89063 +# *.o -> .so shared library (host-cxxshlib)
89064 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
89065 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
89066 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
89067 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
89068 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
89069 + $(call if_changed,host-cxxshlib)
89070 +
89071 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
89072 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
89073 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
89074
89075 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
89076 index cb1f50c..cef2a7c 100644
89077 --- a/scripts/basic/fixdep.c
89078 +++ b/scripts/basic/fixdep.c
89079 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
89080 /*
89081 * Lookup a value in the configuration string.
89082 */
89083 -static int is_defined_config(const char *name, int len, unsigned int hash)
89084 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
89085 {
89086 struct item *aux;
89087
89088 @@ -211,10 +211,10 @@ static void clear_config(void)
89089 /*
89090 * Record the use of a CONFIG_* word.
89091 */
89092 -static void use_config(const char *m, int slen)
89093 +static void use_config(const char *m, unsigned int slen)
89094 {
89095 unsigned int hash = strhash(m, slen);
89096 - int c, i;
89097 + unsigned int c, i;
89098
89099 if (is_defined_config(m, slen, hash))
89100 return;
89101 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
89102
89103 static void parse_config_file(const char *map, size_t len)
89104 {
89105 - const int *end = (const int *) (map + len);
89106 + const unsigned int *end = (const unsigned int *) (map + len);
89107 /* start at +1, so that p can never be < map */
89108 - const int *m = (const int *) map + 1;
89109 + const unsigned int *m = (const unsigned int *) map + 1;
89110 const char *p, *q;
89111
89112 for (; m < end; m++) {
89113 @@ -406,7 +406,7 @@ static void print_deps(void)
89114 static void traps(void)
89115 {
89116 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
89117 - int *p = (int *)test;
89118 + unsigned int *p = (unsigned int *)test;
89119
89120 if (*p != INT_CONF) {
89121 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
89122 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
89123 new file mode 100644
89124 index 0000000..5e0222d
89125 --- /dev/null
89126 +++ b/scripts/gcc-plugin.sh
89127 @@ -0,0 +1,17 @@
89128 +#!/bin/bash
89129 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
89130 +#include "gcc-plugin.h"
89131 +#include "tree.h"
89132 +#include "tm.h"
89133 +#include "rtl.h"
89134 +#ifdef ENABLE_BUILD_WITH_CXX
89135 +#warning $2
89136 +#else
89137 +#warning $1
89138 +#endif
89139 +EOF`
89140 +if [ $? -eq 0 ]
89141 +then
89142 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
89143 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
89144 +fi
89145 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
89146 index b3d907e..a4782ab 100644
89147 --- a/scripts/link-vmlinux.sh
89148 +++ b/scripts/link-vmlinux.sh
89149 @@ -152,7 +152,7 @@ else
89150 fi;
89151
89152 # final build of init/
89153 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
89154 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
89155
89156 kallsymso=""
89157 kallsyms_vmlinux=""
89158 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
89159 index df4fc23..0ea719d 100644
89160 --- a/scripts/mod/file2alias.c
89161 +++ b/scripts/mod/file2alias.c
89162 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
89163 unsigned long size, unsigned long id_size,
89164 void *symval)
89165 {
89166 - int i;
89167 + unsigned int i;
89168
89169 if (size % id_size || size < id_size) {
89170 if (cross_build != 0)
89171 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
89172 /* USB is special because the bcdDevice can be matched against a numeric range */
89173 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
89174 static void do_usb_entry(struct usb_device_id *id,
89175 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
89176 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
89177 unsigned char range_lo, unsigned char range_hi,
89178 unsigned char max, struct module *mod)
89179 {
89180 @@ -262,7 +262,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
89181 {
89182 unsigned int devlo, devhi;
89183 unsigned char chi, clo, max;
89184 - int ndigits;
89185 + unsigned int ndigits;
89186
89187 id->match_flags = TO_NATIVE(id->match_flags);
89188 id->idVendor = TO_NATIVE(id->idVendor);
89189 @@ -507,7 +507,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
89190 for (i = 0; i < count; i++) {
89191 const char *id = (char *)devs[i].id;
89192 char acpi_id[sizeof(devs[0].id)];
89193 - int j;
89194 + unsigned int j;
89195
89196 buf_printf(&mod->dev_table_buf,
89197 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
89198 @@ -537,7 +537,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
89199
89200 for (j = 0; j < PNP_MAX_DEVICES; j++) {
89201 const char *id = (char *)card->devs[j].id;
89202 - int i2, j2;
89203 + unsigned int i2, j2;
89204 int dup = 0;
89205
89206 if (!id[0])
89207 @@ -563,7 +563,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
89208 /* add an individual alias for every device entry */
89209 if (!dup) {
89210 char acpi_id[sizeof(card->devs[0].id)];
89211 - int k;
89212 + unsigned int k;
89213
89214 buf_printf(&mod->dev_table_buf,
89215 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
89216 @@ -888,7 +888,7 @@ static void dmi_ascii_filter(char *d, const char *s)
89217 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
89218 char *alias)
89219 {
89220 - int i, j;
89221 + unsigned int i, j;
89222
89223 sprintf(alias, "dmi*");
89224
89225 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
89226 index ff36c50..7ab4fa9 100644
89227 --- a/scripts/mod/modpost.c
89228 +++ b/scripts/mod/modpost.c
89229 @@ -929,6 +929,7 @@ enum mismatch {
89230 ANY_INIT_TO_ANY_EXIT,
89231 ANY_EXIT_TO_ANY_INIT,
89232 EXPORT_TO_INIT_EXIT,
89233 + DATA_TO_TEXT
89234 };
89235
89236 struct sectioncheck {
89237 @@ -1043,6 +1044,12 @@ const struct sectioncheck sectioncheck[] = {
89238 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
89239 .mismatch = EXPORT_TO_INIT_EXIT,
89240 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
89241 +},
89242 +/* Do not reference code from writable data */
89243 +{
89244 + .fromsec = { DATA_SECTIONS, NULL },
89245 + .tosec = { TEXT_SECTIONS, NULL },
89246 + .mismatch = DATA_TO_TEXT
89247 }
89248 };
89249
89250 @@ -1165,10 +1172,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
89251 continue;
89252 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
89253 continue;
89254 - if (sym->st_value == addr)
89255 - return sym;
89256 /* Find a symbol nearby - addr are maybe negative */
89257 d = sym->st_value - addr;
89258 + if (d == 0)
89259 + return sym;
89260 if (d < 0)
89261 d = addr - sym->st_value;
89262 if (d < distance) {
89263 @@ -1447,6 +1454,14 @@ static void report_sec_mismatch(const char *modname,
89264 tosym, prl_to, prl_to, tosym);
89265 free(prl_to);
89266 break;
89267 + case DATA_TO_TEXT:
89268 +#if 0
89269 + fprintf(stderr,
89270 + "The %s %s:%s references\n"
89271 + "the %s %s:%s%s\n",
89272 + from, fromsec, fromsym, to, tosec, tosym, to_p);
89273 +#endif
89274 + break;
89275 }
89276 fprintf(stderr, "\n");
89277 }
89278 @@ -1681,7 +1696,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
89279 static void check_sec_ref(struct module *mod, const char *modname,
89280 struct elf_info *elf)
89281 {
89282 - int i;
89283 + unsigned int i;
89284 Elf_Shdr *sechdrs = elf->sechdrs;
89285
89286 /* Walk through all sections */
89287 @@ -1779,7 +1794,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
89288 va_end(ap);
89289 }
89290
89291 -void buf_write(struct buffer *buf, const char *s, int len)
89292 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
89293 {
89294 if (buf->size - buf->pos < len) {
89295 buf->size += len + SZ;
89296 @@ -1997,7 +2012,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
89297 if (fstat(fileno(file), &st) < 0)
89298 goto close_write;
89299
89300 - if (st.st_size != b->pos)
89301 + if (st.st_size != (off_t)b->pos)
89302 goto close_write;
89303
89304 tmp = NOFAIL(malloc(b->pos));
89305 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
89306 index 51207e4..f7d603d 100644
89307 --- a/scripts/mod/modpost.h
89308 +++ b/scripts/mod/modpost.h
89309 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
89310
89311 struct buffer {
89312 char *p;
89313 - int pos;
89314 - int size;
89315 + unsigned int pos;
89316 + unsigned int size;
89317 };
89318
89319 void __attribute__((format(printf, 2, 3)))
89320 buf_printf(struct buffer *buf, const char *fmt, ...);
89321
89322 void
89323 -buf_write(struct buffer *buf, const char *s, int len);
89324 +buf_write(struct buffer *buf, const char *s, unsigned int len);
89325
89326 struct module {
89327 struct module *next;
89328 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
89329 index 9dfcd6d..099068e 100644
89330 --- a/scripts/mod/sumversion.c
89331 +++ b/scripts/mod/sumversion.c
89332 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
89333 goto out;
89334 }
89335
89336 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
89337 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
89338 warn("writing sum in %s failed: %s\n",
89339 filename, strerror(errno));
89340 goto out;
89341 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
89342 index 68bb4ef..2f419e1 100644
89343 --- a/scripts/pnmtologo.c
89344 +++ b/scripts/pnmtologo.c
89345 @@ -244,14 +244,14 @@ static void write_header(void)
89346 fprintf(out, " * Linux logo %s\n", logoname);
89347 fputs(" */\n\n", out);
89348 fputs("#include <linux/linux_logo.h>\n\n", out);
89349 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
89350 + fprintf(out, "static unsigned char %s_data[] = {\n",
89351 logoname);
89352 }
89353
89354 static void write_footer(void)
89355 {
89356 fputs("\n};\n\n", out);
89357 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
89358 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
89359 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
89360 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
89361 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
89362 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
89363 fputs("\n};\n\n", out);
89364
89365 /* write logo clut */
89366 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
89367 + fprintf(out, "static unsigned char %s_clut[] = {\n",
89368 logoname);
89369 write_hex_cnt = 0;
89370 for (i = 0; i < logo_clutsize; i++) {
89371 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
89372 index e4fd45b..2eeb5c4 100644
89373 --- a/scripts/sortextable.h
89374 +++ b/scripts/sortextable.h
89375 @@ -106,9 +106,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
89376 const char *secstrtab;
89377 const char *strtab;
89378 char *extab_image;
89379 - int extab_index = 0;
89380 - int i;
89381 - int idx;
89382 + unsigned int extab_index = 0;
89383 + unsigned int i;
89384 + unsigned int idx;
89385
89386 shdr = (Elf_Shdr *)((char *)ehdr + _r(&ehdr->e_shoff));
89387 shstrtab_sec = shdr + r2(&ehdr->e_shstrndx);
89388 diff --git a/security/Kconfig b/security/Kconfig
89389 index e9c6ac7..952353c 100644
89390 --- a/security/Kconfig
89391 +++ b/security/Kconfig
89392 @@ -4,6 +4,925 @@
89393
89394 menu "Security options"
89395
89396 +menu "Grsecurity"
89397 +
89398 + config ARCH_TRACK_EXEC_LIMIT
89399 + bool
89400 +
89401 + config PAX_KERNEXEC_PLUGIN
89402 + bool
89403 +
89404 + config PAX_PER_CPU_PGD
89405 + bool
89406 +
89407 + config TASK_SIZE_MAX_SHIFT
89408 + int
89409 + depends on X86_64
89410 + default 47 if !PAX_PER_CPU_PGD
89411 + default 42 if PAX_PER_CPU_PGD
89412 +
89413 + config PAX_ENABLE_PAE
89414 + bool
89415 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
89416 +
89417 + config PAX_USERCOPY_SLABS
89418 + bool
89419 +
89420 +config GRKERNSEC
89421 + bool "Grsecurity"
89422 + select CRYPTO
89423 + select CRYPTO_SHA256
89424 + select PROC_FS
89425 + select STOP_MACHINE
89426 + help
89427 + If you say Y here, you will be able to configure many features
89428 + that will enhance the security of your system. It is highly
89429 + recommended that you say Y here and read through the help
89430 + for each option so that you fully understand the features and
89431 + can evaluate their usefulness for your machine.
89432 +
89433 +choice
89434 + prompt "Configuration Method"
89435 + depends on GRKERNSEC
89436 + default GRKERNSEC_CONFIG_CUSTOM
89437 + help
89438 +
89439 +config GRKERNSEC_CONFIG_AUTO
89440 + bool "Automatic"
89441 + help
89442 + If you choose this configuration method, you'll be able to answer a small
89443 + number of simple questions about how you plan to use this kernel.
89444 + The settings of grsecurity and PaX will be automatically configured for
89445 + the highest commonly-used settings within the provided constraints.
89446 +
89447 + If you require additional configuration, custom changes can still be made
89448 + from the "custom configuration" menu.
89449 +
89450 +config GRKERNSEC_CONFIG_CUSTOM
89451 + bool "Custom"
89452 + help
89453 + If you choose this configuration method, you'll be able to configure all
89454 + grsecurity and PaX settings manually. Via this method, no options are
89455 + automatically enabled.
89456 +
89457 +endchoice
89458 +
89459 +choice
89460 + prompt "Usage Type"
89461 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89462 + default GRKERNSEC_CONFIG_SERVER
89463 + help
89464 +
89465 +config GRKERNSEC_CONFIG_SERVER
89466 + bool "Server"
89467 + help
89468 + Choose this option if you plan to use this kernel on a server.
89469 +
89470 +config GRKERNSEC_CONFIG_DESKTOP
89471 + bool "Desktop"
89472 + help
89473 + Choose this option if you plan to use this kernel on a desktop.
89474 +
89475 +endchoice
89476 +
89477 +choice
89478 + prompt "Virtualization Type"
89479 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
89480 + default GRKERNSEC_CONFIG_VIRT_NONE
89481 + help
89482 +
89483 +config GRKERNSEC_CONFIG_VIRT_NONE
89484 + bool "None"
89485 + help
89486 + Choose this option if this kernel will be run on bare metal.
89487 +
89488 +config GRKERNSEC_CONFIG_VIRT_GUEST
89489 + bool "Guest"
89490 + help
89491 + Choose this option if this kernel will be run as a VM guest.
89492 +
89493 +config GRKERNSEC_CONFIG_VIRT_HOST
89494 + bool "Host"
89495 + help
89496 + Choose this option if this kernel will be run as a VM host.
89497 +
89498 +endchoice
89499 +
89500 +choice
89501 + prompt "Virtualization Hardware"
89502 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
89503 + help
89504 +
89505 +config GRKERNSEC_CONFIG_VIRT_EPT
89506 + bool "EPT/RVI Processor Support"
89507 + depends on X86
89508 + help
89509 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
89510 + hardware virtualization. This allows for additional kernel hardening protections
89511 + to operate without additional performance impact.
89512 +
89513 + To see if your Intel processor supports EPT, see:
89514 + http://ark.intel.com/Products/VirtualizationTechnology
89515 + (Most Core i3/5/7 support EPT)
89516 +
89517 + To see if your AMD processor supports RVI, see:
89518 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
89519 +
89520 +config GRKERNSEC_CONFIG_VIRT_SOFT
89521 + bool "First-gen/No Hardware Virtualization"
89522 + help
89523 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
89524 + support hardware virtualization or doesn't support the EPT/RVI extensions.
89525 +
89526 +endchoice
89527 +
89528 +choice
89529 + prompt "Virtualization Software"
89530 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
89531 + help
89532 +
89533 +config GRKERNSEC_CONFIG_VIRT_XEN
89534 + bool "Xen"
89535 + help
89536 + Choose this option if this kernel is running as a Xen guest or host.
89537 +
89538 +config GRKERNSEC_CONFIG_VIRT_VMWARE
89539 + bool "VMWare"
89540 + help
89541 + Choose this option if this kernel is running as a VMWare guest or host.
89542 +
89543 +config GRKERNSEC_CONFIG_VIRT_KVM
89544 + bool "KVM"
89545 + help
89546 + Choose this option if this kernel is running as a KVM guest or host.
89547 +
89548 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
89549 + bool "VirtualBox"
89550 + help
89551 + Choose this option if this kernel is running as a VirtualBox guest or host.
89552 +
89553 +endchoice
89554 +
89555 +choice
89556 + prompt "Required Priorities"
89557 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89558 + default GRKERNSEC_CONFIG_PRIORITY_PERF
89559 + help
89560 +
89561 +config GRKERNSEC_CONFIG_PRIORITY_PERF
89562 + bool "Performance"
89563 + help
89564 + Choose this option if performance is of highest priority for this deployment
89565 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
89566 + and freed memory sanitizing will be disabled.
89567 +
89568 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
89569 + bool "Security"
89570 + help
89571 + Choose this option if security is of highest priority for this deployment of
89572 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
89573 + be enabled for this kernel. In a worst-case scenario, these features can
89574 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
89575 +
89576 +endchoice
89577 +
89578 +menu "Default Special Groups"
89579 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
89580 +
89581 +config GRKERNSEC_PROC_GID
89582 + int "GID exempted from /proc restrictions"
89583 + default 1001
89584 + help
89585 + Setting this GID determines which group will be exempted from
89586 + grsecurity's /proc restrictions, allowing users of the specified
89587 + group to view network statistics and the existence of other users'
89588 + processes on the system. This GID may also be chosen at boot time
89589 + via "grsec_proc_gid=" on the kernel commandline.
89590 +
89591 +config GRKERNSEC_TPE_UNTRUSTED_GID
89592 + int "GID for TPE-untrusted users"
89593 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
89594 + default 1005
89595 + help
89596 + Setting this GID determines which group untrusted users should
89597 + be added to. These users will be placed under grsecurity's Trusted Path
89598 + Execution mechanism, preventing them from executing their own binaries.
89599 + The users will only be able to execute binaries in directories owned and
89600 + writable only by the root user. If the sysctl option is enabled, a sysctl
89601 + option with name "tpe_gid" is created.
89602 +
89603 +config GRKERNSEC_TPE_TRUSTED_GID
89604 + int "GID for TPE-trusted users"
89605 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
89606 + default 1005
89607 + help
89608 + Setting this GID determines what group TPE restrictions will be
89609 + *disabled* for. If the sysctl option is enabled, a sysctl option
89610 + with name "tpe_gid" is created.
89611 +
89612 +config GRKERNSEC_SYMLINKOWN_GID
89613 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
89614 + depends on GRKERNSEC_CONFIG_SERVER
89615 + default 1006
89616 + help
89617 + Setting this GID determines what group kernel-enforced
89618 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
89619 + is enabled, a sysctl option with name "symlinkown_gid" is created.
89620 +
89621 +
89622 +endmenu
89623 +
89624 +menu "Customize Configuration"
89625 +depends on GRKERNSEC
89626 +
89627 +menu "PaX"
89628 +
89629 +config PAX
89630 + bool "Enable various PaX features"
89631 + default y if GRKERNSEC_CONFIG_AUTO
89632 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
89633 + help
89634 + This allows you to enable various PaX features. PaX adds
89635 + intrusion prevention mechanisms to the kernel that reduce
89636 + the risks posed by exploitable memory corruption bugs.
89637 +
89638 +menu "PaX Control"
89639 + depends on PAX
89640 +
89641 +config PAX_SOFTMODE
89642 + bool 'Support soft mode'
89643 + help
89644 + Enabling this option will allow you to run PaX in soft mode, that
89645 + is, PaX features will not be enforced by default, only on executables
89646 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
89647 + support as they are the only way to mark executables for soft mode use.
89648 +
89649 + Soft mode can be activated by using the "pax_softmode=1" kernel command
89650 + line option on boot. Furthermore you can control various PaX features
89651 + at runtime via the entries in /proc/sys/kernel/pax.
89652 +
89653 +config PAX_EI_PAX
89654 + bool 'Use legacy ELF header marking'
89655 + default y if GRKERNSEC_CONFIG_AUTO
89656 + help
89657 + Enabling this option will allow you to control PaX features on
89658 + a per executable basis via the 'chpax' utility available at
89659 + http://pax.grsecurity.net/. The control flags will be read from
89660 + an otherwise reserved part of the ELF header. This marking has
89661 + numerous drawbacks (no support for soft-mode, toolchain does not
89662 + know about the non-standard use of the ELF header) therefore it
89663 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
89664 + support.
89665 +
89666 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
89667 + support as well, they will override the legacy EI_PAX marks.
89668 +
89669 + If you enable none of the marking options then all applications
89670 + will run with PaX enabled on them by default.
89671 +
89672 +config PAX_PT_PAX_FLAGS
89673 + bool 'Use ELF program header marking'
89674 + default y if GRKERNSEC_CONFIG_AUTO
89675 + help
89676 + Enabling this option will allow you to control PaX features on
89677 + a per executable basis via the 'paxctl' utility available at
89678 + http://pax.grsecurity.net/. The control flags will be read from
89679 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
89680 + has the benefits of supporting both soft mode and being fully
89681 + integrated into the toolchain (the binutils patch is available
89682 + from http://pax.grsecurity.net).
89683 +
89684 + Note that if you enable the legacy EI_PAX marking support as well,
89685 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
89686 +
89687 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
89688 + must make sure that the marks are the same if a binary has both marks.
89689 +
89690 + If you enable none of the marking options then all applications
89691 + will run with PaX enabled on them by default.
89692 +
89693 +config PAX_XATTR_PAX_FLAGS
89694 + bool 'Use filesystem extended attributes marking'
89695 + default y if GRKERNSEC_CONFIG_AUTO
89696 + select CIFS_XATTR if CIFS
89697 + select EXT2_FS_XATTR if EXT2_FS
89698 + select EXT3_FS_XATTR if EXT3_FS
89699 + select EXT4_FS_XATTR if EXT4_FS
89700 + select JFFS2_FS_XATTR if JFFS2_FS
89701 + select REISERFS_FS_XATTR if REISERFS_FS
89702 + select SQUASHFS_XATTR if SQUASHFS
89703 + select TMPFS_XATTR if TMPFS
89704 + select UBIFS_FS_XATTR if UBIFS_FS
89705 + help
89706 + Enabling this option will allow you to control PaX features on
89707 + a per executable basis via the 'setfattr' utility. The control
89708 + flags will be read from the user.pax.flags extended attribute of
89709 + the file. This marking has the benefit of supporting binary-only
89710 + applications that self-check themselves (e.g., skype) and would
89711 + not tolerate chpax/paxctl changes. The main drawback is that
89712 + extended attributes are not supported by some filesystems (e.g.,
89713 + isofs, udf, vfat) so copying files through such filesystems will
89714 + lose the extended attributes and these PaX markings.
89715 +
89716 + Note that if you enable the legacy EI_PAX marking support as well,
89717 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
89718 +
89719 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
89720 + must make sure that the marks are the same if a binary has both marks.
89721 +
89722 + If you enable none of the marking options then all applications
89723 + will run with PaX enabled on them by default.
89724 +
89725 +choice
89726 + prompt 'MAC system integration'
89727 + default PAX_HAVE_ACL_FLAGS
89728 + help
89729 + Mandatory Access Control systems have the option of controlling
89730 + PaX flags on a per executable basis, choose the method supported
89731 + by your particular system.
89732 +
89733 + - "none": if your MAC system does not interact with PaX,
89734 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
89735 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
89736 +
89737 + NOTE: this option is for developers/integrators only.
89738 +
89739 + config PAX_NO_ACL_FLAGS
89740 + bool 'none'
89741 +
89742 + config PAX_HAVE_ACL_FLAGS
89743 + bool 'direct'
89744 +
89745 + config PAX_HOOK_ACL_FLAGS
89746 + bool 'hook'
89747 +endchoice
89748 +
89749 +endmenu
89750 +
89751 +menu "Non-executable pages"
89752 + depends on PAX
89753 +
89754 +config PAX_NOEXEC
89755 + bool "Enforce non-executable pages"
89756 + default y if GRKERNSEC_CONFIG_AUTO
89757 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
89758 + help
89759 + By design some architectures do not allow for protecting memory
89760 + pages against execution or even if they do, Linux does not make
89761 + use of this feature. In practice this means that if a page is
89762 + readable (such as the stack or heap) it is also executable.
89763 +
89764 + There is a well known exploit technique that makes use of this
89765 + fact and a common programming mistake where an attacker can
89766 + introduce code of his choice somewhere in the attacked program's
89767 + memory (typically the stack or the heap) and then execute it.
89768 +
89769 + If the attacked program was running with different (typically
89770 + higher) privileges than that of the attacker, then he can elevate
89771 + his own privilege level (e.g. get a root shell, write to files for
89772 + which he does not have write access to, etc).
89773 +
89774 + Enabling this option will let you choose from various features
89775 + that prevent the injection and execution of 'foreign' code in
89776 + a program.
89777 +
89778 + This will also break programs that rely on the old behaviour and
89779 + expect that dynamically allocated memory via the malloc() family
89780 + of functions is executable (which it is not). Notable examples
89781 + are the XFree86 4.x server, the java runtime and wine.
89782 +
89783 +config PAX_PAGEEXEC
89784 + bool "Paging based non-executable pages"
89785 + default y if GRKERNSEC_CONFIG_AUTO
89786 + 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)
89787 + select S390_SWITCH_AMODE if S390
89788 + select S390_EXEC_PROTECT if S390
89789 + select ARCH_TRACK_EXEC_LIMIT if X86_32
89790 + help
89791 + This implementation is based on the paging feature of the CPU.
89792 + On i386 without hardware non-executable bit support there is a
89793 + variable but usually low performance impact, however on Intel's
89794 + P4 core based CPUs it is very high so you should not enable this
89795 + for kernels meant to be used on such CPUs.
89796 +
89797 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
89798 + with hardware non-executable bit support there is no performance
89799 + impact, on ppc the impact is negligible.
89800 +
89801 + Note that several architectures require various emulations due to
89802 + badly designed userland ABIs, this will cause a performance impact
89803 + but will disappear as soon as userland is fixed. For example, ppc
89804 + userland MUST have been built with secure-plt by a recent toolchain.
89805 +
89806 +config PAX_SEGMEXEC
89807 + bool "Segmentation based non-executable pages"
89808 + default y if GRKERNSEC_CONFIG_AUTO
89809 + depends on PAX_NOEXEC && X86_32
89810 + help
89811 + This implementation is based on the segmentation feature of the
89812 + CPU and has a very small performance impact, however applications
89813 + will be limited to a 1.5 GB address space instead of the normal
89814 + 3 GB.
89815 +
89816 +config PAX_EMUTRAMP
89817 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
89818 + default y if PARISC
89819 + help
89820 + There are some programs and libraries that for one reason or
89821 + another attempt to execute special small code snippets from
89822 + non-executable memory pages. Most notable examples are the
89823 + signal handler return code generated by the kernel itself and
89824 + the GCC trampolines.
89825 +
89826 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
89827 + such programs will no longer work under your kernel.
89828 +
89829 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
89830 + utilities to enable trampoline emulation for the affected programs
89831 + yet still have the protection provided by the non-executable pages.
89832 +
89833 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
89834 + your system will not even boot.
89835 +
89836 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
89837 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
89838 + for the affected files.
89839 +
89840 + NOTE: enabling this feature *may* open up a loophole in the
89841 + protection provided by non-executable pages that an attacker
89842 + could abuse. Therefore the best solution is to not have any
89843 + files on your system that would require this option. This can
89844 + be achieved by not using libc5 (which relies on the kernel
89845 + signal handler return code) and not using or rewriting programs
89846 + that make use of the nested function implementation of GCC.
89847 + Skilled users can just fix GCC itself so that it implements
89848 + nested function calls in a way that does not interfere with PaX.
89849 +
89850 +config PAX_EMUSIGRT
89851 + bool "Automatically emulate sigreturn trampolines"
89852 + depends on PAX_EMUTRAMP && PARISC
89853 + default y
89854 + help
89855 + Enabling this option will have the kernel automatically detect
89856 + and emulate signal return trampolines executing on the stack
89857 + that would otherwise lead to task termination.
89858 +
89859 + This solution is intended as a temporary one for users with
89860 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
89861 + Modula-3 runtime, etc) or executables linked to such, basically
89862 + everything that does not specify its own SA_RESTORER function in
89863 + normal executable memory like glibc 2.1+ does.
89864 +
89865 + On parisc you MUST enable this option, otherwise your system will
89866 + not even boot.
89867 +
89868 + NOTE: this feature cannot be disabled on a per executable basis
89869 + and since it *does* open up a loophole in the protection provided
89870 + by non-executable pages, the best solution is to not have any
89871 + files on your system that would require this option.
89872 +
89873 +config PAX_MPROTECT
89874 + bool "Restrict mprotect()"
89875 + default y if GRKERNSEC_CONFIG_AUTO
89876 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
89877 + help
89878 + Enabling this option will prevent programs from
89879 + - changing the executable status of memory pages that were
89880 + not originally created as executable,
89881 + - making read-only executable pages writable again,
89882 + - creating executable pages from anonymous memory,
89883 + - making read-only-after-relocations (RELRO) data pages writable again.
89884 +
89885 + You should say Y here to complete the protection provided by
89886 + the enforcement of non-executable pages.
89887 +
89888 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
89889 + this feature on a per file basis.
89890 +
89891 +config PAX_MPROTECT_COMPAT
89892 + bool "Use legacy/compat protection demoting (read help)"
89893 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
89894 + depends on PAX_MPROTECT
89895 + help
89896 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
89897 + by sending the proper error code to the application. For some broken
89898 + userland, this can cause problems with Python or other applications. The
89899 + current implementation however allows for applications like clamav to
89900 + detect if JIT compilation/execution is allowed and to fall back gracefully
89901 + to an interpreter-based mode if it does not. While we encourage everyone
89902 + to use the current implementation as-is and push upstream to fix broken
89903 + userland (note that the RWX logging option can assist with this), in some
89904 + environments this may not be possible. Having to disable MPROTECT
89905 + completely on certain binaries reduces the security benefit of PaX,
89906 + so this option is provided for those environments to revert to the old
89907 + behavior.
89908 +
89909 +config PAX_ELFRELOCS
89910 + bool "Allow ELF text relocations (read help)"
89911 + depends on PAX_MPROTECT
89912 + default n
89913 + help
89914 + Non-executable pages and mprotect() restrictions are effective
89915 + in preventing the introduction of new executable code into an
89916 + attacked task's address space. There remain only two venues
89917 + for this kind of attack: if the attacker can execute already
89918 + existing code in the attacked task then he can either have it
89919 + create and mmap() a file containing his code or have it mmap()
89920 + an already existing ELF library that does not have position
89921 + independent code in it and use mprotect() on it to make it
89922 + writable and copy his code there. While protecting against
89923 + the former approach is beyond PaX, the latter can be prevented
89924 + by having only PIC ELF libraries on one's system (which do not
89925 + need to relocate their code). If you are sure this is your case,
89926 + as is the case with all modern Linux distributions, then leave
89927 + this option disabled. You should say 'n' here.
89928 +
89929 +config PAX_ETEXECRELOCS
89930 + bool "Allow ELF ET_EXEC text relocations"
89931 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
89932 + select PAX_ELFRELOCS
89933 + default y
89934 + help
89935 + On some architectures there are incorrectly created applications
89936 + that require text relocations and would not work without enabling
89937 + this option. If you are an alpha, ia64 or parisc user, you should
89938 + enable this option and disable it once you have made sure that
89939 + none of your applications need it.
89940 +
89941 +config PAX_EMUPLT
89942 + bool "Automatically emulate ELF PLT"
89943 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
89944 + default y
89945 + help
89946 + Enabling this option will have the kernel automatically detect
89947 + and emulate the Procedure Linkage Table entries in ELF files.
89948 + On some architectures such entries are in writable memory, and
89949 + become non-executable leading to task termination. Therefore
89950 + it is mandatory that you enable this option on alpha, parisc,
89951 + sparc and sparc64, otherwise your system would not even boot.
89952 +
89953 + NOTE: this feature *does* open up a loophole in the protection
89954 + provided by the non-executable pages, therefore the proper
89955 + solution is to modify the toolchain to produce a PLT that does
89956 + not need to be writable.
89957 +
89958 +config PAX_DLRESOLVE
89959 + bool 'Emulate old glibc resolver stub'
89960 + depends on PAX_EMUPLT && SPARC
89961 + default n
89962 + help
89963 + This option is needed if userland has an old glibc (before 2.4)
89964 + that puts a 'save' instruction into the runtime generated resolver
89965 + stub that needs special emulation.
89966 +
89967 +config PAX_KERNEXEC
89968 + bool "Enforce non-executable kernel pages"
89969 + 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))
89970 + depends on ((X86 && (!X86_32 || X86_WP_WORKS_OK)) || (ARM && (CPU_V6 || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
89971 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
89972 + select PAX_KERNEXEC_PLUGIN if X86_64
89973 + help
89974 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
89975 + that is, enabling this option will make it harder to inject
89976 + and execute 'foreign' code in kernel memory itself.
89977 +
89978 +choice
89979 + prompt "Return Address Instrumentation Method"
89980 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
89981 + depends on PAX_KERNEXEC_PLUGIN
89982 + help
89983 + Select the method used to instrument function pointer dereferences.
89984 + Note that binary modules cannot be instrumented by this approach.
89985 +
89986 + Note that the implementation requires a gcc with plugin support,
89987 + i.e., gcc 4.5 or newer. You may need to install the supporting
89988 + headers explicitly in addition to the normal gcc package.
89989 +
89990 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
89991 + bool "bts"
89992 + help
89993 + This method is compatible with binary only modules but has
89994 + a higher runtime overhead.
89995 +
89996 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
89997 + bool "or"
89998 + depends on !PARAVIRT
89999 + help
90000 + This method is incompatible with binary only modules but has
90001 + a lower runtime overhead.
90002 +endchoice
90003 +
90004 +config PAX_KERNEXEC_PLUGIN_METHOD
90005 + string
90006 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
90007 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
90008 + default ""
90009 +
90010 +config PAX_KERNEXEC_MODULE_TEXT
90011 + int "Minimum amount of memory reserved for module code"
90012 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
90013 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
90014 + depends on PAX_KERNEXEC && X86_32 && MODULES
90015 + help
90016 + Due to implementation details the kernel must reserve a fixed
90017 + amount of memory for module code at compile time that cannot be
90018 + changed at runtime. Here you can specify the minimum amount
90019 + in MB that will be reserved. Due to the same implementation
90020 + details this size will always be rounded up to the next 2/4 MB
90021 + boundary (depends on PAE) so the actually available memory for
90022 + module code will usually be more than this minimum.
90023 +
90024 + The default 4 MB should be enough for most users but if you have
90025 + an excessive number of modules (e.g., most distribution configs
90026 + compile many drivers as modules) or use huge modules such as
90027 + nvidia's kernel driver, you will need to adjust this amount.
90028 + A good rule of thumb is to look at your currently loaded kernel
90029 + modules and add up their sizes.
90030 +
90031 +endmenu
90032 +
90033 +menu "Address Space Layout Randomization"
90034 + depends on PAX
90035 +
90036 +config PAX_ASLR
90037 + bool "Address Space Layout Randomization"
90038 + default y if GRKERNSEC_CONFIG_AUTO
90039 + help
90040 + Many if not most exploit techniques rely on the knowledge of
90041 + certain addresses in the attacked program. The following options
90042 + will allow the kernel to apply a certain amount of randomization
90043 + to specific parts of the program thereby forcing an attacker to
90044 + guess them in most cases. Any failed guess will most likely crash
90045 + the attacked program which allows the kernel to detect such attempts
90046 + and react on them. PaX itself provides no reaction mechanisms,
90047 + instead it is strongly encouraged that you make use of Nergal's
90048 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
90049 + (http://www.grsecurity.net/) built-in crash detection features or
90050 + develop one yourself.
90051 +
90052 + By saying Y here you can choose to randomize the following areas:
90053 + - top of the task's kernel stack
90054 + - top of the task's userland stack
90055 + - base address for mmap() requests that do not specify one
90056 + (this includes all libraries)
90057 + - base address of the main executable
90058 +
90059 + It is strongly recommended to say Y here as address space layout
90060 + randomization has negligible impact on performance yet it provides
90061 + a very effective protection.
90062 +
90063 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
90064 + this feature on a per file basis.
90065 +
90066 +config PAX_RANDKSTACK
90067 + bool "Randomize kernel stack base"
90068 + default y if GRKERNSEC_CONFIG_AUTO
90069 + depends on X86_TSC && X86
90070 + help
90071 + By saying Y here the kernel will randomize every task's kernel
90072 + stack on every system call. This will not only force an attacker
90073 + to guess it but also prevent him from making use of possible
90074 + leaked information about it.
90075 +
90076 + Since the kernel stack is a rather scarce resource, randomization
90077 + may cause unexpected stack overflows, therefore you should very
90078 + carefully test your system. Note that once enabled in the kernel
90079 + configuration, this feature cannot be disabled on a per file basis.
90080 +
90081 +config PAX_RANDUSTACK
90082 + bool "Randomize user stack base"
90083 + default y if GRKERNSEC_CONFIG_AUTO
90084 + depends on PAX_ASLR
90085 + help
90086 + By saying Y here the kernel will randomize every task's userland
90087 + stack. The randomization is done in two steps where the second
90088 + one may apply a big amount of shift to the top of the stack and
90089 + cause problems for programs that want to use lots of memory (more
90090 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
90091 + For this reason the second step can be controlled by 'chpax' or
90092 + 'paxctl' on a per file basis.
90093 +
90094 +config PAX_RANDMMAP
90095 + bool "Randomize mmap() base"
90096 + default y if GRKERNSEC_CONFIG_AUTO
90097 + depends on PAX_ASLR
90098 + help
90099 + By saying Y here the kernel will use a randomized base address for
90100 + mmap() requests that do not specify one themselves. As a result
90101 + all dynamically loaded libraries will appear at random addresses
90102 + and therefore be harder to exploit by a technique where an attacker
90103 + attempts to execute library code for his purposes (e.g. spawn a
90104 + shell from an exploited program that is running at an elevated
90105 + privilege level).
90106 +
90107 + Furthermore, if a program is relinked as a dynamic ELF file, its
90108 + base address will be randomized as well, completing the full
90109 + randomization of the address space layout. Attacking such programs
90110 + becomes a guess game. You can find an example of doing this at
90111 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
90112 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
90113 +
90114 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
90115 + feature on a per file basis.
90116 +
90117 +endmenu
90118 +
90119 +menu "Miscellaneous hardening features"
90120 +
90121 +config PAX_MEMORY_SANITIZE
90122 + bool "Sanitize all freed memory"
90123 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
90124 + depends on !HIBERNATION
90125 + help
90126 + By saying Y here the kernel will erase memory pages as soon as they
90127 + are freed. This in turn reduces the lifetime of data stored in the
90128 + pages, making it less likely that sensitive information such as
90129 + passwords, cryptographic secrets, etc stay in memory for too long.
90130 +
90131 + This is especially useful for programs whose runtime is short, long
90132 + lived processes and the kernel itself benefit from this as long as
90133 + they operate on whole memory pages and ensure timely freeing of pages
90134 + that may hold sensitive information.
90135 +
90136 + The tradeoff is performance impact, on a single CPU system kernel
90137 + compilation sees a 3% slowdown, other systems and workloads may vary
90138 + and you are advised to test this feature on your expected workload
90139 + before deploying it.
90140 +
90141 + Note that this feature does not protect data stored in live pages,
90142 + e.g., process memory swapped to disk may stay there for a long time.
90143 +
90144 +config PAX_MEMORY_STACKLEAK
90145 + bool "Sanitize kernel stack"
90146 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
90147 + depends on X86
90148 + help
90149 + By saying Y here the kernel will erase the kernel stack before it
90150 + returns from a system call. This in turn reduces the information
90151 + that a kernel stack leak bug can reveal.
90152 +
90153 + Note that such a bug can still leak information that was put on
90154 + the stack by the current system call (the one eventually triggering
90155 + the bug) but traces of earlier system calls on the kernel stack
90156 + cannot leak anymore.
90157 +
90158 + The tradeoff is performance impact: on a single CPU system kernel
90159 + compilation sees a 1% slowdown, other systems and workloads may vary
90160 + and you are advised to test this feature on your expected workload
90161 + before deploying it.
90162 +
90163 + Note that the full feature requires a gcc with plugin support,
90164 + i.e., gcc 4.5 or newer. You may need to install the supporting
90165 + headers explicitly in addition to the normal gcc package. Using
90166 + older gcc versions means that functions with large enough stack
90167 + frames may leave uninitialized memory behind that may be exposed
90168 + to a later syscall leaking the stack.
90169 +
90170 +config PAX_MEMORY_UDEREF
90171 + bool "Prevent invalid userland pointer dereference"
90172 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
90173 + depends on (X86 || (ARM && (CPU_V6 || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
90174 + select PAX_PER_CPU_PGD if X86_64
90175 + help
90176 + By saying Y here the kernel will be prevented from dereferencing
90177 + userland pointers in contexts where the kernel expects only kernel
90178 + pointers. This is both a useful runtime debugging feature and a
90179 + security measure that prevents exploiting a class of kernel bugs.
90180 +
90181 + The tradeoff is that some virtualization solutions may experience
90182 + a huge slowdown and therefore you should not enable this feature
90183 + for kernels meant to run in such environments. Whether a given VM
90184 + solution is affected or not is best determined by simply trying it
90185 + out, the performance impact will be obvious right on boot as this
90186 + mechanism engages from very early on. A good rule of thumb is that
90187 + VMs running on CPUs without hardware virtualization support (i.e.,
90188 + the majority of IA-32 CPUs) will likely experience the slowdown.
90189 +
90190 +config PAX_REFCOUNT
90191 + bool "Prevent various kernel object reference counter overflows"
90192 + default y if GRKERNSEC_CONFIG_AUTO
90193 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
90194 + help
90195 + By saying Y here the kernel will detect and prevent overflowing
90196 + various (but not all) kinds of object reference counters. Such
90197 + overflows can normally occur due to bugs only and are often, if
90198 + not always, exploitable.
90199 +
90200 + The tradeoff is that data structures protected by an overflowed
90201 + refcount will never be freed and therefore will leak memory. Note
90202 + that this leak also happens even without this protection but in
90203 + that case the overflow can eventually trigger the freeing of the
90204 + data structure while it is still being used elsewhere, resulting
90205 + in the exploitable situation that this feature prevents.
90206 +
90207 + Since this has a negligible performance impact, you should enable
90208 + this feature.
90209 +
90210 +config PAX_CONSTIFY_PLUGIN
90211 + bool "Automatically constify eligible structures"
90212 + default y
90213 + depends on !UML
90214 + help
90215 + By saying Y here the compiler will automatically constify a class
90216 + of types that contain only function pointers. This reduces the
90217 + kernel's attack surface and also produces a better memory layout.
90218 +
90219 + Note that the implementation requires a gcc with plugin support,
90220 + i.e., gcc 4.5 or newer. You may need to install the supporting
90221 + headers explicitly in addition to the normal gcc package.
90222 +
90223 + Note that if some code really has to modify constified variables
90224 + then the source code will have to be patched to allow it. Examples
90225 + can be found in PaX itself (the no_const attribute) and for some
90226 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
90227 +
90228 +config PAX_USERCOPY
90229 + bool "Harden heap object copies between kernel and userland"
90230 + default y if GRKERNSEC_CONFIG_AUTO
90231 + depends on ARM || IA64 || PPC || SPARC || X86
90232 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
90233 + select PAX_USERCOPY_SLABS
90234 + help
90235 + By saying Y here the kernel will enforce the size of heap objects
90236 + when they are copied in either direction between the kernel and
90237 + userland, even if only a part of the heap object is copied.
90238 +
90239 + Specifically, this checking prevents information leaking from the
90240 + kernel heap during kernel to userland copies (if the kernel heap
90241 + object is otherwise fully initialized) and prevents kernel heap
90242 + overflows during userland to kernel copies.
90243 +
90244 + Note that the current implementation provides the strictest bounds
90245 + checks for the SLUB allocator.
90246 +
90247 + Enabling this option also enables per-slab cache protection against
90248 + data in a given cache being copied into/out of via userland
90249 + accessors. Though the whitelist of regions will be reduced over
90250 + time, it notably protects important data structures like task structs.
90251 +
90252 + If frame pointers are enabled on x86, this option will also restrict
90253 + copies into and out of the kernel stack to local variables within a
90254 + single frame.
90255 +
90256 + Since this has a negligible performance impact, you should enable
90257 + this feature.
90258 +
90259 +
90260 +config PAX_USERCOPY_DEBUG
90261 + bool
90262 + depends on X86 && PAX_USERCOPY
90263 + default n
90264 +
90265 +config PAX_SIZE_OVERFLOW
90266 + bool "Prevent various integer overflows in function size parameters"
90267 + default y if GRKERNSEC_CONFIG_AUTO
90268 + depends on X86
90269 + help
90270 + By saying Y here the kernel recomputes expressions of function
90271 + arguments marked by a size_overflow attribute with double integer
90272 + precision (DImode/TImode for 32/64 bit integer types).
90273 +
90274 + The recomputed argument is checked against TYPE_MAX and an event
90275 + is logged on overflow and the triggering process is killed.
90276 +
90277 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
90278 +
90279 + Note that the implementation requires a gcc with plugin support,
90280 + i.e., gcc 4.5 or newer. You may need to install the supporting
90281 + headers explicitly in addition to the normal gcc package.
90282 +
90283 +config PAX_LATENT_ENTROPY
90284 + bool "Generate some entropy during boot"
90285 + default y if GRKERNSEC_CONFIG_AUTO
90286 + help
90287 + By saying Y here the kernel will instrument early boot code to
90288 + extract some entropy from both original and artificially created
90289 + program state. This will help especially embedded systems where
90290 + there is little 'natural' source of entropy normally. The cost
90291 + is some slowdown of the boot process.
90292 +
90293 + When pax_extra_latent_entropy is passed on the kernel command line,
90294 + entropy will be extracted from up to the first 4GB of RAM while the
90295 + runtime memory allocator is being initialized. This costs even more
90296 + slowdown of the boot process.
90297 +
90298 + Note that the implementation requires a gcc with plugin support,
90299 + i.e., gcc 4.5 or newer. You may need to install the supporting
90300 + headers explicitly in addition to the normal gcc package.
90301 +
90302 + Note that entropy extracted this way is not cryptographically
90303 + secure!
90304 +
90305 +endmenu
90306 +
90307 +endmenu
90308 +
90309 +source grsecurity/Kconfig
90310 +
90311 +endmenu
90312 +
90313 +endmenu
90314 +
90315 source security/keys/Kconfig
90316
90317 config SECURITY_DMESG_RESTRICT
90318 @@ -103,7 +1022,7 @@ config INTEL_TXT
90319 config LSM_MMAP_MIN_ADDR
90320 int "Low address space for LSM to protect from user allocation"
90321 depends on SECURITY && SECURITY_SELINUX
90322 - default 32768 if ARM
90323 + default 32768 if ALPHA || ARM || PARISC || SPARC32
90324 default 65536
90325 help
90326 This is the portion of low virtual memory which should be protected
90327 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
90328 index 8c2a7f6..b133ac9 100644
90329 --- a/security/apparmor/lsm.c
90330 +++ b/security/apparmor/lsm.c
90331 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
90332 return error;
90333 }
90334
90335 -static struct security_operations apparmor_ops = {
90336 +static struct security_operations apparmor_ops __read_only = {
90337 .name = "apparmor",
90338
90339 .ptrace_access_check = apparmor_ptrace_access_check,
90340 diff --git a/security/commoncap.c b/security/commoncap.c
90341 index 7ee08c7..8d1a9d6 100644
90342 --- a/security/commoncap.c
90343 +++ b/security/commoncap.c
90344 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
90345 return 0;
90346 }
90347
90348 +/* returns:
90349 + 1 for suid privilege
90350 + 2 for sgid privilege
90351 + 3 for fscap privilege
90352 +*/
90353 +int is_privileged_binary(const struct dentry *dentry)
90354 +{
90355 + struct cpu_vfs_cap_data capdata;
90356 + struct inode *inode = dentry->d_inode;
90357 +
90358 + if (!inode || S_ISDIR(inode->i_mode))
90359 + return 0;
90360 +
90361 + if (inode->i_mode & S_ISUID)
90362 + return 1;
90363 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
90364 + return 2;
90365 +
90366 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
90367 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
90368 + return 3;
90369 + }
90370 +
90371 + return 0;
90372 +}
90373 +
90374 /*
90375 * Attempt to get the on-exec apply capability sets for an executable file from
90376 * its xattrs and, if present, apply them to the proposed credentials being
90377 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
90378 const struct cred *cred = current_cred();
90379 kuid_t root_uid = make_kuid(cred->user_ns, 0);
90380
90381 + if (gr_acl_enable_at_secure())
90382 + return 1;
90383 +
90384 if (!uid_eq(cred->uid, root_uid)) {
90385 if (bprm->cap_effective)
90386 return 1;
90387 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
90388 index 079a85d..12e93f8 100644
90389 --- a/security/integrity/ima/ima.h
90390 +++ b/security/integrity/ima/ima.h
90391 @@ -96,8 +96,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
90392 extern spinlock_t ima_queue_lock;
90393
90394 struct ima_h_table {
90395 - atomic_long_t len; /* number of stored measurements in the list */
90396 - atomic_long_t violations;
90397 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
90398 + atomic_long_unchecked_t violations;
90399 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
90400 };
90401 extern struct ima_h_table ima_htable;
90402 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
90403 index 0cea3db..2f0ef77 100644
90404 --- a/security/integrity/ima/ima_api.c
90405 +++ b/security/integrity/ima/ima_api.c
90406 @@ -79,7 +79,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
90407 int result;
90408
90409 /* can overflow, only indicator */
90410 - atomic_long_inc(&ima_htable.violations);
90411 + atomic_long_inc_unchecked(&ima_htable.violations);
90412
90413 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
90414 if (!entry) {
90415 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
90416 index 38477c9..87a60c7 100644
90417 --- a/security/integrity/ima/ima_fs.c
90418 +++ b/security/integrity/ima/ima_fs.c
90419 @@ -28,12 +28,12 @@
90420 static int valid_policy = 1;
90421 #define TMPBUFLEN 12
90422 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
90423 - loff_t *ppos, atomic_long_t *val)
90424 + loff_t *ppos, atomic_long_unchecked_t *val)
90425 {
90426 char tmpbuf[TMPBUFLEN];
90427 ssize_t len;
90428
90429 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
90430 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
90431 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
90432 }
90433
90434 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
90435 index 55a6271..ad829c3 100644
90436 --- a/security/integrity/ima/ima_queue.c
90437 +++ b/security/integrity/ima/ima_queue.c
90438 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
90439 INIT_LIST_HEAD(&qe->later);
90440 list_add_tail_rcu(&qe->later, &ima_measurements);
90441
90442 - atomic_long_inc(&ima_htable.len);
90443 + atomic_long_inc_unchecked(&ima_htable.len);
90444 key = ima_hash_key(entry->digest);
90445 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
90446 return 0;
90447 diff --git a/security/keys/compat.c b/security/keys/compat.c
90448 index 1c26176..64a1ba2 100644
90449 --- a/security/keys/compat.c
90450 +++ b/security/keys/compat.c
90451 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
90452 if (ret == 0)
90453 goto no_payload_free;
90454
90455 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
90456 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
90457
90458 if (iov != iovstack)
90459 kfree(iov);
90460 diff --git a/security/keys/key.c b/security/keys/key.c
90461 index 8fb7c7b..ba3610d 100644
90462 --- a/security/keys/key.c
90463 +++ b/security/keys/key.c
90464 @@ -284,7 +284,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
90465
90466 atomic_set(&key->usage, 1);
90467 init_rwsem(&key->sem);
90468 - lockdep_set_class(&key->sem, &type->lock_class);
90469 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
90470 key->type = type;
90471 key->user = user;
90472 key->quotalen = quotalen;
90473 @@ -1032,7 +1032,9 @@ int register_key_type(struct key_type *ktype)
90474 struct key_type *p;
90475 int ret;
90476
90477 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
90478 + pax_open_kernel();
90479 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
90480 + pax_close_kernel();
90481
90482 ret = -EEXIST;
90483 down_write(&key_types_sem);
90484 @@ -1044,7 +1046,7 @@ int register_key_type(struct key_type *ktype)
90485 }
90486
90487 /* store the type */
90488 - list_add(&ktype->link, &key_types_list);
90489 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
90490
90491 pr_notice("Key type %s registered\n", ktype->name);
90492 ret = 0;
90493 @@ -1066,7 +1068,7 @@ EXPORT_SYMBOL(register_key_type);
90494 void unregister_key_type(struct key_type *ktype)
90495 {
90496 down_write(&key_types_sem);
90497 - list_del_init(&ktype->link);
90498 + pax_list_del_init((struct list_head *)&ktype->link);
90499 downgrade_write(&key_types_sem);
90500 key_gc_keytype(ktype);
90501 pr_notice("Key type %s unregistered\n", ktype->name);
90502 @@ -1084,10 +1086,10 @@ void __init key_init(void)
90503 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
90504
90505 /* add the special key types */
90506 - list_add_tail(&key_type_keyring.link, &key_types_list);
90507 - list_add_tail(&key_type_dead.link, &key_types_list);
90508 - list_add_tail(&key_type_user.link, &key_types_list);
90509 - list_add_tail(&key_type_logon.link, &key_types_list);
90510 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
90511 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
90512 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
90513 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
90514
90515 /* record the root user tracking */
90516 rb_link_node(&root_key_user.node,
90517 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
90518 index 4b5c948..2054dc1 100644
90519 --- a/security/keys/keyctl.c
90520 +++ b/security/keys/keyctl.c
90521 @@ -986,7 +986,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
90522 /*
90523 * Copy the iovec data from userspace
90524 */
90525 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
90526 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
90527 unsigned ioc)
90528 {
90529 for (; ioc > 0; ioc--) {
90530 @@ -1008,7 +1008,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
90531 * If successful, 0 will be returned.
90532 */
90533 long keyctl_instantiate_key_common(key_serial_t id,
90534 - const struct iovec *payload_iov,
90535 + const struct iovec __user *payload_iov,
90536 unsigned ioc,
90537 size_t plen,
90538 key_serial_t ringid)
90539 @@ -1103,7 +1103,7 @@ long keyctl_instantiate_key(key_serial_t id,
90540 [0].iov_len = plen
90541 };
90542
90543 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
90544 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
90545 }
90546
90547 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
90548 @@ -1136,7 +1136,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
90549 if (ret == 0)
90550 goto no_payload_free;
90551
90552 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
90553 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
90554 err:
90555 if (iov != iovstack)
90556 kfree(iov);
90557 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
90558 index 6ece7f2..ecdb55c 100644
90559 --- a/security/keys/keyring.c
90560 +++ b/security/keys/keyring.c
90561 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
90562 ret = -EFAULT;
90563
90564 for (loop = 0; loop < klist->nkeys; loop++) {
90565 + key_serial_t serial;
90566 key = rcu_deref_link_locked(klist, loop,
90567 keyring);
90568 + serial = key->serial;
90569
90570 tmp = sizeof(key_serial_t);
90571 if (tmp > buflen)
90572 tmp = buflen;
90573
90574 - if (copy_to_user(buffer,
90575 - &key->serial,
90576 - tmp) != 0)
90577 + if (copy_to_user(buffer, &serial, tmp))
90578 goto error;
90579
90580 buflen -= tmp;
90581 diff --git a/security/keys/process_keys.c b/security/keys/process_keys.c
90582 index 58dfe08..c5ec083 100644
90583 --- a/security/keys/process_keys.c
90584 +++ b/security/keys/process_keys.c
90585 @@ -57,7 +57,7 @@ int install_user_keyrings(void)
90586
90587 kenter("%p{%u}", user, uid);
90588
90589 - if (user->uid_keyring) {
90590 + if (user->uid_keyring && user->session_keyring) {
90591 kleave(" = 0 [exist]");
90592 return 0;
90593 }
90594 diff --git a/security/min_addr.c b/security/min_addr.c
90595 index f728728..6457a0c 100644
90596 --- a/security/min_addr.c
90597 +++ b/security/min_addr.c
90598 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
90599 */
90600 static void update_mmap_min_addr(void)
90601 {
90602 +#ifndef SPARC
90603 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
90604 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
90605 mmap_min_addr = dac_mmap_min_addr;
90606 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
90607 #else
90608 mmap_min_addr = dac_mmap_min_addr;
90609 #endif
90610 +#endif
90611 }
90612
90613 /*
90614 diff --git a/security/security.c b/security/security.c
90615 index 7b88c6a..1e3ea8f 100644
90616 --- a/security/security.c
90617 +++ b/security/security.c
90618 @@ -20,6 +20,7 @@
90619 #include <linux/ima.h>
90620 #include <linux/evm.h>
90621 #include <linux/fsnotify.h>
90622 +#include <linux/mm.h>
90623 #include <linux/mman.h>
90624 #include <linux/mount.h>
90625 #include <linux/personality.h>
90626 @@ -32,8 +33,8 @@
90627 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
90628 CONFIG_DEFAULT_SECURITY;
90629
90630 -static struct security_operations *security_ops;
90631 -static struct security_operations default_security_ops = {
90632 +static struct security_operations *security_ops __read_only;
90633 +static struct security_operations default_security_ops __read_only = {
90634 .name = "default",
90635 };
90636
90637 @@ -74,7 +75,9 @@ int __init security_init(void)
90638
90639 void reset_security_ops(void)
90640 {
90641 + pax_open_kernel();
90642 security_ops = &default_security_ops;
90643 + pax_close_kernel();
90644 }
90645
90646 /* Save user chosen LSM */
90647 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
90648 index ef26e96..642fb78 100644
90649 --- a/security/selinux/hooks.c
90650 +++ b/security/selinux/hooks.c
90651 @@ -95,8 +95,6 @@
90652
90653 #define NUM_SEL_MNT_OPTS 5
90654
90655 -extern struct security_operations *security_ops;
90656 -
90657 /* SECMARK reference count */
90658 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
90659
90660 @@ -5501,7 +5499,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
90661
90662 #endif
90663
90664 -static struct security_operations selinux_ops = {
90665 +static struct security_operations selinux_ops __read_only = {
90666 .name = "selinux",
90667
90668 .ptrace_access_check = selinux_ptrace_access_check,
90669 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
90670 index 65f67cb..3f141ef 100644
90671 --- a/security/selinux/include/xfrm.h
90672 +++ b/security/selinux/include/xfrm.h
90673 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
90674
90675 static inline void selinux_xfrm_notify_policyload(void)
90676 {
90677 - atomic_inc(&flow_cache_genid);
90678 + atomic_inc_unchecked(&flow_cache_genid);
90679 rt_genid_bump(&init_net);
90680 }
90681 #else
90682 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
90683 index 38be92c..21f49ee 100644
90684 --- a/security/smack/smack_lsm.c
90685 +++ b/security/smack/smack_lsm.c
90686 @@ -3398,7 +3398,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
90687 return 0;
90688 }
90689
90690 -struct security_operations smack_ops = {
90691 +struct security_operations smack_ops __read_only = {
90692 .name = "smack",
90693
90694 .ptrace_access_check = smack_ptrace_access_check,
90695 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
90696 index 390c646..f2f8db3 100644
90697 --- a/security/tomoyo/mount.c
90698 +++ b/security/tomoyo/mount.c
90699 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
90700 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
90701 need_dev = -1; /* dev_name is a directory */
90702 } else {
90703 + if (!capable(CAP_SYS_ADMIN)) {
90704 + error = -EPERM;
90705 + goto out;
90706 + }
90707 fstype = get_fs_type(type);
90708 if (!fstype) {
90709 error = -ENODEV;
90710 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
90711 index a2ee362..5754f34 100644
90712 --- a/security/tomoyo/tomoyo.c
90713 +++ b/security/tomoyo/tomoyo.c
90714 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
90715 * tomoyo_security_ops is a "struct security_operations" which is used for
90716 * registering TOMOYO.
90717 */
90718 -static struct security_operations tomoyo_security_ops = {
90719 +static struct security_operations tomoyo_security_ops __read_only = {
90720 .name = "tomoyo",
90721 .cred_alloc_blank = tomoyo_cred_alloc_blank,
90722 .cred_prepare = tomoyo_cred_prepare,
90723 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
90724 index 20ef514..4182bed 100644
90725 --- a/security/yama/Kconfig
90726 +++ b/security/yama/Kconfig
90727 @@ -1,6 +1,6 @@
90728 config SECURITY_YAMA
90729 bool "Yama support"
90730 - depends on SECURITY
90731 + depends on SECURITY && !GRKERNSEC
90732 select SECURITYFS
90733 select SECURITY_PATH
90734 default n
90735 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
90736 index 23414b9..b92b314 100644
90737 --- a/security/yama/yama_lsm.c
90738 +++ b/security/yama/yama_lsm.c
90739 @@ -367,7 +367,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
90740 }
90741
90742 #ifndef CONFIG_SECURITY_YAMA_STACKED
90743 -static struct security_operations yama_ops = {
90744 +static struct security_operations yama_ops __read_only = {
90745 .name = "yama",
90746
90747 .ptrace_access_check = yama_ptrace_access_check,
90748 @@ -378,28 +378,24 @@ static struct security_operations yama_ops = {
90749 #endif
90750
90751 #ifdef CONFIG_SYSCTL
90752 +static int zero __read_only;
90753 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
90754 +
90755 static int yama_dointvec_minmax(struct ctl_table *table, int write,
90756 void __user *buffer, size_t *lenp, loff_t *ppos)
90757 {
90758 - int rc;
90759 + ctl_table_no_const yama_table;
90760
90761 if (write && !capable(CAP_SYS_PTRACE))
90762 return -EPERM;
90763
90764 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
90765 - if (rc)
90766 - return rc;
90767 -
90768 + yama_table = *table;
90769 /* Lock the max value if it ever gets set. */
90770 - if (write && *(int *)table->data == *(int *)table->extra2)
90771 - table->extra1 = table->extra2;
90772 -
90773 - return rc;
90774 + if (ptrace_scope == max_scope)
90775 + yama_table.extra1 = &max_scope;
90776 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
90777 }
90778
90779 -static int zero;
90780 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
90781 -
90782 struct ctl_path yama_sysctl_path[] = {
90783 { .procname = "kernel", },
90784 { .procname = "yama", },
90785 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
90786 index 4cedc69..e59d8a3 100644
90787 --- a/sound/aoa/codecs/onyx.c
90788 +++ b/sound/aoa/codecs/onyx.c
90789 @@ -54,7 +54,7 @@ struct onyx {
90790 spdif_locked:1,
90791 analog_locked:1,
90792 original_mute:2;
90793 - int open_count;
90794 + local_t open_count;
90795 struct codec_info *codec_info;
90796
90797 /* mutex serializes concurrent access to the device
90798 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
90799 struct onyx *onyx = cii->codec_data;
90800
90801 mutex_lock(&onyx->mutex);
90802 - onyx->open_count++;
90803 + local_inc(&onyx->open_count);
90804 mutex_unlock(&onyx->mutex);
90805
90806 return 0;
90807 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
90808 struct onyx *onyx = cii->codec_data;
90809
90810 mutex_lock(&onyx->mutex);
90811 - onyx->open_count--;
90812 - if (!onyx->open_count)
90813 + if (local_dec_and_test(&onyx->open_count))
90814 onyx->spdif_locked = onyx->analog_locked = 0;
90815 mutex_unlock(&onyx->mutex);
90816
90817 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
90818 index ffd2025..df062c9 100644
90819 --- a/sound/aoa/codecs/onyx.h
90820 +++ b/sound/aoa/codecs/onyx.h
90821 @@ -11,6 +11,7 @@
90822 #include <linux/i2c.h>
90823 #include <asm/pmac_low_i2c.h>
90824 #include <asm/prom.h>
90825 +#include <asm/local.h>
90826
90827 /* PCM3052 register definitions */
90828
90829 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
90830 index 4c1cc51..16040040 100644
90831 --- a/sound/core/oss/pcm_oss.c
90832 +++ b/sound/core/oss/pcm_oss.c
90833 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
90834 if (in_kernel) {
90835 mm_segment_t fs;
90836 fs = snd_enter_user();
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 snd_leave_user(fs);
90840 } else {
90841 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
90842 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
90843 }
90844 if (ret != -EPIPE && ret != -ESTRPIPE)
90845 break;
90846 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
90847 if (in_kernel) {
90848 mm_segment_t fs;
90849 fs = snd_enter_user();
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 snd_leave_user(fs);
90853 } else {
90854 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
90855 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
90856 }
90857 if (ret == -EPIPE) {
90858 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
90859 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
90860 struct snd_pcm_plugin_channel *channels;
90861 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
90862 if (!in_kernel) {
90863 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
90864 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
90865 return -EFAULT;
90866 buf = runtime->oss.buffer;
90867 }
90868 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
90869 }
90870 } else {
90871 tmp = snd_pcm_oss_write2(substream,
90872 - (const char __force *)buf,
90873 + (const char __force_kernel *)buf,
90874 runtime->oss.period_bytes, 0);
90875 if (tmp <= 0)
90876 goto err;
90877 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
90878 struct snd_pcm_runtime *runtime = substream->runtime;
90879 snd_pcm_sframes_t frames, frames1;
90880 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
90881 - char __user *final_dst = (char __force __user *)buf;
90882 + char __user *final_dst = (char __force_user *)buf;
90883 if (runtime->oss.plugin_first) {
90884 struct snd_pcm_plugin_channel *channels;
90885 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
90886 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
90887 xfer += tmp;
90888 runtime->oss.buffer_used -= tmp;
90889 } else {
90890 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
90891 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
90892 runtime->oss.period_bytes, 0);
90893 if (tmp <= 0)
90894 goto err;
90895 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
90896 size1);
90897 size1 /= runtime->channels; /* frames */
90898 fs = snd_enter_user();
90899 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
90900 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
90901 snd_leave_user(fs);
90902 }
90903 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
90904 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
90905 index af49721..e85058e 100644
90906 --- a/sound/core/pcm_compat.c
90907 +++ b/sound/core/pcm_compat.c
90908 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
90909 int err;
90910
90911 fs = snd_enter_user();
90912 - err = snd_pcm_delay(substream, &delay);
90913 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
90914 snd_leave_user(fs);
90915 if (err < 0)
90916 return err;
90917 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
90918 index 09b4286..8620fac 100644
90919 --- a/sound/core/pcm_native.c
90920 +++ b/sound/core/pcm_native.c
90921 @@ -2806,11 +2806,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
90922 switch (substream->stream) {
90923 case SNDRV_PCM_STREAM_PLAYBACK:
90924 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
90925 - (void __user *)arg);
90926 + (void __force_user *)arg);
90927 break;
90928 case SNDRV_PCM_STREAM_CAPTURE:
90929 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
90930 - (void __user *)arg);
90931 + (void __force_user *)arg);
90932 break;
90933 default:
90934 result = -EINVAL;
90935 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
90936 index 040c60e..989a19a 100644
90937 --- a/sound/core/seq/seq_device.c
90938 +++ b/sound/core/seq/seq_device.c
90939 @@ -64,7 +64,7 @@ struct ops_list {
90940 int argsize; /* argument size */
90941
90942 /* operators */
90943 - struct snd_seq_dev_ops ops;
90944 + struct snd_seq_dev_ops *ops;
90945
90946 /* registered devices */
90947 struct list_head dev_list; /* list of devices */
90948 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
90949
90950 mutex_lock(&ops->reg_mutex);
90951 /* copy driver operators */
90952 - ops->ops = *entry;
90953 + ops->ops = entry;
90954 ops->driver |= DRIVER_LOADED;
90955 ops->argsize = argsize;
90956
90957 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
90958 dev->name, ops->id, ops->argsize, dev->argsize);
90959 return -EINVAL;
90960 }
90961 - if (ops->ops.init_device(dev) >= 0) {
90962 + if (ops->ops->init_device(dev) >= 0) {
90963 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
90964 ops->num_init_devices++;
90965 } else {
90966 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
90967 dev->name, ops->id, ops->argsize, dev->argsize);
90968 return -EINVAL;
90969 }
90970 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
90971 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
90972 dev->status = SNDRV_SEQ_DEVICE_FREE;
90973 dev->driver_data = NULL;
90974 ops->num_init_devices--;
90975 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
90976 index 4e0dd22..7a1f32c 100644
90977 --- a/sound/drivers/mts64.c
90978 +++ b/sound/drivers/mts64.c
90979 @@ -29,6 +29,7 @@
90980 #include <sound/initval.h>
90981 #include <sound/rawmidi.h>
90982 #include <sound/control.h>
90983 +#include <asm/local.h>
90984
90985 #define CARD_NAME "Miditerminal 4140"
90986 #define DRIVER_NAME "MTS64"
90987 @@ -67,7 +68,7 @@ struct mts64 {
90988 struct pardevice *pardev;
90989 int pardev_claimed;
90990
90991 - int open_count;
90992 + local_t open_count;
90993 int current_midi_output_port;
90994 int current_midi_input_port;
90995 u8 mode[MTS64_NUM_INPUT_PORTS];
90996 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
90997 {
90998 struct mts64 *mts = substream->rmidi->private_data;
90999
91000 - if (mts->open_count == 0) {
91001 + if (local_read(&mts->open_count) == 0) {
91002 /* We don't need a spinlock here, because this is just called
91003 if the device has not been opened before.
91004 So there aren't any IRQs from the device */
91005 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
91006
91007 msleep(50);
91008 }
91009 - ++(mts->open_count);
91010 + local_inc(&mts->open_count);
91011
91012 return 0;
91013 }
91014 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
91015 struct mts64 *mts = substream->rmidi->private_data;
91016 unsigned long flags;
91017
91018 - --(mts->open_count);
91019 - if (mts->open_count == 0) {
91020 + if (local_dec_return(&mts->open_count) == 0) {
91021 /* We need the spinlock_irqsave here because we can still
91022 have IRQs at this point */
91023 spin_lock_irqsave(&mts->lock, flags);
91024 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
91025
91026 msleep(500);
91027
91028 - } else if (mts->open_count < 0)
91029 - mts->open_count = 0;
91030 + } else if (local_read(&mts->open_count) < 0)
91031 + local_set(&mts->open_count, 0);
91032
91033 return 0;
91034 }
91035 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
91036 index b953fb4..1999c01 100644
91037 --- a/sound/drivers/opl4/opl4_lib.c
91038 +++ b/sound/drivers/opl4/opl4_lib.c
91039 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
91040 MODULE_DESCRIPTION("OPL4 driver");
91041 MODULE_LICENSE("GPL");
91042
91043 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
91044 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
91045 {
91046 int timeout = 10;
91047 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
91048 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
91049 index 991018d..8984740 100644
91050 --- a/sound/drivers/portman2x4.c
91051 +++ b/sound/drivers/portman2x4.c
91052 @@ -48,6 +48,7 @@
91053 #include <sound/initval.h>
91054 #include <sound/rawmidi.h>
91055 #include <sound/control.h>
91056 +#include <asm/local.h>
91057
91058 #define CARD_NAME "Portman 2x4"
91059 #define DRIVER_NAME "portman"
91060 @@ -85,7 +86,7 @@ struct portman {
91061 struct pardevice *pardev;
91062 int pardev_claimed;
91063
91064 - int open_count;
91065 + local_t open_count;
91066 int mode[PORTMAN_NUM_INPUT_PORTS];
91067 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
91068 };
91069 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
91070 index ea995af..f1bfa37 100644
91071 --- a/sound/firewire/amdtp.c
91072 +++ b/sound/firewire/amdtp.c
91073 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
91074 ptr = s->pcm_buffer_pointer + data_blocks;
91075 if (ptr >= pcm->runtime->buffer_size)
91076 ptr -= pcm->runtime->buffer_size;
91077 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
91078 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
91079
91080 s->pcm_period_pointer += data_blocks;
91081 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
91082 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
91083 */
91084 void amdtp_out_stream_update(struct amdtp_out_stream *s)
91085 {
91086 - ACCESS_ONCE(s->source_node_id_field) =
91087 + ACCESS_ONCE_RW(s->source_node_id_field) =
91088 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
91089 }
91090 EXPORT_SYMBOL(amdtp_out_stream_update);
91091 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
91092 index b680c5e..061b7a0 100644
91093 --- a/sound/firewire/amdtp.h
91094 +++ b/sound/firewire/amdtp.h
91095 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
91096 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
91097 struct snd_pcm_substream *pcm)
91098 {
91099 - ACCESS_ONCE(s->pcm) = pcm;
91100 + ACCESS_ONCE_RW(s->pcm) = pcm;
91101 }
91102
91103 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
91104 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
91105 index d428ffe..751ef78 100644
91106 --- a/sound/firewire/isight.c
91107 +++ b/sound/firewire/isight.c
91108 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
91109 ptr += count;
91110 if (ptr >= runtime->buffer_size)
91111 ptr -= runtime->buffer_size;
91112 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
91113 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
91114
91115 isight->period_counter += count;
91116 if (isight->period_counter >= runtime->period_size) {
91117 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
91118 if (err < 0)
91119 return err;
91120
91121 - ACCESS_ONCE(isight->pcm_active) = true;
91122 + ACCESS_ONCE_RW(isight->pcm_active) = true;
91123
91124 return 0;
91125 }
91126 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
91127 {
91128 struct isight *isight = substream->private_data;
91129
91130 - ACCESS_ONCE(isight->pcm_active) = false;
91131 + ACCESS_ONCE_RW(isight->pcm_active) = false;
91132
91133 mutex_lock(&isight->mutex);
91134 isight_stop_streaming(isight);
91135 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
91136
91137 switch (cmd) {
91138 case SNDRV_PCM_TRIGGER_START:
91139 - ACCESS_ONCE(isight->pcm_running) = true;
91140 + ACCESS_ONCE_RW(isight->pcm_running) = true;
91141 break;
91142 case SNDRV_PCM_TRIGGER_STOP:
91143 - ACCESS_ONCE(isight->pcm_running) = false;
91144 + ACCESS_ONCE_RW(isight->pcm_running) = false;
91145 break;
91146 default:
91147 return -EINVAL;
91148 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
91149 index 844a555..985ab83 100644
91150 --- a/sound/firewire/scs1x.c
91151 +++ b/sound/firewire/scs1x.c
91152 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
91153 {
91154 struct scs *scs = stream->rmidi->private_data;
91155
91156 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
91157 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
91158 if (up) {
91159 scs->output_idle = false;
91160 tasklet_schedule(&scs->tasklet);
91161 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
91162 {
91163 struct scs *scs = stream->rmidi->private_data;
91164
91165 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
91166 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
91167 }
91168
91169 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
91170 @@ -457,8 +457,8 @@ static int scs_remove(struct device *dev)
91171
91172 snd_card_disconnect(scs->card);
91173
91174 - ACCESS_ONCE(scs->output) = NULL;
91175 - ACCESS_ONCE(scs->input) = NULL;
91176 + ACCESS_ONCE_RW(scs->output) = NULL;
91177 + ACCESS_ONCE_RW(scs->input) = NULL;
91178
91179 wait_event(scs->idle_wait, scs->output_idle);
91180
91181 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
91182 index 048439a..3be9f6f 100644
91183 --- a/sound/oss/sb_audio.c
91184 +++ b/sound/oss/sb_audio.c
91185 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
91186 buf16 = (signed short *)(localbuf + localoffs);
91187 while (c)
91188 {
91189 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
91190 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
91191 if (copy_from_user(lbuf8,
91192 userbuf+useroffs + p,
91193 locallen))
91194 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
91195 index 7d8803a..559f8d0 100644
91196 --- a/sound/oss/swarm_cs4297a.c
91197 +++ b/sound/oss/swarm_cs4297a.c
91198 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
91199 {
91200 struct cs4297a_state *s;
91201 u32 pwr, id;
91202 - mm_segment_t fs;
91203 int rval;
91204 #ifndef CONFIG_BCM_CS4297A_CSWARM
91205 u64 cfg;
91206 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
91207 if (!rval) {
91208 char *sb1250_duart_present;
91209
91210 +#if 0
91211 + mm_segment_t fs;
91212 fs = get_fs();
91213 set_fs(KERNEL_DS);
91214 -#if 0
91215 val = SOUND_MASK_LINE;
91216 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
91217 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
91218 val = initvol[i].vol;
91219 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
91220 }
91221 + set_fs(fs);
91222 // cs4297a_write_ac97(s, 0x18, 0x0808);
91223 #else
91224 // cs4297a_write_ac97(s, 0x5e, 0x180);
91225 cs4297a_write_ac97(s, 0x02, 0x0808);
91226 cs4297a_write_ac97(s, 0x18, 0x0808);
91227 #endif
91228 - set_fs(fs);
91229
91230 list_add(&s->list, &cs4297a_devs);
91231
91232 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
91233 index 4631a23..001ae57 100644
91234 --- a/sound/pci/ymfpci/ymfpci.h
91235 +++ b/sound/pci/ymfpci/ymfpci.h
91236 @@ -358,7 +358,7 @@ struct snd_ymfpci {
91237 spinlock_t reg_lock;
91238 spinlock_t voice_lock;
91239 wait_queue_head_t interrupt_sleep;
91240 - atomic_t interrupt_sleep_count;
91241 + atomic_unchecked_t interrupt_sleep_count;
91242 struct snd_info_entry *proc_entry;
91243 const struct firmware *dsp_microcode;
91244 const struct firmware *controller_microcode;
91245 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
91246 index 22056c5..25d3244 100644
91247 --- a/sound/pci/ymfpci/ymfpci_main.c
91248 +++ b/sound/pci/ymfpci/ymfpci_main.c
91249 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
91250 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
91251 break;
91252 }
91253 - if (atomic_read(&chip->interrupt_sleep_count)) {
91254 - atomic_set(&chip->interrupt_sleep_count, 0);
91255 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
91256 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
91257 wake_up(&chip->interrupt_sleep);
91258 }
91259 __end:
91260 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
91261 continue;
91262 init_waitqueue_entry(&wait, current);
91263 add_wait_queue(&chip->interrupt_sleep, &wait);
91264 - atomic_inc(&chip->interrupt_sleep_count);
91265 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
91266 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
91267 remove_wait_queue(&chip->interrupt_sleep, &wait);
91268 }
91269 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
91270 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
91271 spin_unlock(&chip->reg_lock);
91272
91273 - if (atomic_read(&chip->interrupt_sleep_count)) {
91274 - atomic_set(&chip->interrupt_sleep_count, 0);
91275 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
91276 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
91277 wake_up(&chip->interrupt_sleep);
91278 }
91279 }
91280 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
91281 spin_lock_init(&chip->reg_lock);
91282 spin_lock_init(&chip->voice_lock);
91283 init_waitqueue_head(&chip->interrupt_sleep);
91284 - atomic_set(&chip->interrupt_sleep_count, 0);
91285 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
91286 chip->card = card;
91287 chip->pci = pci;
91288 chip->irq = -1;
91289 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
91290 new file mode 100644
91291 index 0000000..50f2f2f
91292 --- /dev/null
91293 +++ b/tools/gcc/.gitignore
91294 @@ -0,0 +1 @@
91295 +size_overflow_hash.h
91296 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
91297 new file mode 100644
91298 index 0000000..6920fb3
91299 --- /dev/null
91300 +++ b/tools/gcc/Makefile
91301 @@ -0,0 +1,43 @@
91302 +#CC := gcc
91303 +#PLUGIN_SOURCE_FILES := pax_plugin.c
91304 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
91305 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
91306 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
91307 +
91308 +ifeq ($(PLUGINCC),$(HOSTCC))
91309 +HOSTLIBS := hostlibs
91310 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
91311 +else
91312 +HOSTLIBS := hostcxxlibs
91313 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -ggdb -Wno-unused-parameter
91314 +endif
91315 +
91316 +$(HOSTLIBS)-y := constify_plugin.so
91317 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
91318 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
91319 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
91320 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
91321 +$(HOSTLIBS)-y += colorize_plugin.so
91322 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
91323 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
91324 +
91325 +always := $($(HOSTLIBS)-y)
91326 +
91327 +constify_plugin-objs := constify_plugin.o
91328 +stackleak_plugin-objs := stackleak_plugin.o
91329 +kallocstat_plugin-objs := kallocstat_plugin.o
91330 +kernexec_plugin-objs := kernexec_plugin.o
91331 +checker_plugin-objs := checker_plugin.o
91332 +colorize_plugin-objs := colorize_plugin.o
91333 +size_overflow_plugin-objs := size_overflow_plugin.o
91334 +latent_entropy_plugin-objs := latent_entropy_plugin.o
91335 +
91336 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
91337 +
91338 +quiet_cmd_build_size_overflow_hash = GENHASH $@
91339 + cmd_build_size_overflow_hash = \
91340 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
91341 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
91342 + $(call if_changed,build_size_overflow_hash)
91343 +
91344 +targets += size_overflow_hash.h
91345 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
91346 new file mode 100644
91347 index 0000000..d41b5af
91348 --- /dev/null
91349 +++ b/tools/gcc/checker_plugin.c
91350 @@ -0,0 +1,171 @@
91351 +/*
91352 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
91353 + * Licensed under the GPL v2
91354 + *
91355 + * Note: the choice of the license means that the compilation process is
91356 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91357 + * but for the kernel it doesn't matter since it doesn't link against
91358 + * any of the gcc libraries
91359 + *
91360 + * gcc plugin to implement various sparse (source code checker) features
91361 + *
91362 + * TODO:
91363 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
91364 + *
91365 + * BUGS:
91366 + * - none known
91367 + */
91368 +#include "gcc-plugin.h"
91369 +#include "config.h"
91370 +#include "system.h"
91371 +#include "coretypes.h"
91372 +#include "tree.h"
91373 +#include "tree-pass.h"
91374 +#include "flags.h"
91375 +#include "intl.h"
91376 +#include "toplev.h"
91377 +#include "plugin.h"
91378 +//#include "expr.h" where are you...
91379 +#include "diagnostic.h"
91380 +#include "plugin-version.h"
91381 +#include "tm.h"
91382 +#include "function.h"
91383 +#include "basic-block.h"
91384 +#include "gimple.h"
91385 +#include "rtl.h"
91386 +#include "emit-rtl.h"
91387 +#include "tree-flow.h"
91388 +#include "target.h"
91389 +
91390 +extern void c_register_addr_space (const char *str, addr_space_t as);
91391 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
91392 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
91393 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
91394 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
91395 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
91396 +
91397 +extern void print_gimple_stmt(FILE *, gimple, int, int);
91398 +extern rtx emit_move_insn(rtx x, rtx y);
91399 +
91400 +int plugin_is_GPL_compatible;
91401 +
91402 +static struct plugin_info checker_plugin_info = {
91403 + .version = "201111150100",
91404 +};
91405 +
91406 +#define ADDR_SPACE_KERNEL 0
91407 +#define ADDR_SPACE_FORCE_KERNEL 1
91408 +#define ADDR_SPACE_USER 2
91409 +#define ADDR_SPACE_FORCE_USER 3
91410 +#define ADDR_SPACE_IOMEM 0
91411 +#define ADDR_SPACE_FORCE_IOMEM 0
91412 +#define ADDR_SPACE_PERCPU 0
91413 +#define ADDR_SPACE_FORCE_PERCPU 0
91414 +#define ADDR_SPACE_RCU 0
91415 +#define ADDR_SPACE_FORCE_RCU 0
91416 +
91417 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
91418 +{
91419 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
91420 +}
91421 +
91422 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
91423 +{
91424 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
91425 +}
91426 +
91427 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
91428 +{
91429 + return default_addr_space_valid_pointer_mode(mode, as);
91430 +}
91431 +
91432 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
91433 +{
91434 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
91435 +}
91436 +
91437 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
91438 +{
91439 + return default_addr_space_legitimize_address(x, oldx, mode, as);
91440 +}
91441 +
91442 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
91443 +{
91444 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
91445 + return true;
91446 +
91447 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
91448 + return true;
91449 +
91450 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
91451 + return true;
91452 +
91453 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
91454 + return true;
91455 +
91456 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
91457 + return true;
91458 +
91459 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
91460 + return true;
91461 +
91462 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
91463 + return true;
91464 +
91465 + return subset == superset;
91466 +}
91467 +
91468 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
91469 +{
91470 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
91471 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
91472 +
91473 + return op;
91474 +}
91475 +
91476 +static void register_checker_address_spaces(void *event_data, void *data)
91477 +{
91478 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
91479 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
91480 + c_register_addr_space("__user", ADDR_SPACE_USER);
91481 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
91482 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
91483 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
91484 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
91485 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
91486 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
91487 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
91488 +
91489 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
91490 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
91491 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
91492 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
91493 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
91494 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
91495 + targetm.addr_space.convert = checker_addr_space_convert;
91496 +}
91497 +
91498 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91499 +{
91500 + const char * const plugin_name = plugin_info->base_name;
91501 + const int argc = plugin_info->argc;
91502 + const struct plugin_argument * const argv = plugin_info->argv;
91503 + int i;
91504 +
91505 + if (!plugin_default_version_check(version, &gcc_version)) {
91506 + error(G_("incompatible gcc/plugin versions"));
91507 + return 1;
91508 + }
91509 +
91510 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
91511 +
91512 + for (i = 0; i < argc; ++i)
91513 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
91514 +
91515 + if (TARGET_64BIT == 0)
91516 + return 0;
91517 +
91518 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
91519 +
91520 + return 0;
91521 +}
91522 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
91523 new file mode 100644
91524 index 0000000..414fe5e
91525 --- /dev/null
91526 +++ b/tools/gcc/colorize_plugin.c
91527 @@ -0,0 +1,151 @@
91528 +/*
91529 + * Copyright 2012-2013 by PaX Team <pageexec@freemail.hu>
91530 + * Licensed under the GPL v2
91531 + *
91532 + * Note: the choice of the license means that the compilation process is
91533 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
91534 + * but for the kernel it doesn't matter since it doesn't link against
91535 + * any of the gcc libraries
91536 + *
91537 + * gcc plugin to colorize diagnostic output
91538 + *
91539 + */
91540 +
91541 +#include "gcc-plugin.h"
91542 +#include "config.h"
91543 +#include "system.h"
91544 +#include "coretypes.h"
91545 +#include "tree.h"
91546 +#include "tree-pass.h"
91547 +#include "flags.h"
91548 +#include "intl.h"
91549 +#include "toplev.h"
91550 +#include "plugin.h"
91551 +#include "diagnostic.h"
91552 +#include "plugin-version.h"
91553 +#include "tm.h"
91554 +
91555 +int plugin_is_GPL_compatible;
91556 +
91557 +static struct plugin_info colorize_plugin_info = {
91558 + .version = "201302112000",
91559 + .help = NULL,
91560 +};
91561 +
91562 +#define GREEN "\033[32m\033[2m"
91563 +#define LIGHTGREEN "\033[32m\033[1m"
91564 +#define YELLOW "\033[33m\033[2m"
91565 +#define LIGHTYELLOW "\033[33m\033[1m"
91566 +#define RED "\033[31m\033[2m"
91567 +#define LIGHTRED "\033[31m\033[1m"
91568 +#define BLUE "\033[34m\033[2m"
91569 +#define LIGHTBLUE "\033[34m\033[1m"
91570 +#define BRIGHT "\033[m\033[1m"
91571 +#define NORMAL "\033[m"
91572 +
91573 +static diagnostic_starter_fn old_starter;
91574 +static diagnostic_finalizer_fn old_finalizer;
91575 +
91576 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
91577 +{
91578 + const char *color;
91579 + char *newprefix;
91580 +
91581 + switch (diagnostic->kind) {
91582 + case DK_NOTE:
91583 + color = LIGHTBLUE;
91584 + break;
91585 +
91586 + case DK_PEDWARN:
91587 + case DK_WARNING:
91588 + color = LIGHTYELLOW;
91589 + break;
91590 +
91591 + case DK_ERROR:
91592 + case DK_FATAL:
91593 + case DK_ICE:
91594 + case DK_PERMERROR:
91595 + case DK_SORRY:
91596 + color = LIGHTRED;
91597 + break;
91598 +
91599 + default:
91600 + color = NORMAL;
91601 + }
91602 +
91603 + old_starter(context, diagnostic);
91604 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
91605 + return;
91606 + pp_destroy_prefix(context->printer);
91607 + pp_set_prefix(context->printer, newprefix);
91608 +}
91609 +
91610 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
91611 +{
91612 + old_finalizer(context, diagnostic);
91613 +}
91614 +
91615 +static void colorize_arm(void)
91616 +{
91617 + old_starter = diagnostic_starter(global_dc);
91618 + old_finalizer = diagnostic_finalizer(global_dc);
91619 +
91620 + diagnostic_starter(global_dc) = start_colorize;
91621 + diagnostic_finalizer(global_dc) = finalize_colorize;
91622 +}
91623 +
91624 +static unsigned int execute_colorize_rearm(void)
91625 +{
91626 + if (diagnostic_starter(global_dc) == start_colorize)
91627 + return 0;
91628 +
91629 + colorize_arm();
91630 + return 0;
91631 +}
91632 +
91633 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
91634 + .pass = {
91635 + .type = SIMPLE_IPA_PASS,
91636 + .name = "colorize_rearm",
91637 +#if BUILDING_GCC_VERSION >= 4008
91638 + .optinfo_flags = OPTGROUP_NONE,
91639 +#endif
91640 + .gate = NULL,
91641 + .execute = execute_colorize_rearm,
91642 + .sub = NULL,
91643 + .next = NULL,
91644 + .static_pass_number = 0,
91645 + .tv_id = TV_NONE,
91646 + .properties_required = 0,
91647 + .properties_provided = 0,
91648 + .properties_destroyed = 0,
91649 + .todo_flags_start = 0,
91650 + .todo_flags_finish = 0
91651 + }
91652 +};
91653 +
91654 +static void colorize_start_unit(void *gcc_data, void *user_data)
91655 +{
91656 + colorize_arm();
91657 +}
91658 +
91659 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
91660 +{
91661 + const char * const plugin_name = plugin_info->base_name;
91662 + struct register_pass_info colorize_rearm_pass_info = {
91663 + .pass = &pass_ipa_colorize_rearm.pass,
91664 + .reference_pass_name = "*free_lang_data",
91665 + .ref_pass_instance_number = 1,
91666 + .pos_op = PASS_POS_INSERT_AFTER
91667 + };
91668 +
91669 + if (!plugin_default_version_check(version, &gcc_version)) {
91670 + error(G_("incompatible gcc/plugin versions"));
91671 + return 1;
91672 + }
91673 +
91674 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
91675 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
91676 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
91677 + return 0;
91678 +}
91679 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
91680 new file mode 100644
91681 index 0000000..43e86d6
91682 --- /dev/null
91683 +++ b/tools/gcc/constify_plugin.c
91684 @@ -0,0 +1,512 @@
91685 +/*
91686 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
91687 + * Copyright 2011-2013 by PaX Team <pageexec@freemail.hu>
91688 + * Licensed under the GPL v2, or (at your option) v3
91689 + *
91690 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
91691 + *
91692 + * Homepage:
91693 + * http://www.grsecurity.net/~ephox/const_plugin/
91694 + *
91695 + * Usage:
91696 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
91697 + * $ gcc -fplugin=constify_plugin.so test.c -O2
91698 + */
91699 +
91700 +#include "gcc-plugin.h"
91701 +#include "config.h"
91702 +#include "system.h"
91703 +#include "coretypes.h"
91704 +#include "tree.h"
91705 +#include "tree-pass.h"
91706 +#include "flags.h"
91707 +#include "intl.h"
91708 +#include "toplev.h"
91709 +#include "plugin.h"
91710 +#include "diagnostic.h"
91711 +#include "plugin-version.h"
91712 +#include "tm.h"
91713 +#include "function.h"
91714 +#include "basic-block.h"
91715 +#include "gimple.h"
91716 +#include "rtl.h"
91717 +#include "emit-rtl.h"
91718 +#include "tree-flow.h"
91719 +#include "target.h"
91720 +
91721 +// should come from c-tree.h if only it were installed for gcc 4.5...
91722 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
91723 +
91724 +// unused type flag in all versions 4.5-4.8
91725 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
91726 +
91727 +int plugin_is_GPL_compatible;
91728 +
91729 +static struct plugin_info const_plugin_info = {
91730 + .version = "201303070020",
91731 + .help = "no-constify\tturn off constification\n",
91732 +};
91733 +
91734 +typedef struct {
91735 + bool has_fptr_field;
91736 + bool has_writable_field;
91737 + bool has_do_const_field;
91738 + bool has_no_const_field;
91739 +} constify_info;
91740 +
91741 +static const_tree get_field_type(const_tree field)
91742 +{
91743 + return strip_array_types(TREE_TYPE(field));
91744 +}
91745 +
91746 +static bool is_fptr(const_tree field)
91747 +{
91748 + const_tree ptr = get_field_type(field);
91749 +
91750 + if (TREE_CODE(ptr) != POINTER_TYPE)
91751 + return false;
91752 +
91753 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
91754 +}
91755 +
91756 +/*
91757 + * determine whether the given structure type meets the requirements for automatic constification,
91758 + * including the constification attributes on nested structure types
91759 + */
91760 +static void constifiable(const_tree node, constify_info *cinfo)
91761 +{
91762 + const_tree field;
91763 +
91764 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
91765 +
91766 + // e.g., pointer to structure fields while still constructing the structure type
91767 + if (TYPE_FIELDS(node) == NULL_TREE)
91768 + return;
91769 +
91770 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
91771 + const_tree type = get_field_type(field);
91772 + enum tree_code code = TREE_CODE(type);
91773 +
91774 + if (node == type)
91775 + continue;
91776 +
91777 + if (is_fptr(field))
91778 + cinfo->has_fptr_field = true;
91779 + else if (!TREE_READONLY(field))
91780 + cinfo->has_writable_field = true;
91781 +
91782 + if (code == RECORD_TYPE || code == UNION_TYPE) {
91783 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91784 + cinfo->has_do_const_field = true;
91785 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
91786 + cinfo->has_no_const_field = true;
91787 + else
91788 + constifiable(type, cinfo);
91789 + }
91790 + }
91791 +}
91792 +
91793 +static bool constified(const_tree node)
91794 +{
91795 + constify_info cinfo = {
91796 + .has_fptr_field = false,
91797 + .has_writable_field = false,
91798 + .has_do_const_field = false,
91799 + .has_no_const_field = false
91800 + };
91801 +
91802 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
91803 +
91804 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
91805 + gcc_assert(!TYPE_READONLY(node));
91806 + return false;
91807 + }
91808 +
91809 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
91810 + gcc_assert(TYPE_READONLY(node));
91811 + return true;
91812 + }
91813 +
91814 + constifiable(node, &cinfo);
91815 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
91816 + return false;
91817 +
91818 + return TYPE_READONLY(node);
91819 +}
91820 +
91821 +static void deconstify_tree(tree node);
91822 +
91823 +static void deconstify_type(tree type)
91824 +{
91825 + tree field;
91826 +
91827 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
91828 +
91829 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
91830 + const_tree fieldtype = get_field_type(field);
91831 +
91832 + // special case handling of simple ptr-to-same-array-type members
91833 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
91834 + const_tree ptrtype = TREE_TYPE(TREE_TYPE(field));
91835 +
91836 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
91837 + continue;
91838 + if (TREE_TYPE(TREE_TYPE(field)) == type)
91839 + continue;
91840 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
91841 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
91842 + TREE_TYPE(TREE_TYPE(field)) = type;
91843 + }
91844 + continue;
91845 + }
91846 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
91847 + continue;
91848 + if (!constified(fieldtype))
91849 + continue;
91850 +
91851 + deconstify_tree(field);
91852 + TREE_READONLY(field) = 0;
91853 + }
91854 + TYPE_READONLY(type) = 0;
91855 + C_TYPE_FIELDS_READONLY(type) = 0;
91856 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91857 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
91858 +}
91859 +
91860 +static void deconstify_tree(tree node)
91861 +{
91862 + tree old_type, new_type, field;
91863 +
91864 + old_type = TREE_TYPE(node);
91865 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
91866 + node = TREE_TYPE(node) = copy_node(old_type);
91867 + old_type = TREE_TYPE(old_type);
91868 + }
91869 +
91870 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
91871 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
91872 +
91873 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
91874 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
91875 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
91876 + DECL_FIELD_CONTEXT(field) = new_type;
91877 +
91878 + deconstify_type(new_type);
91879 +
91880 + TREE_TYPE(node) = new_type;
91881 +}
91882 +
91883 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
91884 +{
91885 + tree type;
91886 + constify_info cinfo = {
91887 + .has_fptr_field = false,
91888 + .has_writable_field = false,
91889 + .has_do_const_field = false,
91890 + .has_no_const_field = false
91891 + };
91892 +
91893 + *no_add_attrs = true;
91894 + if (TREE_CODE(*node) == FUNCTION_DECL) {
91895 + error("%qE attribute does not apply to functions", name);
91896 + return NULL_TREE;
91897 + }
91898 +
91899 + if (TREE_CODE(*node) == PARM_DECL) {
91900 + error("%qE attribute does not apply to function parameters", name);
91901 + return NULL_TREE;
91902 + }
91903 +
91904 + if (TREE_CODE(*node) == VAR_DECL) {
91905 + error("%qE attribute does not apply to variables", name);
91906 + return NULL_TREE;
91907 + }
91908 +
91909 + if (TYPE_P(*node)) {
91910 + *no_add_attrs = false;
91911 + type = *node;
91912 + } else {
91913 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
91914 + type = TREE_TYPE(*node);
91915 + }
91916 +
91917 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
91918 + error("%qE attribute applies to struct and union types only", name);
91919 + return NULL_TREE;
91920 + }
91921 +
91922 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
91923 + error("%qE attribute is already applied to the type", name);
91924 + return NULL_TREE;
91925 + }
91926 +
91927 + if (TYPE_P(*node)) {
91928 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
91929 + error("%qE attribute is incompatible with 'do_const'", name);
91930 + return NULL_TREE;
91931 + }
91932 +
91933 + constifiable(type, &cinfo);
91934 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
91935 + deconstify_tree(*node);
91936 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
91937 + return NULL_TREE;
91938 + }
91939 +
91940 + error("%qE attribute used on type that is not constified", name);
91941 + return NULL_TREE;
91942 +}
91943 +
91944 +static void constify_type(tree type)
91945 +{
91946 + TYPE_READONLY(type) = 1;
91947 + C_TYPE_FIELDS_READONLY(type) = 1;
91948 + TYPE_CONSTIFY_VISITED(type) = 1;
91949 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
91950 +}
91951 +
91952 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
91953 +{
91954 + *no_add_attrs = true;
91955 + if (!TYPE_P(*node)) {
91956 + error("%qE attribute applies to types only", name);
91957 + return NULL_TREE;
91958 + }
91959 +
91960 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
91961 + error("%qE attribute applies to struct and union types only", name);
91962 + return NULL_TREE;
91963 + }
91964 +
91965 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
91966 + error("%qE attribute is already applied to the type", name);
91967 + return NULL_TREE;
91968 + }
91969 +
91970 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
91971 + error("%qE attribute is incompatible with 'no_const'", name);
91972 + return NULL_TREE;
91973 + }
91974 +
91975 + *no_add_attrs = false;
91976 + return NULL_TREE;
91977 +}
91978 +
91979 +static struct attribute_spec no_const_attr = {
91980 + .name = "no_const",
91981 + .min_length = 0,
91982 + .max_length = 0,
91983 + .decl_required = false,
91984 + .type_required = false,
91985 + .function_type_required = false,
91986 + .handler = handle_no_const_attribute,
91987 +#if BUILDING_GCC_VERSION >= 4007
91988 + .affects_type_identity = true
91989 +#endif
91990 +};
91991 +
91992 +static struct attribute_spec do_const_attr = {
91993 + .name = "do_const",
91994 + .min_length = 0,
91995 + .max_length = 0,
91996 + .decl_required = false,
91997 + .type_required = false,
91998 + .function_type_required = false,
91999 + .handler = handle_do_const_attribute,
92000 +#if BUILDING_GCC_VERSION >= 4007
92001 + .affects_type_identity = true
92002 +#endif
92003 +};
92004 +
92005 +static void register_attributes(void *event_data, void *data)
92006 +{
92007 + register_attribute(&no_const_attr);
92008 + register_attribute(&do_const_attr);
92009 +}
92010 +
92011 +static void finish_type(void *event_data, void *data)
92012 +{
92013 + tree type = (tree)event_data;
92014 + constify_info cinfo = {
92015 + .has_fptr_field = false,
92016 + .has_writable_field = false,
92017 + .has_do_const_field = false,
92018 + .has_no_const_field = false
92019 + };
92020 +
92021 + if (type == NULL_TREE || type == error_mark_node)
92022 + return;
92023 +
92024 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
92025 + return;
92026 +
92027 + constifiable(type, &cinfo);
92028 +
92029 + if (TYPE_READONLY(type) && C_TYPE_FIELDS_READONLY(type)) {
92030 + if (!lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
92031 + return;
92032 + if (cinfo.has_writable_field)
92033 + return;
92034 + error("'do_const' attribute used on type that is%sconstified", cinfo.has_fptr_field ? " " : " not ");
92035 + return;
92036 + }
92037 +
92038 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
92039 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
92040 + deconstify_type(type);
92041 + TYPE_CONSTIFY_VISITED(type) = 1;
92042 + } else
92043 + error("'no_const' attribute used on type that is not constified");
92044 + return;
92045 + }
92046 +
92047 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
92048 + constify_type(type);
92049 + return;
92050 + }
92051 +
92052 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
92053 + constify_type(type);
92054 + return;
92055 + }
92056 +
92057 + deconstify_type(type);
92058 + TYPE_CONSTIFY_VISITED(type) = 1;
92059 +}
92060 +
92061 +static unsigned int check_local_variables(void)
92062 +{
92063 + unsigned int ret = 0;
92064 + tree var;
92065 +
92066 +#if BUILDING_GCC_VERSION == 4005
92067 + tree vars;
92068 +#else
92069 + unsigned int i;
92070 +#endif
92071 +
92072 +#if BUILDING_GCC_VERSION == 4005
92073 + for (vars = cfun->local_decls; vars; vars = TREE_CHAIN(vars)) {
92074 + var = TREE_VALUE(vars);
92075 +#else
92076 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
92077 +#endif
92078 + tree type = TREE_TYPE(var);
92079 +
92080 + gcc_assert(DECL_P(var));
92081 + if (is_global_var(var))
92082 + continue;
92083 +
92084 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
92085 + continue;
92086 +
92087 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
92088 + continue;
92089 +
92090 + if (!TYPE_CONSTIFY_VISITED(type))
92091 + continue;
92092 +
92093 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
92094 + ret = 1;
92095 + }
92096 + return ret;
92097 +}
92098 +
92099 +static struct gimple_opt_pass pass_local_variable = {
92100 + {
92101 + .type = GIMPLE_PASS,
92102 + .name = "check_local_variables",
92103 +#if BUILDING_GCC_VERSION >= 4008
92104 + .optinfo_flags = OPTGROUP_NONE,
92105 +#endif
92106 + .gate = NULL,
92107 + .execute = check_local_variables,
92108 + .sub = NULL,
92109 + .next = NULL,
92110 + .static_pass_number = 0,
92111 + .tv_id = TV_NONE,
92112 + .properties_required = 0,
92113 + .properties_provided = 0,
92114 + .properties_destroyed = 0,
92115 + .todo_flags_start = 0,
92116 + .todo_flags_finish = 0
92117 + }
92118 +};
92119 +
92120 +static struct {
92121 + const char *name;
92122 + const char *asm_op;
92123 +} sections[] = {
92124 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
92125 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
92126 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
92127 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
92128 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
92129 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
92130 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
92131 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
92132 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
92133 +};
92134 +
92135 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
92136 +
92137 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
92138 +{
92139 + size_t i;
92140 +
92141 + for (i = 0; i < ARRAY_SIZE(sections); i++)
92142 + if (!strcmp(sections[i].name, name))
92143 + return 0;
92144 + return old_section_type_flags(decl, name, reloc);
92145 +}
92146 +
92147 +static void constify_start_unit(void *gcc_data, void *user_data)
92148 +{
92149 +// size_t i;
92150 +
92151 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
92152 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
92153 +// sections[i].section = get_section(sections[i].name, 0, NULL);
92154 +
92155 + old_section_type_flags = targetm.section_type_flags;
92156 + targetm.section_type_flags = constify_section_type_flags;
92157 +}
92158 +
92159 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92160 +{
92161 + const char * const plugin_name = plugin_info->base_name;
92162 + const int argc = plugin_info->argc;
92163 + const struct plugin_argument * const argv = plugin_info->argv;
92164 + int i;
92165 + bool constify = true;
92166 +
92167 + struct register_pass_info local_variable_pass_info = {
92168 + .pass = &pass_local_variable.pass,
92169 + .reference_pass_name = "ssa",
92170 + .ref_pass_instance_number = 1,
92171 + .pos_op = PASS_POS_INSERT_BEFORE
92172 + };
92173 +
92174 + if (!plugin_default_version_check(version, &gcc_version)) {
92175 + error(G_("incompatible gcc/plugin versions"));
92176 + return 1;
92177 + }
92178 +
92179 + for (i = 0; i < argc; ++i) {
92180 + if (!(strcmp(argv[i].key, "no-constify"))) {
92181 + constify = false;
92182 + continue;
92183 + }
92184 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92185 + }
92186 +
92187 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
92188 + if (constify) {
92189 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
92190 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
92191 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
92192 + }
92193 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
92194 +
92195 + return 0;
92196 +}
92197 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
92198 new file mode 100644
92199 index 0000000..e518932
92200 --- /dev/null
92201 +++ b/tools/gcc/generate_size_overflow_hash.sh
92202 @@ -0,0 +1,94 @@
92203 +#!/bin/bash
92204 +
92205 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
92206 +
92207 +header1="size_overflow_hash.h"
92208 +database="size_overflow_hash.data"
92209 +n=65536
92210 +
92211 +usage() {
92212 +cat <<EOF
92213 +usage: $0 options
92214 +OPTIONS:
92215 + -h|--help help
92216 + -o header file
92217 + -d database file
92218 + -n hash array size
92219 +EOF
92220 + return 0
92221 +}
92222 +
92223 +while true
92224 +do
92225 + case "$1" in
92226 + -h|--help) usage && exit 0;;
92227 + -n) n=$2; shift 2;;
92228 + -o) header1="$2"; shift 2;;
92229 + -d) database="$2"; shift 2;;
92230 + --) shift 1; break ;;
92231 + *) break ;;
92232 + esac
92233 +done
92234 +
92235 +create_defines() {
92236 + for i in `seq 0 31`
92237 + do
92238 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
92239 + done
92240 + echo >> "$header1"
92241 +}
92242 +
92243 +create_structs() {
92244 + rm -f "$header1"
92245 +
92246 + create_defines
92247 +
92248 + cat "$database" | while read data
92249 + do
92250 + data_array=($data)
92251 + struct_hash_name="${data_array[0]}"
92252 + funcn="${data_array[1]}"
92253 + params="${data_array[2]}"
92254 + next="${data_array[4]}"
92255 +
92256 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
92257 +
92258 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
92259 + echo -en "\t.param\t= " >> "$header1"
92260 + line=
92261 + for param_num in ${params//-/ };
92262 + do
92263 + line="${line}PARAM"$param_num"|"
92264 + done
92265 +
92266 + echo -e "${line%?},\n};\n" >> "$header1"
92267 + done
92268 +}
92269 +
92270 +create_headers() {
92271 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
92272 +}
92273 +
92274 +create_array_elements() {
92275 + index=0
92276 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
92277 + do
92278 + data_array=($data)
92279 + i="${data_array[3]}"
92280 + hash="${data_array[0]}"
92281 + while [[ $index -lt $i ]]
92282 + do
92283 + echo -e "\t["$index"]\t= NULL," >> "$header1"
92284 + index=$(($index + 1))
92285 + done
92286 + index=$(($index + 1))
92287 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
92288 + done
92289 + echo '};' >> $header1
92290 +}
92291 +
92292 +create_structs
92293 +create_headers
92294 +create_array_elements
92295 +
92296 +exit 0
92297 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
92298 new file mode 100644
92299 index 0000000..568b360
92300 --- /dev/null
92301 +++ b/tools/gcc/kallocstat_plugin.c
92302 @@ -0,0 +1,170 @@
92303 +/*
92304 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
92305 + * Licensed under the GPL v2
92306 + *
92307 + * Note: the choice of the license means that the compilation process is
92308 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92309 + * but for the kernel it doesn't matter since it doesn't link against
92310 + * any of the gcc libraries
92311 + *
92312 + * gcc plugin to find the distribution of k*alloc sizes
92313 + *
92314 + * TODO:
92315 + *
92316 + * BUGS:
92317 + * - none known
92318 + */
92319 +#include "gcc-plugin.h"
92320 +#include "config.h"
92321 +#include "system.h"
92322 +#include "coretypes.h"
92323 +#include "tree.h"
92324 +#include "tree-pass.h"
92325 +#include "flags.h"
92326 +#include "intl.h"
92327 +#include "toplev.h"
92328 +#include "plugin.h"
92329 +//#include "expr.h" where are you...
92330 +#include "diagnostic.h"
92331 +#include "plugin-version.h"
92332 +#include "tm.h"
92333 +#include "function.h"
92334 +#include "basic-block.h"
92335 +#include "gimple.h"
92336 +#include "rtl.h"
92337 +#include "emit-rtl.h"
92338 +
92339 +extern void print_gimple_stmt(FILE *, gimple, int, int);
92340 +
92341 +int plugin_is_GPL_compatible;
92342 +
92343 +static const char * const kalloc_functions[] = {
92344 + "__kmalloc",
92345 + "kmalloc",
92346 + "kmalloc_large",
92347 + "kmalloc_node",
92348 + "kmalloc_order",
92349 + "kmalloc_order_trace",
92350 + "kmalloc_slab",
92351 + "kzalloc",
92352 + "kzalloc_node",
92353 +};
92354 +
92355 +static struct plugin_info kallocstat_plugin_info = {
92356 + .version = "201302112000",
92357 +};
92358 +
92359 +static unsigned int execute_kallocstat(void);
92360 +
92361 +static struct gimple_opt_pass kallocstat_pass = {
92362 + .pass = {
92363 + .type = GIMPLE_PASS,
92364 + .name = "kallocstat",
92365 +#if BUILDING_GCC_VERSION >= 4008
92366 + .optinfo_flags = OPTGROUP_NONE,
92367 +#endif
92368 + .gate = NULL,
92369 + .execute = execute_kallocstat,
92370 + .sub = NULL,
92371 + .next = NULL,
92372 + .static_pass_number = 0,
92373 + .tv_id = TV_NONE,
92374 + .properties_required = 0,
92375 + .properties_provided = 0,
92376 + .properties_destroyed = 0,
92377 + .todo_flags_start = 0,
92378 + .todo_flags_finish = 0
92379 + }
92380 +};
92381 +
92382 +static bool is_kalloc(const char *fnname)
92383 +{
92384 + size_t i;
92385 +
92386 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
92387 + if (!strcmp(fnname, kalloc_functions[i]))
92388 + return true;
92389 + return false;
92390 +}
92391 +
92392 +static unsigned int execute_kallocstat(void)
92393 +{
92394 + basic_block bb;
92395 +
92396 + // 1. loop through BBs and GIMPLE statements
92397 + FOR_EACH_BB(bb) {
92398 + gimple_stmt_iterator gsi;
92399 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92400 + // gimple match:
92401 + tree fndecl, size;
92402 + gimple call_stmt;
92403 + const char *fnname;
92404 +
92405 + // is it a call
92406 + call_stmt = gsi_stmt(gsi);
92407 + if (!is_gimple_call(call_stmt))
92408 + continue;
92409 + fndecl = gimple_call_fndecl(call_stmt);
92410 + if (fndecl == NULL_TREE)
92411 + continue;
92412 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
92413 + continue;
92414 +
92415 + // is it a call to k*alloc
92416 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
92417 + if (!is_kalloc(fnname))
92418 + continue;
92419 +
92420 + // is the size arg the result of a simple const assignment
92421 + size = gimple_call_arg(call_stmt, 0);
92422 + while (true) {
92423 + gimple def_stmt;
92424 + expanded_location xloc;
92425 + size_t size_val;
92426 +
92427 + if (TREE_CODE(size) != SSA_NAME)
92428 + break;
92429 + def_stmt = SSA_NAME_DEF_STMT(size);
92430 + if (!def_stmt || !is_gimple_assign(def_stmt))
92431 + break;
92432 + if (gimple_num_ops(def_stmt) != 2)
92433 + break;
92434 + size = gimple_assign_rhs1(def_stmt);
92435 + if (!TREE_CONSTANT(size))
92436 + continue;
92437 + xloc = expand_location(gimple_location(def_stmt));
92438 + if (!xloc.file)
92439 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
92440 + size_val = TREE_INT_CST_LOW(size);
92441 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
92442 + break;
92443 + }
92444 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
92445 +//debug_tree(gimple_call_fn(call_stmt));
92446 +//print_node(stderr, "pax", fndecl, 4);
92447 + }
92448 + }
92449 +
92450 + return 0;
92451 +}
92452 +
92453 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92454 +{
92455 + const char * const plugin_name = plugin_info->base_name;
92456 + struct register_pass_info kallocstat_pass_info = {
92457 + .pass = &kallocstat_pass.pass,
92458 + .reference_pass_name = "ssa",
92459 + .ref_pass_instance_number = 1,
92460 + .pos_op = PASS_POS_INSERT_AFTER
92461 + };
92462 +
92463 + if (!plugin_default_version_check(version, &gcc_version)) {
92464 + error(G_("incompatible gcc/plugin versions"));
92465 + return 1;
92466 + }
92467 +
92468 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
92469 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
92470 +
92471 + return 0;
92472 +}
92473 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
92474 new file mode 100644
92475 index 0000000..0408e06
92476 --- /dev/null
92477 +++ b/tools/gcc/kernexec_plugin.c
92478 @@ -0,0 +1,465 @@
92479 +/*
92480 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
92481 + * Licensed under the GPL v2
92482 + *
92483 + * Note: the choice of the license means that the compilation process is
92484 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92485 + * but for the kernel it doesn't matter since it doesn't link against
92486 + * any of the gcc libraries
92487 + *
92488 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
92489 + *
92490 + * TODO:
92491 + *
92492 + * BUGS:
92493 + * - none known
92494 + */
92495 +#include "gcc-plugin.h"
92496 +#include "config.h"
92497 +#include "system.h"
92498 +#include "coretypes.h"
92499 +#include "tree.h"
92500 +#include "tree-pass.h"
92501 +#include "flags.h"
92502 +#include "intl.h"
92503 +#include "toplev.h"
92504 +#include "plugin.h"
92505 +//#include "expr.h" where are you...
92506 +#include "diagnostic.h"
92507 +#include "plugin-version.h"
92508 +#include "tm.h"
92509 +#include "function.h"
92510 +#include "basic-block.h"
92511 +#include "gimple.h"
92512 +#include "rtl.h"
92513 +#include "emit-rtl.h"
92514 +#include "tree-flow.h"
92515 +
92516 +extern void print_gimple_stmt(FILE *, gimple, int, int);
92517 +extern rtx emit_move_insn(rtx x, rtx y);
92518 +
92519 +#if BUILDING_GCC_VERSION <= 4006
92520 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
92521 +#endif
92522 +
92523 +#if BUILDING_GCC_VERSION >= 4008
92524 +#define TODO_dump_func 0
92525 +#endif
92526 +
92527 +int plugin_is_GPL_compatible;
92528 +
92529 +static struct plugin_info kernexec_plugin_info = {
92530 + .version = "201302112000",
92531 + .help = "method=[bts|or]\tinstrumentation method\n"
92532 +};
92533 +
92534 +static unsigned int execute_kernexec_reload(void);
92535 +static unsigned int execute_kernexec_fptr(void);
92536 +static unsigned int execute_kernexec_retaddr(void);
92537 +static bool kernexec_cmodel_check(void);
92538 +
92539 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
92540 +static void (*kernexec_instrument_retaddr)(rtx);
92541 +
92542 +static struct gimple_opt_pass kernexec_reload_pass = {
92543 + .pass = {
92544 + .type = GIMPLE_PASS,
92545 + .name = "kernexec_reload",
92546 +#if BUILDING_GCC_VERSION >= 4008
92547 + .optinfo_flags = OPTGROUP_NONE,
92548 +#endif
92549 + .gate = kernexec_cmodel_check,
92550 + .execute = execute_kernexec_reload,
92551 + .sub = NULL,
92552 + .next = NULL,
92553 + .static_pass_number = 0,
92554 + .tv_id = TV_NONE,
92555 + .properties_required = 0,
92556 + .properties_provided = 0,
92557 + .properties_destroyed = 0,
92558 + .todo_flags_start = 0,
92559 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
92560 + }
92561 +};
92562 +
92563 +static struct gimple_opt_pass kernexec_fptr_pass = {
92564 + .pass = {
92565 + .type = GIMPLE_PASS,
92566 + .name = "kernexec_fptr",
92567 +#if BUILDING_GCC_VERSION >= 4008
92568 + .optinfo_flags = OPTGROUP_NONE,
92569 +#endif
92570 + .gate = kernexec_cmodel_check,
92571 + .execute = execute_kernexec_fptr,
92572 + .sub = NULL,
92573 + .next = NULL,
92574 + .static_pass_number = 0,
92575 + .tv_id = TV_NONE,
92576 + .properties_required = 0,
92577 + .properties_provided = 0,
92578 + .properties_destroyed = 0,
92579 + .todo_flags_start = 0,
92580 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
92581 + }
92582 +};
92583 +
92584 +static struct rtl_opt_pass kernexec_retaddr_pass = {
92585 + .pass = {
92586 + .type = RTL_PASS,
92587 + .name = "kernexec_retaddr",
92588 +#if BUILDING_GCC_VERSION >= 4008
92589 + .optinfo_flags = OPTGROUP_NONE,
92590 +#endif
92591 + .gate = kernexec_cmodel_check,
92592 + .execute = execute_kernexec_retaddr,
92593 + .sub = NULL,
92594 + .next = NULL,
92595 + .static_pass_number = 0,
92596 + .tv_id = TV_NONE,
92597 + .properties_required = 0,
92598 + .properties_provided = 0,
92599 + .properties_destroyed = 0,
92600 + .todo_flags_start = 0,
92601 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
92602 + }
92603 +};
92604 +
92605 +static bool kernexec_cmodel_check(void)
92606 +{
92607 + tree section;
92608 +
92609 + if (ix86_cmodel != CM_KERNEL)
92610 + return false;
92611 +
92612 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
92613 + if (!section || !TREE_VALUE(section))
92614 + return true;
92615 +
92616 + section = TREE_VALUE(TREE_VALUE(section));
92617 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
92618 + return true;
92619 +
92620 + return false;
92621 +}
92622 +
92623 +/*
92624 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
92625 + */
92626 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
92627 +{
92628 + gimple asm_movabs_stmt;
92629 +
92630 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
92631 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
92632 + gimple_asm_set_volatile(asm_movabs_stmt, true);
92633 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
92634 + update_stmt(asm_movabs_stmt);
92635 +}
92636 +
92637 +/*
92638 + * find all asm() stmts that clobber r10 and add a reload of r10
92639 + */
92640 +static unsigned int execute_kernexec_reload(void)
92641 +{
92642 + basic_block bb;
92643 +
92644 + // 1. loop through BBs and GIMPLE statements
92645 + FOR_EACH_BB(bb) {
92646 + gimple_stmt_iterator gsi;
92647 +
92648 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92649 + // gimple match: __asm__ ("" : : : "r10");
92650 + gimple asm_stmt;
92651 + size_t nclobbers;
92652 +
92653 + // is it an asm ...
92654 + asm_stmt = gsi_stmt(gsi);
92655 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
92656 + continue;
92657 +
92658 + // ... clobbering r10
92659 + nclobbers = gimple_asm_nclobbers(asm_stmt);
92660 + while (nclobbers--) {
92661 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
92662 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
92663 + continue;
92664 + kernexec_reload_fptr_mask(&gsi);
92665 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
92666 + break;
92667 + }
92668 + }
92669 + }
92670 +
92671 + return 0;
92672 +}
92673 +
92674 +/*
92675 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
92676 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
92677 + */
92678 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
92679 +{
92680 + gimple assign_intptr, assign_new_fptr, call_stmt;
92681 + tree intptr, old_fptr, new_fptr, kernexec_mask;
92682 +
92683 + call_stmt = gsi_stmt(*gsi);
92684 + old_fptr = gimple_call_fn(call_stmt);
92685 +
92686 + // create temporary unsigned long variable used for bitops and cast fptr to it
92687 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
92688 +#if BUILDING_GCC_VERSION <= 4007
92689 + add_referenced_var(intptr);
92690 + mark_sym_for_renaming(intptr);
92691 +#endif
92692 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
92693 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
92694 + update_stmt(assign_intptr);
92695 +
92696 + // apply logical or to temporary unsigned long and bitmask
92697 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
92698 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
92699 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
92700 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
92701 + update_stmt(assign_intptr);
92702 +
92703 + // cast temporary unsigned long back to a temporary fptr variable
92704 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
92705 +#if BUILDING_GCC_VERSION <= 4007
92706 + add_referenced_var(new_fptr);
92707 + mark_sym_for_renaming(new_fptr);
92708 +#endif
92709 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
92710 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
92711 + update_stmt(assign_new_fptr);
92712 +
92713 + // replace call stmt fn with the new fptr
92714 + gimple_call_set_fn(call_stmt, new_fptr);
92715 + update_stmt(call_stmt);
92716 +}
92717 +
92718 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
92719 +{
92720 + gimple asm_or_stmt, call_stmt;
92721 + tree old_fptr, new_fptr, input, output;
92722 +#if BUILDING_GCC_VERSION <= 4007
92723 + VEC(tree, gc) *inputs = NULL;
92724 + VEC(tree, gc) *outputs = NULL;
92725 +#else
92726 + vec<tree, va_gc> *inputs = NULL;
92727 + vec<tree, va_gc> *outputs = NULL;
92728 +#endif
92729 +
92730 + call_stmt = gsi_stmt(*gsi);
92731 + old_fptr = gimple_call_fn(call_stmt);
92732 +
92733 + // create temporary fptr variable
92734 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
92735 +#if BUILDING_GCC_VERSION <= 4007
92736 + add_referenced_var(new_fptr);
92737 + mark_sym_for_renaming(new_fptr);
92738 +#endif
92739 +
92740 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
92741 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
92742 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
92743 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
92744 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
92745 +#if BUILDING_GCC_VERSION <= 4007
92746 + VEC_safe_push(tree, gc, inputs, input);
92747 + VEC_safe_push(tree, gc, outputs, output);
92748 +#else
92749 + vec_safe_push(inputs, input);
92750 + vec_safe_push(outputs, output);
92751 +#endif
92752 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
92753 + gimple_asm_set_volatile(asm_or_stmt, true);
92754 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
92755 + update_stmt(asm_or_stmt);
92756 +
92757 + // replace call stmt fn with the new fptr
92758 + gimple_call_set_fn(call_stmt, new_fptr);
92759 + update_stmt(call_stmt);
92760 +}
92761 +
92762 +/*
92763 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
92764 + */
92765 +static unsigned int execute_kernexec_fptr(void)
92766 +{
92767 + basic_block bb;
92768 +
92769 + // 1. loop through BBs and GIMPLE statements
92770 + FOR_EACH_BB(bb) {
92771 + gimple_stmt_iterator gsi;
92772 +
92773 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
92774 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
92775 + tree fn;
92776 + gimple call_stmt;
92777 +
92778 + // is it a call ...
92779 + call_stmt = gsi_stmt(gsi);
92780 + if (!is_gimple_call(call_stmt))
92781 + continue;
92782 + fn = gimple_call_fn(call_stmt);
92783 + if (TREE_CODE(fn) == ADDR_EXPR)
92784 + continue;
92785 + if (TREE_CODE(fn) != SSA_NAME)
92786 + gcc_unreachable();
92787 +
92788 + // ... through a function pointer
92789 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
92790 + fn = SSA_NAME_VAR(fn);
92791 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
92792 + debug_tree(fn);
92793 + gcc_unreachable();
92794 + }
92795 + }
92796 + fn = TREE_TYPE(fn);
92797 + if (TREE_CODE(fn) != POINTER_TYPE)
92798 + continue;
92799 + fn = TREE_TYPE(fn);
92800 + if (TREE_CODE(fn) != FUNCTION_TYPE)
92801 + continue;
92802 +
92803 + kernexec_instrument_fptr(&gsi);
92804 +
92805 +//debug_tree(gimple_call_fn(call_stmt));
92806 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
92807 + }
92808 + }
92809 +
92810 + return 0;
92811 +}
92812 +
92813 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
92814 +static void kernexec_instrument_retaddr_bts(rtx insn)
92815 +{
92816 + rtx btsq;
92817 + rtvec argvec, constraintvec, labelvec;
92818 + int line;
92819 +
92820 + // create asm volatile("btsq $63,(%%rsp)":::)
92821 + argvec = rtvec_alloc(0);
92822 + constraintvec = rtvec_alloc(0);
92823 + labelvec = rtvec_alloc(0);
92824 + line = expand_location(RTL_LOCATION(insn)).line;
92825 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
92826 + MEM_VOLATILE_P(btsq) = 1;
92827 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
92828 + emit_insn_before(btsq, insn);
92829 +}
92830 +
92831 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
92832 +static void kernexec_instrument_retaddr_or(rtx insn)
92833 +{
92834 + rtx orq;
92835 + rtvec argvec, constraintvec, labelvec;
92836 + int line;
92837 +
92838 + // create asm volatile("orq %%r10,(%%rsp)":::)
92839 + argvec = rtvec_alloc(0);
92840 + constraintvec = rtvec_alloc(0);
92841 + labelvec = rtvec_alloc(0);
92842 + line = expand_location(RTL_LOCATION(insn)).line;
92843 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
92844 + MEM_VOLATILE_P(orq) = 1;
92845 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
92846 + emit_insn_before(orq, insn);
92847 +}
92848 +
92849 +/*
92850 + * find all asm level function returns and forcibly set the highest bit of the return address
92851 + */
92852 +static unsigned int execute_kernexec_retaddr(void)
92853 +{
92854 + rtx insn;
92855 +
92856 + // 1. find function returns
92857 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
92858 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
92859 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
92860 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
92861 + rtx body;
92862 +
92863 + // is it a retn
92864 + if (!JUMP_P(insn))
92865 + continue;
92866 + body = PATTERN(insn);
92867 + if (GET_CODE(body) == PARALLEL)
92868 + body = XVECEXP(body, 0, 0);
92869 + if (!ANY_RETURN_P(body))
92870 + continue;
92871 + kernexec_instrument_retaddr(insn);
92872 + }
92873 +
92874 +// print_simple_rtl(stderr, get_insns());
92875 +// print_rtl(stderr, get_insns());
92876 +
92877 + return 0;
92878 +}
92879 +
92880 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
92881 +{
92882 + const char * const plugin_name = plugin_info->base_name;
92883 + const int argc = plugin_info->argc;
92884 + const struct plugin_argument * const argv = plugin_info->argv;
92885 + int i;
92886 + struct register_pass_info kernexec_reload_pass_info = {
92887 + .pass = &kernexec_reload_pass.pass,
92888 + .reference_pass_name = "ssa",
92889 + .ref_pass_instance_number = 1,
92890 + .pos_op = PASS_POS_INSERT_AFTER
92891 + };
92892 + struct register_pass_info kernexec_fptr_pass_info = {
92893 + .pass = &kernexec_fptr_pass.pass,
92894 + .reference_pass_name = "ssa",
92895 + .ref_pass_instance_number = 1,
92896 + .pos_op = PASS_POS_INSERT_AFTER
92897 + };
92898 + struct register_pass_info kernexec_retaddr_pass_info = {
92899 + .pass = &kernexec_retaddr_pass.pass,
92900 + .reference_pass_name = "pro_and_epilogue",
92901 + .ref_pass_instance_number = 1,
92902 + .pos_op = PASS_POS_INSERT_AFTER
92903 + };
92904 +
92905 + if (!plugin_default_version_check(version, &gcc_version)) {
92906 + error(G_("incompatible gcc/plugin versions"));
92907 + return 1;
92908 + }
92909 +
92910 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
92911 +
92912 + if (TARGET_64BIT == 0)
92913 + return 0;
92914 +
92915 + for (i = 0; i < argc; ++i) {
92916 + if (!strcmp(argv[i].key, "method")) {
92917 + if (!argv[i].value) {
92918 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92919 + continue;
92920 + }
92921 + if (!strcmp(argv[i].value, "bts")) {
92922 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
92923 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
92924 + } else if (!strcmp(argv[i].value, "or")) {
92925 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
92926 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
92927 + fix_register("r10", 1, 1);
92928 + } else
92929 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
92930 + continue;
92931 + }
92932 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
92933 + }
92934 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
92935 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
92936 +
92937 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
92938 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
92939 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
92940 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
92941 +
92942 + return 0;
92943 +}
92944 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
92945 new file mode 100644
92946 index 0000000..b5395ba
92947 --- /dev/null
92948 +++ b/tools/gcc/latent_entropy_plugin.c
92949 @@ -0,0 +1,327 @@
92950 +/*
92951 + * Copyright 2012-2013 by the PaX Team <pageexec@freemail.hu>
92952 + * Licensed under the GPL v2
92953 + *
92954 + * Note: the choice of the license means that the compilation process is
92955 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
92956 + * but for the kernel it doesn't matter since it doesn't link against
92957 + * any of the gcc libraries
92958 + *
92959 + * gcc plugin to help generate a little bit of entropy from program state,
92960 + * used during boot in the kernel
92961 + *
92962 + * TODO:
92963 + * - add ipa pass to identify not explicitly marked candidate functions
92964 + * - mix in more program state (function arguments/return values, loop variables, etc)
92965 + * - more instrumentation control via attribute parameters
92966 + *
92967 + * BUGS:
92968 + * - LTO needs -flto-partition=none for now
92969 + */
92970 +#include "gcc-plugin.h"
92971 +#include "config.h"
92972 +#include "system.h"
92973 +#include "coretypes.h"
92974 +#include "tree.h"
92975 +#include "tree-pass.h"
92976 +#include "flags.h"
92977 +#include "intl.h"
92978 +#include "toplev.h"
92979 +#include "plugin.h"
92980 +//#include "expr.h" where are you...
92981 +#include "diagnostic.h"
92982 +#include "plugin-version.h"
92983 +#include "tm.h"
92984 +#include "function.h"
92985 +#include "basic-block.h"
92986 +#include "gimple.h"
92987 +#include "rtl.h"
92988 +#include "emit-rtl.h"
92989 +#include "tree-flow.h"
92990 +#include "langhooks.h"
92991 +
92992 +#if BUILDING_GCC_VERSION >= 4008
92993 +#define TODO_dump_func 0
92994 +#endif
92995 +
92996 +int plugin_is_GPL_compatible;
92997 +
92998 +static tree latent_entropy_decl;
92999 +
93000 +static struct plugin_info latent_entropy_plugin_info = {
93001 + .version = "201303102320",
93002 + .help = NULL
93003 +};
93004 +
93005 +static unsigned int execute_latent_entropy(void);
93006 +static bool gate_latent_entropy(void);
93007 +
93008 +static struct gimple_opt_pass latent_entropy_pass = {
93009 + .pass = {
93010 + .type = GIMPLE_PASS,
93011 + .name = "latent_entropy",
93012 +#if BUILDING_GCC_VERSION >= 4008
93013 + .optinfo_flags = OPTGROUP_NONE,
93014 +#endif
93015 + .gate = gate_latent_entropy,
93016 + .execute = execute_latent_entropy,
93017 + .sub = NULL,
93018 + .next = NULL,
93019 + .static_pass_number = 0,
93020 + .tv_id = TV_NONE,
93021 + .properties_required = PROP_gimple_leh | PROP_cfg,
93022 + .properties_provided = 0,
93023 + .properties_destroyed = 0,
93024 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
93025 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
93026 + }
93027 +};
93028 +
93029 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
93030 +{
93031 + if (TREE_CODE(*node) != FUNCTION_DECL) {
93032 + *no_add_attrs = true;
93033 + error("%qE attribute only applies to functions", name);
93034 + }
93035 + return NULL_TREE;
93036 +}
93037 +
93038 +static struct attribute_spec latent_entropy_attr = {
93039 + .name = "latent_entropy",
93040 + .min_length = 0,
93041 + .max_length = 0,
93042 + .decl_required = true,
93043 + .type_required = false,
93044 + .function_type_required = false,
93045 + .handler = handle_latent_entropy_attribute,
93046 +#if BUILDING_GCC_VERSION >= 4007
93047 + .affects_type_identity = false
93048 +#endif
93049 +};
93050 +
93051 +static void register_attributes(void *event_data, void *data)
93052 +{
93053 + register_attribute(&latent_entropy_attr);
93054 +}
93055 +
93056 +static bool gate_latent_entropy(void)
93057 +{
93058 + tree latent_entropy_attr;
93059 +
93060 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
93061 + return latent_entropy_attr != NULL_TREE;
93062 +}
93063 +
93064 +static unsigned HOST_WIDE_INT seed;
93065 +static unsigned HOST_WIDE_INT get_random_const(void)
93066 +{
93067 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
93068 + return seed;
93069 +}
93070 +
93071 +static enum tree_code get_op(tree *rhs)
93072 +{
93073 + static enum tree_code op;
93074 + unsigned HOST_WIDE_INT random_const;
93075 +
93076 + random_const = get_random_const();
93077 +
93078 + switch (op) {
93079 + case BIT_XOR_EXPR:
93080 + op = PLUS_EXPR;
93081 + break;
93082 +
93083 + case PLUS_EXPR:
93084 + if (rhs) {
93085 + op = LROTATE_EXPR;
93086 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
93087 + break;
93088 + }
93089 +
93090 + case LROTATE_EXPR:
93091 + default:
93092 + op = BIT_XOR_EXPR;
93093 + break;
93094 + }
93095 + if (rhs)
93096 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
93097 + return op;
93098 +}
93099 +
93100 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
93101 +{
93102 + gimple_stmt_iterator gsi;
93103 + gimple assign;
93104 + tree addxorrol, rhs;
93105 + enum tree_code op;
93106 +
93107 + op = get_op(&rhs);
93108 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
93109 + assign = gimple_build_assign(local_entropy, addxorrol);
93110 +#if BUILDING_GCC_VERSION <= 4007
93111 + find_referenced_vars_in(assign);
93112 +#endif
93113 +//debug_bb(bb);
93114 + gsi = gsi_after_labels(bb);
93115 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
93116 + update_stmt(assign);
93117 +}
93118 +
93119 +static void perturb_latent_entropy(basic_block bb, tree rhs)
93120 +{
93121 + gimple_stmt_iterator gsi;
93122 + gimple assign;
93123 + tree addxorrol, temp;
93124 +
93125 + // 1. create temporary copy of latent_entropy
93126 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
93127 +#if BUILDING_GCC_VERSION <= 4007
93128 + add_referenced_var(temp);
93129 + mark_sym_for_renaming(temp);
93130 +#endif
93131 +
93132 + // 2. read...
93133 + assign = gimple_build_assign(temp, latent_entropy_decl);
93134 +#if BUILDING_GCC_VERSION <= 4007
93135 + find_referenced_vars_in(assign);
93136 +#endif
93137 + gsi = gsi_after_labels(bb);
93138 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93139 + update_stmt(assign);
93140 +
93141 + // 3. ...modify...
93142 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
93143 + assign = gimple_build_assign(temp, addxorrol);
93144 +#if BUILDING_GCC_VERSION <= 4007
93145 + find_referenced_vars_in(assign);
93146 +#endif
93147 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93148 + update_stmt(assign);
93149 +
93150 + // 4. ...write latent_entropy
93151 + assign = gimple_build_assign(latent_entropy_decl, temp);
93152 +#if BUILDING_GCC_VERSION <= 4007
93153 + find_referenced_vars_in(assign);
93154 +#endif
93155 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93156 + update_stmt(assign);
93157 +}
93158 +
93159 +static unsigned int execute_latent_entropy(void)
93160 +{
93161 + basic_block bb;
93162 + gimple assign;
93163 + gimple_stmt_iterator gsi;
93164 + tree local_entropy;
93165 +
93166 + if (!latent_entropy_decl) {
93167 + struct varpool_node *node;
93168 +
93169 +#if BUILDING_GCC_VERSION <= 4007
93170 + for (node = varpool_nodes; node; node = node->next) {
93171 + tree var = node->decl;
93172 +#else
93173 + FOR_EACH_VARIABLE(node) {
93174 + tree var = node->symbol.decl;
93175 +#endif
93176 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
93177 + continue;
93178 + latent_entropy_decl = var;
93179 +// debug_tree(var);
93180 + break;
93181 + }
93182 + if (!latent_entropy_decl) {
93183 +// debug_tree(current_function_decl);
93184 + return 0;
93185 + }
93186 + }
93187 +
93188 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
93189 +
93190 + // 1. create local entropy variable
93191 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
93192 +#if BUILDING_GCC_VERSION <= 4007
93193 + add_referenced_var(local_entropy);
93194 + mark_sym_for_renaming(local_entropy);
93195 +#endif
93196 +
93197 + // 2. initialize local entropy variable
93198 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
93199 + if (dom_info_available_p(CDI_DOMINATORS))
93200 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
93201 + gsi = gsi_start_bb(bb);
93202 +
93203 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
93204 +// gimple_set_location(assign, loc);
93205 +#if BUILDING_GCC_VERSION <= 4007
93206 + find_referenced_vars_in(assign);
93207 +#endif
93208 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
93209 + update_stmt(assign);
93210 + bb = bb->next_bb;
93211 +
93212 + // 3. instrument each BB with an operation on the local entropy variable
93213 + while (bb != EXIT_BLOCK_PTR) {
93214 + perturb_local_entropy(bb, local_entropy);
93215 + bb = bb->next_bb;
93216 + };
93217 +
93218 + // 4. mix local entropy into the global entropy variable
93219 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
93220 + return 0;
93221 +}
93222 +
93223 +static void start_unit_callback(void *gcc_data, void *user_data)
93224 +{
93225 + tree latent_entropy_type;
93226 +
93227 +#if BUILDING_GCC_VERSION >= 4007
93228 + seed = get_random_seed(false);
93229 +#else
93230 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
93231 + seed *= seed;
93232 +#endif
93233 +
93234 + if (in_lto_p)
93235 + return;
93236 +
93237 + // extern volatile u64 latent_entropy
93238 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
93239 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
93240 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
93241 +
93242 + TREE_STATIC(latent_entropy_decl) = 1;
93243 + TREE_PUBLIC(latent_entropy_decl) = 1;
93244 + TREE_USED(latent_entropy_decl) = 1;
93245 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
93246 + DECL_EXTERNAL(latent_entropy_decl) = 1;
93247 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
93248 + DECL_INITIAL(latent_entropy_decl) = NULL;
93249 + lang_hooks.decls.pushdecl(latent_entropy_decl);
93250 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
93251 +// varpool_finalize_decl(latent_entropy_decl);
93252 +// varpool_mark_needed_node(latent_entropy_decl);
93253 +}
93254 +
93255 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
93256 +{
93257 + const char * const plugin_name = plugin_info->base_name;
93258 + struct register_pass_info latent_entropy_pass_info = {
93259 + .pass = &latent_entropy_pass.pass,
93260 + .reference_pass_name = "optimized",
93261 + .ref_pass_instance_number = 1,
93262 + .pos_op = PASS_POS_INSERT_BEFORE
93263 + };
93264 +
93265 + if (!plugin_default_version_check(version, &gcc_version)) {
93266 + error(G_("incompatible gcc/plugin versions"));
93267 + return 1;
93268 + }
93269 +
93270 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
93271 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
93272 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
93273 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
93274 +
93275 + return 0;
93276 +}
93277 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
93278 new file mode 100644
93279 index 0000000..5921fd7
93280 --- /dev/null
93281 +++ b/tools/gcc/size_overflow_hash.data
93282 @@ -0,0 +1,3713 @@
93283 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
93284 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
93285 +batadv_orig_node_del_if_4 batadv_orig_node_del_if 2 4 NULL
93286 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
93287 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
93288 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
93289 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
93290 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
93291 +diva_os_malloc_16406 diva_os_malloc 2 16406 NULL
93292 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
93293 +xfs_dir2_leaf_getdents_23841 xfs_dir2_leaf_getdents 3 23841 NULL
93294 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
93295 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
93296 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
93297 +create_log_8225 create_log 2 8225 NULL
93298 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
93299 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
93300 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
93301 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
93302 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
93303 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
93304 +padzero_55 padzero 1 55 &sel_read_policyvers_55
93305 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
93306 +alloc_wr_24635 alloc_wr 1-2 24635 NULL
93307 +read_file_blob_57406 read_file_blob 3 57406 NULL
93308 +add_rx_skb_8257 add_rx_skb 3 8257 NULL
93309 +enclosure_register_57412 enclosure_register 3 57412 NULL
93310 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
93311 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
93312 +gre_manip_pkt_57416 gre_manip_pkt 4 57416 NULL
93313 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
93314 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
93315 +DepcaSignature_80 DepcaSignature 2 80 NULL nohasharray
93316 +crypto_authenc_setkey_80 crypto_authenc_setkey 3 80 &DepcaSignature_80
93317 +init_cdev_8274 init_cdev 1 8274 NULL
93318 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
93319 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL nohasharray
93320 +alloc_ftrace_hash_57431 alloc_ftrace_hash 1 57431 &compat_keyctl_instantiate_key_iov_57431
93321 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
93322 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
93323 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
93324 +load_msg_95 load_msg 2 95 NULL
93325 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
93326 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
93327 +acpi_tb_check_xsdt_21862 acpi_tb_check_xsdt 1 21862 NULL
93328 +sys_pselect6_57449 sys_pselect6 1 57449 NULL
93329 +biovec_create_pools_9575 biovec_create_pools 2 9575 NULL
93330 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
93331 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
93332 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 NULL nohasharray
93333 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 &ath6kl_usb_submit_ctrl_in_32880
93334 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
93335 +send_midi_async_57463 send_midi_async 3 57463 NULL
93336 +sisusb_clear_vram_57466 sisusb_clear_vram 3-2 57466 NULL
93337 +ath6kl_usb_post_recv_transfers_32892 ath6kl_usb_post_recv_transfers 2 32892 NULL
93338 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL nohasharray
93339 +sep_lock_user_pages_57470 sep_lock_user_pages 2-3 57470 &ieee80211_if_read_flags_57470
93340 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
93341 +construct_key_and_link_8321 construct_key_and_link 4 8321 NULL
93342 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
93343 +init_q_132 init_q 4 132 NULL
93344 +roccat_read_41093 roccat_read 3 41093 NULL nohasharray
93345 +nvme_map_user_pages_41093 nvme_map_user_pages 3-4 41093 &roccat_read_41093
93346 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
93347 +unifi_net_data_malloc_24716 unifi_net_data_malloc 3 24716 NULL
93348 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
93349 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
93350 +uio_read_49300 uio_read 3 49300 NULL
93351 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
93352 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 NULL
93353 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
93354 +firmwareUpload_32794 firmwareUpload 3 32794 NULL
93355 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
93356 +play_iframe_8219 play_iframe 3 8219 NULL
93357 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
93358 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
93359 +ath_rxbuf_alloc_24745 ath_rxbuf_alloc 2 24745 NULL
93360 +nvme_create_queue_170 nvme_create_queue 3 170 NULL
93361 +init_tag_map_57515 init_tag_map 3 57515 NULL
93362 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL
93363 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-3-4 49330 NULL
93364 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
93365 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
93366 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
93367 +DoC_Probe_57534 DoC_Probe 1 57534 NULL
93368 +cfpkt_setlen_49343 cfpkt_setlen 2 49343 NULL
93369 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
93370 +mI_alloc_skb_24770 mI_alloc_skb 1 24770 NULL
93371 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
93372 +virtblk_add_req_197 virtblk_add_req 2-3 197 NULL
93373 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
93374 +rds_tcp_data_recv_53476 rds_tcp_data_recv 3 53476 NULL
93375 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
93376 +skb_make_writable_24783 skb_make_writable 2 24783 NULL
93377 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
93378 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
93379 +cache_read_24790 cache_read 3 24790 NULL
93380 +px_raw_event_49371 px_raw_event 4 49371 NULL
93381 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
93382 +compat_filldir_32999 compat_filldir 3 32999 NULL
93383 +hci_si_event_1404 hci_si_event 3 1404 NULL
93384 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
93385 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
93386 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
93387 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
93388 +applesmc_create_nodes_49392 applesmc_create_nodes 2 49392 NULL
93389 +snd_usb_ctl_msg_8436 snd_usb_ctl_msg 8 8436 NULL
93390 +comedi_buf_alloc_24822 comedi_buf_alloc 3 24822 NULL
93391 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
93392 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
93393 +tun_alloc_skb_41216 tun_alloc_skb 2-4-3 41216 NULL
93394 +proc_scsi_write_proc_267 proc_scsi_write_proc 3 267 NULL
93395 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
93396 +sk_stream_alloc_skb_57622 sk_stream_alloc_skb 2 57622 NULL
93397 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
93398 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
93399 +mfd_add_devices_16668 mfd_add_devices 4 16668 NULL
93400 +packet_recv_error_16669 packet_recv_error 3 16669 NULL
93401 +osdmap_set_max_osd_57630 osdmap_set_max_osd 2 57630 NULL nohasharray
93402 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 &osdmap_set_max_osd_57630
93403 +mem_read_57631 mem_read 3 57631 NULL
93404 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
93405 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
93406 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
93407 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
93408 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
93409 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
93410 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
93411 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
93412 +queues_read_24877 queues_read 3 24877 NULL
93413 +__fprog_create_41263 __fprog_create 2 41263 NULL
93414 +syslog_print_307 syslog_print 2 307 NULL
93415 +platform_device_add_data_310 platform_device_add_data 3 310 NULL
93416 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
93417 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
93418 +sys_mq_timedsend_57661 sys_mq_timedsend 3 57661 NULL
93419 +r3964_write_57662 r3964_write 4 57662 NULL
93420 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
93421 +savu_sysfs_read_49473 savu_sysfs_read 6 49473 NULL
93422 +dn_nsp_do_disc_49474 dn_nsp_do_disc 6-2 49474 NULL
93423 +alloc_context_41283 alloc_context 1 41283 NULL
93424 +__lgwrite_57669 __lgwrite 4 57669 NULL
93425 +ath9k_wmi_cmd_327 ath9k_wmi_cmd 4 327 NULL
93426 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
93427 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
93428 +alloc_pg_vec_8533 alloc_pg_vec 2 8533 NULL
93429 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
93430 +ieee80211_fragment_33112 ieee80211_fragment 4 33112 NULL
93431 +arch_gnttab_map_shared_41306 arch_gnttab_map_shared 3 41306 NULL
93432 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL
93433 +write_node_33121 write_node 4 33121 NULL
93434 +vring_new_virtqueue_54673 vring_new_virtqueue 2 54673 NULL
93435 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
93436 +profile_remove_8556 profile_remove 3 8556 NULL
93437 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
93438 +iscsi_recv_pdu_16755 iscsi_recv_pdu 4 16755 NULL
93439 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
93440 +cmtp_send_interopmsg_376 cmtp_send_interopmsg 7 376 NULL
93441 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
93442 +mga_ioremap_8571 mga_ioremap 1-2 8571 NULL
93443 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
93444 +sys_rt_sigpending_24961 sys_rt_sigpending 2 24961 NULL
93445 +tower_write_8580 tower_write 3 8580 NULL
93446 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
93447 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 NULL nohasharray
93448 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 &compat_sys_set_mempolicy_57742
93449 +jbd2_alloc_41359 jbd2_alloc 1 41359 NULL
93450 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
93451 +nf_nat_sdp_port_24977 nf_nat_sdp_port 7 24977 NULL
93452 +smk_write_access_49561 smk_write_access 3 49561 NULL
93453 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
93454 +kmp_init_41373 kmp_init 2 41373 NULL
93455 +context_alloc_24645 context_alloc 3 24645 NULL
93456 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
93457 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
93458 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
93459 +tipc_send2name_16809 tipc_send2name 6 16809 NULL
93460 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
93461 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
93462 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
93463 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
93464 +dm_vcalloc_16814 dm_vcalloc 1-2 16814 NULL
93465 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
93466 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
93467 +pp_read_33210 pp_read 3 33210 NULL
93468 +sys_flistxattr_41407 sys_flistxattr 3 41407 NULL
93469 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
93470 +ivtv_read_57796 ivtv_read 3 57796 NULL
93471 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
93472 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
93473 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
93474 +heap_init_49617 heap_init 2 49617 NULL
93475 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
93476 +ieee80211_send_probe_req_38307 ieee80211_send_probe_req 6-4 38307 NULL
93477 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
93478 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
93479 +_alloc_get_attr_desc_470 _alloc_get_attr_desc 2 470 NULL
93480 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
93481 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
93482 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
93483 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 4-6 41442 NULL
93484 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
93485 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
93486 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
93487 +st_write_16874 st_write 3 16874 NULL
93488 +copy_to_user_57835 copy_to_user 3 57835 NULL
93489 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
93490 +pidlist_resize_496 pidlist_resize 2 496 NULL
93491 +flash_read_57843 flash_read 3 57843 NULL
93492 +read_vbt_r0_503 read_vbt_r0 1 503 NULL
93493 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
93494 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
93495 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
93496 +arcfb_write_8702 arcfb_write 3 8702 NULL
93497 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
93498 +smp_send_cmd_512 smp_send_cmd 3 512 NULL
93499 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
93500 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
93501 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
93502 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
93503 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
93504 +cxio_hal_init_rhdl_resource_25104 cxio_hal_init_rhdl_resource 1 25104 NULL
93505 +sock_wmalloc_16472 sock_wmalloc 2 16472 NULL
93506 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
93507 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 3-4 49683 NULL
93508 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
93509 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
93510 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
93511 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 NULL nohasharray
93512 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 &psb_unlocked_ioctl_16926
93513 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
93514 +sys_gethostname_49698 sys_gethostname 2 49698 NULL
93515 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
93516 +ieee80211_rx_mgmt_probe_resp_6918 ieee80211_rx_mgmt_probe_resp 3 6918 NULL
93517 +devres_alloc_551 devres_alloc 2 551 NULL
93518 +ldisc_receive_41516 ldisc_receive 4 41516 NULL
93519 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
93520 +ip_append_data_16942 ip_append_data 5-6 16942 NULL
93521 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
93522 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
93523 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
93524 +emi26_writememory_57908 emi26_writememory 4 57908 NULL
93525 +start_isoc_chain_565 start_isoc_chain 2 565 NULL
93526 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
93527 +gsm_mux_rx_netchar_33336 gsm_mux_rx_netchar 3 33336 NULL
93528 +brcmu_pkt_buf_get_skb_5556 brcmu_pkt_buf_get_skb 1 5556 NULL
93529 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
93530 +sys_prctl_8766 sys_prctl 4 8766 NULL
93531 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
93532 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
93533 +compat_sys_preadv_583 compat_sys_preadv 3 583 NULL
93534 +sys_fsetxattr_49736 sys_fsetxattr 4 49736 NULL
93535 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
93536 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
93537 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
93538 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
93539 +sys_fgetxattr_25166 sys_fgetxattr 4 25166 NULL
93540 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
93541 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
93542 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
93543 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
93544 +ath6kl_buf_alloc_57304 ath6kl_buf_alloc 1 57304 NULL
93545 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
93546 +gserial_setup_41558 gserial_setup 2 41558 NULL
93547 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
93548 +rx_57944 rx 4 57944 NULL
93549 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
93550 +nci_skb_alloc_49757 nci_skb_alloc 2 49757 NULL
93551 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
93552 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
93553 +sctp_ulpevent_new_33377 sctp_ulpevent_new 1 33377 NULL
93554 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
93555 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
93556 +isku_sysfs_write_49767 isku_sysfs_write 6 49767 NULL
93557 +i915_cache_sharing_write_57961 i915_cache_sharing_write 3 57961 NULL
93558 +batadv_receive_client_update_packet_41578 batadv_receive_client_update_packet 3 41578 NULL
93559 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
93560 +handle_response_icmp_39574 handle_response_icmp 7 39574 NULL
93561 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
93562 +hfc_empty_fifo_57972 hfc_empty_fifo 2 57972 NULL
93563 +ceph_dns_resolve_name_62488 ceph_dns_resolve_name 2 62488 NULL
93564 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
93565 +icmpv6_manip_pkt_8833 icmpv6_manip_pkt 4 8833 NULL
93566 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
93567 +read_file_rx_chainmask_41605 read_file_rx_chainmask 3 41605 NULL
93568 +vmw_du_crtc_cursor_set_28479 vmw_du_crtc_cursor_set 4-5 28479 NULL
93569 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
93570 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
93571 +a2mp_send_41615 a2mp_send 4 41615 NULL
93572 +ceph_copy_user_to_page_vector_656 ceph_copy_user_to_page_vector 4-3 656 NULL
93573 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
93574 +arch_gnttab_map_status_49812 arch_gnttab_map_status 3 49812 NULL
93575 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
93576 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
93577 +tcf_csum_ipv6_udp_25241 tcf_csum_ipv6_udp 4 25241 NULL
93578 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
93579 +macvtap_alloc_skb_50629 macvtap_alloc_skb 2-4-3 50629 NULL
93580 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
93581 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6 49829 NULL
93582 +add_uuid_49831 add_uuid 4 49831 NULL
93583 +send_pages_8872 send_pages 3 8872 NULL
93584 +ath6kl_fwlog_block_read_49836 ath6kl_fwlog_block_read 3 49836 NULL
93585 +__btrfs_map_block_49839 __btrfs_map_block 3 49839 NULL
93586 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
93587 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
93588 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
93589 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
93590 +__kmalloc_reserve_17080 __kmalloc_reserve 1 17080 NULL
93591 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
93592 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
93593 +vfs_writev_25278 vfs_writev 3 25278 NULL
93594 +rtl8169_try_rx_copy_705 rtl8169_try_rx_copy 3 705 NULL
93595 +alloc_async_14208 alloc_async 1 14208 NULL
93596 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
93597 +persistent_ram_vmap_709 persistent_ram_vmap 2-1 709 NULL
93598 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
93599 +create_entry_33479 create_entry 2 33479 NULL
93600 +mce_async_out_58056 mce_async_out 3 58056 NULL
93601 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
93602 +sys_preadv_17100 sys_preadv 3 17100 NULL
93603 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
93604 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL
93605 +netxen_nic_hw_write_wx_128M_33488 netxen_nic_hw_write_wx_128M 2 33488 NULL
93606 +aac_src_ioremap_41688 aac_src_ioremap 2 41688 NULL
93607 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
93608 +res_counter_read_33499 res_counter_read 4 33499 NULL
93609 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
93610 +cm4040_write_58079 cm4040_write 3 58079 NULL
93611 +fb_read_33506 fb_read 3 33506 NULL
93612 +help_25316 help 5 25316 NULL nohasharray
93613 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 &help_25316
93614 +rfcomm_wmalloc_58090 rfcomm_wmalloc 2 58090 NULL
93615 +mwifiex_get_common_rates_17131 mwifiex_get_common_rates 3 17131 NULL
93616 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
93617 +ddp_set_map_751 ddp_set_map 4 751 NULL
93618 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
93619 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
93620 +dvb_video_write_754 dvb_video_write 3 754 NULL
93621 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
93622 +osd_req_add_get_attr_list_49278 osd_req_add_get_attr_list 3 49278 NULL
93623 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
93624 +bdx_tx_db_init_41719 bdx_tx_db_init 2 41719 NULL
93625 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
93626 +udi_log_event_58105 udi_log_event 3 58105 NULL
93627 +sys_pwritev_41722 sys_pwritev 3 41722 NULL
93628 +l2cap_sock_alloc_skb_cb_33532 l2cap_sock_alloc_skb_cb 2 33532 NULL
93629 +ib_send_cm_mra_60202 ib_send_cm_mra 4 60202 NULL nohasharray
93630 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 &ib_send_cm_mra_60202
93631 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
93632 +__copy_from_user_inatomic_nocache_49921 __copy_from_user_inatomic_nocache 3 49921 NULL
93633 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL
93634 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
93635 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
93636 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
93637 +vol_cdev_read_8968 vol_cdev_read 3 8968 NULL nohasharray
93638 +seq_open_net_8968 seq_open_net 4 8968 &vol_cdev_read_8968
93639 +sep_read_17161 sep_read 3 17161 NULL
93640 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
93641 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
93642 +dup_array_33551 dup_array 3 33551 NULL
93643 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
93644 +solo_enc_read_33553 solo_enc_read 3 33553 NULL
93645 +fillonedir_41746 fillonedir 3 41746 NULL
93646 +init_bch_64130 init_bch 1-2 64130 NULL
93647 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
93648 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
93649 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
93650 +btrfs_alloc_free_block_8986 btrfs_alloc_free_block 3 8986 NULL
93651 +savemem_58129 savemem 3 58129 NULL
93652 +batadv_tt_realloc_packet_buff_49960 batadv_tt_realloc_packet_buff 4 49960 NULL
93653 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
93654 +driver_state_read_17194 driver_state_read 3 17194 NULL nohasharray
93655 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 &driver_state_read_17194
93656 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL
93657 +if_writecmd_815 if_writecmd 2 815 NULL
93658 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
93659 +read_fifo_826 read_fifo 3 826 NULL
93660 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
93661 +scsi_execute_33596 scsi_execute 5 33596 NULL
93662 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
93663 +ms_rw_17220 ms_rw 3-4 17220 NULL
93664 +read_tree_block_841 read_tree_block 3 841 NULL
93665 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
93666 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
93667 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
93668 +__pskb_copy_9038 __pskb_copy 2 9038 NULL
93669 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
93670 +asix_write_cmd_58192 asix_write_cmd 5 58192 NULL
93671 +um_idi_read_850 um_idi_read 3 850 NULL
93672 +__module_alloc_50004 __module_alloc 1 50004 NULL
93673 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
93674 +ts_read_44687 ts_read 3 44687 NULL
93675 +nci_send_cmd_58206 nci_send_cmd 3 58206 NULL
93676 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
93677 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
93678 +provide_user_output_41105 provide_user_output 3 41105 NULL
93679 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
93680 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
93681 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
93682 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
93683 +alloc_ep_17269 alloc_ep 1 17269 NULL
93684 +ath6kl_wmi_beginscan_cmd_25462 ath6kl_wmi_beginscan_cmd 8 25462 NULL
93685 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 NULL
93686 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
93687 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
93688 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
93689 +alloc_ebda_hpc_50046 alloc_ebda_hpc 1-2 50046 NULL
93690 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
93691 +create_queues_9088 create_queues 2-3 9088 NULL
93692 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
93693 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
93694 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
93695 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
93696 +rbd_alloc_coll_33678 rbd_alloc_coll 1 33678 NULL
93697 +read_file_debug_58256 read_file_debug 3 58256 NULL
93698 +skb_pad_17302 skb_pad 2 17302 NULL
93699 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
93700 +btmrvl_hsstate_read_920 btmrvl_hsstate_read 3 920 NULL
93701 +profile_load_58267 profile_load 3 58267 NULL
93702 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
93703 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4 25502 NULL
93704 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
93705 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
93706 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
93707 +pcpu_get_vm_areas_50085 pcpu_get_vm_areas 3 50085 NULL
93708 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
93709 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
93710 +sys_keyctl_33708 sys_keyctl 4 33708 NULL nohasharray
93711 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 &sys_keyctl_33708
93712 +ata_host_alloc_pinfo_17325 ata_host_alloc_pinfo 3 17325 NULL
93713 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
93714 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
93715 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
93716 +get_packet_41914 get_packet 3 41914 NULL
93717 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
93718 +ceph_get_direct_page_vector_41917 ceph_get_direct_page_vector 2 41917 NULL
93719 +read_file_slot_50111 read_file_slot 3 50111 NULL
93720 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
93721 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
93722 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
93723 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
93724 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
93725 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
93726 +copy_items_50140 copy_items 6 50140 NULL
93727 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
93728 +pcim_iomap_58334 pcim_iomap 3 58334 NULL
93729 +diva_init_dma_map_58336 diva_init_dma_map 3 58336 NULL
93730 +map_addr_56144 map_addr 7 56144 NULL
93731 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
93732 +btmrvl_psstate_read_50683 btmrvl_psstate_read 3 50683 NULL
93733 +hdlcdev_rx_997 hdlcdev_rx 3 997 NULL
93734 +portnames_read_41958 portnames_read 3 41958 NULL
93735 +ubi_self_check_all_ff_41959 ubi_self_check_all_ff 4 41959 NULL
93736 +hashtab_create_33769 hashtab_create 3 33769 NULL
93737 +alloc_group_attrs_9194 alloc_group_attrs 2 9194 NULL nohasharray
93738 +altera_swap_ir_9194 altera_swap_ir 2 9194 &alloc_group_attrs_9194
93739 +vmalloc_to_sg_58354 vmalloc_to_sg 2 58354 NULL
93740 +aac_nark_ioremap_50163 aac_nark_ioremap 2 50163 NULL nohasharray
93741 +kmalloc_node_50163 kmalloc_node 1 50163 &aac_nark_ioremap_50163
93742 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
93743 +odev_update_50169 odev_update 2 50169 NULL
93744 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL
93745 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
93746 +__devres_alloc_25598 __devres_alloc 2 25598 NULL
93747 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
93748 +netpoll_send_udp_58955 netpoll_send_udp 3 58955 NULL
93749 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
93750 +ib_send_cm_drep_50186 ib_send_cm_drep 3 50186 NULL
93751 +do_write_orph_node_64343 do_write_orph_node 2 64343 NULL
93752 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
93753 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
93754 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
93755 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
93756 +lguest_map_42008 lguest_map 1-2 42008 NULL
93757 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
93758 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
93759 +pool_allocate_42012 pool_allocate 3 42012 NULL
93760 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
93761 +sctp_make_init_58401 sctp_make_init 4 58401 NULL
93762 +ieee80211_skb_resize_50211 ieee80211_skb_resize 3 50211 NULL
93763 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
93764 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
93765 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
93766 +udplite_manip_pkt_33832 udplite_manip_pkt 4 33832 NULL
93767 +tcf_csum_ipv4_icmp_9258 tcf_csum_ipv4_icmp 3 9258 NULL
93768 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
93769 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
93770 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
93771 +sparse_early_usemaps_alloc_node_9269 sparse_early_usemaps_alloc_node 4 9269 NULL
93772 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
93773 +iscsi_offload_mesg_58425 iscsi_offload_mesg 5 58425 NULL
93774 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
93775 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
93776 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
93777 +nfs_pgarray_set_1085 nfs_pgarray_set 2 1085 NULL
93778 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
93779 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
93780 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
93781 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
93782 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
93783 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
93784 +__alloc_session_17485 __alloc_session 2-1 17485 NULL
93785 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
93786 +pm860x_bulk_write_43875 pm860x_bulk_write 3 43875 NULL
93787 +afs_extract_data_50261 afs_extract_data 5 50261 NULL
93788 +config_proc_write_33878 config_proc_write 3 33878 NULL
93789 +capabilities_read_58457 capabilities_read 3 58457 NULL
93790 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
93791 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
93792 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
93793 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
93794 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
93795 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
93796 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
93797 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
93798 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
93799 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
93800 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
93801 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
93802 +batadv_bla_is_backbone_gw_58488 batadv_bla_is_backbone_gw 3 58488 NULL
93803 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
93804 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
93805 +sel_write_context_25726 sel_write_context 3 25726 NULL nohasharray
93806 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 &sel_write_context_25726
93807 +sysfs_read_file_42113 sysfs_read_file 3 42113 NULL
93808 +mcs_unwrap_fir_25733 mcs_unwrap_fir 3 25733 NULL
93809 +vme_user_write_15587 vme_user_write 3 15587 NULL
93810 +xlog_do_log_recovery_17550 xlog_do_log_recovery 3 17550 NULL
93811 +__copy_to_user_17551 __copy_to_user 3 17551 NULL
93812 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
93813 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
93814 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
93815 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
93816 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
93817 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
93818 +v9fs_alloc_rdir_buf_42150 v9fs_alloc_rdir_buf 2 42150 NULL
93819 +roccat_common2_send_with_status_50343 roccat_common2_send_with_status 4 50343 NULL
93820 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
93821 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
93822 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
93823 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
93824 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
93825 +read_9397 read 3 9397 NULL
93826 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
93827 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
93828 +printer_write_60276 printer_write 3 60276 NULL
93829 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
93830 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
93831 +rts51x_write_mem_17598 rts51x_write_mem 4 17598 NULL
93832 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
93833 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
93834 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
93835 +osst_execute_17607 osst_execute 7-6 17607 NULL
93836 +nf_nat_sip_expect_9418 nf_nat_sip_expect 8 9418 NULL
93837 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
93838 +ipw_packet_received_skb_1230 ipw_packet_received_skb 2 1230 NULL
93839 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
93840 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
93841 +sys32_rt_sigpending_25814 sys32_rt_sigpending 2 25814 NULL
93842 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
93843 +acpi_battery_write_alarm_1240 acpi_battery_write_alarm 3 1240 NULL
93844 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
93845 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
93846 +xip_file_read_58592 xip_file_read 3 58592 NULL
93847 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
93848 +kmalloc_array_9444 kmalloc_array 1-2 9444 NULL
93849 +__ntfs_malloc_34022 __ntfs_malloc 1 34022 NULL
93850 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
93851 +mcs_unwrap_mir_9455 mcs_unwrap_mir 3 9455 NULL
93852 +ppp_write_34034 ppp_write 3 34034 NULL
93853 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
93854 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
93855 +tty_insert_flip_string_34042 tty_insert_flip_string 3 34042 NULL
93856 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
93857 +batadv_tt_prepare_packet_buff_1280 batadv_tt_prepare_packet_buff 4 1280 NULL
93858 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
93859 +module_alloc_update_bounds_rx_58634 module_alloc_update_bounds_rx 1 58634 NULL nohasharray
93860 +efi_ioremap_58634 efi_ioremap 1-2 58634 &module_alloc_update_bounds_rx_58634
93861 +btmrvl_hsmode_write_42252 btmrvl_hsmode_write 3 42252 NULL
93862 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
93863 +dsp_tone_hw_message_17678 dsp_tone_hw_message 3 17678 NULL
93864 +netxen_nic_map_indirect_address_128M_42257 netxen_nic_map_indirect_address_128M 2 42257 NULL
93865 +ulog_alloc_skb_23427 ulog_alloc_skb 1 23427 NULL
93866 +__alloc_preds_9492 __alloc_preds 2 9492 NULL
93867 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
93868 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
93869 +read_file_ant_diversity_34071 read_file_ant_diversity 3 34071 NULL
93870 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
93871 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
93872 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
93873 +savu_sysfs_write_42273 savu_sysfs_write 6 42273 NULL
93874 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 NULL
93875 +lp_write_9511 lp_write 3 9511 NULL
93876 +__einj_error_trigger_17707 __einj_error_trigger 1 17707 NULL nohasharray
93877 +venus_rename_17707 venus_rename 5-4 17707 &__einj_error_trigger_17707
93878 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
93879 +nfs_readdir_make_qstr_12509 nfs_readdir_make_qstr 3 12509 NULL
93880 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
93881 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
93882 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
93883 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
93884 +read_file_dma_9530 read_file_dma 3 9530 NULL
93885 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
93886 +rcname_read_25919 rcname_read 3 25919 NULL
93887 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
93888 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
93889 +tps6586x_writes_58689 tps6586x_writes 3 58689 NULL
93890 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
93891 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
93892 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
93893 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
93894 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
93895 +key_flags_read_25931 key_flags_read 3 25931 NULL
93896 +audit_log_n_untrustedstring_9548 audit_log_n_untrustedstring 3 9548 NULL
93897 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
93898 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
93899 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
93900 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
93901 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
93902 +fw_node_create_9559 fw_node_create 2 9559 NULL
93903 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
93904 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
93905 +kobj_map_9566 kobj_map 2-3 9566 NULL
93906 +snd_pcm_plug_alloc_42339 snd_pcm_plug_alloc 2 42339 NULL
93907 +acpi_map_58725 acpi_map 1-2 58725 NULL
93908 +brcmf_usb_attach_17766 brcmf_usb_attach 2-3 17766 NULL
93909 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
93910 +fwnet_receive_packet_50537 fwnet_receive_packet 9 50537 NULL
93911 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
93912 +ieee80211_tdls_mgmt_9581 ieee80211_tdls_mgmt 8 9581 NULL
93913 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
93914 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
93915 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
93916 +file_read_actor_1401 file_read_actor 4 1401 NULL
93917 +av7110_ipack_init_46655 av7110_ipack_init 2 46655 NULL
93918 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
93919 +ubifs_leb_change_17789 ubifs_leb_change 4 17789 NULL
93920 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
93921 +do_sync_9604 do_sync 1 9604 NULL
93922 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5 9605 NULL
93923 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
93924 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
93925 +__do_config_autodelink_58763 __do_config_autodelink 3 58763 NULL
93926 +sctp_sf_abort_violation_1420 sctp_sf_abort_violation 7 1420 NULL
93927 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
93928 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
93929 +lpfc_sli_probe_sriov_nr_virtfn_26004 lpfc_sli_probe_sriov_nr_virtfn 2 26004 NULL
93930 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
93931 +fat_readpages_50582 fat_readpages 4 50582 NULL nohasharray
93932 +pep_reply_50582 pep_reply 5 50582 &fat_readpages_50582
93933 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
93934 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
93935 +_snd_pcm_lib_alloc_vmalloc_buffer_17820 _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 NULL
93936 +xfs_readdir_41200 xfs_readdir 3 41200 NULL
93937 +sge_rx_50594 sge_rx 3 50594 NULL
93938 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
93939 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
93940 +skb_padto_50759 skb_padto 2 50759 NULL
93941 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
93942 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
93943 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
93944 +isku_sysfs_read_58806 isku_sysfs_read 6 58806 NULL
93945 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
93946 +uvc_alloc_buffers_9656 uvc_alloc_buffers 2-3 9656 NULL
93947 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
93948 +ep_read_58813 ep_read 3 58813 NULL
93949 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
93950 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
93951 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
93952 +pci_enable_sriov_35745 pci_enable_sriov 2 35745 NULL
93953 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
93954 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
93955 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
93956 +dns_query_9676 dns_query 3 9676 NULL
93957 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
93958 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
93959 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
93960 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL
93961 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
93962 +command_write_58841 command_write 3 58841 NULL
93963 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
93964 +dev_config_8506 dev_config 3 8506 NULL
93965 +compat_sys_pwritev_17886 compat_sys_pwritev 3 17886 NULL
93966 +sys_readv_50664 sys_readv 3 50664 NULL
93967 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
93968 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
93969 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
93970 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
93971 +recover_head_17904 recover_head 3 17904 NULL
93972 +dccp_feat_register_sp_17914 dccp_feat_register_sp 5 17914 NULL
93973 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
93974 +brcmf_sdbrcm_bus_txctl_42492 brcmf_sdbrcm_bus_txctl 3 42492 NULL
93975 +srp_iu_pool_alloc_17920 srp_iu_pool_alloc 2 17920 NULL
93976 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
93977 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
93978 +cs553x_init_one_58886 cs553x_init_one 3 58886 NULL
93979 +ddb_input_read_9743 ddb_input_read 3 9743 NULL
93980 +skb_cow_26138 skb_cow 2 26138 NULL
93981 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
93982 +snd_emux_create_port_42533 snd_emux_create_port 3 42533 NULL
93983 +do_sigpending_9766 do_sigpending 2 9766 NULL
93984 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
93985 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
93986 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
93987 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
93988 +copy_oldmem_page_26164 copy_oldmem_page 3-1 26164 NULL
93989 +i915_ring_stop_read_42549 i915_ring_stop_read 3 42549 NULL nohasharray
93990 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 &i915_ring_stop_read_42549
93991 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 NULL
93992 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
93993 +fc_frame_alloc_1596 fc_frame_alloc 2 1596 NULL
93994 +rngapi_reset_34366 rngapi_reset 3 34366 NULL nohasharray
93995 +p54_alloc_skb_34366 p54_alloc_skb 3 34366 &rngapi_reset_34366
93996 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
93997 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
93998 +solo_v4l2_read_59247 solo_v4l2_read 3 59247 NULL
93999 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
94000 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
94001 +reiserfs_resize_34377 reiserfs_resize 2 34377 NULL
94002 +get_registers_26187 get_registers 3 26187 NULL
94003 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
94004 +ttm_bo_fbdev_io_9805 ttm_bo_fbdev_io 4 9805 NULL
94005 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
94006 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
94007 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
94008 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3 27332 NULL
94009 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
94010 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
94011 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL nohasharray
94012 +pipe_handler_request_50774 pipe_handler_request 5 50774 &tm6000_read_write_usb_50774
94013 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
94014 +mce_write_26201 mce_write 3 26201 NULL
94015 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
94016 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
94017 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
94018 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
94019 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
94020 +__pskb_pull_42602 __pskb_pull 2 42602 NULL
94021 +sctp_make_heartbeat_ack_34411 sctp_make_heartbeat_ack 4 34411 NULL
94022 +tpm_write_50798 tpm_write 3 50798 NULL
94023 +btmrvl_hsmode_read_1647 btmrvl_hsmode_read 3 1647 NULL
94024 +tun_do_read_50800 tun_do_read 4 50800 NULL
94025 +handle_rx_packet_58993 handle_rx_packet 3 58993 NULL
94026 +write_flush_50803 write_flush 3 50803 NULL
94027 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
94028 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
94029 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
94030 +dvb_play_50814 dvb_play 3 50814 NULL
94031 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
94032 +sys_move_pages_42626 sys_move_pages 2 42626 NULL
94033 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
94034 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
94035 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
94036 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
94037 +dma_attach_50831 dma_attach 6-7 50831 NULL
94038 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
94039 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
94040 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
94041 +packet_came_18072 packet_came 3 18072 NULL
94042 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
94043 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
94044 +sctp_make_abort_34459 sctp_make_abort 3 34459 NULL
94045 +_regmap_raw_write_42652 _regmap_raw_write 4 42652 NULL
94046 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
94047 +get_vm_area_18080 get_vm_area 1 18080 NULL
94048 +dvb_dvr_set_buffer_size_9840 dvb_dvr_set_buffer_size 2 9840 NULL
94049 +bm_register_write_9893 bm_register_write 3 9893 NULL nohasharray
94050 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 &bm_register_write_9893
94051 +self_check_write_50856 self_check_write 5 50856 NULL
94052 +line6_dumpreq_init_34473 line6_dumpreq_init 3 34473 NULL
94053 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
94054 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
94055 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
94056 +l2tp_xmit_skb_42672 l2tp_xmit_skb 3 42672 NULL
94057 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
94058 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
94059 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
94060 +sis190_try_rx_copy_57069 sis190_try_rx_copy 3 57069 NULL
94061 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
94062 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
94063 +vb2_read_42703 vb2_read 3 42703 NULL
94064 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
94065 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
94066 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
94067 +snd_pcm_plugin_alloc_12580 snd_pcm_plugin_alloc 2 12580 NULL
94068 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
94069 +read_file_misc_9948 read_file_misc 3 9948 NULL
94070 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
94071 +set_rxd_buffer_pointer_9950 set_rxd_buffer_pointer 8 9950 NULL
94072 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
94073 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
94074 +tracing_stats_read_34537 tracing_stats_read 3 34537 NULL
94075 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
94076 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
94077 +cosa_write_1774 cosa_write 3 1774 NULL
94078 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
94079 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4 34547 NULL
94080 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
94081 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
94082 +bnx2fc_cmd_mgr_alloc_24873 bnx2fc_cmd_mgr_alloc 3-2 24873 NULL
94083 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
94084 +ath6kl_usb_submit_ctrl_out_9978 ath6kl_usb_submit_ctrl_out 6 9978 NULL
94085 +dup_to_netobj_26363 dup_to_netobj 3 26363 NULL
94086 +sock_bindtodevice_50942 sock_bindtodevice 3 50942 NULL
94087 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
94088 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
94089 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
94090 +mld_newpack_50950 mld_newpack 2 50950 NULL
94091 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 NULL
94092 +i915_ring_stop_write_59010 i915_ring_stop_write 3 59010 NULL
94093 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
94094 +cfpkt_create_18197 cfpkt_create 1 18197 NULL
94095 +velocity_rx_copy_34583 velocity_rx_copy 2 34583 NULL
94096 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
94097 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
94098 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4 37428 NULL
94099 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
94100 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
94101 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
94102 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
94103 +handle_request_10024 handle_request 9 10024 NULL
94104 +__tty_alloc_driver_53799 __tty_alloc_driver 1 53799 NULL
94105 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
94106 +timeout_write_50991 timeout_write 3 50991 NULL
94107 +batadv_orig_hash_add_if_10033 batadv_orig_hash_add_if 2 10033 NULL
94108 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
94109 +ip_vs_create_timeout_table_64478 ip_vs_create_timeout_table 2 64478 NULL
94110 +proc_write_51003 proc_write 3 51003 NULL
94111 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
94112 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
94113 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
94114 +set_arg_42824 set_arg 3 42824 NULL
94115 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
94116 +fast_rx_path_59214 fast_rx_path 3 59214 NULL
94117 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
94118 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
94119 +audit_log_n_string_31705 audit_log_n_string 3 31705 NULL
94120 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
94121 +pstore_mkfile_50830 pstore_mkfile 5 50830 NULL
94122 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
94123 +hidp_queue_report_1881 hidp_queue_report 3 1881 NULL
94124 +dt3155_read_59226 dt3155_read 3 59226 NULL
94125 +xfs_buf_read_uncached_42844 xfs_buf_read_uncached 3 42844 NULL
94126 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
94127 +dump_midi_51040 dump_midi 3 51040 NULL
94128 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
94129 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
94130 +nf_nat_mangle_udp_packet_34661 nf_nat_mangle_udp_packet 8-6 34661 NULL
94131 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
94132 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
94133 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 NULL
94134 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
94135 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
94136 +em28xx_v4l2_read_16701 em28xx_v4l2_read 3 16701 NULL
94137 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
94138 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
94139 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
94140 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
94141 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 NULL
94142 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
94143 +pskb_expand_head_42881 pskb_expand_head 2-3 42881 NULL
94144 +ip6ip6_err_18308 ip6ip6_err 5 18308 NULL
94145 +read_vmcore_26501 read_vmcore 3 26501 NULL
94146 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
94147 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
94148 +tipc_port_recv_sections_42890 tipc_port_recv_sections 4 42890 NULL
94149 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 3-4 26507 NULL
94150 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
94151 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
94152 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
94153 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
94154 +SendTxCommandPacket_42901 SendTxCommandPacket 3 42901 NULL
94155 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
94156 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
94157 +ath6kl_wmi_send_probe_response_cmd_31728 ath6kl_wmi_send_probe_response_cmd 6 31728 NULL
94158 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
94159 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
94160 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
94161 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
94162 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
94163 +rds_message_inc_copy_to_user_26540 rds_message_inc_copy_to_user 3 26540 NULL
94164 +iscsi_nop_out_rsp_51117 iscsi_nop_out_rsp 4 51117 NULL
94165 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
94166 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
94167 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
94168 +sctp_make_datafrag_empty_34737 sctp_make_datafrag_empty 3 34737 NULL
94169 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
94170 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
94171 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
94172 +fd_copyout_59323 fd_copyout 3 59323 NULL
94173 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
94174 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
94175 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
94176 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
94177 +diva_alloc_dma_map_23798 diva_alloc_dma_map 2 23798 NULL
94178 +solos_param_store_34755 solos_param_store 4 34755 NULL
94179 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
94180 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
94181 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
94182 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
94183 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
94184 +ib_send_cm_rtu_63138 ib_send_cm_rtu 3 63138 NULL
94185 +compat_sys_pwritev64_51151 compat_sys_pwritev64 3 51151 NULL
94186 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL nohasharray
94187 +batadv_receive_server_sync_packet_26577 batadv_receive_server_sync_packet 3 26577 &rts51x_read_mem_26577
94188 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
94189 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
94190 +batadv_tt_commit_changes_2008 batadv_tt_commit_changes 4 2008 NULL
94191 +sep_prepare_input_dma_table_2009 sep_prepare_input_dma_table 2-3 2009 NULL
94192 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
94193 +ubifs_write_node_11258 ubifs_write_node 5-3 11258 NULL
94194 +reada_tree_block_flagged_18402 reada_tree_block_flagged 3 18402 NULL
94195 +iscsi_if_send_reply_52219 iscsi_if_send_reply 7 52219 NULL
94196 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
94197 +__copy_in_user_34790 __copy_in_user 3 34790 NULL
94198 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
94199 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL
94200 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
94201 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
94202 +devm_ioremap_nocache_2036 devm_ioremap_nocache 2-3 2036 NULL
94203 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
94204 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
94205 +batadv_orig_node_add_if_18433 batadv_orig_node_add_if 2 18433 NULL
94206 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
94207 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
94208 +nfc_alloc_recv_skb_10244 nfc_alloc_recv_skb 1 10244 NULL
94209 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
94210 +mangle_sdp_packet_30381 mangle_sdp_packet 10 30381 NULL
94211 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
94212 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
94213 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
94214 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
94215 +subbuf_read_actor_2071 subbuf_read_actor 3 2071 NULL
94216 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
94217 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL
94218 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
94219 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
94220 +receive_DataRequest_9904 receive_DataRequest 3 9904 NULL
94221 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
94222 +tipc_send_51238 tipc_send 4 51238 NULL
94223 +drm_property_create_51239 drm_property_create 4 51239 NULL
94224 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
94225 +squashfs_read_data_59440 squashfs_read_data 6 59440 NULL
94226 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
94227 +audit_expand_2098 audit_expand 2 2098 NULL
94228 +st_read_51251 st_read 3 51251 NULL
94229 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
94230 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
94231 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
94232 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
94233 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
94234 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
94235 +rtsx_read_cfg_seq_48139 rtsx_read_cfg_seq 5-3 48139 NULL
94236 +__find_xattr_2117 __find_xattr 6 2117 NULL nohasharray
94237 +enable_read_2117 enable_read 3 2117 &__find_xattr_2117
94238 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
94239 +pcf50633_write_block_2124 pcf50633_write_block 3 2124 NULL
94240 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
94241 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
94242 +c4_add_card_54968 c4_add_card 3 54968 NULL
94243 +rtllib_authentication_req_26713 rtllib_authentication_req 3 26713 NULL
94244 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
94245 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
94246 +fd_do_readv_51297 fd_do_readv 3 51297 NULL
94247 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 5-6-9 18530 NULL
94248 +nfc_hci_send_cmd_async_26723 nfc_hci_send_cmd_async 5 26723 NULL
94249 +mlx4_init_icm_table_2151 mlx4_init_icm_table 5-4 2151 NULL
94250 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
94251 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
94252 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
94253 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
94254 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
94255 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
94256 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
94257 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
94258 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
94259 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
94260 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
94261 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
94262 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
94263 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
94264 +set_bypass_pwoff_pfs_27669 set_bypass_pwoff_pfs 3 27669 NULL
94265 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
94266 +srp_ring_alloc_26760 srp_ring_alloc 2 26760 NULL
94267 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
94268 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
94269 +ntfs_malloc_nofs_nofail_63631 ntfs_malloc_nofs_nofail 1 63631 NULL
94270 +cosa_net_setup_rx_38594 cosa_net_setup_rx 2 38594 NULL
94271 +skb_gro_header_slow_34958 skb_gro_header_slow 2 34958 NULL
94272 +debug_output_18575 debug_output 3 18575 NULL
94273 +Realloc_34961 Realloc 2 34961 NULL
94274 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
94275 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
94276 +_rtl92s_firmware_downloadcode_14021 _rtl92s_firmware_downloadcode 3 14021 NULL
94277 +__netdev_alloc_skb_18595 __netdev_alloc_skb 2 18595 NULL
94278 +slabinfo_write_18600 slabinfo_write 3 18600 NULL
94279 +ssb_bus_ssbbus_register_2217 ssb_bus_ssbbus_register 2 2217 NULL
94280 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
94281 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
94282 +vhci_write_2224 vhci_write 3 2224 NULL
94283 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
94284 +acpi_os_ioremap_49523 acpi_os_ioremap 1-2 49523 NULL
94285 +rb_alloc_3102 rb_alloc 1 3102 NULL
94286 +uf_create_device_nodes_24948 uf_create_device_nodes 2 24948 NULL
94287 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
94288 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
94289 +write_pbl_59583 write_pbl 4 59583 NULL
94290 +from_buffer_18625 from_buffer 3 18625 NULL
94291 +uio_write_43202 uio_write 3 43202 NULL
94292 +memdup_user_59590 memdup_user 2 59590 NULL
94293 +ieee80211_wx_set_gen_ie_51399 ieee80211_wx_set_gen_ie 3 51399 NULL
94294 +iso_callback_43208 iso_callback 3 43208 NULL
94295 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
94296 +smk_write_load_26829 smk_write_load 3 26829 NULL
94297 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
94298 +do_update_counters_2259 do_update_counters 4 2259 NULL
94299 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
94300 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
94301 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
94302 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
94303 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
94304 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
94305 +mtrr_write_59622 mtrr_write 3 59622 NULL
94306 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
94307 +ip_vs_icmp_xmit_59624 ip_vs_icmp_xmit 4 59624 NULL
94308 +netxen_nic_hw_read_wx_128M_26858 netxen_nic_hw_read_wx_128M 2 26858 NULL
94309 +edge_tty_recv_18667 edge_tty_recv 4 18667 NULL nohasharray
94310 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 &edge_tty_recv_18667
94311 +btmrvl_gpiogap_write_35053 btmrvl_gpiogap_write 3 35053 NULL
94312 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
94313 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
94314 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
94315 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
94316 +fixup_leb_43256 fixup_leb 3 43256 NULL
94317 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
94318 +ubifs_recover_log_leb_12079 ubifs_recover_log_leb 3 12079 NULL
94319 +ubifs_setxattr_59650 ubifs_setxattr 4 59650 NULL nohasharray
94320 +hidraw_read_59650 hidraw_read 3 59650 &ubifs_setxattr_59650
94321 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
94322 +ca91cx42_alloc_resource_10502 ca91cx42_alloc_resource 2 10502 NULL
94323 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
94324 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
94325 +evtchn_write_43278 evtchn_write 3 43278 NULL
94326 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
94327 +store_ifalias_35088 store_ifalias 4 35088 NULL
94328 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
94329 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
94330 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
94331 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
94332 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
94333 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
94334 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
94335 +get_vm_area_caller_10527 get_vm_area_caller 1 10527 NULL
94336 +capi_write_35104 capi_write 3 35104 NULL nohasharray
94337 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
94338 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
94339 +sys_semtimedop_4486 sys_semtimedop 3 4486 NULL
94340 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
94341 +osd_req_write_sg_50908 osd_req_write_sg 5 50908 NULL
94342 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
94343 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
94344 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
94345 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
94346 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
94347 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 NULL nohasharray
94348 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 &pwr_ps_enter_read_26935
94349 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
94350 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 NULL
94351 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
94352 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
94353 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
94354 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
94355 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
94356 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
94357 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
94358 +do_trimming_26952 do_trimming 3 26952 NULL
94359 +ath6kl_wmi_set_ie_cmd_37260 ath6kl_wmi_set_ie_cmd 6 37260 NULL
94360 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
94361 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
94362 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
94363 +alloc_buf_34532 alloc_buf 1 34532 NULL
94364 +sock_rmalloc_59740 sock_rmalloc 2 59740 NULL nohasharray
94365 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 &sock_rmalloc_59740
94366 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
94367 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
94368 +otp_read_10594 otp_read 2-4-5 10594 NULL
94369 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
94370 +sctp_manip_pkt_59749 sctp_manip_pkt 4 59749 NULL
94371 +icmp_manip_pkt_51560 icmp_manip_pkt 4 51560 NULL
94372 +brcmf_sdbrcm_read_control_22721 brcmf_sdbrcm_read_control 3 22721 NULL
94373 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
94374 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
94375 +roccat_common2_send_2422 roccat_common2_send 4 2422 NULL
94376 +ieee80211_auth_challenge_18810 ieee80211_auth_challenge 3 18810 NULL
94377 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
94378 +cxgb3_get_cpl_reply_skb_10620 cxgb3_get_cpl_reply_skb 2 10620 NULL
94379 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
94380 +venus_remove_59781 venus_remove 4 59781 NULL
94381 +ioremap_nocache_2439 ioremap_nocache 1-2 2439 NULL
94382 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
94383 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
94384 +tty_buffer_find_2443 tty_buffer_find 2 2443 NULL
94385 +xlog_do_recover_59789 xlog_do_recover 3 59789 NULL
94386 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
94387 +rfcomm_tty_write_51603 rfcomm_tty_write 3 51603 NULL
94388 +xenfb_write_43412 xenfb_write 3 43412 NULL
94389 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
94390 +nfs4_alloc_slots_2454 nfs4_alloc_slots 1 2454 NULL nohasharray
94391 +ath6kl_usb_bmi_write_2454 ath6kl_usb_bmi_write 3 2454 &nfs4_alloc_slots_2454
94392 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
94393 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
94394 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL nohasharray
94395 +gdm_wimax_netif_rx_43423 gdm_wimax_netif_rx 3 43423 &__alloc_bootmem_low_43423
94396 +rtllib_wx_set_gen_ie_59808 rtllib_wx_set_gen_ie 3 59808 NULL
94397 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
94398 +udp_manip_pkt_45467 udp_manip_pkt 4 45467 NULL
94399 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
94400 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
94401 +ni65_alloc_mem_10664 ni65_alloc_mem 3 10664 NULL
94402 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
94403 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
94404 +cmd_complete_51629 cmd_complete 6 51629 NULL
94405 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
94406 +btmrvl_txdnldready_read_413 btmrvl_txdnldready_read 3 413 NULL
94407 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
94408 +set_fd_set_35249 set_fd_set 1 35249 NULL
94409 +wiphy_new_2482 wiphy_new 2 2482 NULL
94410 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
94411 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
94412 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
94413 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
94414 +tcp_push_10680 tcp_push 3 10680 NULL
94415 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
94416 +c101_run_37279 c101_run 2 37279 NULL
94417 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
94418 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
94419 +tun_put_user_59849 tun_put_user 4 59849 NULL
94420 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
94421 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
94422 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
94423 +dm_write_2513 dm_write 3 2513 NULL
94424 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
94425 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
94426 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL
94427 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
94428 +ntfs_malloc_nofs_49572 ntfs_malloc_nofs 1 49572 NULL
94429 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
94430 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 NULL nohasharray
94431 +shash_async_setkey_10720 shash_async_setkey 3 10720 &pvr2_ioread_read_10720
94432 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
94433 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
94434 +__iscsi_complete_pdu_10726 __iscsi_complete_pdu 4 10726 NULL
94435 +sfi_sysfs_install_table_51688 sfi_sysfs_install_table 1 51688 NULL
94436 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
94437 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
94438 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
94439 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
94440 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 NULL nohasharray
94441 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 &brcmf_sdio_forensic_read_35311
94442 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
94443 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 NULL
94444 +compat_sys_msgsnd_10738 compat_sys_msgsnd 2 10738 NULL
94445 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
94446 +sel_write_access_51704 sel_write_access 3 51704 NULL
94447 +sys_syslog_10746 sys_syslog 3 10746 NULL
94448 +alloc_one_pg_vec_page_10747 alloc_one_pg_vec_page 1 10747 NULL
94449 +new_bind_ctl_35324 new_bind_ctl 2 35324 NULL
94450 +do_readlink_43518 do_readlink 2 43518 NULL
94451 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
94452 +gem_alloc_skb_51715 gem_alloc_skb 2 51715 NULL
94453 +fallback_on_nodma_alloc_35332 fallback_on_nodma_alloc 2 35332 NULL
94454 +read_file_reset_52310 read_file_reset 3 52310 NULL
94455 +pms_capture_27142 pms_capture 4 27142 NULL
94456 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
94457 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
94458 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
94459 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
94460 +msg_set_51725 msg_set 3 51725 NULL
94461 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
94462 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
94463 +hpi_alloc_control_cache_35351 hpi_alloc_control_cache 1 35351 NULL
94464 +hid_parse_report_51737 hid_parse_report 3 51737 NULL
94465 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
94466 +alc_auto_create_extra_outs_18975 alc_auto_create_extra_outs 2 18975 NULL
94467 +i2400m_net_rx_27170 i2400m_net_rx 5 27170 NULL
94468 +l3_alloc_skb_32289 l3_alloc_skb 1 32289 NULL
94469 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
94470 +ath_rx_init_43564 ath_rx_init 2 43564 NULL
94471 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 NULL nohasharray
94472 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 &il_dbgfs_rxon_flags_read_59950
94473 +sys_bind_10799 sys_bind 3 10799 NULL
94474 +_fc_frame_alloc_43568 _fc_frame_alloc 1 43568 NULL
94475 +nfcwilink_send_bts_cmd_10802 nfcwilink_send_bts_cmd 3 10802 NULL
94476 +ioremap_prot_51764 ioremap_prot 1-2 51764 NULL
94477 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
94478 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 2-3 33204 NULL
94479 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
94480 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
94481 +drm_vblank_init_11362 drm_vblank_init 2 11362 NULL
94482 +send_command_10832 send_command 4 10832 NULL
94483 +lro_gen_skb_2644 lro_gen_skb 6 2644 NULL
94484 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
94485 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
94486 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
94487 +proc_read_43614 proc_read 3 43614 NULL
94488 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
94489 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
94490 +drm_fb_helper_init_19044 drm_fb_helper_init 3-4 19044 NULL
94491 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
94492 +xlbd_reserve_minors_18365 xlbd_reserve_minors 1-2 18365 NULL
94493 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
94494 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
94495 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
94496 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
94497 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
94498 +vmalloc_15464 vmalloc 1 15464 NULL
94499 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
94500 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
94501 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
94502 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
94503 +cfpkt_add_trail_27260 cfpkt_add_trail 3 27260 NULL
94504 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
94505 +sys_sched_getaffinity_60033 sys_sched_getaffinity 2 60033 NULL
94506 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 NULL
94507 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
94508 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
94509 +adu_write_30487 adu_write 3 30487 NULL
94510 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
94511 +get_scq_10897 get_scq 2 10897 NULL
94512 +sys_process_vm_readv_19090 sys_process_vm_readv 3-5 19090 NULL nohasharray
94513 +brcmf_usbdev_qinit_19090 brcmf_usbdev_qinit 2 19090 &sys_process_vm_readv_19090
94514 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
94515 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
94516 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
94517 +load_module_60056 load_module 2 60056 NULL nohasharray
94518 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 &load_module_60056
94519 +__videobuf_alloc_cached_12740 __videobuf_alloc_cached 1 12740 NULL
94520 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
94521 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4-2 43679 NULL
94522 +ieee80211_build_probe_req_60064 ieee80211_build_probe_req 8-6 60064 NULL
94523 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
94524 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
94525 +__netdev_alloc_skb_ip_align_55067 __netdev_alloc_skb_ip_align 2 55067 NULL
94526 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
94527 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
94528 +__copy_from_user_10918 __copy_from_user 3 10918 NULL
94529 +user_read_51881 user_read 3 51881 NULL
94530 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
94531 +__xip_file_write_2733 __xip_file_write 4-3 2733 NULL
94532 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL
94533 +ath6kl_wmi_test_cmd_27312 ath6kl_wmi_test_cmd 3 27312 NULL
94534 +max77693_bulk_write_43698 max77693_bulk_write 3 43698 NULL
94535 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
94536 +hidp_send_ctrl_message_43702 hidp_send_ctrl_message 4 43702 NULL
94537 +async_setkey_35521 async_setkey 3 35521 NULL
94538 +set_dev_class_39645 set_dev_class 4 39645 NULL nohasharray
94539 +dm_exception_table_init_39645 dm_exception_table_init 2 39645 &set_dev_class_39645
94540 +cxgb4_pktgl_to_skb_61899 cxgb4_pktgl_to_skb 2 61899 NULL
94541 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
94542 +iio_read_first_n_sw_rb_51911 iio_read_first_n_sw_rb 2 51911 NULL
94543 +hid_report_raw_event_2762 hid_report_raw_event 4 2762 NULL
94544 +add_tty_40055 add_tty 1 40055 NULL nohasharray
94545 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 &add_tty_40055
94546 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
94547 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
94548 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
94549 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
94550 +ttm_bo_kmap_60118 ttm_bo_kmap 3-2 60118 NULL
94551 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
94552 +alloc_context_3194 alloc_context 1 3194 NULL
94553 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
94554 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
94555 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
94556 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
94557 +i915_min_freq_write_10981 i915_min_freq_write 3 10981 NULL
94558 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
94559 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
94560 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
94561 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
94562 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
94563 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
94564 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
94565 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
94566 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
94567 +init_state_60165 init_state 2 60165 NULL
94568 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
94569 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
94570 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3 19214 NULL
94571 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
94572 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
94573 +sg_build_sgat_60179 sg_build_sgat 3 60179 NULL nohasharray
94574 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 &sg_build_sgat_60179
94575 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
94576 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
94577 +calc_hmac_32010 calc_hmac 3 32010 NULL
94578 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
94579 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
94580 +btrfs_copy_from_user_43806 btrfs_copy_from_user 3-1 43806 NULL
94581 +kernel_readv_35617 kernel_readv 3 35617 NULL
94582 +hci_send_cmd_43810 hci_send_cmd 3 43810 NULL
94583 +sys_lgetxattr_45531 sys_lgetxattr 4 45531 NULL
94584 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
94585 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
94586 +nouveau_gpio_create__11048 nouveau_gpio_create_ 4 11048 NULL
94587 +dccp_manip_pkt_476 dccp_manip_pkt 4 476 NULL
94588 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
94589 +set_tap_pfs_60203 set_tap_pfs 3 60203 NULL
94590 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
94591 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
94592 +carl9170_handle_mpdu_11056 carl9170_handle_mpdu 3 11056 NULL
94593 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
94594 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
94595 +vxge_rx_alloc_52024 vxge_rx_alloc 3 52024 NULL
94596 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
94597 +__ip_append_data_16864 __ip_append_data 8-9 16864 NULL
94598 +p54_download_eeprom_43842 p54_download_eeprom 4 43842 NULL
94599 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
94600 +store_debug_level_35652 store_debug_level 3 35652 NULL
94601 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
94602 +read_flush_43851 read_flush 3 43851 NULL
94603 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
94604 +cmm_write_2896 cmm_write 3 2896 NULL
94605 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
94606 +io_mapping_map_wc_19284 io_mapping_map_wc 2 19284 NULL
94607 +tunables_write_59563 tunables_write 3 59563 NULL
94608 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
94609 +rtsx_write_cfg_seq_27485 rtsx_write_cfg_seq 5-3 27485 NULL
94610 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
94611 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
94612 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
94613 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
94614 +dm_table_create_35687 dm_table_create 3 35687 NULL
94615 +qib_create_cq_27497 qib_create_cq 2 27497 NULL
94616 +nfc_hci_execute_cmd_43882 nfc_hci_execute_cmd 5 43882 NULL
94617 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
94618 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
94619 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
94620 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 NULL
94621 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
94622 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
94623 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
94624 +debug_read_19322 debug_read 3 19322 NULL
94625 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
94626 +__pskb_pull_tail_60287 __pskb_pull_tail 2 60287 NULL
94627 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
94628 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 NULL
94629 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
94630 +dn_nsp_return_disc_60296 dn_nsp_return_disc 2 60296 NULL
94631 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
94632 +prism2_sta_send_mgmt_43916 prism2_sta_send_mgmt 5 43916 NULL
94633 +mgmt_device_found_14146 mgmt_device_found 10 14146 NULL
94634 +snd_seq_oss_readq_new_14283 snd_seq_oss_readq_new 2 14283 NULL
94635 +doc_probe_23285 doc_probe 1 23285 NULL
94636 +ppp_cp_event_2965 ppp_cp_event 6 2965 NULL
94637 +SendString_43928 SendString 3 43928 NULL
94638 +acpi_os_map_memory_11161 acpi_os_map_memory 1-2 11161 NULL
94639 +ceph_parse_server_name_60318 ceph_parse_server_name 2 60318 NULL
94640 +retry_count_read_52129 retry_count_read 3 52129 NULL
94641 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
94642 +ioat2_alloc_ring_11172 ioat2_alloc_ring 2 11172 NULL
94643 +read_zero_19366 read_zero 3 19366 NULL
94644 +bch_alloc_4593 bch_alloc 1 4593 NULL
94645 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
94646 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
94647 +libipw_alloc_txb_27579 libipw_alloc_txb 1-2-3 27579 NULL
94648 +raid5_resize_63306 raid5_resize 2 63306 NULL
94649 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
94650 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
94651 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
94652 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
94653 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
94654 +depth_write_3021 depth_write 3 3021 NULL
94655 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
94656 +read_file_stations_35795 read_file_stations 3 35795 NULL
94657 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
94658 +tipc_cfg_reply_alloc_27606 tipc_cfg_reply_alloc 1 27606 NULL
94659 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 NULL
94660 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
94661 +ubi_eba_atomic_leb_change_60379 ubi_eba_atomic_leb_change 5 60379 NULL
94662 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 NULL
94663 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
94664 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
94665 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
94666 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
94667 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
94668 +driver_names_read_60399 driver_names_read 3 60399 NULL
94669 +read_flush_procfs_27642 read_flush_procfs 3 27642 NULL
94670 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
94671 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
94672 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
94673 +_alloc_mISDN_skb_52232 _alloc_mISDN_skb 3 52232 NULL
94674 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
94675 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
94676 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
94677 +do_dmabuf_dirty_ldu_52241 do_dmabuf_dirty_ldu 6 52241 NULL
94678 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
94679 +rx_data_60442 rx_data 4 60442 NULL
94680 +ttusb2_msg_3100 ttusb2_msg 4 3100 NULL
94681 +efivar_create_sysfs_entry_19485 efivar_create_sysfs_entry 2 19485 NULL
94682 +tcf_csum_ipv4_igmp_60446 tcf_csum_ipv4_igmp 3 60446 NULL
94683 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
94684 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
94685 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
94686 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
94687 +__tty_buffer_request_room_27700 __tty_buffer_request_room 2 27700 NULL
94688 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
94689 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
94690 +tcp_mark_head_lost_35895 tcp_mark_head_lost 2 35895 NULL
94691 +skb_realloc_headroom_19516 skb_realloc_headroom 2 19516 NULL
94692 +atm_alloc_charge_19517 atm_alloc_charge 2 19517 NULL nohasharray
94693 +dev_alloc_skb_19517 dev_alloc_skb 1 19517 &atm_alloc_charge_19517
94694 +construct_key_11329 construct_key 3 11329 NULL
94695 +evm_write_key_27715 evm_write_key 3 27715 NULL
94696 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 1-2 11332 NULL
94697 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
94698 +filldir_55137 filldir 3 55137 NULL
94699 +igmpv3_newpack_35912 igmpv3_newpack 2 35912 NULL
94700 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
94701 +reg_w_buf_27724 reg_w_buf 3 27724 NULL
94702 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
94703 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
94704 +a4t_cs_init_27734 a4t_cs_init 3 27734 NULL
94705 +sel_write_create_11353 sel_write_create 3 11353 NULL
94706 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
94707 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
94708 +hwflags_read_52318 hwflags_read 3 52318 NULL
94709 +nfc_alloc_send_skb_3167 nfc_alloc_send_skb 4 3167 NULL
94710 +batadv_skb_head_push_11360 batadv_skb_head_push 2 11360 NULL
94711 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
94712 +vmw_gmr_bind_44130 vmw_gmr_bind 3 44130 NULL
94713 +ath_tx_init_60515 ath_tx_init 2 60515 NULL
94714 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
94715 +ntfs_rl_split_52328 ntfs_rl_split 2-4 52328 NULL
94716 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
94717 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
94718 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
94719 +nfsd_read_19568 nfsd_read 5 19568 NULL
94720 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
94721 +hysdn_sched_rx_60533 hysdn_sched_rx 3 60533 NULL
94722 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
94723 +kcalloc_27770 kcalloc 1-2 27770 NULL
94724 +shmem_pread_slow_3198 shmem_pread_slow 3 3198 NULL
94725 +bm_status_read_19583 bm_status_read 3 19583 NULL
94726 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
94727 +zd_mac_rx_38296 zd_mac_rx 3 38296 NULL
94728 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
94729 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL
94730 +acl_alloc_35979 acl_alloc 1 35979 NULL
94731 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
94732 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
94733 +str_to_user_11411 str_to_user 2 11411 NULL
94734 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
94735 +koneplus_sysfs_write_35993 koneplus_sysfs_write 6 35993 NULL
94736 +trace_options_read_11419 trace_options_read 3 11419 NULL
94737 +ttm_object_file_init_27804 ttm_object_file_init 2 27804 NULL
94738 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
94739 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
94740 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
94741 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
94742 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
94743 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
94744 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
94745 +console_store_36007 console_store 4 36007 NULL
94746 +bttv_read_11432 bttv_read 3 11432 NULL
94747 +key_key_read_3241 key_key_read 3 3241 NULL
94748 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
94749 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
94750 +__feat_register_sp_64712 __feat_register_sp 6 64712 NULL
94751 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
94752 +check_vendor_extension_3254 check_vendor_extension 1 3254 NULL
94753 +ieee80211_amsdu_to_8023s_15561 ieee80211_amsdu_to_8023s 5 15561 NULL
94754 +sys_listxattr_27833 sys_listxattr 3 27833 NULL
94755 +aac_rx_ioremap_52410 aac_rx_ioremap 2 52410 NULL
94756 +ubi_eba_write_leb_36029 ubi_eba_write_leb 5-6 36029 NULL
94757 +um_idi_write_18293 um_idi_write 3 18293 NULL
94758 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
94759 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
94760 +usbvision_rvmalloc_19655 usbvision_rvmalloc 1 19655 NULL
94761 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
94762 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
94763 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
94764 +sys_init_module_36047 sys_init_module 2 36047 NULL
94765 +read_profile_27859 read_profile 3 27859 NULL
94766 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
94767 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 NULL
94768 +enlarge_skb_44248 enlarge_skb 2 44248 NULL nohasharray
94769 +xfs_buf_readahead_map_44248 xfs_buf_readahead_map 3 44248 &enlarge_skb_44248
94770 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
94771 +refill_pool_19477 refill_pool 2 19477 NULL
94772 +ubifs_recover_leb_60639 ubifs_recover_leb 3 60639 NULL
94773 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
94774 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
94775 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
94776 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
94777 +tcp_sacktag_walk_49703 tcp_sacktag_walk 6 49703 NULL
94778 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
94779 +arvo_sysfs_write_3311 arvo_sysfs_write 6 3311 NULL
94780 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
94781 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
94782 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
94783 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
94784 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
94785 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1-2 52477 NULL
94786 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
94787 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
94788 +venus_symlink_23570 venus_symlink 4-6 23570 NULL
94789 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
94790 +aac_rkt_ioremap_3333 aac_rkt_ioremap 2 3333 NULL
94791 +sctp_make_init_ack_3335 sctp_make_init_ack 4 3335 NULL
94792 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
94793 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
94794 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
94795 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
94796 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
94797 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
94798 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
94799 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
94800 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
94801 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
94802 +ath6kl_usb_ctrl_msg_exchange_33327 ath6kl_usb_ctrl_msg_exchange 4 33327 NULL
94803 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
94804 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
94805 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
94806 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
94807 +vmalloc_exec_36132 vmalloc_exec 1 36132 NULL
94808 +init_data_container_60709 init_data_container 1 60709 NULL
94809 +p9_client_read_19750 p9_client_read 5 19750 NULL
94810 +skb_cow_data_11565 skb_cow_data 2 11565 NULL
94811 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
94812 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
94813 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
94814 +mlx4_init_cmpt_table_11569 mlx4_init_cmpt_table 3 11569 NULL
94815 +iwl_trans_txq_alloc_36147 iwl_trans_txq_alloc 3 36147 NULL
94816 +alloc_vm_area_36149 alloc_vm_area 1 36149 NULL
94817 +ubi_eba_write_leb_st_44343 ubi_eba_write_leb_st 5 44343 NULL
94818 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
94819 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
94820 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
94821 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
94822 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 NULL nohasharray
94823 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 &nfs_fscache_get_super_cookie_44355
94824 +saa7146_vmalloc_build_pgtable_19780 saa7146_vmalloc_build_pgtable 2 19780 NULL
94825 +send_stream_3397 send_stream 4 3397 NULL
94826 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
94827 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
94828 +ipx_recvmsg_44366 ipx_recvmsg 4 44366 NULL
94829 +hycapi_rx_capipkt_11602 hycapi_rx_capipkt 3 11602 NULL
94830 +msix_map_region_3411 msix_map_region 3 3411 NULL
94831 +sys_kexec_load_14222 sys_kexec_load 2 14222 NULL
94832 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
94833 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
94834 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
94835 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
94836 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
94837 +opticon_write_60775 opticon_write 4 60775 NULL
94838 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
94839 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
94840 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
94841 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
94842 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
94843 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
94844 +vip_read_19832 vip_read 3 19832 NULL
94845 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
94846 +llc_shdlc_alloc_skb_11645 llc_shdlc_alloc_skb 2 11645 NULL
94847 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
94848 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
94849 +nfqnl_mangle_36226 nfqnl_mangle 4-2 36226 NULL
94850 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
94851 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
94852 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
94853 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
94854 +alloc_skb_fclone_3467 alloc_skb_fclone 1 3467 NULL
94855 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
94856 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
94857 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2 28053 NULL
94858 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
94859 +llcp_allocate_pdu_19866 llcp_allocate_pdu 3 19866 NULL
94860 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
94861 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
94862 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
94863 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
94864 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
94865 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
94866 +split_11691 split 2 11691 NULL
94867 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
94868 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
94869 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
94870 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL
94871 +__kfifo_alloc_22173 __kfifo_alloc 2-3 22173 NULL
94872 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
94873 +gdth_init_isa_28091 gdth_init_isa 1 28091 NULL
94874 +readahead_tree_block_36285 readahead_tree_block 3 36285 NULL
94875 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL nohasharray
94876 +ieee80211_wx_set_gen_ie_rsl_3521 ieee80211_wx_set_gen_ie_rsl 3 3521 &mem_tx_free_mem_blks_read_3521
94877 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
94878 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
94879 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
94880 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
94881 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
94882 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
94883 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
94884 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 NULL
94885 +tcf_csum_ipv6_icmp_11738 tcf_csum_ipv6_icmp 4 11738 NULL
94886 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
94887 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
94888 +spidev_write_44510 spidev_write 3 44510 NULL
94889 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
94890 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
94891 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
94892 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
94893 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
94894 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
94895 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
94896 +kone_receive_4690 kone_receive 4 4690 NULL
94897 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
94898 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
94899 +evtchn_read_3569 evtchn_read 3 3569 NULL
94900 +video_read_28148 video_read 3 28148 NULL
94901 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
94902 +sys_msgsnd_44537 sys_msgsnd 3 44537 NULL nohasharray
94903 +comm_write_44537 comm_write 3 44537 &sys_msgsnd_44537
94904 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
94905 +ax25_send_frame_19964 ax25_send_frame 2 19964 NULL
94906 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
94907 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
94908 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
94909 +vc_resize_3585 vc_resize 2-3 3585 NULL
94910 +gluebi_write_27905 gluebi_write 3 27905 NULL
94911 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
94912 +c4iw_reject_cr_28174 c4iw_reject_cr 3 28174 NULL
94913 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
94914 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
94915 +compat_sys_semtimedop_3606 compat_sys_semtimedop 3 3606 NULL
94916 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
94917 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
94918 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
94919 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
94920 +pti_char_write_60960 pti_char_write 3 60960 NULL
94921 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
94922 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
94923 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
94924 +read_vbt_r10_60679 read_vbt_r10 1 60679 NULL
94925 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
94926 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
94927 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL nohasharray
94928 +fwnet_pd_new_39947 fwnet_pd_new 4 39947 &error_error_frame_read_39947
94929 +snd_pcm_alloc_vmalloc_buffer_44595 snd_pcm_alloc_vmalloc_buffer 2 44595 NULL
94930 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
94931 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
94932 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
94933 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
94934 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
94935 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
94936 +cm_copy_private_data_3649 cm_copy_private_data 2 3649 NULL
94937 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
94938 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 NULL nohasharray
94939 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 &ieee80211_if_read_auto_open_plinks_38268
94940 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL
94941 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
94942 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
94943 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
94944 +cfpkt_add_body_44630 cfpkt_add_body 3 44630 NULL
94945 +nf_nat_sdp_media_11863 nf_nat_sdp_media 9 11863 NULL
94946 +alloc_extent_buffer_52824 alloc_extent_buffer 3 52824 NULL
94947 +skb_cow_head_52495 skb_cow_head 2 52495 NULL
94948 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
94949 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
94950 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
94951 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
94952 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
94953 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
94954 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL
94955 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
94956 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
94957 +btmrvl_psmode_write_3703 btmrvl_psmode_write 3 3703 NULL
94958 +symtab_init_61050 symtab_init 2 61050 NULL
94959 +team_options_register_20091 team_options_register 3 20091 NULL
94960 +videobuf_pages_to_sg_3708 videobuf_pages_to_sg 2 3708 NULL
94961 +mon_bin_get_event_52863 mon_bin_get_event 4 52863 NULL
94962 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
94963 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
94964 +mpi_resize_44674 mpi_resize 2 44674 NULL
94965 +ip6_append_data_36490 ip6_append_data 4-5 36490 NULL nohasharray
94966 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 &ip6_append_data_36490
94967 +kmalloc_slab_11917 kmalloc_slab 1 11917 NULL
94968 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
94969 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
94970 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
94971 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
94972 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
94973 +xfs_trans_read_buf_map_37487 xfs_trans_read_buf_map 5 37487 NULL
94974 +ci_ll_write_3740 ci_ll_write 4 3740 NULL
94975 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
94976 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
94977 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 NULL
94978 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
94979 +dccp_feat_clone_sp_val_11942 dccp_feat_clone_sp_val 3 11942 NULL
94980 +pms_read_53873 pms_read 3 53873 NULL
94981 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
94982 +get_derived_key_61100 get_derived_key 4 61100 NULL
94983 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
94984 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
94985 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
94986 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
94987 +dm_read_15674 dm_read 3 15674 NULL
94988 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
94989 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
94990 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
94991 +kone_send_63435 kone_send 4 63435 NULL
94992 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
94993 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
94994 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
94995 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
94996 +__kfifo_to_user_36555 __kfifo_to_user 3 36555 NULL nohasharray
94997 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
94998 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
94999 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
95000 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
95001 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
95002 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
95003 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
95004 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
95005 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
95006 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
95007 +send_packet_52960 send_packet 4 52960 NULL
95008 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
95009 +ssb_bus_scan_36578 ssb_bus_scan 2 36578 NULL
95010 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
95011 +tipc_port_reject_sections_55229 tipc_port_reject_sections 5 55229 NULL
95012 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
95013 +set_bypass_pfs_28395 set_bypass_pfs 3 28395 NULL
95014 +put_cmsg_36589 put_cmsg 4 36589 NULL
95015 +__vmalloc_61168 __vmalloc 1 61168 NULL
95016 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
95017 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
95018 +read_file_tx_chainmask_3829 read_file_tx_chainmask 3 3829 NULL
95019 +pcnet32_realloc_rx_ring_36598 pcnet32_realloc_rx_ring 3 36598 NULL
95020 +event_oom_late_read_61175 event_oom_late_read 3 61175 NULL nohasharray
95021 +pair_device_61175 pair_device 4 61175 &event_oom_late_read_61175
95022 +sys_lsetxattr_61177 sys_lsetxattr 4 61177 NULL
95023 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
95024 +nfs4_alloc_pages_48426 nfs4_alloc_pages 1 48426 NULL
95025 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
95026 +batadv_check_management_packet_52993 batadv_check_management_packet 3 52993 NULL
95027 +tpci200_slot_map_space_3848 tpci200_slot_map_space 2 3848 NULL
95028 +regmap_bulk_write_59049 regmap_bulk_write 4 59049 NULL
95029 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
95030 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
95031 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
95032 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
95033 +cfpkt_append_61206 cfpkt_append 3 61206 NULL
95034 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
95035 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
95036 +get_fd_set_3866 get_fd_set 1 3866 NULL
95037 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
95038 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
95039 +unlink_queued_645 unlink_queued 3-4 645 NULL
95040 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
95041 +sisusb_write_44834 sisusb_write 3 44834 NULL
95042 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
95043 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
95044 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
95045 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
95046 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
95047 +uea_send_modem_cmd_3888 uea_send_modem_cmd 3 3888 NULL
95048 +h5_prepare_pkt_12085 h5_prepare_pkt 4 12085 NULL
95049 +nvram_write_3894 nvram_write 3 3894 NULL
95050 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
95051 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
95052 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
95053 +vcs_write_3910 vcs_write 3 3910 NULL
95054 +sctp_make_abort_violation_27959 sctp_make_abort_violation 4 27959 NULL
95055 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
95056 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
95057 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL
95058 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
95059 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
95060 +do_tty_write_44896 do_tty_write 5 44896 NULL
95061 +set_powered_12129 set_powered 4 12129 NULL
95062 +qib_resize_cq_53090 qib_resize_cq 2 53090 NULL
95063 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
95064 +nfs_writedata_alloc_12133 nfs_writedata_alloc 2 12133 NULL
95065 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
95066 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
95067 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
95068 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
95069 +vmw_fifo_reserve_12141 vmw_fifo_reserve 2 12141 NULL
95070 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
95071 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
95072 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
95073 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
95074 +capinc_tty_write_28539 capinc_tty_write 3 28539 NULL
95075 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
95076 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL
95077 +line6_dumpreq_initbuf_53123 line6_dumpreq_initbuf 3 53123 NULL
95078 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4 36740 NULL
95079 +gather_array_56641 gather_array 3 56641 NULL
95080 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
95081 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
95082 +dma_memcpy_to_iovec_12173 dma_memcpy_to_iovec 5 12173 NULL
95083 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
95084 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
95085 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
95086 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
95087 +regcache_rbtree_insert_to_block_58009 regcache_rbtree_insert_to_block 5 58009 NULL
95088 +do_add_counters_3992 do_add_counters 3 3992 NULL
95089 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 NULL
95090 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
95091 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
95092 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
95093 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
95094 +ip4ip6_err_36772 ip4ip6_err 5 36772 NULL
95095 +mei_write_4005 mei_write 3 4005 NULL
95096 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
95097 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
95098 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL
95099 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
95100 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
95101 +receive_copy_12216 receive_copy 3 12216 NULL
95102 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 NULL
95103 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
95104 +bcsp_prepare_pkt_12961 bcsp_prepare_pkt 3 12961 NULL
95105 +ftdi_process_packet_45005 ftdi_process_packet 5 45005 NULL
95106 +change_xattr_61390 change_xattr 5 61390 NULL
95107 +find_skb_20431 find_skb 2 20431 NULL
95108 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
95109 +fmc_send_cmd_20435 fmc_send_cmd 5 20435 NULL
95110 +tcp_fragment_20436 tcp_fragment 3 20436 NULL
95111 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
95112 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
95113 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
95114 +sys_sethostname_42962 sys_sethostname 2 42962 NULL
95115 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
95116 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
95117 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
95118 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
95119 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
95120 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
95121 +sctp_make_asconf_4078 sctp_make_asconf 3 4078 NULL
95122 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
95123 +ip_vs_icmp_xmit_v6_20464 ip_vs_icmp_xmit_v6 4 20464 NULL
95124 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
95125 +read_buf_20469 read_buf 2 20469 NULL
95126 +cm_write_36858 cm_write 3 36858 NULL
95127 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
95128 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
95129 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 NULL
95130 +sel_write_user_45060 sel_write_user 3 45060 NULL
95131 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
95132 +__dev_alloc_skb_28681 __dev_alloc_skb 1 28681 NULL
95133 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
95134 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
95135 +fast_user_write_20494 fast_user_write 5 20494 NULL
95136 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
95137 +sctp_make_fwdtsn_53265 sctp_make_fwdtsn 3 53265 NULL
95138 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
95139 +hidraw_report_event_20503 hidraw_report_event 3 20503 NULL
95140 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
95141 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
95142 +lirc_buffer_init_53282 lirc_buffer_init 3-2 53282 NULL
95143 +tipc_msg_build_12326 tipc_msg_build 4 12326 NULL
95144 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
95145 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
95146 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
95147 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
95148 +osst_read_40237 osst_read 3 40237 NULL
95149 +tm6000_read_4151 tm6000_read 3 4151 NULL
95150 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
95151 +usbdev_read_45114 usbdev_read 3 45114 NULL
95152 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
95153 +spi_execute_28736 spi_execute 5 28736 NULL
95154 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
95155 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
95156 +get_alua_req_4166 get_alua_req 3 4166 NULL
95157 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
95158 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
95159 +venus_create_20555 venus_create 4 20555 NULL
95160 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
95161 +batadv_interface_rx_53325 batadv_interface_rx 4 53325 NULL
95162 +receive_packet_12367 receive_packet 2 12367 NULL
95163 +squashfs_cache_init_41656 squashfs_cache_init 2 41656 NULL
95164 +mem_write_22232 mem_write 3 22232 NULL
95165 +read_file_bool_4180 read_file_bool 3 4180 NULL
95166 +send_to_tty_45141 send_to_tty 3 45141 NULL
95167 +fops_read_40672 fops_read 3 40672 NULL
95168 +cxio_init_resource_fifo_28764 cxio_init_resource_fifo 3 28764 NULL
95169 +write_leb_36957 write_leb 5 36957 NULL
95170 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
95171 +device_write_45156 device_write 3 45156 NULL
95172 +i915_max_freq_read_20581 i915_max_freq_read 3 20581 NULL
95173 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
95174 +sparse_early_mem_maps_alloc_node_36971 sparse_early_mem_maps_alloc_node 4 36971 NULL
95175 +batadv_tt_append_diff_20588 batadv_tt_append_diff 4 20588 NULL
95176 +dvb_net_sec_callback_28786 dvb_net_sec_callback 2 28786 NULL
95177 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
95178 +isp1760_register_628 isp1760_register 1-2 628 NULL
95179 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
95180 +lirc_write_20604 lirc_write 3 20604 NULL
95181 +sel_write_member_28800 sel_write_member 3 28800 NULL
95182 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
95183 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
95184 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
95185 +sys_msgrcv_959 sys_msgrcv 3 959 NULL
95186 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL
95187 +pskb_network_may_pull_35336 pskb_network_may_pull 2 35336 NULL
95188 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
95189 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
95190 +setxattr_37006 setxattr 4 37006 NULL
95191 +add_child_45201 add_child 4 45201 NULL
95192 +seq_open_private_61589 seq_open_private 3 61589 NULL
95193 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
95194 +__get_vm_area_61599 __get_vm_area 1 61599 NULL
95195 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
95196 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
95197 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3 20646 NULL
95198 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
95199 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
95200 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
95201 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
95202 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
95203 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL
95204 +ieee80211_rx_bss_info_61630 ieee80211_rx_bss_info 3 61630 NULL
95205 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
95206 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
95207 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
95208 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
95209 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
95210 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 4 20682 NULL
95211 +get_packet_pg_28023 get_packet_pg 4 28023 NULL
95212 +rtllib_auth_challenge_12493 rtllib_auth_challenge 3 12493 NULL
95213 +acpi_tb_parse_root_table_53455 acpi_tb_parse_root_table 1 53455 NULL
95214 +resize_stripes_61650 resize_stripes 2 61650 NULL
95215 +n2_run_53459 n2_run 3 53459 NULL
95216 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
95217 +parse_command_37079 parse_command 2 37079 NULL
95218 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
95219 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
95220 +ttm_page_pool_free_61661 ttm_page_pool_free 2 61661 NULL
95221 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
95222 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
95223 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
95224 +insert_one_name_61668 insert_one_name 7 61668 NULL
95225 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
95226 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
95227 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
95228 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
95229 +lock_loop_61681 lock_loop 1 61681 NULL
95230 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
95231 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
95232 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
95233 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
95234 +vring_add_indirect_20737 vring_add_indirect 3-4 20737 NULL
95235 +push_rx_28939 push_rx 3 28939 NULL
95236 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 3 4365 NULL
95237 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
95238 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
95239 +sys_setdomainname_4373 sys_setdomainname 2 4373 NULL
95240 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
95241 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
95242 +nouveau_dmaobj_create__61730 nouveau_dmaobj_create_ 6 61730 NULL
95243 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3 28963 NULL
95244 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
95245 +aac_srcv_ioremap_6659 aac_srcv_ioremap 2 6659 NULL
95246 +ubi_leb_change_10289 ubi_leb_change 4 10289 NULL
95247 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
95248 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
95249 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
95250 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
95251 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
95252 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL
95253 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
95254 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
95255 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 NULL
95256 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
95257 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
95258 +tstats_write_60432 tstats_write 3 60432 NULL nohasharray
95259 +kmalloc_60432 kmalloc 1 60432 &tstats_write_60432
95260 +bin_uuid_28999 bin_uuid 3 28999 NULL
95261 +sys_sendto_20809 sys_sendto 6 20809 NULL
95262 +alloc_page_cgroup_2919 alloc_page_cgroup 1 2919 NULL
95263 +set_registers_53582 set_registers 3 53582 NULL
95264 +fc_fcp_frame_alloc_12624 fc_fcp_frame_alloc 2 12624 NULL
95265 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
95266 +lane2_associate_req_45398 lane2_associate_req 4 45398 NULL
95267 +tcf_csum_ipv4_udp_30777 tcf_csum_ipv4_udp 4 30777 NULL
95268 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
95269 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2 37213 NULL
95270 +keymap_store_45406 keymap_store 4 45406 NULL
95271 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
95272 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
95273 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
95274 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
95275 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
95276 +xz_dec_init_29029 xz_dec_init 2 29029 NULL
95277 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
95278 +tcp_dma_try_early_copy_4457 tcp_dma_try_early_copy 3 4457 NULL
95279 +__do_replace_37227 __do_replace 5 37227 NULL
95280 +dn_alloc_send_pskb_4465 dn_alloc_send_pskb 2 4465 NULL
95281 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
95282 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
95283 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
95284 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
95285 +tso_fragment_29050 tso_fragment 3 29050 NULL
95286 +__alloc_pred_stack_26687 __alloc_pred_stack 2 26687 NULL
95287 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
95288 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
95289 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
95290 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
95291 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
95292 +__iio_allocate_sw_ring_buffer_4843 __iio_allocate_sw_ring_buffer 3 4843 NULL
95293 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
95294 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
95295 +intel_render_ring_init_dri_45446 intel_render_ring_init_dri 2-3 45446 NULL
95296 +udp_sendmsg_4492 udp_sendmsg 4 4492 NULL
95297 +ieee80211_probereq_get_29069 ieee80211_probereq_get 4-6 29069 NULL
95298 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
95299 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
95300 +_alloc_cdb_cont_23609 _alloc_cdb_cont 2 23609 NULL
95301 +set_link_security_4502 set_link_security 4 4502 NULL
95302 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
95303 +l1oip_socket_parse_4507 l1oip_socket_parse 4 4507 NULL
95304 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
95305 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
95306 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
95307 +srp_target_alloc_37288 srp_target_alloc 3 37288 NULL
95308 +mmio_read_40348 mmio_read 4 40348 NULL
95309 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
95310 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
95311 +compat_sys_readv_20911 compat_sys_readv 3 20911 NULL
95312 +ivtv_write_12721 ivtv_write 3 12721 NULL
95313 +fuse_fill_write_pages_53682 fuse_fill_write_pages 4 53682 NULL
95314 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
95315 +sys_llistxattr_4532 sys_llistxattr 3 4532 NULL
95316 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
95317 +da9052_group_write_4534 da9052_group_write 3 4534 NULL
95318 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
95319 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
95320 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
95321 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
95322 +videobuf_vmalloc_to_sg_4548 videobuf_vmalloc_to_sg 2 4548 NULL
95323 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
95324 +ieee80211_rtl_auth_challenge_61897 ieee80211_rtl_auth_challenge 3 61897 NULL
95325 +send_msg_37323 send_msg 4 37323 NULL
95326 +brcmf_sdbrcm_membytes_37324 brcmf_sdbrcm_membytes 3-5 37324 NULL
95327 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL
95328 +clear_refs_write_61904 clear_refs_write 3 61904 NULL
95329 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
95330 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
95331 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
95332 +virtqueue_add_buf_59470 virtqueue_add_buf 3-4 59470 NULL
95333 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
95334 +dsp_buffer_alloc_11684 dsp_buffer_alloc 2 11684 NULL
95335 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
95336 +reshape_ring_29147 reshape_ring 2 29147 NULL
95337 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
95338 +au0828_init_isoc_61917 au0828_init_isoc 3-2 61917 NULL
95339 +copy_macs_45534 copy_macs 4 45534 NULL
95340 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
95341 +listxattr_12769 listxattr 3 12769 NULL
95342 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
95343 +wdm_write_53735 wdm_write 3 53735 NULL
95344 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
95345 +send_bulk_static_data_61932 send_bulk_static_data 3 61932 NULL
95346 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
95347 +mempool_create_29437 mempool_create 1 29437 NULL
95348 +platform_create_bundle_12785 platform_create_bundle 4-6 12785 NULL
95349 +brcmf_tx_frame_20978 brcmf_tx_frame 3 20978 NULL
95350 +sock_alloc_send_pskb_21246 sock_alloc_send_pskb 2 21246 NULL
95351 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
95352 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
95353 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
95354 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
95355 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL
95356 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
95357 +mgmt_event_12810 mgmt_event 4 12810 NULL
95358 +ntfs_rl_realloc_nofail_32173 ntfs_rl_realloc_nofail 3 32173 NULL
95359 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
95360 +ipath_create_cq_45586 ipath_create_cq 2 45586 NULL
95361 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL nohasharray
95362 +alloc_group_attrs_29203 alloc_group_attrs 3 29203 &wusb_prf_256_29203
95363 +comedi_alloc_subdevices_29207 comedi_alloc_subdevices 2 29207 NULL
95364 +rdma_set_ib_paths_45592 rdma_set_ib_paths 3 45592 NULL
95365 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
95366 +rds_iw_inc_copy_to_user_29214 rds_iw_inc_copy_to_user 3 29214 NULL
95367 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
95368 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
95369 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
95370 +virtnet_send_command_61993 virtnet_send_command 5-6 61993 NULL
95371 +sys_getxattr_37418 sys_getxattr 4 37418 NULL
95372 +regmap_raw_write_53803 regmap_raw_write 4 53803 NULL
95373 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
95374 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
95375 +t4vf_pktgl_to_skb_39005 t4vf_pktgl_to_skb 2 39005 NULL
95376 +audit_log_n_hex_45617 audit_log_n_hex 3 45617 NULL
95377 +devm_ioremap_29235 devm_ioremap 2-3 29235 NULL
95378 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
95379 +recover_peb_29238 recover_peb 6-7 29238 NULL
95380 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
95381 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
95382 +i915_gem_execbuffer_relocate_slow_25355 i915_gem_execbuffer_relocate_slow 7 25355 NULL
95383 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
95384 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
95385 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
95386 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
95387 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
95388 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
95389 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
95390 +ppp_tx_cp_62044 ppp_tx_cp 5 62044 NULL
95391 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
95392 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
95393 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
95394 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
95395 +do_pselect_62061 do_pselect 1 62061 NULL
95396 +btmrvl_gpiogap_read_4718 btmrvl_gpiogap_read 3 4718 NULL
95397 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
95398 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
95399 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
95400 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
95401 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
95402 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
95403 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
95404 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
95405 +sg_read_25799 sg_read 3 25799 NULL
95406 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
95407 +ci_ll_init_12930 ci_ll_init 3 12930 NULL
95408 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL
95409 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
95410 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
95411 +vmalloc_32_user_37519 vmalloc_32_user 1 37519 NULL
95412 +fd_do_writev_29329 fd_do_writev 3 29329 NULL
95413 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
95414 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
95415 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
95416 +dvb_ca_en50221_init_45718 dvb_ca_en50221_init 4 45718 NULL
95417 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
95418 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
95419 +new_skb_21148 new_skb 1 21148 NULL
95420 +ath6kl_mgmt_tx_21153 ath6kl_mgmt_tx 9 21153 NULL
95421 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
95422 +bm_status_write_12964 bm_status_write 3 12964 NULL
95423 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
95424 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL
95425 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
95426 +ip6_ufo_append_data_4780 ip6_ufo_append_data 5-6-7 4780 NULL
95427 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL nohasharray
95428 +nf_nat_mangle_tcp_packet_37551 nf_nat_mangle_tcp_packet 6-8 37551 &sep_create_dcb_dmatables_context_37551
95429 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
95430 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3 45748 NULL nohasharray
95431 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
95432 +qib_diag_write_62133 qib_diag_write 3 62133 NULL
95433 +gnttab_expand_15817 gnttab_expand 1 15817 NULL
95434 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
95435 +sctp_make_chunk_12986 sctp_make_chunk 4 12986 NULL
95436 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
95437 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
95438 +mthca_setup_cmd_doorbells_53954 mthca_setup_cmd_doorbells 2 53954 NULL
95439 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
95440 +video_usercopy_62151 video_usercopy 2 62151 NULL
95441 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
95442 +repair_io_failure_4815 repair_io_failure 4 4815 NULL
95443 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
95444 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
95445 +bnx2i_send_nl_mesg_53353 bnx2i_send_nl_mesg 4 53353 NULL
95446 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
95447 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
95448 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
95449 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 NULL
95450 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
95451 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
95452 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
95453 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
95454 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
95455 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
95456 +input_ff_create_21240 input_ff_create 2 21240 NULL
95457 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
95458 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
95459 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL
95460 +amthi_read_45831 amthi_read 4 45831 NULL
95461 +cmpk_message_handle_tx_54024 cmpk_message_handle_tx 4 54024 NULL
95462 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
95463 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
95464 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
95465 +sys_ipc_4889 sys_ipc 3 4889 NULL
95466 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
95467 +smp_build_cmd_45853 smp_build_cmd 3 45853 NULL
95468 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
95469 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
95470 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
95471 +do_register_entry_29478 do_register_entry 4 29478 NULL
95472 +isdn_write_45863 isdn_write 3 45863 NULL
95473 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
95474 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
95475 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
95476 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
95477 +vmw_gmr2_bind_21305 vmw_gmr2_bind 3 21305 NULL
95478 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
95479 +_malloc_54077 _malloc 1 54077 NULL
95480 +add_res_range_21310 add_res_range 4 21310 NULL
95481 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
95482 +sys_process_vm_writev_4928 sys_process_vm_writev 3-5 4928 NULL
95483 +ntfs_rl_insert_4931 ntfs_rl_insert 2-4 4931 NULL
95484 +ip_make_skb_13129 ip_make_skb 5-6 13129 NULL
95485 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
95486 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
95487 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
95488 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL
95489 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
95490 +create_xattr_54106 create_xattr 5 54106 NULL
95491 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
95492 +ep_write_59008 ep_write 3 59008 NULL
95493 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
95494 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
95495 +devm_kzalloc_4966 devm_kzalloc 2 4966 NULL
95496 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
95497 +udf_sb_alloc_partition_maps_62313 udf_sb_alloc_partition_maps 2 62313 NULL
95498 +alloc_mr_45935 alloc_mr 1 45935 NULL
95499 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
95500 +isku_receive_54130 isku_receive 4 54130 NULL
95501 +hfcpci_empty_bfifo_62323 hfcpci_empty_bfifo 4 62323 NULL
95502 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
95503 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
95504 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
95505 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
95506 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
95507 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
95508 +i915_max_freq_write_11350 i915_max_freq_write 3 11350 NULL
95509 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
95510 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
95511 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
95512 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
95513 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
95514 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
95515 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
95516 +alloc_ldt_21972 alloc_ldt 2 21972 NULL
95517 +ipath_resize_cq_712 ipath_resize_cq 2 712 NULL
95518 +comedi_read_13199 comedi_read 3 13199 NULL
95519 +flash_write_62354 flash_write 3 62354 NULL
95520 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
95521 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
95522 +i2400m_zrealloc_2x_54166 i2400m_zrealloc_2x 3 54166 NULL nohasharray
95523 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 &i2400m_zrealloc_2x_54166
95524 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
95525 +proc_file_read_53905 proc_file_read 3 53905 NULL
95526 +mtd_device_parse_register_5024 mtd_device_parse_register 5 5024 NULL
95527 +acpi_tb_install_table_12988 acpi_tb_install_table 1 12988 NULL
95528 +set_wd_exp_mode_pfs_62372 set_wd_exp_mode_pfs 3 62372 NULL
95529 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
95530 +acpi_os_read_memory_54186 acpi_os_read_memory 1-3 54186 NULL
95531 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
95532 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
95533 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
95534 +cru_detect_11272 cru_detect 1 11272 NULL
95535 +altera_irscan_62396 altera_irscan 2 62396 NULL
95536 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
95537 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
95538 +fw_download_code_13249 fw_download_code 3 13249 NULL
95539 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
95540 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
95541 +set_ssp_62411 set_ssp 4 62411 NULL
95542 +nfc_hci_send_event_21452 nfc_hci_send_event 5 21452 NULL
95543 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
95544 +get_free_entries_46030 get_free_entries 1 46030 NULL
95545 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
95546 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
95547 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
95548 +carl9170_rx_13272 carl9170_rx 3 13272 NULL
95549 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
95550 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 NULL
95551 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
95552 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3 5091 NULL
95553 +netdev_alloc_skb_62437 netdev_alloc_skb 2 62437 NULL
95554 +dma_memcpy_pg_to_iovec_1725 dma_memcpy_pg_to_iovec 6 1725 NULL
95555 +platform_device_add_resources_13289 platform_device_add_resources 3 13289 NULL
95556 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
95557 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
95558 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
95559 +e1000_check_copybreak_62448 e1000_check_copybreak 3 62448 NULL
95560 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
95561 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
95562 +wusb_prf_54261 wusb_prf 7 54261 NULL nohasharray
95563 +audio_write_54261 audio_write 4 54261 &wusb_prf_54261
95564 +sys_setxattr_37880 sys_setxattr 4 37880 NULL
95565 +dvb_net_sec_37884 dvb_net_sec 3 37884 NULL
95566 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
95567 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
95568 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
95569 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
95570 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL nohasharray
95571 +xz_dec_lzma2_create_36353 xz_dec_lzma2_create 2 36353 &v9fs_file_readn_36353
95572 +vfio_config_do_rw_46091 vfio_config_do_rw 3 46091 NULL
95573 +dma_skb_copy_datagram_iovec_21516 dma_skb_copy_datagram_iovec 3-5 21516 NULL
95574 +ata_host_alloc_46094 ata_host_alloc 2 46094 NULL
95575 +probes_write_29711 probes_write 3 29711 NULL
95576 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
95577 +us122l_ctl_msg_13330 us122l_ctl_msg 8 13330 NULL
95578 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
95579 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
95580 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
95581 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
95582 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL
95583 +tipc_link_send_sections_fast_37920 tipc_link_send_sections_fast 4 37920 NULL
95584 +mlx4_en_create_rx_ring_62498 mlx4_en_create_rx_ring 3 62498 NULL
95585 +emi62_writememory_29731 emi62_writememory 4 29731 NULL
95586 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
95587 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
95588 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL
95589 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
95590 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
95591 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
95592 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
95593 +pn_raw_send_54330 pn_raw_send 2 54330 NULL
95594 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
95595 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
95596 +sfi_map_memory_5183 sfi_map_memory 1-2 5183 NULL
95597 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
95598 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
95599 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
95600 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
95601 +ddp_clear_map_46152 ddp_clear_map 4 46152 NULL
95602 +cxio_hal_init_resource_29771 cxio_hal_init_resource 2-6-7 29771 NULL nohasharray
95603 +ip_vs_conn_fill_param_sync_29771 ip_vs_conn_fill_param_sync 6 29771 &cxio_hal_init_resource_29771
95604 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
95605 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
95606 +_osd_realloc_seg_54352 _osd_realloc_seg 3 54352 NULL
95607 +pipe_set_size_5204 pipe_set_size 2 5204 NULL
95608 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
95609 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
95610 +isdn_read_50021 isdn_read 3 50021 NULL
95611 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
95612 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
95613 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
95614 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
95615 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
95616 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
95617 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
95618 +ssb_ioremap_5228 ssb_ioremap 2 5228 NULL
95619 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
95620 +xlog_do_recovery_pass_21618 xlog_do_recovery_pass 3 21618 NULL
95621 +isdn_ppp_skb_push_5236 isdn_ppp_skb_push 2 5236 NULL
95622 +get_subdir_62581 get_subdir 3 62581 NULL
95623 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
95624 +sctp_abort_pkt_new_5241 sctp_abort_pkt_new 6 5241 NULL
95625 +vfs_readv_38011 vfs_readv 3 38011 NULL
95626 +keyring_read_13438 keyring_read 3 13438 NULL
95627 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL nohasharray
95628 +set_tap_pwup_pfs_13440 set_tap_pwup_pfs 3 13440 &sctp_setsockopt_peer_primary_addr_13440
95629 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 7-8-9 13443 NULL
95630 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
95631 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
95632 +packet_alloc_skb_62602 packet_alloc_skb 2-5-4 62602 NULL
95633 +prism2_send_mgmt_62605 prism2_send_mgmt 4 62605 NULL nohasharray
95634 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 &prism2_send_mgmt_62605
95635 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
95636 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
95637 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
95638 +ftrace_write_29551 ftrace_write 3 29551 NULL
95639 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL
95640 +iscsi_post_host_event_13473 iscsi_post_host_event 4 13473 NULL
95641 +ems_pcmcia_add_card_62627 ems_pcmcia_add_card 2 62627 NULL
95642 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
95643 +dev_write_7708 dev_write 3 7708 NULL
95644 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
95645 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
95646 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
95647 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
95648 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
95649 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
95650 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
95651 +nf_nat_ftp_46265 nf_nat_ftp 6 46265 NULL
95652 +nfc_targets_found_29886 nfc_targets_found 3 29886 NULL
95653 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
95654 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
95655 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
95656 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
95657 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
95658 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
95659 +bm_init_13529 bm_init 2 13529 NULL
95660 +check586_29914 check586 2 29914 NULL
95661 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
95662 +pep_alloc_skb_46303 pep_alloc_skb 3 46303 NULL
95663 +reiserfs_allocate_list_bitmaps_21732 reiserfs_allocate_list_bitmaps 3 21732 NULL
95664 +ioremap_wc_62695 ioremap_wc 1-2 62695 NULL
95665 +pg_read_17276 pg_read 3 17276 NULL
95666 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
95667 +ep0_read_38095 ep0_read 3 38095 NULL
95668 +batadv_iv_ogm_queue_add_46319 batadv_iv_ogm_queue_add 3 46319 NULL
95669 +__nf_nat_mangle_tcp_packet_21744 __nf_nat_mangle_tcp_packet 8-6 21744 NULL
95670 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
95671 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
95672 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
95673 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
95674 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
95675 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
95676 +l2down_create_21755 l2down_create 4 21755 NULL
95677 +alloc_tio_13564 alloc_tio 3 13564 NULL
95678 +viacam_read_54526 viacam_read 3 54526 NULL
95679 +btrfs_mksubvol_58240 btrfs_mksubvol 3 58240 NULL
95680 +tunables_read_36385 tunables_read 3 36385 NULL
95681 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
95682 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
95683 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
95684 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 3-4 38153 NULL
95685 +setsockopt_54539 setsockopt 5 54539 NULL
95686 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
95687 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
95688 +tty_register_device_4544 tty_register_device 2 4544 NULL
95689 +cache_write_13589 cache_write 3 13589 NULL
95690 +mpt_lan_receive_post_turbo_13592 mpt_lan_receive_post_turbo 2 13592 NULL
95691 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
95692 +key_replays_read_62746 key_replays_read 3 62746 NULL
95693 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
95694 +aac_sa_ioremap_13596 aac_sa_ioremap 2 13596 NULL nohasharray
95695 +irias_new_octseq_value_13596 irias_new_octseq_value 2 13596 &aac_sa_ioremap_13596
95696 +mwifiex_usb_submit_rx_urb_54558 mwifiex_usb_submit_rx_urb 2 54558 NULL
95697 +irias_add_octseq_attrib_29983 irias_add_octseq_attrib 4 29983 NULL
95698 +cdev_add_38176 cdev_add 2-3 38176 NULL
95699 +brcmf_sdcard_recv_buf_38179 brcmf_sdcard_recv_buf 6 38179 NULL
95700 +__ioremap_caller_21800 __ioremap_caller 1-2 21800 NULL
95701 +alloc_and_copy_ftrace_hash_29368 alloc_and_copy_ftrace_hash 1 29368 NULL
95702 +ubi_dump_flash_46381 ubi_dump_flash 4 46381 NULL
95703 +swap_cgroup_swapon_13614 swap_cgroup_swapon 2 13614 NULL
95704 +wm8994_bulk_write_13615 wm8994_bulk_write 3 13615 NULL
95705 +init_chip_wc_pat_62768 init_chip_wc_pat 2 62768 NULL
95706 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
95707 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
95708 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
95709 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
95710 +vmalloc_user_32308 vmalloc_user 1 32308 NULL
95711 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
95712 +ath6kl_wmi_startscan_cmd_33674 ath6kl_wmi_startscan_cmd 8 33674 NULL
95713 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
95714 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 NULL
95715 +packet_snd_13634 packet_snd 3 13634 NULL
95716 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
95717 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
95718 +sfi_map_table_5462 sfi_map_table 1 5462 NULL
95719 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
95720 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
95721 +fwSendNullPacket_54618 fwSendNullPacket 2 54618 NULL
95722 +drp_wmove_30043 drp_wmove 4 30043 NULL
95723 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
95724 +cache_downcall_13666 cache_downcall 3 13666 NULL
95725 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
95726 +ubi_leb_write_5478 ubi_leb_write 4-5 5478 NULL
95727 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
95728 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
95729 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
95730 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
95731 +tty_write_5494 tty_write 3 5494 NULL
95732 +iscsi_ping_comp_event_38263 iscsi_ping_comp_event 5 38263 NULL
95733 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL
95734 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
95735 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
95736 +teiup_create_43201 teiup_create 3 43201 NULL
95737 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
95738 +filldir64_46469 filldir64 3 46469 NULL
95739 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL nohasharray
95740 +set_dis_disc_pfs_28225 set_dis_disc_pfs 3 28225 &line6_alloc_sysex_buffer_28225
95741 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
95742 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
95743 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
95744 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
95745 +tg3_run_loopback_30093 tg3_run_loopback 2 30093 NULL
95746 +spidev_message_5518 spidev_message 3 5518 NULL
95747 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
95748 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
95749 +ezusb_writememory_45976 ezusb_writememory 4 45976 NULL
95750 +evm_read_key_54674 evm_read_key 3 54674 NULL
95751 +sctp_make_op_error_space_5528 sctp_make_op_error_space 3 5528 NULL
95752 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
95753 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
95754 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
95755 +em28xx_init_isoc_62883 em28xx_init_isoc 4 62883 NULL nohasharray
95756 +aoechr_write_62883 aoechr_write 3 62883 &em28xx_init_isoc_62883
95757 +resize_info_buffer_62889 resize_info_buffer 2 62889 NULL
95758 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
95759 +u32_array_read_2219 u32_array_read 3 2219 NULL
95760 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
95761 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
95762 +sys_add_key_61288 sys_add_key 4 61288 NULL
95763 +kmsg_read_46514 kmsg_read 3 46514 NULL
95764 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
95765 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
95766 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
95767 +recv_stream_30138 recv_stream 4 30138 NULL
95768 +u_memcpya_30139 u_memcpya 2-3 30139 NULL
95769 +getdqbuf_62908 getdqbuf 1 62908 NULL
95770 +bdx_rxdb_create_46525 bdx_rxdb_create 1 46525 NULL
95771 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
95772 +_add_sg_continuation_descriptor_54721 _add_sg_continuation_descriptor 3 54721 NULL
95773 +fc_frame_alloc_fill_59394 fc_frame_alloc_fill 2 59394 NULL
95774 +fir16_create_5574 fir16_create 3 5574 NULL
95775 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
95776 +pt_write_40159 pt_write 3 40159 NULL
95777 +bioset_create_5580 bioset_create 1 5580 NULL
95778 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
95779 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
95780 +oz_ep_alloc_5587 oz_ep_alloc 2 5587 NULL
95781 +kzalloc_54740 kzalloc 1 54740 NULL
95782 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 NULL nohasharray
95783 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 &ipath_reg_phys_mr_23918
95784 +do_msgrcv_5590 do_msgrcv 4 5590 NULL
95785 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
95786 +link_send_sections_long_46556 link_send_sections_long 4 46556 NULL
95787 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
95788 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
95789 +batadv_iv_ogm_aggregate_new_54761 batadv_iv_ogm_aggregate_new 2 54761 NULL
95790 +ldm_frag_add_5611 ldm_frag_add 2 5611 NULL
95791 +cx25821_video_ioctl_30188 cx25821_video_ioctl 2 30188 NULL
95792 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
95793 +rxpipe_descr_host_int_trig_rx_data_read_22001 rxpipe_descr_host_int_trig_rx_data_read 3 22001 NULL nohasharray
95794 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 3 22001 &rxpipe_descr_host_int_trig_rx_data_read_22001
95795 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
95796 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
95797 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
95798 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
95799 +hidp_output_raw_report_5629 hidp_output_raw_report 3 5629 NULL
95800 +nfs_idmap_request_key_30208 nfs_idmap_request_key 3 30208 NULL
95801 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
95802 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
95803 +snd_ac97_pcm_assign_30218 snd_ac97_pcm_assign 2 30218 NULL
95804 +ti_recv_22027 ti_recv 4 22027 NULL
95805 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2 34135 NULL
95806 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
95807 +nfsd_write_54809 nfsd_write 6 54809 NULL
95808 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
95809 +pcnet32_realloc_tx_ring_38428 pcnet32_realloc_tx_ring 3 38428 NULL
95810 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
95811 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
95812 +get_skb_63008 get_skb 2 63008 NULL
95813 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
95814 +netlink_send_38434 netlink_send 5 38434 NULL
95815 +atalk_recvmsg_22053 atalk_recvmsg 4 22053 NULL
95816 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL nohasharray
95817 +alloc_trace_uprobe_13870 alloc_trace_uprobe 3 13870 &compat_ip_setsockopt_13870
95818 +aircable_process_packet_46639 aircable_process_packet 5 46639 NULL
95819 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
95820 +write_rio_54837 write_rio 3 54837 NULL
95821 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 NULL
95822 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
95823 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
95824 +get_arg_5694 get_arg 3 5694 NULL
95825 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
95826 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
95827 +compat_readv_30273 compat_readv 3 30273 NULL
95828 +printer_read_54851 printer_read 3 54851 NULL
95829 +mem_rw_22085 mem_rw 3 22085 NULL
95830 +i915_min_freq_read_38470 i915_min_freq_read 3 38470 NULL
95831 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
95832 +lowpan_fragment_xmit_22095 lowpan_fragment_xmit 3-4 22095 NULL
95833 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
95834 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
95835 +unlink1_63059 unlink1 3 63059 NULL
95836 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 NULL
95837 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
95838 +__do_krealloc_54389 __do_krealloc 2 54389 NULL
95839 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
95840 +tcf_csum_ipv6_tcp_54877 tcf_csum_ipv6_tcp 4 54877 NULL
95841 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
95842 +replay_log_leb_18704 replay_log_leb 3 18704 NULL
95843 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
95844 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
95845 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
95846 +dev_names_read_38509 dev_names_read 3 38509 NULL
95847 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
95848 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 NULL
95849 +get_packet_5747 get_packet 3 5747 NULL
95850 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL
95851 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
95852 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
95853 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
95854 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
95855 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
95856 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
95857 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
95858 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
95859 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL
95860 +_l2_alloc_skb_11883 _l2_alloc_skb 1 11883 NULL
95861 +resource_from_user_30341 resource_from_user 3 30341 NULL
95862 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
95863 +sound_write_5102 sound_write 3 5102 NULL
95864 +pn533_dep_link_up_22154 pn533_dep_link_up 5 22154 NULL
95865 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
95866 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
95867 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
95868 +__vmalloc_node_flags_30352 __vmalloc_node_flags 1 30352 NULL
95869 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
95870 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
95871 +com90xx_found_13974 com90xx_found 3 13974 NULL
95872 +compat_sys_writev_5784 compat_sys_writev 3 5784 NULL
95873 +qcam_read_13977 qcam_read 3 13977 NULL
95874 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
95875 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
95876 +virtblk_add_buf_wait_54943 virtblk_add_buf_wait 3-4 54943 NULL
95877 +wl12xx_cmd_build_probe_req_54946 wl12xx_cmd_build_probe_req 6-8 54946 NULL
95878 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
95879 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
95880 +generic_readlink_32654 generic_readlink 3 32654 NULL
95881 +ieee80211_bss_info_update_13991 ieee80211_bss_info_update 4 13991 NULL
95882 +sys_get_mempolicy_30379 sys_get_mempolicy 3 30379 NULL
95883 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
95884 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
95885 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
95886 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL
95887 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
95888 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
95889 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
95890 +__proc_file_read_54978 __proc_file_read 3 54978 NULL
95891 +concat_writev_21451 concat_writev 3 21451 NULL
95892 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
95893 +_queue_data_54983 _queue_data 4 54983 NULL
95894 +_sys_packet_req_46793 _sys_packet_req 4 46793 NULL
95895 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
95896 +extend_netdev_table_21453 extend_netdev_table 2 21453 NULL
95897 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
95898 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
95899 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
95900 +ixgb_check_copybreak_5847 ixgb_check_copybreak 3 5847 NULL
95901 +setup_req_5848 setup_req 3 5848 NULL
95902 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
95903 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
95904 +rds_ib_inc_copy_to_user_55007 rds_ib_inc_copy_to_user 3 55007 NULL
95905 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
95906 +rbd_create_rw_ops_55297 rbd_create_rw_ops 1 55297 NULL
95907 +compat_sys_move_pages_5861 compat_sys_move_pages 2 5861 NULL
95908 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
95909 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
95910 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
95911 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
95912 +cma_create_area_38642 cma_create_area 2 38642 NULL
95913 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
95914 +sriov_enable_59689 sriov_enable 2 59689 NULL
95915 +enable_write_30456 enable_write 3 30456 NULL
95916 +shmem_pwrite_fast_46842 shmem_pwrite_fast 3 46842 NULL
95917 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
95918 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
95919 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
95920 +tcp_manip_pkt_16563 tcp_manip_pkt 4 16563 NULL
95921 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
95922 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
95923 +ieee80211_mgmt_tx_46860 ieee80211_mgmt_tx 9 46860 NULL
95924 +port_show_regs_5904 port_show_regs 3 5904 NULL
95925 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
95926 +ptp_read_63251 ptp_read 4 63251 NULL
95927 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
95928 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
95929 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
95930 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL
95931 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
95932 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
95933 +ttm_bo_kmap_ttm_5922 ttm_bo_kmap_ttm 3 5922 NULL
95934 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
95935 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
95936 +iscsi_iser_recv_41948 iscsi_iser_recv 4 41948 NULL
95937 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
95938 +em28xx_alloc_isoc_46892 em28xx_alloc_isoc 4 46892 NULL
95939 +read_dma_55086 read_dma 3 55086 NULL
95940 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
95941 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
95942 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
95943 +ntfs_rl_replace_14136 ntfs_rl_replace 2-4 14136 NULL
95944 +ip_send_unicast_reply_38714 ip_send_unicast_reply 6 38714 NULL
95945 +tcp_collapse_63294 tcp_collapse 6-5 63294 NULL
95946 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
95947 +isdn_ppp_ccp_xmit_reset_63297 isdn_ppp_ccp_xmit_reset 6 63297 NULL
95948 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
95949 +tipc_subseq_alloc_5957 tipc_subseq_alloc 1 5957 NULL
95950 +em_canid_change_14150 em_canid_change 3 14150 NULL
95951 +tracing_ctrl_read_46922 tracing_ctrl_read 3 46922 NULL
95952 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
95953 +fb_write_46924 fb_write 3 46924 NULL
95954 +btmrvl_curpsmode_read_46939 btmrvl_curpsmode_read 3 46939 NULL
95955 +wlcore_alloc_hw_22365 wlcore_alloc_hw 1 22365 NULL
95956 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
95957 +br_send_bpdu_29669 br_send_bpdu 3 29669 NULL
95958 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
95959 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
95960 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
95961 +udf_readpages_38761 udf_readpages 4 38761 NULL
95962 +reada_add_block_54247 reada_add_block 2 54247 NULL
95963 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
95964 +proc_info_read_63344 proc_info_read 3 63344 NULL
95965 +pep_indicate_38611 pep_indicate 5 38611 NULL
95966 +set_le_30581 set_le 4 30581 NULL
95967 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
95968 +btmrvl_psmode_read_22395 btmrvl_psmode_read 3 22395 NULL
95969 +alloc_private_22399 alloc_private 2 22399 NULL
95970 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
95971 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
95972 +zoran_write_22404 zoran_write 3 22404 NULL
95973 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 NULL
95974 +idmouse_read_63374 idmouse_read 3 63374 NULL
95975 +queue_reply_22416 queue_reply 3 22416 NULL
95976 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL
95977 +sel_write_bool_46996 sel_write_bool 3 46996 NULL
95978 +ntfs_rl_append_6037 ntfs_rl_append 2-4 6037 NULL
95979 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
95980 +ttm_bo_io_47000 ttm_bo_io 5 47000 NULL
95981 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
95982 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
95983 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 NULL
95984 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
95985 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
95986 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4-2 14244 NULL
95987 +snd_soc_hw_bulk_write_raw_14245 snd_soc_hw_bulk_write_raw 4 14245 NULL
95988 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL nohasharray
95989 +isdn_net_ciscohdlck_alloc_skb_55209 isdn_net_ciscohdlck_alloc_skb 2 55209 &ht40allow_map_read_55209
95990 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
95991 +sys_select_38827 sys_select 1 38827 NULL
95992 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
95993 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
95994 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2 47024 NULL
95995 +direct_entry_38836 direct_entry 3 38836 NULL
95996 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
95997 +gntdev_alloc_map_35145 gntdev_alloc_map 2 35145 NULL
95998 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
95999 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
96000 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
96001 +write_head_30481 write_head 4 30481 NULL
96002 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
96003 +set_dis_bypass_pfs_47038 set_dis_bypass_pfs 3 47038 NULL
96004 +add_numbered_child_14273 add_numbered_child 5 14273 NULL
96005 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
96006 +OS_mem_token_alloc_14276 OS_mem_token_alloc 1 14276 NULL
96007 +sep_prepare_input_output_dma_table_63429 sep_prepare_input_output_dma_table 2-4-3 63429 NULL
96008 +register_unifi_sdio_55239 register_unifi_sdio 2 55239 NULL
96009 +ath6kl_wmi_get_new_buf_52304 ath6kl_wmi_get_new_buf 1 52304 NULL
96010 +agp_remap_30665 agp_remap 2 30665 NULL
96011 +interfaces_38859 interfaces 2 38859 NULL
96012 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
96013 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
96014 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
96015 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
96016 +qc_capture_19298 qc_capture 3 19298 NULL
96017 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
96018 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
96019 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
96020 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
96021 +rtl_port_map_2385 rtl_port_map 1-2 2385 NULL
96022 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
96023 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
96024 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
96025 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
96026 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
96027 +process_bulk_data_command_38906 process_bulk_data_command 4 38906 NULL
96028 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
96029 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
96030 +read_kcore_63488 read_kcore 3 63488 NULL
96031 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
96032 +__skb_cow_39254 __skb_cow 2 39254 NULL
96033 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
96034 +__get_vm_area_node_55305 __get_vm_area_node 1 55305 NULL
96035 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
96036 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
96037 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
96038 +pskb_may_pull_22546 pskb_may_pull 2 22546 NULL
96039 +mousedev_read_47123 mousedev_read 3 47123 NULL
96040 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
96041 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
96042 +vdma_mem_alloc_6171 vdma_mem_alloc 1 6171 NULL
96043 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
96044 +ses_recv_diag_47143 ses_recv_diag 4 47143 NULL nohasharray
96045 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 &ses_recv_diag_47143
96046 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
96047 +vme_user_read_55338 vme_user_read 3 55338 NULL
96048 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 NULL
96049 +cxio_init_resource_fifo_random_47151 cxio_init_resource_fifo_random 3 47151 NULL
96050 +persistent_ram_iomap_47156 persistent_ram_iomap 1-2 47156 NULL
96051 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
96052 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
96053 +__hidp_send_ctrl_message_28303 __hidp_send_ctrl_message 4 28303 NULL
96054 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
96055 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
96056 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
96057 +acpi_system_read_event_55362 acpi_system_read_event 3 55362 NULL
96058 +dbg_leb_write_63555 dbg_leb_write 4-5 63555 NULL nohasharray
96059 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 &dbg_leb_write_63555
96060 +snapshot_read_22601 snapshot_read 3 22601 NULL
96061 +OSDSetBlock_38986 OSDSetBlock 4-2 38986 NULL
96062 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
96063 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
96064 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
96065 +ioremap_cache_47189 ioremap_cache 1-2 47189 NULL
96066 +__send_to_port_55383 __send_to_port 3 55383 NULL
96067 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
96068 +nf_nat_ipv4_manip_pkt_55387 nf_nat_ipv4_manip_pkt 2 55387 NULL
96069 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
96070 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
96071 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
96072 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
96073 +get_nodes_39012 get_nodes 3 39012 NULL
96074 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
96075 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
96076 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
96077 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
96078 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
96079 +create_subvol_30836 create_subvol 4 30836 NULL
96080 +mthca_map_reg_5664 mthca_map_reg 2-3 5664 NULL
96081 +ci13xxx_add_device_14456 ci13xxx_add_device 3 14456 NULL
96082 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
96083 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
96084 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
96085 +read_oldmem_55658 read_oldmem 3 55658 NULL
96086 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
96087 +xenbus_file_write_6282 xenbus_file_write 3 6282 NULL
96088 +options_write_47243 options_write 3 47243 NULL
96089 +module_alloc_63630 module_alloc 1 63630 NULL
96090 +alloc_skb_55439 alloc_skb 1 55439 NULL
96091 +nf_nat_ipv6_manip_pkt_6289 nf_nat_ipv6_manip_pkt 2 6289 NULL
96092 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
96093 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
96094 +ubifs_leb_write_22679 ubifs_leb_write 4-5 22679 NULL
96095 +nf_nat_sack_adjust_6297 nf_nat_sack_adjust 2 6297 NULL
96096 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
96097 +mid_get_vbt_data_r10_6308 mid_get_vbt_data_r10 2 6308 NULL
96098 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
96099 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
96100 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
96101 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
96102 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
96103 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
96104 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
96105 +tty_audit_log_47280 tty_audit_log 8 47280 NULL
96106 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
96107 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
96108 +fc_host_post_vendor_event_30903 fc_host_post_vendor_event 3 30903 NULL
96109 +vbi_read_63673 vbi_read 3 63673 NULL
96110 +tun_get_user_39099 tun_get_user 4 39099 NULL
96111 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
96112 +alloc_tty_driver_63681 alloc_tty_driver 1 63681 NULL
96113 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
96114 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
96115 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
96116 +nfc_hci_hcp_message_tx_14534 nfc_hci_hcp_message_tx 6 14534 NULL
96117 +iommu_map_mmio_space_30919 iommu_map_mmio_space 1 30919 NULL
96118 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
96119 +dataflash_read_user_otp_14536 dataflash_read_user_otp 2-3 14536 &ep0_write_14536
96120 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 2-3-5 4303 NULL
96121 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4 22735 NULL
96122 +ax25_output_22736 ax25_output 2 22736 NULL
96123 +__kfifo_to_user_r_39123 __kfifo_to_user_r 3 39123 NULL
96124 +l2cap_send_cmd_14548 l2cap_send_cmd 4 14548 NULL
96125 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
96126 +drm_vmalloc_dma_14550 drm_vmalloc_dma 1 14550 NULL
96127 +cfpkt_pad_trail_55511 cfpkt_pad_trail 2 55511 NULL nohasharray
96128 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 &cfpkt_pad_trail_55511
96129 +cmtp_add_msgpart_9252 cmtp_add_msgpart 4 9252 NULL
96130 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
96131 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
96132 +hid_input_report_32458 hid_input_report 4 32458 NULL
96133 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
96134 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
96135 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
96136 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
96137 +alloc_ring_39151 alloc_ring 2-4 39151 NULL
96138 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
96139 +create_bounce_buffer_39155 create_bounce_buffer 3 39155 NULL
96140 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
96141 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
96142 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
96143 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
96144 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
96145 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
96146 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
96147 +bt_skb_alloc_6404 bt_skb_alloc 1 6404 NULL
96148 +get_info_55681 get_info 3 55681 NULL
96149 +setkey_14987 setkey 3 14987 NULL
96150 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
96151 +init_list_set_39188 init_list_set 2-3 39188 NULL
96152 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
96153 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
96154 +l2up_create_6430 l2up_create 3 6430 NULL
96155 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
96156 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
96157 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
96158 +add_partition_55588 add_partition 2 55588 NULL
96159 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
96160 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
96161 +depth_read_31112 depth_read 3 31112 NULL
96162 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
96163 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
96164 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
96165 +profile_replace_14652 profile_replace 3 14652 NULL
96166 +vzalloc_47421 vzalloc 1 47421 NULL
96167 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
96168 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
96169 +sys_writev_28384 sys_writev 3 28384 NULL
96170 +batadv_tt_response_fill_table_39236 batadv_tt_response_fill_table 1 39236 NULL
96171 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
96172 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4 44769 NULL
96173 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
96174 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL
96175 +create_attr_set_22861 create_attr_set 1 22861 NULL
96176 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
96177 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
96178 +compat_sys_mq_timedsend_31060 compat_sys_mq_timedsend 3 31060 NULL
96179 +sel_write_load_63830 sel_write_load 3 63830 NULL
96180 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
96181 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
96182 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
96183 +dvb_dmxdev_set_buffer_size_55643 dvb_dmxdev_set_buffer_size 2 55643 NULL
96184 +tsi148_master_set_14685 tsi148_master_set 4 14685 NULL
96185 +ath6kl_wmi_set_appie_cmd_39266 ath6kl_wmi_set_appie_cmd 5 39266 NULL
96186 +probe_bios_17467 probe_bios 1 17467 NULL
96187 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
96188 +ttm_bo_ioremap_31082 ttm_bo_ioremap 2-3 31082 NULL
96189 +mei_read_6507 mei_read 3 6507 NULL
96190 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
96191 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
96192 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
96193 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
96194 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
96195 +SetArea_50835 SetArea 4 50835 NULL
96196 +tpm_read_50344 tpm_read 3 50344 NULL
96197 +newpart_47485 newpart 6 47485 NULL
96198 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
96199 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
96200 +core_sys_select_47494 core_sys_select 1 47494 NULL
96201 +read_file_disable_ani_6536 read_file_disable_ani 3 6536 NULL
96202 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
96203 +__vmalloc_node_39308 __vmalloc_node 1 39308 NULL
96204 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
96205 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
96206 +unlink_simple_47506 unlink_simple 3 47506 NULL
96207 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
96208 +wdm_read_6549 wdm_read 3 6549 NULL
96209 +init_map_ipmac_63896 init_map_ipmac 4-3 63896 NULL
96210 +tipc_multicast_49144 tipc_multicast 5 49144 NULL
96211 +nfs4_realloc_slot_table_22859 nfs4_realloc_slot_table 2 22859 NULL
96212 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
96213 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
96214 +__videobuf_alloc_uncached_55711 __videobuf_alloc_uncached 1 55711 NULL
96215 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
96216 +nfc_hci_send_cmd_55714 nfc_hci_send_cmd 5 55714 NULL
96217 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
96218 +filter_read_61692 filter_read 3 61692 NULL
96219 +mtdswap_init_55719 mtdswap_init 2 55719 NULL
96220 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
96221 +debugfs_read_62535 debugfs_read 3 62535 NULL
96222 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
96223 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL
96224 +divas_write_63901 divas_write 3 63901 NULL
96225 +alloc_sglist_22960 alloc_sglist 1-2-3 22960 NULL
96226 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
96227 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
96228 +cfpkt_split_47541 cfpkt_split 2 47541 NULL
96229 +__copy_from_user_nocache_39351 __copy_from_user_nocache 3 39351 NULL
96230 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
96231 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 3-2 55738 NULL
96232 +ipw_write_59807 ipw_write 3 59807 NULL
96233 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
96234 +tipc_send2port_63935 tipc_send2port 5 63935 NULL
96235 +do_write_log_from_user_39362 do_write_log_from_user 3 39362 NULL
96236 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
96237 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
96238 +mwifiex_cfg80211_mgmt_tx_12022 mwifiex_cfg80211_mgmt_tx 9 12022 NULL
96239 +cycx_setup_47562 cycx_setup 4 47562 NULL
96240 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
96241 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
96242 +set_local_name_55757 set_local_name 4 55757 NULL
96243 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
96244 +btrfs_init_new_buffer_55761 btrfs_init_new_buffer 4 55761 NULL
96245 +read_ldt_47570 read_ldt 2 47570 NULL
96246 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
96247 +pci_iomap_47575 pci_iomap 3 47575 NULL
96248 +acpi_ex_system_memory_space_handler_31192 acpi_ex_system_memory_space_handler 2 31192 NULL
96249 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
96250 +module_alloc_update_bounds_rw_63233 module_alloc_update_bounds_rw 1 63233 NULL
96251 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
96252 +drm_ht_create_18853 drm_ht_create 2 18853 NULL
96253 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
96254 +qlcnic_alloc_msix_entries_46160 qlcnic_alloc_msix_entries 2 46160 NULL
96255 +ieee80211_authentication_req_63973 ieee80211_authentication_req 3 63973 NULL
96256 +dn_alloc_skb_6631 dn_alloc_skb 2 6631 NULL
96257 +conf_read_55786 conf_read 3 55786 NULL
96258 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
96259 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
96260 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
96261 +virtscsi_alloc_tgt_6643 virtscsi_alloc_tgt 2 6643 NULL
96262 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
96263 +user_power_read_39414 user_power_read 3 39414 NULL
96264 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
96265 +uea_request_47613 uea_request 4 47613 NULL
96266 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
96267 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
96268 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
96269 +btrfs_find_create_tree_block_55812 btrfs_find_create_tree_block 3 55812 NULL
96270 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
96271 +lcd_write_14857 lcd_write 3 14857 NULL nohasharray
96272 +__krealloc_14857 __krealloc 2 14857 &lcd_write_14857
96273 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
96274 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
96275 +kmemdup_64015 kmemdup 2 64015 NULL
96276 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
96277 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
96278 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
96279 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
96280 +tcf_csum_skb_nextlayer_64025 tcf_csum_skb_nextlayer 3 64025 NULL
96281 +oz_events_read_47535 oz_events_read 3 47535 NULL
96282 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
96283 +resize_async_buffer_64031 resize_async_buffer 4 64031 NULL
96284 +sys_semop_39457 sys_semop 3 39457 NULL
96285 +vm_map_ram_23078 vm_map_ram 2 23078 NULL nohasharray
96286 +raw_sendmsg_23078 raw_sendmsg 4 23078 &vm_map_ram_23078
96287 +update_pmkid_2481 update_pmkid 4 2481 NULL
96288 +sriov_enable_migration_14889 sriov_enable_migration 2 14889 NULL
96289 +sep_lli_table_secure_dma_64042 sep_lli_table_secure_dma 2-3 64042 NULL
96290 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
96291 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
96292 +hysdn_rx_netpkt_16136 hysdn_rx_netpkt 3 16136 NULL
96293 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
96294 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
96295 +mpeg_read_6708 mpeg_read 3 6708 NULL
96296 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
96297 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
96298 +sky2_receive_13407 sky2_receive 2 13407 NULL
96299 +krealloc_14908 krealloc 2 14908 NULL
96300 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
96301 +bt_skb_send_alloc_6581 bt_skb_send_alloc 2 6581 NULL
96302 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
96303 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
96304 +video_proc_write_6724 video_proc_write 3 6724 NULL
96305 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
96306 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
96307 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
96308 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
96309 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
96310 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
96311 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
96312 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL
96313 +command_file_write_31318 command_file_write 3 31318 NULL
96314 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
96315 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
96316 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
96317 +i915_cache_sharing_read_24775 i915_cache_sharing_read 3 24775 NULL
96318 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
96319 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
96320 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
96321 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
96322 +ca91cx42_master_set_23146 ca91cx42_master_set 4 23146 NULL
96323 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
96324 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
96325 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
96326 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
96327 +sfi_check_table_6772 sfi_check_table 1 6772 NULL
96328 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
96329 +int_proc_write_39542 int_proc_write 3 39542 NULL
96330 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
96331 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
96332 +read_file_ani_23161 read_file_ani 3 23161 NULL
96333 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
96334 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
96335 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
96336 +pp_write_39554 pp_write 3 39554 NULL
96337 +ioremap_23172 ioremap 1-2 23172 NULL
96338 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
96339 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
96340 +usblp_write_23178 usblp_write 3 23178 NULL
96341 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
96342 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
96343 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3 31374 NULL
96344 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
96345 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
96346 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
96347 +fix_unclean_leb_23188 fix_unclean_leb 3 23188 NULL
96348 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
96349 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
96350 +vmalloc_32_1135 vmalloc_32 1 1135 NULL
96351 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
96352 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
96353 +__team_options_register_63941 __team_options_register 3 63941 NULL
96354 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
96355 +ip_ufo_append_data_12775 ip_ufo_append_data 6-7-8 12775 NULL
96356 +rvmalloc_46873 rvmalloc 1 46873 NULL
96357 +vmap_15025 vmap 2 15025 NULL
96358 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
96359 +mcs7830_set_reg_31413 mcs7830_set_reg 3 31413 NULL
96360 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
96361 +tty_buffer_request_room_23228 tty_buffer_request_room 2 23228 NULL
96362 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL
96363 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
96364 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
96365 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
96366 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
96367 +ttm_object_device_init_10321 ttm_object_device_init 2 10321 NULL
96368 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
96369 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
96370 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL
96371 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
96372 +ssb_bus_pcmciabus_register_56020 ssb_bus_pcmciabus_register 3 56020 NULL
96373 +fm_send_cmd_39639 fm_send_cmd 5 39639 NULL
96374 +ip6gre_err_19869 ip6gre_err 5 19869 NULL
96375 +nvme_alloc_iod_56027 nvme_alloc_iod 1 56027 NULL
96376 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
96377 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
96378 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5 15072 NULL
96379 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
96380 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
96381 +get_new_cssid_51665 get_new_cssid 2 51665 NULL
96382 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL
96383 +prism2_info_hostscanresults_39657 prism2_info_hostscanresults 3 39657 NULL
96384 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
96385 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
96386 +__videobuf_alloc_vb_5665 __videobuf_alloc_vb 1 5665 NULL
96387 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
96388 +redrat3_transmit_ir_64244 redrat3_transmit_ir 3 64244 NULL
96389 +__alloc_extent_buffer_15093 __alloc_extent_buffer 3 15093 NULL
96390 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
96391 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
96392 +alg_setkey_31485 alg_setkey 3 31485 NULL
96393 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
96394 +spi_show_regs_6911 spi_show_regs 3 6911 NULL nohasharray
96395 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 &spi_show_regs_6911
96396 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
96397 +vhci_read_47878 vhci_read 3 47878 NULL
96398 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
96399 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
96400 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
96401 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
96402 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
96403 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
96404 +event_id_read_64288 event_id_read 3 64288 NULL nohasharray
96405 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 &event_id_read_64288
96406 +osd_req_read_sg_47905 osd_req_read_sg 5 47905 NULL
96407 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
96408 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
96409 +timeout_read_47915 timeout_read 3 47915 NULL
96410 +hidraw_write_31536 hidraw_write 3 31536 NULL
96411 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
96412 +page_readlink_23346 page_readlink 3 23346 NULL
96413 +videobuf_dma_init_kernel_6963 videobuf_dma_init_kernel 3 6963 NULL
96414 +comedi_write_47926 comedi_write 3 47926 NULL
96415 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
96416 +dsp_write_46218 dsp_write 2 46218 NULL
96417 +kmem_zalloc_large_56128 kmem_zalloc_large 1 56128 NULL
96418 +usbvision_read_31555 usbvision_read 3 31555 NULL
96419 +pd_video_read_24510 pd_video_read 3 24510 NULL
96420 +crypto_authenc_esn_setkey_6985 crypto_authenc_esn_setkey 3 6985 NULL
96421 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
96422 +request_key_async_6990 request_key_async 4 6990 NULL
96423 +ts_write_64336 ts_write 3 64336 NULL
96424 +handle_response_55951 handle_response 5 55951 NULL
96425 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
96426 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
96427 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
96428 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
96429 +osst_write_31581 osst_write 3 31581 NULL
96430 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
96431 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
96432 +wm8350_block_write_19727 wm8350_block_write 3 19727 NULL
96433 +diva_xdi_write_63975 diva_xdi_write 4 63975 NULL
96434 +llc_alloc_frame_64366 llc_alloc_frame 4 64366 NULL
96435 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 NULL nohasharray
96436 +mempool_resize_47983 mempool_resize 2 47983 &iwl_dbgfs_ucode_tracing_read_47983
96437 +mangle_packet_18920 mangle_packet 7-9 18920 NULL
96438 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
96439 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
96440 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
96441 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
96442 +ilo_write_64378 ilo_write 3 64378 NULL
96443 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
96444 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
96445 +vzalloc_node_23424 vzalloc_node 1 23424 NULL
96446 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
96447 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
96448 +variax_alloc_sysex_buffer_15237 variax_alloc_sysex_buffer 3 15237 NULL
96449 +copy_from_user_17559 copy_from_user 3 17559 NULL
96450 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
96451 +sys_migrate_pages_39825 sys_migrate_pages 2 39825 NULL
96452 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
96453 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
96454 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
96455 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
96456 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
96457 +beiscsi_process_async_pdu_39834 beiscsi_process_async_pdu 7 39834 NULL
96458 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
96459 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
96460 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
96461 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
96462 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
96463 +cp210x_get_config_56229 cp210x_get_config 4 56229 NULL
96464 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
96465 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
96466 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
96467 +dn_nsp_send_disc_23469 dn_nsp_send_disc 2 23469 NULL
96468 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
96469 +ping_sendmsg_3782 ping_sendmsg 4 3782 NULL
96470 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
96471 +__lgread_31668 __lgread 4 31668 NULL
96472 +scrub_setup_recheck_block_56245 scrub_setup_recheck_block 4-3 56245 NULL
96473 +fd_copyin_56247 fd_copyin 3 56247 NULL
96474 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
96475 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
96476 +sys_connect_15291 sys_connect 3 15291 NULL nohasharray
96477 +xlate_dev_mem_ptr_15291 xlate_dev_mem_ptr 1 15291 &sys_connect_15291
96478 +linear_conf_23485 linear_conf 2 23485 NULL nohasharray
96479 +divasa_remap_pci_bar_23485 divasa_remap_pci_bar 3-4 23485 &linear_conf_23485
96480 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
96481 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
96482 +_usb_writeN_sync_31682 _usb_writeN_sync 4 31682 NULL
96483 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
96484 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
96485 +event_filter_read_23494 event_filter_read 3 23494 NULL
96486 +tpm_tis_init_15304 tpm_tis_init 2-3 15304 NULL
96487 +fcoe_ctlr_send_keep_alive_15308 fcoe_ctlr_send_keep_alive 3 15308 NULL
96488 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
96489 +sys_setsockopt_35320 sys_setsockopt 5 35320 NULL
96490 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
96491 +pkt_add_39897 pkt_add 3 39897 NULL
96492 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
96493 +send_mpa_reject_7135 send_mpa_reject 3 7135 NULL
96494 +sctp_make_op_error_7057 sctp_make_op_error 5-6 7057 NULL
96495 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
96496 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
96497 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
96498 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
96499 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
96500 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
96501 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
96502 +sctp_make_asconf_ack_31726 sctp_make_asconf_ack 3 31726 NULL
96503 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
96504 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
96505 +alloc_ring_15345 alloc_ring 2-4 15345 NULL
96506 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
96507 +remove_uuid_64505 remove_uuid 4 64505 NULL
96508 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3 31741 NULL
96509 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 NULL
96510 +create_table_16213 create_table 2 16213 NULL
96511 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
96512 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
96513 +dbg_leb_change_23555 dbg_leb_change 4 23555 NULL
96514 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
96515 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
96516 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
96517 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
96518 +set_discoverable_48141 set_discoverable 4 48141 NULL
96519 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
96520 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
96521 +tcp_match_skb_to_sack_23568 tcp_match_skb_to_sack 4 23568 NULL
96522 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
96523 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
96524 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3 39955 NULL
96525 +__tcp_push_pending_frames_48148 __tcp_push_pending_frames 2 48148 NULL
96526 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
96527 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
96528 +ipv6_recv_error_56347 ipv6_recv_error 3 56347 NULL
96529 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
96530 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
96531 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
96532 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
96533 +regmap_register_patch_21681 regmap_register_patch 3 21681 NULL
96534 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
96535 +cfpkt_create_pfx_23594 cfpkt_create_pfx 1-2 23594 NULL
96536 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
96537 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4 56368 NULL
96538 +dev_read_56369 dev_read 3 56369 NULL
96539 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
96540 +alloc_dummy_extent_buffer_56374 alloc_dummy_extent_buffer 2 56374 NULL
96541 +diva_os_alloc_message_buffer_64568 diva_os_alloc_message_buffer 1 64568 NULL
96542 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
96543 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
96544 +init_ipath_48187 init_ipath 1 48187 NULL
96545 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
96546 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4 15423 NULL
96547 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
96548 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
96549 +sys32_ipc_7238 sys32_ipc 3 7238 NULL
96550 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
96551 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1-2 21687 NULL
96552 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
96553 +ddp_ppod_write_idata_25610 ddp_ppod_write_idata 5 25610 NULL
96554 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
96555 +nf_nat_icmpv6_reply_translation_40023 nf_nat_icmpv6_reply_translation 5 40023 NULL nohasharray
96556 +ivtvfb_write_40023 ivtvfb_write 3 40023 &nf_nat_icmpv6_reply_translation_40023
96557 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
96558 +tcp_write_xmit_64602 tcp_write_xmit 2 64602 NULL
96559 +use_pool_64607 use_pool 2 64607 NULL
96560 +__get_vm_area_caller_56416 __get_vm_area_caller 1 56416 NULL nohasharray
96561 +acpi_os_write_memory_56416 acpi_os_write_memory 1-3 56416 &__get_vm_area_caller_56416
96562 +store_msg_56417 store_msg 3 56417 NULL
96563 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
96564 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
96565 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
96566 +read_file_recv_48232 read_file_recv 3 48232 NULL
96567 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
96568 +set_tpl_pfs_27490 set_tpl_pfs 3 27490 NULL
96569 +fanotify_write_64623 fanotify_write 3 64623 NULL
96570 +batadv_add_packet_12136 batadv_add_packet 3 12136 NULL
96571 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
96572 +fl_create_56435 fl_create 5 56435 NULL
96573 +gnttab_map_56439 gnttab_map 2 56439 NULL
96574 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
96575 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
96576 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
96577 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2 56453 NULL
96578 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
96579 +set_connectable_56458 set_connectable 4 56458 NULL
96580 +a2mp_chan_alloc_skb_cb_27159 a2mp_chan_alloc_skb_cb 2 27159 NULL
96581 +nfc_hci_send_response_56462 nfc_hci_send_response 5 56462 NULL
96582 +add_port_54941 add_port 2 54941 NULL
96583 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
96584 +cx18_read_23699 cx18_read 3 23699 NULL
96585 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 NULL
96586 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
96587 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
96588 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
96589 +ddb_output_write_31902 ddb_output_write 3 31902 NULL
96590 +send_set_info_48288 send_set_info 7 48288 NULL
96591 +sock_alloc_send_skb_23720 sock_alloc_send_skb 2 23720 NULL
96592 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
96593 +set_disc_pwup_pfs_48300 set_disc_pwup_pfs 3 48300 NULL
96594 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
96595 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
96596 +new_dir_31919 new_dir 3 31919 NULL
96597 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
96598 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
96599 +sec_bulk_write_64691 sec_bulk_write 3 64691 NULL
96600 +mgmt_control_7349 mgmt_control 3 7349 NULL
96601 +hash_setkey_48310 hash_setkey 3 48310 NULL
96602 +ql_process_mac_rx_page_15543 ql_process_mac_rx_page 4 15543 NULL
96603 +hfcpci_empty_fifo_2427 hfcpci_empty_fifo 4 2427 NULL
96604 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
96605 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
96606 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
96607 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
96608 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4 31942 NULL
96609 +ql_process_mac_rx_skb_6689 ql_process_mac_rx_skb 4 6689 NULL
96610 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
96611 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
96612 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
96613 +vb2_write_31948 vb2_write 3 31948 NULL
96614 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
96615 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
96616 +l1oip_socket_recv_56537 l1oip_socket_recv 6 56537 NULL
96617 +ip_options_get_56538 ip_options_get 4 56538 NULL
96618 +write_62671 write 3 62671 NULL
96619 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
96620 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
96621 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
96622 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
96623 +ceph_copy_page_vector_to_user_31270 ceph_copy_page_vector_to_user 3-4 31270 NULL
96624 +allocate_cnodes_5329 allocate_cnodes 1 5329 NULL
96625 +skb_add_data_48363 skb_add_data 3 48363 NULL
96626 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
96627 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
96628 +iscsi_complete_pdu_48372 iscsi_complete_pdu 4 48372 NULL
96629 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
96630 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
96631 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
96632 +debug_debug2_read_30526 debug_debug2_read 3 30526 NULL
96633 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
96634 +set_dis_tap_pfs_15621 set_dis_tap_pfs 3 15621 NULL
96635 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
96636 +dsp_cmx_send_member_15625 dsp_cmx_send_member 2 15625 NULL
96637 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
96638 +system_enable_read_25815 system_enable_read 3 25815 NULL
96639 +allocate_probes_40204 allocate_probes 1 40204 NULL
96640 +sd_alloc_ctl_entry_29708 sd_alloc_ctl_entry 1 29708 NULL
96641 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
96642 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
96643 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
96644 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
96645 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
96646 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
96647 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
96648 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &tomoyo_scan_bprm_15642
96649 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
96650 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
96651 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
96652 +fs_path_add_15648 fs_path_add 3 15648 NULL
96653 +event_filter_write_56609 event_filter_write 3 56609 NULL
96654 +xfs_buf_read_map_40226 xfs_buf_read_map 3 40226 NULL
96655 +ms_rw_multi_sector_7459 ms_rw_multi_sector 3-4 7459 NULL
96656 +xsd_read_15653 xsd_read 3 15653 NULL
96657 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
96658 +p54_init_common_23850 p54_init_common 1 23850 NULL
96659 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
96660 +vmw_cursor_update_dmabuf_32045 vmw_cursor_update_dmabuf 3-4 32045 NULL
96661 +sys_sched_setaffinity_32046 sys_sched_setaffinity 2 32046 NULL
96662 +garp_request_join_7471 garp_request_join 4 7471 NULL
96663 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
96664 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
96665 +unifi_read_14899 unifi_read 3 14899 NULL
96666 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
96667 +compat_sys_msgrcv_7482 compat_sys_msgrcv 2 7482 NULL
96668 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
96669 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
96670 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
96671 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
96672 +ipv6_recv_rxpmtu_7142 ipv6_recv_rxpmtu 3 7142 NULL
96673 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
96674 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
96675 +ieee80211_if_read_channel_type_23884 ieee80211_if_read_channel_type 3 23884 NULL
96676 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
96677 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
96678 +uf_sme_queue_message_15697 uf_sme_queue_message 3 15697 NULL
96679 +gdth_search_isa_58595 gdth_search_isa 1 58595 NULL
96680 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 NULL
96681 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
96682 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
96683 +iwch_reject_cr_23901 iwch_reject_cr 3 23901 NULL
96684 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
96685 +bio_alloc_32095 bio_alloc 2 32095 NULL
96686 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
96687 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
96688 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
96689 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL
96690 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
96691 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
96692 +ubi_io_write_data_40305 ubi_io_write_data 4-5 40305 NULL
96693 +send_control_msg_48498 send_control_msg 6 48498 NULL
96694 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
96695 +mlx4_en_create_tx_ring_48501 mlx4_en_create_tx_ring 4 48501 NULL
96696 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
96697 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
96698 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
96699 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3 56702 NULL
96700 +uvc_alloc_entity_20836 uvc_alloc_entity 4-3 20836 NULL
96701 +batadv_tt_changes_fill_buff_40323 batadv_tt_changes_fill_buff 4 40323 NULL
96702 +__alloc_skb_23940 __alloc_skb 1 23940 NULL
96703 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
96704 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
96705 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
96706 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
96707 +alloc_tx_32143 alloc_tx 2 32143 NULL
96708 +wiimote_hid_send_48528 wiimote_hid_send 3 48528 NULL
96709 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
96710 +hsc_write_55875 hsc_write 3 55875 NULL
96711 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
96712 +do_test_15766 do_test 1 15766 NULL
96713 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
96714 +ip_recv_error_23109 ip_recv_error 3 23109 NULL
96715 +named_distribute_48544 named_distribute 4 48544 NULL
96716 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
96717 +venus_link_32165 venus_link 5 32165 NULL
96718 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
96719 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
96720 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
96721 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
96722 +set_std_nic_pfs_15792 set_std_nic_pfs 3 15792 NULL
96723 +ubifs_wbuf_write_nolock_64946 ubifs_wbuf_write_nolock 3 64946 NULL
96724 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
96725 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
96726 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
96727 +fwnet_incoming_packet_40380 fwnet_incoming_packet 3 40380 NULL
96728 +groups_alloc_7614 groups_alloc 1 7614 NULL
96729 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
96730 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
96731 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
96732 +ext_sd_execute_read_data_48589 ext_sd_execute_read_data 9 48589 NULL
96733 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
96734 +__carl9170_rx_56784 __carl9170_rx 3 56784 NULL
96735 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL
96736 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
96737 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
96738 +tcf_csum_ipv4_tcp_39713 tcf_csum_ipv4_tcp 4 39713 NULL
96739 +snapshot_write_28351 snapshot_write 3 28351 NULL
96740 +event_enable_read_7074 event_enable_read 3 7074 NULL
96741 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
96742 +do_syslog_56807 do_syslog 3 56807 NULL
96743 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
96744 +pskb_pull_65005 pskb_pull 2 65005 NULL
96745 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
96746 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
96747 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
96748 +unifi_write_65012 unifi_write 3 65012 NULL
96749 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL
96750 +nfs_readdata_alloc_65015 nfs_readdata_alloc 2 65015 NULL
96751 +ubi_io_write_15870 ubi_io_write 5-4 15870 NULL nohasharray
96752 +media_entity_init_15870 media_entity_init 2-4 15870 &ubi_io_write_15870
96753 +mtdchar_write_56831 mtdchar_write 3 56831 NULL nohasharray
96754 +ntfs_rl_realloc_56831 ntfs_rl_realloc 3 56831 &mtdchar_write_56831
96755 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
96756 +mid_get_vbt_data_r1_26170 mid_get_vbt_data_r1 2 26170 NULL
96757 +skb_copy_expand_7685 skb_copy_expand 2-3 7685 NULL nohasharray
96758 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 &skb_copy_expand_7685
96759 +if_write_51756 if_write 3 51756 NULL
96760 +insert_dent_65034 insert_dent 7 65034 NULL
96761 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
96762 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4 56847 NULL
96763 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
96764 +brcmf_sdcard_rwdata_65041 brcmf_sdcard_rwdata 5 65041 NULL
96765 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
96766 +lc_create_48662 lc_create 3 48662 NULL
96767 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
96768 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL nohasharray
96769 +sys_setgroups_48668 sys_setgroups 1 48668 &sm501_create_subdev_48668
96770 +ath9k_multi_regread_65056 ath9k_multi_regread 4 65056 NULL
96771 +brcmf_sdcard_send_buf_7713 brcmf_sdcard_send_buf 6 7713 NULL
96772 +l2cap_build_cmd_48676 l2cap_build_cmd 4 48676 NULL
96773 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
96774 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
96775 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
96776 +bnx2fc_process_l2_frame_compl_65072 bnx2fc_process_l2_frame_compl 3 65072 NULL
96777 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
96778 +persistent_ram_new_40501 persistent_ram_new 1-2 40501 NULL
96779 +ieee80211_send_auth_24121 ieee80211_send_auth 5 24121 NULL
96780 +altera_drscan_48698 altera_drscan 2 48698 NULL
96781 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
96782 +set_bypass_pwup_pfs_7742 set_bypass_pwup_pfs 3 7742 NULL
96783 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
96784 +power_read_15939 power_read 3 15939 NULL
96785 +recv_msg_48709 recv_msg 4 48709 NULL
96786 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL
96787 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
96788 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
96789 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
96790 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
96791 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
96792 +process_vm_rw_pages_15954 process_vm_rw_pages 6-5 15954 NULL
96793 +revalidate_19043 revalidate 2 19043 NULL
96794 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
96795 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 NULL
96796 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
96797 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
96798 +check_header_56930 check_header 2 56930 NULL
96799 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
96800 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
96801 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
96802 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
96803 +sel_read_initcon_32362 sel_read_initcon 3 32362 NULL
96804 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
96805 +frame_alloc_15981 frame_alloc 4 15981 NULL
96806 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
96807 +nf_nat_seq_adjust_44989 nf_nat_seq_adjust 4 44989 NULL
96808 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL
96809 +adu_read_24177 adu_read 3 24177 NULL
96810 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
96811 +send_mpa_reply_32372 send_mpa_reply 3 32372 NULL
96812 +alloc_vm_area_15989 alloc_vm_area 1 15989 NULL
96813 +variax_set_raw2_32374 variax_set_raw2 4 32374 NULL
96814 +vfd_write_14717 vfd_write 3 14717 NULL
96815 +carl9170_rx_copy_data_21656 carl9170_rx_copy_data 2 21656 NULL
96816 +usbtmc_read_32377 usbtmc_read 3 32377 NULL
96817 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
96818 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
96819 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
96820 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
96821 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
96822 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
96823 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
96824 +__cxio_init_resource_fifo_23447 __cxio_init_resource_fifo 3 23447 NULL
96825 +skge_rx_get_40598 skge_rx_get 3 40598 NULL
96826 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
96827 +register_device_60015 register_device 2-3 60015 NULL
96828 +got_frame_16028 got_frame 2 16028 NULL
96829 +ssb_bus_register_65183 ssb_bus_register 3 65183 NULL
96830 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 1-2-3 24224 NULL
96831 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
96832 +scsi_register_49094 scsi_register 2 49094 NULL
96833 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
96834 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
96835 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
96836 +batadv_check_unicast_packet_10866 batadv_check_unicast_packet 2 10866 NULL
96837 +tcp_push_one_48816 tcp_push_one 2 48816 NULL
96838 +nfulnl_alloc_skb_65207 nfulnl_alloc_skb 2 65207 NULL
96839 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
96840 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
96841 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
96842 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
96843 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
96844 +svc_pool_map_alloc_arrays_47181 svc_pool_map_alloc_arrays 2 47181 NULL
96845 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
96846 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
96847 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
96848 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
96849 +compat_sys_preadv64_24283 compat_sys_preadv64 3 24283 NULL
96850 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
96851 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 NULL
96852 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
96853 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
96854 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
96855 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
96856 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
96857 +mid_get_vbt_data_r0_10876 mid_get_vbt_data_r0 2 10876 NULL
96858 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
96859 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
96860 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 NULL nohasharray
96861 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 &dma_tx_requested_read_16110
96862 +sys_setgroups16_48882 sys_setgroups16 1 48882 NULL
96863 +kmem_zalloc_greedy_65268 kmem_zalloc_greedy 3-2 65268 NULL
96864 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
96865 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
96866 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
96867 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
96868 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
96869 +mac_drv_rx_init_48898 mac_drv_rx_init 2 48898 NULL
96870 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
96871 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
96872 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
96873 +fsm_init_16134 fsm_init 2 16134 NULL
96874 +ext_sd_execute_write_data_8175 ext_sd_execute_write_data 9 8175 NULL
96875 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
96876 +disconnect_32521 disconnect 4 32521 NULL
96877 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
96878 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
96879 +ath6kl_wmi_add_wow_pattern_cmd_12842 ath6kl_wmi_add_wow_pattern_cmd 4 12842 NULL
96880 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
96881 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
96882 +ilo_read_32531 ilo_read 3 32531 NULL
96883 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
96884 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
96885 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
96886 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
96887 +gdth_isa_probe_one_48925 gdth_isa_probe_one 1 48925 NULL
96888 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
96889 +nfc_hci_execute_cmd_async_65314 nfc_hci_execute_cmd_async 5 65314 NULL
96890 +msnd_fifo_alloc_23179 msnd_fifo_alloc 2 23179 NULL
96891 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
96892 +nfcwilink_skb_alloc_16167 nfcwilink_skb_alloc 1 16167 NULL
96893 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
96894 +remap_pci_mem_15966 remap_pci_mem 1-2 15966 NULL
96895 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
96896 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
96897 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
96898 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
96899 +card_send_command_40757 card_send_command 3 40757 NULL
96900 +sys_mbind_7990 sys_mbind 5 7990 NULL
96901 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
96902 +pg_write_40766 pg_write 3 40766 NULL
96903 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
96904 +uea_idma_write_64139 uea_idma_write 3 64139 NULL
96905 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
96906 +carl9170_rx_stream_1334 carl9170_rx_stream 3 1334 NULL
96907 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
96908 +ath_descdma_setup_12257 ath_descdma_setup 5 12257 NULL
96909 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
96910 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
96911 +batadv_orig_hash_del_if_48972 batadv_orig_hash_del_if 2 48972 NULL
96912 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
96913 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 NULL nohasharray
96914 +getxattr_24398 getxattr 4 24398 &pvr2_v4l2_ioctl_24398
96915 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
96916 +vcs_read_8017 vcs_read 3 8017 NULL
96917 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
96918 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
96919 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
96920 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
96921 +_alloc_set_attr_list_48991 _alloc_set_attr_list 4 48991 NULL
96922 +sys_set_mempolicy_32608 sys_set_mempolicy 3 32608 NULL
96923 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
96924 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
96925 +copy_and_check_19089 copy_and_check 3 19089 NULL
96926 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
96927 +netdev_alloc_skb_ip_align_40811 netdev_alloc_skb_ip_align 2 40811 NULL
96928 +i915_wedged_read_35474 i915_wedged_read 3 35474 NULL
96929 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
96930 +iser_rcv_completion_8048 iser_rcv_completion 2 8048 NULL
96931 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
96932 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
96933 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
96934 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
96935 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
96936 +smk_user_access_24440 smk_user_access 3 24440 NULL
96937 +xd_rw_49020 xd_rw 3-4 49020 NULL
96938 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
96939 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
96940 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
96941 +kvmalloc_32646 kvmalloc 1 32646 NULL
96942 +alloc_targets_8074 alloc_targets 2 8074 NULL nohasharray
96943 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 &alloc_targets_8074
96944 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
96945 +drm_calloc_large_65421 drm_calloc_large 1-2 65421 NULL
96946 +set_disc_pfs_16270 set_disc_pfs 3 16270 NULL
96947 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
96948 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
96949 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL
96950 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 NULL nohasharray
96951 +nand_bch_init_16280 nand_bch_init 3-2 16280 &drbd_setsockopt_16280
96952 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
96953 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
96954 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
96955 +pn533_init_target_frame_65438 pn533_init_target_frame 3 65438 NULL
96956 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
96957 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
96958 +i915_wedged_write_47771 i915_wedged_write 3 47771 NULL
96959 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
96960 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
96961 +l2cap_bredr_sig_cmd_49065 l2cap_bredr_sig_cmd 3 49065 NULL
96962 +tipc_buf_acquire_60437 tipc_buf_acquire 1 60437 NULL
96963 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
96964 +venus_lookup_8121 venus_lookup 4 8121 NULL
96965 +compat_writev_60063 compat_writev 3 60063 NULL
96966 +io_mapping_create_wc_1354 io_mapping_create_wc 1-2 1354 NULL
96967 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
96968 +read_file_queue_40895 read_file_queue 3 40895 NULL
96969 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
96970 +waiters_read_40902 waiters_read 3 40902 NULL
96971 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
96972 +vmalloc_node_58700 vmalloc_node 1 58700 NULL
96973 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
96974 +ath_rx_edma_init_65483 ath_rx_edma_init 2 65483 NULL
96975 +vmw_cursor_update_image_16332 vmw_cursor_update_image 3-4 16332 NULL
96976 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
96977 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
96978 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
96979 +named_prepare_buf_24532 named_prepare_buf 2 24532 NULL
96980 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
96981 +alloc_dr_65495 alloc_dr 2 65495 NULL
96982 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
96983 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
96984 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
96985 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
96986 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
96987 +rbd_add_16366 rbd_add 3 16366 NULL
96988 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
96989 +pt_read_49136 pt_read 3 49136 NULL
96990 +tsi148_alloc_resource_24563 tsi148_alloc_resource 2 24563 NULL
96991 +snd_vx_create_40948 snd_vx_create 4 40948 NULL
96992 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
96993 +check_mirror_57342 check_mirror 1-2 57342 NULL nohasharray
96994 +usblp_read_57342 usblp_read 3 57342 &check_mirror_57342
96995 +atyfb_setup_generic_49151 atyfb_setup_generic 3 49151 NULL
96996 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
96997 new file mode 100644
96998 index 0000000..838ea58
96999 --- /dev/null
97000 +++ b/tools/gcc/size_overflow_plugin.c
97001 @@ -0,0 +1,1936 @@
97002 +/*
97003 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
97004 + * Licensed under the GPL v2, or (at your option) v3
97005 + *
97006 + * Homepage:
97007 + * http://www.grsecurity.net/~ephox/overflow_plugin/
97008 + *
97009 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
97010 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
97011 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
97012 + *
97013 + * Usage:
97014 + * $ 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
97015 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
97016 + */
97017 +
97018 +#include "gcc-plugin.h"
97019 +#include "config.h"
97020 +#include "system.h"
97021 +#include "coretypes.h"
97022 +#include "tree.h"
97023 +#include "tree-pass.h"
97024 +#include "intl.h"
97025 +#include "plugin-version.h"
97026 +#include "tm.h"
97027 +#include "toplev.h"
97028 +#include "function.h"
97029 +#include "tree-flow.h"
97030 +#include "plugin.h"
97031 +#include "gimple.h"
97032 +#include "diagnostic.h"
97033 +#include "cfgloop.h"
97034 +
97035 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2(EXP)
97036 +
97037 +#if BUILDING_GCC_VERSION >= 4008
97038 +#define TODO_dump_func 0
97039 +#endif
97040 +
97041 +struct size_overflow_hash {
97042 + const struct size_overflow_hash * const next;
97043 + const char * const name;
97044 + const unsigned int param;
97045 +};
97046 +
97047 +#include "size_overflow_hash.h"
97048 +
97049 +enum marked {
97050 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
97051 +};
97052 +
97053 +static unsigned int call_count = 0;
97054 +
97055 +#define __unused __attribute__((__unused__))
97056 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
97057 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
97058 +#define BEFORE_STMT true
97059 +#define AFTER_STMT false
97060 +#define CREATE_NEW_VAR NULL_TREE
97061 +#define CODES_LIMIT 32
97062 +#define MAX_PARAM 32
97063 +#define MY_STMT GF_PLF_1
97064 +#define NO_CAST_CHECK GF_PLF_2
97065 +
97066 +#if BUILDING_GCC_VERSION == 4005
97067 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
97068 +#endif
97069 +
97070 +int plugin_is_GPL_compatible;
97071 +void debug_gimple_stmt(gimple gs);
97072 +
97073 +static tree expand(struct pointer_set_t *visited, tree lhs);
97074 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
97075 +static tree report_size_overflow_decl;
97076 +static const_tree const_char_ptr_type_node;
97077 +static unsigned int handle_function(void);
97078 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
97079 +static tree get_size_overflow_type(gimple stmt, const_tree node);
97080 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
97081 +
97082 +static struct plugin_info size_overflow_plugin_info = {
97083 + .version = "20130109beta",
97084 + .help = "no-size-overflow\tturn off size overflow checking\n",
97085 +};
97086 +
97087 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
97088 +{
97089 + unsigned int arg_count;
97090 + enum tree_code code = TREE_CODE(*node);
97091 +
97092 + switch (code) {
97093 + case FUNCTION_DECL:
97094 + arg_count = type_num_arguments(TREE_TYPE(*node));
97095 + break;
97096 + case FUNCTION_TYPE:
97097 + case METHOD_TYPE:
97098 + arg_count = type_num_arguments(*node);
97099 + break;
97100 + default:
97101 + *no_add_attrs = true;
97102 + error("%s: %qE attribute only applies to functions", __func__, name);
97103 + return NULL_TREE;
97104 + }
97105 +
97106 + for (; args; args = TREE_CHAIN(args)) {
97107 + tree position = TREE_VALUE(args);
97108 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
97109 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
97110 + *no_add_attrs = true;
97111 + }
97112 + }
97113 + return NULL_TREE;
97114 +}
97115 +
97116 +static const char* get_asm_name(tree node)
97117 +{
97118 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
97119 +}
97120 +
97121 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
97122 +{
97123 + unsigned int arg_count, arg_num;
97124 + enum tree_code code = TREE_CODE(*node);
97125 +
97126 + switch (code) {
97127 + case FUNCTION_DECL:
97128 + arg_count = type_num_arguments(TREE_TYPE(*node));
97129 + break;
97130 + case FUNCTION_TYPE:
97131 + case METHOD_TYPE:
97132 + arg_count = type_num_arguments(*node);
97133 + break;
97134 + case FIELD_DECL:
97135 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
97136 + if (arg_num != 0) {
97137 + *no_add_attrs = true;
97138 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
97139 + }
97140 + return NULL_TREE;
97141 + default:
97142 + *no_add_attrs = true;
97143 + error("%qE attribute only applies to functions", name);
97144 + return NULL_TREE;
97145 + }
97146 +
97147 + for (; args; args = TREE_CHAIN(args)) {
97148 + tree position = TREE_VALUE(args);
97149 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
97150 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
97151 + *no_add_attrs = true;
97152 + }
97153 + }
97154 + return NULL_TREE;
97155 +}
97156 +
97157 +static struct attribute_spec size_overflow_attr = {
97158 + .name = "size_overflow",
97159 + .min_length = 1,
97160 + .max_length = -1,
97161 + .decl_required = true,
97162 + .type_required = false,
97163 + .function_type_required = false,
97164 + .handler = handle_size_overflow_attribute,
97165 +#if BUILDING_GCC_VERSION >= 4007
97166 + .affects_type_identity = false
97167 +#endif
97168 +};
97169 +
97170 +static struct attribute_spec intentional_overflow_attr = {
97171 + .name = "intentional_overflow",
97172 + .min_length = 1,
97173 + .max_length = -1,
97174 + .decl_required = true,
97175 + .type_required = false,
97176 + .function_type_required = false,
97177 + .handler = handle_intentional_overflow_attribute,
97178 +#if BUILDING_GCC_VERSION >= 4007
97179 + .affects_type_identity = false
97180 +#endif
97181 +};
97182 +
97183 +static void register_attributes(void __unused *event_data, void __unused *data)
97184 +{
97185 + register_attribute(&size_overflow_attr);
97186 + register_attribute(&intentional_overflow_attr);
97187 +}
97188 +
97189 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
97190 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
97191 +{
97192 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
97193 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
97194 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
97195 +
97196 + unsigned int m = 0x57559429;
97197 + unsigned int n = 0x5052acdb;
97198 + const unsigned int *key4 = (const unsigned int *)key;
97199 + unsigned int h = len;
97200 + unsigned int k = len + seed + n;
97201 + unsigned long long p;
97202 +
97203 + while (len >= 8) {
97204 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
97205 + len -= 8;
97206 + }
97207 + if (len >= 4) {
97208 + cwmixb(key4[0]) key4 += 1;
97209 + len -= 4;
97210 + }
97211 + if (len)
97212 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
97213 + cwmixb(h ^ (k + n));
97214 + return k ^ h;
97215 +
97216 +#undef cwfold
97217 +#undef cwmixa
97218 +#undef cwmixb
97219 +}
97220 +
97221 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
97222 +{
97223 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
97224 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
97225 + return fn ^ codes;
97226 +}
97227 +
97228 +static inline tree get_original_function_decl(tree fndecl)
97229 +{
97230 + if (DECL_ABSTRACT_ORIGIN(fndecl))
97231 + return DECL_ABSTRACT_ORIGIN(fndecl);
97232 + return fndecl;
97233 +}
97234 +
97235 +static inline gimple get_def_stmt(const_tree node)
97236 +{
97237 + gcc_assert(node != NULL_TREE);
97238 + gcc_assert(TREE_CODE(node) == SSA_NAME);
97239 + return SSA_NAME_DEF_STMT(node);
97240 +}
97241 +
97242 +static unsigned char get_tree_code(const_tree type)
97243 +{
97244 + switch (TREE_CODE(type)) {
97245 + case ARRAY_TYPE:
97246 + return 0;
97247 + case BOOLEAN_TYPE:
97248 + return 1;
97249 + case ENUMERAL_TYPE:
97250 + return 2;
97251 + case FUNCTION_TYPE:
97252 + return 3;
97253 + case INTEGER_TYPE:
97254 + return 4;
97255 + case POINTER_TYPE:
97256 + return 5;
97257 + case RECORD_TYPE:
97258 + return 6;
97259 + case UNION_TYPE:
97260 + return 7;
97261 + case VOID_TYPE:
97262 + return 8;
97263 + case REAL_TYPE:
97264 + return 9;
97265 + case VECTOR_TYPE:
97266 + return 10;
97267 + case REFERENCE_TYPE:
97268 + return 11;
97269 + case OFFSET_TYPE:
97270 + return 12;
97271 + case COMPLEX_TYPE:
97272 + return 13;
97273 + default:
97274 + debug_tree((tree)type);
97275 + gcc_unreachable();
97276 + }
97277 +}
97278 +
97279 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
97280 +{
97281 + gcc_assert(type != NULL_TREE);
97282 +
97283 + while (type && len < CODES_LIMIT) {
97284 + tree_codes[len] = get_tree_code(type);
97285 + len++;
97286 + type = TREE_TYPE(type);
97287 + }
97288 + return len;
97289 +}
97290 +
97291 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
97292 +{
97293 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
97294 + enum tree_code code = TREE_CODE(type);
97295 + size_t len = 0;
97296 +
97297 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
97298 +
97299 + arg = TYPE_ARG_TYPES(type);
97300 + // skip builtins __builtin_constant_p
97301 + if (!arg && DECL_BUILT_IN(fndecl))
97302 + return 0;
97303 +
97304 + if (TREE_CODE_CLASS(code) == tcc_type)
97305 + result = type;
97306 + else
97307 + result = DECL_RESULT(fndecl);
97308 +
97309 + gcc_assert(result != NULL_TREE);
97310 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
97311 +
97312 + if (arg == NULL_TREE) {
97313 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
97314 + arg_field = DECL_ARGUMENT_FLD(fndecl);
97315 + if (arg_field == NULL_TREE)
97316 + return 0;
97317 + arg = TREE_TYPE(arg_field);
97318 + len = add_type_codes(arg, tree_codes, len);
97319 + gcc_assert(len != 0);
97320 + return len;
97321 + }
97322 +
97323 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
97324 + while (arg && len < CODES_LIMIT) {
97325 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
97326 + arg = TREE_CHAIN(arg);
97327 + }
97328 +
97329 + gcc_assert(len != 0);
97330 + return len;
97331 +}
97332 +
97333 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
97334 +{
97335 + unsigned int hash;
97336 + const struct size_overflow_hash *entry;
97337 + unsigned char tree_codes[CODES_LIMIT];
97338 + size_t len;
97339 + const char *func_name = get_asm_name(fndecl);
97340 +
97341 + len = get_function_decl(fndecl, tree_codes);
97342 + if (len == 0)
97343 + return NULL;
97344 +
97345 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
97346 +
97347 + entry = size_overflow_hash[hash];
97348 + while (entry) {
97349 + if (!strcmp(entry->name, func_name))
97350 + return entry;
97351 + entry = entry->next;
97352 + }
97353 +
97354 + return NULL;
97355 +}
97356 +
97357 +static void check_arg_type(const_tree arg)
97358 +{
97359 + const_tree type = TREE_TYPE(arg);
97360 + enum tree_code code = TREE_CODE(type);
97361 +
97362 + if (code == BOOLEAN_TYPE)
97363 + return;
97364 +
97365 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
97366 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
97367 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
97368 +}
97369 +
97370 +static unsigned int find_arg_number(const_tree arg, tree func)
97371 +{
97372 + tree var;
97373 + unsigned int argnum = 1;
97374 +
97375 + if (TREE_CODE(arg) == SSA_NAME)
97376 + arg = SSA_NAME_VAR(arg);
97377 +
97378 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
97379 + if (strcmp(NAME(arg), NAME(var))) {
97380 + argnum++;
97381 + continue;
97382 + }
97383 + check_arg_type(var);
97384 + return argnum;
97385 + }
97386 + gcc_unreachable();
97387 +}
97388 +
97389 +static tree create_new_var(tree type)
97390 +{
97391 + tree new_var = create_tmp_var(type, "cicus");
97392 +
97393 +#if BUILDING_GCC_VERSION <= 4007
97394 + add_referenced_var(new_var);
97395 + mark_sym_for_renaming(new_var);
97396 +#endif
97397 + return new_var;
97398 +}
97399 +
97400 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
97401 +{
97402 + gimple assign;
97403 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
97404 + tree type = TREE_TYPE(rhs1);
97405 + tree lhs = create_new_var(type);
97406 +
97407 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
97408 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
97409 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
97410 +
97411 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
97412 + update_stmt(assign);
97413 + gimple_set_plf(assign, MY_STMT, true);
97414 + return assign;
97415 +}
97416 +
97417 +static bool is_bool(const_tree node)
97418 +{
97419 + const_tree type;
97420 +
97421 + if (node == NULL_TREE)
97422 + return false;
97423 +
97424 + type = TREE_TYPE(node);
97425 + if (!INTEGRAL_TYPE_P(type))
97426 + return false;
97427 + if (TREE_CODE(type) == BOOLEAN_TYPE)
97428 + return true;
97429 + if (TYPE_PRECISION(type) == 1)
97430 + return true;
97431 + return false;
97432 +}
97433 +
97434 +static tree cast_a_tree(tree type, tree var)
97435 +{
97436 + gcc_assert(type != NULL_TREE);
97437 + gcc_assert(var != NULL_TREE);
97438 + gcc_assert(fold_convertible_p(type, var));
97439 +
97440 + return fold_convert(type, var);
97441 +}
97442 +
97443 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
97444 +{
97445 + gimple assign;
97446 +
97447 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
97448 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
97449 + gcc_unreachable();
97450 +
97451 + if (lhs == CREATE_NEW_VAR)
97452 + lhs = create_new_var(dst_type);
97453 +
97454 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
97455 +
97456 + if (!gsi_end_p(*gsi)) {
97457 + location_t loc = gimple_location(gsi_stmt(*gsi));
97458 + gimple_set_location(assign, loc);
97459 + }
97460 +
97461 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
97462 +
97463 + if (before)
97464 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
97465 + else
97466 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
97467 + update_stmt(assign);
97468 + gimple_set_plf(assign, MY_STMT, true);
97469 +
97470 + return assign;
97471 +}
97472 +
97473 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
97474 +{
97475 + gimple assign;
97476 + gimple_stmt_iterator gsi;
97477 +
97478 + if (rhs == NULL_TREE)
97479 + return NULL_TREE;
97480 +
97481 + if (types_compatible_p(TREE_TYPE(rhs), size_overflow_type) && gimple_plf(stmt, MY_STMT))
97482 + return rhs;
97483 +
97484 + gsi = gsi_for_stmt(stmt);
97485 + assign = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before);
97486 + gimple_set_plf(assign, MY_STMT, true);
97487 + return gimple_get_lhs(assign);
97488 +}
97489 +
97490 +static tree cast_to_TI_type(gimple stmt, tree node)
97491 +{
97492 + gimple_stmt_iterator gsi;
97493 + gimple cast_stmt;
97494 + tree type = TREE_TYPE(node);
97495 +
97496 + if (types_compatible_p(type, intTI_type_node))
97497 + return node;
97498 +
97499 + gsi = gsi_for_stmt(stmt);
97500 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
97501 + gimple_set_plf(cast_stmt, MY_STMT, true);
97502 + return gimple_get_lhs(cast_stmt);
97503 +}
97504 +
97505 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
97506 +{
97507 + tree lhs;
97508 + gimple_stmt_iterator gsi;
97509 +
97510 + if (rhs1 == NULL_TREE) {
97511 + debug_gimple_stmt(oldstmt);
97512 + error("%s: rhs1 is NULL_TREE", __func__);
97513 + gcc_unreachable();
97514 + }
97515 +
97516 + switch (gimple_code(oldstmt)) {
97517 + case GIMPLE_ASM:
97518 + lhs = rhs1;
97519 + break;
97520 + case GIMPLE_CALL:
97521 + lhs = gimple_call_lhs(oldstmt);
97522 + break;
97523 + case GIMPLE_ASSIGN:
97524 + lhs = gimple_get_lhs(oldstmt);
97525 + break;
97526 + default:
97527 + debug_gimple_stmt(oldstmt);
97528 + gcc_unreachable();
97529 + }
97530 +
97531 + gsi = gsi_for_stmt(oldstmt);
97532 + pointer_set_insert(visited, oldstmt);
97533 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
97534 + basic_block next_bb, cur_bb;
97535 + const_edge e;
97536 +
97537 + gcc_assert(before == false);
97538 + gcc_assert(stmt_can_throw_internal(oldstmt));
97539 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
97540 + gcc_assert(!gsi_end_p(gsi));
97541 +
97542 + cur_bb = gimple_bb(oldstmt);
97543 + next_bb = cur_bb->next_bb;
97544 + e = find_edge(cur_bb, next_bb);
97545 + gcc_assert(e != NULL);
97546 + gcc_assert(e->flags & EDGE_FALLTHRU);
97547 +
97548 + gsi = gsi_after_labels(next_bb);
97549 + gcc_assert(!gsi_end_p(gsi));
97550 +
97551 + before = true;
97552 + oldstmt = gsi_stmt(gsi);
97553 + }
97554 +
97555 + return cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
97556 +}
97557 +
97558 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
97559 +{
97560 + gimple stmt;
97561 + gimple_stmt_iterator gsi;
97562 + tree size_overflow_type, new_var, lhs = gimple_get_lhs(oldstmt);
97563 +
97564 + if (gimple_plf(oldstmt, MY_STMT))
97565 + return lhs;
97566 +
97567 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
97568 + rhs1 = gimple_assign_rhs1(oldstmt);
97569 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
97570 + }
97571 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
97572 + rhs2 = gimple_assign_rhs2(oldstmt);
97573 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
97574 + }
97575 +
97576 + stmt = gimple_copy(oldstmt);
97577 + gimple_set_location(stmt, gimple_location(oldstmt));
97578 + gimple_set_plf(stmt, MY_STMT, true);
97579 +
97580 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
97581 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
97582 +
97583 + size_overflow_type = get_size_overflow_type(oldstmt, node);
97584 +
97585 + if (is_bool(lhs))
97586 + new_var = SSA_NAME_VAR(lhs);
97587 + else
97588 + new_var = create_new_var(size_overflow_type);
97589 + new_var = make_ssa_name(new_var, stmt);
97590 + gimple_set_lhs(stmt, new_var);
97591 +
97592 + if (rhs1 != NULL_TREE)
97593 + gimple_assign_set_rhs1(stmt, rhs1);
97594 +
97595 + if (rhs2 != NULL_TREE)
97596 + gimple_assign_set_rhs2(stmt, rhs2);
97597 +#if BUILDING_GCC_VERSION >= 4007
97598 + if (rhs3 != NULL_TREE)
97599 + gimple_assign_set_rhs3(stmt, rhs3);
97600 +#endif
97601 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
97602 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
97603 +
97604 + gsi = gsi_for_stmt(oldstmt);
97605 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
97606 + update_stmt(stmt);
97607 + pointer_set_insert(visited, oldstmt);
97608 + return gimple_get_lhs(stmt);
97609 +}
97610 +
97611 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
97612 +{
97613 + basic_block bb;
97614 + gimple phi;
97615 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
97616 + gimple_seq seq;
97617 +
97618 + bb = gsi_bb(gsi);
97619 +
97620 + phi = create_phi_node(result, bb);
97621 + seq = phi_nodes(bb);
97622 + gsi = gsi_last(seq);
97623 + gsi_remove(&gsi, false);
97624 +
97625 + gsi = gsi_for_stmt(oldstmt);
97626 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
97627 + gimple_set_bb(phi, bb);
97628 + gimple_set_plf(phi, MY_STMT, true);
97629 + return phi;
97630 +}
97631 +
97632 +static basic_block create_a_first_bb(void)
97633 +{
97634 + basic_block first_bb;
97635 +
97636 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
97637 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
97638 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
97639 + return first_bb;
97640 +}
97641 +
97642 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
97643 +{
97644 + basic_block bb;
97645 + const_gimple newstmt;
97646 + gimple_stmt_iterator gsi;
97647 + bool before = BEFORE_STMT;
97648 +
97649 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
97650 + gsi = gsi_for_stmt(get_def_stmt(arg));
97651 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
97652 + return gimple_get_lhs(newstmt);
97653 + }
97654 +
97655 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
97656 + gsi = gsi_after_labels(bb);
97657 + if (bb->index == 0) {
97658 + bb = create_a_first_bb();
97659 + gsi = gsi_start_bb(bb);
97660 + }
97661 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
97662 + return gimple_get_lhs(newstmt);
97663 +}
97664 +
97665 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
97666 +{
97667 + gimple newstmt;
97668 + gimple_stmt_iterator gsi;
97669 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
97670 + gimple def_newstmt = get_def_stmt(new_rhs);
97671 +
97672 + gsi_insert = gsi_insert_after;
97673 + gsi = gsi_for_stmt(def_newstmt);
97674 +
97675 + switch (gimple_code(get_def_stmt(arg))) {
97676 + case GIMPLE_PHI:
97677 + newstmt = gimple_build_assign(new_var, new_rhs);
97678 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
97679 + gsi_insert = gsi_insert_before;
97680 + break;
97681 + case GIMPLE_ASM:
97682 + case GIMPLE_CALL:
97683 + newstmt = gimple_build_assign(new_var, new_rhs);
97684 + break;
97685 + case GIMPLE_ASSIGN:
97686 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
97687 + break;
97688 + default:
97689 + /* unknown gimple_code (handle_build_new_phi_arg) */
97690 + gcc_unreachable();
97691 + }
97692 +
97693 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
97694 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
97695 + gimple_set_plf(newstmt, MY_STMT, true);
97696 + update_stmt(newstmt);
97697 + return newstmt;
97698 +}
97699 +
97700 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
97701 +{
97702 + const_gimple newstmt;
97703 + gimple def_stmt;
97704 + tree new_rhs;
97705 +
97706 + new_rhs = expand(visited, arg);
97707 + if (new_rhs == NULL_TREE)
97708 + return NULL_TREE;
97709 +
97710 + def_stmt = get_def_stmt(new_rhs);
97711 + if (gimple_code(def_stmt) == GIMPLE_NOP)
97712 + return NULL_TREE;
97713 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
97714 +
97715 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
97716 + return gimple_get_lhs(newstmt);
97717 +}
97718 +
97719 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
97720 +{
97721 + gimple phi, oldstmt = get_def_stmt(orig_result);
97722 + tree new_result, size_overflow_type;
97723 + unsigned int i;
97724 + unsigned int n = gimple_phi_num_args(oldstmt);
97725 +
97726 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
97727 +
97728 + new_result = create_new_var(size_overflow_type);
97729 +
97730 + pointer_set_insert(visited, oldstmt);
97731 + phi = overflow_create_phi_node(oldstmt, new_result);
97732 + for (i = 0; i < n; i++) {
97733 + tree arg, lhs;
97734 +
97735 + arg = gimple_phi_arg_def(oldstmt, i);
97736 + if (is_gimple_constant(arg))
97737 + arg = cast_a_tree(size_overflow_type, arg);
97738 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
97739 + if (lhs == NULL_TREE)
97740 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
97741 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
97742 + }
97743 +
97744 + update_stmt(phi);
97745 + return gimple_phi_result(phi);
97746 +}
97747 +
97748 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
97749 +{
97750 + const_gimple assign;
97751 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
97752 + tree origtype = TREE_TYPE(orig_rhs);
97753 +
97754 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
97755 +
97756 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
97757 + return gimple_get_lhs(assign);
97758 +}
97759 +
97760 +static void change_rhs1(gimple stmt, tree new_rhs1)
97761 +{
97762 + tree assign_rhs;
97763 + const_tree rhs = gimple_assign_rhs1(stmt);
97764 +
97765 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
97766 + gimple_assign_set_rhs1(stmt, assign_rhs);
97767 + update_stmt(stmt);
97768 +}
97769 +
97770 +static bool check_mode_type(const_gimple stmt)
97771 +{
97772 + const_tree lhs = gimple_get_lhs(stmt);
97773 + const_tree lhs_type = TREE_TYPE(lhs);
97774 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
97775 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
97776 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
97777 +
97778 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
97779 + return false;
97780 +
97781 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
97782 + return false;
97783 +
97784 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast
97785 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
97786 + return false;
97787 +
97788 + return true;
97789 +}
97790 +
97791 +static bool check_undefined_integer_operation(const_gimple stmt)
97792 +{
97793 + const_gimple def_stmt;
97794 + const_tree lhs = gimple_get_lhs(stmt);
97795 + const_tree rhs1 = gimple_assign_rhs1(stmt);
97796 + const_tree rhs1_type = TREE_TYPE(rhs1);
97797 + const_tree lhs_type = TREE_TYPE(lhs);
97798 +
97799 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
97800 + return false;
97801 +
97802 + def_stmt = get_def_stmt(rhs1);
97803 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
97804 + return false;
97805 +
97806 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
97807 + return false;
97808 + return true;
97809 +}
97810 +
97811 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
97812 +{
97813 + const_tree rhs1, lhs, rhs1_type, lhs_type;
97814 + enum machine_mode lhs_mode, rhs_mode;
97815 + gimple def_stmt = get_def_stmt(no_const_rhs);
97816 +
97817 + if (!gimple_assign_cast_p(def_stmt))
97818 + return false;
97819 +
97820 + rhs1 = gimple_assign_rhs1(def_stmt);
97821 + lhs = gimple_get_lhs(def_stmt);
97822 + rhs1_type = TREE_TYPE(rhs1);
97823 + lhs_type = TREE_TYPE(lhs);
97824 + rhs_mode = TYPE_MODE(rhs1_type);
97825 + lhs_mode = TYPE_MODE(lhs_type);
97826 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
97827 + return false;
97828 +
97829 + return true;
97830 +}
97831 +
97832 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
97833 +{
97834 + tree rhs1 = gimple_assign_rhs1(stmt);
97835 + tree lhs = gimple_get_lhs(stmt);
97836 + const_tree rhs1_type = TREE_TYPE(rhs1);
97837 + const_tree lhs_type = TREE_TYPE(lhs);
97838 +
97839 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
97840 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97841 +
97842 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
97843 +}
97844 +
97845 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
97846 +{
97847 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
97848 + tree new_rhs1 = NULL_TREE;
97849 + tree rhs1 = gimple_assign_rhs1(stmt);
97850 + const_tree rhs1_type = TREE_TYPE(rhs1);
97851 + const_tree lhs_type = TREE_TYPE(lhs);
97852 +
97853 + if (gimple_plf(stmt, MY_STMT))
97854 + return lhs;
97855 +
97856 + if (TREE_CODE(rhs1_type) == POINTER_TYPE)
97857 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97858 +
97859 + new_rhs1 = expand(visited, rhs1);
97860 +
97861 + if (new_rhs1 == NULL_TREE)
97862 + return create_cast_assign(visited, stmt);
97863 +
97864 + if (gimple_plf(stmt, NO_CAST_CHECK))
97865 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97866 +
97867 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
97868 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
97869 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97870 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
97871 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97872 + }
97873 +
97874 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
97875 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97876 +
97877 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
97878 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
97879 +
97880 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
97881 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97882 +
97883 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
97884 +
97885 + change_rhs1(stmt, new_rhs1);
97886 +
97887 + if (!check_mode_type(stmt))
97888 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97889 +
97890 + size_overflow_type = get_size_overflow_type(stmt, lhs);
97891 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
97892 +
97893 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
97894 +
97895 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97896 +}
97897 +
97898 +static tree handle_unary_ops(struct pointer_set_t *visited, gimple stmt)
97899 +{
97900 + tree rhs1, lhs = gimple_get_lhs(stmt);
97901 + gimple def_stmt = get_def_stmt(lhs);
97902 +
97903 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
97904 + rhs1 = gimple_assign_rhs1(def_stmt);
97905 +
97906 + if (is_gimple_constant(rhs1))
97907 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
97908 +
97909 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
97910 + switch (TREE_CODE(rhs1)) {
97911 + case SSA_NAME:
97912 + return handle_unary_rhs(visited, def_stmt);
97913 + case ARRAY_REF:
97914 + case BIT_FIELD_REF:
97915 + case ADDR_EXPR:
97916 + case COMPONENT_REF:
97917 + case INDIRECT_REF:
97918 +#if BUILDING_GCC_VERSION >= 4006
97919 + case MEM_REF:
97920 +#endif
97921 + case TARGET_MEM_REF:
97922 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
97923 + case PARM_DECL:
97924 + case VAR_DECL:
97925 + return create_assign(visited, stmt, lhs, AFTER_STMT);
97926 +
97927 + default:
97928 + debug_gimple_stmt(def_stmt);
97929 + debug_tree(rhs1);
97930 + gcc_unreachable();
97931 + }
97932 +}
97933 +
97934 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
97935 +{
97936 + gimple cond_stmt;
97937 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
97938 +
97939 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
97940 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
97941 + update_stmt(cond_stmt);
97942 +}
97943 +
97944 +static tree create_string_param(tree string)
97945 +{
97946 + tree i_type, a_type;
97947 + const int length = TREE_STRING_LENGTH(string);
97948 +
97949 + gcc_assert(length > 0);
97950 +
97951 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
97952 + a_type = build_array_type(char_type_node, i_type);
97953 +
97954 + TREE_TYPE(string) = a_type;
97955 + TREE_CONSTANT(string) = 1;
97956 + TREE_READONLY(string) = 1;
97957 +
97958 + return build1(ADDR_EXPR, ptr_type_node, string);
97959 +}
97960 +
97961 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
97962 +{
97963 + gimple func_stmt;
97964 + const_gimple def_stmt;
97965 + const_tree loc_line;
97966 + tree loc_file, ssa_name, current_func;
97967 + expanded_location xloc;
97968 + char *ssa_name_buf;
97969 + int len;
97970 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
97971 +
97972 + def_stmt = get_def_stmt(arg);
97973 + xloc = expand_location(gimple_location(def_stmt));
97974 +
97975 + if (!gimple_has_location(def_stmt)) {
97976 + xloc = expand_location(gimple_location(stmt));
97977 + if (!gimple_has_location(stmt))
97978 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
97979 + }
97980 +
97981 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
97982 +
97983 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
97984 + loc_file = create_string_param(loc_file);
97985 +
97986 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
97987 + current_func = create_string_param(current_func);
97988 +
97989 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
97990 + call_count++;
97991 + 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);
97992 + gcc_assert(len > 0);
97993 + ssa_name = build_string(len + 1, ssa_name_buf);
97994 + free(ssa_name_buf);
97995 + ssa_name = create_string_param(ssa_name);
97996 +
97997 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
97998 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
97999 +
98000 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
98001 +}
98002 +
98003 +static void __unused print_the_code_insertions(const_gimple stmt)
98004 +{
98005 + location_t loc = gimple_location(stmt);
98006 +
98007 + inform(loc, "Integer size_overflow check applied here.");
98008 +}
98009 +
98010 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
98011 +{
98012 + basic_block cond_bb, join_bb, bb_true;
98013 + edge e;
98014 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
98015 +
98016 + cond_bb = gimple_bb(stmt);
98017 + if (before)
98018 + gsi_prev(&gsi);
98019 + if (gsi_end_p(gsi))
98020 + e = split_block_after_labels(cond_bb);
98021 + else
98022 + e = split_block(cond_bb, gsi_stmt(gsi));
98023 + cond_bb = e->src;
98024 + join_bb = e->dest;
98025 + e->flags = EDGE_FALSE_VALUE;
98026 + e->probability = REG_BR_PROB_BASE;
98027 +
98028 + bb_true = create_empty_bb(cond_bb);
98029 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
98030 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
98031 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
98032 +
98033 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
98034 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
98035 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
98036 +
98037 + if (current_loops != NULL) {
98038 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
98039 + add_bb_to_loop(bb_true, cond_bb->loop_father);
98040 + }
98041 +
98042 + insert_cond(cond_bb, arg, cond_code, type_value);
98043 + insert_cond_result(bb_true, stmt, arg, min);
98044 +
98045 +// print_the_code_insertions(stmt);
98046 +}
98047 +
98048 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
98049 +{
98050 + const_tree rhs_type = TREE_TYPE(rhs);
98051 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
98052 +
98053 + gcc_assert(rhs_type != NULL_TREE);
98054 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
98055 + return;
98056 +
98057 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
98058 +
98059 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
98060 + // typemax (-1) < typemin (0)
98061 + if (TREE_OVERFLOW(type_max))
98062 + return;
98063 +
98064 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
98065 +
98066 + cast_rhs_type = TREE_TYPE(cast_rhs);
98067 + type_max_type = TREE_TYPE(type_max);
98068 + type_min_type = TREE_TYPE(type_min);
98069 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
98070 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
98071 +
98072 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
98073 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
98074 +}
98075 +
98076 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
98077 +{
98078 + gimple change_rhs_def_stmt;
98079 + tree lhs = gimple_get_lhs(def_stmt);
98080 + tree lhs_type = TREE_TYPE(lhs);
98081 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
98082 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
98083 +
98084 + if (change_rhs == NULL_TREE)
98085 + return get_size_overflow_type(def_stmt, lhs);
98086 +
98087 + change_rhs_def_stmt = get_def_stmt(change_rhs);
98088 +
98089 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
98090 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
98091 +
98092 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
98093 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
98094 +
98095 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
98096 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
98097 +
98098 + if (!types_compatible_p(lhs_type, rhs1_type) || !types_compatible_p(rhs1_type, rhs2_type)) {
98099 + debug_gimple_stmt(def_stmt);
98100 + gcc_unreachable();
98101 + }
98102 +
98103 + return get_size_overflow_type(def_stmt, lhs);
98104 +}
98105 +
98106 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
98107 +{
98108 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
98109 + return false;
98110 + if (!is_gimple_constant(rhs))
98111 + return false;
98112 + return true;
98113 +}
98114 +
98115 +static bool is_subtraction_special(const_gimple stmt)
98116 +{
98117 + gimple rhs1_def_stmt, rhs2_def_stmt;
98118 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
98119 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
98120 + const_tree rhs1 = gimple_assign_rhs1(stmt);
98121 + const_tree rhs2 = gimple_assign_rhs2(stmt);
98122 +
98123 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
98124 + return false;
98125 +
98126 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
98127 +
98128 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
98129 + return false;
98130 +
98131 + rhs1_def_stmt = get_def_stmt(rhs1);
98132 + rhs2_def_stmt = get_def_stmt(rhs2);
98133 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
98134 + return false;
98135 +
98136 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
98137 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
98138 + rhs1_def_stmt_lhs = gimple_get_lhs(rhs1_def_stmt);
98139 + rhs2_def_stmt_lhs = gimple_get_lhs(rhs2_def_stmt);
98140 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
98141 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
98142 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
98143 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
98144 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
98145 + return false;
98146 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
98147 + return false;
98148 +
98149 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
98150 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
98151 + return true;
98152 +}
98153 +
98154 +static tree get_def_stmt_rhs(const_tree var)
98155 +{
98156 + tree rhs1, def_stmt_rhs1;
98157 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
98158 +
98159 + def_stmt = get_def_stmt(var);
98160 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
98161 +
98162 + rhs1 = gimple_assign_rhs1(def_stmt);
98163 + rhs1_def_stmt = get_def_stmt(rhs1);
98164 + if (!gimple_assign_cast_p(rhs1_def_stmt))
98165 + return rhs1;
98166 +
98167 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
98168 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
98169 +
98170 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
98171 + case GIMPLE_CALL:
98172 + case GIMPLE_NOP:
98173 + case GIMPLE_ASM:
98174 + return def_stmt_rhs1;
98175 + case GIMPLE_ASSIGN:
98176 + return rhs1;
98177 + default:
98178 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
98179 + gcc_unreachable();
98180 + }
98181 +}
98182 +
98183 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
98184 +{
98185 + tree new_rhs1, new_rhs2;
98186 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
98187 + gimple assign, stmt = get_def_stmt(lhs);
98188 + tree rhs1 = gimple_assign_rhs1(stmt);
98189 + tree rhs2 = gimple_assign_rhs2(stmt);
98190 +
98191 + if (!is_subtraction_special(stmt))
98192 + return NULL_TREE;
98193 +
98194 + new_rhs1 = expand(visited, rhs1);
98195 + new_rhs2 = expand(visited, rhs2);
98196 +
98197 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
98198 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
98199 +
98200 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
98201 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
98202 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
98203 + }
98204 +
98205 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
98206 + new_lhs = gimple_get_lhs(assign);
98207 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
98208 +
98209 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
98210 +}
98211 +
98212 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
98213 +{
98214 + const_gimple def_stmt;
98215 +
98216 + if (TREE_CODE(rhs) != SSA_NAME)
98217 + return false;
98218 +
98219 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
98220 + return false;
98221 +
98222 + def_stmt = get_def_stmt(rhs);
98223 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
98224 + return false;
98225 +
98226 + return true;
98227 +}
98228 +
98229 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
98230 +{
98231 + tree new_rhs, size_overflow_type, orig_rhs;
98232 + void (*gimple_assign_set_rhs)(gimple, tree);
98233 + tree rhs1 = gimple_assign_rhs1(stmt);
98234 + tree rhs2 = gimple_assign_rhs2(stmt);
98235 + tree lhs = gimple_get_lhs(stmt);
98236 +
98237 + if (change_rhs == NULL_TREE)
98238 + return create_assign(visited, stmt, lhs, AFTER_STMT);
98239 +
98240 + if (new_rhs2 == NULL_TREE) {
98241 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
98242 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
98243 + orig_rhs = rhs1;
98244 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
98245 + } else {
98246 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
98247 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
98248 + orig_rhs = rhs2;
98249 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
98250 + }
98251 +
98252 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
98253 +
98254 + if (check_overflow)
98255 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
98256 +
98257 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
98258 + gimple_assign_set_rhs(stmt, new_rhs);
98259 + update_stmt(stmt);
98260 +
98261 + return create_assign(visited, stmt, lhs, AFTER_STMT);
98262 +}
98263 +
98264 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
98265 +{
98266 + tree rhs1, rhs2, new_lhs;
98267 + gimple def_stmt = get_def_stmt(lhs);
98268 + tree new_rhs1 = NULL_TREE;
98269 + tree new_rhs2 = NULL_TREE;
98270 +
98271 + rhs1 = gimple_assign_rhs1(def_stmt);
98272 + rhs2 = gimple_assign_rhs2(def_stmt);
98273 +
98274 + /* no DImode/TImode division in the 32/64 bit kernel */
98275 + switch (gimple_assign_rhs_code(def_stmt)) {
98276 + case RDIV_EXPR:
98277 + case TRUNC_DIV_EXPR:
98278 + case CEIL_DIV_EXPR:
98279 + case FLOOR_DIV_EXPR:
98280 + case ROUND_DIV_EXPR:
98281 + case TRUNC_MOD_EXPR:
98282 + case CEIL_MOD_EXPR:
98283 + case FLOOR_MOD_EXPR:
98284 + case ROUND_MOD_EXPR:
98285 + case EXACT_DIV_EXPR:
98286 + case POINTER_PLUS_EXPR:
98287 + case BIT_AND_EXPR:
98288 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
98289 + default:
98290 + break;
98291 + }
98292 +
98293 + new_lhs = handle_integer_truncation(visited, lhs);
98294 + if (new_lhs != NULL_TREE)
98295 + return new_lhs;
98296 +
98297 + if (TREE_CODE(rhs1) == SSA_NAME)
98298 + new_rhs1 = expand(visited, rhs1);
98299 + if (TREE_CODE(rhs2) == SSA_NAME)
98300 + new_rhs2 = expand(visited, rhs2);
98301 +
98302 + if (is_a_neg_overflow(def_stmt, rhs2))
98303 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
98304 + if (is_a_neg_overflow(def_stmt, rhs1))
98305 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
98306 +
98307 + if (is_a_constant_overflow(def_stmt, rhs2))
98308 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
98309 + if (is_a_constant_overflow(def_stmt, rhs1))
98310 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
98311 +
98312 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
98313 +}
98314 +
98315 +#if BUILDING_GCC_VERSION >= 4007
98316 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
98317 +{
98318 + if (is_gimple_constant(rhs))
98319 + return cast_a_tree(size_overflow_type, rhs);
98320 + if (TREE_CODE(rhs) != SSA_NAME)
98321 + return NULL_TREE;
98322 + return expand(visited, rhs);
98323 +}
98324 +
98325 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
98326 +{
98327 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
98328 + gimple def_stmt = get_def_stmt(lhs);
98329 +
98330 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
98331 +
98332 + rhs1 = gimple_assign_rhs1(def_stmt);
98333 + rhs2 = gimple_assign_rhs2(def_stmt);
98334 + rhs3 = gimple_assign_rhs3(def_stmt);
98335 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
98336 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
98337 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
98338 +
98339 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
98340 +}
98341 +#endif
98342 +
98343 +static tree get_size_overflow_type(gimple stmt, const_tree node)
98344 +{
98345 + const_tree type;
98346 + tree new_type;
98347 +
98348 + gcc_assert(node != NULL_TREE);
98349 +
98350 + type = TREE_TYPE(node);
98351 +
98352 + if (gimple_plf(stmt, MY_STMT))
98353 + return TREE_TYPE(node);
98354 +
98355 + switch (TYPE_MODE(type)) {
98356 + case QImode:
98357 + new_type = intHI_type_node;
98358 + break;
98359 + case HImode:
98360 + new_type = intSI_type_node;
98361 + break;
98362 + case SImode:
98363 + new_type = intDI_type_node;
98364 + break;
98365 + case DImode:
98366 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
98367 + new_type = intDI_type_node;
98368 + else
98369 + new_type = intTI_type_node;
98370 + break;
98371 + default:
98372 + debug_tree((tree)node);
98373 + error("%s: unsupported gcc configuration.", __func__);
98374 + gcc_unreachable();
98375 + }
98376 +
98377 + if (TYPE_QUALS(type) != 0)
98378 + return build_qualified_type(new_type, TYPE_QUALS(type));
98379 + return new_type;
98380 +}
98381 +
98382 +static tree expand_visited(gimple def_stmt)
98383 +{
98384 + const_gimple next_stmt;
98385 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
98386 +
98387 + gsi_next(&gsi);
98388 + next_stmt = gsi_stmt(gsi);
98389 +
98390 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
98391 +
98392 + switch (gimple_code(next_stmt)) {
98393 + case GIMPLE_ASSIGN:
98394 + return gimple_get_lhs(next_stmt);
98395 + case GIMPLE_PHI:
98396 + return gimple_phi_result(next_stmt);
98397 + case GIMPLE_CALL:
98398 + return gimple_call_lhs(next_stmt);
98399 + default:
98400 + return NULL_TREE;
98401 + }
98402 +}
98403 +
98404 +static tree expand(struct pointer_set_t *visited, tree lhs)
98405 +{
98406 + gimple def_stmt;
98407 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
98408 +
98409 + if (is_gimple_constant(lhs))
98410 + return NULL_TREE;
98411 +
98412 + if (TREE_CODE(lhs) == ADDR_EXPR)
98413 + return NULL_TREE;
98414 +
98415 + if (code == REAL_TYPE)
98416 + return NULL_TREE;
98417 +
98418 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
98419 +
98420 + def_stmt = get_def_stmt(lhs);
98421 +
98422 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
98423 + return NULL_TREE;
98424 +
98425 + if (gimple_plf(def_stmt, MY_STMT))
98426 + return lhs;
98427 +
98428 + if (pointer_set_contains(visited, def_stmt))
98429 + return expand_visited(def_stmt);
98430 +
98431 + switch (gimple_code(def_stmt)) {
98432 + case GIMPLE_PHI:
98433 + return build_new_phi(visited, lhs);
98434 + case GIMPLE_CALL:
98435 + case GIMPLE_ASM:
98436 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
98437 + case GIMPLE_ASSIGN:
98438 + switch (gimple_num_ops(def_stmt)) {
98439 + case 2:
98440 + return handle_unary_ops(visited, def_stmt);
98441 + case 3:
98442 + return handle_binary_ops(visited, lhs);
98443 +#if BUILDING_GCC_VERSION >= 4007
98444 + case 4:
98445 + return handle_ternary_ops(visited, lhs);
98446 +#endif
98447 + }
98448 + default:
98449 + debug_gimple_stmt(def_stmt);
98450 + error("%s: unknown gimple code", __func__);
98451 + gcc_unreachable();
98452 + }
98453 +}
98454 +
98455 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
98456 +{
98457 + const_gimple assign;
98458 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
98459 + tree origtype = TREE_TYPE(origarg);
98460 +
98461 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
98462 +
98463 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
98464 +
98465 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
98466 + update_stmt(stmt);
98467 +}
98468 +
98469 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
98470 +{
98471 + const char *origid;
98472 + tree arg;
98473 + const_tree origarg;
98474 +
98475 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
98476 + return true;
98477 +
98478 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
98479 + while (origarg && *argnum) {
98480 + (*argnum)--;
98481 + origarg = TREE_CHAIN(origarg);
98482 + }
98483 +
98484 + gcc_assert(*argnum == 0);
98485 +
98486 + gcc_assert(origarg != NULL_TREE);
98487 + origid = NAME(origarg);
98488 + *argnum = 0;
98489 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
98490 + if (!strcmp(origid, NAME(arg)))
98491 + return true;
98492 + (*argnum)++;
98493 + }
98494 + return false;
98495 +}
98496 +
98497 +static bool skip_types(const_tree var)
98498 +{
98499 + const_tree type;
98500 +
98501 + switch (TREE_CODE(var)) {
98502 + case ADDR_EXPR:
98503 +#if BUILDING_GCC_VERSION >= 4006
98504 + case MEM_REF:
98505 +#endif
98506 + case ARRAY_REF:
98507 + case BIT_FIELD_REF:
98508 + case INDIRECT_REF:
98509 + case TARGET_MEM_REF:
98510 + case VAR_DECL:
98511 + return true;
98512 + default:
98513 + break;
98514 + }
98515 +
98516 + type = TREE_TYPE(TREE_TYPE(var));
98517 + if (!type)
98518 + return false;
98519 + switch (TREE_CODE(type)) {
98520 + case RECORD_TYPE:
98521 + return true;
98522 + default:
98523 + break;
98524 + }
98525 +
98526 + return false;
98527 +}
98528 +
98529 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
98530 +{
98531 + gimple phi = get_def_stmt(result);
98532 + unsigned int i, n = gimple_phi_num_args(phi);
98533 +
98534 + if (!phi)
98535 + return false;
98536 +
98537 + pointer_set_insert(visited, phi);
98538 + for (i = 0; i < n; i++) {
98539 + const_tree arg = gimple_phi_arg_def(phi, i);
98540 + if (pre_expand(visited, arg))
98541 + return true;
98542 + }
98543 + return false;
98544 +}
98545 +
98546 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
98547 +{
98548 + gimple def_stmt = get_def_stmt(lhs);
98549 + const_tree rhs;
98550 +
98551 + if (!def_stmt)
98552 + return false;
98553 +
98554 + rhs = gimple_assign_rhs1(def_stmt);
98555 + if (pre_expand(visited, rhs))
98556 + return true;
98557 + return false;
98558 +}
98559 +
98560 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
98561 +{
98562 + bool rhs1_found, rhs2_found;
98563 + gimple def_stmt = get_def_stmt(lhs);
98564 + const_tree rhs1, rhs2;
98565 +
98566 + if (!def_stmt)
98567 + return false;
98568 +
98569 + rhs1 = gimple_assign_rhs1(def_stmt);
98570 + rhs2 = gimple_assign_rhs2(def_stmt);
98571 + rhs1_found = pre_expand(visited, rhs1);
98572 + rhs2_found = pre_expand(visited, rhs2);
98573 +
98574 + return rhs1_found || rhs2_found;
98575 +}
98576 +
98577 +static const_tree search_field_decl(const_tree comp_ref)
98578 +{
98579 + const_tree field = NULL_TREE;
98580 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
98581 +
98582 + for (i = 0; i < len; i++) {
98583 + field = TREE_OPERAND(comp_ref, i);
98584 + if (TREE_CODE(field) == FIELD_DECL)
98585 + break;
98586 + }
98587 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
98588 + return field;
98589 +}
98590 +
98591 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
98592 +{
98593 + const_tree attr, p;
98594 +
98595 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
98596 + if (!attr || !TREE_VALUE(attr))
98597 + return MARKED_NO;
98598 +
98599 + p = TREE_VALUE(attr);
98600 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
98601 + return MARKED_NOT_INTENTIONAL;
98602 +
98603 + do {
98604 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
98605 + return MARKED_YES;
98606 + p = TREE_CHAIN(p);
98607 + } while (p);
98608 +
98609 + return MARKED_NO;
98610 +}
98611 +
98612 +static void print_missing_msg(tree func, unsigned int argnum)
98613 +{
98614 + unsigned int new_hash;
98615 + size_t len;
98616 + unsigned char tree_codes[CODES_LIMIT];
98617 + location_t loc = DECL_SOURCE_LOCATION(func);
98618 + const char *curfunc = get_asm_name(func);
98619 +
98620 + len = get_function_decl(func, tree_codes);
98621 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
98622 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
98623 +}
98624 +
98625 +static unsigned int search_missing_attribute(const_tree arg)
98626 +{
98627 + const_tree type = TREE_TYPE(arg);
98628 + tree func = get_original_function_decl(current_function_decl);
98629 + unsigned int argnum;
98630 + const struct size_overflow_hash *hash;
98631 +
98632 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
98633 +
98634 + if (TREE_CODE(type) == POINTER_TYPE)
98635 + return 0;
98636 +
98637 + argnum = find_arg_number(arg, func);
98638 + if (argnum == 0)
98639 + return 0;
98640 +
98641 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
98642 + return argnum;
98643 +
98644 + hash = get_function_hash(func);
98645 + if (!hash || !(hash->param & (1U << argnum))) {
98646 + print_missing_msg(func, argnum);
98647 + return 0;
98648 + }
98649 + return argnum;
98650 +}
98651 +
98652 +static bool is_already_marked(const_tree lhs)
98653 +{
98654 + unsigned int argnum;
98655 + const_tree fndecl;
98656 +
98657 + argnum = search_missing_attribute(lhs);
98658 + fndecl = get_original_function_decl(current_function_decl);
98659 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
98660 + return true;
98661 + return false;
98662 +}
98663 +
98664 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
98665 +{
98666 + const_gimple def_stmt;
98667 +
98668 + if (is_gimple_constant(lhs))
98669 + return false;
98670 +
98671 + if (skip_types(lhs))
98672 + return false;
98673 +
98674 + // skip char type (FIXME: only kernel)
98675 + if (TYPE_MODE(TREE_TYPE(lhs)) == QImode)
98676 + return false;
98677 +
98678 + if (TREE_CODE(lhs) == PARM_DECL)
98679 + return is_already_marked(lhs);
98680 +
98681 + if (TREE_CODE(lhs) == COMPONENT_REF) {
98682 + const_tree field, attr;
98683 +
98684 + field = search_field_decl(lhs);
98685 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
98686 + if (!attr || !TREE_VALUE(attr))
98687 + return false;
98688 + return true;
98689 + }
98690 +
98691 + def_stmt = get_def_stmt(lhs);
98692 +
98693 + if (!def_stmt)
98694 + return false;
98695 +
98696 + if (pointer_set_contains(visited, def_stmt))
98697 + return false;
98698 +
98699 + switch (gimple_code(def_stmt)) {
98700 + case GIMPLE_NOP:
98701 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
98702 + return is_already_marked(lhs);
98703 + return false;
98704 + case GIMPLE_PHI:
98705 + return walk_phi(visited, lhs);
98706 + case GIMPLE_CALL:
98707 + case GIMPLE_ASM:
98708 + return false;
98709 + case GIMPLE_ASSIGN:
98710 + switch (gimple_num_ops(def_stmt)) {
98711 + case 2:
98712 + return walk_unary_ops(visited, lhs);
98713 + case 3:
98714 + return walk_binary_ops(visited, lhs);
98715 + }
98716 + default:
98717 + debug_gimple_stmt((gimple)def_stmt);
98718 + error("%s: unknown gimple code", __func__);
98719 + gcc_unreachable();
98720 + }
98721 +}
98722 +
98723 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
98724 +{
98725 + struct pointer_set_t *visited;
98726 + bool is_found;
98727 + enum marked is_marked;
98728 + location_t loc;
98729 +
98730 + visited = pointer_set_create();
98731 + is_found = pre_expand(visited, arg);
98732 + pointer_set_destroy(visited);
98733 +
98734 + is_marked = mark_status(fndecl, argnum + 1);
98735 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
98736 + return true;
98737 +
98738 + if (is_found) {
98739 + loc = DECL_SOURCE_LOCATION(fndecl);
98740 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
98741 + return true;
98742 + }
98743 + return false;
98744 +}
98745 +
98746 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
98747 +{
98748 + struct pointer_set_t *visited;
98749 + tree arg, newarg;
98750 + bool match;
98751 +
98752 + match = get_function_arg(&argnum, fndecl);
98753 + if (!match)
98754 + return;
98755 + gcc_assert(gimple_call_num_args(stmt) > argnum);
98756 + arg = gimple_call_arg(stmt, argnum);
98757 + if (arg == NULL_TREE)
98758 + return;
98759 +
98760 + if (is_gimple_constant(arg))
98761 + return;
98762 +
98763 + if (search_attributes(fndecl, arg, argnum))
98764 + return;
98765 +
98766 + if (TREE_CODE(arg) != SSA_NAME)
98767 + return;
98768 +
98769 + check_arg_type(arg);
98770 +
98771 + visited = pointer_set_create();
98772 + newarg = expand(visited, arg);
98773 + pointer_set_destroy(visited);
98774 +
98775 + if (newarg == NULL_TREE)
98776 + return;
98777 +
98778 + change_function_arg(stmt, arg, argnum, newarg);
98779 +
98780 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
98781 +}
98782 +
98783 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
98784 +{
98785 + tree p = TREE_VALUE(attr);
98786 + do {
98787 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
98788 + p = TREE_CHAIN(p);
98789 + } while (p);
98790 +}
98791 +
98792 +static void handle_function_by_hash(gimple stmt, tree fndecl)
98793 +{
98794 + tree orig_fndecl;
98795 + unsigned int num;
98796 + const struct size_overflow_hash *hash;
98797 +
98798 + orig_fndecl = get_original_function_decl(fndecl);
98799 + if (C_DECL_IMPLICIT(orig_fndecl))
98800 + return;
98801 + hash = get_function_hash(orig_fndecl);
98802 + if (!hash)
98803 + return;
98804 +
98805 + for (num = 1; num <= MAX_PARAM; num++)
98806 + if (hash->param & (1U << num))
98807 + handle_function_arg(stmt, fndecl, num - 1);
98808 +}
98809 +
98810 +static void set_plf_false(void)
98811 +{
98812 + basic_block bb;
98813 +
98814 + FOR_ALL_BB(bb) {
98815 + gimple_stmt_iterator si;
98816 +
98817 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
98818 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
98819 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
98820 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
98821 + }
98822 +}
98823 +
98824 +static unsigned int handle_function(void)
98825 +{
98826 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
98827 +
98828 + set_plf_false();
98829 +
98830 + do {
98831 + gimple_stmt_iterator gsi;
98832 + next = bb->next_bb;
98833 +
98834 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
98835 + tree fndecl, attr;
98836 + gimple stmt = gsi_stmt(gsi);
98837 +
98838 + if (!(is_gimple_call(stmt)))
98839 + continue;
98840 + fndecl = gimple_call_fndecl(stmt);
98841 + if (fndecl == NULL_TREE)
98842 + continue;
98843 + if (gimple_call_num_args(stmt) == 0)
98844 + continue;
98845 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
98846 + if (!attr || !TREE_VALUE(attr))
98847 + handle_function_by_hash(stmt, fndecl);
98848 + else
98849 + handle_function_by_attribute(stmt, attr, fndecl);
98850 + gsi = gsi_for_stmt(stmt);
98851 + next = gimple_bb(stmt)->next_bb;
98852 + }
98853 + bb = next;
98854 + } while (bb);
98855 + return 0;
98856 +}
98857 +
98858 +static struct gimple_opt_pass size_overflow_pass = {
98859 + .pass = {
98860 + .type = GIMPLE_PASS,
98861 + .name = "size_overflow",
98862 +#if BUILDING_GCC_VERSION >= 4008
98863 + .optinfo_flags = OPTGROUP_NONE,
98864 +#endif
98865 + .gate = NULL,
98866 + .execute = handle_function,
98867 + .sub = NULL,
98868 + .next = NULL,
98869 + .static_pass_number = 0,
98870 + .tv_id = TV_NONE,
98871 + .properties_required = PROP_cfg,
98872 + .properties_provided = 0,
98873 + .properties_destroyed = 0,
98874 + .todo_flags_start = 0,
98875 + .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
98876 + }
98877 +};
98878 +
98879 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
98880 +{
98881 + tree fntype;
98882 +
98883 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
98884 +
98885 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
98886 + fntype = build_function_type_list(void_type_node,
98887 + const_char_ptr_type_node,
98888 + unsigned_type_node,
98889 + const_char_ptr_type_node,
98890 + const_char_ptr_type_node,
98891 + NULL_TREE);
98892 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
98893 +
98894 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
98895 + TREE_PUBLIC(report_size_overflow_decl) = 1;
98896 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
98897 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
98898 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
98899 +}
98900 +
98901 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
98902 +{
98903 + int i;
98904 + const char * const plugin_name = plugin_info->base_name;
98905 + const int argc = plugin_info->argc;
98906 + const struct plugin_argument * const argv = plugin_info->argv;
98907 + bool enable = true;
98908 +
98909 + struct register_pass_info size_overflow_pass_info = {
98910 + .pass = &size_overflow_pass.pass,
98911 + .reference_pass_name = "ssa",
98912 + .ref_pass_instance_number = 1,
98913 + .pos_op = PASS_POS_INSERT_AFTER
98914 + };
98915 +
98916 + if (!plugin_default_version_check(version, &gcc_version)) {
98917 + error(G_("incompatible gcc/plugin versions"));
98918 + return 1;
98919 + }
98920 +
98921 + for (i = 0; i < argc; ++i) {
98922 + if (!strcmp(argv[i].key, "no-size-overflow")) {
98923 + enable = false;
98924 + continue;
98925 + }
98926 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
98927 + }
98928 +
98929 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
98930 + if (enable) {
98931 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
98932 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
98933 + }
98934 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
98935 +
98936 + return 0;
98937 +}
98938 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
98939 new file mode 100644
98940 index 0000000..ac2901e
98941 --- /dev/null
98942 +++ b/tools/gcc/stackleak_plugin.c
98943 @@ -0,0 +1,327 @@
98944 +/*
98945 + * Copyright 2011-2013 by the PaX Team <pageexec@freemail.hu>
98946 + * Licensed under the GPL v2
98947 + *
98948 + * Note: the choice of the license means that the compilation process is
98949 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
98950 + * but for the kernel it doesn't matter since it doesn't link against
98951 + * any of the gcc libraries
98952 + *
98953 + * gcc plugin to help implement various PaX features
98954 + *
98955 + * - track lowest stack pointer
98956 + *
98957 + * TODO:
98958 + * - initialize all local variables
98959 + *
98960 + * BUGS:
98961 + * - none known
98962 + */
98963 +#include "gcc-plugin.h"
98964 +#include "config.h"
98965 +#include "system.h"
98966 +#include "coretypes.h"
98967 +#include "tree.h"
98968 +#include "tree-pass.h"
98969 +#include "flags.h"
98970 +#include "intl.h"
98971 +#include "toplev.h"
98972 +#include "plugin.h"
98973 +//#include "expr.h" where are you...
98974 +#include "diagnostic.h"
98975 +#include "plugin-version.h"
98976 +#include "tm.h"
98977 +#include "function.h"
98978 +#include "basic-block.h"
98979 +#include "gimple.h"
98980 +#include "rtl.h"
98981 +#include "emit-rtl.h"
98982 +
98983 +#if BUILDING_GCC_VERSION >= 4008
98984 +#define TODO_dump_func 0
98985 +#endif
98986 +
98987 +extern void print_gimple_stmt(FILE *, gimple, int, int);
98988 +
98989 +int plugin_is_GPL_compatible;
98990 +
98991 +static int track_frame_size = -1;
98992 +static const char track_function[] = "pax_track_stack";
98993 +static const char check_function[] = "pax_check_alloca";
98994 +static bool init_locals;
98995 +
98996 +static struct plugin_info stackleak_plugin_info = {
98997 + .version = "201302112000",
98998 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
98999 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
99000 +};
99001 +
99002 +static bool gate_stackleak_track_stack(void);
99003 +static unsigned int execute_stackleak_tree_instrument(void);
99004 +static unsigned int execute_stackleak_final(void);
99005 +
99006 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
99007 + .pass = {
99008 + .type = GIMPLE_PASS,
99009 + .name = "stackleak_tree_instrument",
99010 +#if BUILDING_GCC_VERSION >= 4008
99011 + .optinfo_flags = OPTGROUP_NONE,
99012 +#endif
99013 + .gate = gate_stackleak_track_stack,
99014 + .execute = execute_stackleak_tree_instrument,
99015 + .sub = NULL,
99016 + .next = NULL,
99017 + .static_pass_number = 0,
99018 + .tv_id = TV_NONE,
99019 + .properties_required = PROP_gimple_leh | PROP_cfg,
99020 + .properties_provided = 0,
99021 + .properties_destroyed = 0,
99022 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
99023 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
99024 + }
99025 +};
99026 +
99027 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
99028 + .pass = {
99029 + .type = RTL_PASS,
99030 + .name = "stackleak_final",
99031 +#if BUILDING_GCC_VERSION >= 4008
99032 + .optinfo_flags = OPTGROUP_NONE,
99033 +#endif
99034 + .gate = gate_stackleak_track_stack,
99035 + .execute = execute_stackleak_final,
99036 + .sub = NULL,
99037 + .next = NULL,
99038 + .static_pass_number = 0,
99039 + .tv_id = TV_NONE,
99040 + .properties_required = 0,
99041 + .properties_provided = 0,
99042 + .properties_destroyed = 0,
99043 + .todo_flags_start = 0,
99044 + .todo_flags_finish = TODO_dump_func
99045 + }
99046 +};
99047 +
99048 +static bool gate_stackleak_track_stack(void)
99049 +{
99050 + return track_frame_size >= 0;
99051 +}
99052 +
99053 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
99054 +{
99055 + gimple check_alloca;
99056 + tree fntype, fndecl, alloca_size;
99057 +
99058 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
99059 + fndecl = build_fn_decl(check_function, fntype);
99060 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
99061 +
99062 + // insert call to void pax_check_alloca(unsigned long size)
99063 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
99064 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
99065 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
99066 +}
99067 +
99068 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
99069 +{
99070 + gimple track_stack;
99071 + tree fntype, fndecl;
99072 +
99073 + fntype = build_function_type_list(void_type_node, NULL_TREE);
99074 + fndecl = build_fn_decl(track_function, fntype);
99075 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
99076 +
99077 + // insert call to void pax_track_stack(void)
99078 + track_stack = gimple_build_call(fndecl, 0);
99079 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
99080 +}
99081 +
99082 +#if BUILDING_GCC_VERSION == 4005
99083 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
99084 +{
99085 + tree fndecl;
99086 +
99087 + if (!is_gimple_call(stmt))
99088 + return false;
99089 + fndecl = gimple_call_fndecl(stmt);
99090 + if (!fndecl)
99091 + return false;
99092 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
99093 + return false;
99094 +// print_node(stderr, "pax", fndecl, 4);
99095 + return DECL_FUNCTION_CODE(fndecl) == code;
99096 +}
99097 +#endif
99098 +
99099 +static bool is_alloca(gimple stmt)
99100 +{
99101 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
99102 + return true;
99103 +
99104 +#if BUILDING_GCC_VERSION >= 4007
99105 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
99106 + return true;
99107 +#endif
99108 +
99109 + return false;
99110 +}
99111 +
99112 +static unsigned int execute_stackleak_tree_instrument(void)
99113 +{
99114 + basic_block bb, entry_bb;
99115 + bool prologue_instrumented = false, is_leaf = true;
99116 +
99117 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
99118 +
99119 + // 1. loop through BBs and GIMPLE statements
99120 + FOR_EACH_BB(bb) {
99121 + gimple_stmt_iterator gsi;
99122 +
99123 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
99124 + gimple stmt;
99125 +
99126 + stmt = gsi_stmt(gsi);
99127 +
99128 + if (is_gimple_call(stmt))
99129 + is_leaf = false;
99130 +
99131 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
99132 + if (!is_alloca(stmt))
99133 + continue;
99134 +
99135 + // 2. insert stack overflow check before each __builtin_alloca call
99136 + stackleak_check_alloca(&gsi);
99137 +
99138 + // 3. insert track call after each __builtin_alloca call
99139 + stackleak_add_instrumentation(&gsi);
99140 + if (bb == entry_bb)
99141 + prologue_instrumented = true;
99142 + }
99143 + }
99144 +
99145 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
99146 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
99147 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
99148 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
99149 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
99150 + return 0;
99151 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
99152 + return 0;
99153 +
99154 + // 4. insert track call at the beginning
99155 + if (!prologue_instrumented) {
99156 + gimple_stmt_iterator gsi;
99157 +
99158 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
99159 + if (dom_info_available_p(CDI_DOMINATORS))
99160 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
99161 + gsi = gsi_start_bb(bb);
99162 + stackleak_add_instrumentation(&gsi);
99163 + }
99164 +
99165 + return 0;
99166 +}
99167 +
99168 +static unsigned int execute_stackleak_final(void)
99169 +{
99170 + rtx insn, next;
99171 +
99172 + if (cfun->calls_alloca)
99173 + return 0;
99174 +
99175 + // keep calls only if function frame is big enough
99176 + if (get_frame_size() >= track_frame_size)
99177 + return 0;
99178 +
99179 + // 1. find pax_track_stack calls
99180 + for (insn = get_insns(); insn; insn = next) {
99181 + // 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))
99182 + rtx body;
99183 +
99184 + next = NEXT_INSN(insn);
99185 + if (!CALL_P(insn))
99186 + continue;
99187 + body = PATTERN(insn);
99188 + if (GET_CODE(body) != CALL)
99189 + continue;
99190 + body = XEXP(body, 0);
99191 + if (GET_CODE(body) != MEM)
99192 + continue;
99193 + body = XEXP(body, 0);
99194 + if (GET_CODE(body) != SYMBOL_REF)
99195 + continue;
99196 + if (strcmp(XSTR(body, 0), track_function))
99197 + continue;
99198 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
99199 + // 2. delete call
99200 + delete_insn_and_edges(insn);
99201 +#if BUILDING_GCC_VERSION >= 4007
99202 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
99203 + insn = next;
99204 + next = NEXT_INSN(insn);
99205 + delete_insn_and_edges(insn);
99206 + }
99207 +#endif
99208 + }
99209 +
99210 +// print_simple_rtl(stderr, get_insns());
99211 +// print_rtl(stderr, get_insns());
99212 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
99213 +
99214 + return 0;
99215 +}
99216 +
99217 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
99218 +{
99219 + const char * const plugin_name = plugin_info->base_name;
99220 + const int argc = plugin_info->argc;
99221 + const struct plugin_argument * const argv = plugin_info->argv;
99222 + int i;
99223 + struct register_pass_info stackleak_tree_instrument_pass_info = {
99224 + .pass = &stackleak_tree_instrument_pass.pass,
99225 +// .reference_pass_name = "tree_profile",
99226 + .reference_pass_name = "optimized",
99227 + .ref_pass_instance_number = 1,
99228 + .pos_op = PASS_POS_INSERT_BEFORE
99229 + };
99230 + struct register_pass_info stackleak_final_pass_info = {
99231 + .pass = &stackleak_final_rtl_opt_pass.pass,
99232 + .reference_pass_name = "final",
99233 + .ref_pass_instance_number = 1,
99234 + .pos_op = PASS_POS_INSERT_BEFORE
99235 + };
99236 +
99237 + if (!plugin_default_version_check(version, &gcc_version)) {
99238 + error(G_("incompatible gcc/plugin versions"));
99239 + return 1;
99240 + }
99241 +
99242 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
99243 +
99244 + for (i = 0; i < argc; ++i) {
99245 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
99246 + if (!argv[i].value) {
99247 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
99248 + continue;
99249 + }
99250 + track_frame_size = atoi(argv[i].value);
99251 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
99252 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
99253 + continue;
99254 + }
99255 + if (!strcmp(argv[i].key, "initialize-locals")) {
99256 + if (argv[i].value) {
99257 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
99258 + continue;
99259 + }
99260 + init_locals = true;
99261 + continue;
99262 + }
99263 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
99264 + }
99265 +
99266 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
99267 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
99268 +
99269 + return 0;
99270 +}
99271 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
99272 index 6789d78..4afd019e 100644
99273 --- a/tools/perf/util/include/asm/alternative-asm.h
99274 +++ b/tools/perf/util/include/asm/alternative-asm.h
99275 @@ -5,4 +5,7 @@
99276
99277 #define altinstruction_entry #
99278
99279 + .macro pax_force_retaddr rip=0, reload=0
99280 + .endm
99281 +
99282 #endif
99283 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
99284 index 1cd693a..f4a7b20 100644
99285 --- a/virt/kvm/kvm_main.c
99286 +++ b/virt/kvm/kvm_main.c
99287 @@ -75,12 +75,17 @@ LIST_HEAD(vm_list);
99288
99289 static cpumask_var_t cpus_hardware_enabled;
99290 static int kvm_usage_count = 0;
99291 -static atomic_t hardware_enable_failed;
99292 +static atomic_unchecked_t hardware_enable_failed;
99293
99294 struct kmem_cache *kvm_vcpu_cache;
99295 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
99296
99297 -static __read_mostly struct preempt_ops kvm_preempt_ops;
99298 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
99299 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
99300 +static struct preempt_ops kvm_preempt_ops = {
99301 + .sched_in = kvm_sched_in,
99302 + .sched_out = kvm_sched_out,
99303 +};
99304
99305 struct dentry *kvm_debugfs_dir;
99306
99307 @@ -731,7 +736,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
99308 /* We can read the guest memory with __xxx_user() later on. */
99309 if (user_alloc &&
99310 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
99311 - !access_ok(VERIFY_WRITE,
99312 + !__access_ok(VERIFY_WRITE,
99313 (void __user *)(unsigned long)mem->userspace_addr,
99314 mem->memory_size)))
99315 goto out;
99316 @@ -1783,7 +1788,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
99317 return 0;
99318 }
99319
99320 -static struct file_operations kvm_vcpu_fops = {
99321 +static file_operations_no_const kvm_vcpu_fops __read_only = {
99322 .release = kvm_vcpu_release,
99323 .unlocked_ioctl = kvm_vcpu_ioctl,
99324 #ifdef CONFIG_COMPAT
99325 @@ -2304,7 +2309,7 @@ static int kvm_vm_mmap(struct file *file, struct vm_area_struct *vma)
99326 return 0;
99327 }
99328
99329 -static struct file_operations kvm_vm_fops = {
99330 +static file_operations_no_const kvm_vm_fops __read_only = {
99331 .release = kvm_vm_release,
99332 .unlocked_ioctl = kvm_vm_ioctl,
99333 #ifdef CONFIG_COMPAT
99334 @@ -2402,7 +2407,7 @@ out:
99335 return r;
99336 }
99337
99338 -static struct file_operations kvm_chardev_ops = {
99339 +static file_operations_no_const kvm_chardev_ops __read_only = {
99340 .unlocked_ioctl = kvm_dev_ioctl,
99341 .compat_ioctl = kvm_dev_ioctl,
99342 .llseek = noop_llseek,
99343 @@ -2428,7 +2433,7 @@ static void hardware_enable_nolock(void *junk)
99344
99345 if (r) {
99346 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
99347 - atomic_inc(&hardware_enable_failed);
99348 + atomic_inc_unchecked(&hardware_enable_failed);
99349 printk(KERN_INFO "kvm: enabling virtualization on "
99350 "CPU%d failed\n", cpu);
99351 }
99352 @@ -2482,10 +2487,10 @@ static int hardware_enable_all(void)
99353
99354 kvm_usage_count++;
99355 if (kvm_usage_count == 1) {
99356 - atomic_set(&hardware_enable_failed, 0);
99357 + atomic_set_unchecked(&hardware_enable_failed, 0);
99358 on_each_cpu(hardware_enable_nolock, NULL, 1);
99359
99360 - if (atomic_read(&hardware_enable_failed)) {
99361 + if (atomic_read_unchecked(&hardware_enable_failed)) {
99362 hardware_disable_all_nolock();
99363 r = -EBUSY;
99364 }
99365 @@ -2843,7 +2848,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
99366 kvm_arch_vcpu_put(vcpu);
99367 }
99368
99369 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99370 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99371 struct module *module)
99372 {
99373 int r;
99374 @@ -2879,7 +2884,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99375 if (!vcpu_align)
99376 vcpu_align = __alignof__(struct kvm_vcpu);
99377 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
99378 - 0, NULL);
99379 + SLAB_USERCOPY, NULL);
99380 if (!kvm_vcpu_cache) {
99381 r = -ENOMEM;
99382 goto out_free_3;
99383 @@ -2889,9 +2894,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99384 if (r)
99385 goto out_free;
99386
99387 + pax_open_kernel();
99388 kvm_chardev_ops.owner = module;
99389 kvm_vm_fops.owner = module;
99390 kvm_vcpu_fops.owner = module;
99391 + pax_close_kernel();
99392
99393 r = misc_register(&kvm_dev);
99394 if (r) {
99395 @@ -2901,9 +2908,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
99396
99397 register_syscore_ops(&kvm_syscore_ops);
99398
99399 - kvm_preempt_ops.sched_in = kvm_sched_in;
99400 - kvm_preempt_ops.sched_out = kvm_sched_out;
99401 -
99402 r = kvm_init_debug();
99403 if (r) {
99404 printk(KERN_ERR "kvm: create debugfs files failed\n");