]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-2.9.1-3.5.5-201210061727.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-2.9.1-3.5.5-201210061727.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b4a898f..cd023f2 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,7 +163,7 @@ 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 @@ -153,7 +171,7 @@ kxgettext
123 lkc_defs.h
124 lex.c
125 lex.*.c
126 -linux
127 +lib1funcs.S
128 logo_*.c
129 logo_*_clut224.c
130 logo_*_mono.c
131 @@ -164,14 +182,15 @@ machtypes.h
132 map
133 map_hugetlb
134 maui_boot.h
135 -media
136 mconf
137 +mdp
138 miboot*
139 mk_elfconfig
140 mkboot
141 mkbugboot
142 mkcpustr
143 mkdep
144 +mkpiggy
145 mkprep
146 mkregtable
147 mktables
148 @@ -188,6 +207,8 @@ oui.c*
149 page-types
150 parse.c
151 parse.h
152 +parse-events*
153 +pasyms.h
154 patches*
155 pca200e.bin
156 pca200e_ecd.bin2
157 @@ -197,6 +218,7 @@ perf-archive
158 piggyback
159 piggy.gzip
160 piggy.S
161 +pmu-*
162 pnmtologo
163 ppc_defs.h*
164 pss_boot.h
165 @@ -206,7 +228,10 @@ r200_reg_safe.h
166 r300_reg_safe.h
167 r420_reg_safe.h
168 r600_reg_safe.h
169 +realmode.lds
170 +realmode.relocs
171 recordmcount
172 +regdb.c
173 relocs
174 rlim_names.h
175 rn50_reg_safe.h
176 @@ -216,8 +241,11 @@ series
177 setup
178 setup.bin
179 setup.elf
180 +size_overflow_hash.h
181 sImage
182 +slabinfo
183 sm_tbl*
184 +sortextable
185 split-include
186 syscalltab.h
187 tables.c
188 @@ -227,6 +255,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 @@ -238,13 +267,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 @@ -252,9 +285,11 @@ vsyscall_32.lds
215 wanxlfw.inc
216 uImage
217 unifdef
218 +utsrelease.h
219 wakeup.bin
220 wakeup.elf
221 wakeup.lds
222 zImage*
223 zconf.hash.c
224 +zconf.lex.c
225 zoffset.h
226 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
227 index a92c5eb..b91d3d5 100644
228 --- a/Documentation/kernel-parameters.txt
229 +++ b/Documentation/kernel-parameters.txt
230 @@ -905,6 +905,9 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
231 gpt [EFI] Forces disk with valid GPT signature but
232 invalid Protective MBR to be treated as GPT.
233
234 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
235 + ignore grsecurity's /proc restrictions
236 +
237 hashdist= [KNL,NUMA] Large hashes allocated during boot
238 are distributed across NUMA nodes. Defaults on
239 for 64-bit NUMA, off otherwise.
240 @@ -2051,6 +2054,13 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
241 the specified number of seconds. This is to be used if
242 your oopses keep scrolling off the screen.
243
244 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
245 + virtualization environments that don't cope well with the
246 + expand down segment used by UDEREF on X86-32 or the frequent
247 + page table updates on X86-64.
248 +
249 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
250 +
251 pcbit= [HW,ISDN]
252
253 pcd. [PARIDE]
254 diff --git a/Documentation/sysctl/fs.txt b/Documentation/sysctl/fs.txt
255 index 13d6166..8c235b6 100644
256 --- a/Documentation/sysctl/fs.txt
257 +++ b/Documentation/sysctl/fs.txt
258 @@ -163,16 +163,22 @@ This value can be used to query and set the core dump mode for setuid
259 or otherwise protected/tainted binaries. The modes are
260
261 0 - (default) - traditional behaviour. Any process which has changed
262 - privilege levels or is execute only will not be dumped
263 + privilege levels or is execute only will not be dumped.
264 1 - (debug) - all processes dump core when possible. The core dump is
265 owned by the current user and no security is applied. This is
266 intended for system debugging situations only. Ptrace is unchecked.
267 + This is insecure as it allows regular users to examine the memory
268 + contents of privileged processes.
269 2 - (suidsafe) - any binary which normally would not be dumped is dumped
270 - readable by root only. This allows the end user to remove
271 - such a dump but not access it directly. For security reasons
272 - core dumps in this mode will not overwrite one another or
273 - other files. This mode is appropriate when administrators are
274 - attempting to debug problems in a normal environment.
275 + anyway, but only if the "core_pattern" kernel sysctl is set to
276 + either a pipe handler or a fully qualified path. (For more details
277 + on this limitation, see CVE-2006-2451.) This mode is appropriate
278 + when administrators are attempting to debug problems in a normal
279 + environment, and either have a core dump pipe handler that knows
280 + to treat privileged core dumps with care, or specific directory
281 + defined for catching core dumps. If a core dump happens without
282 + a pipe handler or fully qualifid path, a message will be emitted
283 + to syslog warning about the lack of a correct setting.
284
285 ==============================================================
286
287 diff --git a/Makefile b/Makefile
288 index b3dfc85..61372d3 100644
289 --- a/Makefile
290 +++ b/Makefile
291 @@ -241,8 +241,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
292
293 HOSTCC = gcc
294 HOSTCXX = g++
295 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
296 -HOSTCXXFLAGS = -O2
297 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
298 +HOSTCLFAGS += $(call cc-option, -Wno-empty-body)
299 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
300
301 # Decide whether to build built-in, modular, or both.
302 # Normally, just do built-in.
303 @@ -404,8 +405,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
304 # Rules shared between *config targets and build targets
305
306 # Basic helpers built in scripts/
307 -PHONY += scripts_basic
308 -scripts_basic:
309 +PHONY += scripts_basic gcc-plugins
310 +scripts_basic: gcc-plugins
311 $(Q)$(MAKE) $(build)=scripts/basic
312 $(Q)rm -f .tmp_quiet_recordmcount
313
314 @@ -561,6 +562,60 @@ else
315 KBUILD_CFLAGS += -O2
316 endif
317
318 +ifndef DISABLE_PAX_PLUGINS
319 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
320 +ifneq ($(PLUGINCC),)
321 +ifndef DISABLE_PAX_CONSTIFY_PLUGIN
322 +ifndef CONFIG_UML
323 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
324 +endif
325 +endif
326 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
327 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
328 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
329 +endif
330 +ifdef CONFIG_KALLOCSTAT_PLUGIN
331 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
332 +endif
333 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
334 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
335 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
336 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
337 +endif
338 +ifdef CONFIG_CHECKER_PLUGIN
339 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
340 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
341 +endif
342 +endif
343 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
344 +ifdef CONFIG_PAX_SIZE_OVERFLOW
345 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
346 +endif
347 +ifdef CONFIG_PAX_LATENT_ENTROPY
348 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
349 +endif
350 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
351 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
352 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS)
353 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
354 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
355 +ifeq ($(KBUILD_EXTMOD),)
356 +gcc-plugins:
357 + $(Q)$(MAKE) $(build)=tools/gcc
358 +else
359 +gcc-plugins: ;
360 +endif
361 +else
362 +gcc-plugins:
363 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
364 + $(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.))
365 +else
366 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
367 +endif
368 + $(Q)echo "PAX_MEMORY_STACKLEAK and other features will be less secure"
369 +endif
370 +endif
371 +
372 include $(srctree)/arch/$(SRCARCH)/Makefile
373
374 ifdef CONFIG_READABLE_ASM
375 @@ -715,7 +770,7 @@ export mod_strip_cmd
376
377
378 ifeq ($(KBUILD_EXTMOD),)
379 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
380 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
381
382 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
383 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
384 @@ -762,6 +817,8 @@ endif
385
386 # The actual objects are generated when descending,
387 # make sure no implicit rule kicks in
388 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
389 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
390 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
391
392 # Handle descending into subdirectories listed in $(vmlinux-dirs)
393 @@ -771,7 +828,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
394 # Error messages still appears in the original language
395
396 PHONY += $(vmlinux-dirs)
397 -$(vmlinux-dirs): prepare scripts
398 +$(vmlinux-dirs): gcc-plugins prepare scripts
399 $(Q)$(MAKE) $(build)=$@
400
401 # Store (new) KERNELRELASE string in include/config/kernel.release
402 @@ -815,6 +872,7 @@ prepare0: archprepare FORCE
403 $(Q)$(MAKE) $(build)=.
404
405 # All the preparing..
406 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
407 prepare: prepare0
408
409 # Generate some files
410 @@ -922,6 +980,8 @@ all: modules
411 # using awk while concatenating to the final file.
412
413 PHONY += modules
414 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
415 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
416 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
417 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
418 @$(kecho) ' Building modules, stage 2.';
419 @@ -937,7 +997,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
420
421 # Target to prepare building external modules
422 PHONY += modules_prepare
423 -modules_prepare: prepare scripts
424 +modules_prepare: gcc-plugins prepare scripts
425
426 # Target to install modules
427 PHONY += modules_install
428 @@ -994,7 +1054,7 @@ CLEAN_DIRS += $(MODVERDIR)
429 MRPROPER_DIRS += include/config usr/include include/generated \
430 arch/*/include/generated
431 MRPROPER_FILES += .config .config.old .version .old_version \
432 - include/linux/version.h \
433 + include/linux/version.h tools/gcc/size_overflow_hash.h\
434 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS
435
436 # clean - Delete most, but leave enough to build external modules
437 @@ -1032,6 +1092,7 @@ distclean: mrproper
438 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
439 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
440 -o -name '.*.rej' \
441 + -o -name '.*.rej' -o -name '*.so' \
442 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
443 -type f -print | xargs rm -f
444
445 @@ -1192,6 +1253,8 @@ PHONY += $(module-dirs) modules
446 $(module-dirs): crmodverdir $(objtree)/Module.symvers
447 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
448
449 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
450 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
451 modules: $(module-dirs)
452 @$(kecho) ' Building modules, stage 2.';
453 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
454 @@ -1326,17 +1389,21 @@ else
455 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
456 endif
457
458 -%.s: %.c prepare scripts FORCE
459 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
460 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
461 +%.s: %.c gcc-plugins prepare scripts FORCE
462 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
463 %.i: %.c prepare scripts FORCE
464 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
465 -%.o: %.c prepare scripts FORCE
466 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
467 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
468 +%.o: %.c gcc-plugins prepare scripts FORCE
469 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
470 %.lst: %.c prepare scripts FORCE
471 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
472 -%.s: %.S prepare scripts FORCE
473 +%.s: %.S gcc-plugins prepare scripts FORCE
474 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
475 -%.o: %.S prepare scripts FORCE
476 +%.o: %.S gcc-plugins prepare scripts FORCE
477 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
478 %.symtypes: %.c prepare scripts FORCE
479 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
480 @@ -1346,11 +1413,15 @@ endif
481 $(cmd_crmodverdir)
482 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
483 $(build)=$(build-dir)
484 -%/: prepare scripts FORCE
485 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
486 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
487 +%/: gcc-plugins prepare scripts FORCE
488 $(cmd_crmodverdir)
489 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
490 $(build)=$(build-dir)
491 -%.ko: prepare scripts FORCE
492 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
493 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
494 +%.ko: gcc-plugins prepare scripts FORCE
495 $(cmd_crmodverdir)
496 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
497 $(build)=$(build-dir) $(@:.ko=.o)
498 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
499 index c2cbe4f..f7264b4 100644
500 --- a/arch/alpha/include/asm/atomic.h
501 +++ b/arch/alpha/include/asm/atomic.h
502 @@ -250,6 +250,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
503 #define atomic_dec(v) atomic_sub(1,(v))
504 #define atomic64_dec(v) atomic64_sub(1,(v))
505
506 +#define atomic64_read_unchecked(v) atomic64_read(v)
507 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
508 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
509 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
510 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
511 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
512 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
513 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
514 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
515 +
516 #define smp_mb__before_atomic_dec() smp_mb()
517 #define smp_mb__after_atomic_dec() smp_mb()
518 #define smp_mb__before_atomic_inc() smp_mb()
519 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
520 index ad368a9..fbe0f25 100644
521 --- a/arch/alpha/include/asm/cache.h
522 +++ b/arch/alpha/include/asm/cache.h
523 @@ -4,19 +4,19 @@
524 #ifndef __ARCH_ALPHA_CACHE_H
525 #define __ARCH_ALPHA_CACHE_H
526
527 +#include <linux/const.h>
528
529 /* Bytes per L1 (data) cache line. */
530 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
531 -# define L1_CACHE_BYTES 64
532 # define L1_CACHE_SHIFT 6
533 #else
534 /* Both EV4 and EV5 are write-through, read-allocate,
535 direct-mapped, physical.
536 */
537 -# define L1_CACHE_BYTES 32
538 # define L1_CACHE_SHIFT 5
539 #endif
540
541 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
542 #define SMP_CACHE_BYTES L1_CACHE_BYTES
543
544 #endif
545 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
546 index 968d999..d36b2df 100644
547 --- a/arch/alpha/include/asm/elf.h
548 +++ b/arch/alpha/include/asm/elf.h
549 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
550
551 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
552
553 +#ifdef CONFIG_PAX_ASLR
554 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
555 +
556 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
557 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
558 +#endif
559 +
560 /* $0 is set by ld.so to a pointer to a function which might be
561 registered using atexit. This provides a mean for the dynamic
562 linker to call DT_FINI functions for shared libraries that have
563 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
564 index bc2a0da..8ad11ee 100644
565 --- a/arch/alpha/include/asm/pgalloc.h
566 +++ b/arch/alpha/include/asm/pgalloc.h
567 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
568 pgd_set(pgd, pmd);
569 }
570
571 +static inline void
572 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
573 +{
574 + pgd_populate(mm, pgd, pmd);
575 +}
576 +
577 extern pgd_t *pgd_alloc(struct mm_struct *mm);
578
579 static inline void
580 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
581 index 81a4342..348b927 100644
582 --- a/arch/alpha/include/asm/pgtable.h
583 +++ b/arch/alpha/include/asm/pgtable.h
584 @@ -102,6 +102,17 @@ struct vm_area_struct;
585 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
586 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
587 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
588 +
589 +#ifdef CONFIG_PAX_PAGEEXEC
590 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
591 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
592 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
593 +#else
594 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
595 +# define PAGE_COPY_NOEXEC PAGE_COPY
596 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
597 +#endif
598 +
599 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
600
601 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
602 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
603 index 2fd00b7..cfd5069 100644
604 --- a/arch/alpha/kernel/module.c
605 +++ b/arch/alpha/kernel/module.c
606 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
607
608 /* The small sections were sorted to the end of the segment.
609 The following should definitely cover them. */
610 - gp = (u64)me->module_core + me->core_size - 0x8000;
611 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
612 got = sechdrs[me->arch.gotsecindex].sh_addr;
613
614 for (i = 0; i < n; i++) {
615 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
616 index 98a1036..fb54ccf 100644
617 --- a/arch/alpha/kernel/osf_sys.c
618 +++ b/arch/alpha/kernel/osf_sys.c
619 @@ -1312,7 +1312,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
620 /* At this point: (!vma || addr < vma->vm_end). */
621 if (limit - len < addr)
622 return -ENOMEM;
623 - if (!vma || addr + len <= vma->vm_start)
624 + if (check_heap_stack_gap(vma, addr, len))
625 return addr;
626 addr = vma->vm_end;
627 vma = vma->vm_next;
628 @@ -1348,6 +1348,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
629 merely specific addresses, but regions of memory -- perhaps
630 this feature should be incorporated into all ports? */
631
632 +#ifdef CONFIG_PAX_RANDMMAP
633 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
634 +#endif
635 +
636 if (addr) {
637 addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
638 if (addr != (unsigned long) -ENOMEM)
639 @@ -1355,8 +1359,8 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
640 }
641
642 /* Next, try allocating at TASK_UNMAPPED_BASE. */
643 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
644 - len, limit);
645 + addr = arch_get_unmapped_area_1 (PAGE_ALIGN(current->mm->mmap_base), len, limit);
646 +
647 if (addr != (unsigned long) -ENOMEM)
648 return addr;
649
650 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
651 index 5eecab1..609abc0 100644
652 --- a/arch/alpha/mm/fault.c
653 +++ b/arch/alpha/mm/fault.c
654 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
655 __reload_thread(pcb);
656 }
657
658 +#ifdef CONFIG_PAX_PAGEEXEC
659 +/*
660 + * PaX: decide what to do with offenders (regs->pc = fault address)
661 + *
662 + * returns 1 when task should be killed
663 + * 2 when patched PLT trampoline was detected
664 + * 3 when unpatched PLT trampoline was detected
665 + */
666 +static int pax_handle_fetch_fault(struct pt_regs *regs)
667 +{
668 +
669 +#ifdef CONFIG_PAX_EMUPLT
670 + int err;
671 +
672 + do { /* PaX: patched PLT emulation #1 */
673 + unsigned int ldah, ldq, jmp;
674 +
675 + err = get_user(ldah, (unsigned int *)regs->pc);
676 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
677 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
678 +
679 + if (err)
680 + break;
681 +
682 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
683 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
684 + jmp == 0x6BFB0000U)
685 + {
686 + unsigned long r27, addr;
687 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
688 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
689 +
690 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
691 + err = get_user(r27, (unsigned long *)addr);
692 + if (err)
693 + break;
694 +
695 + regs->r27 = r27;
696 + regs->pc = r27;
697 + return 2;
698 + }
699 + } while (0);
700 +
701 + do { /* PaX: patched PLT emulation #2 */
702 + unsigned int ldah, lda, br;
703 +
704 + err = get_user(ldah, (unsigned int *)regs->pc);
705 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
706 + err |= get_user(br, (unsigned int *)(regs->pc+8));
707 +
708 + if (err)
709 + break;
710 +
711 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
712 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
713 + (br & 0xFFE00000U) == 0xC3E00000U)
714 + {
715 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
716 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
717 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
718 +
719 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
720 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
721 + return 2;
722 + }
723 + } while (0);
724 +
725 + do { /* PaX: unpatched PLT emulation */
726 + unsigned int br;
727 +
728 + err = get_user(br, (unsigned int *)regs->pc);
729 +
730 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
731 + unsigned int br2, ldq, nop, jmp;
732 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
733 +
734 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
735 + err = get_user(br2, (unsigned int *)addr);
736 + err |= get_user(ldq, (unsigned int *)(addr+4));
737 + err |= get_user(nop, (unsigned int *)(addr+8));
738 + err |= get_user(jmp, (unsigned int *)(addr+12));
739 + err |= get_user(resolver, (unsigned long *)(addr+16));
740 +
741 + if (err)
742 + break;
743 +
744 + if (br2 == 0xC3600000U &&
745 + ldq == 0xA77B000CU &&
746 + nop == 0x47FF041FU &&
747 + jmp == 0x6B7B0000U)
748 + {
749 + regs->r28 = regs->pc+4;
750 + regs->r27 = addr+16;
751 + regs->pc = resolver;
752 + return 3;
753 + }
754 + }
755 + } while (0);
756 +#endif
757 +
758 + return 1;
759 +}
760 +
761 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
762 +{
763 + unsigned long i;
764 +
765 + printk(KERN_ERR "PAX: bytes at PC: ");
766 + for (i = 0; i < 5; i++) {
767 + unsigned int c;
768 + if (get_user(c, (unsigned int *)pc+i))
769 + printk(KERN_CONT "???????? ");
770 + else
771 + printk(KERN_CONT "%08x ", c);
772 + }
773 + printk("\n");
774 +}
775 +#endif
776
777 /*
778 * This routine handles page faults. It determines the address,
779 @@ -130,8 +248,29 @@ do_page_fault(unsigned long address, unsigned long mmcsr,
780 good_area:
781 si_code = SEGV_ACCERR;
782 if (cause < 0) {
783 - if (!(vma->vm_flags & VM_EXEC))
784 + if (!(vma->vm_flags & VM_EXEC)) {
785 +
786 +#ifdef CONFIG_PAX_PAGEEXEC
787 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
788 + goto bad_area;
789 +
790 + up_read(&mm->mmap_sem);
791 + switch (pax_handle_fetch_fault(regs)) {
792 +
793 +#ifdef CONFIG_PAX_EMUPLT
794 + case 2:
795 + case 3:
796 + return;
797 +#endif
798 +
799 + }
800 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
801 + do_group_exit(SIGKILL);
802 +#else
803 goto bad_area;
804 +#endif
805 +
806 + }
807 } else if (!cause) {
808 /* Allow reads even for write-only mappings */
809 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
810 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
811 index c79f61f..9ac0642 100644
812 --- a/arch/arm/include/asm/atomic.h
813 +++ b/arch/arm/include/asm/atomic.h
814 @@ -17,17 +17,35 @@
815 #include <asm/barrier.h>
816 #include <asm/cmpxchg.h>
817
818 +#ifdef CONFIG_GENERIC_ATOMIC64
819 +#include <asm-generic/atomic64.h>
820 +#endif
821 +
822 #define ATOMIC_INIT(i) { (i) }
823
824 #ifdef __KERNEL__
825
826 +#define _ASM_EXTABLE(from, to) \
827 +" .pushsection __ex_table,\"a\"\n"\
828 +" .align 3\n" \
829 +" .long " #from ", " #to"\n" \
830 +" .popsection"
831 +
832 /*
833 * On ARM, ordinary assignment (str instruction) doesn't clear the local
834 * strex/ldrex monitor on some implementations. The reason we can use it for
835 * atomic_set() is the clrex or dummy strex done on every exception return.
836 */
837 #define atomic_read(v) (*(volatile int *)&(v)->counter)
838 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
839 +{
840 + return v->counter;
841 +}
842 #define atomic_set(v,i) (((v)->counter) = (i))
843 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
844 +{
845 + v->counter = i;
846 +}
847
848 #if __LINUX_ARM_ARCH__ >= 6
849
850 @@ -42,6 +60,35 @@ static inline void atomic_add(int i, atomic_t *v)
851 int result;
852
853 __asm__ __volatile__("@ atomic_add\n"
854 +"1: ldrex %1, [%3]\n"
855 +" adds %0, %1, %4\n"
856 +
857 +#ifdef CONFIG_PAX_REFCOUNT
858 +" bvc 3f\n"
859 +"2: bkpt 0xf103\n"
860 +"3:\n"
861 +#endif
862 +
863 +" strex %1, %0, [%3]\n"
864 +" teq %1, #0\n"
865 +" bne 1b"
866 +
867 +#ifdef CONFIG_PAX_REFCOUNT
868 +"\n4:\n"
869 + _ASM_EXTABLE(2b, 4b)
870 +#endif
871 +
872 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
873 + : "r" (&v->counter), "Ir" (i)
874 + : "cc");
875 +}
876 +
877 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
878 +{
879 + unsigned long tmp;
880 + int result;
881 +
882 + __asm__ __volatile__("@ atomic_add_unchecked\n"
883 "1: ldrex %0, [%3]\n"
884 " add %0, %0, %4\n"
885 " strex %1, %0, [%3]\n"
886 @@ -60,6 +107,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
887 smp_mb();
888
889 __asm__ __volatile__("@ atomic_add_return\n"
890 +"1: ldrex %1, [%3]\n"
891 +" adds %0, %1, %4\n"
892 +
893 +#ifdef CONFIG_PAX_REFCOUNT
894 +" bvc 3f\n"
895 +" mov %0, %1\n"
896 +"2: bkpt 0xf103\n"
897 +"3:\n"
898 +#endif
899 +
900 +" strex %1, %0, [%3]\n"
901 +" teq %1, #0\n"
902 +" bne 1b"
903 +
904 +#ifdef CONFIG_PAX_REFCOUNT
905 +"\n4:\n"
906 + _ASM_EXTABLE(2b, 4b)
907 +#endif
908 +
909 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
910 + : "r" (&v->counter), "Ir" (i)
911 + : "cc");
912 +
913 + smp_mb();
914 +
915 + return result;
916 +}
917 +
918 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
919 +{
920 + unsigned long tmp;
921 + int result;
922 +
923 + smp_mb();
924 +
925 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
926 "1: ldrex %0, [%3]\n"
927 " add %0, %0, %4\n"
928 " strex %1, %0, [%3]\n"
929 @@ -80,6 +163,35 @@ static inline void atomic_sub(int i, atomic_t *v)
930 int result;
931
932 __asm__ __volatile__("@ atomic_sub\n"
933 +"1: ldrex %1, [%3]\n"
934 +" subs %0, %1, %4\n"
935 +
936 +#ifdef CONFIG_PAX_REFCOUNT
937 +" bvc 3f\n"
938 +"2: bkpt 0xf103\n"
939 +"3:\n"
940 +#endif
941 +
942 +" strex %1, %0, [%3]\n"
943 +" teq %1, #0\n"
944 +" bne 1b"
945 +
946 +#ifdef CONFIG_PAX_REFCOUNT
947 +"\n4:\n"
948 + _ASM_EXTABLE(2b, 4b)
949 +#endif
950 +
951 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
952 + : "r" (&v->counter), "Ir" (i)
953 + : "cc");
954 +}
955 +
956 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
957 +{
958 + unsigned long tmp;
959 + int result;
960 +
961 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
962 "1: ldrex %0, [%3]\n"
963 " sub %0, %0, %4\n"
964 " strex %1, %0, [%3]\n"
965 @@ -98,11 +210,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
966 smp_mb();
967
968 __asm__ __volatile__("@ atomic_sub_return\n"
969 -"1: ldrex %0, [%3]\n"
970 -" sub %0, %0, %4\n"
971 +"1: ldrex %1, [%3]\n"
972 +" subs %0, %1, %4\n"
973 +
974 +#ifdef CONFIG_PAX_REFCOUNT
975 +" bvc 3f\n"
976 +" mov %0, %1\n"
977 +"2: bkpt 0xf103\n"
978 +"3:\n"
979 +#endif
980 +
981 " strex %1, %0, [%3]\n"
982 " teq %1, #0\n"
983 " bne 1b"
984 +
985 +#ifdef CONFIG_PAX_REFCOUNT
986 +"\n4:\n"
987 + _ASM_EXTABLE(2b, 4b)
988 +#endif
989 +
990 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
991 : "r" (&v->counter), "Ir" (i)
992 : "cc");
993 @@ -134,6 +260,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
994 return oldval;
995 }
996
997 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
998 +{
999 + unsigned long oldval, res;
1000 +
1001 + smp_mb();
1002 +
1003 + do {
1004 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1005 + "ldrex %1, [%3]\n"
1006 + "mov %0, #0\n"
1007 + "teq %1, %4\n"
1008 + "strexeq %0, %5, [%3]\n"
1009 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1010 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1011 + : "cc");
1012 + } while (res);
1013 +
1014 + smp_mb();
1015 +
1016 + return oldval;
1017 +}
1018 +
1019 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1020 {
1021 unsigned long tmp, tmp2;
1022 @@ -167,7 +315,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1023
1024 return val;
1025 }
1026 +
1027 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1028 +{
1029 + return atomic_add_return(i, v);
1030 +}
1031 +
1032 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1033 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1034 +{
1035 + (void) atomic_add_return(i, v);
1036 +}
1037
1038 static inline int atomic_sub_return(int i, atomic_t *v)
1039 {
1040 @@ -182,6 +340,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1041 return val;
1042 }
1043 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1044 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1045 +{
1046 + (void) atomic_sub_return(i, v);
1047 +}
1048
1049 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1050 {
1051 @@ -197,6 +359,11 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1052 return ret;
1053 }
1054
1055 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1056 +{
1057 + return atomic_cmpxchg(v, old, new);
1058 +}
1059 +
1060 static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1061 {
1062 unsigned long flags;
1063 @@ -209,6 +376,10 @@ static inline void atomic_clear_mask(unsigned long mask, unsigned long *addr)
1064 #endif /* __LINUX_ARM_ARCH__ */
1065
1066 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1067 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1068 +{
1069 + return xchg(&v->counter, new);
1070 +}
1071
1072 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1073 {
1074 @@ -221,11 +392,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1075 }
1076
1077 #define atomic_inc(v) atomic_add(1, v)
1078 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1079 +{
1080 + atomic_add_unchecked(1, v);
1081 +}
1082 #define atomic_dec(v) atomic_sub(1, v)
1083 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1084 +{
1085 + atomic_sub_unchecked(1, v);
1086 +}
1087
1088 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1089 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1090 +{
1091 + return atomic_add_return_unchecked(1, v) == 0;
1092 +}
1093 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1094 #define atomic_inc_return(v) (atomic_add_return(1, v))
1095 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1096 +{
1097 + return atomic_add_return_unchecked(1, v);
1098 +}
1099 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1100 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1101
1102 @@ -241,6 +428,14 @@ typedef struct {
1103 u64 __aligned(8) counter;
1104 } atomic64_t;
1105
1106 +#ifdef CONFIG_PAX_REFCOUNT
1107 +typedef struct {
1108 + u64 __aligned(8) counter;
1109 +} atomic64_unchecked_t;
1110 +#else
1111 +typedef atomic64_t atomic64_unchecked_t;
1112 +#endif
1113 +
1114 #define ATOMIC64_INIT(i) { (i) }
1115
1116 static inline u64 atomic64_read(const atomic64_t *v)
1117 @@ -256,6 +451,19 @@ static inline u64 atomic64_read(const atomic64_t *v)
1118 return result;
1119 }
1120
1121 +static inline u64 atomic64_read_unchecked(atomic64_unchecked_t *v)
1122 +{
1123 + u64 result;
1124 +
1125 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1126 +" ldrexd %0, %H0, [%1]"
1127 + : "=&r" (result)
1128 + : "r" (&v->counter), "Qo" (v->counter)
1129 + );
1130 +
1131 + return result;
1132 +}
1133 +
1134 static inline void atomic64_set(atomic64_t *v, u64 i)
1135 {
1136 u64 tmp;
1137 @@ -270,6 +478,20 @@ static inline void atomic64_set(atomic64_t *v, u64 i)
1138 : "cc");
1139 }
1140
1141 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, u64 i)
1142 +{
1143 + u64 tmp;
1144 +
1145 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1146 +"1: ldrexd %0, %H0, [%2]\n"
1147 +" strexd %0, %3, %H3, [%2]\n"
1148 +" teq %0, #0\n"
1149 +" bne 1b"
1150 + : "=&r" (tmp), "=Qo" (v->counter)
1151 + : "r" (&v->counter), "r" (i)
1152 + : "cc");
1153 +}
1154 +
1155 static inline void atomic64_add(u64 i, atomic64_t *v)
1156 {
1157 u64 result;
1158 @@ -278,6 +500,36 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1159 __asm__ __volatile__("@ atomic64_add\n"
1160 "1: ldrexd %0, %H0, [%3]\n"
1161 " adds %0, %0, %4\n"
1162 +" adcs %H0, %H0, %H4\n"
1163 +
1164 +#ifdef CONFIG_PAX_REFCOUNT
1165 +" bvc 3f\n"
1166 +"2: bkpt 0xf103\n"
1167 +"3:\n"
1168 +#endif
1169 +
1170 +" strexd %1, %0, %H0, [%3]\n"
1171 +" teq %1, #0\n"
1172 +" bne 1b"
1173 +
1174 +#ifdef CONFIG_PAX_REFCOUNT
1175 +"\n4:\n"
1176 + _ASM_EXTABLE(2b, 4b)
1177 +#endif
1178 +
1179 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1180 + : "r" (&v->counter), "r" (i)
1181 + : "cc");
1182 +}
1183 +
1184 +static inline void atomic64_add_unchecked(u64 i, atomic64_unchecked_t *v)
1185 +{
1186 + u64 result;
1187 + unsigned long tmp;
1188 +
1189 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1190 +"1: ldrexd %0, %H0, [%3]\n"
1191 +" adds %0, %0, %4\n"
1192 " adc %H0, %H0, %H4\n"
1193 " strexd %1, %0, %H0, [%3]\n"
1194 " teq %1, #0\n"
1195 @@ -289,12 +541,49 @@ static inline void atomic64_add(u64 i, atomic64_t *v)
1196
1197 static inline u64 atomic64_add_return(u64 i, atomic64_t *v)
1198 {
1199 - u64 result;
1200 - unsigned long tmp;
1201 + u64 result, tmp;
1202
1203 smp_mb();
1204
1205 __asm__ __volatile__("@ atomic64_add_return\n"
1206 +"1: ldrexd %1, %H1, [%3]\n"
1207 +" adds %0, %1, %4\n"
1208 +" adcs %H0, %H1, %H4\n"
1209 +
1210 +#ifdef CONFIG_PAX_REFCOUNT
1211 +" bvc 3f\n"
1212 +" mov %0, %1\n"
1213 +" mov %H0, %H1\n"
1214 +"2: bkpt 0xf103\n"
1215 +"3:\n"
1216 +#endif
1217 +
1218 +" strexd %1, %0, %H0, [%3]\n"
1219 +" teq %1, #0\n"
1220 +" bne 1b"
1221 +
1222 +#ifdef CONFIG_PAX_REFCOUNT
1223 +"\n4:\n"
1224 + _ASM_EXTABLE(2b, 4b)
1225 +#endif
1226 +
1227 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1228 + : "r" (&v->counter), "r" (i)
1229 + : "cc");
1230 +
1231 + smp_mb();
1232 +
1233 + return result;
1234 +}
1235 +
1236 +static inline u64 atomic64_add_return_unchecked(u64 i, atomic64_unchecked_t *v)
1237 +{
1238 + u64 result;
1239 + unsigned long tmp;
1240 +
1241 + smp_mb();
1242 +
1243 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1244 "1: ldrexd %0, %H0, [%3]\n"
1245 " adds %0, %0, %4\n"
1246 " adc %H0, %H0, %H4\n"
1247 @@ -318,6 +607,36 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1248 __asm__ __volatile__("@ atomic64_sub\n"
1249 "1: ldrexd %0, %H0, [%3]\n"
1250 " subs %0, %0, %4\n"
1251 +" sbcs %H0, %H0, %H4\n"
1252 +
1253 +#ifdef CONFIG_PAX_REFCOUNT
1254 +" bvc 3f\n"
1255 +"2: bkpt 0xf103\n"
1256 +"3:\n"
1257 +#endif
1258 +
1259 +" strexd %1, %0, %H0, [%3]\n"
1260 +" teq %1, #0\n"
1261 +" bne 1b"
1262 +
1263 +#ifdef CONFIG_PAX_REFCOUNT
1264 +"\n4:\n"
1265 + _ASM_EXTABLE(2b, 4b)
1266 +#endif
1267 +
1268 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1269 + : "r" (&v->counter), "r" (i)
1270 + : "cc");
1271 +}
1272 +
1273 +static inline void atomic64_sub_unchecked(u64 i, atomic64_unchecked_t *v)
1274 +{
1275 + u64 result;
1276 + unsigned long tmp;
1277 +
1278 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1279 +"1: ldrexd %0, %H0, [%3]\n"
1280 +" subs %0, %0, %4\n"
1281 " sbc %H0, %H0, %H4\n"
1282 " strexd %1, %0, %H0, [%3]\n"
1283 " teq %1, #0\n"
1284 @@ -329,18 +648,32 @@ static inline void atomic64_sub(u64 i, atomic64_t *v)
1285
1286 static inline u64 atomic64_sub_return(u64 i, atomic64_t *v)
1287 {
1288 - u64 result;
1289 - unsigned long tmp;
1290 + u64 result, tmp;
1291
1292 smp_mb();
1293
1294 __asm__ __volatile__("@ atomic64_sub_return\n"
1295 -"1: ldrexd %0, %H0, [%3]\n"
1296 -" subs %0, %0, %4\n"
1297 -" sbc %H0, %H0, %H4\n"
1298 +"1: ldrexd %1, %H1, [%3]\n"
1299 +" subs %0, %1, %4\n"
1300 +" sbcs %H0, %H1, %H4\n"
1301 +
1302 +#ifdef CONFIG_PAX_REFCOUNT
1303 +" bvc 3f\n"
1304 +" mov %0, %1\n"
1305 +" mov %H0, %H1\n"
1306 +"2: bkpt 0xf103\n"
1307 +"3:\n"
1308 +#endif
1309 +
1310 " strexd %1, %0, %H0, [%3]\n"
1311 " teq %1, #0\n"
1312 " bne 1b"
1313 +
1314 +#ifdef CONFIG_PAX_REFCOUNT
1315 +"\n4:\n"
1316 + _ASM_EXTABLE(2b, 4b)
1317 +#endif
1318 +
1319 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1320 : "r" (&v->counter), "r" (i)
1321 : "cc");
1322 @@ -374,6 +707,30 @@ static inline u64 atomic64_cmpxchg(atomic64_t *ptr, u64 old, u64 new)
1323 return oldval;
1324 }
1325
1326 +static inline u64 atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, u64 old, u64 new)
1327 +{
1328 + u64 oldval;
1329 + unsigned long res;
1330 +
1331 + smp_mb();
1332 +
1333 + do {
1334 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1335 + "ldrexd %1, %H1, [%3]\n"
1336 + "mov %0, #0\n"
1337 + "teq %1, %4\n"
1338 + "teqeq %H1, %H4\n"
1339 + "strexdeq %0, %5, %H5, [%3]"
1340 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1341 + : "r" (&ptr->counter), "r" (old), "r" (new)
1342 + : "cc");
1343 + } while (res);
1344 +
1345 + smp_mb();
1346 +
1347 + return oldval;
1348 +}
1349 +
1350 static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1351 {
1352 u64 result;
1353 @@ -397,21 +754,34 @@ static inline u64 atomic64_xchg(atomic64_t *ptr, u64 new)
1354
1355 static inline u64 atomic64_dec_if_positive(atomic64_t *v)
1356 {
1357 - u64 result;
1358 - unsigned long tmp;
1359 + u64 result, tmp;
1360
1361 smp_mb();
1362
1363 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1364 -"1: ldrexd %0, %H0, [%3]\n"
1365 -" subs %0, %0, #1\n"
1366 -" sbc %H0, %H0, #0\n"
1367 +"1: ldrexd %1, %H1, [%3]\n"
1368 +" subs %0, %1, #1\n"
1369 +" sbcs %H0, %H1, #0\n"
1370 +
1371 +#ifdef CONFIG_PAX_REFCOUNT
1372 +" bvc 3f\n"
1373 +" mov %0, %1\n"
1374 +" mov %H0, %H1\n"
1375 +"2: bkpt 0xf103\n"
1376 +"3:\n"
1377 +#endif
1378 +
1379 " teq %H0, #0\n"
1380 -" bmi 2f\n"
1381 +" bmi 4f\n"
1382 " strexd %1, %0, %H0, [%3]\n"
1383 " teq %1, #0\n"
1384 " bne 1b\n"
1385 -"2:"
1386 +"4:\n"
1387 +
1388 +#ifdef CONFIG_PAX_REFCOUNT
1389 + _ASM_EXTABLE(2b, 4b)
1390 +#endif
1391 +
1392 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1393 : "r" (&v->counter)
1394 : "cc");
1395 @@ -434,13 +804,25 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1396 " teq %0, %5\n"
1397 " teqeq %H0, %H5\n"
1398 " moveq %1, #0\n"
1399 -" beq 2f\n"
1400 +" beq 4f\n"
1401 " adds %0, %0, %6\n"
1402 -" adc %H0, %H0, %H6\n"
1403 +" adcs %H0, %H0, %H6\n"
1404 +
1405 +#ifdef CONFIG_PAX_REFCOUNT
1406 +" bvc 3f\n"
1407 +"2: bkpt 0xf103\n"
1408 +"3:\n"
1409 +#endif
1410 +
1411 " strexd %2, %0, %H0, [%4]\n"
1412 " teq %2, #0\n"
1413 " bne 1b\n"
1414 -"2:"
1415 +"4:\n"
1416 +
1417 +#ifdef CONFIG_PAX_REFCOUNT
1418 + _ASM_EXTABLE(2b, 4b)
1419 +#endif
1420 +
1421 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1422 : "r" (&v->counter), "r" (u), "r" (a)
1423 : "cc");
1424 @@ -453,10 +835,13 @@ static inline int atomic64_add_unless(atomic64_t *v, u64 a, u64 u)
1425
1426 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1427 #define atomic64_inc(v) atomic64_add(1LL, (v))
1428 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1429 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1430 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1431 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1432 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1433 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1434 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1435 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1436 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1437 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1438 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1439 index 75fe66b..2255c86 100644
1440 --- a/arch/arm/include/asm/cache.h
1441 +++ b/arch/arm/include/asm/cache.h
1442 @@ -4,8 +4,10 @@
1443 #ifndef __ASMARM_CACHE_H
1444 #define __ASMARM_CACHE_H
1445
1446 +#include <linux/const.h>
1447 +
1448 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1449 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1450 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1451
1452 /*
1453 * Memory returned by kmalloc() may be used for DMA, so we must make
1454 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1455 index e4448e1..7bc86b7 100644
1456 --- a/arch/arm/include/asm/cacheflush.h
1457 +++ b/arch/arm/include/asm/cacheflush.h
1458 @@ -108,7 +108,7 @@ struct cpu_cache_fns {
1459 void (*dma_unmap_area)(const void *, size_t, int);
1460
1461 void (*dma_flush_range)(const void *, const void *);
1462 -};
1463 +} __no_const;
1464
1465 /*
1466 * Select the calling method
1467 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1468 index 7eb18c1..e38b6d2 100644
1469 --- a/arch/arm/include/asm/cmpxchg.h
1470 +++ b/arch/arm/include/asm/cmpxchg.h
1471 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1472
1473 #define xchg(ptr,x) \
1474 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1475 +#define xchg_unchecked(ptr,x) \
1476 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1477
1478 #include <asm-generic/cmpxchg-local.h>
1479
1480 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1481 index 38050b1..9d90e8b 100644
1482 --- a/arch/arm/include/asm/elf.h
1483 +++ b/arch/arm/include/asm/elf.h
1484 @@ -116,7 +116,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1485 the loader. We need to make sure that it is out of the way of the program
1486 that it will "exec", and that there is sufficient room for the brk. */
1487
1488 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1489 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1490 +
1491 +#ifdef CONFIG_PAX_ASLR
1492 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1493 +
1494 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1495 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1496 +#endif
1497
1498 /* When the program starts, a1 contains a pointer to a function to be
1499 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1500 @@ -126,8 +133,4 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1501 extern void elf_set_personality(const struct elf32_hdr *);
1502 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1503
1504 -struct mm_struct;
1505 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1506 -#define arch_randomize_brk arch_randomize_brk
1507 -
1508 #endif
1509 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1510 index e51b1e8..32a3113 100644
1511 --- a/arch/arm/include/asm/kmap_types.h
1512 +++ b/arch/arm/include/asm/kmap_types.h
1513 @@ -21,6 +21,7 @@ enum km_type {
1514 KM_L1_CACHE,
1515 KM_L2_CACHE,
1516 KM_KDB,
1517 + KM_CLEARPAGE,
1518 KM_TYPE_NR
1519 };
1520
1521 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1522 index 53426c6..c7baff3 100644
1523 --- a/arch/arm/include/asm/outercache.h
1524 +++ b/arch/arm/include/asm/outercache.h
1525 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1526 #endif
1527 void (*set_debug)(unsigned long);
1528 void (*resume)(void);
1529 -};
1530 +} __no_const;
1531
1532 #ifdef CONFIG_OUTER_CACHE
1533
1534 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1535 index ecf9019..b71d9a1 100644
1536 --- a/arch/arm/include/asm/page.h
1537 +++ b/arch/arm/include/asm/page.h
1538 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1539 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1540 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1541 unsigned long vaddr, struct vm_area_struct *vma);
1542 -};
1543 +} __no_const;
1544
1545 #ifdef MULTI_USER
1546 extern struct cpu_user_fns cpu_user;
1547 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1548 index 943504f..bf8d667 100644
1549 --- a/arch/arm/include/asm/pgalloc.h
1550 +++ b/arch/arm/include/asm/pgalloc.h
1551 @@ -43,6 +43,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1552 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1553 }
1554
1555 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1556 +{
1557 + pud_populate(mm, pud, pmd);
1558 +}
1559 +
1560 #else /* !CONFIG_ARM_LPAE */
1561
1562 /*
1563 @@ -51,6 +56,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1564 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1565 #define pmd_free(mm, pmd) do { } while (0)
1566 #define pud_populate(mm,pmd,pte) BUG()
1567 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1568
1569 #endif /* CONFIG_ARM_LPAE */
1570
1571 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
1572 index af7b0bd..6750a8c 100644
1573 --- a/arch/arm/include/asm/thread_info.h
1574 +++ b/arch/arm/include/asm/thread_info.h
1575 @@ -148,6 +148,12 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1576 #define TIF_NOTIFY_RESUME 2 /* callback before returning to user */
1577 #define TIF_SYSCALL_TRACE 8
1578 #define TIF_SYSCALL_AUDIT 9
1579 +
1580 +/* within 8 bits of TIF_SYSCALL_TRACE
1581 + to meet flexible second operand requirements
1582 +*/
1583 +#define TIF_GRSEC_SETXID 10
1584 +
1585 #define TIF_POLLING_NRFLAG 16
1586 #define TIF_USING_IWMMXT 17
1587 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
1588 @@ -163,9 +169,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
1589 #define _TIF_POLLING_NRFLAG (1 << TIF_POLLING_NRFLAG)
1590 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
1591 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
1592 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
1593
1594 /* Checks for any syscall work in entry-common.S */
1595 -#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
1596 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
1597 + _TIF_GRSEC_SETXID)
1598
1599 /*
1600 * Change these and you break ASM code in entry-common.S
1601 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
1602 index 0a070e9..9e9e129 100644
1603 --- a/arch/arm/include/asm/uaccess.h
1604 +++ b/arch/arm/include/asm/uaccess.h
1605 @@ -22,6 +22,8 @@
1606 #define VERIFY_READ 0
1607 #define VERIFY_WRITE 1
1608
1609 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
1610 +
1611 /*
1612 * The exception table consists of pairs of addresses: the first is the
1613 * address of an instruction that is allowed to fault, and the second is
1614 @@ -401,8 +403,23 @@ do { \
1615
1616
1617 #ifdef CONFIG_MMU
1618 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
1619 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
1620 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
1621 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
1622 +
1623 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
1624 +{
1625 + if (!__builtin_constant_p(n))
1626 + check_object_size(to, n, false);
1627 + return ___copy_from_user(to, from, n);
1628 +}
1629 +
1630 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
1631 +{
1632 + if (!__builtin_constant_p(n))
1633 + check_object_size(from, n, true);
1634 + return ___copy_to_user(to, from, n);
1635 +}
1636 +
1637 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
1638 extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
1639 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
1640 @@ -417,6 +434,9 @@ extern unsigned long __must_check __strnlen_user(const char __user *s, long n);
1641
1642 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
1643 {
1644 + if ((long)n < 0)
1645 + return n;
1646 +
1647 if (access_ok(VERIFY_READ, from, n))
1648 n = __copy_from_user(to, from, n);
1649 else /* security hole - plug it */
1650 @@ -426,6 +446,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
1651
1652 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
1653 {
1654 + if ((long)n < 0)
1655 + return n;
1656 +
1657 if (access_ok(VERIFY_WRITE, to, n))
1658 n = __copy_to_user(to, from, n);
1659 return n;
1660 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
1661 index b57c75e..ed2d6b2 100644
1662 --- a/arch/arm/kernel/armksyms.c
1663 +++ b/arch/arm/kernel/armksyms.c
1664 @@ -94,8 +94,8 @@ EXPORT_SYMBOL(__strncpy_from_user);
1665 #ifdef CONFIG_MMU
1666 EXPORT_SYMBOL(copy_page);
1667
1668 -EXPORT_SYMBOL(__copy_from_user);
1669 -EXPORT_SYMBOL(__copy_to_user);
1670 +EXPORT_SYMBOL(___copy_from_user);
1671 +EXPORT_SYMBOL(___copy_to_user);
1672 EXPORT_SYMBOL(__clear_user);
1673
1674 EXPORT_SYMBOL(__get_user_1);
1675 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
1676 index 693b744..e684262 100644
1677 --- a/arch/arm/kernel/process.c
1678 +++ b/arch/arm/kernel/process.c
1679 @@ -28,7 +28,6 @@
1680 #include <linux/tick.h>
1681 #include <linux/utsname.h>
1682 #include <linux/uaccess.h>
1683 -#include <linux/random.h>
1684 #include <linux/hw_breakpoint.h>
1685 #include <linux/cpuidle.h>
1686
1687 @@ -256,9 +255,10 @@ void machine_power_off(void)
1688 machine_shutdown();
1689 if (pm_power_off)
1690 pm_power_off();
1691 + BUG();
1692 }
1693
1694 -void machine_restart(char *cmd)
1695 +__noreturn void machine_restart(char *cmd)
1696 {
1697 machine_shutdown();
1698
1699 @@ -501,12 +501,6 @@ unsigned long get_wchan(struct task_struct *p)
1700 return 0;
1701 }
1702
1703 -unsigned long arch_randomize_brk(struct mm_struct *mm)
1704 -{
1705 - unsigned long range_end = mm->brk + 0x02000000;
1706 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
1707 -}
1708 -
1709 #ifdef CONFIG_MMU
1710 /*
1711 * The vectors page is always readable from user space for the
1712 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
1713 index 14e3826..d832d89 100644
1714 --- a/arch/arm/kernel/ptrace.c
1715 +++ b/arch/arm/kernel/ptrace.c
1716 @@ -907,10 +907,19 @@ long arch_ptrace(struct task_struct *child, long request,
1717 return ret;
1718 }
1719
1720 +#ifdef CONFIG_GRKERNSEC_SETXID
1721 +extern void gr_delayed_cred_worker(void);
1722 +#endif
1723 +
1724 asmlinkage int syscall_trace(int why, struct pt_regs *regs, int scno)
1725 {
1726 unsigned long ip;
1727
1728 +#ifdef CONFIG_GRKERNSEC_SETXID
1729 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
1730 + gr_delayed_cred_worker();
1731 +#endif
1732 +
1733 if (why)
1734 audit_syscall_exit(regs);
1735 else
1736 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
1737 index e15d83b..8c466dd 100644
1738 --- a/arch/arm/kernel/setup.c
1739 +++ b/arch/arm/kernel/setup.c
1740 @@ -112,13 +112,13 @@ struct processor processor __read_mostly;
1741 struct cpu_tlb_fns cpu_tlb __read_mostly;
1742 #endif
1743 #ifdef MULTI_USER
1744 -struct cpu_user_fns cpu_user __read_mostly;
1745 +struct cpu_user_fns cpu_user __read_only;
1746 #endif
1747 #ifdef MULTI_CACHE
1748 -struct cpu_cache_fns cpu_cache __read_mostly;
1749 +struct cpu_cache_fns cpu_cache __read_only;
1750 #endif
1751 #ifdef CONFIG_OUTER_CACHE
1752 -struct outer_cache_fns outer_cache __read_mostly;
1753 +struct outer_cache_fns outer_cache __read_only;
1754 EXPORT_SYMBOL(outer_cache);
1755 #endif
1756
1757 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
1758 index eeb7520..1cbe902 100644
1759 --- a/arch/arm/kernel/traps.c
1760 +++ b/arch/arm/kernel/traps.c
1761 @@ -264,6 +264,8 @@ static int __die(const char *str, int err, struct thread_info *thread, struct pt
1762
1763 static DEFINE_RAW_SPINLOCK(die_lock);
1764
1765 +extern void gr_handle_kernel_exploit(void);
1766 +
1767 /*
1768 * This function is protected against re-entrancy.
1769 */
1770 @@ -296,6 +298,9 @@ void die(const char *str, struct pt_regs *regs, int err)
1771 panic("Fatal exception in interrupt");
1772 if (panic_on_oops)
1773 panic("Fatal exception");
1774 +
1775 + gr_handle_kernel_exploit();
1776 +
1777 if (ret != NOTIFY_STOP)
1778 do_exit(SIGSEGV);
1779 }
1780 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
1781 index 66a477a..bee61d3 100644
1782 --- a/arch/arm/lib/copy_from_user.S
1783 +++ b/arch/arm/lib/copy_from_user.S
1784 @@ -16,7 +16,7 @@
1785 /*
1786 * Prototype:
1787 *
1788 - * size_t __copy_from_user(void *to, const void *from, size_t n)
1789 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
1790 *
1791 * Purpose:
1792 *
1793 @@ -84,11 +84,11 @@
1794
1795 .text
1796
1797 -ENTRY(__copy_from_user)
1798 +ENTRY(___copy_from_user)
1799
1800 #include "copy_template.S"
1801
1802 -ENDPROC(__copy_from_user)
1803 +ENDPROC(___copy_from_user)
1804
1805 .pushsection .fixup,"ax"
1806 .align 0
1807 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
1808 index 6ee2f67..d1cce76 100644
1809 --- a/arch/arm/lib/copy_page.S
1810 +++ b/arch/arm/lib/copy_page.S
1811 @@ -10,6 +10,7 @@
1812 * ASM optimised string functions
1813 */
1814 #include <linux/linkage.h>
1815 +#include <linux/const.h>
1816 #include <asm/assembler.h>
1817 #include <asm/asm-offsets.h>
1818 #include <asm/cache.h>
1819 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
1820 index d066df6..df28194 100644
1821 --- a/arch/arm/lib/copy_to_user.S
1822 +++ b/arch/arm/lib/copy_to_user.S
1823 @@ -16,7 +16,7 @@
1824 /*
1825 * Prototype:
1826 *
1827 - * size_t __copy_to_user(void *to, const void *from, size_t n)
1828 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
1829 *
1830 * Purpose:
1831 *
1832 @@ -88,11 +88,11 @@
1833 .text
1834
1835 ENTRY(__copy_to_user_std)
1836 -WEAK(__copy_to_user)
1837 +WEAK(___copy_to_user)
1838
1839 #include "copy_template.S"
1840
1841 -ENDPROC(__copy_to_user)
1842 +ENDPROC(___copy_to_user)
1843 ENDPROC(__copy_to_user_std)
1844
1845 .pushsection .fixup,"ax"
1846 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
1847 index 025f742..8432b08 100644
1848 --- a/arch/arm/lib/uaccess_with_memcpy.c
1849 +++ b/arch/arm/lib/uaccess_with_memcpy.c
1850 @@ -104,7 +104,7 @@ out:
1851 }
1852
1853 unsigned long
1854 -__copy_to_user(void __user *to, const void *from, unsigned long n)
1855 +___copy_to_user(void __user *to, const void *from, unsigned long n)
1856 {
1857 /*
1858 * This test is stubbed out of the main function above to keep
1859 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
1860 index f261cd2..4ae63fb 100644
1861 --- a/arch/arm/mach-kirkwood/common.c
1862 +++ b/arch/arm/mach-kirkwood/common.c
1863 @@ -128,7 +128,7 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
1864 clk_gate_ops.disable(hw);
1865 }
1866
1867 -static struct clk_ops clk_gate_fn_ops;
1868 +static clk_ops_no_const clk_gate_fn_ops;
1869
1870 static struct clk __init *clk_register_gate_fn(struct device *dev,
1871 const char *name,
1872 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
1873 index 2c5d0ed..7d9099c 100644
1874 --- a/arch/arm/mach-omap2/board-n8x0.c
1875 +++ b/arch/arm/mach-omap2/board-n8x0.c
1876 @@ -594,7 +594,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
1877 }
1878 #endif
1879
1880 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
1881 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
1882 .late_init = n8x0_menelaus_late_init,
1883 };
1884
1885 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
1886 index c3bd834..e81ef02 100644
1887 --- a/arch/arm/mm/fault.c
1888 +++ b/arch/arm/mm/fault.c
1889 @@ -174,6 +174,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
1890 }
1891 #endif
1892
1893 +#ifdef CONFIG_PAX_PAGEEXEC
1894 + if (fsr & FSR_LNX_PF) {
1895 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
1896 + do_group_exit(SIGKILL);
1897 + }
1898 +#endif
1899 +
1900 tsk->thread.address = addr;
1901 tsk->thread.error_code = fsr;
1902 tsk->thread.trap_no = 14;
1903 @@ -397,6 +404,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
1904 }
1905 #endif /* CONFIG_MMU */
1906
1907 +#ifdef CONFIG_PAX_PAGEEXEC
1908 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
1909 +{
1910 + long i;
1911 +
1912 + printk(KERN_ERR "PAX: bytes at PC: ");
1913 + for (i = 0; i < 20; i++) {
1914 + unsigned char c;
1915 + if (get_user(c, (__force unsigned char __user *)pc+i))
1916 + printk(KERN_CONT "?? ");
1917 + else
1918 + printk(KERN_CONT "%02x ", c);
1919 + }
1920 + printk("\n");
1921 +
1922 + printk(KERN_ERR "PAX: bytes at SP-4: ");
1923 + for (i = -1; i < 20; i++) {
1924 + unsigned long c;
1925 + if (get_user(c, (__force unsigned long __user *)sp+i))
1926 + printk(KERN_CONT "???????? ");
1927 + else
1928 + printk(KERN_CONT "%08lx ", c);
1929 + }
1930 + printk("\n");
1931 +}
1932 +#endif
1933 +
1934 /*
1935 * First Level Translation Fault Handler
1936 *
1937 @@ -574,6 +608,20 @@ do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
1938 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
1939 struct siginfo info;
1940
1941 +#ifdef CONFIG_PAX_REFCOUNT
1942 + if (fsr_fs(ifsr) == 2) {
1943 + unsigned int bkpt;
1944 +
1945 + if (!probe_kernel_address((unsigned int *)addr, bkpt) && bkpt == 0xe12f1073) {
1946 + current->thread.error_code = ifsr;
1947 + current->thread.trap_no = 0;
1948 + pax_report_refcount_overflow(regs);
1949 + fixup_exception(regs);
1950 + return;
1951 + }
1952 + }
1953 +#endif
1954 +
1955 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
1956 return;
1957
1958 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
1959 index ce8cb19..3ec539d 100644
1960 --- a/arch/arm/mm/mmap.c
1961 +++ b/arch/arm/mm/mmap.c
1962 @@ -93,6 +93,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1963 if (len > TASK_SIZE)
1964 return -ENOMEM;
1965
1966 +#ifdef CONFIG_PAX_RANDMMAP
1967 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
1968 +#endif
1969 +
1970 if (addr) {
1971 if (do_align)
1972 addr = COLOUR_ALIGN(addr, pgoff);
1973 @@ -100,15 +104,14 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
1974 addr = PAGE_ALIGN(addr);
1975
1976 vma = find_vma(mm, addr);
1977 - if (TASK_SIZE - len >= addr &&
1978 - (!vma || addr + len <= vma->vm_start))
1979 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
1980 return addr;
1981 }
1982 if (len > mm->cached_hole_size) {
1983 - start_addr = addr = mm->free_area_cache;
1984 + start_addr = addr = mm->free_area_cache;
1985 } else {
1986 - start_addr = addr = mm->mmap_base;
1987 - mm->cached_hole_size = 0;
1988 + start_addr = addr = mm->mmap_base;
1989 + mm->cached_hole_size = 0;
1990 }
1991
1992 full_search:
1993 @@ -124,14 +127,14 @@ full_search:
1994 * Start a new search - just in case we missed
1995 * some holes.
1996 */
1997 - if (start_addr != TASK_UNMAPPED_BASE) {
1998 - start_addr = addr = TASK_UNMAPPED_BASE;
1999 + if (start_addr != mm->mmap_base) {
2000 + start_addr = addr = mm->mmap_base;
2001 mm->cached_hole_size = 0;
2002 goto full_search;
2003 }
2004 return -ENOMEM;
2005 }
2006 - if (!vma || addr + len <= vma->vm_start) {
2007 + if (check_heap_stack_gap(vma, addr, len)) {
2008 /*
2009 * Remember the place where we stopped the search:
2010 */
2011 @@ -266,10 +269,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
2012
2013 if (mmap_is_legacy()) {
2014 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
2015 +
2016 +#ifdef CONFIG_PAX_RANDMMAP
2017 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2018 + mm->mmap_base += mm->delta_mmap;
2019 +#endif
2020 +
2021 mm->get_unmapped_area = arch_get_unmapped_area;
2022 mm->unmap_area = arch_unmap_area;
2023 } else {
2024 mm->mmap_base = mmap_base(random_factor);
2025 +
2026 +#ifdef CONFIG_PAX_RANDMMAP
2027 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2028 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
2029 +#endif
2030 +
2031 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
2032 mm->unmap_area = arch_unmap_area_topdown;
2033 }
2034 diff --git a/arch/arm/plat-orion/include/plat/addr-map.h b/arch/arm/plat-orion/include/plat/addr-map.h
2035 index fd556f7..af2e7d2 100644
2036 --- a/arch/arm/plat-orion/include/plat/addr-map.h
2037 +++ b/arch/arm/plat-orion/include/plat/addr-map.h
2038 @@ -26,7 +26,7 @@ struct orion_addr_map_cfg {
2039 value in bridge_virt_base */
2040 void __iomem *(*win_cfg_base) (const struct orion_addr_map_cfg *cfg,
2041 const int win);
2042 -};
2043 +} __no_const;
2044
2045 /*
2046 * Information needed to setup one address mapping.
2047 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
2048 index 71a6827..e7fbc23 100644
2049 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
2050 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
2051 @@ -43,7 +43,7 @@ struct samsung_dma_ops {
2052 int (*started)(unsigned ch);
2053 int (*flush)(unsigned ch);
2054 int (*stop)(unsigned ch);
2055 -};
2056 +} __no_const;
2057
2058 extern void *samsung_dmadev_get_ops(void);
2059 extern void *s3c_dma_get_ops(void);
2060 diff --git a/arch/arm/plat-samsung/include/plat/ehci.h b/arch/arm/plat-samsung/include/plat/ehci.h
2061 index 5f28cae..3d23723 100644
2062 --- a/arch/arm/plat-samsung/include/plat/ehci.h
2063 +++ b/arch/arm/plat-samsung/include/plat/ehci.h
2064 @@ -14,7 +14,7 @@
2065 struct s5p_ehci_platdata {
2066 int (*phy_init)(struct platform_device *pdev, int type);
2067 int (*phy_exit)(struct platform_device *pdev, int type);
2068 -};
2069 +} __no_const;
2070
2071 extern void s5p_ehci_set_platdata(struct s5p_ehci_platdata *pd);
2072
2073 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
2074 index c3a58a1..78fbf54 100644
2075 --- a/arch/avr32/include/asm/cache.h
2076 +++ b/arch/avr32/include/asm/cache.h
2077 @@ -1,8 +1,10 @@
2078 #ifndef __ASM_AVR32_CACHE_H
2079 #define __ASM_AVR32_CACHE_H
2080
2081 +#include <linux/const.h>
2082 +
2083 #define L1_CACHE_SHIFT 5
2084 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2085 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2086
2087 /*
2088 * Memory returned by kmalloc() may be used for DMA, so we must make
2089 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
2090 index 3b3159b..425ea94 100644
2091 --- a/arch/avr32/include/asm/elf.h
2092 +++ b/arch/avr32/include/asm/elf.h
2093 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
2094 the loader. We need to make sure that it is out of the way of the program
2095 that it will "exec", and that there is sufficient room for the brk. */
2096
2097 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
2098 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2099
2100 +#ifdef CONFIG_PAX_ASLR
2101 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
2102 +
2103 +#define PAX_DELTA_MMAP_LEN 15
2104 +#define PAX_DELTA_STACK_LEN 15
2105 +#endif
2106
2107 /* This yields a mask that user programs can use to figure out what
2108 instruction set this CPU supports. This could be done in user space,
2109 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
2110 index b7f5c68..556135c 100644
2111 --- a/arch/avr32/include/asm/kmap_types.h
2112 +++ b/arch/avr32/include/asm/kmap_types.h
2113 @@ -22,7 +22,8 @@ D(10) KM_IRQ0,
2114 D(11) KM_IRQ1,
2115 D(12) KM_SOFTIRQ0,
2116 D(13) KM_SOFTIRQ1,
2117 -D(14) KM_TYPE_NR
2118 +D(14) KM_CLEARPAGE,
2119 +D(15) KM_TYPE_NR
2120 };
2121
2122 #undef D
2123 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
2124 index f7040a1..db9f300 100644
2125 --- a/arch/avr32/mm/fault.c
2126 +++ b/arch/avr32/mm/fault.c
2127 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
2128
2129 int exception_trace = 1;
2130
2131 +#ifdef CONFIG_PAX_PAGEEXEC
2132 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2133 +{
2134 + unsigned long i;
2135 +
2136 + printk(KERN_ERR "PAX: bytes at PC: ");
2137 + for (i = 0; i < 20; i++) {
2138 + unsigned char c;
2139 + if (get_user(c, (unsigned char *)pc+i))
2140 + printk(KERN_CONT "???????? ");
2141 + else
2142 + printk(KERN_CONT "%02x ", c);
2143 + }
2144 + printk("\n");
2145 +}
2146 +#endif
2147 +
2148 /*
2149 * This routine handles page faults. It determines the address and the
2150 * problem, and then passes it off to one of the appropriate routines.
2151 @@ -156,6 +173,16 @@ bad_area:
2152 up_read(&mm->mmap_sem);
2153
2154 if (user_mode(regs)) {
2155 +
2156 +#ifdef CONFIG_PAX_PAGEEXEC
2157 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
2158 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
2159 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
2160 + do_group_exit(SIGKILL);
2161 + }
2162 + }
2163 +#endif
2164 +
2165 if (exception_trace && printk_ratelimit())
2166 printk("%s%s[%d]: segfault at %08lx pc %08lx "
2167 "sp %08lx ecr %lu\n",
2168 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
2169 index 568885a..f8008df 100644
2170 --- a/arch/blackfin/include/asm/cache.h
2171 +++ b/arch/blackfin/include/asm/cache.h
2172 @@ -7,6 +7,7 @@
2173 #ifndef __ARCH_BLACKFIN_CACHE_H
2174 #define __ARCH_BLACKFIN_CACHE_H
2175
2176 +#include <linux/const.h>
2177 #include <linux/linkage.h> /* for asmlinkage */
2178
2179 /*
2180 @@ -14,7 +15,7 @@
2181 * Blackfin loads 32 bytes for cache
2182 */
2183 #define L1_CACHE_SHIFT 5
2184 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2185 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2186 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2187
2188 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2189 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
2190 index aea2718..3639a60 100644
2191 --- a/arch/cris/include/arch-v10/arch/cache.h
2192 +++ b/arch/cris/include/arch-v10/arch/cache.h
2193 @@ -1,8 +1,9 @@
2194 #ifndef _ASM_ARCH_CACHE_H
2195 #define _ASM_ARCH_CACHE_H
2196
2197 +#include <linux/const.h>
2198 /* Etrax 100LX have 32-byte cache-lines. */
2199 -#define L1_CACHE_BYTES 32
2200 #define L1_CACHE_SHIFT 5
2201 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2202
2203 #endif /* _ASM_ARCH_CACHE_H */
2204 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
2205 index 7caf25d..ee65ac5 100644
2206 --- a/arch/cris/include/arch-v32/arch/cache.h
2207 +++ b/arch/cris/include/arch-v32/arch/cache.h
2208 @@ -1,11 +1,12 @@
2209 #ifndef _ASM_CRIS_ARCH_CACHE_H
2210 #define _ASM_CRIS_ARCH_CACHE_H
2211
2212 +#include <linux/const.h>
2213 #include <arch/hwregs/dma.h>
2214
2215 /* A cache-line is 32 bytes. */
2216 -#define L1_CACHE_BYTES 32
2217 #define L1_CACHE_SHIFT 5
2218 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2219
2220 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
2221
2222 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
2223 index b86329d..6709906 100644
2224 --- a/arch/frv/include/asm/atomic.h
2225 +++ b/arch/frv/include/asm/atomic.h
2226 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
2227 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
2228 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
2229
2230 +#define atomic64_read_unchecked(v) atomic64_read(v)
2231 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2232 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2233 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2234 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2235 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2236 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2237 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2238 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2239 +
2240 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
2241 {
2242 int c, old;
2243 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
2244 index 2797163..c2a401d 100644
2245 --- a/arch/frv/include/asm/cache.h
2246 +++ b/arch/frv/include/asm/cache.h
2247 @@ -12,10 +12,11 @@
2248 #ifndef __ASM_CACHE_H
2249 #define __ASM_CACHE_H
2250
2251 +#include <linux/const.h>
2252
2253 /* bytes per L1 cache line */
2254 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
2255 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2256 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2257
2258 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2259 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
2260 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
2261 index f8e16b2..c73ff79 100644
2262 --- a/arch/frv/include/asm/kmap_types.h
2263 +++ b/arch/frv/include/asm/kmap_types.h
2264 @@ -23,6 +23,7 @@ enum km_type {
2265 KM_IRQ1,
2266 KM_SOFTIRQ0,
2267 KM_SOFTIRQ1,
2268 + KM_CLEARPAGE,
2269 KM_TYPE_NR
2270 };
2271
2272 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
2273 index 385fd30..6c3d97e 100644
2274 --- a/arch/frv/mm/elf-fdpic.c
2275 +++ b/arch/frv/mm/elf-fdpic.c
2276 @@ -73,8 +73,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2277 if (addr) {
2278 addr = PAGE_ALIGN(addr);
2279 vma = find_vma(current->mm, addr);
2280 - if (TASK_SIZE - len >= addr &&
2281 - (!vma || addr + len <= vma->vm_start))
2282 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
2283 goto success;
2284 }
2285
2286 @@ -89,7 +88,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2287 for (; vma; vma = vma->vm_next) {
2288 if (addr > limit)
2289 break;
2290 - if (addr + len <= vma->vm_start)
2291 + if (check_heap_stack_gap(vma, addr, len))
2292 goto success;
2293 addr = vma->vm_end;
2294 }
2295 @@ -104,7 +103,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
2296 for (; vma; vma = vma->vm_next) {
2297 if (addr > limit)
2298 break;
2299 - if (addr + len <= vma->vm_start)
2300 + if (check_heap_stack_gap(vma, addr, len))
2301 goto success;
2302 addr = vma->vm_end;
2303 }
2304 diff --git a/arch/h8300/include/asm/cache.h b/arch/h8300/include/asm/cache.h
2305 index c635028..6d9445a 100644
2306 --- a/arch/h8300/include/asm/cache.h
2307 +++ b/arch/h8300/include/asm/cache.h
2308 @@ -1,8 +1,10 @@
2309 #ifndef __ARCH_H8300_CACHE_H
2310 #define __ARCH_H8300_CACHE_H
2311
2312 +#include <linux/const.h>
2313 +
2314 /* bytes per L1 cache line */
2315 -#define L1_CACHE_BYTES 4
2316 +#define L1_CACHE_BYTES _AC(4,UL)
2317
2318 /* m68k-elf-gcc 2.95.2 doesn't like these */
2319
2320 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
2321 index 0f01de2..d37d309 100644
2322 --- a/arch/hexagon/include/asm/cache.h
2323 +++ b/arch/hexagon/include/asm/cache.h
2324 @@ -21,9 +21,11 @@
2325 #ifndef __ASM_CACHE_H
2326 #define __ASM_CACHE_H
2327
2328 +#include <linux/const.h>
2329 +
2330 /* Bytes per L1 cache line */
2331 -#define L1_CACHE_SHIFT (5)
2332 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2333 +#define L1_CACHE_SHIFT 5
2334 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2335
2336 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
2337 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
2338 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
2339 index 6e6fe18..a6ae668 100644
2340 --- a/arch/ia64/include/asm/atomic.h
2341 +++ b/arch/ia64/include/asm/atomic.h
2342 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
2343 #define atomic64_inc(v) atomic64_add(1, (v))
2344 #define atomic64_dec(v) atomic64_sub(1, (v))
2345
2346 +#define atomic64_read_unchecked(v) atomic64_read(v)
2347 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2348 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2349 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2350 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2351 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2352 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2353 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2354 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2355 +
2356 /* Atomic operations are already serializing */
2357 #define smp_mb__before_atomic_dec() barrier()
2358 #define smp_mb__after_atomic_dec() barrier()
2359 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
2360 index 988254a..e1ee885 100644
2361 --- a/arch/ia64/include/asm/cache.h
2362 +++ b/arch/ia64/include/asm/cache.h
2363 @@ -1,6 +1,7 @@
2364 #ifndef _ASM_IA64_CACHE_H
2365 #define _ASM_IA64_CACHE_H
2366
2367 +#include <linux/const.h>
2368
2369 /*
2370 * Copyright (C) 1998-2000 Hewlett-Packard Co
2371 @@ -9,7 +10,7 @@
2372
2373 /* Bytes per L1 (data) cache line. */
2374 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
2375 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2376 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2377
2378 #ifdef CONFIG_SMP
2379 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2380 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
2381 index b5298eb..67c6e62 100644
2382 --- a/arch/ia64/include/asm/elf.h
2383 +++ b/arch/ia64/include/asm/elf.h
2384 @@ -42,6 +42,13 @@
2385 */
2386 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
2387
2388 +#ifdef CONFIG_PAX_ASLR
2389 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
2390 +
2391 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2392 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
2393 +#endif
2394 +
2395 #define PT_IA_64_UNWIND 0x70000001
2396
2397 /* IA-64 relocations: */
2398 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
2399 index 96a8d92..617a1cf 100644
2400 --- a/arch/ia64/include/asm/pgalloc.h
2401 +++ b/arch/ia64/include/asm/pgalloc.h
2402 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2403 pgd_val(*pgd_entry) = __pa(pud);
2404 }
2405
2406 +static inline void
2407 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
2408 +{
2409 + pgd_populate(mm, pgd_entry, pud);
2410 +}
2411 +
2412 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
2413 {
2414 return quicklist_alloc(0, GFP_KERNEL, NULL);
2415 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2416 pud_val(*pud_entry) = __pa(pmd);
2417 }
2418
2419 +static inline void
2420 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
2421 +{
2422 + pud_populate(mm, pud_entry, pmd);
2423 +}
2424 +
2425 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
2426 {
2427 return quicklist_alloc(0, GFP_KERNEL, NULL);
2428 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
2429 index 815810c..d60bd4c 100644
2430 --- a/arch/ia64/include/asm/pgtable.h
2431 +++ b/arch/ia64/include/asm/pgtable.h
2432 @@ -12,7 +12,7 @@
2433 * David Mosberger-Tang <davidm@hpl.hp.com>
2434 */
2435
2436 -
2437 +#include <linux/const.h>
2438 #include <asm/mman.h>
2439 #include <asm/page.h>
2440 #include <asm/processor.h>
2441 @@ -142,6 +142,17 @@
2442 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2443 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2444 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
2445 +
2446 +#ifdef CONFIG_PAX_PAGEEXEC
2447 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
2448 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2449 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
2450 +#else
2451 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
2452 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
2453 +# define PAGE_COPY_NOEXEC PAGE_COPY
2454 +#endif
2455 +
2456 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
2457 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
2458 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
2459 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
2460 index 54ff557..70c88b7 100644
2461 --- a/arch/ia64/include/asm/spinlock.h
2462 +++ b/arch/ia64/include/asm/spinlock.h
2463 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
2464 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
2465
2466 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
2467 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
2468 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
2469 }
2470
2471 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
2472 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
2473 index 449c8c0..432a3d2 100644
2474 --- a/arch/ia64/include/asm/uaccess.h
2475 +++ b/arch/ia64/include/asm/uaccess.h
2476 @@ -257,7 +257,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2477 const void *__cu_from = (from); \
2478 long __cu_len = (n); \
2479 \
2480 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
2481 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) \
2482 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
2483 __cu_len; \
2484 })
2485 @@ -269,7 +269,7 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
2486 long __cu_len = (n); \
2487 \
2488 __chk_user_ptr(__cu_from); \
2489 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
2490 + if (__cu_len > 0 && __cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) \
2491 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
2492 __cu_len; \
2493 })
2494 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
2495 index 24603be..948052d 100644
2496 --- a/arch/ia64/kernel/module.c
2497 +++ b/arch/ia64/kernel/module.c
2498 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
2499 void
2500 module_free (struct module *mod, void *module_region)
2501 {
2502 - if (mod && mod->arch.init_unw_table &&
2503 - module_region == mod->module_init) {
2504 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
2505 unw_remove_unwind_table(mod->arch.init_unw_table);
2506 mod->arch.init_unw_table = NULL;
2507 }
2508 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
2509 }
2510
2511 static inline int
2512 +in_init_rx (const struct module *mod, uint64_t addr)
2513 +{
2514 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
2515 +}
2516 +
2517 +static inline int
2518 +in_init_rw (const struct module *mod, uint64_t addr)
2519 +{
2520 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
2521 +}
2522 +
2523 +static inline int
2524 in_init (const struct module *mod, uint64_t addr)
2525 {
2526 - return addr - (uint64_t) mod->module_init < mod->init_size;
2527 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
2528 +}
2529 +
2530 +static inline int
2531 +in_core_rx (const struct module *mod, uint64_t addr)
2532 +{
2533 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
2534 +}
2535 +
2536 +static inline int
2537 +in_core_rw (const struct module *mod, uint64_t addr)
2538 +{
2539 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
2540 }
2541
2542 static inline int
2543 in_core (const struct module *mod, uint64_t addr)
2544 {
2545 - return addr - (uint64_t) mod->module_core < mod->core_size;
2546 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
2547 }
2548
2549 static inline int
2550 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
2551 break;
2552
2553 case RV_BDREL:
2554 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
2555 + if (in_init_rx(mod, val))
2556 + val -= (uint64_t) mod->module_init_rx;
2557 + else if (in_init_rw(mod, val))
2558 + val -= (uint64_t) mod->module_init_rw;
2559 + else if (in_core_rx(mod, val))
2560 + val -= (uint64_t) mod->module_core_rx;
2561 + else if (in_core_rw(mod, val))
2562 + val -= (uint64_t) mod->module_core_rw;
2563 break;
2564
2565 case RV_LTV:
2566 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
2567 * addresses have been selected...
2568 */
2569 uint64_t gp;
2570 - if (mod->core_size > MAX_LTOFF)
2571 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
2572 /*
2573 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
2574 * at the end of the module.
2575 */
2576 - gp = mod->core_size - MAX_LTOFF / 2;
2577 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
2578 else
2579 - gp = mod->core_size / 2;
2580 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
2581 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
2582 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
2583 mod->arch.gp = gp;
2584 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
2585 }
2586 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
2587 index d9439ef..b9a4303 100644
2588 --- a/arch/ia64/kernel/sys_ia64.c
2589 +++ b/arch/ia64/kernel/sys_ia64.c
2590 @@ -43,6 +43,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2591 if (REGION_NUMBER(addr) == RGN_HPAGE)
2592 addr = 0;
2593 #endif
2594 +
2595 +#ifdef CONFIG_PAX_RANDMMAP
2596 + if (mm->pax_flags & MF_PAX_RANDMMAP)
2597 + addr = mm->free_area_cache;
2598 + else
2599 +#endif
2600 +
2601 if (!addr)
2602 addr = mm->free_area_cache;
2603
2604 @@ -61,14 +68,14 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
2605 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
2606 /* At this point: (!vma || addr < vma->vm_end). */
2607 if (TASK_SIZE - len < addr || RGN_MAP_LIMIT - len < REGION_OFFSET(addr)) {
2608 - if (start_addr != TASK_UNMAPPED_BASE) {
2609 + if (start_addr != mm->mmap_base) {
2610 /* Start a new search --- just in case we missed some holes. */
2611 - addr = TASK_UNMAPPED_BASE;
2612 + addr = mm->mmap_base;
2613 goto full_search;
2614 }
2615 return -ENOMEM;
2616 }
2617 - if (!vma || addr + len <= vma->vm_start) {
2618 + if (check_heap_stack_gap(vma, addr, len)) {
2619 /* Remember the address where we stopped this search: */
2620 mm->free_area_cache = addr + len;
2621 return addr;
2622 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
2623 index 0ccb28f..8992469 100644
2624 --- a/arch/ia64/kernel/vmlinux.lds.S
2625 +++ b/arch/ia64/kernel/vmlinux.lds.S
2626 @@ -198,7 +198,7 @@ SECTIONS {
2627 /* Per-cpu data: */
2628 . = ALIGN(PERCPU_PAGE_SIZE);
2629 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
2630 - __phys_per_cpu_start = __per_cpu_load;
2631 + __phys_per_cpu_start = per_cpu_load;
2632 /*
2633 * ensure percpu data fits
2634 * into percpu page size
2635 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
2636 index 02d29c2..ea893df 100644
2637 --- a/arch/ia64/mm/fault.c
2638 +++ b/arch/ia64/mm/fault.c
2639 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
2640 return pte_present(pte);
2641 }
2642
2643 +#ifdef CONFIG_PAX_PAGEEXEC
2644 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
2645 +{
2646 + unsigned long i;
2647 +
2648 + printk(KERN_ERR "PAX: bytes at PC: ");
2649 + for (i = 0; i < 8; i++) {
2650 + unsigned int c;
2651 + if (get_user(c, (unsigned int *)pc+i))
2652 + printk(KERN_CONT "???????? ");
2653 + else
2654 + printk(KERN_CONT "%08x ", c);
2655 + }
2656 + printk("\n");
2657 +}
2658 +#endif
2659 +
2660 void __kprobes
2661 ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *regs)
2662 {
2663 @@ -145,9 +162,23 @@ ia64_do_page_fault (unsigned long address, unsigned long isr, struct pt_regs *re
2664 mask = ( (((isr >> IA64_ISR_X_BIT) & 1UL) << VM_EXEC_BIT)
2665 | (((isr >> IA64_ISR_W_BIT) & 1UL) << VM_WRITE_BIT));
2666
2667 - if ((vma->vm_flags & mask) != mask)
2668 + if ((vma->vm_flags & mask) != mask) {
2669 +
2670 +#ifdef CONFIG_PAX_PAGEEXEC
2671 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
2672 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
2673 + goto bad_area;
2674 +
2675 + up_read(&mm->mmap_sem);
2676 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
2677 + do_group_exit(SIGKILL);
2678 + }
2679 +#endif
2680 +
2681 goto bad_area;
2682
2683 + }
2684 +
2685 /*
2686 * If for any reason at all we couldn't handle the fault, make
2687 * sure we exit gracefully rather than endlessly redo the
2688 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
2689 index 5ca674b..e0e1b70 100644
2690 --- a/arch/ia64/mm/hugetlbpage.c
2691 +++ b/arch/ia64/mm/hugetlbpage.c
2692 @@ -171,7 +171,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
2693 /* At this point: (!vmm || addr < vmm->vm_end). */
2694 if (REGION_OFFSET(addr) + len > RGN_MAP_LIMIT)
2695 return -ENOMEM;
2696 - if (!vmm || (addr + len) <= vmm->vm_start)
2697 + if (check_heap_stack_gap(vmm, addr, len))
2698 return addr;
2699 addr = ALIGN(vmm->vm_end, HPAGE_SIZE);
2700 }
2701 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
2702 index 0eab454..bd794f2 100644
2703 --- a/arch/ia64/mm/init.c
2704 +++ b/arch/ia64/mm/init.c
2705 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
2706 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
2707 vma->vm_end = vma->vm_start + PAGE_SIZE;
2708 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
2709 +
2710 +#ifdef CONFIG_PAX_PAGEEXEC
2711 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
2712 + vma->vm_flags &= ~VM_EXEC;
2713 +
2714 +#ifdef CONFIG_PAX_MPROTECT
2715 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
2716 + vma->vm_flags &= ~VM_MAYEXEC;
2717 +#endif
2718 +
2719 + }
2720 +#endif
2721 +
2722 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
2723 down_write(&current->mm->mmap_sem);
2724 if (insert_vm_struct(current->mm, vma)) {
2725 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
2726 index 40b3ee9..8c2c112 100644
2727 --- a/arch/m32r/include/asm/cache.h
2728 +++ b/arch/m32r/include/asm/cache.h
2729 @@ -1,8 +1,10 @@
2730 #ifndef _ASM_M32R_CACHE_H
2731 #define _ASM_M32R_CACHE_H
2732
2733 +#include <linux/const.h>
2734 +
2735 /* L1 cache line size */
2736 #define L1_CACHE_SHIFT 4
2737 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2738 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2739
2740 #endif /* _ASM_M32R_CACHE_H */
2741 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
2742 index 82abd15..d95ae5d 100644
2743 --- a/arch/m32r/lib/usercopy.c
2744 +++ b/arch/m32r/lib/usercopy.c
2745 @@ -14,6 +14,9 @@
2746 unsigned long
2747 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2748 {
2749 + if ((long)n < 0)
2750 + return n;
2751 +
2752 prefetch(from);
2753 if (access_ok(VERIFY_WRITE, to, n))
2754 __copy_user(to,from,n);
2755 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
2756 unsigned long
2757 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
2758 {
2759 + if ((long)n < 0)
2760 + return n;
2761 +
2762 prefetchw(to);
2763 if (access_ok(VERIFY_READ, from, n))
2764 __copy_user_zeroing(to,from,n);
2765 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
2766 index 0395c51..5f26031 100644
2767 --- a/arch/m68k/include/asm/cache.h
2768 +++ b/arch/m68k/include/asm/cache.h
2769 @@ -4,9 +4,11 @@
2770 #ifndef __ARCH_M68K_CACHE_H
2771 #define __ARCH_M68K_CACHE_H
2772
2773 +#include <linux/const.h>
2774 +
2775 /* bytes per L1 cache line */
2776 #define L1_CACHE_SHIFT 4
2777 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
2778 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2779
2780 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
2781
2782 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
2783 index 4efe96a..60e8699 100644
2784 --- a/arch/microblaze/include/asm/cache.h
2785 +++ b/arch/microblaze/include/asm/cache.h
2786 @@ -13,11 +13,12 @@
2787 #ifndef _ASM_MICROBLAZE_CACHE_H
2788 #define _ASM_MICROBLAZE_CACHE_H
2789
2790 +#include <linux/const.h>
2791 #include <asm/registers.h>
2792
2793 #define L1_CACHE_SHIFT 5
2794 /* word-granular cache in microblaze */
2795 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2796 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2797
2798 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2799
2800 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
2801 index 3f4c5cb..3439c6e 100644
2802 --- a/arch/mips/include/asm/atomic.h
2803 +++ b/arch/mips/include/asm/atomic.h
2804 @@ -21,6 +21,10 @@
2805 #include <asm/cmpxchg.h>
2806 #include <asm/war.h>
2807
2808 +#ifdef CONFIG_GENERIC_ATOMIC64
2809 +#include <asm-generic/atomic64.h>
2810 +#endif
2811 +
2812 #define ATOMIC_INIT(i) { (i) }
2813
2814 /*
2815 @@ -765,6 +769,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
2816 */
2817 #define atomic64_add_negative(i, v) (atomic64_add_return(i, (v)) < 0)
2818
2819 +#define atomic64_read_unchecked(v) atomic64_read(v)
2820 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
2821 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
2822 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
2823 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
2824 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
2825 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
2826 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
2827 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
2828 +
2829 #endif /* CONFIG_64BIT */
2830
2831 /*
2832 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
2833 index b4db69f..8f3b093 100644
2834 --- a/arch/mips/include/asm/cache.h
2835 +++ b/arch/mips/include/asm/cache.h
2836 @@ -9,10 +9,11 @@
2837 #ifndef _ASM_CACHE_H
2838 #define _ASM_CACHE_H
2839
2840 +#include <linux/const.h>
2841 #include <kmalloc.h>
2842
2843 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
2844 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
2845 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
2846
2847 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
2848 #define SMP_CACHE_BYTES L1_CACHE_BYTES
2849 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
2850 index 455c0ac..ad65fbe 100644
2851 --- a/arch/mips/include/asm/elf.h
2852 +++ b/arch/mips/include/asm/elf.h
2853 @@ -372,13 +372,16 @@ extern const char *__elf_platform;
2854 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
2855 #endif
2856
2857 +#ifdef CONFIG_PAX_ASLR
2858 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2859 +
2860 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2861 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2862 +#endif
2863 +
2864 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
2865 struct linux_binprm;
2866 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
2867 int uses_interp);
2868
2869 -struct mm_struct;
2870 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
2871 -#define arch_randomize_brk arch_randomize_brk
2872 -
2873 #endif /* _ASM_ELF_H */
2874 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
2875 index c1f6afa..38cc6e9 100644
2876 --- a/arch/mips/include/asm/exec.h
2877 +++ b/arch/mips/include/asm/exec.h
2878 @@ -12,6 +12,6 @@
2879 #ifndef _ASM_EXEC_H
2880 #define _ASM_EXEC_H
2881
2882 -extern unsigned long arch_align_stack(unsigned long sp);
2883 +#define arch_align_stack(x) ((x) & ~0xfUL)
2884
2885 #endif /* _ASM_EXEC_H */
2886 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
2887 index da9bd7d..91aa7ab 100644
2888 --- a/arch/mips/include/asm/page.h
2889 +++ b/arch/mips/include/asm/page.h
2890 @@ -98,7 +98,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
2891 #ifdef CONFIG_CPU_MIPS32
2892 typedef struct { unsigned long pte_low, pte_high; } pte_t;
2893 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
2894 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
2895 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
2896 #else
2897 typedef struct { unsigned long long pte; } pte_t;
2898 #define pte_val(x) ((x).pte)
2899 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
2900 index 881d18b..cea38bc 100644
2901 --- a/arch/mips/include/asm/pgalloc.h
2902 +++ b/arch/mips/include/asm/pgalloc.h
2903 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2904 {
2905 set_pud(pud, __pud((unsigned long)pmd));
2906 }
2907 +
2908 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
2909 +{
2910 + pud_populate(mm, pud, pmd);
2911 +}
2912 #endif
2913
2914 /*
2915 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
2916 index ca97e0e..cd08920 100644
2917 --- a/arch/mips/include/asm/thread_info.h
2918 +++ b/arch/mips/include/asm/thread_info.h
2919 @@ -111,6 +111,8 @@ register struct thread_info *__current_thread_info __asm__("$28");
2920 #define TIF_32BIT_ADDR 23 /* 32-bit address space (o32/n32) */
2921 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
2922 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
2923 +/* li takes a 32bit immediate */
2924 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
2925 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
2926
2927 #ifdef CONFIG_MIPS32_O32
2928 @@ -134,15 +136,18 @@ register struct thread_info *__current_thread_info __asm__("$28");
2929 #define _TIF_32BIT_ADDR (1<<TIF_32BIT_ADDR)
2930 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
2931 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
2932 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
2933 +
2934 +#define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2935
2936 /* work to do in syscall_trace_leave() */
2937 -#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT)
2938 +#define _TIF_WORK_SYSCALL_EXIT (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_GRSEC_SETXID)
2939
2940 /* work to do on interrupt/exception return */
2941 #define _TIF_WORK_MASK (0x0000ffef & \
2942 ~(_TIF_SECCOMP | _TIF_SYSCALL_AUDIT))
2943 /* work to do on any return to u-space */
2944 -#define _TIF_ALLWORK_MASK (0x8000ffff & ~_TIF_SECCOMP)
2945 +#define _TIF_ALLWORK_MASK ((0x8000ffff & ~_TIF_SECCOMP) | _TIF_GRSEC_SETXID)
2946
2947 #endif /* __KERNEL__ */
2948
2949 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
2950 index 9fdd8bc..4bd7f1a 100644
2951 --- a/arch/mips/kernel/binfmt_elfn32.c
2952 +++ b/arch/mips/kernel/binfmt_elfn32.c
2953 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2954 #undef ELF_ET_DYN_BASE
2955 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2956
2957 +#ifdef CONFIG_PAX_ASLR
2958 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2959 +
2960 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2961 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2962 +#endif
2963 +
2964 #include <asm/processor.h>
2965 #include <linux/module.h>
2966 #include <linux/elfcore.h>
2967 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
2968 index ff44823..97f8906 100644
2969 --- a/arch/mips/kernel/binfmt_elfo32.c
2970 +++ b/arch/mips/kernel/binfmt_elfo32.c
2971 @@ -52,6 +52,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
2972 #undef ELF_ET_DYN_BASE
2973 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
2974
2975 +#ifdef CONFIG_PAX_ASLR
2976 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
2977 +
2978 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2979 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
2980 +#endif
2981 +
2982 #include <asm/processor.h>
2983
2984 /*
2985 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
2986 index e9a5fd7..378809a 100644
2987 --- a/arch/mips/kernel/process.c
2988 +++ b/arch/mips/kernel/process.c
2989 @@ -480,15 +480,3 @@ unsigned long get_wchan(struct task_struct *task)
2990 out:
2991 return pc;
2992 }
2993 -
2994 -/*
2995 - * Don't forget that the stack pointer must be aligned on a 8 bytes
2996 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
2997 - */
2998 -unsigned long arch_align_stack(unsigned long sp)
2999 -{
3000 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
3001 - sp -= get_random_int() & ~PAGE_MASK;
3002 -
3003 - return sp & ALMASK;
3004 -}
3005 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
3006 index 4812c6d..2069554 100644
3007 --- a/arch/mips/kernel/ptrace.c
3008 +++ b/arch/mips/kernel/ptrace.c
3009 @@ -528,6 +528,10 @@ static inline int audit_arch(void)
3010 return arch;
3011 }
3012
3013 +#ifdef CONFIG_GRKERNSEC_SETXID
3014 +extern void gr_delayed_cred_worker(void);
3015 +#endif
3016 +
3017 /*
3018 * Notification of system call entry/exit
3019 * - triggered by current->work.syscall_trace
3020 @@ -537,6 +541,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
3021 /* do the secure computing check first */
3022 secure_computing_strict(regs->regs[2]);
3023
3024 +#ifdef CONFIG_GRKERNSEC_SETXID
3025 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
3026 + gr_delayed_cred_worker();
3027 +#endif
3028 +
3029 if (!(current->ptrace & PT_PTRACED))
3030 goto out;
3031
3032 diff --git a/arch/mips/kernel/scall32-o32.S b/arch/mips/kernel/scall32-o32.S
3033 index a632bc1..0b77c7c 100644
3034 --- a/arch/mips/kernel/scall32-o32.S
3035 +++ b/arch/mips/kernel/scall32-o32.S
3036 @@ -52,7 +52,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3037
3038 stack_done:
3039 lw t0, TI_FLAGS($28) # syscall tracing enabled?
3040 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3041 + li t1, _TIF_SYSCALL_WORK
3042 and t0, t1
3043 bnez t0, syscall_trace_entry # -> yes
3044
3045 diff --git a/arch/mips/kernel/scall64-64.S b/arch/mips/kernel/scall64-64.S
3046 index 3b5a5e9..e1ee86d 100644
3047 --- a/arch/mips/kernel/scall64-64.S
3048 +++ b/arch/mips/kernel/scall64-64.S
3049 @@ -54,7 +54,7 @@ NESTED(handle_sys64, PT_SIZE, sp)
3050
3051 sd a3, PT_R26(sp) # save a3 for syscall restarting
3052
3053 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3054 + li t1, _TIF_SYSCALL_WORK
3055 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3056 and t0, t1, t0
3057 bnez t0, syscall_trace_entry
3058 diff --git a/arch/mips/kernel/scall64-n32.S b/arch/mips/kernel/scall64-n32.S
3059 index 6be6f70..1859577 100644
3060 --- a/arch/mips/kernel/scall64-n32.S
3061 +++ b/arch/mips/kernel/scall64-n32.S
3062 @@ -53,7 +53,7 @@ NESTED(handle_sysn32, PT_SIZE, sp)
3063
3064 sd a3, PT_R26(sp) # save a3 for syscall restarting
3065
3066 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3067 + li t1, _TIF_SYSCALL_WORK
3068 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3069 and t0, t1, t0
3070 bnez t0, n32_syscall_trace_entry
3071 diff --git a/arch/mips/kernel/scall64-o32.S b/arch/mips/kernel/scall64-o32.S
3072 index 5422855..74e63a3 100644
3073 --- a/arch/mips/kernel/scall64-o32.S
3074 +++ b/arch/mips/kernel/scall64-o32.S
3075 @@ -81,7 +81,7 @@ NESTED(handle_sys, PT_SIZE, sp)
3076 PTR 4b, bad_stack
3077 .previous
3078
3079 - li t1, _TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT
3080 + li t1, _TIF_SYSCALL_WORK
3081 LONG_L t0, TI_FLAGS($28) # syscall tracing enabled?
3082 and t0, t1, t0
3083 bnez t0, trace_a_syscall
3084 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
3085 index c14f6df..537e729 100644
3086 --- a/arch/mips/mm/fault.c
3087 +++ b/arch/mips/mm/fault.c
3088 @@ -27,6 +27,23 @@
3089 #include <asm/highmem.h> /* For VMALLOC_END */
3090 #include <linux/kdebug.h>
3091
3092 +#ifdef CONFIG_PAX_PAGEEXEC
3093 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3094 +{
3095 + unsigned long i;
3096 +
3097 + printk(KERN_ERR "PAX: bytes at PC: ");
3098 + for (i = 0; i < 5; i++) {
3099 + unsigned int c;
3100 + if (get_user(c, (unsigned int *)pc+i))
3101 + printk(KERN_CONT "???????? ");
3102 + else
3103 + printk(KERN_CONT "%08x ", c);
3104 + }
3105 + printk("\n");
3106 +}
3107 +#endif
3108 +
3109 /*
3110 * This routine handles page faults. It determines the address,
3111 * and the problem, and then passes it off to one of the appropriate
3112 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
3113 index 302d779..7d35bf8 100644
3114 --- a/arch/mips/mm/mmap.c
3115 +++ b/arch/mips/mm/mmap.c
3116 @@ -95,6 +95,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3117 do_color_align = 1;
3118
3119 /* requesting a specific address */
3120 +
3121 +#ifdef CONFIG_PAX_RANDMMAP
3122 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
3123 +#endif
3124 +
3125 if (addr) {
3126 if (do_color_align)
3127 addr = COLOUR_ALIGN(addr, pgoff);
3128 @@ -102,8 +107,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3129 addr = PAGE_ALIGN(addr);
3130
3131 vma = find_vma(mm, addr);
3132 - if (TASK_SIZE - len >= addr &&
3133 - (!vma || addr + len <= vma->vm_start))
3134 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len))
3135 return addr;
3136 }
3137
3138 @@ -118,7 +122,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3139 /* At this point: (!vma || addr < vma->vm_end). */
3140 if (TASK_SIZE - len < addr)
3141 return -ENOMEM;
3142 - if (!vma || addr + len <= vma->vm_start)
3143 + if (check_heap_stack_gap(vmm, addr, len))
3144 return addr;
3145 addr = vma->vm_end;
3146 if (do_color_align)
3147 @@ -145,7 +149,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3148 /* make sure it can fit in the remaining address space */
3149 if (likely(addr > len)) {
3150 vma = find_vma(mm, addr - len);
3151 - if (!vma || addr <= vma->vm_start) {
3152 + if (check_heap_stack_gap(vmm, addr - len, len))
3153 /* cache the address as a hint for next time */
3154 return mm->free_area_cache = addr - len;
3155 }
3156 @@ -165,7 +169,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
3157 * return with success:
3158 */
3159 vma = find_vma(mm, addr);
3160 - if (likely(!vma || addr + len <= vma->vm_start)) {
3161 + if (check_heap_stack_gap(vmm, addr, len)) {
3162 /* cache the address as a hint for next time */
3163 return mm->free_area_cache = addr;
3164 }
3165 @@ -242,30 +246,3 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
3166 mm->unmap_area = arch_unmap_area_topdown;
3167 }
3168 }
3169 -
3170 -static inline unsigned long brk_rnd(void)
3171 -{
3172 - unsigned long rnd = get_random_int();
3173 -
3174 - rnd = rnd << PAGE_SHIFT;
3175 - /* 8MB for 32bit, 256MB for 64bit */
3176 - if (TASK_IS_32BIT_ADDR)
3177 - rnd = rnd & 0x7ffffful;
3178 - else
3179 - rnd = rnd & 0xffffffful;
3180 -
3181 - return rnd;
3182 -}
3183 -
3184 -unsigned long arch_randomize_brk(struct mm_struct *mm)
3185 -{
3186 - unsigned long base = mm->brk;
3187 - unsigned long ret;
3188 -
3189 - ret = PAGE_ALIGN(base + brk_rnd());
3190 -
3191 - if (ret < mm->brk)
3192 - return mm->brk;
3193 -
3194 - return ret;
3195 -}
3196 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3197 index 967d144..db12197 100644
3198 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
3199 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
3200 @@ -11,12 +11,14 @@
3201 #ifndef _ASM_PROC_CACHE_H
3202 #define _ASM_PROC_CACHE_H
3203
3204 +#include <linux/const.h>
3205 +
3206 /* L1 cache */
3207
3208 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3209 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
3210 -#define L1_CACHE_BYTES 16 /* bytes per entry */
3211 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
3212 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3213 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
3214
3215 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3216 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3217 index bcb5df2..84fabd2 100644
3218 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3219 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
3220 @@ -16,13 +16,15 @@
3221 #ifndef _ASM_PROC_CACHE_H
3222 #define _ASM_PROC_CACHE_H
3223
3224 +#include <linux/const.h>
3225 +
3226 /*
3227 * L1 cache
3228 */
3229 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
3230 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
3231 -#define L1_CACHE_BYTES 32 /* bytes per entry */
3232 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
3233 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
3234 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
3235
3236 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
3237 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
3238 index 4ce7a01..449202a 100644
3239 --- a/arch/openrisc/include/asm/cache.h
3240 +++ b/arch/openrisc/include/asm/cache.h
3241 @@ -19,11 +19,13 @@
3242 #ifndef __ASM_OPENRISC_CACHE_H
3243 #define __ASM_OPENRISC_CACHE_H
3244
3245 +#include <linux/const.h>
3246 +
3247 /* FIXME: How can we replace these with values from the CPU...
3248 * they shouldn't be hard-coded!
3249 */
3250
3251 -#define L1_CACHE_BYTES 16
3252 #define L1_CACHE_SHIFT 4
3253 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3254
3255 #endif /* __ASM_OPENRISC_CACHE_H */
3256 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
3257 index af9cf30..2aae9b2 100644
3258 --- a/arch/parisc/include/asm/atomic.h
3259 +++ b/arch/parisc/include/asm/atomic.h
3260 @@ -229,6 +229,16 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
3261
3262 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
3263
3264 +#define atomic64_read_unchecked(v) atomic64_read(v)
3265 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3266 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3267 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3268 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3269 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3270 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3271 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3272 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3273 +
3274 #endif /* !CONFIG_64BIT */
3275
3276
3277 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
3278 index 47f11c7..3420df2 100644
3279 --- a/arch/parisc/include/asm/cache.h
3280 +++ b/arch/parisc/include/asm/cache.h
3281 @@ -5,6 +5,7 @@
3282 #ifndef __ARCH_PARISC_CACHE_H
3283 #define __ARCH_PARISC_CACHE_H
3284
3285 +#include <linux/const.h>
3286
3287 /*
3288 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
3289 @@ -15,13 +16,13 @@
3290 * just ruin performance.
3291 */
3292 #ifdef CONFIG_PA20
3293 -#define L1_CACHE_BYTES 64
3294 #define L1_CACHE_SHIFT 6
3295 #else
3296 -#define L1_CACHE_BYTES 32
3297 #define L1_CACHE_SHIFT 5
3298 #endif
3299
3300 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3301 +
3302 #ifndef __ASSEMBLY__
3303
3304 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3305 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
3306 index 19f6cb1..6c78cf2 100644
3307 --- a/arch/parisc/include/asm/elf.h
3308 +++ b/arch/parisc/include/asm/elf.h
3309 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
3310
3311 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
3312
3313 +#ifdef CONFIG_PAX_ASLR
3314 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
3315 +
3316 +#define PAX_DELTA_MMAP_LEN 16
3317 +#define PAX_DELTA_STACK_LEN 16
3318 +#endif
3319 +
3320 /* This yields a mask that user programs can use to figure out what
3321 instruction set this CPU supports. This could be done in user space,
3322 but it's not easy, and we've already done it here. */
3323 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
3324 index fc987a1..6e068ef 100644
3325 --- a/arch/parisc/include/asm/pgalloc.h
3326 +++ b/arch/parisc/include/asm/pgalloc.h
3327 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3328 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
3329 }
3330
3331 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
3332 +{
3333 + pgd_populate(mm, pgd, pmd);
3334 +}
3335 +
3336 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
3337 {
3338 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
3339 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
3340 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
3341 #define pmd_free(mm, x) do { } while (0)
3342 #define pgd_populate(mm, pmd, pte) BUG()
3343 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
3344
3345 #endif
3346
3347 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
3348 index ee99f23..802b0a1 100644
3349 --- a/arch/parisc/include/asm/pgtable.h
3350 +++ b/arch/parisc/include/asm/pgtable.h
3351 @@ -212,6 +212,17 @@ struct vm_area_struct;
3352 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
3353 #define PAGE_COPY PAGE_EXECREAD
3354 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
3355 +
3356 +#ifdef CONFIG_PAX_PAGEEXEC
3357 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
3358 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3359 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
3360 +#else
3361 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
3362 +# define PAGE_COPY_NOEXEC PAGE_COPY
3363 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
3364 +#endif
3365 +
3366 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
3367 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
3368 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
3369 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
3370 index 4ba2c93..f5e3974 100644
3371 --- a/arch/parisc/include/asm/uaccess.h
3372 +++ b/arch/parisc/include/asm/uaccess.h
3373 @@ -251,10 +251,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
3374 const void __user *from,
3375 unsigned long n)
3376 {
3377 - int sz = __compiletime_object_size(to);
3378 + size_t sz = __compiletime_object_size(to);
3379 int ret = -EFAULT;
3380
3381 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
3382 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
3383 ret = __copy_from_user(to, from, n);
3384 else
3385 copy_from_user_overflow();
3386 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
3387 index 5e34ccf..672bc9c 100644
3388 --- a/arch/parisc/kernel/module.c
3389 +++ b/arch/parisc/kernel/module.c
3390 @@ -98,16 +98,38 @@
3391
3392 /* three functions to determine where in the module core
3393 * or init pieces the location is */
3394 +static inline int in_init_rx(struct module *me, void *loc)
3395 +{
3396 + return (loc >= me->module_init_rx &&
3397 + loc < (me->module_init_rx + me->init_size_rx));
3398 +}
3399 +
3400 +static inline int in_init_rw(struct module *me, void *loc)
3401 +{
3402 + return (loc >= me->module_init_rw &&
3403 + loc < (me->module_init_rw + me->init_size_rw));
3404 +}
3405 +
3406 static inline int in_init(struct module *me, void *loc)
3407 {
3408 - return (loc >= me->module_init &&
3409 - loc <= (me->module_init + me->init_size));
3410 + return in_init_rx(me, loc) || in_init_rw(me, loc);
3411 +}
3412 +
3413 +static inline int in_core_rx(struct module *me, void *loc)
3414 +{
3415 + return (loc >= me->module_core_rx &&
3416 + loc < (me->module_core_rx + me->core_size_rx));
3417 +}
3418 +
3419 +static inline int in_core_rw(struct module *me, void *loc)
3420 +{
3421 + return (loc >= me->module_core_rw &&
3422 + loc < (me->module_core_rw + me->core_size_rw));
3423 }
3424
3425 static inline int in_core(struct module *me, void *loc)
3426 {
3427 - return (loc >= me->module_core &&
3428 - loc <= (me->module_core + me->core_size));
3429 + return in_core_rx(me, loc) || in_core_rw(me, loc);
3430 }
3431
3432 static inline int in_local(struct module *me, void *loc)
3433 @@ -373,13 +395,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
3434 }
3435
3436 /* align things a bit */
3437 - me->core_size = ALIGN(me->core_size, 16);
3438 - me->arch.got_offset = me->core_size;
3439 - me->core_size += gots * sizeof(struct got_entry);
3440 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3441 + me->arch.got_offset = me->core_size_rw;
3442 + me->core_size_rw += gots * sizeof(struct got_entry);
3443
3444 - me->core_size = ALIGN(me->core_size, 16);
3445 - me->arch.fdesc_offset = me->core_size;
3446 - me->core_size += fdescs * sizeof(Elf_Fdesc);
3447 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
3448 + me->arch.fdesc_offset = me->core_size_rw;
3449 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
3450
3451 me->arch.got_max = gots;
3452 me->arch.fdesc_max = fdescs;
3453 @@ -397,7 +419,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3454
3455 BUG_ON(value == 0);
3456
3457 - got = me->module_core + me->arch.got_offset;
3458 + got = me->module_core_rw + me->arch.got_offset;
3459 for (i = 0; got[i].addr; i++)
3460 if (got[i].addr == value)
3461 goto out;
3462 @@ -415,7 +437,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
3463 #ifdef CONFIG_64BIT
3464 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3465 {
3466 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
3467 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
3468
3469 if (!value) {
3470 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
3471 @@ -433,7 +455,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
3472
3473 /* Create new one */
3474 fdesc->addr = value;
3475 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3476 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3477 return (Elf_Addr)fdesc;
3478 }
3479 #endif /* CONFIG_64BIT */
3480 @@ -845,7 +867,7 @@ register_unwind_table(struct module *me,
3481
3482 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
3483 end = table + sechdrs[me->arch.unwind_section].sh_size;
3484 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
3485 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
3486
3487 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
3488 me->arch.unwind_section, table, end, gp);
3489 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
3490 index c9b9322..02d8940 100644
3491 --- a/arch/parisc/kernel/sys_parisc.c
3492 +++ b/arch/parisc/kernel/sys_parisc.c
3493 @@ -43,7 +43,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
3494 /* At this point: (!vma || addr < vma->vm_end). */
3495 if (TASK_SIZE - len < addr)
3496 return -ENOMEM;
3497 - if (!vma || addr + len <= vma->vm_start)
3498 + if (check_heap_stack_gap(vma, addr, len))
3499 return addr;
3500 addr = vma->vm_end;
3501 }
3502 @@ -79,7 +79,7 @@ static unsigned long get_shared_area(struct address_space *mapping,
3503 /* At this point: (!vma || addr < vma->vm_end). */
3504 if (TASK_SIZE - len < addr)
3505 return -ENOMEM;
3506 - if (!vma || addr + len <= vma->vm_start)
3507 + if (check_heap_stack_gap(vma, addr, len))
3508 return addr;
3509 addr = DCACHE_ALIGN(vma->vm_end - offset) + offset;
3510 if (addr < vma->vm_end) /* handle wraparound */
3511 @@ -98,7 +98,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
3512 if (flags & MAP_FIXED)
3513 return addr;
3514 if (!addr)
3515 - addr = TASK_UNMAPPED_BASE;
3516 + addr = current->mm->mmap_base;
3517
3518 if (filp) {
3519 addr = get_shared_area(filp->f_mapping, addr, len, pgoff);
3520 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
3521 index 45ba99f..8e22c33 100644
3522 --- a/arch/parisc/kernel/traps.c
3523 +++ b/arch/parisc/kernel/traps.c
3524 @@ -732,9 +732,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
3525
3526 down_read(&current->mm->mmap_sem);
3527 vma = find_vma(current->mm,regs->iaoq[0]);
3528 - if (vma && (regs->iaoq[0] >= vma->vm_start)
3529 - && (vma->vm_flags & VM_EXEC)) {
3530 -
3531 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
3532 fault_address = regs->iaoq[0];
3533 fault_space = regs->iasq[0];
3534
3535 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
3536 index 18162ce..94de376 100644
3537 --- a/arch/parisc/mm/fault.c
3538 +++ b/arch/parisc/mm/fault.c
3539 @@ -15,6 +15,7 @@
3540 #include <linux/sched.h>
3541 #include <linux/interrupt.h>
3542 #include <linux/module.h>
3543 +#include <linux/unistd.h>
3544
3545 #include <asm/uaccess.h>
3546 #include <asm/traps.h>
3547 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
3548 static unsigned long
3549 parisc_acctyp(unsigned long code, unsigned int inst)
3550 {
3551 - if (code == 6 || code == 16)
3552 + if (code == 6 || code == 7 || code == 16)
3553 return VM_EXEC;
3554
3555 switch (inst & 0xf0000000) {
3556 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
3557 }
3558 #endif
3559
3560 +#ifdef CONFIG_PAX_PAGEEXEC
3561 +/*
3562 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
3563 + *
3564 + * returns 1 when task should be killed
3565 + * 2 when rt_sigreturn trampoline was detected
3566 + * 3 when unpatched PLT trampoline was detected
3567 + */
3568 +static int pax_handle_fetch_fault(struct pt_regs *regs)
3569 +{
3570 +
3571 +#ifdef CONFIG_PAX_EMUPLT
3572 + int err;
3573 +
3574 + do { /* PaX: unpatched PLT emulation */
3575 + unsigned int bl, depwi;
3576 +
3577 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
3578 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
3579 +
3580 + if (err)
3581 + break;
3582 +
3583 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
3584 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
3585 +
3586 + err = get_user(ldw, (unsigned int *)addr);
3587 + err |= get_user(bv, (unsigned int *)(addr+4));
3588 + err |= get_user(ldw2, (unsigned int *)(addr+8));
3589 +
3590 + if (err)
3591 + break;
3592 +
3593 + if (ldw == 0x0E801096U &&
3594 + bv == 0xEAC0C000U &&
3595 + ldw2 == 0x0E881095U)
3596 + {
3597 + unsigned int resolver, map;
3598 +
3599 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
3600 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
3601 + if (err)
3602 + break;
3603 +
3604 + regs->gr[20] = instruction_pointer(regs)+8;
3605 + regs->gr[21] = map;
3606 + regs->gr[22] = resolver;
3607 + regs->iaoq[0] = resolver | 3UL;
3608 + regs->iaoq[1] = regs->iaoq[0] + 4;
3609 + return 3;
3610 + }
3611 + }
3612 + } while (0);
3613 +#endif
3614 +
3615 +#ifdef CONFIG_PAX_EMUTRAMP
3616 +
3617 +#ifndef CONFIG_PAX_EMUSIGRT
3618 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
3619 + return 1;
3620 +#endif
3621 +
3622 + do { /* PaX: rt_sigreturn emulation */
3623 + unsigned int ldi1, ldi2, bel, nop;
3624 +
3625 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
3626 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
3627 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
3628 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
3629 +
3630 + if (err)
3631 + break;
3632 +
3633 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
3634 + ldi2 == 0x3414015AU &&
3635 + bel == 0xE4008200U &&
3636 + nop == 0x08000240U)
3637 + {
3638 + regs->gr[25] = (ldi1 & 2) >> 1;
3639 + regs->gr[20] = __NR_rt_sigreturn;
3640 + regs->gr[31] = regs->iaoq[1] + 16;
3641 + regs->sr[0] = regs->iasq[1];
3642 + regs->iaoq[0] = 0x100UL;
3643 + regs->iaoq[1] = regs->iaoq[0] + 4;
3644 + regs->iasq[0] = regs->sr[2];
3645 + regs->iasq[1] = regs->sr[2];
3646 + return 2;
3647 + }
3648 + } while (0);
3649 +#endif
3650 +
3651 + return 1;
3652 +}
3653 +
3654 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3655 +{
3656 + unsigned long i;
3657 +
3658 + printk(KERN_ERR "PAX: bytes at PC: ");
3659 + for (i = 0; i < 5; i++) {
3660 + unsigned int c;
3661 + if (get_user(c, (unsigned int *)pc+i))
3662 + printk(KERN_CONT "???????? ");
3663 + else
3664 + printk(KERN_CONT "%08x ", c);
3665 + }
3666 + printk("\n");
3667 +}
3668 +#endif
3669 +
3670 int fixup_exception(struct pt_regs *regs)
3671 {
3672 const struct exception_table_entry *fix;
3673 @@ -192,8 +303,33 @@ good_area:
3674
3675 acc_type = parisc_acctyp(code,regs->iir);
3676
3677 - if ((vma->vm_flags & acc_type) != acc_type)
3678 + if ((vma->vm_flags & acc_type) != acc_type) {
3679 +
3680 +#ifdef CONFIG_PAX_PAGEEXEC
3681 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
3682 + (address & ~3UL) == instruction_pointer(regs))
3683 + {
3684 + up_read(&mm->mmap_sem);
3685 + switch (pax_handle_fetch_fault(regs)) {
3686 +
3687 +#ifdef CONFIG_PAX_EMUPLT
3688 + case 3:
3689 + return;
3690 +#endif
3691 +
3692 +#ifdef CONFIG_PAX_EMUTRAMP
3693 + case 2:
3694 + return;
3695 +#endif
3696 +
3697 + }
3698 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
3699 + do_group_exit(SIGKILL);
3700 + }
3701 +#endif
3702 +
3703 goto bad_area;
3704 + }
3705
3706 /*
3707 * If for any reason at all we couldn't handle the fault, make
3708 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
3709 index da29032..f76c24c 100644
3710 --- a/arch/powerpc/include/asm/atomic.h
3711 +++ b/arch/powerpc/include/asm/atomic.h
3712 @@ -522,6 +522,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
3713 return t1;
3714 }
3715
3716 +#define atomic64_read_unchecked(v) atomic64_read(v)
3717 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
3718 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
3719 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
3720 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
3721 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
3722 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
3723 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
3724 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
3725 +
3726 #endif /* __powerpc64__ */
3727
3728 #endif /* __KERNEL__ */
3729 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
3730 index 9e495c9..b6878e5 100644
3731 --- a/arch/powerpc/include/asm/cache.h
3732 +++ b/arch/powerpc/include/asm/cache.h
3733 @@ -3,6 +3,7 @@
3734
3735 #ifdef __KERNEL__
3736
3737 +#include <linux/const.h>
3738
3739 /* bytes per L1 cache line */
3740 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
3741 @@ -22,7 +23,7 @@
3742 #define L1_CACHE_SHIFT 7
3743 #endif
3744
3745 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
3746 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
3747
3748 #define SMP_CACHE_BYTES L1_CACHE_BYTES
3749
3750 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
3751 index 3bf9cca..e7457d0 100644
3752 --- a/arch/powerpc/include/asm/elf.h
3753 +++ b/arch/powerpc/include/asm/elf.h
3754 @@ -178,8 +178,19 @@ typedef elf_fpreg_t elf_vsrreghalf_t32[ELF_NVSRHALFREG];
3755 the loader. We need to make sure that it is out of the way of the program
3756 that it will "exec", and that there is sufficient room for the brk. */
3757
3758 -extern unsigned long randomize_et_dyn(unsigned long base);
3759 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
3760 +#define ELF_ET_DYN_BASE (0x20000000)
3761 +
3762 +#ifdef CONFIG_PAX_ASLR
3763 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
3764 +
3765 +#ifdef __powerpc64__
3766 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
3767 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
3768 +#else
3769 +#define PAX_DELTA_MMAP_LEN 15
3770 +#define PAX_DELTA_STACK_LEN 15
3771 +#endif
3772 +#endif
3773
3774 /*
3775 * Our registers are always unsigned longs, whether we're a 32 bit
3776 @@ -274,9 +285,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
3777 (0x7ff >> (PAGE_SHIFT - 12)) : \
3778 (0x3ffff >> (PAGE_SHIFT - 12)))
3779
3780 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
3781 -#define arch_randomize_brk arch_randomize_brk
3782 -
3783 #endif /* __KERNEL__ */
3784
3785 /*
3786 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
3787 index 8196e9c..d83a9f3 100644
3788 --- a/arch/powerpc/include/asm/exec.h
3789 +++ b/arch/powerpc/include/asm/exec.h
3790 @@ -4,6 +4,6 @@
3791 #ifndef _ASM_POWERPC_EXEC_H
3792 #define _ASM_POWERPC_EXEC_H
3793
3794 -extern unsigned long arch_align_stack(unsigned long sp);
3795 +#define arch_align_stack(x) ((x) & ~0xfUL)
3796
3797 #endif /* _ASM_POWERPC_EXEC_H */
3798 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
3799 index bca8fdc..61e9580 100644
3800 --- a/arch/powerpc/include/asm/kmap_types.h
3801 +++ b/arch/powerpc/include/asm/kmap_types.h
3802 @@ -27,6 +27,7 @@ enum km_type {
3803 KM_PPC_SYNC_PAGE,
3804 KM_PPC_SYNC_ICACHE,
3805 KM_KDB,
3806 + KM_CLEARPAGE,
3807 KM_TYPE_NR
3808 };
3809
3810 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
3811 index d4a7f64..451de1c 100644
3812 --- a/arch/powerpc/include/asm/mman.h
3813 +++ b/arch/powerpc/include/asm/mman.h
3814 @@ -44,7 +44,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
3815 }
3816 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
3817
3818 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
3819 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
3820 {
3821 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
3822 }
3823 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
3824 index f072e97..b436dee 100644
3825 --- a/arch/powerpc/include/asm/page.h
3826 +++ b/arch/powerpc/include/asm/page.h
3827 @@ -220,8 +220,9 @@ extern long long virt_phys_offset;
3828 * and needs to be executable. This means the whole heap ends
3829 * up being executable.
3830 */
3831 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3832 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3833 +#define VM_DATA_DEFAULT_FLAGS32 \
3834 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3835 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3836
3837 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3838 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3839 @@ -249,6 +250,9 @@ extern long long virt_phys_offset;
3840 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
3841 #endif
3842
3843 +#define ktla_ktva(addr) (addr)
3844 +#define ktva_ktla(addr) (addr)
3845 +
3846 /*
3847 * Use the top bit of the higher-level page table entries to indicate whether
3848 * the entries we point to contain hugepages. This works because we know that
3849 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
3850 index fed85e6..da5c71b 100644
3851 --- a/arch/powerpc/include/asm/page_64.h
3852 +++ b/arch/powerpc/include/asm/page_64.h
3853 @@ -146,15 +146,18 @@ do { \
3854 * stack by default, so in the absence of a PT_GNU_STACK program header
3855 * we turn execute permission off.
3856 */
3857 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
3858 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3859 +#define VM_STACK_DEFAULT_FLAGS32 \
3860 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
3861 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3862
3863 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
3864 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
3865
3866 +#ifndef CONFIG_PAX_PAGEEXEC
3867 #define VM_STACK_DEFAULT_FLAGS \
3868 (is_32bit_task() ? \
3869 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
3870 +#endif
3871
3872 #include <asm-generic/getorder.h>
3873
3874 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
3875 index 292725c..f87ae14 100644
3876 --- a/arch/powerpc/include/asm/pgalloc-64.h
3877 +++ b/arch/powerpc/include/asm/pgalloc-64.h
3878 @@ -50,6 +50,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
3879 #ifndef CONFIG_PPC_64K_PAGES
3880
3881 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
3882 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
3883
3884 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
3885 {
3886 @@ -67,6 +68,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3887 pud_set(pud, (unsigned long)pmd);
3888 }
3889
3890 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3891 +{
3892 + pud_populate(mm, pud, pmd);
3893 +}
3894 +
3895 #define pmd_populate(mm, pmd, pte_page) \
3896 pmd_populate_kernel(mm, pmd, page_address(pte_page))
3897 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
3898 @@ -76,6 +82,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
3899 #else /* CONFIG_PPC_64K_PAGES */
3900
3901 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
3902 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
3903
3904 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
3905 pte_t *pte)
3906 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
3907 index 2e0e411..7899c68 100644
3908 --- a/arch/powerpc/include/asm/pgtable.h
3909 +++ b/arch/powerpc/include/asm/pgtable.h
3910 @@ -2,6 +2,7 @@
3911 #define _ASM_POWERPC_PGTABLE_H
3912 #ifdef __KERNEL__
3913
3914 +#include <linux/const.h>
3915 #ifndef __ASSEMBLY__
3916 #include <asm/processor.h> /* For TASK_SIZE */
3917 #include <asm/mmu.h>
3918 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
3919 index 4aad413..85d86bf 100644
3920 --- a/arch/powerpc/include/asm/pte-hash32.h
3921 +++ b/arch/powerpc/include/asm/pte-hash32.h
3922 @@ -21,6 +21,7 @@
3923 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
3924 #define _PAGE_USER 0x004 /* usermode access allowed */
3925 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
3926 +#define _PAGE_EXEC _PAGE_GUARDED
3927 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
3928 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
3929 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
3930 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
3931 index 360585d..c3930ef 100644
3932 --- a/arch/powerpc/include/asm/reg.h
3933 +++ b/arch/powerpc/include/asm/reg.h
3934 @@ -212,6 +212,7 @@
3935 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
3936 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
3937 #define DSISR_NOHPTE 0x40000000 /* no translation found */
3938 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
3939 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
3940 #define DSISR_ISSTORE 0x02000000 /* access was a store */
3941 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
3942 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
3943 index 68831e9..379c695 100644
3944 --- a/arch/powerpc/include/asm/thread_info.h
3945 +++ b/arch/powerpc/include/asm/thread_info.h
3946 @@ -91,12 +91,14 @@ static inline struct thread_info *current_thread_info(void)
3947 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
3948 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
3949 #define TIF_SINGLESTEP 8 /* singlestepping active */
3950 -#define TIF_MEMDIE 9 /* is terminating due to OOM killer */
3951 #define TIF_SECCOMP 10 /* secure computing */
3952 #define TIF_RESTOREALL 11 /* Restore all regs (implies NOERROR) */
3953 #define TIF_NOERROR 12 /* Force successful syscall return */
3954 #define TIF_NOTIFY_RESUME 13 /* callback before returning to user */
3955 #define TIF_SYSCALL_TRACEPOINT 15 /* syscall tracepoint instrumentation */
3956 +#define TIF_MEMDIE 16 /* is terminating due to OOM killer */
3957 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
3958 +#define TIF_GRSEC_SETXID 9 /* update credentials on syscall entry/exit */
3959
3960 /* as above, but as bit values */
3961 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
3962 @@ -113,8 +115,10 @@ static inline struct thread_info *current_thread_info(void)
3963 #define _TIF_NOERROR (1<<TIF_NOERROR)
3964 #define _TIF_NOTIFY_RESUME (1<<TIF_NOTIFY_RESUME)
3965 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
3966 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
3967 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
3968 - _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT)
3969 + _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
3970 + _TIF_GRSEC_SETXID)
3971
3972 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
3973 _TIF_NOTIFY_RESUME)
3974 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
3975 index 17bb40c..353c98b 100644
3976 --- a/arch/powerpc/include/asm/uaccess.h
3977 +++ b/arch/powerpc/include/asm/uaccess.h
3978 @@ -13,6 +13,8 @@
3979 #define VERIFY_READ 0
3980 #define VERIFY_WRITE 1
3981
3982 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
3983 +
3984 /*
3985 * The fs value determines whether argument validity checking should be
3986 * performed or not. If get_fs() == USER_DS, checking is performed, with
3987 @@ -329,52 +331,6 @@ do { \
3988 extern unsigned long __copy_tofrom_user(void __user *to,
3989 const void __user *from, unsigned long size);
3990
3991 -#ifndef __powerpc64__
3992 -
3993 -static inline unsigned long copy_from_user(void *to,
3994 - const void __user *from, unsigned long n)
3995 -{
3996 - unsigned long over;
3997 -
3998 - if (access_ok(VERIFY_READ, from, n))
3999 - return __copy_tofrom_user((__force void __user *)to, from, n);
4000 - if ((unsigned long)from < TASK_SIZE) {
4001 - over = (unsigned long)from + n - TASK_SIZE;
4002 - return __copy_tofrom_user((__force void __user *)to, from,
4003 - n - over) + over;
4004 - }
4005 - return n;
4006 -}
4007 -
4008 -static inline unsigned long copy_to_user(void __user *to,
4009 - const void *from, unsigned long n)
4010 -{
4011 - unsigned long over;
4012 -
4013 - if (access_ok(VERIFY_WRITE, to, n))
4014 - return __copy_tofrom_user(to, (__force void __user *)from, n);
4015 - if ((unsigned long)to < TASK_SIZE) {
4016 - over = (unsigned long)to + n - TASK_SIZE;
4017 - return __copy_tofrom_user(to, (__force void __user *)from,
4018 - n - over) + over;
4019 - }
4020 - return n;
4021 -}
4022 -
4023 -#else /* __powerpc64__ */
4024 -
4025 -#define __copy_in_user(to, from, size) \
4026 - __copy_tofrom_user((to), (from), (size))
4027 -
4028 -extern unsigned long copy_from_user(void *to, const void __user *from,
4029 - unsigned long n);
4030 -extern unsigned long copy_to_user(void __user *to, const void *from,
4031 - unsigned long n);
4032 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
4033 - unsigned long n);
4034 -
4035 -#endif /* __powerpc64__ */
4036 -
4037 static inline unsigned long __copy_from_user_inatomic(void *to,
4038 const void __user *from, unsigned long n)
4039 {
4040 @@ -398,6 +354,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
4041 if (ret == 0)
4042 return 0;
4043 }
4044 +
4045 + if (!__builtin_constant_p(n))
4046 + check_object_size(to, n, false);
4047 +
4048 return __copy_tofrom_user((__force void __user *)to, from, n);
4049 }
4050
4051 @@ -424,6 +384,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
4052 if (ret == 0)
4053 return 0;
4054 }
4055 +
4056 + if (!__builtin_constant_p(n))
4057 + check_object_size(from, n, true);
4058 +
4059 return __copy_tofrom_user(to, (__force const void __user *)from, n);
4060 }
4061
4062 @@ -441,6 +405,92 @@ static inline unsigned long __copy_to_user(void __user *to,
4063 return __copy_to_user_inatomic(to, from, size);
4064 }
4065
4066 +#ifndef __powerpc64__
4067 +
4068 +static inline unsigned long __must_check copy_from_user(void *to,
4069 + const void __user *from, unsigned long n)
4070 +{
4071 + unsigned long over;
4072 +
4073 + if ((long)n < 0)
4074 + return n;
4075 +
4076 + if (access_ok(VERIFY_READ, from, n)) {
4077 + if (!__builtin_constant_p(n))
4078 + check_object_size(to, n, false);
4079 + return __copy_tofrom_user((__force void __user *)to, from, n);
4080 + }
4081 + if ((unsigned long)from < TASK_SIZE) {
4082 + over = (unsigned long)from + n - TASK_SIZE;
4083 + if (!__builtin_constant_p(n - over))
4084 + check_object_size(to, n - over, false);
4085 + return __copy_tofrom_user((__force void __user *)to, from,
4086 + n - over) + over;
4087 + }
4088 + return n;
4089 +}
4090 +
4091 +static inline unsigned long __must_check copy_to_user(void __user *to,
4092 + const void *from, unsigned long n)
4093 +{
4094 + unsigned long over;
4095 +
4096 + if ((long)n < 0)
4097 + return n;
4098 +
4099 + if (access_ok(VERIFY_WRITE, to, n)) {
4100 + if (!__builtin_constant_p(n))
4101 + check_object_size(from, n, true);
4102 + return __copy_tofrom_user(to, (__force void __user *)from, n);
4103 + }
4104 + if ((unsigned long)to < TASK_SIZE) {
4105 + over = (unsigned long)to + n - TASK_SIZE;
4106 + if (!__builtin_constant_p(n))
4107 + check_object_size(from, n - over, true);
4108 + return __copy_tofrom_user(to, (__force void __user *)from,
4109 + n - over) + over;
4110 + }
4111 + return n;
4112 +}
4113 +
4114 +#else /* __powerpc64__ */
4115 +
4116 +#define __copy_in_user(to, from, size) \
4117 + __copy_tofrom_user((to), (from), (size))
4118 +
4119 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
4120 +{
4121 + if ((long)n < 0 || n > INT_MAX)
4122 + return n;
4123 +
4124 + if (!__builtin_constant_p(n))
4125 + check_object_size(to, n, false);
4126 +
4127 + if (likely(access_ok(VERIFY_READ, from, n)))
4128 + n = __copy_from_user(to, from, n);
4129 + else
4130 + memset(to, 0, n);
4131 + return n;
4132 +}
4133 +
4134 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
4135 +{
4136 + if ((long)n < 0 || n > INT_MAX)
4137 + return n;
4138 +
4139 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
4140 + if (!__builtin_constant_p(n))
4141 + check_object_size(from, n, true);
4142 + n = __copy_to_user(to, from, n);
4143 + }
4144 + return n;
4145 +}
4146 +
4147 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
4148 + unsigned long n);
4149 +
4150 +#endif /* __powerpc64__ */
4151 +
4152 extern unsigned long __clear_user(void __user *addr, unsigned long size);
4153
4154 static inline unsigned long clear_user(void __user *addr, unsigned long size)
4155 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
4156 index 7215cc2..a9730c1 100644
4157 --- a/arch/powerpc/kernel/exceptions-64e.S
4158 +++ b/arch/powerpc/kernel/exceptions-64e.S
4159 @@ -661,6 +661,7 @@ storage_fault_common:
4160 std r14,_DAR(r1)
4161 std r15,_DSISR(r1)
4162 addi r3,r1,STACK_FRAME_OVERHEAD
4163 + bl .save_nvgprs
4164 mr r4,r14
4165 mr r5,r15
4166 ld r14,PACA_EXGEN+EX_R14(r13)
4167 @@ -669,8 +670,7 @@ storage_fault_common:
4168 cmpdi r3,0
4169 bne- 1f
4170 b .ret_from_except_lite
4171 -1: bl .save_nvgprs
4172 - mr r5,r3
4173 +1: mr r5,r3
4174 addi r3,r1,STACK_FRAME_OVERHEAD
4175 ld r4,_DAR(r1)
4176 bl .bad_page_fault
4177 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
4178 index 1c06d29..c2a339b 100644
4179 --- a/arch/powerpc/kernel/exceptions-64s.S
4180 +++ b/arch/powerpc/kernel/exceptions-64s.S
4181 @@ -888,10 +888,10 @@ handle_page_fault:
4182 11: ld r4,_DAR(r1)
4183 ld r5,_DSISR(r1)
4184 addi r3,r1,STACK_FRAME_OVERHEAD
4185 + bl .save_nvgprs
4186 bl .do_page_fault
4187 cmpdi r3,0
4188 beq+ 12f
4189 - bl .save_nvgprs
4190 mr r5,r3
4191 addi r3,r1,STACK_FRAME_OVERHEAD
4192 lwz r4,_DAR(r1)
4193 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
4194 index 2e3200c..72095ce 100644
4195 --- a/arch/powerpc/kernel/module_32.c
4196 +++ b/arch/powerpc/kernel/module_32.c
4197 @@ -162,7 +162,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
4198 me->arch.core_plt_section = i;
4199 }
4200 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
4201 - printk("Module doesn't contain .plt or .init.plt sections.\n");
4202 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
4203 return -ENOEXEC;
4204 }
4205
4206 @@ -192,11 +192,16 @@ static uint32_t do_plt_call(void *location,
4207
4208 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
4209 /* Init, or core PLT? */
4210 - if (location >= mod->module_core
4211 - && location < mod->module_core + mod->core_size)
4212 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
4213 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
4214 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
4215 - else
4216 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
4217 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
4218 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
4219 + else {
4220 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
4221 + return ~0UL;
4222 + }
4223
4224 /* Find this entry, or if that fails, the next avail. entry */
4225 while (entry->jump[0]) {
4226 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
4227 index 1a1f2dd..f4d1bb4 100644
4228 --- a/arch/powerpc/kernel/process.c
4229 +++ b/arch/powerpc/kernel/process.c
4230 @@ -681,8 +681,8 @@ void show_regs(struct pt_regs * regs)
4231 * Lookup NIP late so we have the best change of getting the
4232 * above info out without failing
4233 */
4234 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
4235 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
4236 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
4237 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
4238 #endif
4239 show_stack(current, (unsigned long *) regs->gpr[1]);
4240 if (!user_mode(regs))
4241 @@ -1181,10 +1181,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4242 newsp = stack[0];
4243 ip = stack[STACK_FRAME_LR_SAVE];
4244 if (!firstframe || ip != lr) {
4245 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
4246 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
4247 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
4248 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
4249 - printk(" (%pS)",
4250 + printk(" (%pA)",
4251 (void *)current->ret_stack[curr_frame].ret);
4252 curr_frame--;
4253 }
4254 @@ -1204,7 +1204,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
4255 struct pt_regs *regs = (struct pt_regs *)
4256 (sp + STACK_FRAME_OVERHEAD);
4257 lr = regs->link;
4258 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
4259 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
4260 regs->trap, (void *)regs->nip, (void *)lr);
4261 firstframe = 1;
4262 }
4263 @@ -1246,58 +1246,3 @@ void __ppc64_runlatch_off(void)
4264 mtspr(SPRN_CTRLT, ctrl);
4265 }
4266 #endif /* CONFIG_PPC64 */
4267 -
4268 -unsigned long arch_align_stack(unsigned long sp)
4269 -{
4270 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4271 - sp -= get_random_int() & ~PAGE_MASK;
4272 - return sp & ~0xf;
4273 -}
4274 -
4275 -static inline unsigned long brk_rnd(void)
4276 -{
4277 - unsigned long rnd = 0;
4278 -
4279 - /* 8MB for 32bit, 1GB for 64bit */
4280 - if (is_32bit_task())
4281 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
4282 - else
4283 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
4284 -
4285 - return rnd << PAGE_SHIFT;
4286 -}
4287 -
4288 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4289 -{
4290 - unsigned long base = mm->brk;
4291 - unsigned long ret;
4292 -
4293 -#ifdef CONFIG_PPC_STD_MMU_64
4294 - /*
4295 - * If we are using 1TB segments and we are allowed to randomise
4296 - * the heap, we can put it above 1TB so it is backed by a 1TB
4297 - * segment. Otherwise the heap will be in the bottom 1TB
4298 - * which always uses 256MB segments and this may result in a
4299 - * performance penalty.
4300 - */
4301 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
4302 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
4303 -#endif
4304 -
4305 - ret = PAGE_ALIGN(base + brk_rnd());
4306 -
4307 - if (ret < mm->brk)
4308 - return mm->brk;
4309 -
4310 - return ret;
4311 -}
4312 -
4313 -unsigned long randomize_et_dyn(unsigned long base)
4314 -{
4315 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4316 -
4317 - if (ret < base)
4318 - return base;
4319 -
4320 - return ret;
4321 -}
4322 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
4323 index c10fc28..c4ef063 100644
4324 --- a/arch/powerpc/kernel/ptrace.c
4325 +++ b/arch/powerpc/kernel/ptrace.c
4326 @@ -1660,6 +1660,10 @@ long arch_ptrace(struct task_struct *child, long request,
4327 return ret;
4328 }
4329
4330 +#ifdef CONFIG_GRKERNSEC_SETXID
4331 +extern void gr_delayed_cred_worker(void);
4332 +#endif
4333 +
4334 /*
4335 * We must return the syscall number to actually look up in the table.
4336 * This can be -1L to skip running any syscall at all.
4337 @@ -1670,6 +1674,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
4338
4339 secure_computing_strict(regs->gpr[0]);
4340
4341 +#ifdef CONFIG_GRKERNSEC_SETXID
4342 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4343 + gr_delayed_cred_worker();
4344 +#endif
4345 +
4346 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
4347 tracehook_report_syscall_entry(regs))
4348 /*
4349 @@ -1704,6 +1713,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
4350 {
4351 int step;
4352
4353 +#ifdef CONFIG_GRKERNSEC_SETXID
4354 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
4355 + gr_delayed_cred_worker();
4356 +#endif
4357 +
4358 audit_syscall_exit(regs);
4359
4360 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
4361 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
4362 index 8b4c049..dcd6ef3 100644
4363 --- a/arch/powerpc/kernel/signal_32.c
4364 +++ b/arch/powerpc/kernel/signal_32.c
4365 @@ -852,7 +852,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
4366 /* Save user registers on the stack */
4367 frame = &rt_sf->uc.uc_mcontext;
4368 addr = frame;
4369 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
4370 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4371 if (save_user_regs(regs, frame, 0, 1))
4372 goto badframe;
4373 regs->link = current->mm->context.vdso_base + vdso32_rt_sigtramp;
4374 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
4375 index d183f87..1867f1a 100644
4376 --- a/arch/powerpc/kernel/signal_64.c
4377 +++ b/arch/powerpc/kernel/signal_64.c
4378 @@ -430,7 +430,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
4379 current->thread.fpscr.val = 0;
4380
4381 /* Set up to return from userspace. */
4382 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
4383 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
4384 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
4385 } else {
4386 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
4387 diff --git a/arch/powerpc/kernel/syscalls.c b/arch/powerpc/kernel/syscalls.c
4388 index f2496f2..4e3cc47 100644
4389 --- a/arch/powerpc/kernel/syscalls.c
4390 +++ b/arch/powerpc/kernel/syscalls.c
4391 @@ -107,11 +107,11 @@ long ppc64_personality(unsigned long personality)
4392 long ret;
4393
4394 if (personality(current->personality) == PER_LINUX32
4395 - && personality == PER_LINUX)
4396 - personality = PER_LINUX32;
4397 + && personality(personality) == PER_LINUX)
4398 + personality = (personality & ~PER_MASK) | PER_LINUX32;
4399 ret = sys_personality(personality);
4400 - if (ret == PER_LINUX32)
4401 - ret = PER_LINUX;
4402 + if (personality(ret) == PER_LINUX32)
4403 + ret = (ret & ~PER_MASK) | PER_LINUX;
4404 return ret;
4405 }
4406 #endif
4407 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
4408 index ae0843f..f16372c 100644
4409 --- a/arch/powerpc/kernel/traps.c
4410 +++ b/arch/powerpc/kernel/traps.c
4411 @@ -133,6 +133,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
4412 return flags;
4413 }
4414
4415 +extern void gr_handle_kernel_exploit(void);
4416 +
4417 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4418 int signr)
4419 {
4420 @@ -182,6 +184,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
4421 panic("Fatal exception in interrupt");
4422 if (panic_on_oops)
4423 panic("Fatal exception");
4424 +
4425 + gr_handle_kernel_exploit();
4426 +
4427 do_exit(signr);
4428 }
4429
4430 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
4431 index 9eb5b9b..e45498a 100644
4432 --- a/arch/powerpc/kernel/vdso.c
4433 +++ b/arch/powerpc/kernel/vdso.c
4434 @@ -34,6 +34,7 @@
4435 #include <asm/firmware.h>
4436 #include <asm/vdso.h>
4437 #include <asm/vdso_datapage.h>
4438 +#include <asm/mman.h>
4439
4440 #include "setup.h"
4441
4442 @@ -218,7 +219,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4443 vdso_base = VDSO32_MBASE;
4444 #endif
4445
4446 - current->mm->context.vdso_base = 0;
4447 + current->mm->context.vdso_base = ~0UL;
4448
4449 /* vDSO has a problem and was disabled, just don't "enable" it for the
4450 * process
4451 @@ -238,7 +239,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
4452 vdso_base = get_unmapped_area(NULL, vdso_base,
4453 (vdso_pages << PAGE_SHIFT) +
4454 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
4455 - 0, 0);
4456 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
4457 if (IS_ERR_VALUE(vdso_base)) {
4458 rc = vdso_base;
4459 goto fail_mmapsem;
4460 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
4461 index 5eea6f3..5d10396 100644
4462 --- a/arch/powerpc/lib/usercopy_64.c
4463 +++ b/arch/powerpc/lib/usercopy_64.c
4464 @@ -9,22 +9,6 @@
4465 #include <linux/module.h>
4466 #include <asm/uaccess.h>
4467
4468 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
4469 -{
4470 - if (likely(access_ok(VERIFY_READ, from, n)))
4471 - n = __copy_from_user(to, from, n);
4472 - else
4473 - memset(to, 0, n);
4474 - return n;
4475 -}
4476 -
4477 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
4478 -{
4479 - if (likely(access_ok(VERIFY_WRITE, to, n)))
4480 - n = __copy_to_user(to, from, n);
4481 - return n;
4482 -}
4483 -
4484 unsigned long copy_in_user(void __user *to, const void __user *from,
4485 unsigned long n)
4486 {
4487 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
4488 return n;
4489 }
4490
4491 -EXPORT_SYMBOL(copy_from_user);
4492 -EXPORT_SYMBOL(copy_to_user);
4493 EXPORT_SYMBOL(copy_in_user);
4494
4495 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
4496 index 08ffcf5..a0ab912 100644
4497 --- a/arch/powerpc/mm/fault.c
4498 +++ b/arch/powerpc/mm/fault.c
4499 @@ -32,6 +32,10 @@
4500 #include <linux/perf_event.h>
4501 #include <linux/magic.h>
4502 #include <linux/ratelimit.h>
4503 +#include <linux/slab.h>
4504 +#include <linux/pagemap.h>
4505 +#include <linux/compiler.h>
4506 +#include <linux/unistd.h>
4507
4508 #include <asm/firmware.h>
4509 #include <asm/page.h>
4510 @@ -68,6 +72,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
4511 }
4512 #endif
4513
4514 +#ifdef CONFIG_PAX_PAGEEXEC
4515 +/*
4516 + * PaX: decide what to do with offenders (regs->nip = fault address)
4517 + *
4518 + * returns 1 when task should be killed
4519 + */
4520 +static int pax_handle_fetch_fault(struct pt_regs *regs)
4521 +{
4522 + return 1;
4523 +}
4524 +
4525 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4526 +{
4527 + unsigned long i;
4528 +
4529 + printk(KERN_ERR "PAX: bytes at PC: ");
4530 + for (i = 0; i < 5; i++) {
4531 + unsigned int c;
4532 + if (get_user(c, (unsigned int __user *)pc+i))
4533 + printk(KERN_CONT "???????? ");
4534 + else
4535 + printk(KERN_CONT "%08x ", c);
4536 + }
4537 + printk("\n");
4538 +}
4539 +#endif
4540 +
4541 /*
4542 * Check whether the instruction at regs->nip is a store using
4543 * an update addressing form which will update r1.
4544 @@ -215,7 +246,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
4545 * indicate errors in DSISR but can validly be set in SRR1.
4546 */
4547 if (trap == 0x400)
4548 - error_code &= 0x48200000;
4549 + error_code &= 0x58200000;
4550 else
4551 is_write = error_code & DSISR_ISSTORE;
4552 #else
4553 @@ -366,7 +397,7 @@ good_area:
4554 * "undefined". Of those that can be set, this is the only
4555 * one which seems bad.
4556 */
4557 - if (error_code & 0x10000000)
4558 + if (error_code & DSISR_GUARDED)
4559 /* Guarded storage error. */
4560 goto bad_area;
4561 #endif /* CONFIG_8xx */
4562 @@ -381,7 +412,7 @@ good_area:
4563 * processors use the same I/D cache coherency mechanism
4564 * as embedded.
4565 */
4566 - if (error_code & DSISR_PROTFAULT)
4567 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
4568 goto bad_area;
4569 #endif /* CONFIG_PPC_STD_MMU */
4570
4571 @@ -463,6 +494,23 @@ bad_area:
4572 bad_area_nosemaphore:
4573 /* User mode accesses cause a SIGSEGV */
4574 if (user_mode(regs)) {
4575 +
4576 +#ifdef CONFIG_PAX_PAGEEXEC
4577 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4578 +#ifdef CONFIG_PPC_STD_MMU
4579 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
4580 +#else
4581 + if (is_exec && regs->nip == address) {
4582 +#endif
4583 + switch (pax_handle_fetch_fault(regs)) {
4584 + }
4585 +
4586 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
4587 + do_group_exit(SIGKILL);
4588 + }
4589 + }
4590 +#endif
4591 +
4592 _exception(SIGSEGV, regs, code, address);
4593 return 0;
4594 }
4595 diff --git a/arch/powerpc/mm/mmap_64.c b/arch/powerpc/mm/mmap_64.c
4596 index 67a42ed..1c7210c 100644
4597 --- a/arch/powerpc/mm/mmap_64.c
4598 +++ b/arch/powerpc/mm/mmap_64.c
4599 @@ -91,10 +91,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4600 */
4601 if (mmap_is_legacy()) {
4602 mm->mmap_base = TASK_UNMAPPED_BASE;
4603 +
4604 +#ifdef CONFIG_PAX_RANDMMAP
4605 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4606 + mm->mmap_base += mm->delta_mmap;
4607 +#endif
4608 +
4609 mm->get_unmapped_area = arch_get_unmapped_area;
4610 mm->unmap_area = arch_unmap_area;
4611 } else {
4612 mm->mmap_base = mmap_base();
4613 +
4614 +#ifdef CONFIG_PAX_RANDMMAP
4615 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4616 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4617 +#endif
4618 +
4619 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4620 mm->unmap_area = arch_unmap_area_topdown;
4621 }
4622 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
4623 index 73709f7..6b90313 100644
4624 --- a/arch/powerpc/mm/slice.c
4625 +++ b/arch/powerpc/mm/slice.c
4626 @@ -98,7 +98,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
4627 if ((mm->task_size - len) < addr)
4628 return 0;
4629 vma = find_vma(mm, addr);
4630 - return (!vma || (addr + len) <= vma->vm_start);
4631 + return check_heap_stack_gap(vma, addr, len);
4632 }
4633
4634 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
4635 @@ -256,7 +256,7 @@ full_search:
4636 addr = _ALIGN_UP(addr + 1, 1ul << SLICE_HIGH_SHIFT);
4637 continue;
4638 }
4639 - if (!vma || addr + len <= vma->vm_start) {
4640 + if (check_heap_stack_gap(vma, addr, len)) {
4641 /*
4642 * Remember the place where we stopped the search:
4643 */
4644 @@ -313,10 +313,14 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4645 }
4646 }
4647
4648 - addr = mm->mmap_base;
4649 - while (addr > len) {
4650 + if (mm->mmap_base < len)
4651 + addr = -ENOMEM;
4652 + else
4653 + addr = mm->mmap_base - len;
4654 +
4655 + while (!IS_ERR_VALUE(addr)) {
4656 /* Go down by chunk size */
4657 - addr = _ALIGN_DOWN(addr - len, 1ul << pshift);
4658 + addr = _ALIGN_DOWN(addr, 1ul << pshift);
4659
4660 /* Check for hit with different page size */
4661 mask = slice_range_to_mask(addr, len);
4662 @@ -336,7 +340,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4663 * return with success:
4664 */
4665 vma = find_vma(mm, addr);
4666 - if (!vma || (addr + len) <= vma->vm_start) {
4667 + if (check_heap_stack_gap(vma, addr, len)) {
4668 /* remember the address as a hint for next time */
4669 if (use_cache)
4670 mm->free_area_cache = addr;
4671 @@ -348,7 +352,7 @@ static unsigned long slice_find_area_topdown(struct mm_struct *mm,
4672 mm->cached_hole_size = vma->vm_start - addr;
4673
4674 /* try just below the current vma->vm_start */
4675 - addr = vma->vm_start;
4676 + addr = skip_heap_stack_gap(vma, len);
4677 }
4678
4679 /*
4680 @@ -426,6 +430,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
4681 if (fixed && addr > (mm->task_size - len))
4682 return -EINVAL;
4683
4684 +#ifdef CONFIG_PAX_RANDMMAP
4685 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
4686 + addr = 0;
4687 +#endif
4688 +
4689 /* If hint, make sure it matches our alignment restrictions */
4690 if (!fixed && addr) {
4691 addr = _ALIGN_UP(addr, 1ul << pshift);
4692 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
4693 index 748347b..81bc6c7 100644
4694 --- a/arch/s390/include/asm/atomic.h
4695 +++ b/arch/s390/include/asm/atomic.h
4696 @@ -326,6 +326,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
4697 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
4698 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
4699
4700 +#define atomic64_read_unchecked(v) atomic64_read(v)
4701 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4702 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4703 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4704 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4705 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4706 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4707 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4708 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4709 +
4710 #define smp_mb__before_atomic_dec() smp_mb()
4711 #define smp_mb__after_atomic_dec() smp_mb()
4712 #define smp_mb__before_atomic_inc() smp_mb()
4713 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
4714 index 2a30d5a..5e5586f 100644
4715 --- a/arch/s390/include/asm/cache.h
4716 +++ b/arch/s390/include/asm/cache.h
4717 @@ -11,8 +11,10 @@
4718 #ifndef __ARCH_S390_CACHE_H
4719 #define __ARCH_S390_CACHE_H
4720
4721 -#define L1_CACHE_BYTES 256
4722 +#include <linux/const.h>
4723 +
4724 #define L1_CACHE_SHIFT 8
4725 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4726 #define NET_SKB_PAD 32
4727
4728 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4729 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
4730 index 06151e6..598f9a5 100644
4731 --- a/arch/s390/include/asm/elf.h
4732 +++ b/arch/s390/include/asm/elf.h
4733 @@ -161,8 +161,14 @@ extern unsigned int vdso_enabled;
4734 the loader. We need to make sure that it is out of the way of the program
4735 that it will "exec", and that there is sufficient room for the brk. */
4736
4737 -extern unsigned long randomize_et_dyn(unsigned long base);
4738 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
4739 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
4740 +
4741 +#ifdef CONFIG_PAX_ASLR
4742 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
4743 +
4744 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4745 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
4746 +#endif
4747
4748 /* This yields a mask that user programs can use to figure out what
4749 instruction set this CPU supports. */
4750 @@ -182,7 +188,8 @@ extern char elf_platform[];
4751 #define ELF_PLATFORM (elf_platform)
4752
4753 #ifndef CONFIG_64BIT
4754 -#define SET_PERSONALITY(ex) set_personality(PER_LINUX)
4755 +#define SET_PERSONALITY(ex) \
4756 + set_personality(PER_LINUX | (current->personality & (~PER_MASK)))
4757 #else /* CONFIG_64BIT */
4758 #define SET_PERSONALITY(ex) \
4759 do { \
4760 @@ -210,7 +217,4 @@ struct linux_binprm;
4761 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
4762 int arch_setup_additional_pages(struct linux_binprm *, int);
4763
4764 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
4765 -#define arch_randomize_brk arch_randomize_brk
4766 -
4767 #endif
4768 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
4769 index c4a93d6..4d2a9b4 100644
4770 --- a/arch/s390/include/asm/exec.h
4771 +++ b/arch/s390/include/asm/exec.h
4772 @@ -7,6 +7,6 @@
4773 #ifndef __ASM_EXEC_H
4774 #define __ASM_EXEC_H
4775
4776 -extern unsigned long arch_align_stack(unsigned long sp);
4777 +#define arch_align_stack(x) ((x) & ~0xfUL)
4778
4779 #endif /* __ASM_EXEC_H */
4780 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
4781 index 1f3a79b..44d7f9c 100644
4782 --- a/arch/s390/include/asm/uaccess.h
4783 +++ b/arch/s390/include/asm/uaccess.h
4784 @@ -241,6 +241,10 @@ static inline unsigned long __must_check
4785 copy_to_user(void __user *to, const void *from, unsigned long n)
4786 {
4787 might_fault();
4788 +
4789 + if ((long)n < 0)
4790 + return n;
4791 +
4792 if (access_ok(VERIFY_WRITE, to, n))
4793 n = __copy_to_user(to, from, n);
4794 return n;
4795 @@ -266,6 +270,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
4796 static inline unsigned long __must_check
4797 __copy_from_user(void *to, const void __user *from, unsigned long n)
4798 {
4799 + if ((long)n < 0)
4800 + return n;
4801 +
4802 if (__builtin_constant_p(n) && (n <= 256))
4803 return uaccess.copy_from_user_small(n, from, to);
4804 else
4805 @@ -297,10 +304,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
4806 static inline unsigned long __must_check
4807 copy_from_user(void *to, const void __user *from, unsigned long n)
4808 {
4809 - unsigned int sz = __compiletime_object_size(to);
4810 + size_t sz = __compiletime_object_size(to);
4811
4812 might_fault();
4813 - if (unlikely(sz != -1 && sz < n)) {
4814 +
4815 + if ((long)n < 0)
4816 + return n;
4817 +
4818 + if (unlikely(sz != (size_t)-1 && sz < n)) {
4819 copy_from_user_overflow();
4820 return n;
4821 }
4822 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
4823 index dfcb343..eda788a 100644
4824 --- a/arch/s390/kernel/module.c
4825 +++ b/arch/s390/kernel/module.c
4826 @@ -161,11 +161,11 @@ module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
4827
4828 /* Increase core size by size of got & plt and set start
4829 offsets for got and plt. */
4830 - me->core_size = ALIGN(me->core_size, 4);
4831 - me->arch.got_offset = me->core_size;
4832 - me->core_size += me->arch.got_size;
4833 - me->arch.plt_offset = me->core_size;
4834 - me->core_size += me->arch.plt_size;
4835 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
4836 + me->arch.got_offset = me->core_size_rw;
4837 + me->core_size_rw += me->arch.got_size;
4838 + me->arch.plt_offset = me->core_size_rx;
4839 + me->core_size_rx += me->arch.plt_size;
4840 return 0;
4841 }
4842
4843 @@ -242,7 +242,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4844 if (info->got_initialized == 0) {
4845 Elf_Addr *gotent;
4846
4847 - gotent = me->module_core + me->arch.got_offset +
4848 + gotent = me->module_core_rw + me->arch.got_offset +
4849 info->got_offset;
4850 *gotent = val;
4851 info->got_initialized = 1;
4852 @@ -266,7 +266,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4853 else if (r_type == R_390_GOTENT ||
4854 r_type == R_390_GOTPLTENT)
4855 *(unsigned int *) loc =
4856 - (val + (Elf_Addr) me->module_core - loc) >> 1;
4857 + (val + (Elf_Addr) me->module_core_rw - loc) >> 1;
4858 else if (r_type == R_390_GOT64 ||
4859 r_type == R_390_GOTPLT64)
4860 *(unsigned long *) loc = val;
4861 @@ -280,7 +280,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4862 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
4863 if (info->plt_initialized == 0) {
4864 unsigned int *ip;
4865 - ip = me->module_core + me->arch.plt_offset +
4866 + ip = me->module_core_rx + me->arch.plt_offset +
4867 info->plt_offset;
4868 #ifndef CONFIG_64BIT
4869 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
4870 @@ -305,7 +305,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4871 val - loc + 0xffffUL < 0x1ffffeUL) ||
4872 (r_type == R_390_PLT32DBL &&
4873 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
4874 - val = (Elf_Addr) me->module_core +
4875 + val = (Elf_Addr) me->module_core_rx +
4876 me->arch.plt_offset +
4877 info->plt_offset;
4878 val += rela->r_addend - loc;
4879 @@ -327,7 +327,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4880 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
4881 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
4882 val = val + rela->r_addend -
4883 - ((Elf_Addr) me->module_core + me->arch.got_offset);
4884 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
4885 if (r_type == R_390_GOTOFF16)
4886 *(unsigned short *) loc = val;
4887 else if (r_type == R_390_GOTOFF32)
4888 @@ -337,7 +337,7 @@ apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
4889 break;
4890 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
4891 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
4892 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
4893 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
4894 rela->r_addend - loc;
4895 if (r_type == R_390_GOTPC)
4896 *(unsigned int *) loc = val;
4897 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
4898 index 60055ce..ee4b252 100644
4899 --- a/arch/s390/kernel/process.c
4900 +++ b/arch/s390/kernel/process.c
4901 @@ -316,39 +316,3 @@ unsigned long get_wchan(struct task_struct *p)
4902 }
4903 return 0;
4904 }
4905 -
4906 -unsigned long arch_align_stack(unsigned long sp)
4907 -{
4908 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
4909 - sp -= get_random_int() & ~PAGE_MASK;
4910 - return sp & ~0xf;
4911 -}
4912 -
4913 -static inline unsigned long brk_rnd(void)
4914 -{
4915 - /* 8MB for 32bit, 1GB for 64bit */
4916 - if (is_32bit_task())
4917 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
4918 - else
4919 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
4920 -}
4921 -
4922 -unsigned long arch_randomize_brk(struct mm_struct *mm)
4923 -{
4924 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
4925 -
4926 - if (ret < mm->brk)
4927 - return mm->brk;
4928 - return ret;
4929 -}
4930 -
4931 -unsigned long randomize_et_dyn(unsigned long base)
4932 -{
4933 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
4934 -
4935 - if (!(current->flags & PF_RANDOMIZE))
4936 - return base;
4937 - if (ret < base)
4938 - return base;
4939 - return ret;
4940 -}
4941 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
4942 index a64fe53..5c66963 100644
4943 --- a/arch/s390/mm/mmap.c
4944 +++ b/arch/s390/mm/mmap.c
4945 @@ -92,10 +92,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4946 */
4947 if (mmap_is_legacy()) {
4948 mm->mmap_base = TASK_UNMAPPED_BASE;
4949 +
4950 +#ifdef CONFIG_PAX_RANDMMAP
4951 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4952 + mm->mmap_base += mm->delta_mmap;
4953 +#endif
4954 +
4955 mm->get_unmapped_area = arch_get_unmapped_area;
4956 mm->unmap_area = arch_unmap_area;
4957 } else {
4958 mm->mmap_base = mmap_base();
4959 +
4960 +#ifdef CONFIG_PAX_RANDMMAP
4961 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4962 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4963 +#endif
4964 +
4965 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4966 mm->unmap_area = arch_unmap_area_topdown;
4967 }
4968 @@ -174,10 +186,22 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4969 */
4970 if (mmap_is_legacy()) {
4971 mm->mmap_base = TASK_UNMAPPED_BASE;
4972 +
4973 +#ifdef CONFIG_PAX_RANDMMAP
4974 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4975 + mm->mmap_base += mm->delta_mmap;
4976 +#endif
4977 +
4978 mm->get_unmapped_area = s390_get_unmapped_area;
4979 mm->unmap_area = arch_unmap_area;
4980 } else {
4981 mm->mmap_base = mmap_base();
4982 +
4983 +#ifdef CONFIG_PAX_RANDMMAP
4984 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4985 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4986 +#endif
4987 +
4988 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
4989 mm->unmap_area = arch_unmap_area_topdown;
4990 }
4991 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
4992 index ae3d59f..f65f075 100644
4993 --- a/arch/score/include/asm/cache.h
4994 +++ b/arch/score/include/asm/cache.h
4995 @@ -1,7 +1,9 @@
4996 #ifndef _ASM_SCORE_CACHE_H
4997 #define _ASM_SCORE_CACHE_H
4998
4999 +#include <linux/const.h>
5000 +
5001 #define L1_CACHE_SHIFT 4
5002 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5003 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5004
5005 #endif /* _ASM_SCORE_CACHE_H */
5006 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
5007 index f9f3cd5..58ff438 100644
5008 --- a/arch/score/include/asm/exec.h
5009 +++ b/arch/score/include/asm/exec.h
5010 @@ -1,6 +1,6 @@
5011 #ifndef _ASM_SCORE_EXEC_H
5012 #define _ASM_SCORE_EXEC_H
5013
5014 -extern unsigned long arch_align_stack(unsigned long sp);
5015 +#define arch_align_stack(x) (x)
5016
5017 #endif /* _ASM_SCORE_EXEC_H */
5018 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
5019 index 2707023..1c2a3b7 100644
5020 --- a/arch/score/kernel/process.c
5021 +++ b/arch/score/kernel/process.c
5022 @@ -159,8 +159,3 @@ unsigned long get_wchan(struct task_struct *task)
5023
5024 return task_pt_regs(task)->cp0_epc;
5025 }
5026 -
5027 -unsigned long arch_align_stack(unsigned long sp)
5028 -{
5029 - return sp;
5030 -}
5031 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
5032 index ef9e555..331bd29 100644
5033 --- a/arch/sh/include/asm/cache.h
5034 +++ b/arch/sh/include/asm/cache.h
5035 @@ -9,10 +9,11 @@
5036 #define __ASM_SH_CACHE_H
5037 #ifdef __KERNEL__
5038
5039 +#include <linux/const.h>
5040 #include <linux/init.h>
5041 #include <cpu/cache.h>
5042
5043 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5044 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5045
5046 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
5047
5048 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
5049 index afeb710..d1d1289 100644
5050 --- a/arch/sh/mm/mmap.c
5051 +++ b/arch/sh/mm/mmap.c
5052 @@ -74,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
5053 addr = PAGE_ALIGN(addr);
5054
5055 vma = find_vma(mm, addr);
5056 - if (TASK_SIZE - len >= addr &&
5057 - (!vma || addr + len <= vma->vm_start))
5058 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5059 return addr;
5060 }
5061
5062 @@ -106,7 +105,7 @@ full_search:
5063 }
5064 return -ENOMEM;
5065 }
5066 - if (likely(!vma || addr + len <= vma->vm_start)) {
5067 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5068 /*
5069 * Remember the place where we stopped the search:
5070 */
5071 @@ -157,8 +156,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5072 addr = PAGE_ALIGN(addr);
5073
5074 vma = find_vma(mm, addr);
5075 - if (TASK_SIZE - len >= addr &&
5076 - (!vma || addr + len <= vma->vm_start))
5077 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len))
5078 return addr;
5079 }
5080
5081 @@ -179,7 +177,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5082 /* make sure it can fit in the remaining address space */
5083 if (likely(addr > len)) {
5084 vma = find_vma(mm, addr-len);
5085 - if (!vma || addr <= vma->vm_start) {
5086 + if (check_heap_stack_gap(vma, addr - len, len)) {
5087 /* remember the address as a hint for next time */
5088 return (mm->free_area_cache = addr-len);
5089 }
5090 @@ -188,18 +186,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5091 if (unlikely(mm->mmap_base < len))
5092 goto bottomup;
5093
5094 - addr = mm->mmap_base-len;
5095 - if (do_colour_align)
5096 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5097 + addr = mm->mmap_base - len;
5098
5099 do {
5100 + if (do_colour_align)
5101 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5102 /*
5103 * Lookup failure means no vma is above this address,
5104 * else if new region fits below vma->vm_start,
5105 * return with success:
5106 */
5107 vma = find_vma(mm, addr);
5108 - if (likely(!vma || addr+len <= vma->vm_start)) {
5109 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5110 /* remember the address as a hint for next time */
5111 return (mm->free_area_cache = addr);
5112 }
5113 @@ -209,10 +207,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5114 mm->cached_hole_size = vma->vm_start - addr;
5115
5116 /* try just below the current vma->vm_start */
5117 - addr = vma->vm_start-len;
5118 - if (do_colour_align)
5119 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5120 - } while (likely(len < vma->vm_start));
5121 + addr = skip_heap_stack_gap(vma, len);
5122 + } while (!IS_ERR_VALUE(addr));
5123
5124 bottomup:
5125 /*
5126 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
5127 index ce35a1c..2e7b8f9 100644
5128 --- a/arch/sparc/include/asm/atomic_64.h
5129 +++ b/arch/sparc/include/asm/atomic_64.h
5130 @@ -14,18 +14,40 @@
5131 #define ATOMIC64_INIT(i) { (i) }
5132
5133 #define atomic_read(v) (*(volatile int *)&(v)->counter)
5134 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5135 +{
5136 + return v->counter;
5137 +}
5138 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
5139 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5140 +{
5141 + return v->counter;
5142 +}
5143
5144 #define atomic_set(v, i) (((v)->counter) = i)
5145 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5146 +{
5147 + v->counter = i;
5148 +}
5149 #define atomic64_set(v, i) (((v)->counter) = i)
5150 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5151 +{
5152 + v->counter = i;
5153 +}
5154
5155 extern void atomic_add(int, atomic_t *);
5156 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
5157 extern void atomic64_add(long, atomic64_t *);
5158 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
5159 extern void atomic_sub(int, atomic_t *);
5160 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
5161 extern void atomic64_sub(long, atomic64_t *);
5162 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
5163
5164 extern int atomic_add_ret(int, atomic_t *);
5165 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
5166 extern long atomic64_add_ret(long, atomic64_t *);
5167 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
5168 extern int atomic_sub_ret(int, atomic_t *);
5169 extern long atomic64_sub_ret(long, atomic64_t *);
5170
5171 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5172 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
5173
5174 #define atomic_inc_return(v) atomic_add_ret(1, v)
5175 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5176 +{
5177 + return atomic_add_ret_unchecked(1, v);
5178 +}
5179 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
5180 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
5181 +{
5182 + return atomic64_add_ret_unchecked(1, v);
5183 +}
5184
5185 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
5186 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
5187
5188 #define atomic_add_return(i, v) atomic_add_ret(i, v)
5189 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5190 +{
5191 + return atomic_add_ret_unchecked(i, v);
5192 +}
5193 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
5194 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
5195 +{
5196 + return atomic64_add_ret_unchecked(i, v);
5197 +}
5198
5199 /*
5200 * atomic_inc_and_test - increment and test
5201 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5202 * other cases.
5203 */
5204 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5205 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5206 +{
5207 + return atomic_inc_return_unchecked(v) == 0;
5208 +}
5209 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
5210
5211 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
5212 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
5213 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
5214
5215 #define atomic_inc(v) atomic_add(1, v)
5216 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
5217 +{
5218 + atomic_add_unchecked(1, v);
5219 +}
5220 #define atomic64_inc(v) atomic64_add(1, v)
5221 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
5222 +{
5223 + atomic64_add_unchecked(1, v);
5224 +}
5225
5226 #define atomic_dec(v) atomic_sub(1, v)
5227 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
5228 +{
5229 + atomic_sub_unchecked(1, v);
5230 +}
5231 #define atomic64_dec(v) atomic64_sub(1, v)
5232 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
5233 +{
5234 + atomic64_sub_unchecked(1, v);
5235 +}
5236
5237 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
5238 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
5239
5240 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5241 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
5242 +{
5243 + return cmpxchg(&v->counter, old, new);
5244 +}
5245 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
5246 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5247 +{
5248 + return xchg(&v->counter, new);
5249 +}
5250
5251 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5252 {
5253 - int c, old;
5254 + int c, old, new;
5255 c = atomic_read(v);
5256 for (;;) {
5257 - if (unlikely(c == (u)))
5258 + if (unlikely(c == u))
5259 break;
5260 - old = atomic_cmpxchg((v), c, c + (a));
5261 +
5262 + asm volatile("addcc %2, %0, %0\n"
5263 +
5264 +#ifdef CONFIG_PAX_REFCOUNT
5265 + "tvs %%icc, 6\n"
5266 +#endif
5267 +
5268 + : "=r" (new)
5269 + : "0" (c), "ir" (a)
5270 + : "cc");
5271 +
5272 + old = atomic_cmpxchg(v, c, new);
5273 if (likely(old == c))
5274 break;
5275 c = old;
5276 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
5277 #define atomic64_cmpxchg(v, o, n) \
5278 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
5279 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
5280 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
5281 +{
5282 + return xchg(&v->counter, new);
5283 +}
5284
5285 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
5286 {
5287 - long c, old;
5288 + long c, old, new;
5289 c = atomic64_read(v);
5290 for (;;) {
5291 - if (unlikely(c == (u)))
5292 + if (unlikely(c == u))
5293 break;
5294 - old = atomic64_cmpxchg((v), c, c + (a));
5295 +
5296 + asm volatile("addcc %2, %0, %0\n"
5297 +
5298 +#ifdef CONFIG_PAX_REFCOUNT
5299 + "tvs %%xcc, 6\n"
5300 +#endif
5301 +
5302 + : "=r" (new)
5303 + : "0" (c), "ir" (a)
5304 + : "cc");
5305 +
5306 + old = atomic64_cmpxchg(v, c, new);
5307 if (likely(old == c))
5308 break;
5309 c = old;
5310 }
5311 - return c != (u);
5312 + return c != u;
5313 }
5314
5315 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
5316 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
5317 index 5bb6991..5c2132e 100644
5318 --- a/arch/sparc/include/asm/cache.h
5319 +++ b/arch/sparc/include/asm/cache.h
5320 @@ -7,10 +7,12 @@
5321 #ifndef _SPARC_CACHE_H
5322 #define _SPARC_CACHE_H
5323
5324 +#include <linux/const.h>
5325 +
5326 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
5327
5328 #define L1_CACHE_SHIFT 5
5329 -#define L1_CACHE_BYTES 32
5330 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5331
5332 #ifdef CONFIG_SPARC32
5333 #define SMP_CACHE_BYTES_SHIFT 5
5334 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
5335 index 2d4d755..81b6662 100644
5336 --- a/arch/sparc/include/asm/elf_32.h
5337 +++ b/arch/sparc/include/asm/elf_32.h
5338 @@ -114,6 +114,13 @@ typedef struct {
5339
5340 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
5341
5342 +#ifdef CONFIG_PAX_ASLR
5343 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
5344 +
5345 +#define PAX_DELTA_MMAP_LEN 16
5346 +#define PAX_DELTA_STACK_LEN 16
5347 +#endif
5348 +
5349 /* This yields a mask that user programs can use to figure out what
5350 instruction set this cpu supports. This can NOT be done in userspace
5351 on Sparc. */
5352 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
5353 index 7df8b7f..4946269 100644
5354 --- a/arch/sparc/include/asm/elf_64.h
5355 +++ b/arch/sparc/include/asm/elf_64.h
5356 @@ -180,6 +180,13 @@ typedef struct {
5357 #define ELF_ET_DYN_BASE 0x0000010000000000UL
5358 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
5359
5360 +#ifdef CONFIG_PAX_ASLR
5361 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
5362 +
5363 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
5364 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
5365 +#endif
5366 +
5367 extern unsigned long sparc64_elf_hwcap;
5368 #define ELF_HWCAP sparc64_elf_hwcap
5369
5370 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
5371 index e5b169b46..e90b4fa 100644
5372 --- a/arch/sparc/include/asm/pgalloc_32.h
5373 +++ b/arch/sparc/include/asm/pgalloc_32.h
5374 @@ -46,6 +46,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
5375 }
5376
5377 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
5378 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
5379
5380 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
5381 unsigned long address)
5382 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
5383 index 40b2d7a..22a665b 100644
5384 --- a/arch/sparc/include/asm/pgalloc_64.h
5385 +++ b/arch/sparc/include/asm/pgalloc_64.h
5386 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
5387 }
5388
5389 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
5390 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
5391
5392 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5393 {
5394 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
5395 index cbbbed5..97f72f9 100644
5396 --- a/arch/sparc/include/asm/pgtable_32.h
5397 +++ b/arch/sparc/include/asm/pgtable_32.h
5398 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
5399 #define PAGE_SHARED SRMMU_PAGE_SHARED
5400 #define PAGE_COPY SRMMU_PAGE_COPY
5401 #define PAGE_READONLY SRMMU_PAGE_RDONLY
5402 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
5403 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
5404 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
5405 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
5406
5407 /* Top-level page directory */
5408 @@ -61,18 +64,18 @@ extern unsigned long ptr_in_current_pgd;
5409
5410 /* xwr */
5411 #define __P000 PAGE_NONE
5412 -#define __P001 PAGE_READONLY
5413 -#define __P010 PAGE_COPY
5414 -#define __P011 PAGE_COPY
5415 +#define __P001 PAGE_READONLY_NOEXEC
5416 +#define __P010 PAGE_COPY_NOEXEC
5417 +#define __P011 PAGE_COPY_NOEXEC
5418 #define __P100 PAGE_READONLY
5419 #define __P101 PAGE_READONLY
5420 #define __P110 PAGE_COPY
5421 #define __P111 PAGE_COPY
5422
5423 #define __S000 PAGE_NONE
5424 -#define __S001 PAGE_READONLY
5425 -#define __S010 PAGE_SHARED
5426 -#define __S011 PAGE_SHARED
5427 +#define __S001 PAGE_READONLY_NOEXEC
5428 +#define __S010 PAGE_SHARED_NOEXEC
5429 +#define __S011 PAGE_SHARED_NOEXEC
5430 #define __S100 PAGE_READONLY
5431 #define __S101 PAGE_READONLY
5432 #define __S110 PAGE_SHARED
5433 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
5434 index 79da178..c2eede8 100644
5435 --- a/arch/sparc/include/asm/pgtsrmmu.h
5436 +++ b/arch/sparc/include/asm/pgtsrmmu.h
5437 @@ -115,6 +115,11 @@
5438 SRMMU_EXEC | SRMMU_REF)
5439 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
5440 SRMMU_EXEC | SRMMU_REF)
5441 +
5442 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
5443 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5444 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
5445 +
5446 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
5447 SRMMU_DIRTY | SRMMU_REF)
5448
5449 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
5450 index 9689176..63c18ea 100644
5451 --- a/arch/sparc/include/asm/spinlock_64.h
5452 +++ b/arch/sparc/include/asm/spinlock_64.h
5453 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
5454
5455 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
5456
5457 -static void inline arch_read_lock(arch_rwlock_t *lock)
5458 +static inline void arch_read_lock(arch_rwlock_t *lock)
5459 {
5460 unsigned long tmp1, tmp2;
5461
5462 __asm__ __volatile__ (
5463 "1: ldsw [%2], %0\n"
5464 " brlz,pn %0, 2f\n"
5465 -"4: add %0, 1, %1\n"
5466 +"4: addcc %0, 1, %1\n"
5467 +
5468 +#ifdef CONFIG_PAX_REFCOUNT
5469 +" tvs %%icc, 6\n"
5470 +#endif
5471 +
5472 " cas [%2], %0, %1\n"
5473 " cmp %0, %1\n"
5474 " bne,pn %%icc, 1b\n"
5475 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
5476 " .previous"
5477 : "=&r" (tmp1), "=&r" (tmp2)
5478 : "r" (lock)
5479 - : "memory");
5480 + : "memory", "cc");
5481 }
5482
5483 -static int inline arch_read_trylock(arch_rwlock_t *lock)
5484 +static inline int arch_read_trylock(arch_rwlock_t *lock)
5485 {
5486 int tmp1, tmp2;
5487
5488 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5489 "1: ldsw [%2], %0\n"
5490 " brlz,a,pn %0, 2f\n"
5491 " mov 0, %0\n"
5492 -" add %0, 1, %1\n"
5493 +" addcc %0, 1, %1\n"
5494 +
5495 +#ifdef CONFIG_PAX_REFCOUNT
5496 +" tvs %%icc, 6\n"
5497 +#endif
5498 +
5499 " cas [%2], %0, %1\n"
5500 " cmp %0, %1\n"
5501 " bne,pn %%icc, 1b\n"
5502 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
5503 return tmp1;
5504 }
5505
5506 -static void inline arch_read_unlock(arch_rwlock_t *lock)
5507 +static inline void arch_read_unlock(arch_rwlock_t *lock)
5508 {
5509 unsigned long tmp1, tmp2;
5510
5511 __asm__ __volatile__(
5512 "1: lduw [%2], %0\n"
5513 -" sub %0, 1, %1\n"
5514 +" subcc %0, 1, %1\n"
5515 +
5516 +#ifdef CONFIG_PAX_REFCOUNT
5517 +" tvs %%icc, 6\n"
5518 +#endif
5519 +
5520 " cas [%2], %0, %1\n"
5521 " cmp %0, %1\n"
5522 " bne,pn %%xcc, 1b\n"
5523 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
5524 : "memory");
5525 }
5526
5527 -static void inline arch_write_lock(arch_rwlock_t *lock)
5528 +static inline void arch_write_lock(arch_rwlock_t *lock)
5529 {
5530 unsigned long mask, tmp1, tmp2;
5531
5532 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
5533 : "memory");
5534 }
5535
5536 -static void inline arch_write_unlock(arch_rwlock_t *lock)
5537 +static inline void arch_write_unlock(arch_rwlock_t *lock)
5538 {
5539 __asm__ __volatile__(
5540 " stw %%g0, [%0]"
5541 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
5542 : "memory");
5543 }
5544
5545 -static int inline arch_write_trylock(arch_rwlock_t *lock)
5546 +static inline int arch_write_trylock(arch_rwlock_t *lock)
5547 {
5548 unsigned long mask, tmp1, tmp2, result;
5549
5550 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
5551 index e6cd224..3a71793 100644
5552 --- a/arch/sparc/include/asm/thread_info_32.h
5553 +++ b/arch/sparc/include/asm/thread_info_32.h
5554 @@ -49,6 +49,8 @@ struct thread_info {
5555 unsigned long w_saved;
5556
5557 struct restart_block restart_block;
5558 +
5559 + unsigned long lowest_stack;
5560 };
5561
5562 /*
5563 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
5564 index cfa8c38..13f30d3 100644
5565 --- a/arch/sparc/include/asm/thread_info_64.h
5566 +++ b/arch/sparc/include/asm/thread_info_64.h
5567 @@ -63,6 +63,8 @@ struct thread_info {
5568 struct pt_regs *kern_una_regs;
5569 unsigned int kern_una_insn;
5570
5571 + unsigned long lowest_stack;
5572 +
5573 unsigned long fpregs[0] __attribute__ ((aligned(64)));
5574 };
5575
5576 @@ -193,10 +195,11 @@ register struct thread_info *current_thread_info_reg asm("g6");
5577 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
5578 /* flag bit 6 is available */
5579 #define TIF_32BIT 7 /* 32-bit binary */
5580 -/* flag bit 8 is available */
5581 +#define TIF_GRSEC_SETXID 8 /* update credentials on syscall entry/exit */
5582 #define TIF_SECCOMP 9 /* secure computing */
5583 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
5584 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
5585 +
5586 /* NOTE: Thread flags >= 12 should be ones we have no interest
5587 * in using in assembly, else we can't use the mask as
5588 * an immediate value in instructions such as andcc.
5589 @@ -215,12 +218,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
5590 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
5591 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
5592 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
5593 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
5594
5595 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
5596 _TIF_DO_NOTIFY_RESUME_MASK | \
5597 _TIF_NEED_RESCHED)
5598 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
5599
5600 +#define _TIF_WORK_SYSCALL \
5601 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
5602 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
5603 +
5604 +
5605 /*
5606 * Thread-synchronous status.
5607 *
5608 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
5609 index 0167d26..9acd8ed 100644
5610 --- a/arch/sparc/include/asm/uaccess.h
5611 +++ b/arch/sparc/include/asm/uaccess.h
5612 @@ -1,5 +1,13 @@
5613 #ifndef ___ASM_SPARC_UACCESS_H
5614 #define ___ASM_SPARC_UACCESS_H
5615 +
5616 +#ifdef __KERNEL__
5617 +#ifndef __ASSEMBLY__
5618 +#include <linux/types.h>
5619 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
5620 +#endif
5621 +#endif
5622 +
5623 #if defined(__sparc__) && defined(__arch64__)
5624 #include <asm/uaccess_64.h>
5625 #else
5626 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
5627 index 53a28dd..50c38c3 100644
5628 --- a/arch/sparc/include/asm/uaccess_32.h
5629 +++ b/arch/sparc/include/asm/uaccess_32.h
5630 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
5631
5632 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
5633 {
5634 - if (n && __access_ok((unsigned long) to, n))
5635 + if ((long)n < 0)
5636 + return n;
5637 +
5638 + if (n && __access_ok((unsigned long) to, n)) {
5639 + if (!__builtin_constant_p(n))
5640 + check_object_size(from, n, true);
5641 return __copy_user(to, (__force void __user *) from, n);
5642 - else
5643 + } else
5644 return n;
5645 }
5646
5647 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
5648 {
5649 + if ((long)n < 0)
5650 + return n;
5651 +
5652 + if (!__builtin_constant_p(n))
5653 + check_object_size(from, n, true);
5654 +
5655 return __copy_user(to, (__force void __user *) from, n);
5656 }
5657
5658 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
5659 {
5660 - if (n && __access_ok((unsigned long) from, n))
5661 + if ((long)n < 0)
5662 + return n;
5663 +
5664 + if (n && __access_ok((unsigned long) from, n)) {
5665 + if (!__builtin_constant_p(n))
5666 + check_object_size(to, n, false);
5667 return __copy_user((__force void __user *) to, from, n);
5668 - else
5669 + } else
5670 return n;
5671 }
5672
5673 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
5674 {
5675 + if ((long)n < 0)
5676 + return n;
5677 +
5678 return __copy_user((__force void __user *) to, from, n);
5679 }
5680
5681 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
5682 index 7c831d8..d440ca7 100644
5683 --- a/arch/sparc/include/asm/uaccess_64.h
5684 +++ b/arch/sparc/include/asm/uaccess_64.h
5685 @@ -10,6 +10,7 @@
5686 #include <linux/compiler.h>
5687 #include <linux/string.h>
5688 #include <linux/thread_info.h>
5689 +#include <linux/kernel.h>
5690 #include <asm/asi.h>
5691 #include <asm/spitfire.h>
5692 #include <asm-generic/uaccess-unaligned.h>
5693 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
5694 static inline unsigned long __must_check
5695 copy_from_user(void *to, const void __user *from, unsigned long size)
5696 {
5697 - unsigned long ret = ___copy_from_user(to, from, size);
5698 + unsigned long ret;
5699
5700 + if ((long)size < 0 || size > INT_MAX)
5701 + return size;
5702 +
5703 + if (!__builtin_constant_p(size))
5704 + check_object_size(to, size, false);
5705 +
5706 + ret = ___copy_from_user(to, from, size);
5707 if (unlikely(ret))
5708 ret = copy_from_user_fixup(to, from, size);
5709
5710 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
5711 static inline unsigned long __must_check
5712 copy_to_user(void __user *to, const void *from, unsigned long size)
5713 {
5714 - unsigned long ret = ___copy_to_user(to, from, size);
5715 + unsigned long ret;
5716
5717 + if ((long)size < 0 || size > INT_MAX)
5718 + return size;
5719 +
5720 + if (!__builtin_constant_p(size))
5721 + check_object_size(from, size, true);
5722 +
5723 + ret = ___copy_to_user(to, from, size);
5724 if (unlikely(ret))
5725 ret = copy_to_user_fixup(to, from, size);
5726 return ret;
5727 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
5728 index 6cf591b..b49e65a 100644
5729 --- a/arch/sparc/kernel/Makefile
5730 +++ b/arch/sparc/kernel/Makefile
5731 @@ -3,7 +3,7 @@
5732 #
5733
5734 asflags-y := -ansi
5735 -ccflags-y := -Werror
5736 +#ccflags-y := -Werror
5737
5738 extra-y := head_$(BITS).o
5739
5740 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
5741 index cb36e82..1c1462f 100644
5742 --- a/arch/sparc/kernel/process_32.c
5743 +++ b/arch/sparc/kernel/process_32.c
5744 @@ -126,14 +126,14 @@ void show_regs(struct pt_regs *r)
5745
5746 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
5747 r->psr, r->pc, r->npc, r->y, print_tainted());
5748 - printk("PC: <%pS>\n", (void *) r->pc);
5749 + printk("PC: <%pA>\n", (void *) r->pc);
5750 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5751 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
5752 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
5753 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5754 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
5755 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
5756 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
5757 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
5758
5759 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
5760 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
5761 @@ -168,7 +168,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
5762 rw = (struct reg_window32 *) fp;
5763 pc = rw->ins[7];
5764 printk("[%08lx : ", pc);
5765 - printk("%pS ] ", (void *) pc);
5766 + printk("%pA ] ", (void *) pc);
5767 fp = rw->ins[6];
5768 } while (++count < 16);
5769 printk("\n");
5770 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
5771 index aff0c72..9067b39 100644
5772 --- a/arch/sparc/kernel/process_64.c
5773 +++ b/arch/sparc/kernel/process_64.c
5774 @@ -179,14 +179,14 @@ static void show_regwindow(struct pt_regs *regs)
5775 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
5776 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
5777 if (regs->tstate & TSTATE_PRIV)
5778 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
5779 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
5780 }
5781
5782 void show_regs(struct pt_regs *regs)
5783 {
5784 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
5785 regs->tpc, regs->tnpc, regs->y, print_tainted());
5786 - printk("TPC: <%pS>\n", (void *) regs->tpc);
5787 + printk("TPC: <%pA>\n", (void *) regs->tpc);
5788 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
5789 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
5790 regs->u_regs[3]);
5791 @@ -199,7 +199,7 @@ void show_regs(struct pt_regs *regs)
5792 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
5793 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
5794 regs->u_regs[15]);
5795 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
5796 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
5797 show_regwindow(regs);
5798 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
5799 }
5800 @@ -284,7 +284,7 @@ void arch_trigger_all_cpu_backtrace(void)
5801 ((tp && tp->task) ? tp->task->pid : -1));
5802
5803 if (gp->tstate & TSTATE_PRIV) {
5804 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
5805 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
5806 (void *) gp->tpc,
5807 (void *) gp->o7,
5808 (void *) gp->i7,
5809 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
5810 index 484daba..0674139 100644
5811 --- a/arch/sparc/kernel/ptrace_64.c
5812 +++ b/arch/sparc/kernel/ptrace_64.c
5813 @@ -1057,6 +1057,10 @@ long arch_ptrace(struct task_struct *child, long request,
5814 return ret;
5815 }
5816
5817 +#ifdef CONFIG_GRKERNSEC_SETXID
5818 +extern void gr_delayed_cred_worker(void);
5819 +#endif
5820 +
5821 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5822 {
5823 int ret = 0;
5824 @@ -1064,6 +1068,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5825 /* do the secure computing check first */
5826 secure_computing_strict(regs->u_regs[UREG_G1]);
5827
5828 +#ifdef CONFIG_GRKERNSEC_SETXID
5829 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5830 + gr_delayed_cred_worker();
5831 +#endif
5832 +
5833 if (test_thread_flag(TIF_SYSCALL_TRACE))
5834 ret = tracehook_report_syscall_entry(regs);
5835
5836 @@ -1084,6 +1093,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
5837
5838 asmlinkage void syscall_trace_leave(struct pt_regs *regs)
5839 {
5840 +#ifdef CONFIG_GRKERNSEC_SETXID
5841 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
5842 + gr_delayed_cred_worker();
5843 +#endif
5844 +
5845 audit_syscall_exit(regs);
5846
5847 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
5848 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
5849 index 0c9b31b..7cb7aee 100644
5850 --- a/arch/sparc/kernel/sys_sparc_32.c
5851 +++ b/arch/sparc/kernel/sys_sparc_32.c
5852 @@ -54,7 +54,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5853 if (len > TASK_SIZE - PAGE_SIZE)
5854 return -ENOMEM;
5855 if (!addr)
5856 - addr = TASK_UNMAPPED_BASE;
5857 + addr = current->mm->mmap_base;
5858
5859 if (flags & MAP_SHARED)
5860 addr = COLOUR_ALIGN(addr);
5861 @@ -65,7 +65,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5862 /* At this point: (!vmm || addr < vmm->vm_end). */
5863 if (TASK_SIZE - PAGE_SIZE - len < addr)
5864 return -ENOMEM;
5865 - if (!vmm || addr + len <= vmm->vm_start)
5866 + if (check_heap_stack_gap(vmm, addr, len))
5867 return addr;
5868 addr = vmm->vm_end;
5869 if (flags & MAP_SHARED)
5870 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
5871 index 275f74f..81bf5b8 100644
5872 --- a/arch/sparc/kernel/sys_sparc_64.c
5873 +++ b/arch/sparc/kernel/sys_sparc_64.c
5874 @@ -124,7 +124,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5875 /* We do not accept a shared mapping if it would violate
5876 * cache aliasing constraints.
5877 */
5878 - if ((flags & MAP_SHARED) &&
5879 + if ((filp || (flags & MAP_SHARED)) &&
5880 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5881 return -EINVAL;
5882 return addr;
5883 @@ -139,6 +139,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5884 if (filp || (flags & MAP_SHARED))
5885 do_color_align = 1;
5886
5887 +#ifdef CONFIG_PAX_RANDMMAP
5888 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
5889 +#endif
5890 +
5891 if (addr) {
5892 if (do_color_align)
5893 addr = COLOUR_ALIGN(addr, pgoff);
5894 @@ -146,15 +150,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
5895 addr = PAGE_ALIGN(addr);
5896
5897 vma = find_vma(mm, addr);
5898 - if (task_size - len >= addr &&
5899 - (!vma || addr + len <= vma->vm_start))
5900 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5901 return addr;
5902 }
5903
5904 if (len > mm->cached_hole_size) {
5905 - start_addr = addr = mm->free_area_cache;
5906 + start_addr = addr = mm->free_area_cache;
5907 } else {
5908 - start_addr = addr = TASK_UNMAPPED_BASE;
5909 + start_addr = addr = mm->mmap_base;
5910 mm->cached_hole_size = 0;
5911 }
5912
5913 @@ -174,14 +177,14 @@ full_search:
5914 vma = find_vma(mm, VA_EXCLUDE_END);
5915 }
5916 if (unlikely(task_size < addr)) {
5917 - if (start_addr != TASK_UNMAPPED_BASE) {
5918 - start_addr = addr = TASK_UNMAPPED_BASE;
5919 + if (start_addr != mm->mmap_base) {
5920 + start_addr = addr = mm->mmap_base;
5921 mm->cached_hole_size = 0;
5922 goto full_search;
5923 }
5924 return -ENOMEM;
5925 }
5926 - if (likely(!vma || addr + len <= vma->vm_start)) {
5927 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5928 /*
5929 * Remember the place where we stopped the search:
5930 */
5931 @@ -215,7 +218,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5932 /* We do not accept a shared mapping if it would violate
5933 * cache aliasing constraints.
5934 */
5935 - if ((flags & MAP_SHARED) &&
5936 + if ((filp || (flags & MAP_SHARED)) &&
5937 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
5938 return -EINVAL;
5939 return addr;
5940 @@ -236,8 +239,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5941 addr = PAGE_ALIGN(addr);
5942
5943 vma = find_vma(mm, addr);
5944 - if (task_size - len >= addr &&
5945 - (!vma || addr + len <= vma->vm_start))
5946 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
5947 return addr;
5948 }
5949
5950 @@ -258,7 +260,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5951 /* make sure it can fit in the remaining address space */
5952 if (likely(addr > len)) {
5953 vma = find_vma(mm, addr-len);
5954 - if (!vma || addr <= vma->vm_start) {
5955 + if (check_heap_stack_gap(vma, addr - len, len)) {
5956 /* remember the address as a hint for next time */
5957 return (mm->free_area_cache = addr-len);
5958 }
5959 @@ -267,18 +269,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5960 if (unlikely(mm->mmap_base < len))
5961 goto bottomup;
5962
5963 - addr = mm->mmap_base-len;
5964 - if (do_color_align)
5965 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5966 + addr = mm->mmap_base - len;
5967
5968 do {
5969 + if (do_color_align)
5970 + addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5971 /*
5972 * Lookup failure means no vma is above this address,
5973 * else if new region fits below vma->vm_start,
5974 * return with success:
5975 */
5976 vma = find_vma(mm, addr);
5977 - if (likely(!vma || addr+len <= vma->vm_start)) {
5978 + if (likely(check_heap_stack_gap(vma, addr, len))) {
5979 /* remember the address as a hint for next time */
5980 return (mm->free_area_cache = addr);
5981 }
5982 @@ -288,10 +290,8 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
5983 mm->cached_hole_size = vma->vm_start - addr;
5984
5985 /* try just below the current vma->vm_start */
5986 - addr = vma->vm_start-len;
5987 - if (do_color_align)
5988 - addr = COLOUR_ALIGN_DOWN(addr, pgoff);
5989 - } while (likely(len < vma->vm_start));
5990 + addr = skip_heap_stack_gap(vma, len);
5991 + } while (!IS_ERR_VALUE(addr));
5992
5993 bottomup:
5994 /*
5995 @@ -390,6 +390,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
5996 gap == RLIM_INFINITY ||
5997 sysctl_legacy_va_layout) {
5998 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
5999 +
6000 +#ifdef CONFIG_PAX_RANDMMAP
6001 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6002 + mm->mmap_base += mm->delta_mmap;
6003 +#endif
6004 +
6005 mm->get_unmapped_area = arch_get_unmapped_area;
6006 mm->unmap_area = arch_unmap_area;
6007 } else {
6008 @@ -402,6 +408,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6009 gap = (task_size / 6 * 5);
6010
6011 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
6012 +
6013 +#ifdef CONFIG_PAX_RANDMMAP
6014 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6015 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6016 +#endif
6017 +
6018 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6019 mm->unmap_area = arch_unmap_area_topdown;
6020 }
6021 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
6022 index 1d7e274..b39c527 100644
6023 --- a/arch/sparc/kernel/syscalls.S
6024 +++ b/arch/sparc/kernel/syscalls.S
6025 @@ -62,7 +62,7 @@ sys32_rt_sigreturn:
6026 #endif
6027 .align 32
6028 1: ldx [%g6 + TI_FLAGS], %l5
6029 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6030 + andcc %l5, _TIF_WORK_SYSCALL, %g0
6031 be,pt %icc, rtrap
6032 nop
6033 call syscall_trace_leave
6034 @@ -179,7 +179,7 @@ linux_sparc_syscall32:
6035
6036 srl %i5, 0, %o5 ! IEU1
6037 srl %i2, 0, %o2 ! IEU0 Group
6038 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6039 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6040 bne,pn %icc, linux_syscall_trace32 ! CTI
6041 mov %i0, %l5 ! IEU1
6042 call %l7 ! CTI Group brk forced
6043 @@ -202,7 +202,7 @@ linux_sparc_syscall:
6044
6045 mov %i3, %o3 ! IEU1
6046 mov %i4, %o4 ! IEU0 Group
6047 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %g0
6048 + andcc %l0, _TIF_WORK_SYSCALL, %g0
6049 bne,pn %icc, linux_syscall_trace ! CTI Group
6050 mov %i0, %l5 ! IEU0
6051 2: call %l7 ! CTI Group brk forced
6052 @@ -226,7 +226,7 @@ ret_sys_call:
6053
6054 cmp %o0, -ERESTART_RESTARTBLOCK
6055 bgeu,pn %xcc, 1f
6056 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6057 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6058 80:
6059 /* System call success, clear Carry condition code. */
6060 andn %g3, %g2, %g3
6061 @@ -241,7 +241,7 @@ ret_sys_call:
6062 /* System call failure, set Carry condition code.
6063 * Also, get abs(errno) to return to the process.
6064 */
6065 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT), %l6
6066 + andcc %l0, _TIF_WORK_SYSCALL, %l6
6067 sub %g0, %o0, %o0
6068 or %g3, %g2, %g3
6069 stx %o0, [%sp + PTREGS_OFF + PT_V9_I0]
6070 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
6071 index a5785ea..405c5f7 100644
6072 --- a/arch/sparc/kernel/traps_32.c
6073 +++ b/arch/sparc/kernel/traps_32.c
6074 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
6075 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
6076 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
6077
6078 +extern void gr_handle_kernel_exploit(void);
6079 +
6080 void die_if_kernel(char *str, struct pt_regs *regs)
6081 {
6082 static int die_counter;
6083 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6084 count++ < 30 &&
6085 (((unsigned long) rw) >= PAGE_OFFSET) &&
6086 !(((unsigned long) rw) & 0x7)) {
6087 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
6088 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
6089 (void *) rw->ins[7]);
6090 rw = (struct reg_window32 *)rw->ins[6];
6091 }
6092 }
6093 printk("Instruction DUMP:");
6094 instruction_dump ((unsigned long *) regs->pc);
6095 - if(regs->psr & PSR_PS)
6096 + if(regs->psr & PSR_PS) {
6097 + gr_handle_kernel_exploit();
6098 do_exit(SIGKILL);
6099 + }
6100 do_exit(SIGSEGV);
6101 }
6102
6103 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
6104 index 3b05e66..6ea2917 100644
6105 --- a/arch/sparc/kernel/traps_64.c
6106 +++ b/arch/sparc/kernel/traps_64.c
6107 @@ -75,7 +75,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
6108 i + 1,
6109 p->trapstack[i].tstate, p->trapstack[i].tpc,
6110 p->trapstack[i].tnpc, p->trapstack[i].tt);
6111 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
6112 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
6113 }
6114 }
6115
6116 @@ -95,6 +95,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
6117
6118 lvl -= 0x100;
6119 if (regs->tstate & TSTATE_PRIV) {
6120 +
6121 +#ifdef CONFIG_PAX_REFCOUNT
6122 + if (lvl == 6)
6123 + pax_report_refcount_overflow(regs);
6124 +#endif
6125 +
6126 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
6127 die_if_kernel(buffer, regs);
6128 }
6129 @@ -113,11 +119,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
6130 void bad_trap_tl1(struct pt_regs *regs, long lvl)
6131 {
6132 char buffer[32];
6133 -
6134 +
6135 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
6136 0, lvl, SIGTRAP) == NOTIFY_STOP)
6137 return;
6138
6139 +#ifdef CONFIG_PAX_REFCOUNT
6140 + if (lvl == 6)
6141 + pax_report_refcount_overflow(regs);
6142 +#endif
6143 +
6144 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
6145
6146 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
6147 @@ -1141,7 +1152,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
6148 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
6149 printk("%s" "ERROR(%d): ",
6150 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
6151 - printk("TPC<%pS>\n", (void *) regs->tpc);
6152 + printk("TPC<%pA>\n", (void *) regs->tpc);
6153 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
6154 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
6155 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
6156 @@ -1748,7 +1759,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6157 smp_processor_id(),
6158 (type & 0x1) ? 'I' : 'D',
6159 regs->tpc);
6160 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
6161 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
6162 panic("Irrecoverable Cheetah+ parity error.");
6163 }
6164
6165 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
6166 smp_processor_id(),
6167 (type & 0x1) ? 'I' : 'D',
6168 regs->tpc);
6169 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
6170 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
6171 }
6172
6173 struct sun4v_error_entry {
6174 @@ -1963,9 +1974,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
6175
6176 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
6177 regs->tpc, tl);
6178 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
6179 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
6180 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6181 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
6182 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
6183 (void *) regs->u_regs[UREG_I7]);
6184 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
6185 "pte[%lx] error[%lx]\n",
6186 @@ -1987,9 +1998,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
6187
6188 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
6189 regs->tpc, tl);
6190 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
6191 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
6192 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
6193 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
6194 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
6195 (void *) regs->u_regs[UREG_I7]);
6196 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
6197 "pte[%lx] error[%lx]\n",
6198 @@ -2195,13 +2206,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
6199 fp = (unsigned long)sf->fp + STACK_BIAS;
6200 }
6201
6202 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6203 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6204 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
6205 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
6206 int index = tsk->curr_ret_stack;
6207 if (tsk->ret_stack && index >= graph) {
6208 pc = tsk->ret_stack[index - graph].ret;
6209 - printk(" [%016lx] %pS\n", pc, (void *) pc);
6210 + printk(" [%016lx] %pA\n", pc, (void *) pc);
6211 graph++;
6212 }
6213 }
6214 @@ -2226,6 +2237,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
6215 return (struct reg_window *) (fp + STACK_BIAS);
6216 }
6217
6218 +extern void gr_handle_kernel_exploit(void);
6219 +
6220 void die_if_kernel(char *str, struct pt_regs *regs)
6221 {
6222 static int die_counter;
6223 @@ -2254,7 +2267,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6224 while (rw &&
6225 count++ < 30 &&
6226 kstack_valid(tp, (unsigned long) rw)) {
6227 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
6228 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
6229 (void *) rw->ins[7]);
6230
6231 rw = kernel_stack_up(rw);
6232 @@ -2267,8 +2280,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
6233 }
6234 user_instruction_dump ((unsigned int __user *) regs->tpc);
6235 }
6236 - if (regs->tstate & TSTATE_PRIV)
6237 + if (regs->tstate & TSTATE_PRIV) {
6238 + gr_handle_kernel_exploit();
6239 do_exit(SIGKILL);
6240 + }
6241 do_exit(SIGSEGV);
6242 }
6243 EXPORT_SYMBOL(die_if_kernel);
6244 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
6245 index f81d038..e7a4680 100644
6246 --- a/arch/sparc/kernel/unaligned_64.c
6247 +++ b/arch/sparc/kernel/unaligned_64.c
6248 @@ -278,7 +278,7 @@ static void log_unaligned(struct pt_regs *regs)
6249 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
6250
6251 if (__ratelimit(&ratelimit)) {
6252 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
6253 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
6254 regs->tpc, (void *) regs->tpc);
6255 }
6256 }
6257 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
6258 index dff4096..bd9a388 100644
6259 --- a/arch/sparc/lib/Makefile
6260 +++ b/arch/sparc/lib/Makefile
6261 @@ -2,7 +2,7 @@
6262 #
6263
6264 asflags-y := -ansi -DST_DIV0=0x02
6265 -ccflags-y := -Werror
6266 +#ccflags-y := -Werror
6267
6268 lib-$(CONFIG_SPARC32) += ashrdi3.o
6269 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
6270 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
6271 index 4d502da..527c48d 100644
6272 --- a/arch/sparc/lib/atomic_64.S
6273 +++ b/arch/sparc/lib/atomic_64.S
6274 @@ -17,7 +17,12 @@
6275 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6276 BACKOFF_SETUP(%o2)
6277 1: lduw [%o1], %g1
6278 - add %g1, %o0, %g7
6279 + addcc %g1, %o0, %g7
6280 +
6281 +#ifdef CONFIG_PAX_REFCOUNT
6282 + tvs %icc, 6
6283 +#endif
6284 +
6285 cas [%o1], %g1, %g7
6286 cmp %g1, %g7
6287 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6288 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
6289 2: BACKOFF_SPIN(%o2, %o3, 1b)
6290 ENDPROC(atomic_add)
6291
6292 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6293 + BACKOFF_SETUP(%o2)
6294 +1: lduw [%o1], %g1
6295 + add %g1, %o0, %g7
6296 + cas [%o1], %g1, %g7
6297 + cmp %g1, %g7
6298 + bne,pn %icc, 2f
6299 + nop
6300 + retl
6301 + nop
6302 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6303 +ENDPROC(atomic_add_unchecked)
6304 +
6305 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6306 BACKOFF_SETUP(%o2)
6307 1: lduw [%o1], %g1
6308 - sub %g1, %o0, %g7
6309 + subcc %g1, %o0, %g7
6310 +
6311 +#ifdef CONFIG_PAX_REFCOUNT
6312 + tvs %icc, 6
6313 +#endif
6314 +
6315 cas [%o1], %g1, %g7
6316 cmp %g1, %g7
6317 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6318 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6319 2: BACKOFF_SPIN(%o2, %o3, 1b)
6320 ENDPROC(atomic_sub)
6321
6322 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6323 + BACKOFF_SETUP(%o2)
6324 +1: lduw [%o1], %g1
6325 + sub %g1, %o0, %g7
6326 + cas [%o1], %g1, %g7
6327 + cmp %g1, %g7
6328 + bne,pn %icc, 2f
6329 + nop
6330 + retl
6331 + nop
6332 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6333 +ENDPROC(atomic_sub_unchecked)
6334 +
6335 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6336 BACKOFF_SETUP(%o2)
6337 1: lduw [%o1], %g1
6338 - add %g1, %o0, %g7
6339 + addcc %g1, %o0, %g7
6340 +
6341 +#ifdef CONFIG_PAX_REFCOUNT
6342 + tvs %icc, 6
6343 +#endif
6344 +
6345 cas [%o1], %g1, %g7
6346 cmp %g1, %g7
6347 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6348 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6349 2: BACKOFF_SPIN(%o2, %o3, 1b)
6350 ENDPROC(atomic_add_ret)
6351
6352 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6353 + BACKOFF_SETUP(%o2)
6354 +1: lduw [%o1], %g1
6355 + addcc %g1, %o0, %g7
6356 + cas [%o1], %g1, %g7
6357 + cmp %g1, %g7
6358 + bne,pn %icc, 2f
6359 + add %g7, %o0, %g7
6360 + sra %g7, 0, %o0
6361 + retl
6362 + nop
6363 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6364 +ENDPROC(atomic_add_ret_unchecked)
6365 +
6366 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6367 BACKOFF_SETUP(%o2)
6368 1: lduw [%o1], %g1
6369 - sub %g1, %o0, %g7
6370 + subcc %g1, %o0, %g7
6371 +
6372 +#ifdef CONFIG_PAX_REFCOUNT
6373 + tvs %icc, 6
6374 +#endif
6375 +
6376 cas [%o1], %g1, %g7
6377 cmp %g1, %g7
6378 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
6379 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
6380 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6381 BACKOFF_SETUP(%o2)
6382 1: ldx [%o1], %g1
6383 - add %g1, %o0, %g7
6384 + addcc %g1, %o0, %g7
6385 +
6386 +#ifdef CONFIG_PAX_REFCOUNT
6387 + tvs %xcc, 6
6388 +#endif
6389 +
6390 casx [%o1], %g1, %g7
6391 cmp %g1, %g7
6392 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6393 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
6394 2: BACKOFF_SPIN(%o2, %o3, 1b)
6395 ENDPROC(atomic64_add)
6396
6397 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6398 + BACKOFF_SETUP(%o2)
6399 +1: ldx [%o1], %g1
6400 + addcc %g1, %o0, %g7
6401 + casx [%o1], %g1, %g7
6402 + cmp %g1, %g7
6403 + bne,pn %xcc, 2f
6404 + nop
6405 + retl
6406 + nop
6407 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6408 +ENDPROC(atomic64_add_unchecked)
6409 +
6410 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6411 BACKOFF_SETUP(%o2)
6412 1: ldx [%o1], %g1
6413 - sub %g1, %o0, %g7
6414 + subcc %g1, %o0, %g7
6415 +
6416 +#ifdef CONFIG_PAX_REFCOUNT
6417 + tvs %xcc, 6
6418 +#endif
6419 +
6420 casx [%o1], %g1, %g7
6421 cmp %g1, %g7
6422 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6423 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
6424 2: BACKOFF_SPIN(%o2, %o3, 1b)
6425 ENDPROC(atomic64_sub)
6426
6427 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
6428 + BACKOFF_SETUP(%o2)
6429 +1: ldx [%o1], %g1
6430 + subcc %g1, %o0, %g7
6431 + casx [%o1], %g1, %g7
6432 + cmp %g1, %g7
6433 + bne,pn %xcc, 2f
6434 + nop
6435 + retl
6436 + nop
6437 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6438 +ENDPROC(atomic64_sub_unchecked)
6439 +
6440 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6441 BACKOFF_SETUP(%o2)
6442 1: ldx [%o1], %g1
6443 - add %g1, %o0, %g7
6444 + addcc %g1, %o0, %g7
6445 +
6446 +#ifdef CONFIG_PAX_REFCOUNT
6447 + tvs %xcc, 6
6448 +#endif
6449 +
6450 casx [%o1], %g1, %g7
6451 cmp %g1, %g7
6452 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6453 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
6454 2: BACKOFF_SPIN(%o2, %o3, 1b)
6455 ENDPROC(atomic64_add_ret)
6456
6457 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
6458 + BACKOFF_SETUP(%o2)
6459 +1: ldx [%o1], %g1
6460 + addcc %g1, %o0, %g7
6461 + casx [%o1], %g1, %g7
6462 + cmp %g1, %g7
6463 + bne,pn %xcc, 2f
6464 + add %g7, %o0, %g7
6465 + mov %g7, %o0
6466 + retl
6467 + nop
6468 +2: BACKOFF_SPIN(%o2, %o3, 1b)
6469 +ENDPROC(atomic64_add_ret_unchecked)
6470 +
6471 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
6472 BACKOFF_SETUP(%o2)
6473 1: ldx [%o1], %g1
6474 - sub %g1, %o0, %g7
6475 + subcc %g1, %o0, %g7
6476 +
6477 +#ifdef CONFIG_PAX_REFCOUNT
6478 + tvs %xcc, 6
6479 +#endif
6480 +
6481 casx [%o1], %g1, %g7
6482 cmp %g1, %g7
6483 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
6484 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
6485 index 3b31218..345c609 100644
6486 --- a/arch/sparc/lib/ksyms.c
6487 +++ b/arch/sparc/lib/ksyms.c
6488 @@ -109,12 +109,18 @@ EXPORT_SYMBOL(__downgrade_write);
6489
6490 /* Atomic counter implementation. */
6491 EXPORT_SYMBOL(atomic_add);
6492 +EXPORT_SYMBOL(atomic_add_unchecked);
6493 EXPORT_SYMBOL(atomic_add_ret);
6494 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
6495 EXPORT_SYMBOL(atomic_sub);
6496 +EXPORT_SYMBOL(atomic_sub_unchecked);
6497 EXPORT_SYMBOL(atomic_sub_ret);
6498 EXPORT_SYMBOL(atomic64_add);
6499 +EXPORT_SYMBOL(atomic64_add_unchecked);
6500 EXPORT_SYMBOL(atomic64_add_ret);
6501 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
6502 EXPORT_SYMBOL(atomic64_sub);
6503 +EXPORT_SYMBOL(atomic64_sub_unchecked);
6504 EXPORT_SYMBOL(atomic64_sub_ret);
6505
6506 /* Atomic bit operations. */
6507 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
6508 index 30c3ecc..736f015 100644
6509 --- a/arch/sparc/mm/Makefile
6510 +++ b/arch/sparc/mm/Makefile
6511 @@ -2,7 +2,7 @@
6512 #
6513
6514 asflags-y := -ansi
6515 -ccflags-y := -Werror
6516 +#ccflags-y := -Werror
6517
6518 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
6519 obj-y += fault_$(BITS).o
6520 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
6521 index f46cf6b..7235ec9 100644
6522 --- a/arch/sparc/mm/fault_32.c
6523 +++ b/arch/sparc/mm/fault_32.c
6524 @@ -21,6 +21,9 @@
6525 #include <linux/perf_event.h>
6526 #include <linux/interrupt.h>
6527 #include <linux/kdebug.h>
6528 +#include <linux/slab.h>
6529 +#include <linux/pagemap.h>
6530 +#include <linux/compiler.h>
6531
6532 #include <asm/page.h>
6533 #include <asm/pgtable.h>
6534 @@ -177,6 +180,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
6535 return safe_compute_effective_address(regs, insn);
6536 }
6537
6538 +#ifdef CONFIG_PAX_PAGEEXEC
6539 +#ifdef CONFIG_PAX_DLRESOLVE
6540 +static void pax_emuplt_close(struct vm_area_struct *vma)
6541 +{
6542 + vma->vm_mm->call_dl_resolve = 0UL;
6543 +}
6544 +
6545 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6546 +{
6547 + unsigned int *kaddr;
6548 +
6549 + vmf->page = alloc_page(GFP_HIGHUSER);
6550 + if (!vmf->page)
6551 + return VM_FAULT_OOM;
6552 +
6553 + kaddr = kmap(vmf->page);
6554 + memset(kaddr, 0, PAGE_SIZE);
6555 + kaddr[0] = 0x9DE3BFA8U; /* save */
6556 + flush_dcache_page(vmf->page);
6557 + kunmap(vmf->page);
6558 + return VM_FAULT_MAJOR;
6559 +}
6560 +
6561 +static const struct vm_operations_struct pax_vm_ops = {
6562 + .close = pax_emuplt_close,
6563 + .fault = pax_emuplt_fault
6564 +};
6565 +
6566 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6567 +{
6568 + int ret;
6569 +
6570 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6571 + vma->vm_mm = current->mm;
6572 + vma->vm_start = addr;
6573 + vma->vm_end = addr + PAGE_SIZE;
6574 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6575 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6576 + vma->vm_ops = &pax_vm_ops;
6577 +
6578 + ret = insert_vm_struct(current->mm, vma);
6579 + if (ret)
6580 + return ret;
6581 +
6582 + ++current->mm->total_vm;
6583 + return 0;
6584 +}
6585 +#endif
6586 +
6587 +/*
6588 + * PaX: decide what to do with offenders (regs->pc = fault address)
6589 + *
6590 + * returns 1 when task should be killed
6591 + * 2 when patched PLT trampoline was detected
6592 + * 3 when unpatched PLT trampoline was detected
6593 + */
6594 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6595 +{
6596 +
6597 +#ifdef CONFIG_PAX_EMUPLT
6598 + int err;
6599 +
6600 + do { /* PaX: patched PLT emulation #1 */
6601 + unsigned int sethi1, sethi2, jmpl;
6602 +
6603 + err = get_user(sethi1, (unsigned int *)regs->pc);
6604 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
6605 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
6606 +
6607 + if (err)
6608 + break;
6609 +
6610 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6611 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6612 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6613 + {
6614 + unsigned int addr;
6615 +
6616 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6617 + addr = regs->u_regs[UREG_G1];
6618 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6619 + regs->pc = addr;
6620 + regs->npc = addr+4;
6621 + return 2;
6622 + }
6623 + } while (0);
6624 +
6625 + do { /* PaX: patched PLT emulation #2 */
6626 + unsigned int ba;
6627 +
6628 + err = get_user(ba, (unsigned int *)regs->pc);
6629 +
6630 + if (err)
6631 + break;
6632 +
6633 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6634 + unsigned int addr;
6635 +
6636 + if ((ba & 0xFFC00000U) == 0x30800000U)
6637 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6638 + else
6639 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6640 + regs->pc = addr;
6641 + regs->npc = addr+4;
6642 + return 2;
6643 + }
6644 + } while (0);
6645 +
6646 + do { /* PaX: patched PLT emulation #3 */
6647 + unsigned int sethi, bajmpl, nop;
6648 +
6649 + err = get_user(sethi, (unsigned int *)regs->pc);
6650 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
6651 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6652 +
6653 + if (err)
6654 + break;
6655 +
6656 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6657 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6658 + nop == 0x01000000U)
6659 + {
6660 + unsigned int addr;
6661 +
6662 + addr = (sethi & 0x003FFFFFU) << 10;
6663 + regs->u_regs[UREG_G1] = addr;
6664 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6665 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6666 + else
6667 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6668 + regs->pc = addr;
6669 + regs->npc = addr+4;
6670 + return 2;
6671 + }
6672 + } while (0);
6673 +
6674 + do { /* PaX: unpatched PLT emulation step 1 */
6675 + unsigned int sethi, ba, nop;
6676 +
6677 + err = get_user(sethi, (unsigned int *)regs->pc);
6678 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
6679 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
6680 +
6681 + if (err)
6682 + break;
6683 +
6684 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6685 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
6686 + nop == 0x01000000U)
6687 + {
6688 + unsigned int addr, save, call;
6689 +
6690 + if ((ba & 0xFFC00000U) == 0x30800000U)
6691 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
6692 + else
6693 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
6694 +
6695 + err = get_user(save, (unsigned int *)addr);
6696 + err |= get_user(call, (unsigned int *)(addr+4));
6697 + err |= get_user(nop, (unsigned int *)(addr+8));
6698 + if (err)
6699 + break;
6700 +
6701 +#ifdef CONFIG_PAX_DLRESOLVE
6702 + if (save == 0x9DE3BFA8U &&
6703 + (call & 0xC0000000U) == 0x40000000U &&
6704 + nop == 0x01000000U)
6705 + {
6706 + struct vm_area_struct *vma;
6707 + unsigned long call_dl_resolve;
6708 +
6709 + down_read(&current->mm->mmap_sem);
6710 + call_dl_resolve = current->mm->call_dl_resolve;
6711 + up_read(&current->mm->mmap_sem);
6712 + if (likely(call_dl_resolve))
6713 + goto emulate;
6714 +
6715 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
6716 +
6717 + down_write(&current->mm->mmap_sem);
6718 + if (current->mm->call_dl_resolve) {
6719 + call_dl_resolve = current->mm->call_dl_resolve;
6720 + up_write(&current->mm->mmap_sem);
6721 + if (vma)
6722 + kmem_cache_free(vm_area_cachep, vma);
6723 + goto emulate;
6724 + }
6725 +
6726 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
6727 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
6728 + up_write(&current->mm->mmap_sem);
6729 + if (vma)
6730 + kmem_cache_free(vm_area_cachep, vma);
6731 + return 1;
6732 + }
6733 +
6734 + if (pax_insert_vma(vma, call_dl_resolve)) {
6735 + up_write(&current->mm->mmap_sem);
6736 + kmem_cache_free(vm_area_cachep, vma);
6737 + return 1;
6738 + }
6739 +
6740 + current->mm->call_dl_resolve = call_dl_resolve;
6741 + up_write(&current->mm->mmap_sem);
6742 +
6743 +emulate:
6744 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6745 + regs->pc = call_dl_resolve;
6746 + regs->npc = addr+4;
6747 + return 3;
6748 + }
6749 +#endif
6750 +
6751 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
6752 + if ((save & 0xFFC00000U) == 0x05000000U &&
6753 + (call & 0xFFFFE000U) == 0x85C0A000U &&
6754 + nop == 0x01000000U)
6755 + {
6756 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
6757 + regs->u_regs[UREG_G2] = addr + 4;
6758 + addr = (save & 0x003FFFFFU) << 10;
6759 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
6760 + regs->pc = addr;
6761 + regs->npc = addr+4;
6762 + return 3;
6763 + }
6764 + }
6765 + } while (0);
6766 +
6767 + do { /* PaX: unpatched PLT emulation step 2 */
6768 + unsigned int save, call, nop;
6769 +
6770 + err = get_user(save, (unsigned int *)(regs->pc-4));
6771 + err |= get_user(call, (unsigned int *)regs->pc);
6772 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
6773 + if (err)
6774 + break;
6775 +
6776 + if (save == 0x9DE3BFA8U &&
6777 + (call & 0xC0000000U) == 0x40000000U &&
6778 + nop == 0x01000000U)
6779 + {
6780 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
6781 +
6782 + regs->u_regs[UREG_RETPC] = regs->pc;
6783 + regs->pc = dl_resolve;
6784 + regs->npc = dl_resolve+4;
6785 + return 3;
6786 + }
6787 + } while (0);
6788 +#endif
6789 +
6790 + return 1;
6791 +}
6792 +
6793 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6794 +{
6795 + unsigned long i;
6796 +
6797 + printk(KERN_ERR "PAX: bytes at PC: ");
6798 + for (i = 0; i < 8; i++) {
6799 + unsigned int c;
6800 + if (get_user(c, (unsigned int *)pc+i))
6801 + printk(KERN_CONT "???????? ");
6802 + else
6803 + printk(KERN_CONT "%08x ", c);
6804 + }
6805 + printk("\n");
6806 +}
6807 +#endif
6808 +
6809 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
6810 int text_fault)
6811 {
6812 @@ -248,6 +522,24 @@ good_area:
6813 if (!(vma->vm_flags & VM_WRITE))
6814 goto bad_area;
6815 } else {
6816 +
6817 +#ifdef CONFIG_PAX_PAGEEXEC
6818 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
6819 + up_read(&mm->mmap_sem);
6820 + switch (pax_handle_fetch_fault(regs)) {
6821 +
6822 +#ifdef CONFIG_PAX_EMUPLT
6823 + case 2:
6824 + case 3:
6825 + return;
6826 +#endif
6827 +
6828 + }
6829 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
6830 + do_group_exit(SIGKILL);
6831 + }
6832 +#endif
6833 +
6834 /* Allow reads even for write-only mappings */
6835 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
6836 goto bad_area;
6837 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
6838 index 1fe0429..8dd5dd5 100644
6839 --- a/arch/sparc/mm/fault_64.c
6840 +++ b/arch/sparc/mm/fault_64.c
6841 @@ -21,6 +21,9 @@
6842 #include <linux/kprobes.h>
6843 #include <linux/kdebug.h>
6844 #include <linux/percpu.h>
6845 +#include <linux/slab.h>
6846 +#include <linux/pagemap.h>
6847 +#include <linux/compiler.h>
6848
6849 #include <asm/page.h>
6850 #include <asm/pgtable.h>
6851 @@ -74,7 +77,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
6852 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
6853 regs->tpc);
6854 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
6855 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
6856 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
6857 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
6858 dump_stack();
6859 unhandled_fault(regs->tpc, current, regs);
6860 @@ -272,6 +275,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
6861 show_regs(regs);
6862 }
6863
6864 +#ifdef CONFIG_PAX_PAGEEXEC
6865 +#ifdef CONFIG_PAX_DLRESOLVE
6866 +static void pax_emuplt_close(struct vm_area_struct *vma)
6867 +{
6868 + vma->vm_mm->call_dl_resolve = 0UL;
6869 +}
6870 +
6871 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
6872 +{
6873 + unsigned int *kaddr;
6874 +
6875 + vmf->page = alloc_page(GFP_HIGHUSER);
6876 + if (!vmf->page)
6877 + return VM_FAULT_OOM;
6878 +
6879 + kaddr = kmap(vmf->page);
6880 + memset(kaddr, 0, PAGE_SIZE);
6881 + kaddr[0] = 0x9DE3BFA8U; /* save */
6882 + flush_dcache_page(vmf->page);
6883 + kunmap(vmf->page);
6884 + return VM_FAULT_MAJOR;
6885 +}
6886 +
6887 +static const struct vm_operations_struct pax_vm_ops = {
6888 + .close = pax_emuplt_close,
6889 + .fault = pax_emuplt_fault
6890 +};
6891 +
6892 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
6893 +{
6894 + int ret;
6895 +
6896 + INIT_LIST_HEAD(&vma->anon_vma_chain);
6897 + vma->vm_mm = current->mm;
6898 + vma->vm_start = addr;
6899 + vma->vm_end = addr + PAGE_SIZE;
6900 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
6901 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
6902 + vma->vm_ops = &pax_vm_ops;
6903 +
6904 + ret = insert_vm_struct(current->mm, vma);
6905 + if (ret)
6906 + return ret;
6907 +
6908 + ++current->mm->total_vm;
6909 + return 0;
6910 +}
6911 +#endif
6912 +
6913 +/*
6914 + * PaX: decide what to do with offenders (regs->tpc = fault address)
6915 + *
6916 + * returns 1 when task should be killed
6917 + * 2 when patched PLT trampoline was detected
6918 + * 3 when unpatched PLT trampoline was detected
6919 + */
6920 +static int pax_handle_fetch_fault(struct pt_regs *regs)
6921 +{
6922 +
6923 +#ifdef CONFIG_PAX_EMUPLT
6924 + int err;
6925 +
6926 + do { /* PaX: patched PLT emulation #1 */
6927 + unsigned int sethi1, sethi2, jmpl;
6928 +
6929 + err = get_user(sethi1, (unsigned int *)regs->tpc);
6930 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
6931 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
6932 +
6933 + if (err)
6934 + break;
6935 +
6936 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
6937 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
6938 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
6939 + {
6940 + unsigned long addr;
6941 +
6942 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
6943 + addr = regs->u_regs[UREG_G1];
6944 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
6945 +
6946 + if (test_thread_flag(TIF_32BIT))
6947 + addr &= 0xFFFFFFFFUL;
6948 +
6949 + regs->tpc = addr;
6950 + regs->tnpc = addr+4;
6951 + return 2;
6952 + }
6953 + } while (0);
6954 +
6955 + do { /* PaX: patched PLT emulation #2 */
6956 + unsigned int ba;
6957 +
6958 + err = get_user(ba, (unsigned int *)regs->tpc);
6959 +
6960 + if (err)
6961 + break;
6962 +
6963 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
6964 + unsigned long addr;
6965 +
6966 + if ((ba & 0xFFC00000U) == 0x30800000U)
6967 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
6968 + else
6969 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
6970 +
6971 + if (test_thread_flag(TIF_32BIT))
6972 + addr &= 0xFFFFFFFFUL;
6973 +
6974 + regs->tpc = addr;
6975 + regs->tnpc = addr+4;
6976 + return 2;
6977 + }
6978 + } while (0);
6979 +
6980 + do { /* PaX: patched PLT emulation #3 */
6981 + unsigned int sethi, bajmpl, nop;
6982 +
6983 + err = get_user(sethi, (unsigned int *)regs->tpc);
6984 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
6985 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
6986 +
6987 + if (err)
6988 + break;
6989 +
6990 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
6991 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
6992 + nop == 0x01000000U)
6993 + {
6994 + unsigned long addr;
6995 +
6996 + addr = (sethi & 0x003FFFFFU) << 10;
6997 + regs->u_regs[UREG_G1] = addr;
6998 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
6999 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7000 + else
7001 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7002 +
7003 + if (test_thread_flag(TIF_32BIT))
7004 + addr &= 0xFFFFFFFFUL;
7005 +
7006 + regs->tpc = addr;
7007 + regs->tnpc = addr+4;
7008 + return 2;
7009 + }
7010 + } while (0);
7011 +
7012 + do { /* PaX: patched PLT emulation #4 */
7013 + unsigned int sethi, mov1, call, mov2;
7014 +
7015 + err = get_user(sethi, (unsigned int *)regs->tpc);
7016 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
7017 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
7018 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
7019 +
7020 + if (err)
7021 + break;
7022 +
7023 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7024 + mov1 == 0x8210000FU &&
7025 + (call & 0xC0000000U) == 0x40000000U &&
7026 + mov2 == 0x9E100001U)
7027 + {
7028 + unsigned long addr;
7029 +
7030 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
7031 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7032 +
7033 + if (test_thread_flag(TIF_32BIT))
7034 + addr &= 0xFFFFFFFFUL;
7035 +
7036 + regs->tpc = addr;
7037 + regs->tnpc = addr+4;
7038 + return 2;
7039 + }
7040 + } while (0);
7041 +
7042 + do { /* PaX: patched PLT emulation #5 */
7043 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
7044 +
7045 + err = get_user(sethi, (unsigned int *)regs->tpc);
7046 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7047 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7048 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
7049 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
7050 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
7051 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
7052 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
7053 +
7054 + if (err)
7055 + break;
7056 +
7057 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7058 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7059 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7060 + (or1 & 0xFFFFE000U) == 0x82106000U &&
7061 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7062 + sllx == 0x83287020U &&
7063 + jmpl == 0x81C04005U &&
7064 + nop == 0x01000000U)
7065 + {
7066 + unsigned long addr;
7067 +
7068 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7069 + regs->u_regs[UREG_G1] <<= 32;
7070 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7071 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7072 + regs->tpc = addr;
7073 + regs->tnpc = addr+4;
7074 + return 2;
7075 + }
7076 + } while (0);
7077 +
7078 + do { /* PaX: patched PLT emulation #6 */
7079 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
7080 +
7081 + err = get_user(sethi, (unsigned int *)regs->tpc);
7082 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
7083 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
7084 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
7085 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
7086 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
7087 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
7088 +
7089 + if (err)
7090 + break;
7091 +
7092 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7093 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
7094 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7095 + sllx == 0x83287020U &&
7096 + (or & 0xFFFFE000U) == 0x8A116000U &&
7097 + jmpl == 0x81C04005U &&
7098 + nop == 0x01000000U)
7099 + {
7100 + unsigned long addr;
7101 +
7102 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
7103 + regs->u_regs[UREG_G1] <<= 32;
7104 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
7105 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
7106 + regs->tpc = addr;
7107 + regs->tnpc = addr+4;
7108 + return 2;
7109 + }
7110 + } while (0);
7111 +
7112 + do { /* PaX: unpatched PLT emulation step 1 */
7113 + unsigned int sethi, ba, nop;
7114 +
7115 + err = get_user(sethi, (unsigned int *)regs->tpc);
7116 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7117 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7118 +
7119 + if (err)
7120 + break;
7121 +
7122 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7123 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
7124 + nop == 0x01000000U)
7125 + {
7126 + unsigned long addr;
7127 + unsigned int save, call;
7128 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
7129 +
7130 + if ((ba & 0xFFC00000U) == 0x30800000U)
7131 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
7132 + else
7133 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7134 +
7135 + if (test_thread_flag(TIF_32BIT))
7136 + addr &= 0xFFFFFFFFUL;
7137 +
7138 + err = get_user(save, (unsigned int *)addr);
7139 + err |= get_user(call, (unsigned int *)(addr+4));
7140 + err |= get_user(nop, (unsigned int *)(addr+8));
7141 + if (err)
7142 + break;
7143 +
7144 +#ifdef CONFIG_PAX_DLRESOLVE
7145 + if (save == 0x9DE3BFA8U &&
7146 + (call & 0xC0000000U) == 0x40000000U &&
7147 + nop == 0x01000000U)
7148 + {
7149 + struct vm_area_struct *vma;
7150 + unsigned long call_dl_resolve;
7151 +
7152 + down_read(&current->mm->mmap_sem);
7153 + call_dl_resolve = current->mm->call_dl_resolve;
7154 + up_read(&current->mm->mmap_sem);
7155 + if (likely(call_dl_resolve))
7156 + goto emulate;
7157 +
7158 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
7159 +
7160 + down_write(&current->mm->mmap_sem);
7161 + if (current->mm->call_dl_resolve) {
7162 + call_dl_resolve = current->mm->call_dl_resolve;
7163 + up_write(&current->mm->mmap_sem);
7164 + if (vma)
7165 + kmem_cache_free(vm_area_cachep, vma);
7166 + goto emulate;
7167 + }
7168 +
7169 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
7170 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
7171 + up_write(&current->mm->mmap_sem);
7172 + if (vma)
7173 + kmem_cache_free(vm_area_cachep, vma);
7174 + return 1;
7175 + }
7176 +
7177 + if (pax_insert_vma(vma, call_dl_resolve)) {
7178 + up_write(&current->mm->mmap_sem);
7179 + kmem_cache_free(vm_area_cachep, vma);
7180 + return 1;
7181 + }
7182 +
7183 + current->mm->call_dl_resolve = call_dl_resolve;
7184 + up_write(&current->mm->mmap_sem);
7185 +
7186 +emulate:
7187 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7188 + regs->tpc = call_dl_resolve;
7189 + regs->tnpc = addr+4;
7190 + return 3;
7191 + }
7192 +#endif
7193 +
7194 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
7195 + if ((save & 0xFFC00000U) == 0x05000000U &&
7196 + (call & 0xFFFFE000U) == 0x85C0A000U &&
7197 + nop == 0x01000000U)
7198 + {
7199 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7200 + regs->u_regs[UREG_G2] = addr + 4;
7201 + addr = (save & 0x003FFFFFU) << 10;
7202 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
7203 +
7204 + if (test_thread_flag(TIF_32BIT))
7205 + addr &= 0xFFFFFFFFUL;
7206 +
7207 + regs->tpc = addr;
7208 + regs->tnpc = addr+4;
7209 + return 3;
7210 + }
7211 +
7212 + /* PaX: 64-bit PLT stub */
7213 + err = get_user(sethi1, (unsigned int *)addr);
7214 + err |= get_user(sethi2, (unsigned int *)(addr+4));
7215 + err |= get_user(or1, (unsigned int *)(addr+8));
7216 + err |= get_user(or2, (unsigned int *)(addr+12));
7217 + err |= get_user(sllx, (unsigned int *)(addr+16));
7218 + err |= get_user(add, (unsigned int *)(addr+20));
7219 + err |= get_user(jmpl, (unsigned int *)(addr+24));
7220 + err |= get_user(nop, (unsigned int *)(addr+28));
7221 + if (err)
7222 + break;
7223 +
7224 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
7225 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
7226 + (or1 & 0xFFFFE000U) == 0x88112000U &&
7227 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
7228 + sllx == 0x89293020U &&
7229 + add == 0x8A010005U &&
7230 + jmpl == 0x89C14000U &&
7231 + nop == 0x01000000U)
7232 + {
7233 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
7234 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
7235 + regs->u_regs[UREG_G4] <<= 32;
7236 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
7237 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
7238 + regs->u_regs[UREG_G4] = addr + 24;
7239 + addr = regs->u_regs[UREG_G5];
7240 + regs->tpc = addr;
7241 + regs->tnpc = addr+4;
7242 + return 3;
7243 + }
7244 + }
7245 + } while (0);
7246 +
7247 +#ifdef CONFIG_PAX_DLRESOLVE
7248 + do { /* PaX: unpatched PLT emulation step 2 */
7249 + unsigned int save, call, nop;
7250 +
7251 + err = get_user(save, (unsigned int *)(regs->tpc-4));
7252 + err |= get_user(call, (unsigned int *)regs->tpc);
7253 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
7254 + if (err)
7255 + break;
7256 +
7257 + if (save == 0x9DE3BFA8U &&
7258 + (call & 0xC0000000U) == 0x40000000U &&
7259 + nop == 0x01000000U)
7260 + {
7261 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
7262 +
7263 + if (test_thread_flag(TIF_32BIT))
7264 + dl_resolve &= 0xFFFFFFFFUL;
7265 +
7266 + regs->u_regs[UREG_RETPC] = regs->tpc;
7267 + regs->tpc = dl_resolve;
7268 + regs->tnpc = dl_resolve+4;
7269 + return 3;
7270 + }
7271 + } while (0);
7272 +#endif
7273 +
7274 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
7275 + unsigned int sethi, ba, nop;
7276 +
7277 + err = get_user(sethi, (unsigned int *)regs->tpc);
7278 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
7279 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
7280 +
7281 + if (err)
7282 + break;
7283 +
7284 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
7285 + (ba & 0xFFF00000U) == 0x30600000U &&
7286 + nop == 0x01000000U)
7287 + {
7288 + unsigned long addr;
7289 +
7290 + addr = (sethi & 0x003FFFFFU) << 10;
7291 + regs->u_regs[UREG_G1] = addr;
7292 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
7293 +
7294 + if (test_thread_flag(TIF_32BIT))
7295 + addr &= 0xFFFFFFFFUL;
7296 +
7297 + regs->tpc = addr;
7298 + regs->tnpc = addr+4;
7299 + return 2;
7300 + }
7301 + } while (0);
7302 +
7303 +#endif
7304 +
7305 + return 1;
7306 +}
7307 +
7308 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7309 +{
7310 + unsigned long i;
7311 +
7312 + printk(KERN_ERR "PAX: bytes at PC: ");
7313 + for (i = 0; i < 8; i++) {
7314 + unsigned int c;
7315 + if (get_user(c, (unsigned int *)pc+i))
7316 + printk(KERN_CONT "???????? ");
7317 + else
7318 + printk(KERN_CONT "%08x ", c);
7319 + }
7320 + printk("\n");
7321 +}
7322 +#endif
7323 +
7324 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
7325 {
7326 struct mm_struct *mm = current->mm;
7327 @@ -343,6 +806,29 @@ retry:
7328 if (!vma)
7329 goto bad_area;
7330
7331 +#ifdef CONFIG_PAX_PAGEEXEC
7332 + /* PaX: detect ITLB misses on non-exec pages */
7333 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
7334 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
7335 + {
7336 + if (address != regs->tpc)
7337 + goto good_area;
7338 +
7339 + up_read(&mm->mmap_sem);
7340 + switch (pax_handle_fetch_fault(regs)) {
7341 +
7342 +#ifdef CONFIG_PAX_EMUPLT
7343 + case 2:
7344 + case 3:
7345 + return;
7346 +#endif
7347 +
7348 + }
7349 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
7350 + do_group_exit(SIGKILL);
7351 + }
7352 +#endif
7353 +
7354 /* Pure DTLB misses do not tell us whether the fault causing
7355 * load/store/atomic was a write or not, it only says that there
7356 * was no match. So in such a case we (carefully) read the
7357 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
7358 index 07e1453..0a7d9e9 100644
7359 --- a/arch/sparc/mm/hugetlbpage.c
7360 +++ b/arch/sparc/mm/hugetlbpage.c
7361 @@ -67,7 +67,7 @@ full_search:
7362 }
7363 return -ENOMEM;
7364 }
7365 - if (likely(!vma || addr + len <= vma->vm_start)) {
7366 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7367 /*
7368 * Remember the place where we stopped the search:
7369 */
7370 @@ -106,7 +106,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7371 /* make sure it can fit in the remaining address space */
7372 if (likely(addr > len)) {
7373 vma = find_vma(mm, addr-len);
7374 - if (!vma || addr <= vma->vm_start) {
7375 + if (check_heap_stack_gap(vma, addr - len, len)) {
7376 /* remember the address as a hint for next time */
7377 return (mm->free_area_cache = addr-len);
7378 }
7379 @@ -115,16 +115,17 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7380 if (unlikely(mm->mmap_base < len))
7381 goto bottomup;
7382
7383 - addr = (mm->mmap_base-len) & HPAGE_MASK;
7384 + addr = mm->mmap_base - len;
7385
7386 do {
7387 + addr &= HPAGE_MASK;
7388 /*
7389 * Lookup failure means no vma is above this address,
7390 * else if new region fits below vma->vm_start,
7391 * return with success:
7392 */
7393 vma = find_vma(mm, addr);
7394 - if (likely(!vma || addr+len <= vma->vm_start)) {
7395 + if (likely(check_heap_stack_gap(vma, addr, len))) {
7396 /* remember the address as a hint for next time */
7397 return (mm->free_area_cache = addr);
7398 }
7399 @@ -134,8 +135,8 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
7400 mm->cached_hole_size = vma->vm_start - addr;
7401
7402 /* try just below the current vma->vm_start */
7403 - addr = (vma->vm_start-len) & HPAGE_MASK;
7404 - } while (likely(len < vma->vm_start));
7405 + addr = skip_heap_stack_gap(vma, len);
7406 + } while (!IS_ERR_VALUE(addr));
7407
7408 bottomup:
7409 /*
7410 @@ -181,8 +182,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
7411 if (addr) {
7412 addr = ALIGN(addr, HPAGE_SIZE);
7413 vma = find_vma(mm, addr);
7414 - if (task_size - len >= addr &&
7415 - (!vma || addr + len <= vma->vm_start))
7416 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
7417 return addr;
7418 }
7419 if (mm->get_unmapped_area == arch_get_unmapped_area)
7420 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
7421 index f4500c6..889656c 100644
7422 --- a/arch/tile/include/asm/atomic_64.h
7423 +++ b/arch/tile/include/asm/atomic_64.h
7424 @@ -143,6 +143,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
7425
7426 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
7427
7428 +#define atomic64_read_unchecked(v) atomic64_read(v)
7429 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7430 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7431 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7432 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7433 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7434 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7435 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7436 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7437 +
7438 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
7439 #define smp_mb__before_atomic_dec() smp_mb()
7440 #define smp_mb__after_atomic_dec() smp_mb()
7441 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
7442 index 392e533..536b092 100644
7443 --- a/arch/tile/include/asm/cache.h
7444 +++ b/arch/tile/include/asm/cache.h
7445 @@ -15,11 +15,12 @@
7446 #ifndef _ASM_TILE_CACHE_H
7447 #define _ASM_TILE_CACHE_H
7448
7449 +#include <linux/const.h>
7450 #include <arch/chip.h>
7451
7452 /* bytes per L1 data cache line */
7453 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
7454 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7455 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7456
7457 /* bytes per L2 cache line */
7458 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
7459 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
7460 index 9ab078a..d6635c2 100644
7461 --- a/arch/tile/include/asm/uaccess.h
7462 +++ b/arch/tile/include/asm/uaccess.h
7463 @@ -403,9 +403,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
7464 const void __user *from,
7465 unsigned long n)
7466 {
7467 - int sz = __compiletime_object_size(to);
7468 + size_t sz = __compiletime_object_size(to);
7469
7470 - if (likely(sz == -1 || sz >= n))
7471 + if (likely(sz == (size_t)-1 || sz >= n))
7472 n = _copy_from_user(to, from, n);
7473 else
7474 copy_from_user_overflow();
7475 diff --git a/arch/um/Makefile b/arch/um/Makefile
7476 index 0970910..9f65c40 100644
7477 --- a/arch/um/Makefile
7478 +++ b/arch/um/Makefile
7479 @@ -62,6 +62,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
7480 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
7481 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
7482
7483 +ifdef CONSTIFY_PLUGIN
7484 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7485 +endif
7486 +
7487 #This will adjust *FLAGS accordingly to the platform.
7488 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
7489
7490 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
7491 index 19e1bdd..3665b77 100644
7492 --- a/arch/um/include/asm/cache.h
7493 +++ b/arch/um/include/asm/cache.h
7494 @@ -1,6 +1,7 @@
7495 #ifndef __UM_CACHE_H
7496 #define __UM_CACHE_H
7497
7498 +#include <linux/const.h>
7499
7500 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
7501 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
7502 @@ -12,6 +13,6 @@
7503 # define L1_CACHE_SHIFT 5
7504 #endif
7505
7506 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7508
7509 #endif
7510 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
7511 index 6c03acd..a5e0215 100644
7512 --- a/arch/um/include/asm/kmap_types.h
7513 +++ b/arch/um/include/asm/kmap_types.h
7514 @@ -23,6 +23,7 @@ enum km_type {
7515 KM_IRQ1,
7516 KM_SOFTIRQ0,
7517 KM_SOFTIRQ1,
7518 + KM_CLEARPAGE,
7519 KM_TYPE_NR
7520 };
7521
7522 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
7523 index 7cfc3ce..cbd1a58 100644
7524 --- a/arch/um/include/asm/page.h
7525 +++ b/arch/um/include/asm/page.h
7526 @@ -14,6 +14,9 @@
7527 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
7528 #define PAGE_MASK (~(PAGE_SIZE-1))
7529
7530 +#define ktla_ktva(addr) (addr)
7531 +#define ktva_ktla(addr) (addr)
7532 +
7533 #ifndef __ASSEMBLY__
7534
7535 struct page;
7536 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
7537 index 0032f92..cd151e0 100644
7538 --- a/arch/um/include/asm/pgtable-3level.h
7539 +++ b/arch/um/include/asm/pgtable-3level.h
7540 @@ -58,6 +58,7 @@
7541 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
7542 #define pud_populate(mm, pud, pmd) \
7543 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
7544 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7545
7546 #ifdef CONFIG_64BIT
7547 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
7548 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
7549 index ccb9a9d..cc425bb 100644
7550 --- a/arch/um/kernel/process.c
7551 +++ b/arch/um/kernel/process.c
7552 @@ -407,22 +407,6 @@ int singlestepping(void * t)
7553 return 2;
7554 }
7555
7556 -/*
7557 - * Only x86 and x86_64 have an arch_align_stack().
7558 - * All other arches have "#define arch_align_stack(x) (x)"
7559 - * in their asm/system.h
7560 - * As this is included in UML from asm-um/system-generic.h,
7561 - * we can use it to behave as the subarch does.
7562 - */
7563 -#ifndef arch_align_stack
7564 -unsigned long arch_align_stack(unsigned long sp)
7565 -{
7566 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
7567 - sp -= get_random_int() % 8192;
7568 - return sp & ~0xf;
7569 -}
7570 -#endif
7571 -
7572 unsigned long get_wchan(struct task_struct *p)
7573 {
7574 unsigned long stack_page, sp, ip;
7575 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
7576 index ad8f795..2c7eec6 100644
7577 --- a/arch/unicore32/include/asm/cache.h
7578 +++ b/arch/unicore32/include/asm/cache.h
7579 @@ -12,8 +12,10 @@
7580 #ifndef __UNICORE_CACHE_H__
7581 #define __UNICORE_CACHE_H__
7582
7583 -#define L1_CACHE_SHIFT (5)
7584 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7585 +#include <linux/const.h>
7586 +
7587 +#define L1_CACHE_SHIFT 5
7588 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7589
7590 /*
7591 * Memory returned by kmalloc() may be used for DMA, so we must make
7592 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
7593 index c70684f..698fa4b 100644
7594 --- a/arch/x86/Kconfig
7595 +++ b/arch/x86/Kconfig
7596 @@ -218,7 +218,7 @@ config X86_HT
7597
7598 config X86_32_LAZY_GS
7599 def_bool y
7600 - depends on X86_32 && !CC_STACKPROTECTOR
7601 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
7602
7603 config ARCH_HWEIGHT_CFLAGS
7604 string
7605 @@ -1047,7 +1047,7 @@ choice
7606
7607 config NOHIGHMEM
7608 bool "off"
7609 - depends on !X86_NUMAQ
7610 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7611 ---help---
7612 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
7613 However, the address space of 32-bit x86 processors is only 4
7614 @@ -1084,7 +1084,7 @@ config NOHIGHMEM
7615
7616 config HIGHMEM4G
7617 bool "4GB"
7618 - depends on !X86_NUMAQ
7619 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
7620 ---help---
7621 Select this if you have a 32-bit processor and between 1 and 4
7622 gigabytes of physical RAM.
7623 @@ -1138,7 +1138,7 @@ config PAGE_OFFSET
7624 hex
7625 default 0xB0000000 if VMSPLIT_3G_OPT
7626 default 0x80000000 if VMSPLIT_2G
7627 - default 0x78000000 if VMSPLIT_2G_OPT
7628 + default 0x70000000 if VMSPLIT_2G_OPT
7629 default 0x40000000 if VMSPLIT_1G
7630 default 0xC0000000
7631 depends on X86_32
7632 @@ -1526,6 +1526,7 @@ config SECCOMP
7633
7634 config CC_STACKPROTECTOR
7635 bool "Enable -fstack-protector buffer overflow detection (EXPERIMENTAL)"
7636 + depends on X86_64 || !PAX_MEMORY_UDEREF
7637 ---help---
7638 This option turns on the -fstack-protector GCC feature. This
7639 feature puts, at the beginning of functions, a canary value on
7640 @@ -1583,6 +1584,7 @@ config KEXEC_JUMP
7641 config PHYSICAL_START
7642 hex "Physical address where the kernel is loaded" if (EXPERT || CRASH_DUMP)
7643 default "0x1000000"
7644 + range 0x400000 0x40000000
7645 ---help---
7646 This gives the physical address where the kernel is loaded.
7647
7648 @@ -1646,6 +1648,7 @@ config X86_NEED_RELOCS
7649 config PHYSICAL_ALIGN
7650 hex "Alignment value to which kernel should be aligned" if X86_32
7651 default "0x1000000"
7652 + range 0x400000 0x1000000 if PAX_KERNEXEC
7653 range 0x2000 0x1000000
7654 ---help---
7655 This value puts the alignment restrictions on physical address
7656 @@ -1677,9 +1680,10 @@ config HOTPLUG_CPU
7657 Say N if you want to disable CPU hotplug.
7658
7659 config COMPAT_VDSO
7660 - def_bool y
7661 + def_bool n
7662 prompt "Compat VDSO support"
7663 depends on X86_32 || IA32_EMULATION
7664 + depends on !PAX_NOEXEC && !PAX_MEMORY_UDEREF
7665 ---help---
7666 Map the 32-bit VDSO to the predictable old-style address too.
7667
7668 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
7669 index 706e12e..62e4feb 100644
7670 --- a/arch/x86/Kconfig.cpu
7671 +++ b/arch/x86/Kconfig.cpu
7672 @@ -334,7 +334,7 @@ config X86_PPRO_FENCE
7673
7674 config X86_F00F_BUG
7675 def_bool y
7676 - depends on M586MMX || M586TSC || M586 || M486 || M386
7677 + depends on (M586MMX || M586TSC || M586 || M486 || M386) && !PAX_KERNEXEC
7678
7679 config X86_INVD_BUG
7680 def_bool y
7681 @@ -358,7 +358,7 @@ config X86_POPAD_OK
7682
7683 config X86_ALIGNMENT_16
7684 def_bool y
7685 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7686 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
7687
7688 config X86_INTEL_USERCOPY
7689 def_bool y
7690 @@ -404,7 +404,7 @@ config X86_CMPXCHG64
7691 # generates cmov.
7692 config X86_CMOV
7693 def_bool y
7694 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7695 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
7696
7697 config X86_MINIMUM_CPU_FAMILY
7698 int
7699 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
7700 index e46c214..ab62fd1 100644
7701 --- a/arch/x86/Kconfig.debug
7702 +++ b/arch/x86/Kconfig.debug
7703 @@ -84,7 +84,7 @@ config X86_PTDUMP
7704 config DEBUG_RODATA
7705 bool "Write protect kernel read-only data structures"
7706 default y
7707 - depends on DEBUG_KERNEL
7708 + depends on DEBUG_KERNEL && BROKEN
7709 ---help---
7710 Mark the kernel read-only data as write-protected in the pagetables,
7711 in order to catch accidental (and incorrect) writes to such const
7712 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
7713
7714 config DEBUG_SET_MODULE_RONX
7715 bool "Set loadable kernel module data as NX and text as RO"
7716 - depends on MODULES
7717 + depends on MODULES && BROKEN
7718 ---help---
7719 This option helps catch unintended modifications to loadable
7720 kernel module's text and read-only data. It also prevents execution
7721 @@ -275,7 +275,7 @@ config OPTIMIZE_INLINING
7722
7723 config DEBUG_STRICT_USER_COPY_CHECKS
7724 bool "Strict copy size checks"
7725 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
7726 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
7727 ---help---
7728 Enabling this option turns a certain set of sanity checks for user
7729 copy operations into compile time failures.
7730 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
7731 index 1f25214..39422b3 100644
7732 --- a/arch/x86/Makefile
7733 +++ b/arch/x86/Makefile
7734 @@ -46,6 +46,7 @@ else
7735 UTS_MACHINE := x86_64
7736 CHECKFLAGS += -D__x86_64__ -m64
7737
7738 + biarch := $(call cc-option,-m64)
7739 KBUILD_AFLAGS += -m64
7740 KBUILD_CFLAGS += -m64
7741
7742 @@ -222,3 +223,12 @@ define archhelp
7743 echo ' FDARGS="..." arguments for the booted kernel'
7744 echo ' FDINITRD=file initrd for the booted kernel'
7745 endef
7746 +
7747 +define OLD_LD
7748 +
7749 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
7750 +*** Please upgrade your binutils to 2.18 or newer
7751 +endef
7752 +
7753 +archprepare:
7754 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
7755 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
7756 index 5a747dd..00bece7 100644
7757 --- a/arch/x86/boot/Makefile
7758 +++ b/arch/x86/boot/Makefile
7759 @@ -64,6 +64,9 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -g -Os -D_SETUP -D__KERNEL__ \
7760 $(call cc-option, -fno-stack-protector) \
7761 $(call cc-option, -mpreferred-stack-boundary=2)
7762 KBUILD_CFLAGS += $(call cc-option, -m32)
7763 +ifdef CONSTIFY_PLUGIN
7764 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7765 +endif
7766 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7767 GCOV_PROFILE := n
7768
7769 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
7770 index 878e4b9..20537ab 100644
7771 --- a/arch/x86/boot/bitops.h
7772 +++ b/arch/x86/boot/bitops.h
7773 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7774 u8 v;
7775 const u32 *p = (const u32 *)addr;
7776
7777 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7778 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
7779 return v;
7780 }
7781
7782 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
7783
7784 static inline void set_bit(int nr, void *addr)
7785 {
7786 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7787 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
7788 }
7789
7790 #endif /* BOOT_BITOPS_H */
7791 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
7792 index 18997e5..83d9c67 100644
7793 --- a/arch/x86/boot/boot.h
7794 +++ b/arch/x86/boot/boot.h
7795 @@ -85,7 +85,7 @@ static inline void io_delay(void)
7796 static inline u16 ds(void)
7797 {
7798 u16 seg;
7799 - asm("movw %%ds,%0" : "=rm" (seg));
7800 + asm volatile("movw %%ds,%0" : "=rm" (seg));
7801 return seg;
7802 }
7803
7804 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
7805 static inline int memcmp(const void *s1, const void *s2, size_t len)
7806 {
7807 u8 diff;
7808 - asm("repe; cmpsb; setnz %0"
7809 + asm volatile("repe; cmpsb; setnz %0"
7810 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
7811 return diff;
7812 }
7813 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
7814 index e398bb5..80fc805 100644
7815 --- a/arch/x86/boot/compressed/Makefile
7816 +++ b/arch/x86/boot/compressed/Makefile
7817 @@ -14,6 +14,9 @@ cflags-$(CONFIG_X86_64) := -mcmodel=small
7818 KBUILD_CFLAGS += $(cflags-y)
7819 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
7820 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
7821 +ifdef CONSTIFY_PLUGIN
7822 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
7823 +endif
7824
7825 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
7826 GCOV_PROFILE := n
7827 diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c
7828 index 4e85f5f..39fa641 100644
7829 --- a/arch/x86/boot/compressed/eboot.c
7830 +++ b/arch/x86/boot/compressed/eboot.c
7831 @@ -142,7 +142,6 @@ again:
7832 *addr = max_addr;
7833 }
7834
7835 -free_pool:
7836 efi_call_phys1(sys_table->boottime->free_pool, map);
7837
7838 fail:
7839 @@ -206,7 +205,6 @@ static efi_status_t low_alloc(unsigned long size, unsigned long align,
7840 if (i == map_size / desc_size)
7841 status = EFI_NOT_FOUND;
7842
7843 -free_pool:
7844 efi_call_phys1(sys_table->boottime->free_pool, map);
7845 fail:
7846 return status;
7847 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
7848 index c85e3ac..6f5aa80 100644
7849 --- a/arch/x86/boot/compressed/head_32.S
7850 +++ b/arch/x86/boot/compressed/head_32.S
7851 @@ -106,7 +106,7 @@ preferred_addr:
7852 notl %eax
7853 andl %eax, %ebx
7854 #else
7855 - movl $LOAD_PHYSICAL_ADDR, %ebx
7856 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7857 #endif
7858
7859 /* Target address to relocate to for decompression */
7860 @@ -192,7 +192,7 @@ relocated:
7861 * and where it was actually loaded.
7862 */
7863 movl %ebp, %ebx
7864 - subl $LOAD_PHYSICAL_ADDR, %ebx
7865 + subl $____LOAD_PHYSICAL_ADDR, %ebx
7866 jz 2f /* Nothing to be done if loaded at compiled addr. */
7867 /*
7868 * Process relocations.
7869 @@ -200,8 +200,7 @@ relocated:
7870
7871 1: subl $4, %edi
7872 movl (%edi), %ecx
7873 - testl %ecx, %ecx
7874 - jz 2f
7875 + jecxz 2f
7876 addl %ebx, -__PAGE_OFFSET(%ebx, %ecx)
7877 jmp 1b
7878 2:
7879 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
7880 index 87e03a1..0d94c76 100644
7881 --- a/arch/x86/boot/compressed/head_64.S
7882 +++ b/arch/x86/boot/compressed/head_64.S
7883 @@ -91,7 +91,7 @@ ENTRY(startup_32)
7884 notl %eax
7885 andl %eax, %ebx
7886 #else
7887 - movl $LOAD_PHYSICAL_ADDR, %ebx
7888 + movl $____LOAD_PHYSICAL_ADDR, %ebx
7889 #endif
7890
7891 /* Target address to relocate to for decompression */
7892 @@ -263,7 +263,7 @@ preferred_addr:
7893 notq %rax
7894 andq %rax, %rbp
7895 #else
7896 - movq $LOAD_PHYSICAL_ADDR, %rbp
7897 + movq $____LOAD_PHYSICAL_ADDR, %rbp
7898 #endif
7899
7900 /* Target address to relocate to for decompression */
7901 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
7902 index 7116dcb..d9ae1d7 100644
7903 --- a/arch/x86/boot/compressed/misc.c
7904 +++ b/arch/x86/boot/compressed/misc.c
7905 @@ -310,7 +310,7 @@ static void parse_elf(void *output)
7906 case PT_LOAD:
7907 #ifdef CONFIG_RELOCATABLE
7908 dest = output;
7909 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
7910 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
7911 #else
7912 dest = (void *)(phdr->p_paddr);
7913 #endif
7914 @@ -365,7 +365,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
7915 error("Destination address too large");
7916 #endif
7917 #ifndef CONFIG_RELOCATABLE
7918 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
7919 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
7920 error("Wrong destination address");
7921 #endif
7922
7923 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
7924 index 4d3ff03..e4972ff 100644
7925 --- a/arch/x86/boot/cpucheck.c
7926 +++ b/arch/x86/boot/cpucheck.c
7927 @@ -74,7 +74,7 @@ static int has_fpu(void)
7928 u16 fcw = -1, fsw = -1;
7929 u32 cr0;
7930
7931 - asm("movl %%cr0,%0" : "=r" (cr0));
7932 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
7933 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
7934 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
7935 asm volatile("movl %0,%%cr0" : : "r" (cr0));
7936 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
7937 {
7938 u32 f0, f1;
7939
7940 - asm("pushfl ; "
7941 + asm volatile("pushfl ; "
7942 "pushfl ; "
7943 "popl %0 ; "
7944 "movl %0,%1 ; "
7945 @@ -115,7 +115,7 @@ static void get_flags(void)
7946 set_bit(X86_FEATURE_FPU, cpu.flags);
7947
7948 if (has_eflag(X86_EFLAGS_ID)) {
7949 - asm("cpuid"
7950 + asm volatile("cpuid"
7951 : "=a" (max_intel_level),
7952 "=b" (cpu_vendor[0]),
7953 "=d" (cpu_vendor[1]),
7954 @@ -124,7 +124,7 @@ static void get_flags(void)
7955
7956 if (max_intel_level >= 0x00000001 &&
7957 max_intel_level <= 0x0000ffff) {
7958 - asm("cpuid"
7959 + asm volatile("cpuid"
7960 : "=a" (tfms),
7961 "=c" (cpu.flags[4]),
7962 "=d" (cpu.flags[0])
7963 @@ -136,7 +136,7 @@ static void get_flags(void)
7964 cpu.model += ((tfms >> 16) & 0xf) << 4;
7965 }
7966
7967 - asm("cpuid"
7968 + asm volatile("cpuid"
7969 : "=a" (max_amd_level)
7970 : "a" (0x80000000)
7971 : "ebx", "ecx", "edx");
7972 @@ -144,7 +144,7 @@ static void get_flags(void)
7973 if (max_amd_level >= 0x80000001 &&
7974 max_amd_level <= 0x8000ffff) {
7975 u32 eax = 0x80000001;
7976 - asm("cpuid"
7977 + asm volatile("cpuid"
7978 : "+a" (eax),
7979 "=c" (cpu.flags[6]),
7980 "=d" (cpu.flags[1])
7981 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7982 u32 ecx = MSR_K7_HWCR;
7983 u32 eax, edx;
7984
7985 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7986 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7987 eax &= ~(1 << 15);
7988 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7989 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
7990
7991 get_flags(); /* Make sure it really did something */
7992 err = check_flags();
7993 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
7994 u32 ecx = MSR_VIA_FCR;
7995 u32 eax, edx;
7996
7997 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7998 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
7999 eax |= (1<<1)|(1<<7);
8000 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8001 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8002
8003 set_bit(X86_FEATURE_CX8, cpu.flags);
8004 err = check_flags();
8005 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
8006 u32 eax, edx;
8007 u32 level = 1;
8008
8009 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8010 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8011 - asm("cpuid"
8012 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
8013 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
8014 + asm volatile("cpuid"
8015 : "+a" (level), "=d" (cpu.flags[0])
8016 : : "ecx", "ebx");
8017 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8018 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
8019
8020 err = check_flags();
8021 }
8022 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
8023 index efe5acf..22a3784 100644
8024 --- a/arch/x86/boot/header.S
8025 +++ b/arch/x86/boot/header.S
8026 @@ -391,10 +391,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
8027 # single linked list of
8028 # struct setup_data
8029
8030 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
8031 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
8032
8033 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
8034 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
8035 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
8036 +#else
8037 #define VO_INIT_SIZE (VO__end - VO__text)
8038 +#endif
8039 #if ZO_INIT_SIZE > VO_INIT_SIZE
8040 #define INIT_SIZE ZO_INIT_SIZE
8041 #else
8042 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
8043 index db75d07..8e6d0af 100644
8044 --- a/arch/x86/boot/memory.c
8045 +++ b/arch/x86/boot/memory.c
8046 @@ -19,7 +19,7 @@
8047
8048 static int detect_memory_e820(void)
8049 {
8050 - int count = 0;
8051 + unsigned int count = 0;
8052 struct biosregs ireg, oreg;
8053 struct e820entry *desc = boot_params.e820_map;
8054 static struct e820entry buf; /* static so it is zeroed */
8055 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
8056 index 11e8c6e..fdbb1ed 100644
8057 --- a/arch/x86/boot/video-vesa.c
8058 +++ b/arch/x86/boot/video-vesa.c
8059 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
8060
8061 boot_params.screen_info.vesapm_seg = oreg.es;
8062 boot_params.screen_info.vesapm_off = oreg.di;
8063 + boot_params.screen_info.vesapm_size = oreg.cx;
8064 }
8065
8066 /*
8067 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
8068 index 43eda28..5ab5fdb 100644
8069 --- a/arch/x86/boot/video.c
8070 +++ b/arch/x86/boot/video.c
8071 @@ -96,7 +96,7 @@ static void store_mode_params(void)
8072 static unsigned int get_entry(void)
8073 {
8074 char entry_buf[4];
8075 - int i, len = 0;
8076 + unsigned int i, len = 0;
8077 int key;
8078 unsigned int v;
8079
8080 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
8081 index 5b577d5..3c1fed4 100644
8082 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
8083 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
8084 @@ -8,6 +8,8 @@
8085 * including this sentence is retained in full.
8086 */
8087
8088 +#include <asm/alternative-asm.h>
8089 +
8090 .extern crypto_ft_tab
8091 .extern crypto_it_tab
8092 .extern crypto_fl_tab
8093 @@ -71,6 +73,8 @@ FUNC: movq r1,r2; \
8094 je B192; \
8095 leaq 32(r9),r9;
8096
8097 +#define ret pax_force_retaddr 0, 1; ret
8098 +
8099 #define epilogue(r1,r2,r3,r4,r5,r6,r7,r8,r9) \
8100 movq r1,r2; \
8101 movq r3,r4; \
8102 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
8103 index 3470624..201259d 100644
8104 --- a/arch/x86/crypto/aesni-intel_asm.S
8105 +++ b/arch/x86/crypto/aesni-intel_asm.S
8106 @@ -31,6 +31,7 @@
8107
8108 #include <linux/linkage.h>
8109 #include <asm/inst.h>
8110 +#include <asm/alternative-asm.h>
8111
8112 #ifdef __x86_64__
8113 .data
8114 @@ -1436,7 +1437,9 @@ _return_T_done_decrypt:
8115 pop %r14
8116 pop %r13
8117 pop %r12
8118 + pax_force_retaddr 0, 1
8119 ret
8120 +ENDPROC(aesni_gcm_dec)
8121
8122
8123 /*****************************************************************************
8124 @@ -1699,7 +1702,9 @@ _return_T_done_encrypt:
8125 pop %r14
8126 pop %r13
8127 pop %r12
8128 + pax_force_retaddr 0, 1
8129 ret
8130 +ENDPROC(aesni_gcm_enc)
8131
8132 #endif
8133
8134 @@ -1714,6 +1719,7 @@ _key_expansion_256a:
8135 pxor %xmm1, %xmm0
8136 movaps %xmm0, (TKEYP)
8137 add $0x10, TKEYP
8138 + pax_force_retaddr_bts
8139 ret
8140
8141 .align 4
8142 @@ -1738,6 +1744,7 @@ _key_expansion_192a:
8143 shufps $0b01001110, %xmm2, %xmm1
8144 movaps %xmm1, 0x10(TKEYP)
8145 add $0x20, TKEYP
8146 + pax_force_retaddr_bts
8147 ret
8148
8149 .align 4
8150 @@ -1757,6 +1764,7 @@ _key_expansion_192b:
8151
8152 movaps %xmm0, (TKEYP)
8153 add $0x10, TKEYP
8154 + pax_force_retaddr_bts
8155 ret
8156
8157 .align 4
8158 @@ -1769,6 +1777,7 @@ _key_expansion_256b:
8159 pxor %xmm1, %xmm2
8160 movaps %xmm2, (TKEYP)
8161 add $0x10, TKEYP
8162 + pax_force_retaddr_bts
8163 ret
8164
8165 /*
8166 @@ -1881,7 +1890,9 @@ ENTRY(aesni_set_key)
8167 #ifndef __x86_64__
8168 popl KEYP
8169 #endif
8170 + pax_force_retaddr 0, 1
8171 ret
8172 +ENDPROC(aesni_set_key)
8173
8174 /*
8175 * void aesni_enc(struct crypto_aes_ctx *ctx, u8 *dst, const u8 *src)
8176 @@ -1902,7 +1913,9 @@ ENTRY(aesni_enc)
8177 popl KLEN
8178 popl KEYP
8179 #endif
8180 + pax_force_retaddr 0, 1
8181 ret
8182 +ENDPROC(aesni_enc)
8183
8184 /*
8185 * _aesni_enc1: internal ABI
8186 @@ -1959,6 +1972,7 @@ _aesni_enc1:
8187 AESENC KEY STATE
8188 movaps 0x70(TKEYP), KEY
8189 AESENCLAST KEY STATE
8190 + pax_force_retaddr_bts
8191 ret
8192
8193 /*
8194 @@ -2067,6 +2081,7 @@ _aesni_enc4:
8195 AESENCLAST KEY STATE2
8196 AESENCLAST KEY STATE3
8197 AESENCLAST KEY STATE4
8198 + pax_force_retaddr_bts
8199 ret
8200
8201 /*
8202 @@ -2089,7 +2104,9 @@ ENTRY(aesni_dec)
8203 popl KLEN
8204 popl KEYP
8205 #endif
8206 + pax_force_retaddr 0, 1
8207 ret
8208 +ENDPROC(aesni_dec)
8209
8210 /*
8211 * _aesni_dec1: internal ABI
8212 @@ -2146,6 +2163,7 @@ _aesni_dec1:
8213 AESDEC KEY STATE
8214 movaps 0x70(TKEYP), KEY
8215 AESDECLAST KEY STATE
8216 + pax_force_retaddr_bts
8217 ret
8218
8219 /*
8220 @@ -2254,6 +2272,7 @@ _aesni_dec4:
8221 AESDECLAST KEY STATE2
8222 AESDECLAST KEY STATE3
8223 AESDECLAST KEY STATE4
8224 + pax_force_retaddr_bts
8225 ret
8226
8227 /*
8228 @@ -2311,7 +2330,9 @@ ENTRY(aesni_ecb_enc)
8229 popl KEYP
8230 popl LEN
8231 #endif
8232 + pax_force_retaddr 0, 1
8233 ret
8234 +ENDPROC(aesni_ecb_enc)
8235
8236 /*
8237 * void aesni_ecb_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8238 @@ -2369,7 +2390,9 @@ ENTRY(aesni_ecb_dec)
8239 popl KEYP
8240 popl LEN
8241 #endif
8242 + pax_force_retaddr 0, 1
8243 ret
8244 +ENDPROC(aesni_ecb_dec)
8245
8246 /*
8247 * void aesni_cbc_enc(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8248 @@ -2410,7 +2433,9 @@ ENTRY(aesni_cbc_enc)
8249 popl LEN
8250 popl IVP
8251 #endif
8252 + pax_force_retaddr 0, 1
8253 ret
8254 +ENDPROC(aesni_cbc_enc)
8255
8256 /*
8257 * void aesni_cbc_dec(struct crypto_aes_ctx *ctx, const u8 *dst, u8 *src,
8258 @@ -2500,7 +2525,9 @@ ENTRY(aesni_cbc_dec)
8259 popl LEN
8260 popl IVP
8261 #endif
8262 + pax_force_retaddr 0, 1
8263 ret
8264 +ENDPROC(aesni_cbc_dec)
8265
8266 #ifdef __x86_64__
8267 .align 16
8268 @@ -2526,6 +2553,7 @@ _aesni_inc_init:
8269 mov $1, TCTR_LOW
8270 MOVQ_R64_XMM TCTR_LOW INC
8271 MOVQ_R64_XMM CTR TCTR_LOW
8272 + pax_force_retaddr_bts
8273 ret
8274
8275 /*
8276 @@ -2554,6 +2582,7 @@ _aesni_inc:
8277 .Linc_low:
8278 movaps CTR, IV
8279 PSHUFB_XMM BSWAP_MASK IV
8280 + pax_force_retaddr_bts
8281 ret
8282
8283 /*
8284 @@ -2614,5 +2643,7 @@ ENTRY(aesni_ctr_enc)
8285 .Lctr_enc_ret:
8286 movups IV, (IVP)
8287 .Lctr_enc_just_ret:
8288 + pax_force_retaddr 0, 1
8289 ret
8290 +ENDPROC(aesni_ctr_enc)
8291 #endif
8292 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8293 index 391d245..67f35c2 100644
8294 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
8295 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
8296 @@ -20,6 +20,8 @@
8297 *
8298 */
8299
8300 +#include <asm/alternative-asm.h>
8301 +
8302 .file "blowfish-x86_64-asm.S"
8303 .text
8304
8305 @@ -151,9 +153,11 @@ __blowfish_enc_blk:
8306 jnz __enc_xor;
8307
8308 write_block();
8309 + pax_force_retaddr 0, 1
8310 ret;
8311 __enc_xor:
8312 xor_block();
8313 + pax_force_retaddr 0, 1
8314 ret;
8315
8316 .align 8
8317 @@ -188,6 +192,7 @@ blowfish_dec_blk:
8318
8319 movq %r11, %rbp;
8320
8321 + pax_force_retaddr 0, 1
8322 ret;
8323
8324 /**********************************************************************
8325 @@ -342,6 +347,7 @@ __blowfish_enc_blk_4way:
8326
8327 popq %rbx;
8328 popq %rbp;
8329 + pax_force_retaddr 0, 1
8330 ret;
8331
8332 __enc_xor4:
8333 @@ -349,6 +355,7 @@ __enc_xor4:
8334
8335 popq %rbx;
8336 popq %rbp;
8337 + pax_force_retaddr 0, 1
8338 ret;
8339
8340 .align 8
8341 @@ -386,5 +393,6 @@ blowfish_dec_blk_4way:
8342 popq %rbx;
8343 popq %rbp;
8344
8345 + pax_force_retaddr 0, 1
8346 ret;
8347
8348 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
8349 index 0b33743..7a56206 100644
8350 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
8351 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
8352 @@ -20,6 +20,8 @@
8353 *
8354 */
8355
8356 +#include <asm/alternative-asm.h>
8357 +
8358 .file "camellia-x86_64-asm_64.S"
8359 .text
8360
8361 @@ -229,12 +231,14 @@ __enc_done:
8362 enc_outunpack(mov, RT1);
8363
8364 movq RRBP, %rbp;
8365 + pax_force_retaddr 0, 1
8366 ret;
8367
8368 __enc_xor:
8369 enc_outunpack(xor, RT1);
8370
8371 movq RRBP, %rbp;
8372 + pax_force_retaddr 0, 1
8373 ret;
8374
8375 .global camellia_dec_blk;
8376 @@ -275,6 +279,7 @@ __dec_rounds16:
8377 dec_outunpack();
8378
8379 movq RRBP, %rbp;
8380 + pax_force_retaddr 0, 1
8381 ret;
8382
8383 /**********************************************************************
8384 @@ -468,6 +473,7 @@ __enc2_done:
8385
8386 movq RRBP, %rbp;
8387 popq %rbx;
8388 + pax_force_retaddr 0, 1
8389 ret;
8390
8391 __enc2_xor:
8392 @@ -475,6 +481,7 @@ __enc2_xor:
8393
8394 movq RRBP, %rbp;
8395 popq %rbx;
8396 + pax_force_retaddr 0, 1
8397 ret;
8398
8399 .global camellia_dec_blk_2way;
8400 @@ -517,4 +524,5 @@ __dec2_rounds16:
8401
8402 movq RRBP, %rbp;
8403 movq RXOR, %rbx;
8404 + pax_force_retaddr 0, 1
8405 ret;
8406 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8407 index 6214a9b..1f4fc9a 100644
8408 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
8409 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
8410 @@ -1,3 +1,5 @@
8411 +#include <asm/alternative-asm.h>
8412 +
8413 # enter ECRYPT_encrypt_bytes
8414 .text
8415 .p2align 5
8416 @@ -790,6 +792,7 @@ ECRYPT_encrypt_bytes:
8417 add %r11,%rsp
8418 mov %rdi,%rax
8419 mov %rsi,%rdx
8420 + pax_force_retaddr 0, 1
8421 ret
8422 # bytesatleast65:
8423 ._bytesatleast65:
8424 @@ -891,6 +894,7 @@ ECRYPT_keysetup:
8425 add %r11,%rsp
8426 mov %rdi,%rax
8427 mov %rsi,%rdx
8428 + pax_force_retaddr
8429 ret
8430 # enter ECRYPT_ivsetup
8431 .text
8432 @@ -917,4 +921,5 @@ ECRYPT_ivsetup:
8433 add %r11,%rsp
8434 mov %rdi,%rax
8435 mov %rsi,%rdx
8436 + pax_force_retaddr
8437 ret
8438 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8439 index 3ee1ff0..cbc568b 100644
8440 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8441 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
8442 @@ -24,6 +24,8 @@
8443 *
8444 */
8445
8446 +#include <asm/alternative-asm.h>
8447 +
8448 .file "serpent-sse2-x86_64-asm_64.S"
8449 .text
8450
8451 @@ -692,12 +694,14 @@ __serpent_enc_blk_8way:
8452 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8453 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8454
8455 + pax_force_retaddr
8456 ret;
8457
8458 __enc_xor8:
8459 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
8460 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
8461
8462 + pax_force_retaddr
8463 ret;
8464
8465 .align 8
8466 @@ -755,4 +759,5 @@ serpent_dec_blk_8way:
8467 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
8468 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
8469
8470 + pax_force_retaddr
8471 ret;
8472 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
8473 index b2c2f57..8470cab 100644
8474 --- a/arch/x86/crypto/sha1_ssse3_asm.S
8475 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
8476 @@ -28,6 +28,8 @@
8477 * (at your option) any later version.
8478 */
8479
8480 +#include <asm/alternative-asm.h>
8481 +
8482 #define CTX %rdi // arg1
8483 #define BUF %rsi // arg2
8484 #define CNT %rdx // arg3
8485 @@ -104,6 +106,7 @@
8486 pop %r12
8487 pop %rbp
8488 pop %rbx
8489 + pax_force_retaddr 0, 1
8490 ret
8491
8492 .size \name, .-\name
8493 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8494 index 5b012a2..36d5364 100644
8495 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8496 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
8497 @@ -20,6 +20,8 @@
8498 *
8499 */
8500
8501 +#include <asm/alternative-asm.h>
8502 +
8503 .file "twofish-x86_64-asm-3way.S"
8504 .text
8505
8506 @@ -260,6 +262,7 @@ __twofish_enc_blk_3way:
8507 popq %r13;
8508 popq %r14;
8509 popq %r15;
8510 + pax_force_retaddr 0, 1
8511 ret;
8512
8513 __enc_xor3:
8514 @@ -271,6 +274,7 @@ __enc_xor3:
8515 popq %r13;
8516 popq %r14;
8517 popq %r15;
8518 + pax_force_retaddr 0, 1
8519 ret;
8520
8521 .global twofish_dec_blk_3way
8522 @@ -312,5 +316,6 @@ twofish_dec_blk_3way:
8523 popq %r13;
8524 popq %r14;
8525 popq %r15;
8526 + pax_force_retaddr 0, 1
8527 ret;
8528
8529 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
8530 index 7bcf3fc..f53832f 100644
8531 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
8532 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
8533 @@ -21,6 +21,7 @@
8534 .text
8535
8536 #include <asm/asm-offsets.h>
8537 +#include <asm/alternative-asm.h>
8538
8539 #define a_offset 0
8540 #define b_offset 4
8541 @@ -268,6 +269,7 @@ twofish_enc_blk:
8542
8543 popq R1
8544 movq $1,%rax
8545 + pax_force_retaddr 0, 1
8546 ret
8547
8548 twofish_dec_blk:
8549 @@ -319,4 +321,5 @@ twofish_dec_blk:
8550
8551 popq R1
8552 movq $1,%rax
8553 + pax_force_retaddr 0, 1
8554 ret
8555 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
8556 index 07b3a68..bd2a388 100644
8557 --- a/arch/x86/ia32/ia32_aout.c
8558 +++ b/arch/x86/ia32/ia32_aout.c
8559 @@ -159,6 +159,8 @@ static int aout_core_dump(long signr, struct pt_regs *regs, struct file *file,
8560 unsigned long dump_start, dump_size;
8561 struct user32 dump;
8562
8563 + memset(&dump, 0, sizeof(dump));
8564 +
8565 fs = get_fs();
8566 set_fs(KERNEL_DS);
8567 has_dumped = 1;
8568 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
8569 index 673ac9b..7a8c5df 100644
8570 --- a/arch/x86/ia32/ia32_signal.c
8571 +++ b/arch/x86/ia32/ia32_signal.c
8572 @@ -162,7 +162,7 @@ asmlinkage long sys32_sigaltstack(const stack_ia32_t __user *uss_ptr,
8573 }
8574 seg = get_fs();
8575 set_fs(KERNEL_DS);
8576 - ret = do_sigaltstack(uss_ptr ? &uss : NULL, &uoss, regs->sp);
8577 + ret = do_sigaltstack(uss_ptr ? (const stack_t __force_user *)&uss : NULL, (stack_t __force_user *)&uoss, regs->sp);
8578 set_fs(seg);
8579 if (ret >= 0 && uoss_ptr) {
8580 if (!access_ok(VERIFY_WRITE, uoss_ptr, sizeof(stack_ia32_t)))
8581 @@ -361,7 +361,7 @@ static int ia32_setup_sigcontext(struct sigcontext_ia32 __user *sc,
8582 */
8583 static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8584 size_t frame_size,
8585 - void **fpstate)
8586 + void __user **fpstate)
8587 {
8588 unsigned long sp;
8589
8590 @@ -382,7 +382,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8591
8592 if (used_math()) {
8593 sp = sp - sig_xstate_ia32_size;
8594 - *fpstate = (struct _fpstate_ia32 *) sp;
8595 + *fpstate = (struct _fpstate_ia32 __user *) sp;
8596 if (save_i387_xstate_ia32(*fpstate) < 0)
8597 return (void __user *) -1L;
8598 }
8599 @@ -390,7 +390,7 @@ static void __user *get_sigframe(struct k_sigaction *ka, struct pt_regs *regs,
8600 sp -= frame_size;
8601 /* Align the stack pointer according to the i386 ABI,
8602 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
8603 - sp = ((sp + 4) & -16ul) - 4;
8604 + sp = ((sp - 12) & -16ul) - 4;
8605 return (void __user *) sp;
8606 }
8607
8608 @@ -448,7 +448,7 @@ int ia32_setup_frame(int sig, struct k_sigaction *ka,
8609 * These are actually not used anymore, but left because some
8610 * gdb versions depend on them as a marker.
8611 */
8612 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8613 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8614 } put_user_catch(err);
8615
8616 if (err)
8617 @@ -490,7 +490,7 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8618 0xb8,
8619 __NR_ia32_rt_sigreturn,
8620 0x80cd,
8621 - 0,
8622 + 0
8623 };
8624
8625 frame = get_sigframe(ka, regs, sizeof(*frame), &fpstate);
8626 @@ -520,16 +520,18 @@ int ia32_setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
8627
8628 if (ka->sa.sa_flags & SA_RESTORER)
8629 restorer = ka->sa.sa_restorer;
8630 + else if (current->mm->context.vdso)
8631 + /* Return stub is in 32bit vsyscall page */
8632 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
8633 else
8634 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
8635 - rt_sigreturn);
8636 + restorer = &frame->retcode;
8637 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
8638
8639 /*
8640 * Not actually used anymore, but left because some gdb
8641 * versions need it.
8642 */
8643 - put_user_ex(*((u64 *)&code), (u64 *)frame->retcode);
8644 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
8645 } put_user_catch(err);
8646
8647 if (err)
8648 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
8649 index 20e5f7b..f33c779 100644
8650 --- a/arch/x86/ia32/ia32entry.S
8651 +++ b/arch/x86/ia32/ia32entry.S
8652 @@ -14,8 +14,10 @@
8653 #include <asm/segment.h>
8654 #include <asm/irqflags.h>
8655 #include <asm/asm.h>
8656 +#include <asm/pgtable.h>
8657 #include <linux/linkage.h>
8658 #include <linux/err.h>
8659 +#include <asm/alternative-asm.h>
8660
8661 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
8662 #include <linux/elf-em.h>
8663 @@ -95,6 +97,32 @@ ENTRY(native_irq_enable_sysexit)
8664 ENDPROC(native_irq_enable_sysexit)
8665 #endif
8666
8667 + .macro pax_enter_kernel_user
8668 + pax_set_fptr_mask
8669 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8670 + call pax_enter_kernel_user
8671 +#endif
8672 + .endm
8673 +
8674 + .macro pax_exit_kernel_user
8675 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8676 + call pax_exit_kernel_user
8677 +#endif
8678 +#ifdef CONFIG_PAX_RANDKSTACK
8679 + pushq %rax
8680 + pushq %r11
8681 + call pax_randomize_kstack
8682 + popq %r11
8683 + popq %rax
8684 +#endif
8685 + .endm
8686 +
8687 +.macro pax_erase_kstack
8688 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
8689 + call pax_erase_kstack
8690 +#endif
8691 +.endm
8692 +
8693 /*
8694 * 32bit SYSENTER instruction entry.
8695 *
8696 @@ -121,12 +149,6 @@ ENTRY(ia32_sysenter_target)
8697 CFI_REGISTER rsp,rbp
8698 SWAPGS_UNSAFE_STACK
8699 movq PER_CPU_VAR(kernel_stack), %rsp
8700 - addq $(KERNEL_STACK_OFFSET),%rsp
8701 - /*
8702 - * No need to follow this irqs on/off section: the syscall
8703 - * disabled irqs, here we enable it straight after entry:
8704 - */
8705 - ENABLE_INTERRUPTS(CLBR_NONE)
8706 movl %ebp,%ebp /* zero extension */
8707 pushq_cfi $__USER32_DS
8708 /*CFI_REL_OFFSET ss,0*/
8709 @@ -134,22 +156,42 @@ ENTRY(ia32_sysenter_target)
8710 CFI_REL_OFFSET rsp,0
8711 pushfq_cfi
8712 /*CFI_REL_OFFSET rflags,0*/
8713 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
8714 - CFI_REGISTER rip,r10
8715 + orl $X86_EFLAGS_IF,(%rsp)
8716 + GET_THREAD_INFO(%r11)
8717 + movl TI_sysenter_return(%r11), %r11d
8718 + CFI_REGISTER rip,r11
8719 pushq_cfi $__USER32_CS
8720 /*CFI_REL_OFFSET cs,0*/
8721 movl %eax, %eax
8722 - pushq_cfi %r10
8723 + pushq_cfi %r11
8724 CFI_REL_OFFSET rip,0
8725 pushq_cfi %rax
8726 cld
8727 SAVE_ARGS 0,1,0
8728 + pax_enter_kernel_user
8729 +
8730 +#ifdef CONFIG_PAX_RANDKSTACK
8731 + pax_erase_kstack
8732 +#endif
8733 +
8734 + /*
8735 + * No need to follow this irqs on/off section: the syscall
8736 + * disabled irqs, here we enable it straight after entry:
8737 + */
8738 + ENABLE_INTERRUPTS(CLBR_NONE)
8739 /* no need to do an access_ok check here because rbp has been
8740 32bit zero extended */
8741 +
8742 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8743 + mov $PAX_USER_SHADOW_BASE,%r11
8744 + add %r11,%rbp
8745 +#endif
8746 +
8747 1: movl (%rbp),%ebp
8748 _ASM_EXTABLE(1b,ia32_badarg)
8749 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8750 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8751 + GET_THREAD_INFO(%r11)
8752 + orl $TS_COMPAT,TI_status(%r11)
8753 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8754 CFI_REMEMBER_STATE
8755 jnz sysenter_tracesys
8756 cmpq $(IA32_NR_syscalls-1),%rax
8757 @@ -159,12 +201,15 @@ sysenter_do_call:
8758 sysenter_dispatch:
8759 call *ia32_sys_call_table(,%rax,8)
8760 movq %rax,RAX-ARGOFFSET(%rsp)
8761 + GET_THREAD_INFO(%r11)
8762 DISABLE_INTERRUPTS(CLBR_NONE)
8763 TRACE_IRQS_OFF
8764 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8765 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8766 jnz sysexit_audit
8767 sysexit_from_sys_call:
8768 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8769 + pax_exit_kernel_user
8770 + pax_erase_kstack
8771 + andl $~TS_COMPAT,TI_status(%r11)
8772 /* clear IF, that popfq doesn't enable interrupts early */
8773 andl $~0x200,EFLAGS-R11(%rsp)
8774 movl RIP-R11(%rsp),%edx /* User %eip */
8775 @@ -190,6 +235,9 @@ sysexit_from_sys_call:
8776 movl %eax,%esi /* 2nd arg: syscall number */
8777 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
8778 call __audit_syscall_entry
8779 +
8780 + pax_erase_kstack
8781 +
8782 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
8783 cmpq $(IA32_NR_syscalls-1),%rax
8784 ja ia32_badsys
8785 @@ -201,7 +249,7 @@ sysexit_from_sys_call:
8786 .endm
8787
8788 .macro auditsys_exit exit
8789 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8790 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8791 jnz ia32_ret_from_sys_call
8792 TRACE_IRQS_ON
8793 sti
8794 @@ -212,11 +260,12 @@ sysexit_from_sys_call:
8795 1: setbe %al /* 1 if error, 0 if not */
8796 movzbl %al,%edi /* zero-extend that into %edi */
8797 call __audit_syscall_exit
8798 + GET_THREAD_INFO(%r11)
8799 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
8800 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
8801 cli
8802 TRACE_IRQS_OFF
8803 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8804 + testl %edi,TI_flags(%r11)
8805 jz \exit
8806 CLEAR_RREGS -ARGOFFSET
8807 jmp int_with_check
8808 @@ -234,7 +283,7 @@ sysexit_audit:
8809
8810 sysenter_tracesys:
8811 #ifdef CONFIG_AUDITSYSCALL
8812 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8813 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8814 jz sysenter_auditsys
8815 #endif
8816 SAVE_REST
8817 @@ -246,6 +295,9 @@ sysenter_tracesys:
8818 RESTORE_REST
8819 cmpq $(IA32_NR_syscalls-1),%rax
8820 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
8821 +
8822 + pax_erase_kstack
8823 +
8824 jmp sysenter_do_call
8825 CFI_ENDPROC
8826 ENDPROC(ia32_sysenter_target)
8827 @@ -273,19 +325,25 @@ ENDPROC(ia32_sysenter_target)
8828 ENTRY(ia32_cstar_target)
8829 CFI_STARTPROC32 simple
8830 CFI_SIGNAL_FRAME
8831 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
8832 + CFI_DEF_CFA rsp,0
8833 CFI_REGISTER rip,rcx
8834 /*CFI_REGISTER rflags,r11*/
8835 SWAPGS_UNSAFE_STACK
8836 movl %esp,%r8d
8837 CFI_REGISTER rsp,r8
8838 movq PER_CPU_VAR(kernel_stack),%rsp
8839 + SAVE_ARGS 8*6,0,0
8840 + pax_enter_kernel_user
8841 +
8842 +#ifdef CONFIG_PAX_RANDKSTACK
8843 + pax_erase_kstack
8844 +#endif
8845 +
8846 /*
8847 * No need to follow this irqs on/off section: the syscall
8848 * disabled irqs and here we enable it straight after entry:
8849 */
8850 ENABLE_INTERRUPTS(CLBR_NONE)
8851 - SAVE_ARGS 8,0,0
8852 movl %eax,%eax /* zero extension */
8853 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
8854 movq %rcx,RIP-ARGOFFSET(%rsp)
8855 @@ -301,10 +359,17 @@ ENTRY(ia32_cstar_target)
8856 /* no need to do an access_ok check here because r8 has been
8857 32bit zero extended */
8858 /* hardware stack frame is complete now */
8859 +
8860 +#ifdef CONFIG_PAX_MEMORY_UDEREF
8861 + mov $PAX_USER_SHADOW_BASE,%r11
8862 + add %r11,%r8
8863 +#endif
8864 +
8865 1: movl (%r8),%r9d
8866 _ASM_EXTABLE(1b,ia32_badarg)
8867 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8868 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8869 + GET_THREAD_INFO(%r11)
8870 + orl $TS_COMPAT,TI_status(%r11)
8871 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8872 CFI_REMEMBER_STATE
8873 jnz cstar_tracesys
8874 cmpq $IA32_NR_syscalls-1,%rax
8875 @@ -314,12 +379,15 @@ cstar_do_call:
8876 cstar_dispatch:
8877 call *ia32_sys_call_table(,%rax,8)
8878 movq %rax,RAX-ARGOFFSET(%rsp)
8879 + GET_THREAD_INFO(%r11)
8880 DISABLE_INTERRUPTS(CLBR_NONE)
8881 TRACE_IRQS_OFF
8882 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8883 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
8884 jnz sysretl_audit
8885 sysretl_from_sys_call:
8886 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8887 + pax_exit_kernel_user
8888 + pax_erase_kstack
8889 + andl $~TS_COMPAT,TI_status(%r11)
8890 RESTORE_ARGS 0,-ARG_SKIP,0,0,0
8891 movl RIP-ARGOFFSET(%rsp),%ecx
8892 CFI_REGISTER rip,rcx
8893 @@ -347,7 +415,7 @@ sysretl_audit:
8894
8895 cstar_tracesys:
8896 #ifdef CONFIG_AUDITSYSCALL
8897 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8898 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
8899 jz cstar_auditsys
8900 #endif
8901 xchgl %r9d,%ebp
8902 @@ -361,6 +429,9 @@ cstar_tracesys:
8903 xchgl %ebp,%r9d
8904 cmpq $(IA32_NR_syscalls-1),%rax
8905 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
8906 +
8907 + pax_erase_kstack
8908 +
8909 jmp cstar_do_call
8910 END(ia32_cstar_target)
8911
8912 @@ -401,19 +472,26 @@ ENTRY(ia32_syscall)
8913 CFI_REL_OFFSET rip,RIP-RIP
8914 PARAVIRT_ADJUST_EXCEPTION_FRAME
8915 SWAPGS
8916 - /*
8917 - * No need to follow this irqs on/off section: the syscall
8918 - * disabled irqs and here we enable it straight after entry:
8919 - */
8920 - ENABLE_INTERRUPTS(CLBR_NONE)
8921 movl %eax,%eax
8922 pushq_cfi %rax
8923 cld
8924 /* note the registers are not zero extended to the sf.
8925 this could be a problem. */
8926 SAVE_ARGS 0,1,0
8927 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8928 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
8929 + pax_enter_kernel_user
8930 +
8931 +#ifdef CONFIG_PAX_RANDKSTACK
8932 + pax_erase_kstack
8933 +#endif
8934 +
8935 + /*
8936 + * No need to follow this irqs on/off section: the syscall
8937 + * disabled irqs and here we enable it straight after entry:
8938 + */
8939 + ENABLE_INTERRUPTS(CLBR_NONE)
8940 + GET_THREAD_INFO(%r11)
8941 + orl $TS_COMPAT,TI_status(%r11)
8942 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
8943 jnz ia32_tracesys
8944 cmpq $(IA32_NR_syscalls-1),%rax
8945 ja ia32_badsys
8946 @@ -436,6 +514,9 @@ ia32_tracesys:
8947 RESTORE_REST
8948 cmpq $(IA32_NR_syscalls-1),%rax
8949 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
8950 +
8951 + pax_erase_kstack
8952 +
8953 jmp ia32_do_call
8954 END(ia32_syscall)
8955
8956 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
8957 index 4540bec..714d913 100644
8958 --- a/arch/x86/ia32/sys_ia32.c
8959 +++ b/arch/x86/ia32/sys_ia32.c
8960 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
8961 */
8962 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
8963 {
8964 - typeof(ubuf->st_uid) uid = 0;
8965 - typeof(ubuf->st_gid) gid = 0;
8966 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
8967 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
8968 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
8969 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
8970 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
8971 @@ -287,7 +287,7 @@ asmlinkage long sys32_sigaction(int sig, struct old_sigaction32 __user *act,
8972 return ret;
8973 }
8974
8975 -asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int *stat_addr,
8976 +asmlinkage long sys32_waitpid(compat_pid_t pid, unsigned int __user *stat_addr,
8977 int options)
8978 {
8979 return compat_sys_wait4(pid, stat_addr, options, NULL);
8980 @@ -303,7 +303,7 @@ asmlinkage long sys32_sched_rr_get_interval(compat_pid_t pid,
8981 mm_segment_t old_fs = get_fs();
8982
8983 set_fs(KERNEL_DS);
8984 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
8985 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
8986 set_fs(old_fs);
8987 if (put_compat_timespec(&t, interval))
8988 return -EFAULT;
8989 @@ -319,7 +319,7 @@ asmlinkage long sys32_rt_sigpending(compat_sigset_t __user *set,
8990 mm_segment_t old_fs = get_fs();
8991
8992 set_fs(KERNEL_DS);
8993 - ret = sys_rt_sigpending((sigset_t __user *)&s, sigsetsize);
8994 + ret = sys_rt_sigpending((sigset_t __force_user *)&s, sigsetsize);
8995 set_fs(old_fs);
8996 if (!ret) {
8997 switch (_NSIG_WORDS) {
8998 @@ -344,7 +344,7 @@ asmlinkage long sys32_rt_sigqueueinfo(int pid, int sig,
8999 if (copy_siginfo_from_user32(&info, uinfo))
9000 return -EFAULT;
9001 set_fs(KERNEL_DS);
9002 - ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __user *)&info);
9003 + ret = sys_rt_sigqueueinfo(pid, sig, (siginfo_t __force_user *)&info);
9004 set_fs(old_fs);
9005 return ret;
9006 }
9007 @@ -376,7 +376,7 @@ asmlinkage long sys32_sendfile(int out_fd, int in_fd,
9008 return -EFAULT;
9009
9010 set_fs(KERNEL_DS);
9011 - ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __user *)&of : NULL,
9012 + ret = sys_sendfile(out_fd, in_fd, offset ? (off_t __force_user *)&of : NULL,
9013 count);
9014 set_fs(old_fs);
9015
9016 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
9017 index 952bd01..7692c6f 100644
9018 --- a/arch/x86/include/asm/alternative-asm.h
9019 +++ b/arch/x86/include/asm/alternative-asm.h
9020 @@ -15,6 +15,45 @@
9021 .endm
9022 #endif
9023
9024 +#ifdef KERNEXEC_PLUGIN
9025 + .macro pax_force_retaddr_bts rip=0
9026 + btsq $63,\rip(%rsp)
9027 + .endm
9028 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
9029 + .macro pax_force_retaddr rip=0, reload=0
9030 + btsq $63,\rip(%rsp)
9031 + .endm
9032 + .macro pax_force_fptr ptr
9033 + btsq $63,\ptr
9034 + .endm
9035 + .macro pax_set_fptr_mask
9036 + .endm
9037 +#endif
9038 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
9039 + .macro pax_force_retaddr rip=0, reload=0
9040 + .if \reload
9041 + pax_set_fptr_mask
9042 + .endif
9043 + orq %r10,\rip(%rsp)
9044 + .endm
9045 + .macro pax_force_fptr ptr
9046 + orq %r10,\ptr
9047 + .endm
9048 + .macro pax_set_fptr_mask
9049 + movabs $0x8000000000000000,%r10
9050 + .endm
9051 +#endif
9052 +#else
9053 + .macro pax_force_retaddr rip=0, reload=0
9054 + .endm
9055 + .macro pax_force_fptr ptr
9056 + .endm
9057 + .macro pax_force_retaddr_bts rip=0
9058 + .endm
9059 + .macro pax_set_fptr_mask
9060 + .endm
9061 +#endif
9062 +
9063 .macro altinstruction_entry orig alt feature orig_len alt_len
9064 .long \orig - .
9065 .long \alt - .
9066 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
9067 index 49331be..9706065 100644
9068 --- a/arch/x86/include/asm/alternative.h
9069 +++ b/arch/x86/include/asm/alternative.h
9070 @@ -89,7 +89,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
9071 ".section .discard,\"aw\",@progbits\n" \
9072 " .byte 0xff + (664f-663f) - (662b-661b)\n" /* rlen <= slen */ \
9073 ".previous\n" \
9074 - ".section .altinstr_replacement, \"ax\"\n" \
9075 + ".section .altinstr_replacement, \"a\"\n" \
9076 "663:\n\t" newinstr "\n664:\n" /* replacement */ \
9077 ".previous"
9078
9079 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
9080 index eaff479..1eff9b5 100644
9081 --- a/arch/x86/include/asm/apic.h
9082 +++ b/arch/x86/include/asm/apic.h
9083 @@ -44,7 +44,7 @@ static inline void generic_apic_probe(void)
9084
9085 #ifdef CONFIG_X86_LOCAL_APIC
9086
9087 -extern unsigned int apic_verbosity;
9088 +extern int apic_verbosity;
9089 extern int local_apic_timer_c2_ok;
9090
9091 extern int disable_apic;
9092 @@ -390,7 +390,7 @@ struct apic {
9093 */
9094 int (*x86_32_numa_cpu_node)(int cpu);
9095 #endif
9096 -};
9097 +} __do_const;
9098
9099 /*
9100 * Pointer to the local APIC driver in use on this system (there's
9101 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
9102 index 20370c6..a2eb9b0 100644
9103 --- a/arch/x86/include/asm/apm.h
9104 +++ b/arch/x86/include/asm/apm.h
9105 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
9106 __asm__ __volatile__(APM_DO_ZERO_SEGS
9107 "pushl %%edi\n\t"
9108 "pushl %%ebp\n\t"
9109 - "lcall *%%cs:apm_bios_entry\n\t"
9110 + "lcall *%%ss:apm_bios_entry\n\t"
9111 "setc %%al\n\t"
9112 "popl %%ebp\n\t"
9113 "popl %%edi\n\t"
9114 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
9115 __asm__ __volatile__(APM_DO_ZERO_SEGS
9116 "pushl %%edi\n\t"
9117 "pushl %%ebp\n\t"
9118 - "lcall *%%cs:apm_bios_entry\n\t"
9119 + "lcall *%%ss:apm_bios_entry\n\t"
9120 "setc %%bl\n\t"
9121 "popl %%ebp\n\t"
9122 "popl %%edi\n\t"
9123 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
9124 index 58cb6d4..a4b806c 100644
9125 --- a/arch/x86/include/asm/atomic.h
9126 +++ b/arch/x86/include/asm/atomic.h
9127 @@ -22,7 +22,18 @@
9128 */
9129 static inline int atomic_read(const atomic_t *v)
9130 {
9131 - return (*(volatile int *)&(v)->counter);
9132 + return (*(volatile const int *)&(v)->counter);
9133 +}
9134 +
9135 +/**
9136 + * atomic_read_unchecked - read atomic variable
9137 + * @v: pointer of type atomic_unchecked_t
9138 + *
9139 + * Atomically reads the value of @v.
9140 + */
9141 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
9142 +{
9143 + return (*(volatile const int *)&(v)->counter);
9144 }
9145
9146 /**
9147 @@ -38,6 +49,18 @@ static inline void atomic_set(atomic_t *v, int i)
9148 }
9149
9150 /**
9151 + * atomic_set_unchecked - set atomic variable
9152 + * @v: pointer of type atomic_unchecked_t
9153 + * @i: required value
9154 + *
9155 + * Atomically sets the value of @v to @i.
9156 + */
9157 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
9158 +{
9159 + v->counter = i;
9160 +}
9161 +
9162 +/**
9163 * atomic_add - add integer to atomic variable
9164 * @i: integer value to add
9165 * @v: pointer of type atomic_t
9166 @@ -46,7 +69,29 @@ static inline void atomic_set(atomic_t *v, int i)
9167 */
9168 static inline void atomic_add(int i, atomic_t *v)
9169 {
9170 - asm volatile(LOCK_PREFIX "addl %1,%0"
9171 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9172 +
9173 +#ifdef CONFIG_PAX_REFCOUNT
9174 + "jno 0f\n"
9175 + LOCK_PREFIX "subl %1,%0\n"
9176 + "int $4\n0:\n"
9177 + _ASM_EXTABLE(0b, 0b)
9178 +#endif
9179 +
9180 + : "+m" (v->counter)
9181 + : "ir" (i));
9182 +}
9183 +
9184 +/**
9185 + * atomic_add_unchecked - add integer to atomic variable
9186 + * @i: integer value to add
9187 + * @v: pointer of type atomic_unchecked_t
9188 + *
9189 + * Atomically adds @i to @v.
9190 + */
9191 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
9192 +{
9193 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
9194 : "+m" (v->counter)
9195 : "ir" (i));
9196 }
9197 @@ -60,7 +105,29 @@ static inline void atomic_add(int i, atomic_t *v)
9198 */
9199 static inline void atomic_sub(int i, atomic_t *v)
9200 {
9201 - asm volatile(LOCK_PREFIX "subl %1,%0"
9202 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9203 +
9204 +#ifdef CONFIG_PAX_REFCOUNT
9205 + "jno 0f\n"
9206 + LOCK_PREFIX "addl %1,%0\n"
9207 + "int $4\n0:\n"
9208 + _ASM_EXTABLE(0b, 0b)
9209 +#endif
9210 +
9211 + : "+m" (v->counter)
9212 + : "ir" (i));
9213 +}
9214 +
9215 +/**
9216 + * atomic_sub_unchecked - subtract integer from atomic variable
9217 + * @i: integer value to subtract
9218 + * @v: pointer of type atomic_unchecked_t
9219 + *
9220 + * Atomically subtracts @i from @v.
9221 + */
9222 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
9223 +{
9224 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
9225 : "+m" (v->counter)
9226 : "ir" (i));
9227 }
9228 @@ -78,7 +145,16 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9229 {
9230 unsigned char c;
9231
9232 - asm volatile(LOCK_PREFIX "subl %2,%0; sete %1"
9233 + asm volatile(LOCK_PREFIX "subl %2,%0\n"
9234 +
9235 +#ifdef CONFIG_PAX_REFCOUNT
9236 + "jno 0f\n"
9237 + LOCK_PREFIX "addl %2,%0\n"
9238 + "int $4\n0:\n"
9239 + _ASM_EXTABLE(0b, 0b)
9240 +#endif
9241 +
9242 + "sete %1\n"
9243 : "+m" (v->counter), "=qm" (c)
9244 : "ir" (i) : "memory");
9245 return c;
9246 @@ -92,7 +168,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
9247 */
9248 static inline void atomic_inc(atomic_t *v)
9249 {
9250 - asm volatile(LOCK_PREFIX "incl %0"
9251 + asm volatile(LOCK_PREFIX "incl %0\n"
9252 +
9253 +#ifdef CONFIG_PAX_REFCOUNT
9254 + "jno 0f\n"
9255 + LOCK_PREFIX "decl %0\n"
9256 + "int $4\n0:\n"
9257 + _ASM_EXTABLE(0b, 0b)
9258 +#endif
9259 +
9260 + : "+m" (v->counter));
9261 +}
9262 +
9263 +/**
9264 + * atomic_inc_unchecked - increment atomic variable
9265 + * @v: pointer of type atomic_unchecked_t
9266 + *
9267 + * Atomically increments @v by 1.
9268 + */
9269 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9270 +{
9271 + asm volatile(LOCK_PREFIX "incl %0\n"
9272 : "+m" (v->counter));
9273 }
9274
9275 @@ -104,7 +200,27 @@ static inline void atomic_inc(atomic_t *v)
9276 */
9277 static inline void atomic_dec(atomic_t *v)
9278 {
9279 - asm volatile(LOCK_PREFIX "decl %0"
9280 + asm volatile(LOCK_PREFIX "decl %0\n"
9281 +
9282 +#ifdef CONFIG_PAX_REFCOUNT
9283 + "jno 0f\n"
9284 + LOCK_PREFIX "incl %0\n"
9285 + "int $4\n0:\n"
9286 + _ASM_EXTABLE(0b, 0b)
9287 +#endif
9288 +
9289 + : "+m" (v->counter));
9290 +}
9291 +
9292 +/**
9293 + * atomic_dec_unchecked - decrement atomic variable
9294 + * @v: pointer of type atomic_unchecked_t
9295 + *
9296 + * Atomically decrements @v by 1.
9297 + */
9298 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9299 +{
9300 + asm volatile(LOCK_PREFIX "decl %0\n"
9301 : "+m" (v->counter));
9302 }
9303
9304 @@ -120,7 +236,16 @@ static inline int atomic_dec_and_test(atomic_t *v)
9305 {
9306 unsigned char c;
9307
9308 - asm volatile(LOCK_PREFIX "decl %0; sete %1"
9309 + asm volatile(LOCK_PREFIX "decl %0\n"
9310 +
9311 +#ifdef CONFIG_PAX_REFCOUNT
9312 + "jno 0f\n"
9313 + LOCK_PREFIX "incl %0\n"
9314 + "int $4\n0:\n"
9315 + _ASM_EXTABLE(0b, 0b)
9316 +#endif
9317 +
9318 + "sete %1\n"
9319 : "+m" (v->counter), "=qm" (c)
9320 : : "memory");
9321 return c != 0;
9322 @@ -138,7 +263,35 @@ static inline int atomic_inc_and_test(atomic_t *v)
9323 {
9324 unsigned char c;
9325
9326 - asm volatile(LOCK_PREFIX "incl %0; sete %1"
9327 + asm volatile(LOCK_PREFIX "incl %0\n"
9328 +
9329 +#ifdef CONFIG_PAX_REFCOUNT
9330 + "jno 0f\n"
9331 + LOCK_PREFIX "decl %0\n"
9332 + "int $4\n0:\n"
9333 + _ASM_EXTABLE(0b, 0b)
9334 +#endif
9335 +
9336 + "sete %1\n"
9337 + : "+m" (v->counter), "=qm" (c)
9338 + : : "memory");
9339 + return c != 0;
9340 +}
9341 +
9342 +/**
9343 + * atomic_inc_and_test_unchecked - increment and test
9344 + * @v: pointer of type atomic_unchecked_t
9345 + *
9346 + * Atomically increments @v by 1
9347 + * and returns true if the result is zero, or false for all
9348 + * other cases.
9349 + */
9350 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9351 +{
9352 + unsigned char c;
9353 +
9354 + asm volatile(LOCK_PREFIX "incl %0\n"
9355 + "sete %1\n"
9356 : "+m" (v->counter), "=qm" (c)
9357 : : "memory");
9358 return c != 0;
9359 @@ -157,7 +310,16 @@ static inline int atomic_add_negative(int i, atomic_t *v)
9360 {
9361 unsigned char c;
9362
9363 - asm volatile(LOCK_PREFIX "addl %2,%0; sets %1"
9364 + asm volatile(LOCK_PREFIX "addl %2,%0\n"
9365 +
9366 +#ifdef CONFIG_PAX_REFCOUNT
9367 + "jno 0f\n"
9368 + LOCK_PREFIX "subl %2,%0\n"
9369 + "int $4\n0:\n"
9370 + _ASM_EXTABLE(0b, 0b)
9371 +#endif
9372 +
9373 + "sets %1\n"
9374 : "+m" (v->counter), "=qm" (c)
9375 : "ir" (i) : "memory");
9376 return c;
9377 @@ -179,7 +341,7 @@ static inline int atomic_add_return(int i, atomic_t *v)
9378 goto no_xadd;
9379 #endif
9380 /* Modern 486+ processor */
9381 - return i + xadd(&v->counter, i);
9382 + return i + xadd_check_overflow(&v->counter, i);
9383
9384 #ifdef CONFIG_M386
9385 no_xadd: /* Legacy 386 processor */
9386 @@ -192,6 +354,34 @@ no_xadd: /* Legacy 386 processor */
9387 }
9388
9389 /**
9390 + * atomic_add_return_unchecked - add integer and return
9391 + * @i: integer value to add
9392 + * @v: pointer of type atomic_unchecked_t
9393 + *
9394 + * Atomically adds @i to @v and returns @i + @v
9395 + */
9396 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9397 +{
9398 +#ifdef CONFIG_M386
9399 + int __i;
9400 + unsigned long flags;
9401 + if (unlikely(boot_cpu_data.x86 <= 3))
9402 + goto no_xadd;
9403 +#endif
9404 + /* Modern 486+ processor */
9405 + return i + xadd(&v->counter, i);
9406 +
9407 +#ifdef CONFIG_M386
9408 +no_xadd: /* Legacy 386 processor */
9409 + raw_local_irq_save(flags);
9410 + __i = atomic_read_unchecked(v);
9411 + atomic_set_unchecked(v, i + __i);
9412 + raw_local_irq_restore(flags);
9413 + return i + __i;
9414 +#endif
9415 +}
9416 +
9417 +/**
9418 * atomic_sub_return - subtract integer and return
9419 * @v: pointer of type atomic_t
9420 * @i: integer value to subtract
9421 @@ -204,6 +394,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
9422 }
9423
9424 #define atomic_inc_return(v) (atomic_add_return(1, v))
9425 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9426 +{
9427 + return atomic_add_return_unchecked(1, v);
9428 +}
9429 #define atomic_dec_return(v) (atomic_sub_return(1, v))
9430
9431 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9432 @@ -211,11 +405,21 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
9433 return cmpxchg(&v->counter, old, new);
9434 }
9435
9436 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9437 +{
9438 + return cmpxchg(&v->counter, old, new);
9439 +}
9440 +
9441 static inline int atomic_xchg(atomic_t *v, int new)
9442 {
9443 return xchg(&v->counter, new);
9444 }
9445
9446 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9447 +{
9448 + return xchg(&v->counter, new);
9449 +}
9450 +
9451 /**
9452 * __atomic_add_unless - add unless the number is already a given value
9453 * @v: pointer of type atomic_t
9454 @@ -227,12 +431,25 @@ static inline int atomic_xchg(atomic_t *v, int new)
9455 */
9456 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9457 {
9458 - int c, old;
9459 + int c, old, new;
9460 c = atomic_read(v);
9461 for (;;) {
9462 - if (unlikely(c == (u)))
9463 + if (unlikely(c == u))
9464 break;
9465 - old = atomic_cmpxchg((v), c, c + (a));
9466 +
9467 + asm volatile("addl %2,%0\n"
9468 +
9469 +#ifdef CONFIG_PAX_REFCOUNT
9470 + "jno 0f\n"
9471 + "subl %2,%0\n"
9472 + "int $4\n0:\n"
9473 + _ASM_EXTABLE(0b, 0b)
9474 +#endif
9475 +
9476 + : "=r" (new)
9477 + : "0" (c), "ir" (a));
9478 +
9479 + old = atomic_cmpxchg(v, c, new);
9480 if (likely(old == c))
9481 break;
9482 c = old;
9483 @@ -240,6 +457,48 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9484 return c;
9485 }
9486
9487 +/**
9488 + * atomic_inc_not_zero_hint - increment if not null
9489 + * @v: pointer of type atomic_t
9490 + * @hint: probable value of the atomic before the increment
9491 + *
9492 + * This version of atomic_inc_not_zero() gives a hint of probable
9493 + * value of the atomic. This helps processor to not read the memory
9494 + * before doing the atomic read/modify/write cycle, lowering
9495 + * number of bus transactions on some arches.
9496 + *
9497 + * Returns: 0 if increment was not done, 1 otherwise.
9498 + */
9499 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
9500 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
9501 +{
9502 + int val, c = hint, new;
9503 +
9504 + /* sanity test, should be removed by compiler if hint is a constant */
9505 + if (!hint)
9506 + return __atomic_add_unless(v, 1, 0);
9507 +
9508 + do {
9509 + asm volatile("incl %0\n"
9510 +
9511 +#ifdef CONFIG_PAX_REFCOUNT
9512 + "jno 0f\n"
9513 + "decl %0\n"
9514 + "int $4\n0:\n"
9515 + _ASM_EXTABLE(0b, 0b)
9516 +#endif
9517 +
9518 + : "=r" (new)
9519 + : "0" (c));
9520 +
9521 + val = atomic_cmpxchg(v, c, new);
9522 + if (val == c)
9523 + return 1;
9524 + c = val;
9525 + } while (c);
9526 +
9527 + return 0;
9528 +}
9529
9530 /*
9531 * atomic_dec_if_positive - decrement by 1 if old value positive
9532 @@ -293,14 +552,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
9533 #endif
9534
9535 /* These are x86-specific, used by some header files */
9536 -#define atomic_clear_mask(mask, addr) \
9537 - asm volatile(LOCK_PREFIX "andl %0,%1" \
9538 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
9539 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
9540 +{
9541 + asm volatile(LOCK_PREFIX "andl %1,%0"
9542 + : "+m" (v->counter)
9543 + : "r" (~(mask))
9544 + : "memory");
9545 +}
9546
9547 -#define atomic_set_mask(mask, addr) \
9548 - asm volatile(LOCK_PREFIX "orl %0,%1" \
9549 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
9550 - : "memory")
9551 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9552 +{
9553 + asm volatile(LOCK_PREFIX "andl %1,%0"
9554 + : "+m" (v->counter)
9555 + : "r" (~(mask))
9556 + : "memory");
9557 +}
9558 +
9559 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
9560 +{
9561 + asm volatile(LOCK_PREFIX "orl %1,%0"
9562 + : "+m" (v->counter)
9563 + : "r" (mask)
9564 + : "memory");
9565 +}
9566 +
9567 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
9568 +{
9569 + asm volatile(LOCK_PREFIX "orl %1,%0"
9570 + : "+m" (v->counter)
9571 + : "r" (mask)
9572 + : "memory");
9573 +}
9574
9575 /* Atomic operations are already serializing on x86 */
9576 #define smp_mb__before_atomic_dec() barrier()
9577 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
9578 index b154de7..aadebd8 100644
9579 --- a/arch/x86/include/asm/atomic64_32.h
9580 +++ b/arch/x86/include/asm/atomic64_32.h
9581 @@ -12,6 +12,14 @@ typedef struct {
9582 u64 __aligned(8) counter;
9583 } atomic64_t;
9584
9585 +#ifdef CONFIG_PAX_REFCOUNT
9586 +typedef struct {
9587 + u64 __aligned(8) counter;
9588 +} atomic64_unchecked_t;
9589 +#else
9590 +typedef atomic64_t atomic64_unchecked_t;
9591 +#endif
9592 +
9593 #define ATOMIC64_INIT(val) { (val) }
9594
9595 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
9596 @@ -37,21 +45,31 @@ typedef struct {
9597 ATOMIC64_DECL_ONE(sym##_386)
9598
9599 ATOMIC64_DECL_ONE(add_386);
9600 +ATOMIC64_DECL_ONE(add_unchecked_386);
9601 ATOMIC64_DECL_ONE(sub_386);
9602 +ATOMIC64_DECL_ONE(sub_unchecked_386);
9603 ATOMIC64_DECL_ONE(inc_386);
9604 +ATOMIC64_DECL_ONE(inc_unchecked_386);
9605 ATOMIC64_DECL_ONE(dec_386);
9606 +ATOMIC64_DECL_ONE(dec_unchecked_386);
9607 #endif
9608
9609 #define alternative_atomic64(f, out, in...) \
9610 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
9611
9612 ATOMIC64_DECL(read);
9613 +ATOMIC64_DECL(read_unchecked);
9614 ATOMIC64_DECL(set);
9615 +ATOMIC64_DECL(set_unchecked);
9616 ATOMIC64_DECL(xchg);
9617 ATOMIC64_DECL(add_return);
9618 +ATOMIC64_DECL(add_return_unchecked);
9619 ATOMIC64_DECL(sub_return);
9620 +ATOMIC64_DECL(sub_return_unchecked);
9621 ATOMIC64_DECL(inc_return);
9622 +ATOMIC64_DECL(inc_return_unchecked);
9623 ATOMIC64_DECL(dec_return);
9624 +ATOMIC64_DECL(dec_return_unchecked);
9625 ATOMIC64_DECL(dec_if_positive);
9626 ATOMIC64_DECL(inc_not_zero);
9627 ATOMIC64_DECL(add_unless);
9628 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
9629 }
9630
9631 /**
9632 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
9633 + * @p: pointer to type atomic64_unchecked_t
9634 + * @o: expected value
9635 + * @n: new value
9636 + *
9637 + * Atomically sets @v to @n if it was equal to @o and returns
9638 + * the old value.
9639 + */
9640 +
9641 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
9642 +{
9643 + return cmpxchg64(&v->counter, o, n);
9644 +}
9645 +
9646 +/**
9647 * atomic64_xchg - xchg atomic64 variable
9648 * @v: pointer to type atomic64_t
9649 * @n: value to assign
9650 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
9651 }
9652
9653 /**
9654 + * atomic64_set_unchecked - set atomic64 variable
9655 + * @v: pointer to type atomic64_unchecked_t
9656 + * @n: value to assign
9657 + *
9658 + * Atomically sets the value of @v to @n.
9659 + */
9660 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
9661 +{
9662 + unsigned high = (unsigned)(i >> 32);
9663 + unsigned low = (unsigned)i;
9664 + alternative_atomic64(set, /* no output */,
9665 + "S" (v), "b" (low), "c" (high)
9666 + : "eax", "edx", "memory");
9667 +}
9668 +
9669 +/**
9670 * atomic64_read - read atomic64 variable
9671 * @v: pointer to type atomic64_t
9672 *
9673 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
9674 }
9675
9676 /**
9677 + * atomic64_read_unchecked - read atomic64 variable
9678 + * @v: pointer to type atomic64_unchecked_t
9679 + *
9680 + * Atomically reads the value of @v and returns it.
9681 + */
9682 +static inline long long atomic64_read_unchecked(atomic64_unchecked_t *v)
9683 +{
9684 + long long r;
9685 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
9686 + return r;
9687 + }
9688 +
9689 +/**
9690 * atomic64_add_return - add and return
9691 * @i: integer value to add
9692 * @v: pointer to type atomic64_t
9693 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
9694 return i;
9695 }
9696
9697 +/**
9698 + * atomic64_add_return_unchecked - add and return
9699 + * @i: integer value to add
9700 + * @v: pointer to type atomic64_unchecked_t
9701 + *
9702 + * Atomically adds @i to @v and returns @i + *@v
9703 + */
9704 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
9705 +{
9706 + alternative_atomic64(add_return_unchecked,
9707 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9708 + ASM_NO_INPUT_CLOBBER("memory"));
9709 + return i;
9710 +}
9711 +
9712 /*
9713 * Other variants with different arithmetic operators:
9714 */
9715 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
9716 return a;
9717 }
9718
9719 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9720 +{
9721 + long long a;
9722 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
9723 + "S" (v) : "memory", "ecx");
9724 + return a;
9725 +}
9726 +
9727 static inline long long atomic64_dec_return(atomic64_t *v)
9728 {
9729 long long a;
9730 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
9731 }
9732
9733 /**
9734 + * atomic64_add_unchecked - add integer to atomic64 variable
9735 + * @i: integer value to add
9736 + * @v: pointer to type atomic64_unchecked_t
9737 + *
9738 + * Atomically adds @i to @v.
9739 + */
9740 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
9741 +{
9742 + __alternative_atomic64(add_unchecked, add_return_unchecked,
9743 + ASM_OUTPUT2("+A" (i), "+c" (v)),
9744 + ASM_NO_INPUT_CLOBBER("memory"));
9745 + return i;
9746 +}
9747 +
9748 +/**
9749 * atomic64_sub - subtract the atomic64 variable
9750 * @i: integer value to subtract
9751 * @v: pointer to type atomic64_t
9752 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
9753 index 0e1cbfc..5623683 100644
9754 --- a/arch/x86/include/asm/atomic64_64.h
9755 +++ b/arch/x86/include/asm/atomic64_64.h
9756 @@ -18,7 +18,19 @@
9757 */
9758 static inline long atomic64_read(const atomic64_t *v)
9759 {
9760 - return (*(volatile long *)&(v)->counter);
9761 + return (*(volatile const long *)&(v)->counter);
9762 +}
9763 +
9764 +/**
9765 + * atomic64_read_unchecked - read atomic64 variable
9766 + * @v: pointer of type atomic64_unchecked_t
9767 + *
9768 + * Atomically reads the value of @v.
9769 + * Doesn't imply a read memory barrier.
9770 + */
9771 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
9772 +{
9773 + return (*(volatile const long *)&(v)->counter);
9774 }
9775
9776 /**
9777 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
9778 }
9779
9780 /**
9781 + * atomic64_set_unchecked - set atomic64 variable
9782 + * @v: pointer to type atomic64_unchecked_t
9783 + * @i: required value
9784 + *
9785 + * Atomically sets the value of @v to @i.
9786 + */
9787 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
9788 +{
9789 + v->counter = i;
9790 +}
9791 +
9792 +/**
9793 * atomic64_add - add integer to atomic64 variable
9794 * @i: integer value to add
9795 * @v: pointer to type atomic64_t
9796 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
9797 */
9798 static inline void atomic64_add(long i, atomic64_t *v)
9799 {
9800 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
9801 +
9802 +#ifdef CONFIG_PAX_REFCOUNT
9803 + "jno 0f\n"
9804 + LOCK_PREFIX "subq %1,%0\n"
9805 + "int $4\n0:\n"
9806 + _ASM_EXTABLE(0b, 0b)
9807 +#endif
9808 +
9809 + : "=m" (v->counter)
9810 + : "er" (i), "m" (v->counter));
9811 +}
9812 +
9813 +/**
9814 + * atomic64_add_unchecked - add integer to atomic64 variable
9815 + * @i: integer value to add
9816 + * @v: pointer to type atomic64_unchecked_t
9817 + *
9818 + * Atomically adds @i to @v.
9819 + */
9820 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
9821 +{
9822 asm volatile(LOCK_PREFIX "addq %1,%0"
9823 : "=m" (v->counter)
9824 : "er" (i), "m" (v->counter));
9825 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
9826 */
9827 static inline void atomic64_sub(long i, atomic64_t *v)
9828 {
9829 - asm volatile(LOCK_PREFIX "subq %1,%0"
9830 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9831 +
9832 +#ifdef CONFIG_PAX_REFCOUNT
9833 + "jno 0f\n"
9834 + LOCK_PREFIX "addq %1,%0\n"
9835 + "int $4\n0:\n"
9836 + _ASM_EXTABLE(0b, 0b)
9837 +#endif
9838 +
9839 + : "=m" (v->counter)
9840 + : "er" (i), "m" (v->counter));
9841 +}
9842 +
9843 +/**
9844 + * atomic64_sub_unchecked - subtract the atomic64 variable
9845 + * @i: integer value to subtract
9846 + * @v: pointer to type atomic64_unchecked_t
9847 + *
9848 + * Atomically subtracts @i from @v.
9849 + */
9850 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
9851 +{
9852 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
9853 : "=m" (v->counter)
9854 : "er" (i), "m" (v->counter));
9855 }
9856 @@ -74,7 +142,16 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9857 {
9858 unsigned char c;
9859
9860 - asm volatile(LOCK_PREFIX "subq %2,%0; sete %1"
9861 + asm volatile(LOCK_PREFIX "subq %2,%0\n"
9862 +
9863 +#ifdef CONFIG_PAX_REFCOUNT
9864 + "jno 0f\n"
9865 + LOCK_PREFIX "addq %2,%0\n"
9866 + "int $4\n0:\n"
9867 + _ASM_EXTABLE(0b, 0b)
9868 +#endif
9869 +
9870 + "sete %1\n"
9871 : "=m" (v->counter), "=qm" (c)
9872 : "er" (i), "m" (v->counter) : "memory");
9873 return c;
9874 @@ -88,6 +165,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
9875 */
9876 static inline void atomic64_inc(atomic64_t *v)
9877 {
9878 + asm volatile(LOCK_PREFIX "incq %0\n"
9879 +
9880 +#ifdef CONFIG_PAX_REFCOUNT
9881 + "jno 0f\n"
9882 + LOCK_PREFIX "decq %0\n"
9883 + "int $4\n0:\n"
9884 + _ASM_EXTABLE(0b, 0b)
9885 +#endif
9886 +
9887 + : "=m" (v->counter)
9888 + : "m" (v->counter));
9889 +}
9890 +
9891 +/**
9892 + * atomic64_inc_unchecked - increment atomic64 variable
9893 + * @v: pointer to type atomic64_unchecked_t
9894 + *
9895 + * Atomically increments @v by 1.
9896 + */
9897 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9898 +{
9899 asm volatile(LOCK_PREFIX "incq %0"
9900 : "=m" (v->counter)
9901 : "m" (v->counter));
9902 @@ -101,7 +199,28 @@ static inline void atomic64_inc(atomic64_t *v)
9903 */
9904 static inline void atomic64_dec(atomic64_t *v)
9905 {
9906 - asm volatile(LOCK_PREFIX "decq %0"
9907 + asm volatile(LOCK_PREFIX "decq %0\n"
9908 +
9909 +#ifdef CONFIG_PAX_REFCOUNT
9910 + "jno 0f\n"
9911 + LOCK_PREFIX "incq %0\n"
9912 + "int $4\n0:\n"
9913 + _ASM_EXTABLE(0b, 0b)
9914 +#endif
9915 +
9916 + : "=m" (v->counter)
9917 + : "m" (v->counter));
9918 +}
9919 +
9920 +/**
9921 + * atomic64_dec_unchecked - decrement atomic64 variable
9922 + * @v: pointer to type atomic64_t
9923 + *
9924 + * Atomically decrements @v by 1.
9925 + */
9926 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9927 +{
9928 + asm volatile(LOCK_PREFIX "decq %0\n"
9929 : "=m" (v->counter)
9930 : "m" (v->counter));
9931 }
9932 @@ -118,7 +237,16 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
9933 {
9934 unsigned char c;
9935
9936 - asm volatile(LOCK_PREFIX "decq %0; sete %1"
9937 + asm volatile(LOCK_PREFIX "decq %0\n"
9938 +
9939 +#ifdef CONFIG_PAX_REFCOUNT
9940 + "jno 0f\n"
9941 + LOCK_PREFIX "incq %0\n"
9942 + "int $4\n0:\n"
9943 + _ASM_EXTABLE(0b, 0b)
9944 +#endif
9945 +
9946 + "sete %1\n"
9947 : "=m" (v->counter), "=qm" (c)
9948 : "m" (v->counter) : "memory");
9949 return c != 0;
9950 @@ -136,7 +264,16 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
9951 {
9952 unsigned char c;
9953
9954 - asm volatile(LOCK_PREFIX "incq %0; sete %1"
9955 + asm volatile(LOCK_PREFIX "incq %0\n"
9956 +
9957 +#ifdef CONFIG_PAX_REFCOUNT
9958 + "jno 0f\n"
9959 + LOCK_PREFIX "decq %0\n"
9960 + "int $4\n0:\n"
9961 + _ASM_EXTABLE(0b, 0b)
9962 +#endif
9963 +
9964 + "sete %1\n"
9965 : "=m" (v->counter), "=qm" (c)
9966 : "m" (v->counter) : "memory");
9967 return c != 0;
9968 @@ -155,7 +292,16 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9969 {
9970 unsigned char c;
9971
9972 - asm volatile(LOCK_PREFIX "addq %2,%0; sets %1"
9973 + asm volatile(LOCK_PREFIX "addq %2,%0\n"
9974 +
9975 +#ifdef CONFIG_PAX_REFCOUNT
9976 + "jno 0f\n"
9977 + LOCK_PREFIX "subq %2,%0\n"
9978 + "int $4\n0:\n"
9979 + _ASM_EXTABLE(0b, 0b)
9980 +#endif
9981 +
9982 + "sets %1\n"
9983 : "=m" (v->counter), "=qm" (c)
9984 : "er" (i), "m" (v->counter) : "memory");
9985 return c;
9986 @@ -170,6 +316,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
9987 */
9988 static inline long atomic64_add_return(long i, atomic64_t *v)
9989 {
9990 + return i + xadd_check_overflow(&v->counter, i);
9991 +}
9992 +
9993 +/**
9994 + * atomic64_add_return_unchecked - add and return
9995 + * @i: integer value to add
9996 + * @v: pointer to type atomic64_unchecked_t
9997 + *
9998 + * Atomically adds @i to @v and returns @i + @v
9999 + */
10000 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
10001 +{
10002 return i + xadd(&v->counter, i);
10003 }
10004
10005 @@ -179,6 +337,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
10006 }
10007
10008 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
10009 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
10010 +{
10011 + return atomic64_add_return_unchecked(1, v);
10012 +}
10013 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
10014
10015 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10016 @@ -186,6 +348,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
10017 return cmpxchg(&v->counter, old, new);
10018 }
10019
10020 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
10021 +{
10022 + return cmpxchg(&v->counter, old, new);
10023 +}
10024 +
10025 static inline long atomic64_xchg(atomic64_t *v, long new)
10026 {
10027 return xchg(&v->counter, new);
10028 @@ -202,17 +369,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
10029 */
10030 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
10031 {
10032 - long c, old;
10033 + long c, old, new;
10034 c = atomic64_read(v);
10035 for (;;) {
10036 - if (unlikely(c == (u)))
10037 + if (unlikely(c == u))
10038 break;
10039 - old = atomic64_cmpxchg((v), c, c + (a));
10040 +
10041 + asm volatile("add %2,%0\n"
10042 +
10043 +#ifdef CONFIG_PAX_REFCOUNT
10044 + "jno 0f\n"
10045 + "sub %2,%0\n"
10046 + "int $4\n0:\n"
10047 + _ASM_EXTABLE(0b, 0b)
10048 +#endif
10049 +
10050 + : "=r" (new)
10051 + : "0" (c), "ir" (a));
10052 +
10053 + old = atomic64_cmpxchg(v, c, new);
10054 if (likely(old == c))
10055 break;
10056 c = old;
10057 }
10058 - return c != (u);
10059 + return c != u;
10060 }
10061
10062 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
10063 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
10064 index a6983b2..63f48a2 100644
10065 --- a/arch/x86/include/asm/bitops.h
10066 +++ b/arch/x86/include/asm/bitops.h
10067 @@ -40,7 +40,7 @@
10068 * a mask operation on a byte.
10069 */
10070 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
10071 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
10072 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
10073 #define CONST_MASK(nr) (1 << ((nr) & 7))
10074
10075 /**
10076 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
10077 index b13fe63..0dab13a 100644
10078 --- a/arch/x86/include/asm/boot.h
10079 +++ b/arch/x86/include/asm/boot.h
10080 @@ -11,10 +11,15 @@
10081 #include <asm/pgtable_types.h>
10082
10083 /* Physical address where kernel should be loaded. */
10084 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10085 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
10086 + (CONFIG_PHYSICAL_ALIGN - 1)) \
10087 & ~(CONFIG_PHYSICAL_ALIGN - 1))
10088
10089 +#ifndef __ASSEMBLY__
10090 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
10091 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
10092 +#endif
10093 +
10094 /* Minimum kernel alignment, as a power of two */
10095 #ifdef CONFIG_X86_64
10096 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
10097 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
10098 index 48f99f1..d78ebf9 100644
10099 --- a/arch/x86/include/asm/cache.h
10100 +++ b/arch/x86/include/asm/cache.h
10101 @@ -5,12 +5,13 @@
10102
10103 /* L1 cache line size */
10104 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
10105 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
10106 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
10107
10108 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
10109 +#define __read_only __attribute__((__section__(".data..read_only")))
10110
10111 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
10112 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
10113 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
10114
10115 #ifdef CONFIG_X86_VSMP
10116 #ifdef CONFIG_SMP
10117 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
10118 index 9863ee3..4a1f8e1 100644
10119 --- a/arch/x86/include/asm/cacheflush.h
10120 +++ b/arch/x86/include/asm/cacheflush.h
10121 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
10122 unsigned long pg_flags = pg->flags & _PGMT_MASK;
10123
10124 if (pg_flags == _PGMT_DEFAULT)
10125 - return -1;
10126 + return ~0UL;
10127 else if (pg_flags == _PGMT_WC)
10128 return _PAGE_CACHE_WC;
10129 else if (pg_flags == _PGMT_UC_MINUS)
10130 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
10131 index 46fc474..b02b0f9 100644
10132 --- a/arch/x86/include/asm/checksum_32.h
10133 +++ b/arch/x86/include/asm/checksum_32.h
10134 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
10135 int len, __wsum sum,
10136 int *src_err_ptr, int *dst_err_ptr);
10137
10138 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
10139 + int len, __wsum sum,
10140 + int *src_err_ptr, int *dst_err_ptr);
10141 +
10142 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
10143 + int len, __wsum sum,
10144 + int *src_err_ptr, int *dst_err_ptr);
10145 +
10146 /*
10147 * Note: when you get a NULL pointer exception here this means someone
10148 * passed in an incorrect kernel address to one of these functions.
10149 @@ -50,7 +58,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
10150 int *err_ptr)
10151 {
10152 might_sleep();
10153 - return csum_partial_copy_generic((__force void *)src, dst,
10154 + return csum_partial_copy_generic_from_user((__force void *)src, dst,
10155 len, sum, err_ptr, NULL);
10156 }
10157
10158 @@ -178,7 +186,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
10159 {
10160 might_sleep();
10161 if (access_ok(VERIFY_WRITE, dst, len))
10162 - return csum_partial_copy_generic(src, (__force void *)dst,
10163 + return csum_partial_copy_generic_to_user(src, (__force void *)dst,
10164 len, sum, NULL, err_ptr);
10165
10166 if (len)
10167 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
10168 index 99480e5..d81165b 100644
10169 --- a/arch/x86/include/asm/cmpxchg.h
10170 +++ b/arch/x86/include/asm/cmpxchg.h
10171 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
10172 __compiletime_error("Bad argument size for cmpxchg");
10173 extern void __xadd_wrong_size(void)
10174 __compiletime_error("Bad argument size for xadd");
10175 +extern void __xadd_check_overflow_wrong_size(void)
10176 + __compiletime_error("Bad argument size for xadd_check_overflow");
10177 extern void __add_wrong_size(void)
10178 __compiletime_error("Bad argument size for add");
10179 +extern void __add_check_overflow_wrong_size(void)
10180 + __compiletime_error("Bad argument size for add_check_overflow");
10181
10182 /*
10183 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
10184 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
10185 __ret; \
10186 })
10187
10188 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
10189 + ({ \
10190 + __typeof__ (*(ptr)) __ret = (arg); \
10191 + switch (sizeof(*(ptr))) { \
10192 + case __X86_CASE_L: \
10193 + asm volatile (lock #op "l %0, %1\n" \
10194 + "jno 0f\n" \
10195 + "mov %0,%1\n" \
10196 + "int $4\n0:\n" \
10197 + _ASM_EXTABLE(0b, 0b) \
10198 + : "+r" (__ret), "+m" (*(ptr)) \
10199 + : : "memory", "cc"); \
10200 + break; \
10201 + case __X86_CASE_Q: \
10202 + asm volatile (lock #op "q %q0, %1\n" \
10203 + "jno 0f\n" \
10204 + "mov %0,%1\n" \
10205 + "int $4\n0:\n" \
10206 + _ASM_EXTABLE(0b, 0b) \
10207 + : "+r" (__ret), "+m" (*(ptr)) \
10208 + : : "memory", "cc"); \
10209 + break; \
10210 + default: \
10211 + __ ## op ## _check_overflow_wrong_size(); \
10212 + } \
10213 + __ret; \
10214 + })
10215 +
10216 /*
10217 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
10218 * Since this is generally used to protect other memory information, we
10219 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
10220 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
10221 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
10222
10223 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
10224 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
10225 +
10226 #define __add(ptr, inc, lock) \
10227 ({ \
10228 __typeof__ (*(ptr)) __ret = (inc); \
10229 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
10230 index f91e80f..7731066 100644
10231 --- a/arch/x86/include/asm/cpufeature.h
10232 +++ b/arch/x86/include/asm/cpufeature.h
10233 @@ -202,11 +202,12 @@
10234 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
10235 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
10236 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
10237 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
10238 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
10239 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
10240 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
10241 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
10242 #define X86_FEATURE_RTM (9*32+11) /* Restricted Transactional Memory */
10243 +#define X86_FEATURE_SMAP (9*32+20) /* Supervisor Mode Access Prevention */
10244
10245 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
10246
10247 @@ -371,7 +372,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
10248 ".section .discard,\"aw\",@progbits\n"
10249 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
10250 ".previous\n"
10251 - ".section .altinstr_replacement,\"ax\"\n"
10252 + ".section .altinstr_replacement,\"a\"\n"
10253 "3: movb $1,%0\n"
10254 "4:\n"
10255 ".previous\n"
10256 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
10257 index 8bf1c06..f723dfd 100644
10258 --- a/arch/x86/include/asm/desc.h
10259 +++ b/arch/x86/include/asm/desc.h
10260 @@ -4,6 +4,7 @@
10261 #include <asm/desc_defs.h>
10262 #include <asm/ldt.h>
10263 #include <asm/mmu.h>
10264 +#include <asm/pgtable.h>
10265
10266 #include <linux/smp.h>
10267 #include <linux/percpu.h>
10268 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10269
10270 desc->type = (info->read_exec_only ^ 1) << 1;
10271 desc->type |= info->contents << 2;
10272 + desc->type |= info->seg_not_present ^ 1;
10273
10274 desc->s = 1;
10275 desc->dpl = 0x3;
10276 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
10277 }
10278
10279 extern struct desc_ptr idt_descr;
10280 -extern gate_desc idt_table[];
10281 extern struct desc_ptr nmi_idt_descr;
10282 -extern gate_desc nmi_idt_table[];
10283 -
10284 -struct gdt_page {
10285 - struct desc_struct gdt[GDT_ENTRIES];
10286 -} __attribute__((aligned(PAGE_SIZE)));
10287 -
10288 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
10289 +extern gate_desc idt_table[256];
10290 +extern gate_desc nmi_idt_table[256];
10291
10292 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
10293 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
10294 {
10295 - return per_cpu(gdt_page, cpu).gdt;
10296 + return cpu_gdt_table[cpu];
10297 }
10298
10299 #ifdef CONFIG_X86_64
10300 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
10301 unsigned long base, unsigned dpl, unsigned flags,
10302 unsigned short seg)
10303 {
10304 - gate->a = (seg << 16) | (base & 0xffff);
10305 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
10306 + gate->gate.offset_low = base;
10307 + gate->gate.seg = seg;
10308 + gate->gate.reserved = 0;
10309 + gate->gate.type = type;
10310 + gate->gate.s = 0;
10311 + gate->gate.dpl = dpl;
10312 + gate->gate.p = 1;
10313 + gate->gate.offset_high = base >> 16;
10314 }
10315
10316 #endif
10317 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
10318
10319 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
10320 {
10321 + pax_open_kernel();
10322 memcpy(&idt[entry], gate, sizeof(*gate));
10323 + pax_close_kernel();
10324 }
10325
10326 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
10327 {
10328 + pax_open_kernel();
10329 memcpy(&ldt[entry], desc, 8);
10330 + pax_close_kernel();
10331 }
10332
10333 static inline void
10334 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
10335 default: size = sizeof(*gdt); break;
10336 }
10337
10338 + pax_open_kernel();
10339 memcpy(&gdt[entry], desc, size);
10340 + pax_close_kernel();
10341 }
10342
10343 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
10344 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
10345
10346 static inline void native_load_tr_desc(void)
10347 {
10348 + pax_open_kernel();
10349 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
10350 + pax_close_kernel();
10351 }
10352
10353 static inline void native_load_gdt(const struct desc_ptr *dtr)
10354 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
10355 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
10356 unsigned int i;
10357
10358 + pax_open_kernel();
10359 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
10360 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
10361 + pax_close_kernel();
10362 }
10363
10364 #define _LDT_empty(info) \
10365 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
10366 }
10367
10368 #ifdef CONFIG_X86_64
10369 -static inline void set_nmi_gate(int gate, void *addr)
10370 +static inline void set_nmi_gate(int gate, const void *addr)
10371 {
10372 gate_desc s;
10373
10374 @@ -320,7 +333,7 @@ static inline void set_nmi_gate(int gate, void *addr)
10375 }
10376 #endif
10377
10378 -static inline void _set_gate(int gate, unsigned type, void *addr,
10379 +static inline void _set_gate(int gate, unsigned type, const void *addr,
10380 unsigned dpl, unsigned ist, unsigned seg)
10381 {
10382 gate_desc s;
10383 @@ -339,7 +352,7 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
10384 * Pentium F0 0F bugfix can have resulted in the mapped
10385 * IDT being write-protected.
10386 */
10387 -static inline void set_intr_gate(unsigned int n, void *addr)
10388 +static inline void set_intr_gate(unsigned int n, const void *addr)
10389 {
10390 BUG_ON((unsigned)n > 0xFF);
10391 _set_gate(n, GATE_INTERRUPT, addr, 0, 0, __KERNEL_CS);
10392 @@ -369,19 +382,19 @@ static inline void alloc_intr_gate(unsigned int n, void *addr)
10393 /*
10394 * This routine sets up an interrupt gate at directory privilege level 3.
10395 */
10396 -static inline void set_system_intr_gate(unsigned int n, void *addr)
10397 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
10398 {
10399 BUG_ON((unsigned)n > 0xFF);
10400 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
10401 }
10402
10403 -static inline void set_system_trap_gate(unsigned int n, void *addr)
10404 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
10405 {
10406 BUG_ON((unsigned)n > 0xFF);
10407 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
10408 }
10409
10410 -static inline void set_trap_gate(unsigned int n, void *addr)
10411 +static inline void set_trap_gate(unsigned int n, const void *addr)
10412 {
10413 BUG_ON((unsigned)n > 0xFF);
10414 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
10415 @@ -390,19 +403,31 @@ static inline void set_trap_gate(unsigned int n, void *addr)
10416 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
10417 {
10418 BUG_ON((unsigned)n > 0xFF);
10419 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
10420 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
10421 }
10422
10423 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
10424 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
10425 {
10426 BUG_ON((unsigned)n > 0xFF);
10427 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
10428 }
10429
10430 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
10431 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
10432 {
10433 BUG_ON((unsigned)n > 0xFF);
10434 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
10435 }
10436
10437 +#ifdef CONFIG_X86_32
10438 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
10439 +{
10440 + struct desc_struct d;
10441 +
10442 + if (likely(limit))
10443 + limit = (limit - 1UL) >> PAGE_SHIFT;
10444 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
10445 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
10446 +}
10447 +#endif
10448 +
10449 #endif /* _ASM_X86_DESC_H */
10450 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
10451 index 278441f..b95a174 100644
10452 --- a/arch/x86/include/asm/desc_defs.h
10453 +++ b/arch/x86/include/asm/desc_defs.h
10454 @@ -31,6 +31,12 @@ struct desc_struct {
10455 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
10456 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
10457 };
10458 + struct {
10459 + u16 offset_low;
10460 + u16 seg;
10461 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
10462 + unsigned offset_high: 16;
10463 + } gate;
10464 };
10465 } __attribute__((packed));
10466
10467 diff --git a/arch/x86/include/asm/e820.h b/arch/x86/include/asm/e820.h
10468 index 3778256..c5d4fce 100644
10469 --- a/arch/x86/include/asm/e820.h
10470 +++ b/arch/x86/include/asm/e820.h
10471 @@ -69,7 +69,7 @@ struct e820map {
10472 #define ISA_START_ADDRESS 0xa0000
10473 #define ISA_END_ADDRESS 0x100000
10474
10475 -#define BIOS_BEGIN 0x000a0000
10476 +#define BIOS_BEGIN 0x000c0000
10477 #define BIOS_END 0x00100000
10478
10479 #define BIOS_ROM_BASE 0xffe00000
10480 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
10481 index 5939f44..f8845f6 100644
10482 --- a/arch/x86/include/asm/elf.h
10483 +++ b/arch/x86/include/asm/elf.h
10484 @@ -243,7 +243,25 @@ extern int force_personality32;
10485 the loader. We need to make sure that it is out of the way of the program
10486 that it will "exec", and that there is sufficient room for the brk. */
10487
10488 +#ifdef CONFIG_PAX_SEGMEXEC
10489 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
10490 +#else
10491 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
10492 +#endif
10493 +
10494 +#ifdef CONFIG_PAX_ASLR
10495 +#ifdef CONFIG_X86_32
10496 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
10497 +
10498 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10499 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
10500 +#else
10501 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
10502 +
10503 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10504 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
10505 +#endif
10506 +#endif
10507
10508 /* This yields a mask that user programs can use to figure out what
10509 instruction set this CPU supports. This could be done in user space,
10510 @@ -296,16 +314,12 @@ do { \
10511
10512 #define ARCH_DLINFO \
10513 do { \
10514 - if (vdso_enabled) \
10515 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10516 - (unsigned long)current->mm->context.vdso); \
10517 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10518 } while (0)
10519
10520 #define ARCH_DLINFO_X32 \
10521 do { \
10522 - if (vdso_enabled) \
10523 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
10524 - (unsigned long)current->mm->context.vdso); \
10525 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
10526 } while (0)
10527
10528 #define AT_SYSINFO 32
10529 @@ -320,7 +334,7 @@ else \
10530
10531 #endif /* !CONFIG_X86_32 */
10532
10533 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
10534 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
10535
10536 #define VDSO_ENTRY \
10537 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
10538 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
10539 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
10540 #define compat_arch_setup_additional_pages syscall32_setup_pages
10541
10542 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
10543 -#define arch_randomize_brk arch_randomize_brk
10544 -
10545 /*
10546 * True on X86_32 or when emulating IA32 on X86_64
10547 */
10548 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
10549 index cc70c1c..d96d011 100644
10550 --- a/arch/x86/include/asm/emergency-restart.h
10551 +++ b/arch/x86/include/asm/emergency-restart.h
10552 @@ -15,6 +15,6 @@ enum reboot_type {
10553
10554 extern enum reboot_type reboot_type;
10555
10556 -extern void machine_emergency_restart(void);
10557 +extern void machine_emergency_restart(void) __noreturn;
10558
10559 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
10560 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
10561 index 75f4c6d..ee3eb8f 100644
10562 --- a/arch/x86/include/asm/fpu-internal.h
10563 +++ b/arch/x86/include/asm/fpu-internal.h
10564 @@ -86,6 +86,11 @@ static inline int fxrstor_checking(struct i387_fxsave_struct *fx)
10565 {
10566 int err;
10567
10568 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10569 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10570 + fx = (struct i387_fxsave_struct __user *)((void *)fx + PAX_USER_SHADOW_BASE);
10571 +#endif
10572 +
10573 /* See comment in fxsave() below. */
10574 #ifdef CONFIG_AS_FXSAVEQ
10575 asm volatile("1: fxrstorq %[fx]\n\t"
10576 @@ -115,6 +120,11 @@ static inline int fxsave_user(struct i387_fxsave_struct __user *fx)
10577 {
10578 int err;
10579
10580 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10581 + if ((unsigned long)fx < PAX_USER_SHADOW_BASE)
10582 + fx = (struct i387_fxsave_struct __user *)((void __user *)fx + PAX_USER_SHADOW_BASE);
10583 +#endif
10584 +
10585 /*
10586 * Clear the bytes not touched by the fxsave and reserved
10587 * for the SW usage.
10588 @@ -271,7 +281,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
10589 "emms\n\t" /* clear stack tags */
10590 "fildl %P[addr]", /* set F?P to defined value */
10591 X86_FEATURE_FXSAVE_LEAK,
10592 - [addr] "m" (tsk->thread.fpu.has_fpu));
10593 + [addr] "m" (init_tss[smp_processor_id()].x86_tss.sp0));
10594
10595 return fpu_restore_checking(&tsk->thread.fpu);
10596 }
10597 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
10598 index 71ecbcb..bac10b7 100644
10599 --- a/arch/x86/include/asm/futex.h
10600 +++ b/arch/x86/include/asm/futex.h
10601 @@ -11,16 +11,18 @@
10602 #include <asm/processor.h>
10603
10604 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
10605 + typecheck(u32 __user *, uaddr); \
10606 asm volatile("1:\t" insn "\n" \
10607 "2:\t.section .fixup,\"ax\"\n" \
10608 "3:\tmov\t%3, %1\n" \
10609 "\tjmp\t2b\n" \
10610 "\t.previous\n" \
10611 _ASM_EXTABLE(1b, 3b) \
10612 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
10613 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr))\
10614 : "i" (-EFAULT), "0" (oparg), "1" (0))
10615
10616 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
10617 + typecheck(u32 __user *, uaddr); \
10618 asm volatile("1:\tmovl %2, %0\n" \
10619 "\tmovl\t%0, %3\n" \
10620 "\t" insn "\n" \
10621 @@ -33,7 +35,7 @@
10622 _ASM_EXTABLE(1b, 4b) \
10623 _ASM_EXTABLE(2b, 4b) \
10624 : "=&a" (oldval), "=&r" (ret), \
10625 - "+m" (*uaddr), "=&r" (tem) \
10626 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
10627 : "r" (oparg), "i" (-EFAULT), "1" (0))
10628
10629 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10630 @@ -60,10 +62,10 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
10631
10632 switch (op) {
10633 case FUTEX_OP_SET:
10634 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
10635 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
10636 break;
10637 case FUTEX_OP_ADD:
10638 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
10639 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
10640 uaddr, oparg);
10641 break;
10642 case FUTEX_OP_OR:
10643 @@ -122,13 +124,13 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
10644 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
10645 return -EFAULT;
10646
10647 - asm volatile("1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
10648 + asm volatile("1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
10649 "2:\t.section .fixup, \"ax\"\n"
10650 "3:\tmov %3, %0\n"
10651 "\tjmp 2b\n"
10652 "\t.previous\n"
10653 _ASM_EXTABLE(1b, 3b)
10654 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
10655 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
10656 : "i" (-EFAULT), "r" (newval), "1" (oldval)
10657 : "memory"
10658 );
10659 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
10660 index eb92a6e..b98b2f4 100644
10661 --- a/arch/x86/include/asm/hw_irq.h
10662 +++ b/arch/x86/include/asm/hw_irq.h
10663 @@ -136,8 +136,8 @@ extern void setup_ioapic_dest(void);
10664 extern void enable_IO_APIC(void);
10665
10666 /* Statistics */
10667 -extern atomic_t irq_err_count;
10668 -extern atomic_t irq_mis_count;
10669 +extern atomic_unchecked_t irq_err_count;
10670 +extern atomic_unchecked_t irq_mis_count;
10671
10672 /* EISA */
10673 extern void eisa_set_level_irq(unsigned int irq);
10674 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
10675 index d8e8eef..99f81ae 100644
10676 --- a/arch/x86/include/asm/io.h
10677 +++ b/arch/x86/include/asm/io.h
10678 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
10679
10680 #include <linux/vmalloc.h>
10681
10682 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
10683 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
10684 +{
10685 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10686 +}
10687 +
10688 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
10689 +{
10690 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
10691 +}
10692 +
10693 /*
10694 * Convert a virtual cached pointer to an uncached pointer
10695 */
10696 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
10697 index bba3cf8..06bc8da 100644
10698 --- a/arch/x86/include/asm/irqflags.h
10699 +++ b/arch/x86/include/asm/irqflags.h
10700 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
10701 sti; \
10702 sysexit
10703
10704 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
10705 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
10706 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
10707 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
10708 +
10709 #else
10710 #define INTERRUPT_RETURN iret
10711 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
10712 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
10713 index 5478825..839e88c 100644
10714 --- a/arch/x86/include/asm/kprobes.h
10715 +++ b/arch/x86/include/asm/kprobes.h
10716 @@ -37,13 +37,8 @@ typedef u8 kprobe_opcode_t;
10717 #define RELATIVEJUMP_SIZE 5
10718 #define RELATIVECALL_OPCODE 0xe8
10719 #define RELATIVE_ADDR_SIZE 4
10720 -#define MAX_STACK_SIZE 64
10721 -#define MIN_STACK_SIZE(ADDR) \
10722 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
10723 - THREAD_SIZE - (unsigned long)(ADDR))) \
10724 - ? (MAX_STACK_SIZE) \
10725 - : (((unsigned long)current_thread_info()) + \
10726 - THREAD_SIZE - (unsigned long)(ADDR)))
10727 +#define MAX_STACK_SIZE 64UL
10728 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
10729
10730 #define flush_insn_slot(p) do { } while (0)
10731
10732 diff --git a/arch/x86/include/asm/kvm_host.h b/arch/x86/include/asm/kvm_host.h
10733 index db7c1f2..92f130a 100644
10734 --- a/arch/x86/include/asm/kvm_host.h
10735 +++ b/arch/x86/include/asm/kvm_host.h
10736 @@ -680,7 +680,7 @@ struct kvm_x86_ops {
10737 int (*check_intercept)(struct kvm_vcpu *vcpu,
10738 struct x86_instruction_info *info,
10739 enum x86_intercept_stage stage);
10740 -};
10741 +} __do_const;
10742
10743 struct kvm_arch_async_pf {
10744 u32 token;
10745 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
10746 index c8bed0d..e5721fa 100644
10747 --- a/arch/x86/include/asm/local.h
10748 +++ b/arch/x86/include/asm/local.h
10749 @@ -17,26 +17,58 @@ typedef struct {
10750
10751 static inline void local_inc(local_t *l)
10752 {
10753 - asm volatile(_ASM_INC "%0"
10754 + asm volatile(_ASM_INC "%0\n"
10755 +
10756 +#ifdef CONFIG_PAX_REFCOUNT
10757 + "jno 0f\n"
10758 + _ASM_DEC "%0\n"
10759 + "int $4\n0:\n"
10760 + _ASM_EXTABLE(0b, 0b)
10761 +#endif
10762 +
10763 : "+m" (l->a.counter));
10764 }
10765
10766 static inline void local_dec(local_t *l)
10767 {
10768 - asm volatile(_ASM_DEC "%0"
10769 + asm volatile(_ASM_DEC "%0\n"
10770 +
10771 +#ifdef CONFIG_PAX_REFCOUNT
10772 + "jno 0f\n"
10773 + _ASM_INC "%0\n"
10774 + "int $4\n0:\n"
10775 + _ASM_EXTABLE(0b, 0b)
10776 +#endif
10777 +
10778 : "+m" (l->a.counter));
10779 }
10780
10781 static inline void local_add(long i, local_t *l)
10782 {
10783 - asm volatile(_ASM_ADD "%1,%0"
10784 + asm volatile(_ASM_ADD "%1,%0\n"
10785 +
10786 +#ifdef CONFIG_PAX_REFCOUNT
10787 + "jno 0f\n"
10788 + _ASM_SUB "%1,%0\n"
10789 + "int $4\n0:\n"
10790 + _ASM_EXTABLE(0b, 0b)
10791 +#endif
10792 +
10793 : "+m" (l->a.counter)
10794 : "ir" (i));
10795 }
10796
10797 static inline void local_sub(long i, local_t *l)
10798 {
10799 - asm volatile(_ASM_SUB "%1,%0"
10800 + asm volatile(_ASM_SUB "%1,%0\n"
10801 +
10802 +#ifdef CONFIG_PAX_REFCOUNT
10803 + "jno 0f\n"
10804 + _ASM_ADD "%1,%0\n"
10805 + "int $4\n0:\n"
10806 + _ASM_EXTABLE(0b, 0b)
10807 +#endif
10808 +
10809 : "+m" (l->a.counter)
10810 : "ir" (i));
10811 }
10812 @@ -54,7 +86,16 @@ static inline int local_sub_and_test(long i, local_t *l)
10813 {
10814 unsigned char c;
10815
10816 - asm volatile(_ASM_SUB "%2,%0; sete %1"
10817 + asm volatile(_ASM_SUB "%2,%0\n"
10818 +
10819 +#ifdef CONFIG_PAX_REFCOUNT
10820 + "jno 0f\n"
10821 + _ASM_ADD "%2,%0\n"
10822 + "int $4\n0:\n"
10823 + _ASM_EXTABLE(0b, 0b)
10824 +#endif
10825 +
10826 + "sete %1\n"
10827 : "+m" (l->a.counter), "=qm" (c)
10828 : "ir" (i) : "memory");
10829 return c;
10830 @@ -72,7 +113,16 @@ static inline int local_dec_and_test(local_t *l)
10831 {
10832 unsigned char c;
10833
10834 - asm volatile(_ASM_DEC "%0; sete %1"
10835 + asm volatile(_ASM_DEC "%0\n"
10836 +
10837 +#ifdef CONFIG_PAX_REFCOUNT
10838 + "jno 0f\n"
10839 + _ASM_INC "%0\n"
10840 + "int $4\n0:\n"
10841 + _ASM_EXTABLE(0b, 0b)
10842 +#endif
10843 +
10844 + "sete %1\n"
10845 : "+m" (l->a.counter), "=qm" (c)
10846 : : "memory");
10847 return c != 0;
10848 @@ -90,7 +140,16 @@ static inline int local_inc_and_test(local_t *l)
10849 {
10850 unsigned char c;
10851
10852 - asm volatile(_ASM_INC "%0; sete %1"
10853 + asm volatile(_ASM_INC "%0\n"
10854 +
10855 +#ifdef CONFIG_PAX_REFCOUNT
10856 + "jno 0f\n"
10857 + _ASM_DEC "%0\n"
10858 + "int $4\n0:\n"
10859 + _ASM_EXTABLE(0b, 0b)
10860 +#endif
10861 +
10862 + "sete %1\n"
10863 : "+m" (l->a.counter), "=qm" (c)
10864 : : "memory");
10865 return c != 0;
10866 @@ -109,7 +168,16 @@ static inline int local_add_negative(long i, local_t *l)
10867 {
10868 unsigned char c;
10869
10870 - asm volatile(_ASM_ADD "%2,%0; sets %1"
10871 + asm volatile(_ASM_ADD "%2,%0\n"
10872 +
10873 +#ifdef CONFIG_PAX_REFCOUNT
10874 + "jno 0f\n"
10875 + _ASM_SUB "%2,%0\n"
10876 + "int $4\n0:\n"
10877 + _ASM_EXTABLE(0b, 0b)
10878 +#endif
10879 +
10880 + "sets %1\n"
10881 : "+m" (l->a.counter), "=qm" (c)
10882 : "ir" (i) : "memory");
10883 return c;
10884 @@ -132,7 +200,15 @@ static inline long local_add_return(long i, local_t *l)
10885 #endif
10886 /* Modern 486+ processor */
10887 __i = i;
10888 - asm volatile(_ASM_XADD "%0, %1;"
10889 + asm volatile(_ASM_XADD "%0, %1\n"
10890 +
10891 +#ifdef CONFIG_PAX_REFCOUNT
10892 + "jno 0f\n"
10893 + _ASM_MOV "%0,%1\n"
10894 + "int $4\n0:\n"
10895 + _ASM_EXTABLE(0b, 0b)
10896 +#endif
10897 +
10898 : "+r" (i), "+m" (l->a.counter)
10899 : : "memory");
10900 return i + __i;
10901 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
10902 index 593e51d..fa69c9a 100644
10903 --- a/arch/x86/include/asm/mman.h
10904 +++ b/arch/x86/include/asm/mman.h
10905 @@ -5,4 +5,14 @@
10906
10907 #include <asm-generic/mman.h>
10908
10909 +#ifdef __KERNEL__
10910 +#ifndef __ASSEMBLY__
10911 +#ifdef CONFIG_X86_32
10912 +#define arch_mmap_check i386_mmap_check
10913 +int i386_mmap_check(unsigned long addr, unsigned long len,
10914 + unsigned long flags);
10915 +#endif
10916 +#endif
10917 +#endif
10918 +
10919 #endif /* _ASM_X86_MMAN_H */
10920 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
10921 index 5f55e69..e20bfb1 100644
10922 --- a/arch/x86/include/asm/mmu.h
10923 +++ b/arch/x86/include/asm/mmu.h
10924 @@ -9,7 +9,7 @@
10925 * we put the segment information here.
10926 */
10927 typedef struct {
10928 - void *ldt;
10929 + struct desc_struct *ldt;
10930 int size;
10931
10932 #ifdef CONFIG_X86_64
10933 @@ -18,7 +18,19 @@ typedef struct {
10934 #endif
10935
10936 struct mutex lock;
10937 - void *vdso;
10938 + unsigned long vdso;
10939 +
10940 +#ifdef CONFIG_X86_32
10941 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
10942 + unsigned long user_cs_base;
10943 + unsigned long user_cs_limit;
10944 +
10945 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
10946 + cpumask_t cpu_user_cs_mask;
10947 +#endif
10948 +
10949 +#endif
10950 +#endif
10951 } mm_context_t;
10952
10953 #ifdef CONFIG_SMP
10954 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
10955 index cdbf367..adb37ac 100644
10956 --- a/arch/x86/include/asm/mmu_context.h
10957 +++ b/arch/x86/include/asm/mmu_context.h
10958 @@ -24,6 +24,18 @@ void destroy_context(struct mm_struct *mm);
10959
10960 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
10961 {
10962 +
10963 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
10964 + unsigned int i;
10965 + pgd_t *pgd;
10966 +
10967 + pax_open_kernel();
10968 + pgd = get_cpu_pgd(smp_processor_id());
10969 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
10970 + set_pgd_batched(pgd+i, native_make_pgd(0));
10971 + pax_close_kernel();
10972 +#endif
10973 +
10974 #ifdef CONFIG_SMP
10975 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
10976 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
10977 @@ -34,16 +46,30 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
10978 struct task_struct *tsk)
10979 {
10980 unsigned cpu = smp_processor_id();
10981 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10982 + int tlbstate = TLBSTATE_OK;
10983 +#endif
10984
10985 if (likely(prev != next)) {
10986 #ifdef CONFIG_SMP
10987 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
10988 + tlbstate = this_cpu_read(cpu_tlbstate.state);
10989 +#endif
10990 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
10991 this_cpu_write(cpu_tlbstate.active_mm, next);
10992 #endif
10993 cpumask_set_cpu(cpu, mm_cpumask(next));
10994
10995 /* Re-load page tables */
10996 +#ifdef CONFIG_PAX_PER_CPU_PGD
10997 + pax_open_kernel();
10998 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
10999 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11000 + pax_close_kernel();
11001 + load_cr3(get_cpu_pgd(cpu));
11002 +#else
11003 load_cr3(next->pgd);
11004 +#endif
11005
11006 /* stop flush ipis for the previous mm */
11007 cpumask_clear_cpu(cpu, mm_cpumask(prev));
11008 @@ -53,9 +79,38 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11009 */
11010 if (unlikely(prev->context.ldt != next->context.ldt))
11011 load_LDT_nolock(&next->context);
11012 - }
11013 +
11014 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
11015 + if (!(__supported_pte_mask & _PAGE_NX)) {
11016 + smp_mb__before_clear_bit();
11017 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
11018 + smp_mb__after_clear_bit();
11019 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11020 + }
11021 +#endif
11022 +
11023 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11024 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
11025 + prev->context.user_cs_limit != next->context.user_cs_limit))
11026 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11027 #ifdef CONFIG_SMP
11028 + else if (unlikely(tlbstate != TLBSTATE_OK))
11029 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11030 +#endif
11031 +#endif
11032 +
11033 + }
11034 else {
11035 +
11036 +#ifdef CONFIG_PAX_PER_CPU_PGD
11037 + pax_open_kernel();
11038 + __clone_user_pgds(get_cpu_pgd(cpu), next->pgd);
11039 + __shadow_user_pgds(get_cpu_pgd(cpu) + USER_PGD_PTRS, next->pgd);
11040 + pax_close_kernel();
11041 + load_cr3(get_cpu_pgd(cpu));
11042 +#endif
11043 +
11044 +#ifdef CONFIG_SMP
11045 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
11046 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
11047
11048 @@ -64,11 +119,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
11049 * tlb flush IPI delivery. We must reload CR3
11050 * to make sure to use no freed page tables.
11051 */
11052 +
11053 +#ifndef CONFIG_PAX_PER_CPU_PGD
11054 load_cr3(next->pgd);
11055 +#endif
11056 +
11057 load_LDT_nolock(&next->context);
11058 +
11059 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
11060 + if (!(__supported_pte_mask & _PAGE_NX))
11061 + cpu_set(cpu, next->context.cpu_user_cs_mask);
11062 +#endif
11063 +
11064 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
11065 +#ifdef CONFIG_PAX_PAGEEXEC
11066 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
11067 +#endif
11068 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
11069 +#endif
11070 +
11071 }
11072 +#endif
11073 }
11074 -#endif
11075 }
11076
11077 #define activate_mm(prev, next) \
11078 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
11079 index 9eae775..c914fea 100644
11080 --- a/arch/x86/include/asm/module.h
11081 +++ b/arch/x86/include/asm/module.h
11082 @@ -5,6 +5,7 @@
11083
11084 #ifdef CONFIG_X86_64
11085 /* X86_64 does not define MODULE_PROC_FAMILY */
11086 +#define MODULE_PROC_FAMILY ""
11087 #elif defined CONFIG_M386
11088 #define MODULE_PROC_FAMILY "386 "
11089 #elif defined CONFIG_M486
11090 @@ -59,8 +60,20 @@
11091 #error unknown processor family
11092 #endif
11093
11094 -#ifdef CONFIG_X86_32
11095 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
11096 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
11097 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
11098 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
11099 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
11100 +#else
11101 +#define MODULE_PAX_KERNEXEC ""
11102 #endif
11103
11104 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11105 +#define MODULE_PAX_UDEREF "UDEREF "
11106 +#else
11107 +#define MODULE_PAX_UDEREF ""
11108 +#endif
11109 +
11110 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
11111 +
11112 #endif /* _ASM_X86_MODULE_H */
11113 diff --git a/arch/x86/include/asm/page_64_types.h b/arch/x86/include/asm/page_64_types.h
11114 index 320f7bb..e89f8f8 100644
11115 --- a/arch/x86/include/asm/page_64_types.h
11116 +++ b/arch/x86/include/asm/page_64_types.h
11117 @@ -56,7 +56,7 @@ void copy_page(void *to, void *from);
11118
11119 /* duplicated to the one in bootmem.h */
11120 extern unsigned long max_pfn;
11121 -extern unsigned long phys_base;
11122 +extern const unsigned long phys_base;
11123
11124 extern unsigned long __phys_addr(unsigned long);
11125 #define __phys_reloc_hide(x) (x)
11126 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
11127 index 6cbbabf..11b3aed 100644
11128 --- a/arch/x86/include/asm/paravirt.h
11129 +++ b/arch/x86/include/asm/paravirt.h
11130 @@ -668,6 +668,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
11131 val);
11132 }
11133
11134 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11135 +{
11136 + pgdval_t val = native_pgd_val(pgd);
11137 +
11138 + if (sizeof(pgdval_t) > sizeof(long))
11139 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
11140 + val, (u64)val >> 32);
11141 + else
11142 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
11143 + val);
11144 +}
11145 +
11146 static inline void pgd_clear(pgd_t *pgdp)
11147 {
11148 set_pgd(pgdp, __pgd(0));
11149 @@ -749,6 +761,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
11150 pv_mmu_ops.set_fixmap(idx, phys, flags);
11151 }
11152
11153 +#ifdef CONFIG_PAX_KERNEXEC
11154 +static inline unsigned long pax_open_kernel(void)
11155 +{
11156 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
11157 +}
11158 +
11159 +static inline unsigned long pax_close_kernel(void)
11160 +{
11161 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
11162 +}
11163 +#else
11164 +static inline unsigned long pax_open_kernel(void) { return 0; }
11165 +static inline unsigned long pax_close_kernel(void) { return 0; }
11166 +#endif
11167 +
11168 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
11169
11170 static inline int arch_spin_is_locked(struct arch_spinlock *lock)
11171 @@ -965,7 +992,7 @@ extern void default_banner(void);
11172
11173 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
11174 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
11175 -#define PARA_INDIRECT(addr) *%cs:addr
11176 +#define PARA_INDIRECT(addr) *%ss:addr
11177 #endif
11178
11179 #define INTERRUPT_RETURN \
11180 @@ -1040,6 +1067,21 @@ extern void default_banner(void);
11181 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
11182 CLBR_NONE, \
11183 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
11184 +
11185 +#define GET_CR0_INTO_RDI \
11186 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
11187 + mov %rax,%rdi
11188 +
11189 +#define SET_RDI_INTO_CR0 \
11190 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
11191 +
11192 +#define GET_CR3_INTO_RDI \
11193 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
11194 + mov %rax,%rdi
11195 +
11196 +#define SET_RDI_INTO_CR3 \
11197 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
11198 +
11199 #endif /* CONFIG_X86_32 */
11200
11201 #endif /* __ASSEMBLY__ */
11202 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
11203 index 8e8b9a4..f07d725 100644
11204 --- a/arch/x86/include/asm/paravirt_types.h
11205 +++ b/arch/x86/include/asm/paravirt_types.h
11206 @@ -84,20 +84,20 @@ struct pv_init_ops {
11207 */
11208 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
11209 unsigned long addr, unsigned len);
11210 -};
11211 +} __no_const;
11212
11213
11214 struct pv_lazy_ops {
11215 /* Set deferred update mode, used for batching operations. */
11216 void (*enter)(void);
11217 void (*leave)(void);
11218 -};
11219 +} __no_const;
11220
11221 struct pv_time_ops {
11222 unsigned long long (*sched_clock)(void);
11223 unsigned long long (*steal_clock)(int cpu);
11224 unsigned long (*get_tsc_khz)(void);
11225 -};
11226 +} __no_const;
11227
11228 struct pv_cpu_ops {
11229 /* hooks for various privileged instructions */
11230 @@ -193,7 +193,7 @@ struct pv_cpu_ops {
11231
11232 void (*start_context_switch)(struct task_struct *prev);
11233 void (*end_context_switch)(struct task_struct *next);
11234 -};
11235 +} __no_const;
11236
11237 struct pv_irq_ops {
11238 /*
11239 @@ -224,7 +224,7 @@ struct pv_apic_ops {
11240 unsigned long start_eip,
11241 unsigned long start_esp);
11242 #endif
11243 -};
11244 +} __no_const;
11245
11246 struct pv_mmu_ops {
11247 unsigned long (*read_cr2)(void);
11248 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
11249 struct paravirt_callee_save make_pud;
11250
11251 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
11252 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
11253 #endif /* PAGETABLE_LEVELS == 4 */
11254 #endif /* PAGETABLE_LEVELS >= 3 */
11255
11256 @@ -324,6 +325,12 @@ struct pv_mmu_ops {
11257 an mfn. We can tell which is which from the index. */
11258 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
11259 phys_addr_t phys, pgprot_t flags);
11260 +
11261 +#ifdef CONFIG_PAX_KERNEXEC
11262 + unsigned long (*pax_open_kernel)(void);
11263 + unsigned long (*pax_close_kernel)(void);
11264 +#endif
11265 +
11266 };
11267
11268 struct arch_spinlock;
11269 @@ -334,7 +341,7 @@ struct pv_lock_ops {
11270 void (*spin_lock_flags)(struct arch_spinlock *lock, unsigned long flags);
11271 int (*spin_trylock)(struct arch_spinlock *lock);
11272 void (*spin_unlock)(struct arch_spinlock *lock);
11273 -};
11274 +} __no_const;
11275
11276 /* This contains all the paravirt structures: we get a convenient
11277 * number for each function using the offset which we use to indicate
11278 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
11279 index b4389a4..7024269 100644
11280 --- a/arch/x86/include/asm/pgalloc.h
11281 +++ b/arch/x86/include/asm/pgalloc.h
11282 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
11283 pmd_t *pmd, pte_t *pte)
11284 {
11285 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11286 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
11287 +}
11288 +
11289 +static inline void pmd_populate_user(struct mm_struct *mm,
11290 + pmd_t *pmd, pte_t *pte)
11291 +{
11292 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
11293 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
11294 }
11295
11296 @@ -99,12 +106,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
11297
11298 #ifdef CONFIG_X86_PAE
11299 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
11300 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
11301 +{
11302 + pud_populate(mm, pudp, pmd);
11303 +}
11304 #else /* !CONFIG_X86_PAE */
11305 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11306 {
11307 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11308 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
11309 }
11310 +
11311 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
11312 +{
11313 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
11314 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
11315 +}
11316 #endif /* CONFIG_X86_PAE */
11317
11318 #if PAGETABLE_LEVELS > 3
11319 @@ -114,6 +131,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11320 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
11321 }
11322
11323 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
11324 +{
11325 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
11326 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
11327 +}
11328 +
11329 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
11330 {
11331 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
11332 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
11333 index 98391db..8f6984e 100644
11334 --- a/arch/x86/include/asm/pgtable-2level.h
11335 +++ b/arch/x86/include/asm/pgtable-2level.h
11336 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
11337
11338 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11339 {
11340 + pax_open_kernel();
11341 *pmdp = pmd;
11342 + pax_close_kernel();
11343 }
11344
11345 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11346 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
11347 index cb00ccc..17e9054 100644
11348 --- a/arch/x86/include/asm/pgtable-3level.h
11349 +++ b/arch/x86/include/asm/pgtable-3level.h
11350 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11351
11352 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11353 {
11354 + pax_open_kernel();
11355 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
11356 + pax_close_kernel();
11357 }
11358
11359 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11360 {
11361 + pax_open_kernel();
11362 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
11363 + pax_close_kernel();
11364 }
11365
11366 /*
11367 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
11368 index 49afb3f..91a8c63 100644
11369 --- a/arch/x86/include/asm/pgtable.h
11370 +++ b/arch/x86/include/asm/pgtable.h
11371 @@ -44,6 +44,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11372
11373 #ifndef __PAGETABLE_PUD_FOLDED
11374 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
11375 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
11376 #define pgd_clear(pgd) native_pgd_clear(pgd)
11377 #endif
11378
11379 @@ -81,12 +82,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
11380
11381 #define arch_end_context_switch(prev) do {} while(0)
11382
11383 +#define pax_open_kernel() native_pax_open_kernel()
11384 +#define pax_close_kernel() native_pax_close_kernel()
11385 #endif /* CONFIG_PARAVIRT */
11386
11387 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
11388 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
11389 +
11390 +#ifdef CONFIG_PAX_KERNEXEC
11391 +static inline unsigned long native_pax_open_kernel(void)
11392 +{
11393 + unsigned long cr0;
11394 +
11395 + preempt_disable();
11396 + barrier();
11397 + cr0 = read_cr0() ^ X86_CR0_WP;
11398 + BUG_ON(unlikely(cr0 & X86_CR0_WP));
11399 + write_cr0(cr0);
11400 + return cr0 ^ X86_CR0_WP;
11401 +}
11402 +
11403 +static inline unsigned long native_pax_close_kernel(void)
11404 +{
11405 + unsigned long cr0;
11406 +
11407 + cr0 = read_cr0() ^ X86_CR0_WP;
11408 + BUG_ON(unlikely(!(cr0 & X86_CR0_WP)));
11409 + write_cr0(cr0);
11410 + barrier();
11411 + preempt_enable_no_resched();
11412 + return cr0 ^ X86_CR0_WP;
11413 +}
11414 +#else
11415 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
11416 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
11417 +#endif
11418 +
11419 /*
11420 * The following only work if pte_present() is true.
11421 * Undefined behaviour if not..
11422 */
11423 +static inline int pte_user(pte_t pte)
11424 +{
11425 + return pte_val(pte) & _PAGE_USER;
11426 +}
11427 +
11428 static inline int pte_dirty(pte_t pte)
11429 {
11430 return pte_flags(pte) & _PAGE_DIRTY;
11431 @@ -196,9 +236,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
11432 return pte_clear_flags(pte, _PAGE_RW);
11433 }
11434
11435 +static inline pte_t pte_mkread(pte_t pte)
11436 +{
11437 + return __pte(pte_val(pte) | _PAGE_USER);
11438 +}
11439 +
11440 static inline pte_t pte_mkexec(pte_t pte)
11441 {
11442 - return pte_clear_flags(pte, _PAGE_NX);
11443 +#ifdef CONFIG_X86_PAE
11444 + if (__supported_pte_mask & _PAGE_NX)
11445 + return pte_clear_flags(pte, _PAGE_NX);
11446 + else
11447 +#endif
11448 + return pte_set_flags(pte, _PAGE_USER);
11449 +}
11450 +
11451 +static inline pte_t pte_exprotect(pte_t pte)
11452 +{
11453 +#ifdef CONFIG_X86_PAE
11454 + if (__supported_pte_mask & _PAGE_NX)
11455 + return pte_set_flags(pte, _PAGE_NX);
11456 + else
11457 +#endif
11458 + return pte_clear_flags(pte, _PAGE_USER);
11459 }
11460
11461 static inline pte_t pte_mkdirty(pte_t pte)
11462 @@ -390,6 +450,15 @@ pte_t *populate_extra_pte(unsigned long vaddr);
11463 #endif
11464
11465 #ifndef __ASSEMBLY__
11466 +
11467 +#ifdef CONFIG_PAX_PER_CPU_PGD
11468 +extern pgd_t cpu_pgd[NR_CPUS][PTRS_PER_PGD];
11469 +static inline pgd_t *get_cpu_pgd(unsigned int cpu)
11470 +{
11471 + return cpu_pgd[cpu];
11472 +}
11473 +#endif
11474 +
11475 #include <linux/mm_types.h>
11476
11477 static inline int pte_none(pte_t pte)
11478 @@ -560,7 +629,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
11479
11480 static inline int pgd_bad(pgd_t pgd)
11481 {
11482 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
11483 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
11484 }
11485
11486 static inline int pgd_none(pgd_t pgd)
11487 @@ -583,7 +652,12 @@ static inline int pgd_none(pgd_t pgd)
11488 * pgd_offset() returns a (pgd_t *)
11489 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
11490 */
11491 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
11492 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
11493 +
11494 +#ifdef CONFIG_PAX_PER_CPU_PGD
11495 +#define pgd_offset_cpu(cpu, address) (get_cpu_pgd(cpu) + pgd_index(address))
11496 +#endif
11497 +
11498 /*
11499 * a shortcut which implies the use of the kernel's pgd, instead
11500 * of a process's
11501 @@ -594,6 +668,20 @@ static inline int pgd_none(pgd_t pgd)
11502 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
11503 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
11504
11505 +#ifdef CONFIG_X86_32
11506 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
11507 +#else
11508 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
11509 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
11510 +
11511 +#ifdef CONFIG_PAX_MEMORY_UDEREF
11512 +#define PAX_USER_SHADOW_BASE (_AC(1,UL) << TASK_SIZE_MAX_SHIFT)
11513 +#else
11514 +#define PAX_USER_SHADOW_BASE (_AC(0,UL))
11515 +#endif
11516 +
11517 +#endif
11518 +
11519 #ifndef __ASSEMBLY__
11520
11521 extern int direct_gbpages;
11522 @@ -758,11 +846,23 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
11523 * dst and src can be on the same page, but the range must not overlap,
11524 * and must not cross a page boundary.
11525 */
11526 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
11527 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
11528 {
11529 - memcpy(dst, src, count * sizeof(pgd_t));
11530 + pax_open_kernel();
11531 + while (count--)
11532 + *dst++ = *src++;
11533 + pax_close_kernel();
11534 }
11535
11536 +#ifdef CONFIG_PAX_PER_CPU_PGD
11537 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
11538 +#endif
11539 +
11540 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
11541 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
11542 +#else
11543 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
11544 +#endif
11545
11546 #include <asm-generic/pgtable.h>
11547 #endif /* __ASSEMBLY__ */
11548 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
11549 index 0c92113..34a77c6 100644
11550 --- a/arch/x86/include/asm/pgtable_32.h
11551 +++ b/arch/x86/include/asm/pgtable_32.h
11552 @@ -25,9 +25,6 @@
11553 struct mm_struct;
11554 struct vm_area_struct;
11555
11556 -extern pgd_t swapper_pg_dir[1024];
11557 -extern pgd_t initial_page_table[1024];
11558 -
11559 static inline void pgtable_cache_init(void) { }
11560 static inline void check_pgt_cache(void) { }
11561 void paging_init(void);
11562 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11563 # include <asm/pgtable-2level.h>
11564 #endif
11565
11566 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
11567 +extern pgd_t initial_page_table[PTRS_PER_PGD];
11568 +#ifdef CONFIG_X86_PAE
11569 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
11570 +#endif
11571 +
11572 #if defined(CONFIG_HIGHPTE)
11573 #define pte_offset_map(dir, address) \
11574 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
11575 @@ -62,7 +65,9 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
11576 /* Clear a kernel PTE and flush it from the TLB */
11577 #define kpte_clear_flush(ptep, vaddr) \
11578 do { \
11579 + pax_open_kernel(); \
11580 pte_clear(&init_mm, (vaddr), (ptep)); \
11581 + pax_close_kernel(); \
11582 __flush_tlb_one((vaddr)); \
11583 } while (0)
11584
11585 @@ -74,6 +79,9 @@ do { \
11586
11587 #endif /* !__ASSEMBLY__ */
11588
11589 +#define HAVE_ARCH_UNMAPPED_AREA
11590 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
11591 +
11592 /*
11593 * kern_addr_valid() is (1) for FLATMEM and (0) for
11594 * SPARSEMEM and DISCONTIGMEM
11595 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
11596 index ed5903b..c7fe163 100644
11597 --- a/arch/x86/include/asm/pgtable_32_types.h
11598 +++ b/arch/x86/include/asm/pgtable_32_types.h
11599 @@ -8,7 +8,7 @@
11600 */
11601 #ifdef CONFIG_X86_PAE
11602 # include <asm/pgtable-3level_types.h>
11603 -# define PMD_SIZE (1UL << PMD_SHIFT)
11604 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
11605 # define PMD_MASK (~(PMD_SIZE - 1))
11606 #else
11607 # include <asm/pgtable-2level_types.h>
11608 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
11609 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
11610 #endif
11611
11612 +#ifdef CONFIG_PAX_KERNEXEC
11613 +#ifndef __ASSEMBLY__
11614 +extern unsigned char MODULES_EXEC_VADDR[];
11615 +extern unsigned char MODULES_EXEC_END[];
11616 +#endif
11617 +#include <asm/boot.h>
11618 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
11619 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
11620 +#else
11621 +#define ktla_ktva(addr) (addr)
11622 +#define ktva_ktla(addr) (addr)
11623 +#endif
11624 +
11625 #define MODULES_VADDR VMALLOC_START
11626 #define MODULES_END VMALLOC_END
11627 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
11628 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
11629 index 975f709..9f779c9 100644
11630 --- a/arch/x86/include/asm/pgtable_64.h
11631 +++ b/arch/x86/include/asm/pgtable_64.h
11632 @@ -16,10 +16,14 @@
11633
11634 extern pud_t level3_kernel_pgt[512];
11635 extern pud_t level3_ident_pgt[512];
11636 +extern pud_t level3_vmalloc_start_pgt[512];
11637 +extern pud_t level3_vmalloc_end_pgt[512];
11638 +extern pud_t level3_vmemmap_pgt[512];
11639 +extern pud_t level2_vmemmap_pgt[512];
11640 extern pmd_t level2_kernel_pgt[512];
11641 extern pmd_t level2_fixmap_pgt[512];
11642 -extern pmd_t level2_ident_pgt[512];
11643 -extern pgd_t init_level4_pgt[];
11644 +extern pmd_t level2_ident_pgt[512*2];
11645 +extern pgd_t init_level4_pgt[512];
11646
11647 #define swapper_pg_dir init_level4_pgt
11648
11649 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
11650
11651 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
11652 {
11653 + pax_open_kernel();
11654 *pmdp = pmd;
11655 + pax_close_kernel();
11656 }
11657
11658 static inline void native_pmd_clear(pmd_t *pmd)
11659 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
11660
11661 static inline void native_set_pud(pud_t *pudp, pud_t pud)
11662 {
11663 + pax_open_kernel();
11664 *pudp = pud;
11665 + pax_close_kernel();
11666 }
11667
11668 static inline void native_pud_clear(pud_t *pud)
11669 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
11670
11671 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
11672 {
11673 + pax_open_kernel();
11674 + *pgdp = pgd;
11675 + pax_close_kernel();
11676 +}
11677 +
11678 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
11679 +{
11680 *pgdp = pgd;
11681 }
11682
11683 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
11684 index 766ea16..5b96cb3 100644
11685 --- a/arch/x86/include/asm/pgtable_64_types.h
11686 +++ b/arch/x86/include/asm/pgtable_64_types.h
11687 @@ -59,5 +59,10 @@ typedef struct { pteval_t pte; } pte_t;
11688 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
11689 #define MODULES_END _AC(0xffffffffff000000, UL)
11690 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
11691 +#define MODULES_EXEC_VADDR MODULES_VADDR
11692 +#define MODULES_EXEC_END MODULES_END
11693 +
11694 +#define ktla_ktva(addr) (addr)
11695 +#define ktva_ktla(addr) (addr)
11696
11697 #endif /* _ASM_X86_PGTABLE_64_DEFS_H */
11698 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
11699 index 013286a..8b42f4f 100644
11700 --- a/arch/x86/include/asm/pgtable_types.h
11701 +++ b/arch/x86/include/asm/pgtable_types.h
11702 @@ -16,13 +16,12 @@
11703 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
11704 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
11705 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
11706 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
11707 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
11708 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
11709 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
11710 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
11711 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
11712 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
11713 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
11714 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
11715 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
11716 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
11717
11718 /* If _PAGE_BIT_PRESENT is clear, we use these: */
11719 @@ -40,7 +39,6 @@
11720 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
11721 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
11722 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
11723 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
11724 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
11725 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
11726 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
11727 @@ -57,8 +55,10 @@
11728
11729 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
11730 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
11731 -#else
11732 +#elif defined(CONFIG_KMEMCHECK)
11733 #define _PAGE_NX (_AT(pteval_t, 0))
11734 +#else
11735 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
11736 #endif
11737
11738 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
11739 @@ -96,6 +96,9 @@
11740 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
11741 _PAGE_ACCESSED)
11742
11743 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
11744 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
11745 +
11746 #define __PAGE_KERNEL_EXEC \
11747 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
11748 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
11749 @@ -106,7 +109,7 @@
11750 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
11751 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
11752 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
11753 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
11754 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
11755 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
11756 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
11757 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
11758 @@ -168,8 +171,8 @@
11759 * bits are combined, this will alow user to access the high address mapped
11760 * VDSO in the presence of CONFIG_COMPAT_VDSO
11761 */
11762 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
11763 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
11764 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11765 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
11766 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
11767 #endif
11768
11769 @@ -207,7 +210,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
11770 {
11771 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
11772 }
11773 +#endif
11774
11775 +#if PAGETABLE_LEVELS == 3
11776 +#include <asm-generic/pgtable-nopud.h>
11777 +#endif
11778 +
11779 +#if PAGETABLE_LEVELS == 2
11780 +#include <asm-generic/pgtable-nopmd.h>
11781 +#endif
11782 +
11783 +#ifndef __ASSEMBLY__
11784 #if PAGETABLE_LEVELS > 3
11785 typedef struct { pudval_t pud; } pud_t;
11786
11787 @@ -221,8 +234,6 @@ static inline pudval_t native_pud_val(pud_t pud)
11788 return pud.pud;
11789 }
11790 #else
11791 -#include <asm-generic/pgtable-nopud.h>
11792 -
11793 static inline pudval_t native_pud_val(pud_t pud)
11794 {
11795 return native_pgd_val(pud.pgd);
11796 @@ -242,8 +253,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
11797 return pmd.pmd;
11798 }
11799 #else
11800 -#include <asm-generic/pgtable-nopmd.h>
11801 -
11802 static inline pmdval_t native_pmd_val(pmd_t pmd)
11803 {
11804 return native_pgd_val(pmd.pud.pgd);
11805 @@ -283,7 +292,6 @@ typedef struct page *pgtable_t;
11806
11807 extern pteval_t __supported_pte_mask;
11808 extern void set_nx(void);
11809 -extern int nx_enabled;
11810
11811 #define pgprot_writecombine pgprot_writecombine
11812 extern pgprot_t pgprot_writecombine(pgprot_t prot);
11813 diff --git a/arch/x86/include/asm/processor-flags.h b/arch/x86/include/asm/processor-flags.h
11814 index f8ab3ea..67889db 100644
11815 --- a/arch/x86/include/asm/processor-flags.h
11816 +++ b/arch/x86/include/asm/processor-flags.h
11817 @@ -63,6 +63,7 @@
11818 #define X86_CR4_RDWRGSFS 0x00010000 /* enable RDWRGSFS support */
11819 #define X86_CR4_OSXSAVE 0x00040000 /* enable xsave and xrestore */
11820 #define X86_CR4_SMEP 0x00100000 /* enable SMEP support */
11821 +#define X86_CR4_SMAP 0x00200000 /* enable SMAP support */
11822
11823 /*
11824 * x86-64 Task Priority Register, CR8
11825 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
11826 index 39bc577..538233f 100644
11827 --- a/arch/x86/include/asm/processor.h
11828 +++ b/arch/x86/include/asm/processor.h
11829 @@ -276,7 +276,7 @@ struct tss_struct {
11830
11831 } ____cacheline_aligned;
11832
11833 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
11834 +extern struct tss_struct init_tss[NR_CPUS];
11835
11836 /*
11837 * Save the original ist values for checking stack pointers during debugging
11838 @@ -809,11 +809,18 @@ static inline void spin_lock_prefetch(const void *x)
11839 */
11840 #define TASK_SIZE PAGE_OFFSET
11841 #define TASK_SIZE_MAX TASK_SIZE
11842 +
11843 +#ifdef CONFIG_PAX_SEGMEXEC
11844 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
11845 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
11846 +#else
11847 #define STACK_TOP TASK_SIZE
11848 -#define STACK_TOP_MAX STACK_TOP
11849 +#endif
11850 +
11851 +#define STACK_TOP_MAX TASK_SIZE
11852
11853 #define INIT_THREAD { \
11854 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11855 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11856 .vm86_info = NULL, \
11857 .sysenter_cs = __KERNEL_CS, \
11858 .io_bitmap_ptr = NULL, \
11859 @@ -827,7 +834,7 @@ static inline void spin_lock_prefetch(const void *x)
11860 */
11861 #define INIT_TSS { \
11862 .x86_tss = { \
11863 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
11864 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
11865 .ss0 = __KERNEL_DS, \
11866 .ss1 = __KERNEL_CS, \
11867 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
11868 @@ -838,11 +845,7 @@ static inline void spin_lock_prefetch(const void *x)
11869 extern unsigned long thread_saved_pc(struct task_struct *tsk);
11870
11871 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
11872 -#define KSTK_TOP(info) \
11873 -({ \
11874 - unsigned long *__ptr = (unsigned long *)(info); \
11875 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
11876 -})
11877 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
11878
11879 /*
11880 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
11881 @@ -857,7 +860,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11882 #define task_pt_regs(task) \
11883 ({ \
11884 struct pt_regs *__regs__; \
11885 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
11886 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
11887 __regs__ - 1; \
11888 })
11889
11890 @@ -867,13 +870,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11891 /*
11892 * User space process size. 47bits minus one guard page.
11893 */
11894 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
11895 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
11896
11897 /* This decides where the kernel will search for a free chunk of vm
11898 * space during mmap's.
11899 */
11900 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
11901 - 0xc0000000 : 0xFFFFe000)
11902 + 0xc0000000 : 0xFFFFf000)
11903
11904 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
11905 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
11906 @@ -884,11 +887,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
11907 #define STACK_TOP_MAX TASK_SIZE_MAX
11908
11909 #define INIT_THREAD { \
11910 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11911 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11912 }
11913
11914 #define INIT_TSS { \
11915 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
11916 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
11917 }
11918
11919 /*
11920 @@ -916,6 +919,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
11921 */
11922 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
11923
11924 +#ifdef CONFIG_PAX_SEGMEXEC
11925 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
11926 +#endif
11927 +
11928 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
11929
11930 /* Get/set a process' ability to use the timestamp counter instruction */
11931 @@ -976,12 +983,12 @@ extern bool cpu_has_amd_erratum(const int *);
11932 #define cpu_has_amd_erratum(x) (false)
11933 #endif /* CONFIG_CPU_SUP_AMD */
11934
11935 -extern unsigned long arch_align_stack(unsigned long sp);
11936 +#define arch_align_stack(x) ((x) & ~0xfUL)
11937 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
11938
11939 void default_idle(void);
11940 bool set_pm_idle_to_default(void);
11941
11942 -void stop_this_cpu(void *dummy);
11943 +void stop_this_cpu(void *dummy) __noreturn;
11944
11945 #endif /* _ASM_X86_PROCESSOR_H */
11946 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
11947 index dcfde52..dbfea06 100644
11948 --- a/arch/x86/include/asm/ptrace.h
11949 +++ b/arch/x86/include/asm/ptrace.h
11950 @@ -155,28 +155,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
11951 }
11952
11953 /*
11954 - * user_mode_vm(regs) determines whether a register set came from user mode.
11955 + * user_mode(regs) determines whether a register set came from user mode.
11956 * This is true if V8086 mode was enabled OR if the register set was from
11957 * protected mode with RPL-3 CS value. This tricky test checks that with
11958 * one comparison. Many places in the kernel can bypass this full check
11959 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
11960 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
11961 + * be used.
11962 */
11963 -static inline int user_mode(struct pt_regs *regs)
11964 +static inline int user_mode_novm(struct pt_regs *regs)
11965 {
11966 #ifdef CONFIG_X86_32
11967 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
11968 #else
11969 - return !!(regs->cs & 3);
11970 + return !!(regs->cs & SEGMENT_RPL_MASK);
11971 #endif
11972 }
11973
11974 -static inline int user_mode_vm(struct pt_regs *regs)
11975 +static inline int user_mode(struct pt_regs *regs)
11976 {
11977 #ifdef CONFIG_X86_32
11978 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
11979 USER_RPL;
11980 #else
11981 - return user_mode(regs);
11982 + return user_mode_novm(regs);
11983 #endif
11984 }
11985
11986 @@ -192,15 +193,16 @@ static inline int v8086_mode(struct pt_regs *regs)
11987 #ifdef CONFIG_X86_64
11988 static inline bool user_64bit_mode(struct pt_regs *regs)
11989 {
11990 + unsigned long cs = regs->cs & 0xffff;
11991 #ifndef CONFIG_PARAVIRT
11992 /*
11993 * On non-paravirt systems, this is the only long mode CPL 3
11994 * selector. We do not allow long mode selectors in the LDT.
11995 */
11996 - return regs->cs == __USER_CS;
11997 + return cs == __USER_CS;
11998 #else
11999 /* Headers are too twisted for this to go in paravirt.h. */
12000 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
12001 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
12002 #endif
12003 }
12004 #endif
12005 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
12006 index fce3f4a..3f69f2a 100644
12007 --- a/arch/x86/include/asm/realmode.h
12008 +++ b/arch/x86/include/asm/realmode.h
12009 @@ -30,7 +30,7 @@ struct real_mode_header {
12010 struct trampoline_header {
12011 #ifdef CONFIG_X86_32
12012 u32 start;
12013 - u16 gdt_pad;
12014 + u16 boot_cs;
12015 u16 gdt_limit;
12016 u32 gdt_base;
12017 #else
12018 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
12019 index 92f29706..d0a1a53 100644
12020 --- a/arch/x86/include/asm/reboot.h
12021 +++ b/arch/x86/include/asm/reboot.h
12022 @@ -6,19 +6,19 @@
12023 struct pt_regs;
12024
12025 struct machine_ops {
12026 - void (*restart)(char *cmd);
12027 - void (*halt)(void);
12028 - void (*power_off)(void);
12029 + void (* __noreturn restart)(char *cmd);
12030 + void (* __noreturn halt)(void);
12031 + void (* __noreturn power_off)(void);
12032 void (*shutdown)(void);
12033 void (*crash_shutdown)(struct pt_regs *);
12034 - void (*emergency_restart)(void);
12035 -};
12036 + void (* __noreturn emergency_restart)(void);
12037 +} __no_const;
12038
12039 extern struct machine_ops machine_ops;
12040
12041 void native_machine_crash_shutdown(struct pt_regs *regs);
12042 void native_machine_shutdown(void);
12043 -void machine_real_restart(unsigned int type);
12044 +void __noreturn machine_real_restart(unsigned int type);
12045 /* These must match dispatch_table in reboot_32.S */
12046 #define MRR_BIOS 0
12047 #define MRR_APM 1
12048 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
12049 index 2dbe4a7..ce1db00 100644
12050 --- a/arch/x86/include/asm/rwsem.h
12051 +++ b/arch/x86/include/asm/rwsem.h
12052 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
12053 {
12054 asm volatile("# beginning down_read\n\t"
12055 LOCK_PREFIX _ASM_INC "(%1)\n\t"
12056 +
12057 +#ifdef CONFIG_PAX_REFCOUNT
12058 + "jno 0f\n"
12059 + LOCK_PREFIX _ASM_DEC "(%1)\n"
12060 + "int $4\n0:\n"
12061 + _ASM_EXTABLE(0b, 0b)
12062 +#endif
12063 +
12064 /* adds 0x00000001 */
12065 " jns 1f\n"
12066 " call call_rwsem_down_read_failed\n"
12067 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
12068 "1:\n\t"
12069 " mov %1,%2\n\t"
12070 " add %3,%2\n\t"
12071 +
12072 +#ifdef CONFIG_PAX_REFCOUNT
12073 + "jno 0f\n"
12074 + "sub %3,%2\n"
12075 + "int $4\n0:\n"
12076 + _ASM_EXTABLE(0b, 0b)
12077 +#endif
12078 +
12079 " jle 2f\n\t"
12080 LOCK_PREFIX " cmpxchg %2,%0\n\t"
12081 " jnz 1b\n\t"
12082 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
12083 long tmp;
12084 asm volatile("# beginning down_write\n\t"
12085 LOCK_PREFIX " xadd %1,(%2)\n\t"
12086 +
12087 +#ifdef CONFIG_PAX_REFCOUNT
12088 + "jno 0f\n"
12089 + "mov %1,(%2)\n"
12090 + "int $4\n0:\n"
12091 + _ASM_EXTABLE(0b, 0b)
12092 +#endif
12093 +
12094 /* adds 0xffff0001, returns the old value */
12095 " test %1,%1\n\t"
12096 /* was the count 0 before? */
12097 @@ -141,6 +165,14 @@ static inline void __up_read(struct rw_semaphore *sem)
12098 long tmp;
12099 asm volatile("# beginning __up_read\n\t"
12100 LOCK_PREFIX " xadd %1,(%2)\n\t"
12101 +
12102 +#ifdef CONFIG_PAX_REFCOUNT
12103 + "jno 0f\n"
12104 + "mov %1,(%2)\n"
12105 + "int $4\n0:\n"
12106 + _ASM_EXTABLE(0b, 0b)
12107 +#endif
12108 +
12109 /* subtracts 1, returns the old value */
12110 " jns 1f\n\t"
12111 " call call_rwsem_wake\n" /* expects old value in %edx */
12112 @@ -159,6 +191,14 @@ static inline void __up_write(struct rw_semaphore *sem)
12113 long tmp;
12114 asm volatile("# beginning __up_write\n\t"
12115 LOCK_PREFIX " xadd %1,(%2)\n\t"
12116 +
12117 +#ifdef CONFIG_PAX_REFCOUNT
12118 + "jno 0f\n"
12119 + "mov %1,(%2)\n"
12120 + "int $4\n0:\n"
12121 + _ASM_EXTABLE(0b, 0b)
12122 +#endif
12123 +
12124 /* subtracts 0xffff0001, returns the old value */
12125 " jns 1f\n\t"
12126 " call call_rwsem_wake\n" /* expects old value in %edx */
12127 @@ -176,6 +216,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12128 {
12129 asm volatile("# beginning __downgrade_write\n\t"
12130 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
12131 +
12132 +#ifdef CONFIG_PAX_REFCOUNT
12133 + "jno 0f\n"
12134 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
12135 + "int $4\n0:\n"
12136 + _ASM_EXTABLE(0b, 0b)
12137 +#endif
12138 +
12139 /*
12140 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
12141 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
12142 @@ -194,7 +242,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
12143 */
12144 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12145 {
12146 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
12147 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
12148 +
12149 +#ifdef CONFIG_PAX_REFCOUNT
12150 + "jno 0f\n"
12151 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
12152 + "int $4\n0:\n"
12153 + _ASM_EXTABLE(0b, 0b)
12154 +#endif
12155 +
12156 : "+m" (sem->count)
12157 : "er" (delta));
12158 }
12159 @@ -204,7 +260,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
12160 */
12161 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
12162 {
12163 - return delta + xadd(&sem->count, delta);
12164 + return delta + xadd_check_overflow(&sem->count, delta);
12165 }
12166
12167 #endif /* __KERNEL__ */
12168 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
12169 index c48a950..c6d7468 100644
12170 --- a/arch/x86/include/asm/segment.h
12171 +++ b/arch/x86/include/asm/segment.h
12172 @@ -64,10 +64,15 @@
12173 * 26 - ESPFIX small SS
12174 * 27 - per-cpu [ offset to per-cpu data area ]
12175 * 28 - stack_canary-20 [ for stack protector ]
12176 - * 29 - unused
12177 - * 30 - unused
12178 + * 29 - PCI BIOS CS
12179 + * 30 - PCI BIOS DS
12180 * 31 - TSS for double fault handler
12181 */
12182 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
12183 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
12184 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
12185 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
12186 +
12187 #define GDT_ENTRY_TLS_MIN 6
12188 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
12189
12190 @@ -79,6 +84,8 @@
12191
12192 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
12193
12194 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
12195 +
12196 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
12197
12198 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
12199 @@ -104,6 +111,12 @@
12200 #define __KERNEL_STACK_CANARY 0
12201 #endif
12202
12203 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
12204 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
12205 +
12206 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
12207 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
12208 +
12209 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
12210
12211 /*
12212 @@ -141,7 +154,7 @@
12213 */
12214
12215 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
12216 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
12217 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
12218
12219
12220 #else
12221 @@ -165,6 +178,8 @@
12222 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
12223 #define __USER32_DS __USER_DS
12224
12225 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
12226 +
12227 #define GDT_ENTRY_TSS 8 /* needs two entries */
12228 #define GDT_ENTRY_LDT 10 /* needs two entries */
12229 #define GDT_ENTRY_TLS_MIN 12
12230 @@ -185,6 +200,7 @@
12231 #endif
12232
12233 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
12234 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
12235 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
12236 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
12237 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
12238 @@ -265,7 +281,7 @@ static inline unsigned long get_limit(unsigned long segment)
12239 {
12240 unsigned long __limit;
12241 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
12242 - return __limit + 1;
12243 + return __limit;
12244 }
12245
12246 #endif /* !__ASSEMBLY__ */
12247 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
12248 index f483945..64a7851 100644
12249 --- a/arch/x86/include/asm/smp.h
12250 +++ b/arch/x86/include/asm/smp.h
12251 @@ -36,7 +36,7 @@ DECLARE_PER_CPU(cpumask_var_t, cpu_core_map);
12252 /* cpus sharing the last level cache: */
12253 DECLARE_PER_CPU(cpumask_var_t, cpu_llc_shared_map);
12254 DECLARE_PER_CPU(u16, cpu_llc_id);
12255 -DECLARE_PER_CPU(int, cpu_number);
12256 +DECLARE_PER_CPU(unsigned int, cpu_number);
12257
12258 static inline struct cpumask *cpu_sibling_mask(int cpu)
12259 {
12260 @@ -79,7 +79,7 @@ struct smp_ops {
12261
12262 void (*send_call_func_ipi)(const struct cpumask *mask);
12263 void (*send_call_func_single_ipi)(int cpu);
12264 -};
12265 +} __no_const;
12266
12267 /* Globals due to paravirt */
12268 extern void set_cpu_sibling_map(int cpu);
12269 @@ -195,14 +195,8 @@ extern unsigned disabled_cpus __cpuinitdata;
12270 extern int safe_smp_processor_id(void);
12271
12272 #elif defined(CONFIG_X86_64_SMP)
12273 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12274 -
12275 -#define stack_smp_processor_id() \
12276 -({ \
12277 - struct thread_info *ti; \
12278 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
12279 - ti->cpu; \
12280 -})
12281 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
12282 +#define stack_smp_processor_id() raw_smp_processor_id()
12283 #define safe_smp_processor_id() smp_processor_id()
12284
12285 #endif
12286 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
12287 index b315a33..8849ab0 100644
12288 --- a/arch/x86/include/asm/spinlock.h
12289 +++ b/arch/x86/include/asm/spinlock.h
12290 @@ -173,6 +173,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
12291 static inline void arch_read_lock(arch_rwlock_t *rw)
12292 {
12293 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
12294 +
12295 +#ifdef CONFIG_PAX_REFCOUNT
12296 + "jno 0f\n"
12297 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
12298 + "int $4\n0:\n"
12299 + _ASM_EXTABLE(0b, 0b)
12300 +#endif
12301 +
12302 "jns 1f\n"
12303 "call __read_lock_failed\n\t"
12304 "1:\n"
12305 @@ -182,6 +190,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
12306 static inline void arch_write_lock(arch_rwlock_t *rw)
12307 {
12308 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
12309 +
12310 +#ifdef CONFIG_PAX_REFCOUNT
12311 + "jno 0f\n"
12312 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
12313 + "int $4\n0:\n"
12314 + _ASM_EXTABLE(0b, 0b)
12315 +#endif
12316 +
12317 "jz 1f\n"
12318 "call __write_lock_failed\n\t"
12319 "1:\n"
12320 @@ -211,13 +227,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
12321
12322 static inline void arch_read_unlock(arch_rwlock_t *rw)
12323 {
12324 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
12325 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
12326 +
12327 +#ifdef CONFIG_PAX_REFCOUNT
12328 + "jno 0f\n"
12329 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
12330 + "int $4\n0:\n"
12331 + _ASM_EXTABLE(0b, 0b)
12332 +#endif
12333 +
12334 :"+m" (rw->lock) : : "memory");
12335 }
12336
12337 static inline void arch_write_unlock(arch_rwlock_t *rw)
12338 {
12339 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
12340 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
12341 +
12342 +#ifdef CONFIG_PAX_REFCOUNT
12343 + "jno 0f\n"
12344 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
12345 + "int $4\n0:\n"
12346 + _ASM_EXTABLE(0b, 0b)
12347 +#endif
12348 +
12349 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
12350 }
12351
12352 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
12353 index 6a99859..03cb807 100644
12354 --- a/arch/x86/include/asm/stackprotector.h
12355 +++ b/arch/x86/include/asm/stackprotector.h
12356 @@ -47,7 +47,7 @@
12357 * head_32 for boot CPU and setup_per_cpu_areas() for others.
12358 */
12359 #define GDT_STACK_CANARY_INIT \
12360 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
12361 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
12362
12363 /*
12364 * Initialize the stackprotector canary value.
12365 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
12366
12367 static inline void load_stack_canary_segment(void)
12368 {
12369 -#ifdef CONFIG_X86_32
12370 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
12371 asm volatile ("mov %0, %%gs" : : "r" (0));
12372 #endif
12373 }
12374 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
12375 index 70bbe39..4ae2bd4 100644
12376 --- a/arch/x86/include/asm/stacktrace.h
12377 +++ b/arch/x86/include/asm/stacktrace.h
12378 @@ -11,28 +11,20 @@
12379
12380 extern int kstack_depth_to_print;
12381
12382 -struct thread_info;
12383 +struct task_struct;
12384 struct stacktrace_ops;
12385
12386 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
12387 - unsigned long *stack,
12388 - unsigned long bp,
12389 - const struct stacktrace_ops *ops,
12390 - void *data,
12391 - unsigned long *end,
12392 - int *graph);
12393 +typedef unsigned long walk_stack_t(struct task_struct *task,
12394 + void *stack_start,
12395 + unsigned long *stack,
12396 + unsigned long bp,
12397 + const struct stacktrace_ops *ops,
12398 + void *data,
12399 + unsigned long *end,
12400 + int *graph);
12401
12402 -extern unsigned long
12403 -print_context_stack(struct thread_info *tinfo,
12404 - unsigned long *stack, unsigned long bp,
12405 - const struct stacktrace_ops *ops, void *data,
12406 - unsigned long *end, int *graph);
12407 -
12408 -extern unsigned long
12409 -print_context_stack_bp(struct thread_info *tinfo,
12410 - unsigned long *stack, unsigned long bp,
12411 - const struct stacktrace_ops *ops, void *data,
12412 - unsigned long *end, int *graph);
12413 +extern walk_stack_t print_context_stack;
12414 +extern walk_stack_t print_context_stack_bp;
12415
12416 /* Generic stack tracer with callbacks */
12417
12418 @@ -40,7 +32,7 @@ struct stacktrace_ops {
12419 void (*address)(void *data, unsigned long address, int reliable);
12420 /* On negative return stop dumping */
12421 int (*stack)(void *data, char *name);
12422 - walk_stack_t walk_stack;
12423 + walk_stack_t *walk_stack;
12424 };
12425
12426 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
12427 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
12428 index 4ec45b3..a4f0a8a 100644
12429 --- a/arch/x86/include/asm/switch_to.h
12430 +++ b/arch/x86/include/asm/switch_to.h
12431 @@ -108,7 +108,7 @@ do { \
12432 "call __switch_to\n\t" \
12433 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
12434 __switch_canary \
12435 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
12436 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
12437 "movq %%rax,%%rdi\n\t" \
12438 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
12439 "jnz ret_from_fork\n\t" \
12440 @@ -119,7 +119,7 @@ do { \
12441 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
12442 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
12443 [_tif_fork] "i" (_TIF_FORK), \
12444 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
12445 + [thread_info] "m" (current_tinfo), \
12446 [current_task] "m" (current_task) \
12447 __switch_canary_iparam \
12448 : "memory", "cc" __EXTRA_CLOBBER)
12449 diff --git a/arch/x86/include/asm/sys_ia32.h b/arch/x86/include/asm/sys_ia32.h
12450 index 3fda9db4..4ca1c61 100644
12451 --- a/arch/x86/include/asm/sys_ia32.h
12452 +++ b/arch/x86/include/asm/sys_ia32.h
12453 @@ -40,7 +40,7 @@ asmlinkage long sys32_sigaction(int, struct old_sigaction32 __user *,
12454 struct old_sigaction32 __user *);
12455 asmlinkage long sys32_alarm(unsigned int);
12456
12457 -asmlinkage long sys32_waitpid(compat_pid_t, unsigned int *, int);
12458 +asmlinkage long sys32_waitpid(compat_pid_t, unsigned int __user *, int);
12459 asmlinkage long sys32_sysfs(int, u32, u32);
12460
12461 asmlinkage long sys32_sched_rr_get_interval(compat_pid_t,
12462 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
12463 index 89f794f..1422765 100644
12464 --- a/arch/x86/include/asm/thread_info.h
12465 +++ b/arch/x86/include/asm/thread_info.h
12466 @@ -10,6 +10,7 @@
12467 #include <linux/compiler.h>
12468 #include <asm/page.h>
12469 #include <asm/types.h>
12470 +#include <asm/percpu.h>
12471
12472 /*
12473 * low level task data that entry.S needs immediate access to
12474 @@ -24,7 +25,6 @@ struct exec_domain;
12475 #include <linux/atomic.h>
12476
12477 struct thread_info {
12478 - struct task_struct *task; /* main task structure */
12479 struct exec_domain *exec_domain; /* execution domain */
12480 __u32 flags; /* low level flags */
12481 __u32 status; /* thread synchronous flags */
12482 @@ -34,19 +34,13 @@ struct thread_info {
12483 mm_segment_t addr_limit;
12484 struct restart_block restart_block;
12485 void __user *sysenter_return;
12486 -#ifdef CONFIG_X86_32
12487 - unsigned long previous_esp; /* ESP of the previous stack in
12488 - case of nested (IRQ) stacks
12489 - */
12490 - __u8 supervisor_stack[0];
12491 -#endif
12492 + unsigned long lowest_stack;
12493 unsigned int sig_on_uaccess_error:1;
12494 unsigned int uaccess_err:1; /* uaccess failed */
12495 };
12496
12497 -#define INIT_THREAD_INFO(tsk) \
12498 +#define INIT_THREAD_INFO \
12499 { \
12500 - .task = &tsk, \
12501 .exec_domain = &default_exec_domain, \
12502 .flags = 0, \
12503 .cpu = 0, \
12504 @@ -57,7 +51,7 @@ struct thread_info {
12505 }, \
12506 }
12507
12508 -#define init_thread_info (init_thread_union.thread_info)
12509 +#define init_thread_info (init_thread_union.stack)
12510 #define init_stack (init_thread_union.stack)
12511
12512 #else /* !__ASSEMBLY__ */
12513 @@ -98,6 +92,7 @@ struct thread_info {
12514 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
12515 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
12516 #define TIF_X32 30 /* 32-bit native x86-64 binary */
12517 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
12518
12519 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
12520 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
12521 @@ -122,16 +117,18 @@ struct thread_info {
12522 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
12523 #define _TIF_ADDR32 (1 << TIF_ADDR32)
12524 #define _TIF_X32 (1 << TIF_X32)
12525 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
12526
12527 /* work to do in syscall_trace_enter() */
12528 #define _TIF_WORK_SYSCALL_ENTRY \
12529 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
12530 - _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT)
12531 + _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
12532 + _TIF_GRSEC_SETXID)
12533
12534 /* work to do in syscall_trace_leave() */
12535 #define _TIF_WORK_SYSCALL_EXIT \
12536 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
12537 - _TIF_SYSCALL_TRACEPOINT)
12538 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
12539
12540 /* work to do on interrupt/exception return */
12541 #define _TIF_WORK_MASK \
12542 @@ -141,7 +138,8 @@ struct thread_info {
12543
12544 /* work to do on any return to user space */
12545 #define _TIF_ALLWORK_MASK \
12546 - ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT)
12547 + ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
12548 + _TIF_GRSEC_SETXID)
12549
12550 /* Only used for 64 bit */
12551 #define _TIF_DO_NOTIFY_MASK \
12552 @@ -157,45 +155,40 @@ struct thread_info {
12553
12554 #define PREEMPT_ACTIVE 0x10000000
12555
12556 -#ifdef CONFIG_X86_32
12557 -
12558 -#define STACK_WARN (THREAD_SIZE/8)
12559 -/*
12560 - * macros/functions for gaining access to the thread information structure
12561 - *
12562 - * preempt_count needs to be 1 initially, until the scheduler is functional.
12563 - */
12564 -#ifndef __ASSEMBLY__
12565 -
12566 -
12567 -/* how to get the current stack pointer from C */
12568 -register unsigned long current_stack_pointer asm("esp") __used;
12569 -
12570 -/* how to get the thread information struct from C */
12571 -static inline struct thread_info *current_thread_info(void)
12572 -{
12573 - return (struct thread_info *)
12574 - (current_stack_pointer & ~(THREAD_SIZE - 1));
12575 -}
12576 -
12577 -#else /* !__ASSEMBLY__ */
12578 -
12579 +#ifdef __ASSEMBLY__
12580 /* how to get the thread information struct from ASM */
12581 #define GET_THREAD_INFO(reg) \
12582 - movl $-THREAD_SIZE, reg; \
12583 - andl %esp, reg
12584 + mov PER_CPU_VAR(current_tinfo), reg
12585
12586 /* use this one if reg already contains %esp */
12587 -#define GET_THREAD_INFO_WITH_ESP(reg) \
12588 - andl $-THREAD_SIZE, reg
12589 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
12590 +#else
12591 +/* how to get the thread information struct from C */
12592 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
12593 +
12594 +static __always_inline struct thread_info *current_thread_info(void)
12595 +{
12596 + return this_cpu_read_stable(current_tinfo);
12597 +}
12598 +#endif
12599 +
12600 +#ifdef CONFIG_X86_32
12601 +
12602 +#define STACK_WARN (THREAD_SIZE/8)
12603 +/*
12604 + * macros/functions for gaining access to the thread information structure
12605 + *
12606 + * preempt_count needs to be 1 initially, until the scheduler is functional.
12607 + */
12608 +#ifndef __ASSEMBLY__
12609 +
12610 +/* how to get the current stack pointer from C */
12611 +register unsigned long current_stack_pointer asm("esp") __used;
12612
12613 #endif
12614
12615 #else /* X86_32 */
12616
12617 -#include <asm/percpu.h>
12618 -#define KERNEL_STACK_OFFSET (5*8)
12619 -
12620 /*
12621 * macros/functions for gaining access to the thread information structure
12622 * preempt_count needs to be 1 initially, until the scheduler is functional.
12623 @@ -203,27 +196,8 @@ static inline struct thread_info *current_thread_info(void)
12624 #ifndef __ASSEMBLY__
12625 DECLARE_PER_CPU(unsigned long, kernel_stack);
12626
12627 -static inline struct thread_info *current_thread_info(void)
12628 -{
12629 - struct thread_info *ti;
12630 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
12631 - KERNEL_STACK_OFFSET - THREAD_SIZE);
12632 - return ti;
12633 -}
12634 -
12635 -#else /* !__ASSEMBLY__ */
12636 -
12637 -/* how to get the thread information struct from ASM */
12638 -#define GET_THREAD_INFO(reg) \
12639 - movq PER_CPU_VAR(kernel_stack),reg ; \
12640 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
12641 -
12642 -/*
12643 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
12644 - * a certain register (to be used in assembler memory operands).
12645 - */
12646 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
12647 -
12648 +/* how to get the current stack pointer from C */
12649 +register unsigned long current_stack_pointer asm("rsp") __used;
12650 #endif
12651
12652 #endif /* !X86_32 */
12653 @@ -284,5 +258,12 @@ static inline bool is_ia32_task(void)
12654 extern void arch_task_cache_init(void);
12655 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
12656 extern void arch_release_task_struct(struct task_struct *tsk);
12657 +
12658 +#define __HAVE_THREAD_FUNCTIONS
12659 +#define task_thread_info(task) (&(task)->tinfo)
12660 +#define task_stack_page(task) ((task)->stack)
12661 +#define setup_thread_stack(p, org) do {} while (0)
12662 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
12663 +
12664 #endif
12665 #endif /* _ASM_X86_THREAD_INFO_H */
12666 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
12667 index e1f3a17..1ab364d 100644
12668 --- a/arch/x86/include/asm/uaccess.h
12669 +++ b/arch/x86/include/asm/uaccess.h
12670 @@ -7,12 +7,15 @@
12671 #include <linux/compiler.h>
12672 #include <linux/thread_info.h>
12673 #include <linux/string.h>
12674 +#include <linux/sched.h>
12675 #include <asm/asm.h>
12676 #include <asm/page.h>
12677
12678 #define VERIFY_READ 0
12679 #define VERIFY_WRITE 1
12680
12681 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
12682 +
12683 /*
12684 * The fs value determines whether argument validity checking should be
12685 * performed or not. If get_fs() == USER_DS, checking is performed, with
12686 @@ -28,7 +31,12 @@
12687
12688 #define get_ds() (KERNEL_DS)
12689 #define get_fs() (current_thread_info()->addr_limit)
12690 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12691 +void __set_fs(mm_segment_t x);
12692 +void set_fs(mm_segment_t x);
12693 +#else
12694 #define set_fs(x) (current_thread_info()->addr_limit = (x))
12695 +#endif
12696
12697 #define segment_eq(a, b) ((a).seg == (b).seg)
12698
12699 @@ -76,8 +84,33 @@
12700 * checks that the pointer is in the user space range - after calling
12701 * this function, memory access functions may still return -EFAULT.
12702 */
12703 -#define access_ok(type, addr, size) \
12704 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12705 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
12706 +#define access_ok(type, addr, size) \
12707 +({ \
12708 + long __size = size; \
12709 + unsigned long __addr = (unsigned long)addr; \
12710 + unsigned long __addr_ao = __addr & PAGE_MASK; \
12711 + unsigned long __end_ao = __addr + __size - 1; \
12712 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
12713 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
12714 + while(__addr_ao <= __end_ao) { \
12715 + char __c_ao; \
12716 + __addr_ao += PAGE_SIZE; \
12717 + if (__size > PAGE_SIZE) \
12718 + cond_resched(); \
12719 + if (__get_user(__c_ao, (char __user *)__addr)) \
12720 + break; \
12721 + if (type != VERIFY_WRITE) { \
12722 + __addr = __addr_ao; \
12723 + continue; \
12724 + } \
12725 + if (__put_user(__c_ao, (char __user *)__addr)) \
12726 + break; \
12727 + __addr = __addr_ao; \
12728 + } \
12729 + } \
12730 + __ret_ao; \
12731 +})
12732
12733 /*
12734 * The exception table consists of pairs of addresses relative to the
12735 @@ -188,12 +221,20 @@ extern int __get_user_bad(void);
12736 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
12737 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
12738
12739 -
12740 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
12741 +#define __copyuser_seg "gs;"
12742 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
12743 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
12744 +#else
12745 +#define __copyuser_seg
12746 +#define __COPYUSER_SET_ES
12747 +#define __COPYUSER_RESTORE_ES
12748 +#endif
12749
12750 #ifdef CONFIG_X86_32
12751 #define __put_user_asm_u64(x, addr, err, errret) \
12752 - asm volatile("1: movl %%eax,0(%2)\n" \
12753 - "2: movl %%edx,4(%2)\n" \
12754 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%2)\n" \
12755 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
12756 "3:\n" \
12757 ".section .fixup,\"ax\"\n" \
12758 "4: movl %3,%0\n" \
12759 @@ -205,8 +246,8 @@ extern int __get_user_bad(void);
12760 : "A" (x), "r" (addr), "i" (errret), "0" (err))
12761
12762 #define __put_user_asm_ex_u64(x, addr) \
12763 - asm volatile("1: movl %%eax,0(%1)\n" \
12764 - "2: movl %%edx,4(%1)\n" \
12765 + asm volatile("1: "__copyuser_seg"movl %%eax,0(%1)\n" \
12766 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
12767 "3:\n" \
12768 _ASM_EXTABLE_EX(1b, 2b) \
12769 _ASM_EXTABLE_EX(2b, 3b) \
12770 @@ -258,7 +299,7 @@ extern void __put_user_8(void);
12771 __typeof__(*(ptr)) __pu_val; \
12772 __chk_user_ptr(ptr); \
12773 might_fault(); \
12774 - __pu_val = x; \
12775 + __pu_val = (x); \
12776 switch (sizeof(*(ptr))) { \
12777 case 1: \
12778 __put_user_x(1, __pu_val, ptr, __ret_pu); \
12779 @@ -379,7 +420,7 @@ do { \
12780 } while (0)
12781
12782 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12783 - asm volatile("1: mov"itype" %2,%"rtype"1\n" \
12784 + asm volatile("1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
12785 "2:\n" \
12786 ".section .fixup,\"ax\"\n" \
12787 "3: mov %3,%0\n" \
12788 @@ -387,7 +428,7 @@ do { \
12789 " jmp 2b\n" \
12790 ".previous\n" \
12791 _ASM_EXTABLE(1b, 3b) \
12792 - : "=r" (err), ltype(x) \
12793 + : "=r" (err), ltype (x) \
12794 : "m" (__m(addr)), "i" (errret), "0" (err))
12795
12796 #define __get_user_size_ex(x, ptr, size) \
12797 @@ -412,7 +453,7 @@ do { \
12798 } while (0)
12799
12800 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
12801 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
12802 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
12803 "2:\n" \
12804 _ASM_EXTABLE_EX(1b, 2b) \
12805 : ltype(x) : "m" (__m(addr)))
12806 @@ -429,13 +470,24 @@ do { \
12807 int __gu_err; \
12808 unsigned long __gu_val; \
12809 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
12810 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
12811 + (x) = (__typeof__(*(ptr)))__gu_val; \
12812 __gu_err; \
12813 })
12814
12815 /* FIXME: this hack is definitely wrong -AK */
12816 struct __large_struct { unsigned long buf[100]; };
12817 -#define __m(x) (*(struct __large_struct __user *)(x))
12818 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12819 +#define ____m(x) \
12820 +({ \
12821 + unsigned long ____x = (unsigned long)(x); \
12822 + if (____x < PAX_USER_SHADOW_BASE) \
12823 + ____x += PAX_USER_SHADOW_BASE; \
12824 + (void __user *)____x; \
12825 +})
12826 +#else
12827 +#define ____m(x) (x)
12828 +#endif
12829 +#define __m(x) (*(struct __large_struct __user *)____m(x))
12830
12831 /*
12832 * Tell gcc we read from memory instead of writing: this is because
12833 @@ -443,7 +495,7 @@ struct __large_struct { unsigned long buf[100]; };
12834 * aliasing issues.
12835 */
12836 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
12837 - asm volatile("1: mov"itype" %"rtype"1,%2\n" \
12838 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
12839 "2:\n" \
12840 ".section .fixup,\"ax\"\n" \
12841 "3: mov %3,%0\n" \
12842 @@ -451,10 +503,10 @@ struct __large_struct { unsigned long buf[100]; };
12843 ".previous\n" \
12844 _ASM_EXTABLE(1b, 3b) \
12845 : "=r"(err) \
12846 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
12847 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err))
12848
12849 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
12850 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
12851 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
12852 "2:\n" \
12853 _ASM_EXTABLE_EX(1b, 2b) \
12854 : : ltype(x), "m" (__m(addr)))
12855 @@ -493,8 +545,12 @@ struct __large_struct { unsigned long buf[100]; };
12856 * On error, the variable @x is set to zero.
12857 */
12858
12859 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12860 +#define __get_user(x, ptr) get_user((x), (ptr))
12861 +#else
12862 #define __get_user(x, ptr) \
12863 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
12864 +#endif
12865
12866 /**
12867 * __put_user: - Write a simple value into user space, with less checking.
12868 @@ -516,8 +572,12 @@ struct __large_struct { unsigned long buf[100]; };
12869 * Returns zero on success, or -EFAULT on error.
12870 */
12871
12872 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
12873 +#define __put_user(x, ptr) put_user((x), (ptr))
12874 +#else
12875 #define __put_user(x, ptr) \
12876 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
12877 +#endif
12878
12879 #define __get_user_unaligned __get_user
12880 #define __put_user_unaligned __put_user
12881 @@ -535,7 +595,7 @@ struct __large_struct { unsigned long buf[100]; };
12882 #define get_user_ex(x, ptr) do { \
12883 unsigned long __gue_val; \
12884 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
12885 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
12886 + (x) = (__typeof__(*(ptr)))__gue_val; \
12887 } while (0)
12888
12889 #ifdef CONFIG_X86_WP_WORKS_OK
12890 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
12891 index 576e39b..ccd0a39 100644
12892 --- a/arch/x86/include/asm/uaccess_32.h
12893 +++ b/arch/x86/include/asm/uaccess_32.h
12894 @@ -11,15 +11,15 @@
12895 #include <asm/page.h>
12896
12897 unsigned long __must_check __copy_to_user_ll
12898 - (void __user *to, const void *from, unsigned long n);
12899 + (void __user *to, const void *from, unsigned long n) __size_overflow(3);
12900 unsigned long __must_check __copy_from_user_ll
12901 - (void *to, const void __user *from, unsigned long n);
12902 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12903 unsigned long __must_check __copy_from_user_ll_nozero
12904 - (void *to, const void __user *from, unsigned long n);
12905 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12906 unsigned long __must_check __copy_from_user_ll_nocache
12907 - (void *to, const void __user *from, unsigned long n);
12908 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12909 unsigned long __must_check __copy_from_user_ll_nocache_nozero
12910 - (void *to, const void __user *from, unsigned long n);
12911 + (void *to, const void __user *from, unsigned long n) __size_overflow(3);
12912
12913 /**
12914 * __copy_to_user_inatomic: - Copy a block of data into user space, with less checking.
12915 @@ -43,6 +43,9 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
12916 static __always_inline unsigned long __must_check
12917 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12918 {
12919 + if ((long)n < 0)
12920 + return n;
12921 +
12922 if (__builtin_constant_p(n)) {
12923 unsigned long ret;
12924
12925 @@ -61,6 +64,8 @@ __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
12926 return ret;
12927 }
12928 }
12929 + if (!__builtin_constant_p(n))
12930 + check_object_size(from, n, true);
12931 return __copy_to_user_ll(to, from, n);
12932 }
12933
12934 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
12935 __copy_to_user(void __user *to, const void *from, unsigned long n)
12936 {
12937 might_fault();
12938 +
12939 return __copy_to_user_inatomic(to, from, n);
12940 }
12941
12942 static __always_inline unsigned long
12943 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
12944 {
12945 + if ((long)n < 0)
12946 + return n;
12947 +
12948 /* Avoid zeroing the tail if the copy fails..
12949 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
12950 * but as the zeroing behaviour is only significant when n is not
12951 @@ -137,6 +146,10 @@ static __always_inline unsigned long
12952 __copy_from_user(void *to, const void __user *from, unsigned long n)
12953 {
12954 might_fault();
12955 +
12956 + if ((long)n < 0)
12957 + return n;
12958 +
12959 if (__builtin_constant_p(n)) {
12960 unsigned long ret;
12961
12962 @@ -152,6 +165,8 @@ __copy_from_user(void *to, const void __user *from, unsigned long n)
12963 return ret;
12964 }
12965 }
12966 + if (!__builtin_constant_p(n))
12967 + check_object_size(to, n, false);
12968 return __copy_from_user_ll(to, from, n);
12969 }
12970
12971 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
12972 const void __user *from, unsigned long n)
12973 {
12974 might_fault();
12975 +
12976 + if ((long)n < 0)
12977 + return n;
12978 +
12979 if (__builtin_constant_p(n)) {
12980 unsigned long ret;
12981
12982 @@ -181,15 +200,19 @@ static __always_inline unsigned long
12983 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
12984 unsigned long n)
12985 {
12986 - return __copy_from_user_ll_nocache_nozero(to, from, n);
12987 + if ((long)n < 0)
12988 + return n;
12989 +
12990 + return __copy_from_user_ll_nocache_nozero(to, from, n);
12991 }
12992
12993 -unsigned long __must_check copy_to_user(void __user *to,
12994 - const void *from, unsigned long n);
12995 -unsigned long __must_check _copy_from_user(void *to,
12996 - const void __user *from,
12997 - unsigned long n);
12998 -
12999 +extern void copy_to_user_overflow(void)
13000 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13001 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13002 +#else
13003 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13004 +#endif
13005 +;
13006
13007 extern void copy_from_user_overflow(void)
13008 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13009 @@ -199,21 +222,65 @@ extern void copy_from_user_overflow(void)
13010 #endif
13011 ;
13012
13013 -static inline unsigned long __must_check copy_from_user(void *to,
13014 - const void __user *from,
13015 - unsigned long n)
13016 +/**
13017 + * copy_to_user: - Copy a block of data into user space.
13018 + * @to: Destination address, in user space.
13019 + * @from: Source address, in kernel space.
13020 + * @n: Number of bytes to copy.
13021 + *
13022 + * Context: User context only. This function may sleep.
13023 + *
13024 + * Copy data from kernel space to user space.
13025 + *
13026 + * Returns number of bytes that could not be copied.
13027 + * On success, this will be zero.
13028 + */
13029 +static inline unsigned long __must_check
13030 +copy_to_user(void __user *to, const void *from, unsigned long n)
13031 {
13032 - int sz = __compiletime_object_size(to);
13033 + size_t sz = __compiletime_object_size(from);
13034
13035 - if (likely(sz == -1 || sz >= n))
13036 - n = _copy_from_user(to, from, n);
13037 - else
13038 + if (unlikely(sz != (size_t)-1 && sz < n))
13039 + copy_to_user_overflow();
13040 + else if (access_ok(VERIFY_WRITE, to, n))
13041 + n = __copy_to_user(to, from, n);
13042 + return n;
13043 +}
13044 +
13045 +/**
13046 + * copy_from_user: - Copy a block of data from user space.
13047 + * @to: Destination address, in kernel space.
13048 + * @from: Source address, in user space.
13049 + * @n: Number of bytes to copy.
13050 + *
13051 + * Context: User context only. This function may sleep.
13052 + *
13053 + * Copy data from user space to kernel space.
13054 + *
13055 + * Returns number of bytes that could not be copied.
13056 + * On success, this will be zero.
13057 + *
13058 + * If some data could not be copied, this function will pad the copied
13059 + * data to the requested size using zero bytes.
13060 + */
13061 +static inline unsigned long __must_check
13062 +copy_from_user(void *to, const void __user *from, unsigned long n)
13063 +{
13064 + size_t sz = __compiletime_object_size(to);
13065 +
13066 + if (unlikely(sz != (size_t)-1 && sz < n))
13067 copy_from_user_overflow();
13068 -
13069 + else if (access_ok(VERIFY_READ, from, n))
13070 + n = __copy_from_user(to, from, n);
13071 + else if ((long)n > 0) {
13072 + if (!__builtin_constant_p(n))
13073 + check_object_size(to, n, false);
13074 + memset(to, 0, n);
13075 + }
13076 return n;
13077 }
13078
13079 -unsigned long __must_check clear_user(void __user *mem, unsigned long len);
13080 -unsigned long __must_check __clear_user(void __user *mem, unsigned long len);
13081 +unsigned long __must_check clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13082 +unsigned long __must_check __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13083
13084 #endif /* _ASM_X86_UACCESS_32_H */
13085 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
13086 index 8e796fb..468c55a 100644
13087 --- a/arch/x86/include/asm/uaccess_64.h
13088 +++ b/arch/x86/include/asm/uaccess_64.h
13089 @@ -10,6 +10,9 @@
13090 #include <asm/alternative.h>
13091 #include <asm/cpufeature.h>
13092 #include <asm/page.h>
13093 +#include <asm/pgtable.h>
13094 +
13095 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
13096
13097 /*
13098 * Copy To/From Userspace
13099 @@ -17,12 +20,12 @@
13100
13101 /* Handles exceptions in both to and from, but doesn't do access_ok */
13102 __must_check unsigned long
13103 -copy_user_generic_string(void *to, const void *from, unsigned len);
13104 +copy_user_generic_string(void *to, const void *from, unsigned long len) __size_overflow(3);
13105 __must_check unsigned long
13106 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
13107 +copy_user_generic_unrolled(void *to, const void *from, unsigned long len) __size_overflow(3);
13108
13109 -static __always_inline __must_check unsigned long
13110 -copy_user_generic(void *to, const void *from, unsigned len)
13111 +static __always_inline __must_check __size_overflow(3) unsigned long
13112 +copy_user_generic(void *to, const void *from, unsigned long len)
13113 {
13114 unsigned ret;
13115
13116 @@ -32,142 +35,238 @@ copy_user_generic(void *to, const void *from, unsigned len)
13117 ASM_OUTPUT2("=a" (ret), "=D" (to), "=S" (from),
13118 "=d" (len)),
13119 "1" (to), "2" (from), "3" (len)
13120 - : "memory", "rcx", "r8", "r9", "r10", "r11");
13121 + : "memory", "rcx", "r8", "r9", "r11");
13122 return ret;
13123 }
13124
13125 +static __always_inline __must_check unsigned long
13126 +__copy_to_user(void __user *to, const void *from, unsigned long len) __size_overflow(3);
13127 +static __always_inline __must_check unsigned long
13128 +__copy_from_user(void *to, const void __user *from, unsigned long len) __size_overflow(3);
13129 __must_check unsigned long
13130 -_copy_to_user(void __user *to, const void *from, unsigned len);
13131 -__must_check unsigned long
13132 -_copy_from_user(void *to, const void __user *from, unsigned len);
13133 -__must_check unsigned long
13134 -copy_in_user(void __user *to, const void __user *from, unsigned len);
13135 +copy_in_user(void __user *to, const void __user *from, unsigned long len) __size_overflow(3);
13136 +
13137 +extern void copy_to_user_overflow(void)
13138 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13139 + __compiletime_error("copy_to_user() buffer size is not provably correct")
13140 +#else
13141 + __compiletime_warning("copy_to_user() buffer size is not provably correct")
13142 +#endif
13143 +;
13144 +
13145 +extern void copy_from_user_overflow(void)
13146 +#ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
13147 + __compiletime_error("copy_from_user() buffer size is not provably correct")
13148 +#else
13149 + __compiletime_warning("copy_from_user() buffer size is not provably correct")
13150 +#endif
13151 +;
13152
13153 static inline unsigned long __must_check copy_from_user(void *to,
13154 const void __user *from,
13155 unsigned long n)
13156 {
13157 - int sz = __compiletime_object_size(to);
13158 -
13159 might_fault();
13160 - if (likely(sz == -1 || sz >= n))
13161 - n = _copy_from_user(to, from, n);
13162 -#ifdef CONFIG_DEBUG_VM
13163 - else
13164 - WARN(1, "Buffer overflow detected!\n");
13165 -#endif
13166 +
13167 + if (access_ok(VERIFY_READ, from, n))
13168 + n = __copy_from_user(to, from, n);
13169 + else if (n < INT_MAX) {
13170 + if (!__builtin_constant_p(n))
13171 + check_object_size(to, n, false);
13172 + memset(to, 0, n);
13173 + }
13174 return n;
13175 }
13176
13177 static __always_inline __must_check
13178 -int copy_to_user(void __user *dst, const void *src, unsigned size)
13179 +int copy_to_user(void __user *dst, const void *src, unsigned long size)
13180 {
13181 might_fault();
13182
13183 - return _copy_to_user(dst, src, size);
13184 + if (access_ok(VERIFY_WRITE, dst, size))
13185 + size = __copy_to_user(dst, src, size);
13186 + return size;
13187 }
13188
13189 static __always_inline __must_check
13190 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
13191 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
13192 {
13193 - int ret = 0;
13194 + size_t sz = __compiletime_object_size(dst);
13195 + unsigned ret = 0;
13196
13197 might_fault();
13198 - if (!__builtin_constant_p(size))
13199 - return copy_user_generic(dst, (__force void *)src, size);
13200 +
13201 + if (size > INT_MAX)
13202 + return size;
13203 +
13204 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13205 + if (!__access_ok(VERIFY_READ, src, size))
13206 + return size;
13207 +#endif
13208 +
13209 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13210 + copy_from_user_overflow();
13211 + return size;
13212 + }
13213 +
13214 + if (!__builtin_constant_p(size)) {
13215 + check_object_size(dst, size, false);
13216 +
13217 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13218 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13219 + src += PAX_USER_SHADOW_BASE;
13220 +#endif
13221 +
13222 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13223 + }
13224 switch (size) {
13225 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
13226 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
13227 ret, "b", "b", "=q", 1);
13228 return ret;
13229 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
13230 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
13231 ret, "w", "w", "=r", 2);
13232 return ret;
13233 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
13234 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
13235 ret, "l", "k", "=r", 4);
13236 return ret;
13237 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
13238 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13239 ret, "q", "", "=r", 8);
13240 return ret;
13241 case 10:
13242 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13243 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13244 ret, "q", "", "=r", 10);
13245 if (unlikely(ret))
13246 return ret;
13247 __get_user_asm(*(u16 *)(8 + (char *)dst),
13248 - (u16 __user *)(8 + (char __user *)src),
13249 + (const u16 __user *)(8 + (const char __user *)src),
13250 ret, "w", "w", "=r", 2);
13251 return ret;
13252 case 16:
13253 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
13254 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
13255 ret, "q", "", "=r", 16);
13256 if (unlikely(ret))
13257 return ret;
13258 __get_user_asm(*(u64 *)(8 + (char *)dst),
13259 - (u64 __user *)(8 + (char __user *)src),
13260 + (const u64 __user *)(8 + (const char __user *)src),
13261 ret, "q", "", "=r", 8);
13262 return ret;
13263 default:
13264 - return copy_user_generic(dst, (__force void *)src, size);
13265 +
13266 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13267 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13268 + src += PAX_USER_SHADOW_BASE;
13269 +#endif
13270 +
13271 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13272 }
13273 }
13274
13275 static __always_inline __must_check
13276 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
13277 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
13278 {
13279 - int ret = 0;
13280 + size_t sz = __compiletime_object_size(src);
13281 + unsigned ret = 0;
13282
13283 might_fault();
13284 - if (!__builtin_constant_p(size))
13285 - return copy_user_generic((__force void *)dst, src, size);
13286 +
13287 + if (size > INT_MAX)
13288 + return size;
13289 +
13290 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13291 + if (!__access_ok(VERIFY_WRITE, dst, size))
13292 + return size;
13293 +#endif
13294 +
13295 + if (unlikely(sz != (size_t)-1 && sz < size)) {
13296 + copy_to_user_overflow();
13297 + return size;
13298 + }
13299 +
13300 + if (!__builtin_constant_p(size)) {
13301 + check_object_size(src, size, true);
13302 +
13303 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13304 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13305 + dst += PAX_USER_SHADOW_BASE;
13306 +#endif
13307 +
13308 + return copy_user_generic((__force_kernel void *)dst, src, size);
13309 + }
13310 switch (size) {
13311 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
13312 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
13313 ret, "b", "b", "iq", 1);
13314 return ret;
13315 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
13316 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
13317 ret, "w", "w", "ir", 2);
13318 return ret;
13319 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
13320 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
13321 ret, "l", "k", "ir", 4);
13322 return ret;
13323 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
13324 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13325 ret, "q", "", "er", 8);
13326 return ret;
13327 case 10:
13328 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13329 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13330 ret, "q", "", "er", 10);
13331 if (unlikely(ret))
13332 return ret;
13333 asm("":::"memory");
13334 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
13335 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
13336 ret, "w", "w", "ir", 2);
13337 return ret;
13338 case 16:
13339 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
13340 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
13341 ret, "q", "", "er", 16);
13342 if (unlikely(ret))
13343 return ret;
13344 asm("":::"memory");
13345 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
13346 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
13347 ret, "q", "", "er", 8);
13348 return ret;
13349 default:
13350 - return copy_user_generic((__force void *)dst, src, size);
13351 +
13352 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13353 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13354 + dst += PAX_USER_SHADOW_BASE;
13355 +#endif
13356 +
13357 + return copy_user_generic((__force_kernel void *)dst, src, size);
13358 }
13359 }
13360
13361 static __always_inline __must_check
13362 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13363 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned long size)
13364 {
13365 - int ret = 0;
13366 + unsigned ret = 0;
13367
13368 might_fault();
13369 - if (!__builtin_constant_p(size))
13370 - return copy_user_generic((__force void *)dst,
13371 - (__force void *)src, size);
13372 +
13373 + if (size > INT_MAX)
13374 + return size;
13375 +
13376 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13377 + if (!__access_ok(VERIFY_READ, src, size))
13378 + return size;
13379 + if (!__access_ok(VERIFY_WRITE, dst, size))
13380 + return size;
13381 +#endif
13382 +
13383 + if (!__builtin_constant_p(size)) {
13384 +
13385 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13386 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13387 + src += PAX_USER_SHADOW_BASE;
13388 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13389 + dst += PAX_USER_SHADOW_BASE;
13390 +#endif
13391 +
13392 + return copy_user_generic((__force_kernel void *)dst,
13393 + (__force_kernel const void *)src, size);
13394 + }
13395 switch (size) {
13396 case 1: {
13397 u8 tmp;
13398 - __get_user_asm(tmp, (u8 __user *)src,
13399 + __get_user_asm(tmp, (const u8 __user *)src,
13400 ret, "b", "b", "=q", 1);
13401 if (likely(!ret))
13402 __put_user_asm(tmp, (u8 __user *)dst,
13403 @@ -176,7 +275,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13404 }
13405 case 2: {
13406 u16 tmp;
13407 - __get_user_asm(tmp, (u16 __user *)src,
13408 + __get_user_asm(tmp, (const u16 __user *)src,
13409 ret, "w", "w", "=r", 2);
13410 if (likely(!ret))
13411 __put_user_asm(tmp, (u16 __user *)dst,
13412 @@ -186,7 +285,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13413
13414 case 4: {
13415 u32 tmp;
13416 - __get_user_asm(tmp, (u32 __user *)src,
13417 + __get_user_asm(tmp, (const u32 __user *)src,
13418 ret, "l", "k", "=r", 4);
13419 if (likely(!ret))
13420 __put_user_asm(tmp, (u32 __user *)dst,
13421 @@ -195,7 +294,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13422 }
13423 case 8: {
13424 u64 tmp;
13425 - __get_user_asm(tmp, (u64 __user *)src,
13426 + __get_user_asm(tmp, (const u64 __user *)src,
13427 ret, "q", "", "=r", 8);
13428 if (likely(!ret))
13429 __put_user_asm(tmp, (u64 __user *)dst,
13430 @@ -203,44 +302,89 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
13431 return ret;
13432 }
13433 default:
13434 - return copy_user_generic((__force void *)dst,
13435 - (__force void *)src, size);
13436 +
13437 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13438 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13439 + src += PAX_USER_SHADOW_BASE;
13440 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13441 + dst += PAX_USER_SHADOW_BASE;
13442 +#endif
13443 +
13444 + return copy_user_generic((__force_kernel void *)dst,
13445 + (__force_kernel const void *)src, size);
13446 }
13447 }
13448
13449 -__must_check unsigned long clear_user(void __user *mem, unsigned long len);
13450 -__must_check unsigned long __clear_user(void __user *mem, unsigned long len);
13451 +__must_check unsigned long clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13452 +__must_check unsigned long __clear_user(void __user *mem, unsigned long len) __size_overflow(2);
13453
13454 static __must_check __always_inline int
13455 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
13456 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
13457 {
13458 - return copy_user_generic(dst, (__force const void *)src, size);
13459 + if (size > INT_MAX)
13460 + return size;
13461 +
13462 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13463 + if (!__access_ok(VERIFY_READ, src, size))
13464 + return size;
13465 +
13466 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
13467 + src += PAX_USER_SHADOW_BASE;
13468 +#endif
13469 +
13470 + return copy_user_generic(dst, (__force_kernel const void *)src, size);
13471 }
13472
13473 -static __must_check __always_inline int
13474 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
13475 +static __must_check __always_inline unsigned long
13476 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
13477 {
13478 - return copy_user_generic((__force void *)dst, src, size);
13479 + if (size > INT_MAX)
13480 + return size;
13481 +
13482 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13483 + if (!__access_ok(VERIFY_WRITE, dst, size))
13484 + return size;
13485 +
13486 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
13487 + dst += PAX_USER_SHADOW_BASE;
13488 +#endif
13489 +
13490 + return copy_user_generic((__force_kernel void *)dst, src, size);
13491 }
13492
13493 -extern long __copy_user_nocache(void *dst, const void __user *src,
13494 - unsigned size, int zerorest);
13495 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
13496 + unsigned long size, int zerorest) __size_overflow(3);
13497
13498 -static inline int
13499 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
13500 +static inline unsigned long __copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
13501 {
13502 might_sleep();
13503 +
13504 + if (size > INT_MAX)
13505 + return size;
13506 +
13507 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13508 + if (!__access_ok(VERIFY_READ, src, size))
13509 + return size;
13510 +#endif
13511 +
13512 return __copy_user_nocache(dst, src, size, 1);
13513 }
13514
13515 -static inline int
13516 -__copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13517 - unsigned size)
13518 +static inline unsigned long __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
13519 + unsigned long size)
13520 {
13521 + if (size > INT_MAX)
13522 + return size;
13523 +
13524 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13525 + if (!__access_ok(VERIFY_READ, src, size))
13526 + return size;
13527 +#endif
13528 +
13529 return __copy_user_nocache(dst, src, size, 0);
13530 }
13531
13532 -unsigned long
13533 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
13534 +extern unsigned long
13535 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
13536
13537 #endif /* _ASM_X86_UACCESS_64_H */
13538 diff --git a/arch/x86/include/asm/vdso.h b/arch/x86/include/asm/vdso.h
13539 index bb05228..d763d5b 100644
13540 --- a/arch/x86/include/asm/vdso.h
13541 +++ b/arch/x86/include/asm/vdso.h
13542 @@ -11,7 +11,7 @@ extern const char VDSO32_PRELINK[];
13543 #define VDSO32_SYMBOL(base, name) \
13544 ({ \
13545 extern const char VDSO32_##name[]; \
13546 - (void *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13547 + (void __user *)(VDSO32_##name - VDSO32_PRELINK + (unsigned long)(base)); \
13548 })
13549 #endif
13550
13551 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
13552 index 5b238981..77fdd78 100644
13553 --- a/arch/x86/include/asm/word-at-a-time.h
13554 +++ b/arch/x86/include/asm/word-at-a-time.h
13555 @@ -11,7 +11,7 @@
13556 * and shift, for example.
13557 */
13558 struct word_at_a_time {
13559 - const unsigned long one_bits, high_bits;
13560 + unsigned long one_bits, high_bits;
13561 };
13562
13563 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
13564 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
13565 index c090af1..7e7bf16 100644
13566 --- a/arch/x86/include/asm/x86_init.h
13567 +++ b/arch/x86/include/asm/x86_init.h
13568 @@ -29,7 +29,7 @@ struct x86_init_mpparse {
13569 void (*mpc_oem_bus_info)(struct mpc_bus *m, char *name);
13570 void (*find_smp_config)(void);
13571 void (*get_smp_config)(unsigned int early);
13572 -};
13573 +} __no_const;
13574
13575 /**
13576 * struct x86_init_resources - platform specific resource related ops
13577 @@ -43,7 +43,7 @@ struct x86_init_resources {
13578 void (*probe_roms)(void);
13579 void (*reserve_resources)(void);
13580 char *(*memory_setup)(void);
13581 -};
13582 +} __no_const;
13583
13584 /**
13585 * struct x86_init_irqs - platform specific interrupt setup
13586 @@ -56,7 +56,7 @@ struct x86_init_irqs {
13587 void (*pre_vector_init)(void);
13588 void (*intr_init)(void);
13589 void (*trap_init)(void);
13590 -};
13591 +} __no_const;
13592
13593 /**
13594 * struct x86_init_oem - oem platform specific customizing functions
13595 @@ -66,7 +66,7 @@ struct x86_init_irqs {
13596 struct x86_init_oem {
13597 void (*arch_setup)(void);
13598 void (*banner)(void);
13599 -};
13600 +} __no_const;
13601
13602 /**
13603 * struct x86_init_mapping - platform specific initial kernel pagetable setup
13604 @@ -77,7 +77,7 @@ struct x86_init_oem {
13605 */
13606 struct x86_init_mapping {
13607 void (*pagetable_reserve)(u64 start, u64 end);
13608 -};
13609 +} __no_const;
13610
13611 /**
13612 * struct x86_init_paging - platform specific paging functions
13613 @@ -87,7 +87,7 @@ struct x86_init_mapping {
13614 struct x86_init_paging {
13615 void (*pagetable_setup_start)(pgd_t *base);
13616 void (*pagetable_setup_done)(pgd_t *base);
13617 -};
13618 +} __no_const;
13619
13620 /**
13621 * struct x86_init_timers - platform specific timer setup
13622 @@ -102,7 +102,7 @@ struct x86_init_timers {
13623 void (*tsc_pre_init)(void);
13624 void (*timer_init)(void);
13625 void (*wallclock_init)(void);
13626 -};
13627 +} __no_const;
13628
13629 /**
13630 * struct x86_init_iommu - platform specific iommu setup
13631 @@ -110,7 +110,7 @@ struct x86_init_timers {
13632 */
13633 struct x86_init_iommu {
13634 int (*iommu_init)(void);
13635 -};
13636 +} __no_const;
13637
13638 /**
13639 * struct x86_init_pci - platform specific pci init functions
13640 @@ -124,7 +124,7 @@ struct x86_init_pci {
13641 int (*init)(void);
13642 void (*init_irq)(void);
13643 void (*fixup_irqs)(void);
13644 -};
13645 +} __no_const;
13646
13647 /**
13648 * struct x86_init_ops - functions for platform specific setup
13649 @@ -140,7 +140,7 @@ struct x86_init_ops {
13650 struct x86_init_timers timers;
13651 struct x86_init_iommu iommu;
13652 struct x86_init_pci pci;
13653 -};
13654 +} __no_const;
13655
13656 /**
13657 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
13658 @@ -151,7 +151,7 @@ struct x86_cpuinit_ops {
13659 void (*setup_percpu_clockev)(void);
13660 void (*early_percpu_clock_init)(void);
13661 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
13662 -};
13663 +} __no_const;
13664
13665 /**
13666 * struct x86_platform_ops - platform specific runtime functions
13667 @@ -177,7 +177,7 @@ struct x86_platform_ops {
13668 int (*i8042_detect)(void);
13669 void (*save_sched_clock_state)(void);
13670 void (*restore_sched_clock_state)(void);
13671 -};
13672 +} __no_const;
13673
13674 struct pci_dev;
13675
13676 @@ -186,14 +186,14 @@ struct x86_msi_ops {
13677 void (*teardown_msi_irq)(unsigned int irq);
13678 void (*teardown_msi_irqs)(struct pci_dev *dev);
13679 void (*restore_msi_irqs)(struct pci_dev *dev, int irq);
13680 -};
13681 +} __no_const;
13682
13683 struct x86_io_apic_ops {
13684 void (*init) (void);
13685 unsigned int (*read) (unsigned int apic, unsigned int reg);
13686 void (*write) (unsigned int apic, unsigned int reg, unsigned int value);
13687 void (*modify)(unsigned int apic, unsigned int reg, unsigned int value);
13688 -};
13689 +} __no_const;
13690
13691 extern struct x86_init_ops x86_init;
13692 extern struct x86_cpuinit_ops x86_cpuinit;
13693 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
13694 index 8a1b6f9..a29c4e4 100644
13695 --- a/arch/x86/include/asm/xsave.h
13696 +++ b/arch/x86/include/asm/xsave.h
13697 @@ -65,6 +65,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13698 {
13699 int err;
13700
13701 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13702 + if ((unsigned long)buf < PAX_USER_SHADOW_BASE)
13703 + buf = (struct xsave_struct __user *)((void __user*)buf + PAX_USER_SHADOW_BASE);
13704 +#endif
13705 +
13706 /*
13707 * Clear the xsave header first, so that reserved fields are
13708 * initialized to zero.
13709 @@ -93,10 +98,15 @@ static inline int xsave_user(struct xsave_struct __user *buf)
13710 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
13711 {
13712 int err;
13713 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
13714 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
13715 u32 lmask = mask;
13716 u32 hmask = mask >> 32;
13717
13718 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
13719 + if ((unsigned long)xstate < PAX_USER_SHADOW_BASE)
13720 + xstate = (struct xsave_struct *)((void *)xstate + PAX_USER_SHADOW_BASE);
13721 +#endif
13722 +
13723 __asm__ __volatile__("1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
13724 "2:\n"
13725 ".section .fixup,\"ax\"\n"
13726 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
13727 index 95bf99de..de9235c 100644
13728 --- a/arch/x86/kernel/acpi/sleep.c
13729 +++ b/arch/x86/kernel/acpi/sleep.c
13730 @@ -73,8 +73,12 @@ int acpi_suspend_lowlevel(void)
13731 #else /* CONFIG_64BIT */
13732 #ifdef CONFIG_SMP
13733 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
13734 +
13735 + pax_open_kernel();
13736 early_gdt_descr.address =
13737 (unsigned long)get_cpu_gdt_table(smp_processor_id());
13738 + pax_close_kernel();
13739 +
13740 initial_gs = per_cpu_offset(smp_processor_id());
13741 #endif
13742 initial_code = (unsigned long)wakeup_long64;
13743 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
13744 index 7261083..5c12053 100644
13745 --- a/arch/x86/kernel/acpi/wakeup_32.S
13746 +++ b/arch/x86/kernel/acpi/wakeup_32.S
13747 @@ -30,13 +30,11 @@ wakeup_pmode_return:
13748 # and restore the stack ... but you need gdt for this to work
13749 movl saved_context_esp, %esp
13750
13751 - movl %cs:saved_magic, %eax
13752 - cmpl $0x12345678, %eax
13753 + cmpl $0x12345678, saved_magic
13754 jne bogus_magic
13755
13756 # jump to place where we left off
13757 - movl saved_eip, %eax
13758 - jmp *%eax
13759 + jmp *(saved_eip)
13760
13761 bogus_magic:
13762 jmp bogus_magic
13763 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
13764 index 73ef56c..0238021 100644
13765 --- a/arch/x86/kernel/alternative.c
13766 +++ b/arch/x86/kernel/alternative.c
13767 @@ -276,6 +276,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
13768 */
13769 for (a = start; a < end; a++) {
13770 instr = (u8 *)&a->instr_offset + a->instr_offset;
13771 +
13772 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13773 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13774 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
13775 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13776 +#endif
13777 +
13778 replacement = (u8 *)&a->repl_offset + a->repl_offset;
13779 BUG_ON(a->replacementlen > a->instrlen);
13780 BUG_ON(a->instrlen > sizeof(insnbuf));
13781 @@ -307,10 +314,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
13782 for (poff = start; poff < end; poff++) {
13783 u8 *ptr = (u8 *)poff + *poff;
13784
13785 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13786 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13787 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13788 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13789 +#endif
13790 +
13791 if (!*poff || ptr < text || ptr >= text_end)
13792 continue;
13793 /* turn DS segment override prefix into lock prefix */
13794 - if (*ptr == 0x3e)
13795 + if (*ktla_ktva(ptr) == 0x3e)
13796 text_poke(ptr, ((unsigned char []){0xf0}), 1);
13797 };
13798 mutex_unlock(&text_mutex);
13799 @@ -328,10 +341,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
13800 for (poff = start; poff < end; poff++) {
13801 u8 *ptr = (u8 *)poff + *poff;
13802
13803 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
13804 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13805 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
13806 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
13807 +#endif
13808 +
13809 if (!*poff || ptr < text || ptr >= text_end)
13810 continue;
13811 /* turn lock prefix into DS segment override prefix */
13812 - if (*ptr == 0xf0)
13813 + if (*ktla_ktva(ptr) == 0xf0)
13814 text_poke(ptr, ((unsigned char []){0x3E}), 1);
13815 };
13816 mutex_unlock(&text_mutex);
13817 @@ -500,7 +519,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
13818
13819 BUG_ON(p->len > MAX_PATCH_LEN);
13820 /* prep the buffer with the original instructions */
13821 - memcpy(insnbuf, p->instr, p->len);
13822 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
13823 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
13824 (unsigned long)p->instr, p->len);
13825
13826 @@ -568,7 +587,7 @@ void __init alternative_instructions(void)
13827 if (smp_alt_once)
13828 free_init_pages("SMP alternatives",
13829 (unsigned long)__smp_locks,
13830 - (unsigned long)__smp_locks_end);
13831 + PAGE_ALIGN((unsigned long)__smp_locks_end));
13832
13833 restart_nmi();
13834 }
13835 @@ -585,13 +604,17 @@ void __init alternative_instructions(void)
13836 * instructions. And on the local CPU you need to be protected again NMI or MCE
13837 * handlers seeing an inconsistent instruction while you patch.
13838 */
13839 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
13840 +void *__kprobes text_poke_early(void *addr, const void *opcode,
13841 size_t len)
13842 {
13843 unsigned long flags;
13844 local_irq_save(flags);
13845 - memcpy(addr, opcode, len);
13846 +
13847 + pax_open_kernel();
13848 + memcpy(ktla_ktva(addr), opcode, len);
13849 sync_core();
13850 + pax_close_kernel();
13851 +
13852 local_irq_restore(flags);
13853 /* Could also do a CLFLUSH here to speed up CPU recovery; but
13854 that causes hangs on some VIA CPUs. */
13855 @@ -613,36 +636,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
13856 */
13857 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
13858 {
13859 - unsigned long flags;
13860 - char *vaddr;
13861 + unsigned char *vaddr = ktla_ktva(addr);
13862 struct page *pages[2];
13863 - int i;
13864 + size_t i;
13865
13866 if (!core_kernel_text((unsigned long)addr)) {
13867 - pages[0] = vmalloc_to_page(addr);
13868 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
13869 + pages[0] = vmalloc_to_page(vaddr);
13870 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
13871 } else {
13872 - pages[0] = virt_to_page(addr);
13873 + pages[0] = virt_to_page(vaddr);
13874 WARN_ON(!PageReserved(pages[0]));
13875 - pages[1] = virt_to_page(addr + PAGE_SIZE);
13876 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
13877 }
13878 BUG_ON(!pages[0]);
13879 - local_irq_save(flags);
13880 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
13881 - if (pages[1])
13882 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
13883 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
13884 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
13885 - clear_fixmap(FIX_TEXT_POKE0);
13886 - if (pages[1])
13887 - clear_fixmap(FIX_TEXT_POKE1);
13888 - local_flush_tlb();
13889 - sync_core();
13890 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
13891 - that causes hangs on some VIA CPUs. */
13892 + text_poke_early(addr, opcode, len);
13893 for (i = 0; i < len; i++)
13894 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
13895 - local_irq_restore(flags);
13896 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
13897 return addr;
13898 }
13899
13900 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
13901 index 39a222e..85a7767 100644
13902 --- a/arch/x86/kernel/apic/apic.c
13903 +++ b/arch/x86/kernel/apic/apic.c
13904 @@ -185,7 +185,7 @@ int first_system_vector = 0xfe;
13905 /*
13906 * Debug level, exported for io_apic.c
13907 */
13908 -unsigned int apic_verbosity;
13909 +int apic_verbosity;
13910
13911 int pic_mode;
13912
13913 @@ -1923,7 +1923,7 @@ void smp_error_interrupt(struct pt_regs *regs)
13914 apic_write(APIC_ESR, 0);
13915 v1 = apic_read(APIC_ESR);
13916 ack_APIC_irq();
13917 - atomic_inc(&irq_err_count);
13918 + atomic_inc_unchecked(&irq_err_count);
13919
13920 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
13921 smp_processor_id(), v0 , v1);
13922 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
13923 index 5f0ff59..f9e01bc 100644
13924 --- a/arch/x86/kernel/apic/io_apic.c
13925 +++ b/arch/x86/kernel/apic/io_apic.c
13926 @@ -1084,7 +1084,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
13927 }
13928 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
13929
13930 -void lock_vector_lock(void)
13931 +void lock_vector_lock(void) __acquires(vector_lock)
13932 {
13933 /* Used to the online set of cpus does not change
13934 * during assign_irq_vector.
13935 @@ -1092,7 +1092,7 @@ void lock_vector_lock(void)
13936 raw_spin_lock(&vector_lock);
13937 }
13938
13939 -void unlock_vector_lock(void)
13940 +void unlock_vector_lock(void) __releases(vector_lock)
13941 {
13942 raw_spin_unlock(&vector_lock);
13943 }
13944 @@ -2369,7 +2369,7 @@ static void ack_apic_edge(struct irq_data *data)
13945 ack_APIC_irq();
13946 }
13947
13948 -atomic_t irq_mis_count;
13949 +atomic_unchecked_t irq_mis_count;
13950
13951 #ifdef CONFIG_GENERIC_PENDING_IRQ
13952 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
13953 @@ -2510,7 +2510,7 @@ static void ack_apic_level(struct irq_data *data)
13954 * at the cpu.
13955 */
13956 if (!(v & (1 << (i & 0x1f)))) {
13957 - atomic_inc(&irq_mis_count);
13958 + atomic_inc_unchecked(&irq_mis_count);
13959
13960 eoi_ioapic_irq(irq, cfg);
13961 }
13962 diff --git a/arch/x86/kernel/apic/probe_64.c b/arch/x86/kernel/apic/probe_64.c
13963 index 3fe9866..6abf259 100644
13964 --- a/arch/x86/kernel/apic/probe_64.c
13965 +++ b/arch/x86/kernel/apic/probe_64.c
13966 @@ -50,7 +50,7 @@ void __init default_setup_apic_routing(void)
13967
13968 if (is_vsmp_box()) {
13969 /* need to update phys_pkg_id */
13970 - apic->phys_pkg_id = apicid_phys_pkg_id;
13971 + *(void **)&apic->phys_pkg_id = apicid_phys_pkg_id;
13972 }
13973 }
13974
13975 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
13976 index 07b0c0d..1df6f42 100644
13977 --- a/arch/x86/kernel/apm_32.c
13978 +++ b/arch/x86/kernel/apm_32.c
13979 @@ -410,7 +410,7 @@ static DEFINE_MUTEX(apm_mutex);
13980 * This is for buggy BIOS's that refer to (real mode) segment 0x40
13981 * even though they are called in protected mode.
13982 */
13983 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
13984 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
13985 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
13986
13987 static const char driver_version[] = "1.16ac"; /* no spaces */
13988 @@ -588,7 +588,10 @@ static long __apm_bios_call(void *_call)
13989 BUG_ON(cpu != 0);
13990 gdt = get_cpu_gdt_table(cpu);
13991 save_desc_40 = gdt[0x40 / 8];
13992 +
13993 + pax_open_kernel();
13994 gdt[0x40 / 8] = bad_bios_desc;
13995 + pax_close_kernel();
13996
13997 apm_irq_save(flags);
13998 APM_DO_SAVE_SEGS;
13999 @@ -597,7 +600,11 @@ static long __apm_bios_call(void *_call)
14000 &call->esi);
14001 APM_DO_RESTORE_SEGS;
14002 apm_irq_restore(flags);
14003 +
14004 + pax_open_kernel();
14005 gdt[0x40 / 8] = save_desc_40;
14006 + pax_close_kernel();
14007 +
14008 put_cpu();
14009
14010 return call->eax & 0xff;
14011 @@ -664,7 +671,10 @@ static long __apm_bios_call_simple(void *_call)
14012 BUG_ON(cpu != 0);
14013 gdt = get_cpu_gdt_table(cpu);
14014 save_desc_40 = gdt[0x40 / 8];
14015 +
14016 + pax_open_kernel();
14017 gdt[0x40 / 8] = bad_bios_desc;
14018 + pax_close_kernel();
14019
14020 apm_irq_save(flags);
14021 APM_DO_SAVE_SEGS;
14022 @@ -672,7 +682,11 @@ static long __apm_bios_call_simple(void *_call)
14023 &call->eax);
14024 APM_DO_RESTORE_SEGS;
14025 apm_irq_restore(flags);
14026 +
14027 + pax_open_kernel();
14028 gdt[0x40 / 8] = save_desc_40;
14029 + pax_close_kernel();
14030 +
14031 put_cpu();
14032 return error;
14033 }
14034 @@ -2345,12 +2359,15 @@ static int __init apm_init(void)
14035 * code to that CPU.
14036 */
14037 gdt = get_cpu_gdt_table(0);
14038 +
14039 + pax_open_kernel();
14040 set_desc_base(&gdt[APM_CS >> 3],
14041 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
14042 set_desc_base(&gdt[APM_CS_16 >> 3],
14043 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
14044 set_desc_base(&gdt[APM_DS >> 3],
14045 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
14046 + pax_close_kernel();
14047
14048 proc_create("apm", 0, NULL, &apm_file_ops);
14049
14050 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
14051 index 68de2dc..1f3c720 100644
14052 --- a/arch/x86/kernel/asm-offsets.c
14053 +++ b/arch/x86/kernel/asm-offsets.c
14054 @@ -33,6 +33,8 @@ void common(void) {
14055 OFFSET(TI_status, thread_info, status);
14056 OFFSET(TI_addr_limit, thread_info, addr_limit);
14057 OFFSET(TI_preempt_count, thread_info, preempt_count);
14058 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
14059 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
14060
14061 BLANK();
14062 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
14063 @@ -53,8 +55,26 @@ void common(void) {
14064 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
14065 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
14066 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
14067 +
14068 +#ifdef CONFIG_PAX_KERNEXEC
14069 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
14070 #endif
14071
14072 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14073 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
14074 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
14075 +#ifdef CONFIG_X86_64
14076 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
14077 +#endif
14078 +#endif
14079 +
14080 +#endif
14081 +
14082 + BLANK();
14083 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
14084 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
14085 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
14086 +
14087 #ifdef CONFIG_XEN
14088 BLANK();
14089 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
14090 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
14091 index 1b4754f..fbb4227 100644
14092 --- a/arch/x86/kernel/asm-offsets_64.c
14093 +++ b/arch/x86/kernel/asm-offsets_64.c
14094 @@ -76,6 +76,7 @@ int main(void)
14095 BLANK();
14096 #undef ENTRY
14097
14098 + DEFINE(TSS_size, sizeof(struct tss_struct));
14099 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
14100 BLANK();
14101
14102 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
14103 index 6ab6aa2..8f71507 100644
14104 --- a/arch/x86/kernel/cpu/Makefile
14105 +++ b/arch/x86/kernel/cpu/Makefile
14106 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
14107 CFLAGS_REMOVE_perf_event.o = -pg
14108 endif
14109
14110 -# Make sure load_percpu_segment has no stackprotector
14111 -nostackp := $(call cc-option, -fno-stack-protector)
14112 -CFLAGS_common.o := $(nostackp)
14113 -
14114 obj-y := intel_cacheinfo.o scattered.o topology.o
14115 obj-y += proc.o capflags.o powerflags.o common.o
14116 obj-y += vmware.o hypervisor.o sched.o mshyperv.o
14117 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
14118 index 146bb62..ac9c74a 100644
14119 --- a/arch/x86/kernel/cpu/amd.c
14120 +++ b/arch/x86/kernel/cpu/amd.c
14121 @@ -691,7 +691,7 @@ static unsigned int __cpuinit amd_size_cache(struct cpuinfo_x86 *c,
14122 unsigned int size)
14123 {
14124 /* AMD errata T13 (order #21922) */
14125 - if ((c->x86 == 6)) {
14126 + if (c->x86 == 6) {
14127 /* Duron Rev A0 */
14128 if (c->x86_model == 3 && c->x86_mask == 0)
14129 size = 64;
14130 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
14131 index cc9c146..2373d59 100644
14132 --- a/arch/x86/kernel/cpu/common.c
14133 +++ b/arch/x86/kernel/cpu/common.c
14134 @@ -86,60 +86,6 @@ static const struct cpu_dev __cpuinitconst default_cpu = {
14135
14136 static const struct cpu_dev *this_cpu __cpuinitdata = &default_cpu;
14137
14138 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
14139 -#ifdef CONFIG_X86_64
14140 - /*
14141 - * We need valid kernel segments for data and code in long mode too
14142 - * IRET will check the segment types kkeil 2000/10/28
14143 - * Also sysret mandates a special GDT layout
14144 - *
14145 - * TLS descriptors are currently at a different place compared to i386.
14146 - * Hopefully nobody expects them at a fixed place (Wine?)
14147 - */
14148 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
14149 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
14150 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
14151 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
14152 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
14153 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
14154 -#else
14155 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
14156 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14157 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
14158 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
14159 - /*
14160 - * Segments used for calling PnP BIOS have byte granularity.
14161 - * They code segments and data segments have fixed 64k limits,
14162 - * the transfer segment sizes are set at run time.
14163 - */
14164 - /* 32-bit code */
14165 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14166 - /* 16-bit code */
14167 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14168 - /* 16-bit data */
14169 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
14170 - /* 16-bit data */
14171 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
14172 - /* 16-bit data */
14173 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
14174 - /*
14175 - * The APM segments have byte granularity and their bases
14176 - * are set at run time. All have 64k limits.
14177 - */
14178 - /* 32-bit code */
14179 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
14180 - /* 16-bit code */
14181 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
14182 - /* data */
14183 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
14184 -
14185 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14186 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
14187 - GDT_STACK_CANARY_INIT
14188 -#endif
14189 -} };
14190 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
14191 -
14192 static int __init x86_xsave_setup(char *s)
14193 {
14194 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
14195 @@ -376,7 +322,7 @@ void switch_to_new_gdt(int cpu)
14196 {
14197 struct desc_ptr gdt_descr;
14198
14199 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
14200 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
14201 gdt_descr.size = GDT_SIZE - 1;
14202 load_gdt(&gdt_descr);
14203 /* Reload the per-cpu base */
14204 @@ -843,6 +789,10 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c)
14205 /* Filter out anything that depends on CPUID levels we don't have */
14206 filter_cpuid_features(c, true);
14207
14208 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
14209 + setup_clear_cpu_cap(X86_FEATURE_SEP);
14210 +#endif
14211 +
14212 /* If the model name is still unset, do table lookup. */
14213 if (!c->x86_model_id[0]) {
14214 const char *p;
14215 @@ -1023,10 +973,12 @@ static __init int setup_disablecpuid(char *arg)
14216 }
14217 __setup("clearcpuid=", setup_disablecpuid);
14218
14219 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
14220 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
14221 +
14222 #ifdef CONFIG_X86_64
14223 struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
14224 -struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1,
14225 - (unsigned long) nmi_idt_table };
14226 +struct desc_ptr nmi_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) nmi_idt_table };
14227
14228 DEFINE_PER_CPU_FIRST(union irq_stack_union,
14229 irq_stack_union) __aligned(PAGE_SIZE);
14230 @@ -1040,7 +992,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
14231 EXPORT_PER_CPU_SYMBOL(current_task);
14232
14233 DEFINE_PER_CPU(unsigned long, kernel_stack) =
14234 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
14235 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
14236 EXPORT_PER_CPU_SYMBOL(kernel_stack);
14237
14238 DEFINE_PER_CPU(char *, irq_stack_ptr) =
14239 @@ -1134,7 +1086,7 @@ struct pt_regs * __cpuinit idle_regs(struct pt_regs *regs)
14240 {
14241 memset(regs, 0, sizeof(struct pt_regs));
14242 regs->fs = __KERNEL_PERCPU;
14243 - regs->gs = __KERNEL_STACK_CANARY;
14244 + savesegment(gs, regs->gs);
14245
14246 return regs;
14247 }
14248 @@ -1189,7 +1141,7 @@ void __cpuinit cpu_init(void)
14249 int i;
14250
14251 cpu = stack_smp_processor_id();
14252 - t = &per_cpu(init_tss, cpu);
14253 + t = init_tss + cpu;
14254 oist = &per_cpu(orig_ist, cpu);
14255
14256 #ifdef CONFIG_NUMA
14257 @@ -1215,7 +1167,7 @@ void __cpuinit cpu_init(void)
14258 switch_to_new_gdt(cpu);
14259 loadsegment(fs, 0);
14260
14261 - load_idt((const struct desc_ptr *)&idt_descr);
14262 + load_idt(&idt_descr);
14263
14264 memset(me->thread.tls_array, 0, GDT_ENTRY_TLS_ENTRIES * 8);
14265 syscall_init();
14266 @@ -1224,7 +1176,6 @@ void __cpuinit cpu_init(void)
14267 wrmsrl(MSR_KERNEL_GS_BASE, 0);
14268 barrier();
14269
14270 - x86_configure_nx();
14271 if (cpu != 0)
14272 enable_x2apic();
14273
14274 @@ -1280,7 +1231,7 @@ void __cpuinit cpu_init(void)
14275 {
14276 int cpu = smp_processor_id();
14277 struct task_struct *curr = current;
14278 - struct tss_struct *t = &per_cpu(init_tss, cpu);
14279 + struct tss_struct *t = init_tss + cpu;
14280 struct thread_struct *thread = &curr->thread;
14281
14282 if (cpumask_test_and_set_cpu(cpu, cpu_initialized_mask)) {
14283 diff --git a/arch/x86/kernel/cpu/intel.c b/arch/x86/kernel/cpu/intel.c
14284 index 3e6ff6c..54b4992 100644
14285 --- a/arch/x86/kernel/cpu/intel.c
14286 +++ b/arch/x86/kernel/cpu/intel.c
14287 @@ -174,7 +174,7 @@ static void __cpuinit trap_init_f00f_bug(void)
14288 * Update the IDT descriptor and reload the IDT so that
14289 * it uses the read-only mapped virtual address.
14290 */
14291 - idt_descr.address = fix_to_virt(FIX_F00F_IDT);
14292 + idt_descr.address = (struct desc_struct *)fix_to_virt(FIX_F00F_IDT);
14293 load_idt(&idt_descr);
14294 }
14295 #endif
14296 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
14297 index c46ed49..5dc0a53 100644
14298 --- a/arch/x86/kernel/cpu/mcheck/mce.c
14299 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
14300 @@ -42,6 +42,7 @@
14301 #include <asm/processor.h>
14302 #include <asm/mce.h>
14303 #include <asm/msr.h>
14304 +#include <asm/local.h>
14305
14306 #include "mce-internal.h"
14307
14308 @@ -250,7 +251,7 @@ static void print_mce(struct mce *m)
14309 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
14310 m->cs, m->ip);
14311
14312 - if (m->cs == __KERNEL_CS)
14313 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
14314 print_symbol("{%s}", m->ip);
14315 pr_cont("\n");
14316 }
14317 @@ -283,10 +284,10 @@ static void print_mce(struct mce *m)
14318
14319 #define PANIC_TIMEOUT 5 /* 5 seconds */
14320
14321 -static atomic_t mce_paniced;
14322 +static atomic_unchecked_t mce_paniced;
14323
14324 static int fake_panic;
14325 -static atomic_t mce_fake_paniced;
14326 +static atomic_unchecked_t mce_fake_paniced;
14327
14328 /* Panic in progress. Enable interrupts and wait for final IPI */
14329 static void wait_for_panic(void)
14330 @@ -310,7 +311,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14331 /*
14332 * Make sure only one CPU runs in machine check panic
14333 */
14334 - if (atomic_inc_return(&mce_paniced) > 1)
14335 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
14336 wait_for_panic();
14337 barrier();
14338
14339 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
14340 console_verbose();
14341 } else {
14342 /* Don't log too much for fake panic */
14343 - if (atomic_inc_return(&mce_fake_paniced) > 1)
14344 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
14345 return;
14346 }
14347 /* First print corrected ones that are still unlogged */
14348 @@ -686,7 +687,7 @@ static int mce_timed_out(u64 *t)
14349 * might have been modified by someone else.
14350 */
14351 rmb();
14352 - if (atomic_read(&mce_paniced))
14353 + if (atomic_read_unchecked(&mce_paniced))
14354 wait_for_panic();
14355 if (!monarch_timeout)
14356 goto out;
14357 @@ -1581,7 +1582,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
14358 }
14359
14360 /* Call the installed machine check handler for this CPU setup. */
14361 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
14362 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
14363 unexpected_machine_check;
14364
14365 /*
14366 @@ -1604,7 +1605,9 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14367 return;
14368 }
14369
14370 + pax_open_kernel();
14371 machine_check_vector = do_machine_check;
14372 + pax_close_kernel();
14373
14374 __mcheck_cpu_init_generic();
14375 __mcheck_cpu_init_vendor(c);
14376 @@ -1618,7 +1621,7 @@ void __cpuinit mcheck_cpu_init(struct cpuinfo_x86 *c)
14377 */
14378
14379 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
14380 -static int mce_chrdev_open_count; /* #times opened */
14381 +static local_t mce_chrdev_open_count; /* #times opened */
14382 static int mce_chrdev_open_exclu; /* already open exclusive? */
14383
14384 static int mce_chrdev_open(struct inode *inode, struct file *file)
14385 @@ -1626,7 +1629,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14386 spin_lock(&mce_chrdev_state_lock);
14387
14388 if (mce_chrdev_open_exclu ||
14389 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
14390 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
14391 spin_unlock(&mce_chrdev_state_lock);
14392
14393 return -EBUSY;
14394 @@ -1634,7 +1637,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
14395
14396 if (file->f_flags & O_EXCL)
14397 mce_chrdev_open_exclu = 1;
14398 - mce_chrdev_open_count++;
14399 + local_inc(&mce_chrdev_open_count);
14400
14401 spin_unlock(&mce_chrdev_state_lock);
14402
14403 @@ -1645,7 +1648,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
14404 {
14405 spin_lock(&mce_chrdev_state_lock);
14406
14407 - mce_chrdev_open_count--;
14408 + local_dec(&mce_chrdev_open_count);
14409 mce_chrdev_open_exclu = 0;
14410
14411 spin_unlock(&mce_chrdev_state_lock);
14412 @@ -2370,7 +2373,7 @@ struct dentry *mce_get_debugfs_dir(void)
14413 static void mce_reset(void)
14414 {
14415 cpu_missing = 0;
14416 - atomic_set(&mce_fake_paniced, 0);
14417 + atomic_set_unchecked(&mce_fake_paniced, 0);
14418 atomic_set(&mce_executing, 0);
14419 atomic_set(&mce_callin, 0);
14420 atomic_set(&global_nwo, 0);
14421 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
14422 index 2d5454c..51987eb 100644
14423 --- a/arch/x86/kernel/cpu/mcheck/p5.c
14424 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
14425 @@ -11,6 +11,7 @@
14426 #include <asm/processor.h>
14427 #include <asm/mce.h>
14428 #include <asm/msr.h>
14429 +#include <asm/pgtable.h>
14430
14431 /* By default disabled */
14432 int mce_p5_enabled __read_mostly;
14433 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
14434 if (!cpu_has(c, X86_FEATURE_MCE))
14435 return;
14436
14437 + pax_open_kernel();
14438 machine_check_vector = pentium_machine_check;
14439 + pax_close_kernel();
14440 /* Make sure the vector pointer is visible before we enable MCEs: */
14441 wmb();
14442
14443 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
14444 index 2d7998f..17c9de1 100644
14445 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
14446 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
14447 @@ -10,6 +10,7 @@
14448 #include <asm/processor.h>
14449 #include <asm/mce.h>
14450 #include <asm/msr.h>
14451 +#include <asm/pgtable.h>
14452
14453 /* Machine check handler for WinChip C6: */
14454 static void winchip_machine_check(struct pt_regs *regs, long error_code)
14455 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
14456 {
14457 u32 lo, hi;
14458
14459 + pax_open_kernel();
14460 machine_check_vector = winchip_machine_check;
14461 + pax_close_kernel();
14462 /* Make sure the vector pointer is visible before we enable MCEs: */
14463 wmb();
14464
14465 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
14466 index 6b96110..0da73eb 100644
14467 --- a/arch/x86/kernel/cpu/mtrr/main.c
14468 +++ b/arch/x86/kernel/cpu/mtrr/main.c
14469 @@ -62,7 +62,7 @@ static DEFINE_MUTEX(mtrr_mutex);
14470 u64 size_or_mask, size_and_mask;
14471 static bool mtrr_aps_delayed_init;
14472
14473 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
14474 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
14475
14476 const struct mtrr_ops *mtrr_if;
14477
14478 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
14479 index df5e41f..816c719 100644
14480 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
14481 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
14482 @@ -25,7 +25,7 @@ struct mtrr_ops {
14483 int (*validate_add_page)(unsigned long base, unsigned long size,
14484 unsigned int type);
14485 int (*have_wrcomb)(void);
14486 -};
14487 +} __do_const;
14488
14489 extern int generic_get_free_region(unsigned long base, unsigned long size,
14490 int replace_reg);
14491 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
14492 index c4706cf..264b0f7 100644
14493 --- a/arch/x86/kernel/cpu/perf_event.c
14494 +++ b/arch/x86/kernel/cpu/perf_event.c
14495 @@ -1837,7 +1837,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
14496 break;
14497
14498 perf_callchain_store(entry, frame.return_address);
14499 - fp = frame.next_frame;
14500 + fp = (const void __force_user *)frame.next_frame;
14501 }
14502 }
14503
14504 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
14505 index 187c294..28a069c 100644
14506 --- a/arch/x86/kernel/cpu/perf_event_intel.c
14507 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
14508 @@ -1811,10 +1811,10 @@ __init int intel_pmu_init(void)
14509 * v2 and above have a perf capabilities MSR
14510 */
14511 if (version > 1) {
14512 - u64 capabilities;
14513 + u64 capabilities = x86_pmu.intel_cap.capabilities;
14514
14515 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
14516 - x86_pmu.intel_cap.capabilities = capabilities;
14517 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
14518 + x86_pmu.intel_cap.capabilities = capabilities;
14519 }
14520
14521 intel_ds_init();
14522 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
14523 index 13ad899..f642b9a 100644
14524 --- a/arch/x86/kernel/crash.c
14525 +++ b/arch/x86/kernel/crash.c
14526 @@ -36,10 +36,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
14527 {
14528 #ifdef CONFIG_X86_32
14529 struct pt_regs fixed_regs;
14530 -#endif
14531
14532 -#ifdef CONFIG_X86_32
14533 - if (!user_mode_vm(regs)) {
14534 + if (!user_mode(regs)) {
14535 crash_fixup_ss_esp(&fixed_regs, regs);
14536 regs = &fixed_regs;
14537 }
14538 diff --git a/arch/x86/kernel/doublefault_32.c b/arch/x86/kernel/doublefault_32.c
14539 index 37250fe..bf2ec74 100644
14540 --- a/arch/x86/kernel/doublefault_32.c
14541 +++ b/arch/x86/kernel/doublefault_32.c
14542 @@ -11,7 +11,7 @@
14543
14544 #define DOUBLEFAULT_STACKSIZE (1024)
14545 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
14546 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
14547 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
14548
14549 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
14550
14551 @@ -21,7 +21,7 @@ static void doublefault_fn(void)
14552 unsigned long gdt, tss;
14553
14554 store_gdt(&gdt_desc);
14555 - gdt = gdt_desc.address;
14556 + gdt = (unsigned long)gdt_desc.address;
14557
14558 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
14559
14560 @@ -58,10 +58,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
14561 /* 0x2 bit is always set */
14562 .flags = X86_EFLAGS_SF | 0x2,
14563 .sp = STACK_START,
14564 - .es = __USER_DS,
14565 + .es = __KERNEL_DS,
14566 .cs = __KERNEL_CS,
14567 .ss = __KERNEL_DS,
14568 - .ds = __USER_DS,
14569 + .ds = __KERNEL_DS,
14570 .fs = __KERNEL_PERCPU,
14571
14572 .__cr3 = __pa_nodebug(swapper_pg_dir),
14573 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
14574 index 571246d..81f335c 100644
14575 --- a/arch/x86/kernel/dumpstack.c
14576 +++ b/arch/x86/kernel/dumpstack.c
14577 @@ -2,6 +2,9 @@
14578 * Copyright (C) 1991, 1992 Linus Torvalds
14579 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
14580 */
14581 +#ifdef CONFIG_GRKERNSEC_HIDESYM
14582 +#define __INCLUDED_BY_HIDESYM 1
14583 +#endif
14584 #include <linux/kallsyms.h>
14585 #include <linux/kprobes.h>
14586 #include <linux/uaccess.h>
14587 @@ -35,16 +38,14 @@ void printk_address(unsigned long address, int reliable)
14588 static void
14589 print_ftrace_graph_addr(unsigned long addr, void *data,
14590 const struct stacktrace_ops *ops,
14591 - struct thread_info *tinfo, int *graph)
14592 + struct task_struct *task, int *graph)
14593 {
14594 - struct task_struct *task;
14595 unsigned long ret_addr;
14596 int index;
14597
14598 if (addr != (unsigned long)return_to_handler)
14599 return;
14600
14601 - task = tinfo->task;
14602 index = task->curr_ret_stack;
14603
14604 if (!task->ret_stack || index < *graph)
14605 @@ -61,7 +62,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14606 static inline void
14607 print_ftrace_graph_addr(unsigned long addr, void *data,
14608 const struct stacktrace_ops *ops,
14609 - struct thread_info *tinfo, int *graph)
14610 + struct task_struct *task, int *graph)
14611 { }
14612 #endif
14613
14614 @@ -72,10 +73,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
14615 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
14616 */
14617
14618 -static inline int valid_stack_ptr(struct thread_info *tinfo,
14619 - void *p, unsigned int size, void *end)
14620 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
14621 {
14622 - void *t = tinfo;
14623 if (end) {
14624 if (p < end && p >= (end-THREAD_SIZE))
14625 return 1;
14626 @@ -86,14 +85,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
14627 }
14628
14629 unsigned long
14630 -print_context_stack(struct thread_info *tinfo,
14631 +print_context_stack(struct task_struct *task, void *stack_start,
14632 unsigned long *stack, unsigned long bp,
14633 const struct stacktrace_ops *ops, void *data,
14634 unsigned long *end, int *graph)
14635 {
14636 struct stack_frame *frame = (struct stack_frame *)bp;
14637
14638 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
14639 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
14640 unsigned long addr;
14641
14642 addr = *stack;
14643 @@ -105,7 +104,7 @@ print_context_stack(struct thread_info *tinfo,
14644 } else {
14645 ops->address(data, addr, 0);
14646 }
14647 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14648 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14649 }
14650 stack++;
14651 }
14652 @@ -114,7 +113,7 @@ print_context_stack(struct thread_info *tinfo,
14653 EXPORT_SYMBOL_GPL(print_context_stack);
14654
14655 unsigned long
14656 -print_context_stack_bp(struct thread_info *tinfo,
14657 +print_context_stack_bp(struct task_struct *task, void *stack_start,
14658 unsigned long *stack, unsigned long bp,
14659 const struct stacktrace_ops *ops, void *data,
14660 unsigned long *end, int *graph)
14661 @@ -122,7 +121,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14662 struct stack_frame *frame = (struct stack_frame *)bp;
14663 unsigned long *ret_addr = &frame->return_address;
14664
14665 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
14666 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
14667 unsigned long addr = *ret_addr;
14668
14669 if (!__kernel_text_address(addr))
14670 @@ -131,7 +130,7 @@ print_context_stack_bp(struct thread_info *tinfo,
14671 ops->address(data, addr, 1);
14672 frame = frame->next_frame;
14673 ret_addr = &frame->return_address;
14674 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
14675 + print_ftrace_graph_addr(addr, data, ops, task, graph);
14676 }
14677
14678 return (unsigned long)frame;
14679 @@ -189,7 +188,7 @@ void dump_stack(void)
14680
14681 bp = stack_frame(current, NULL);
14682 printk("Pid: %d, comm: %.20s %s %s %.*s\n",
14683 - current->pid, current->comm, print_tainted(),
14684 + task_pid_nr(current), current->comm, print_tainted(),
14685 init_utsname()->release,
14686 (int)strcspn(init_utsname()->version, " "),
14687 init_utsname()->version);
14688 @@ -225,6 +224,8 @@ unsigned __kprobes long oops_begin(void)
14689 }
14690 EXPORT_SYMBOL_GPL(oops_begin);
14691
14692 +extern void gr_handle_kernel_exploit(void);
14693 +
14694 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14695 {
14696 if (regs && kexec_should_crash(current))
14697 @@ -246,7 +247,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
14698 panic("Fatal exception in interrupt");
14699 if (panic_on_oops)
14700 panic("Fatal exception");
14701 - do_exit(signr);
14702 +
14703 + gr_handle_kernel_exploit();
14704 +
14705 + do_group_exit(signr);
14706 }
14707
14708 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14709 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
14710
14711 show_regs(regs);
14712 #ifdef CONFIG_X86_32
14713 - if (user_mode_vm(regs)) {
14714 + if (user_mode(regs)) {
14715 sp = regs->sp;
14716 ss = regs->ss & 0xffff;
14717 } else {
14718 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
14719 unsigned long flags = oops_begin();
14720 int sig = SIGSEGV;
14721
14722 - if (!user_mode_vm(regs))
14723 + if (!user_mode(regs))
14724 report_bug(regs->ip, regs);
14725
14726 if (__die(str, regs, err))
14727 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
14728 index e0b1d78..a8ade5e 100644
14729 --- a/arch/x86/kernel/dumpstack_32.c
14730 +++ b/arch/x86/kernel/dumpstack_32.c
14731 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14732 bp = stack_frame(task, regs);
14733
14734 for (;;) {
14735 - struct thread_info *context;
14736 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14737
14738 - context = (struct thread_info *)
14739 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
14740 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
14741 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14742
14743 - stack = (unsigned long *)context->previous_esp;
14744 - if (!stack)
14745 + if (stack_start == task_stack_page(task))
14746 break;
14747 + stack = *(unsigned long **)stack_start;
14748 if (ops->stack(data, "IRQ") < 0)
14749 break;
14750 touch_nmi_watchdog();
14751 @@ -87,7 +85,7 @@ void show_regs(struct pt_regs *regs)
14752 int i;
14753
14754 print_modules();
14755 - __show_regs(regs, !user_mode_vm(regs));
14756 + __show_regs(regs, !user_mode(regs));
14757
14758 printk(KERN_EMERG "Process %.*s (pid: %d, ti=%p task=%p task.ti=%p)\n",
14759 TASK_COMM_LEN, current->comm, task_pid_nr(current),
14760 @@ -96,21 +94,22 @@ void show_regs(struct pt_regs *regs)
14761 * When in-kernel, we also print out the stack and code at the
14762 * time of the fault..
14763 */
14764 - if (!user_mode_vm(regs)) {
14765 + if (!user_mode(regs)) {
14766 unsigned int code_prologue = code_bytes * 43 / 64;
14767 unsigned int code_len = code_bytes;
14768 unsigned char c;
14769 u8 *ip;
14770 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(smp_processor_id())[(0xffff & regs->cs) >> 3]);
14771
14772 printk(KERN_EMERG "Stack:\n");
14773 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
14774
14775 printk(KERN_EMERG "Code: ");
14776
14777 - ip = (u8 *)regs->ip - code_prologue;
14778 + ip = (u8 *)regs->ip - code_prologue + cs_base;
14779 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
14780 /* try starting at IP */
14781 - ip = (u8 *)regs->ip;
14782 + ip = (u8 *)regs->ip + cs_base;
14783 code_len = code_len - code_prologue + 1;
14784 }
14785 for (i = 0; i < code_len; i++, ip++) {
14786 @@ -119,7 +118,7 @@ void show_regs(struct pt_regs *regs)
14787 printk(KERN_CONT " Bad EIP value.");
14788 break;
14789 }
14790 - if (ip == (u8 *)regs->ip)
14791 + if (ip == (u8 *)regs->ip + cs_base)
14792 printk(KERN_CONT "<%02x> ", c);
14793 else
14794 printk(KERN_CONT "%02x ", c);
14795 @@ -132,6 +131,7 @@ int is_valid_bugaddr(unsigned long ip)
14796 {
14797 unsigned short ud2;
14798
14799 + ip = ktla_ktva(ip);
14800 if (ip < PAGE_OFFSET)
14801 return 0;
14802 if (probe_kernel_address((unsigned short *)ip, ud2))
14803 @@ -139,3 +139,15 @@ int is_valid_bugaddr(unsigned long ip)
14804
14805 return ud2 == 0x0b0f;
14806 }
14807 +
14808 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14809 +void pax_check_alloca(unsigned long size)
14810 +{
14811 + unsigned long sp = (unsigned long)&sp, stack_left;
14812 +
14813 + /* all kernel stacks are of the same size */
14814 + stack_left = sp & (THREAD_SIZE - 1);
14815 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14816 +}
14817 +EXPORT_SYMBOL(pax_check_alloca);
14818 +#endif
14819 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
14820 index 791b761..2ab6e33 100644
14821 --- a/arch/x86/kernel/dumpstack_64.c
14822 +++ b/arch/x86/kernel/dumpstack_64.c
14823 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14824 unsigned long *irq_stack_end =
14825 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
14826 unsigned used = 0;
14827 - struct thread_info *tinfo;
14828 int graph = 0;
14829 unsigned long dummy;
14830 + void *stack_start;
14831
14832 if (!task)
14833 task = current;
14834 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14835 * current stack address. If the stacks consist of nested
14836 * exceptions
14837 */
14838 - tinfo = task_thread_info(task);
14839 for (;;) {
14840 char *id;
14841 unsigned long *estack_end;
14842 +
14843 estack_end = in_exception_stack(cpu, (unsigned long)stack,
14844 &used, &id);
14845
14846 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14847 if (ops->stack(data, id) < 0)
14848 break;
14849
14850 - bp = ops->walk_stack(tinfo, stack, bp, ops,
14851 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
14852 data, estack_end, &graph);
14853 ops->stack(data, "<EOE>");
14854 /*
14855 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14856 * second-to-last pointer (index -2 to end) in the
14857 * exception stack:
14858 */
14859 + if ((u16)estack_end[-1] != __KERNEL_DS)
14860 + goto out;
14861 stack = (unsigned long *) estack_end[-2];
14862 continue;
14863 }
14864 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14865 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
14866 if (ops->stack(data, "IRQ") < 0)
14867 break;
14868 - bp = ops->walk_stack(tinfo, stack, bp,
14869 + bp = ops->walk_stack(task, irq_stack, stack, bp,
14870 ops, data, irq_stack_end, &graph);
14871 /*
14872 * We link to the next stack (which would be
14873 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
14874 /*
14875 * This handles the process stack:
14876 */
14877 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
14878 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
14879 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
14880 +out:
14881 put_cpu();
14882 }
14883 EXPORT_SYMBOL(dump_trace);
14884 @@ -305,3 +309,50 @@ int is_valid_bugaddr(unsigned long ip)
14885
14886 return ud2 == 0x0b0f;
14887 }
14888 +
14889 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
14890 +void pax_check_alloca(unsigned long size)
14891 +{
14892 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
14893 + unsigned cpu, used;
14894 + char *id;
14895 +
14896 + /* check the process stack first */
14897 + stack_start = (unsigned long)task_stack_page(current);
14898 + stack_end = stack_start + THREAD_SIZE;
14899 + if (likely(stack_start <= sp && sp < stack_end)) {
14900 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
14901 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14902 + return;
14903 + }
14904 +
14905 + cpu = get_cpu();
14906 +
14907 + /* check the irq stacks */
14908 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
14909 + stack_start = stack_end - IRQ_STACK_SIZE;
14910 + if (stack_start <= sp && sp < stack_end) {
14911 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
14912 + put_cpu();
14913 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14914 + return;
14915 + }
14916 +
14917 + /* check the exception stacks */
14918 + used = 0;
14919 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
14920 + stack_start = stack_end - EXCEPTION_STKSZ;
14921 + if (stack_end && stack_start <= sp && sp < stack_end) {
14922 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
14923 + put_cpu();
14924 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
14925 + return;
14926 + }
14927 +
14928 + put_cpu();
14929 +
14930 + /* unknown stack */
14931 + BUG();
14932 +}
14933 +EXPORT_SYMBOL(pax_check_alloca);
14934 +#endif
14935 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
14936 index 9b9f18b..9fcaa04 100644
14937 --- a/arch/x86/kernel/early_printk.c
14938 +++ b/arch/x86/kernel/early_printk.c
14939 @@ -7,6 +7,7 @@
14940 #include <linux/pci_regs.h>
14941 #include <linux/pci_ids.h>
14942 #include <linux/errno.h>
14943 +#include <linux/sched.h>
14944 #include <asm/io.h>
14945 #include <asm/processor.h>
14946 #include <asm/fcntl.h>
14947 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
14948 index 623f288..8bdd78a 100644
14949 --- a/arch/x86/kernel/entry_32.S
14950 +++ b/arch/x86/kernel/entry_32.S
14951 @@ -176,13 +176,153 @@
14952 /*CFI_REL_OFFSET gs, PT_GS*/
14953 .endm
14954 .macro SET_KERNEL_GS reg
14955 +
14956 +#ifdef CONFIG_CC_STACKPROTECTOR
14957 movl $(__KERNEL_STACK_CANARY), \reg
14958 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
14959 + movl $(__USER_DS), \reg
14960 +#else
14961 + xorl \reg, \reg
14962 +#endif
14963 +
14964 movl \reg, %gs
14965 .endm
14966
14967 #endif /* CONFIG_X86_32_LAZY_GS */
14968
14969 -.macro SAVE_ALL
14970 +.macro pax_enter_kernel
14971 +#ifdef CONFIG_PAX_KERNEXEC
14972 + call pax_enter_kernel
14973 +#endif
14974 +.endm
14975 +
14976 +.macro pax_exit_kernel
14977 +#ifdef CONFIG_PAX_KERNEXEC
14978 + call pax_exit_kernel
14979 +#endif
14980 +.endm
14981 +
14982 +#ifdef CONFIG_PAX_KERNEXEC
14983 +ENTRY(pax_enter_kernel)
14984 +#ifdef CONFIG_PARAVIRT
14985 + pushl %eax
14986 + pushl %ecx
14987 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
14988 + mov %eax, %esi
14989 +#else
14990 + mov %cr0, %esi
14991 +#endif
14992 + bts $16, %esi
14993 + jnc 1f
14994 + mov %cs, %esi
14995 + cmp $__KERNEL_CS, %esi
14996 + jz 3f
14997 + ljmp $__KERNEL_CS, $3f
14998 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
14999 +2:
15000 +#ifdef CONFIG_PARAVIRT
15001 + mov %esi, %eax
15002 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
15003 +#else
15004 + mov %esi, %cr0
15005 +#endif
15006 +3:
15007 +#ifdef CONFIG_PARAVIRT
15008 + popl %ecx
15009 + popl %eax
15010 +#endif
15011 + ret
15012 +ENDPROC(pax_enter_kernel)
15013 +
15014 +ENTRY(pax_exit_kernel)
15015 +#ifdef CONFIG_PARAVIRT
15016 + pushl %eax
15017 + pushl %ecx
15018 +#endif
15019 + mov %cs, %esi
15020 + cmp $__KERNEXEC_KERNEL_CS, %esi
15021 + jnz 2f
15022 +#ifdef CONFIG_PARAVIRT
15023 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
15024 + mov %eax, %esi
15025 +#else
15026 + mov %cr0, %esi
15027 +#endif
15028 + btr $16, %esi
15029 + ljmp $__KERNEL_CS, $1f
15030 +1:
15031 +#ifdef CONFIG_PARAVIRT
15032 + mov %esi, %eax
15033 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
15034 +#else
15035 + mov %esi, %cr0
15036 +#endif
15037 +2:
15038 +#ifdef CONFIG_PARAVIRT
15039 + popl %ecx
15040 + popl %eax
15041 +#endif
15042 + ret
15043 +ENDPROC(pax_exit_kernel)
15044 +#endif
15045 +
15046 +.macro pax_erase_kstack
15047 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15048 + call pax_erase_kstack
15049 +#endif
15050 +.endm
15051 +
15052 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
15053 +/*
15054 + * ebp: thread_info
15055 + */
15056 +ENTRY(pax_erase_kstack)
15057 + pushl %edi
15058 + pushl %ecx
15059 + pushl %eax
15060 +
15061 + mov TI_lowest_stack(%ebp), %edi
15062 + mov $-0xBEEF, %eax
15063 + std
15064 +
15065 +1: mov %edi, %ecx
15066 + and $THREAD_SIZE_asm - 1, %ecx
15067 + shr $2, %ecx
15068 + repne scasl
15069 + jecxz 2f
15070 +
15071 + cmp $2*16, %ecx
15072 + jc 2f
15073 +
15074 + mov $2*16, %ecx
15075 + repe scasl
15076 + jecxz 2f
15077 + jne 1b
15078 +
15079 +2: cld
15080 + mov %esp, %ecx
15081 + sub %edi, %ecx
15082 +
15083 + cmp $THREAD_SIZE_asm, %ecx
15084 + jb 3f
15085 + ud2
15086 +3:
15087 +
15088 + shr $2, %ecx
15089 + rep stosl
15090 +
15091 + mov TI_task_thread_sp0(%ebp), %edi
15092 + sub $128, %edi
15093 + mov %edi, TI_lowest_stack(%ebp)
15094 +
15095 + popl %eax
15096 + popl %ecx
15097 + popl %edi
15098 + ret
15099 +ENDPROC(pax_erase_kstack)
15100 +#endif
15101 +
15102 +.macro __SAVE_ALL _DS
15103 cld
15104 PUSH_GS
15105 pushl_cfi %fs
15106 @@ -205,7 +345,7 @@
15107 CFI_REL_OFFSET ecx, 0
15108 pushl_cfi %ebx
15109 CFI_REL_OFFSET ebx, 0
15110 - movl $(__USER_DS), %edx
15111 + movl $\_DS, %edx
15112 movl %edx, %ds
15113 movl %edx, %es
15114 movl $(__KERNEL_PERCPU), %edx
15115 @@ -213,6 +353,15 @@
15116 SET_KERNEL_GS %edx
15117 .endm
15118
15119 +.macro SAVE_ALL
15120 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
15121 + __SAVE_ALL __KERNEL_DS
15122 + pax_enter_kernel
15123 +#else
15124 + __SAVE_ALL __USER_DS
15125 +#endif
15126 +.endm
15127 +
15128 .macro RESTORE_INT_REGS
15129 popl_cfi %ebx
15130 CFI_RESTORE ebx
15131 @@ -296,7 +445,7 @@ ENTRY(ret_from_fork)
15132 popfl_cfi
15133 jmp syscall_exit
15134 CFI_ENDPROC
15135 -END(ret_from_fork)
15136 +ENDPROC(ret_from_fork)
15137
15138 /*
15139 * Interrupt exit functions should be protected against kprobes
15140 @@ -329,7 +478,15 @@ ret_from_intr:
15141 andl $SEGMENT_RPL_MASK, %eax
15142 #endif
15143 cmpl $USER_RPL, %eax
15144 +
15145 +#ifdef CONFIG_PAX_KERNEXEC
15146 + jae resume_userspace
15147 +
15148 + pax_exit_kernel
15149 + jmp resume_kernel
15150 +#else
15151 jb resume_kernel # not returning to v8086 or userspace
15152 +#endif
15153
15154 ENTRY(resume_userspace)
15155 LOCKDEP_SYS_EXIT
15156 @@ -341,8 +498,8 @@ ENTRY(resume_userspace)
15157 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
15158 # int/exception return?
15159 jne work_pending
15160 - jmp restore_all
15161 -END(ret_from_exception)
15162 + jmp restore_all_pax
15163 +ENDPROC(ret_from_exception)
15164
15165 #ifdef CONFIG_PREEMPT
15166 ENTRY(resume_kernel)
15167 @@ -357,7 +514,7 @@ need_resched:
15168 jz restore_all
15169 call preempt_schedule_irq
15170 jmp need_resched
15171 -END(resume_kernel)
15172 +ENDPROC(resume_kernel)
15173 #endif
15174 CFI_ENDPROC
15175 /*
15176 @@ -391,28 +548,43 @@ sysenter_past_esp:
15177 /*CFI_REL_OFFSET cs, 0*/
15178 /*
15179 * Push current_thread_info()->sysenter_return to the stack.
15180 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
15181 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
15182 */
15183 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
15184 + pushl_cfi $0
15185 CFI_REL_OFFSET eip, 0
15186
15187 pushl_cfi %eax
15188 SAVE_ALL
15189 + GET_THREAD_INFO(%ebp)
15190 + movl TI_sysenter_return(%ebp),%ebp
15191 + movl %ebp,PT_EIP(%esp)
15192 ENABLE_INTERRUPTS(CLBR_NONE)
15193
15194 /*
15195 * Load the potential sixth argument from user stack.
15196 * Careful about security.
15197 */
15198 + movl PT_OLDESP(%esp),%ebp
15199 +
15200 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15201 + mov PT_OLDSS(%esp),%ds
15202 +1: movl %ds:(%ebp),%ebp
15203 + push %ss
15204 + pop %ds
15205 +#else
15206 cmpl $__PAGE_OFFSET-3,%ebp
15207 jae syscall_fault
15208 1: movl (%ebp),%ebp
15209 +#endif
15210 +
15211 movl %ebp,PT_EBP(%esp)
15212 _ASM_EXTABLE(1b,syscall_fault)
15213
15214 GET_THREAD_INFO(%ebp)
15215
15216 +#ifdef CONFIG_PAX_RANDKSTACK
15217 + pax_erase_kstack
15218 +#endif
15219 +
15220 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15221 jnz sysenter_audit
15222 sysenter_do_call:
15223 @@ -427,12 +599,24 @@ sysenter_do_call:
15224 testl $_TIF_ALLWORK_MASK, %ecx
15225 jne sysexit_audit
15226 sysenter_exit:
15227 +
15228 +#ifdef CONFIG_PAX_RANDKSTACK
15229 + pushl_cfi %eax
15230 + movl %esp, %eax
15231 + call pax_randomize_kstack
15232 + popl_cfi %eax
15233 +#endif
15234 +
15235 + pax_erase_kstack
15236 +
15237 /* if something modifies registers it must also disable sysexit */
15238 movl PT_EIP(%esp), %edx
15239 movl PT_OLDESP(%esp), %ecx
15240 xorl %ebp,%ebp
15241 TRACE_IRQS_ON
15242 1: mov PT_FS(%esp), %fs
15243 +2: mov PT_DS(%esp), %ds
15244 +3: mov PT_ES(%esp), %es
15245 PTGS_TO_GS
15246 ENABLE_INTERRUPTS_SYSEXIT
15247
15248 @@ -449,6 +633,9 @@ sysenter_audit:
15249 movl %eax,%edx /* 2nd arg: syscall number */
15250 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
15251 call __audit_syscall_entry
15252 +
15253 + pax_erase_kstack
15254 +
15255 pushl_cfi %ebx
15256 movl PT_EAX(%esp),%eax /* reload syscall number */
15257 jmp sysenter_do_call
15258 @@ -474,10 +661,16 @@ sysexit_audit:
15259
15260 CFI_ENDPROC
15261 .pushsection .fixup,"ax"
15262 -2: movl $0,PT_FS(%esp)
15263 +4: movl $0,PT_FS(%esp)
15264 + jmp 1b
15265 +5: movl $0,PT_DS(%esp)
15266 + jmp 1b
15267 +6: movl $0,PT_ES(%esp)
15268 jmp 1b
15269 .popsection
15270 - _ASM_EXTABLE(1b,2b)
15271 + _ASM_EXTABLE(1b,4b)
15272 + _ASM_EXTABLE(2b,5b)
15273 + _ASM_EXTABLE(3b,6b)
15274 PTGS_TO_GS_EX
15275 ENDPROC(ia32_sysenter_target)
15276
15277 @@ -491,6 +684,11 @@ ENTRY(system_call)
15278 pushl_cfi %eax # save orig_eax
15279 SAVE_ALL
15280 GET_THREAD_INFO(%ebp)
15281 +
15282 +#ifdef CONFIG_PAX_RANDKSTACK
15283 + pax_erase_kstack
15284 +#endif
15285 +
15286 # system call tracing in operation / emulation
15287 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
15288 jnz syscall_trace_entry
15289 @@ -509,6 +707,15 @@ syscall_exit:
15290 testl $_TIF_ALLWORK_MASK, %ecx # current->work
15291 jne syscall_exit_work
15292
15293 +restore_all_pax:
15294 +
15295 +#ifdef CONFIG_PAX_RANDKSTACK
15296 + movl %esp, %eax
15297 + call pax_randomize_kstack
15298 +#endif
15299 +
15300 + pax_erase_kstack
15301 +
15302 restore_all:
15303 TRACE_IRQS_IRET
15304 restore_all_notrace:
15305 @@ -565,14 +772,34 @@ ldt_ss:
15306 * compensating for the offset by changing to the ESPFIX segment with
15307 * a base address that matches for the difference.
15308 */
15309 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
15310 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
15311 mov %esp, %edx /* load kernel esp */
15312 mov PT_OLDESP(%esp), %eax /* load userspace esp */
15313 mov %dx, %ax /* eax: new kernel esp */
15314 sub %eax, %edx /* offset (low word is 0) */
15315 +#ifdef CONFIG_SMP
15316 + movl PER_CPU_VAR(cpu_number), %ebx
15317 + shll $PAGE_SHIFT_asm, %ebx
15318 + addl $cpu_gdt_table, %ebx
15319 +#else
15320 + movl $cpu_gdt_table, %ebx
15321 +#endif
15322 shr $16, %edx
15323 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
15324 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
15325 +
15326 +#ifdef CONFIG_PAX_KERNEXEC
15327 + mov %cr0, %esi
15328 + btr $16, %esi
15329 + mov %esi, %cr0
15330 +#endif
15331 +
15332 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
15333 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
15334 +
15335 +#ifdef CONFIG_PAX_KERNEXEC
15336 + bts $16, %esi
15337 + mov %esi, %cr0
15338 +#endif
15339 +
15340 pushl_cfi $__ESPFIX_SS
15341 pushl_cfi %eax /* new kernel esp */
15342 /* Disable interrupts, but do not irqtrace this section: we
15343 @@ -601,35 +828,23 @@ work_resched:
15344 movl TI_flags(%ebp), %ecx
15345 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
15346 # than syscall tracing?
15347 - jz restore_all
15348 + jz restore_all_pax
15349 testb $_TIF_NEED_RESCHED, %cl
15350 jnz work_resched
15351
15352 work_notifysig: # deal with pending signals and
15353 # notify-resume requests
15354 + movl %esp, %eax
15355 #ifdef CONFIG_VM86
15356 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
15357 - movl %esp, %eax
15358 - jne work_notifysig_v86 # returning to kernel-space or
15359 + jz 1f # returning to kernel-space or
15360 # vm86-space
15361 - TRACE_IRQS_ON
15362 - ENABLE_INTERRUPTS(CLBR_NONE)
15363 - movb PT_CS(%esp), %bl
15364 - andb $SEGMENT_RPL_MASK, %bl
15365 - cmpb $USER_RPL, %bl
15366 - jb resume_kernel
15367 - xorl %edx, %edx
15368 - call do_notify_resume
15369 - jmp resume_userspace
15370
15371 - ALIGN
15372 -work_notifysig_v86:
15373 pushl_cfi %ecx # save ti_flags for do_notify_resume
15374 call save_v86_state # %eax contains pt_regs pointer
15375 popl_cfi %ecx
15376 movl %eax, %esp
15377 -#else
15378 - movl %esp, %eax
15379 +1:
15380 #endif
15381 TRACE_IRQS_ON
15382 ENABLE_INTERRUPTS(CLBR_NONE)
15383 @@ -640,7 +855,7 @@ work_notifysig_v86:
15384 xorl %edx, %edx
15385 call do_notify_resume
15386 jmp resume_userspace
15387 -END(work_pending)
15388 +ENDPROC(work_pending)
15389
15390 # perform syscall exit tracing
15391 ALIGN
15392 @@ -648,11 +863,14 @@ syscall_trace_entry:
15393 movl $-ENOSYS,PT_EAX(%esp)
15394 movl %esp, %eax
15395 call syscall_trace_enter
15396 +
15397 + pax_erase_kstack
15398 +
15399 /* What it returned is what we'll actually use. */
15400 cmpl $(NR_syscalls), %eax
15401 jnae syscall_call
15402 jmp syscall_exit
15403 -END(syscall_trace_entry)
15404 +ENDPROC(syscall_trace_entry)
15405
15406 # perform syscall exit tracing
15407 ALIGN
15408 @@ -665,20 +883,24 @@ syscall_exit_work:
15409 movl %esp, %eax
15410 call syscall_trace_leave
15411 jmp resume_userspace
15412 -END(syscall_exit_work)
15413 +ENDPROC(syscall_exit_work)
15414 CFI_ENDPROC
15415
15416 RING0_INT_FRAME # can't unwind into user space anyway
15417 syscall_fault:
15418 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15419 + push %ss
15420 + pop %ds
15421 +#endif
15422 GET_THREAD_INFO(%ebp)
15423 movl $-EFAULT,PT_EAX(%esp)
15424 jmp resume_userspace
15425 -END(syscall_fault)
15426 +ENDPROC(syscall_fault)
15427
15428 syscall_badsys:
15429 movl $-ENOSYS,PT_EAX(%esp)
15430 jmp resume_userspace
15431 -END(syscall_badsys)
15432 +ENDPROC(syscall_badsys)
15433 CFI_ENDPROC
15434 /*
15435 * End of kprobes section
15436 @@ -750,6 +972,36 @@ ENTRY(ptregs_clone)
15437 CFI_ENDPROC
15438 ENDPROC(ptregs_clone)
15439
15440 + ALIGN;
15441 +ENTRY(kernel_execve)
15442 + CFI_STARTPROC
15443 + pushl_cfi %ebp
15444 + sub $PT_OLDSS+4,%esp
15445 + pushl_cfi %edi
15446 + pushl_cfi %ecx
15447 + pushl_cfi %eax
15448 + lea 3*4(%esp),%edi
15449 + mov $PT_OLDSS/4+1,%ecx
15450 + xorl %eax,%eax
15451 + rep stosl
15452 + popl_cfi %eax
15453 + popl_cfi %ecx
15454 + popl_cfi %edi
15455 + movl $X86_EFLAGS_IF,PT_EFLAGS(%esp)
15456 + pushl_cfi %esp
15457 + call sys_execve
15458 + add $4,%esp
15459 + CFI_ADJUST_CFA_OFFSET -4
15460 + GET_THREAD_INFO(%ebp)
15461 + test %eax,%eax
15462 + jz syscall_exit
15463 + add $PT_OLDSS+4,%esp
15464 + CFI_ADJUST_CFA_OFFSET -PT_OLDSS-4
15465 + popl_cfi %ebp
15466 + ret
15467 + CFI_ENDPROC
15468 +ENDPROC(kernel_execve)
15469 +
15470 .macro FIXUP_ESPFIX_STACK
15471 /*
15472 * Switch back for ESPFIX stack to the normal zerobased stack
15473 @@ -759,8 +1011,15 @@ ENDPROC(ptregs_clone)
15474 * normal stack and adjusts ESP with the matching offset.
15475 */
15476 /* fixup the stack */
15477 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
15478 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
15479 +#ifdef CONFIG_SMP
15480 + movl PER_CPU_VAR(cpu_number), %ebx
15481 + shll $PAGE_SHIFT_asm, %ebx
15482 + addl $cpu_gdt_table, %ebx
15483 +#else
15484 + movl $cpu_gdt_table, %ebx
15485 +#endif
15486 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
15487 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
15488 shl $16, %eax
15489 addl %esp, %eax /* the adjusted stack pointer */
15490 pushl_cfi $__KERNEL_DS
15491 @@ -813,7 +1072,7 @@ vector=vector+1
15492 .endr
15493 2: jmp common_interrupt
15494 .endr
15495 -END(irq_entries_start)
15496 +ENDPROC(irq_entries_start)
15497
15498 .previous
15499 END(interrupt)
15500 @@ -861,7 +1120,7 @@ ENTRY(coprocessor_error)
15501 pushl_cfi $do_coprocessor_error
15502 jmp error_code
15503 CFI_ENDPROC
15504 -END(coprocessor_error)
15505 +ENDPROC(coprocessor_error)
15506
15507 ENTRY(simd_coprocessor_error)
15508 RING0_INT_FRAME
15509 @@ -882,7 +1141,7 @@ ENTRY(simd_coprocessor_error)
15510 #endif
15511 jmp error_code
15512 CFI_ENDPROC
15513 -END(simd_coprocessor_error)
15514 +ENDPROC(simd_coprocessor_error)
15515
15516 ENTRY(device_not_available)
15517 RING0_INT_FRAME
15518 @@ -890,18 +1149,18 @@ ENTRY(device_not_available)
15519 pushl_cfi $do_device_not_available
15520 jmp error_code
15521 CFI_ENDPROC
15522 -END(device_not_available)
15523 +ENDPROC(device_not_available)
15524
15525 #ifdef CONFIG_PARAVIRT
15526 ENTRY(native_iret)
15527 iret
15528 _ASM_EXTABLE(native_iret, iret_exc)
15529 -END(native_iret)
15530 +ENDPROC(native_iret)
15531
15532 ENTRY(native_irq_enable_sysexit)
15533 sti
15534 sysexit
15535 -END(native_irq_enable_sysexit)
15536 +ENDPROC(native_irq_enable_sysexit)
15537 #endif
15538
15539 ENTRY(overflow)
15540 @@ -910,7 +1169,7 @@ ENTRY(overflow)
15541 pushl_cfi $do_overflow
15542 jmp error_code
15543 CFI_ENDPROC
15544 -END(overflow)
15545 +ENDPROC(overflow)
15546
15547 ENTRY(bounds)
15548 RING0_INT_FRAME
15549 @@ -918,7 +1177,7 @@ ENTRY(bounds)
15550 pushl_cfi $do_bounds
15551 jmp error_code
15552 CFI_ENDPROC
15553 -END(bounds)
15554 +ENDPROC(bounds)
15555
15556 ENTRY(invalid_op)
15557 RING0_INT_FRAME
15558 @@ -926,7 +1185,7 @@ ENTRY(invalid_op)
15559 pushl_cfi $do_invalid_op
15560 jmp error_code
15561 CFI_ENDPROC
15562 -END(invalid_op)
15563 +ENDPROC(invalid_op)
15564
15565 ENTRY(coprocessor_segment_overrun)
15566 RING0_INT_FRAME
15567 @@ -934,35 +1193,35 @@ ENTRY(coprocessor_segment_overrun)
15568 pushl_cfi $do_coprocessor_segment_overrun
15569 jmp error_code
15570 CFI_ENDPROC
15571 -END(coprocessor_segment_overrun)
15572 +ENDPROC(coprocessor_segment_overrun)
15573
15574 ENTRY(invalid_TSS)
15575 RING0_EC_FRAME
15576 pushl_cfi $do_invalid_TSS
15577 jmp error_code
15578 CFI_ENDPROC
15579 -END(invalid_TSS)
15580 +ENDPROC(invalid_TSS)
15581
15582 ENTRY(segment_not_present)
15583 RING0_EC_FRAME
15584 pushl_cfi $do_segment_not_present
15585 jmp error_code
15586 CFI_ENDPROC
15587 -END(segment_not_present)
15588 +ENDPROC(segment_not_present)
15589
15590 ENTRY(stack_segment)
15591 RING0_EC_FRAME
15592 pushl_cfi $do_stack_segment
15593 jmp error_code
15594 CFI_ENDPROC
15595 -END(stack_segment)
15596 +ENDPROC(stack_segment)
15597
15598 ENTRY(alignment_check)
15599 RING0_EC_FRAME
15600 pushl_cfi $do_alignment_check
15601 jmp error_code
15602 CFI_ENDPROC
15603 -END(alignment_check)
15604 +ENDPROC(alignment_check)
15605
15606 ENTRY(divide_error)
15607 RING0_INT_FRAME
15608 @@ -970,7 +1229,7 @@ ENTRY(divide_error)
15609 pushl_cfi $do_divide_error
15610 jmp error_code
15611 CFI_ENDPROC
15612 -END(divide_error)
15613 +ENDPROC(divide_error)
15614
15615 #ifdef CONFIG_X86_MCE
15616 ENTRY(machine_check)
15617 @@ -979,7 +1238,7 @@ ENTRY(machine_check)
15618 pushl_cfi machine_check_vector
15619 jmp error_code
15620 CFI_ENDPROC
15621 -END(machine_check)
15622 +ENDPROC(machine_check)
15623 #endif
15624
15625 ENTRY(spurious_interrupt_bug)
15626 @@ -988,7 +1247,7 @@ ENTRY(spurious_interrupt_bug)
15627 pushl_cfi $do_spurious_interrupt_bug
15628 jmp error_code
15629 CFI_ENDPROC
15630 -END(spurious_interrupt_bug)
15631 +ENDPROC(spurious_interrupt_bug)
15632 /*
15633 * End of kprobes section
15634 */
15635 @@ -1100,7 +1359,7 @@ BUILD_INTERRUPT3(xen_hvm_callback_vector, XEN_HVM_EVTCHN_CALLBACK,
15636
15637 ENTRY(mcount)
15638 ret
15639 -END(mcount)
15640 +ENDPROC(mcount)
15641
15642 ENTRY(ftrace_caller)
15643 cmpl $0, function_trace_stop
15644 @@ -1129,7 +1388,7 @@ ftrace_graph_call:
15645 .globl ftrace_stub
15646 ftrace_stub:
15647 ret
15648 -END(ftrace_caller)
15649 +ENDPROC(ftrace_caller)
15650
15651 #else /* ! CONFIG_DYNAMIC_FTRACE */
15652
15653 @@ -1165,7 +1424,7 @@ trace:
15654 popl %ecx
15655 popl %eax
15656 jmp ftrace_stub
15657 -END(mcount)
15658 +ENDPROC(mcount)
15659 #endif /* CONFIG_DYNAMIC_FTRACE */
15660 #endif /* CONFIG_FUNCTION_TRACER */
15661
15662 @@ -1186,7 +1445,7 @@ ENTRY(ftrace_graph_caller)
15663 popl %ecx
15664 popl %eax
15665 ret
15666 -END(ftrace_graph_caller)
15667 +ENDPROC(ftrace_graph_caller)
15668
15669 .globl return_to_handler
15670 return_to_handler:
15671 @@ -1241,15 +1500,18 @@ error_code:
15672 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
15673 REG_TO_PTGS %ecx
15674 SET_KERNEL_GS %ecx
15675 - movl $(__USER_DS), %ecx
15676 + movl $(__KERNEL_DS), %ecx
15677 movl %ecx, %ds
15678 movl %ecx, %es
15679 +
15680 + pax_enter_kernel
15681 +
15682 TRACE_IRQS_OFF
15683 movl %esp,%eax # pt_regs pointer
15684 call *%edi
15685 jmp ret_from_exception
15686 CFI_ENDPROC
15687 -END(page_fault)
15688 +ENDPROC(page_fault)
15689
15690 /*
15691 * Debug traps and NMI can happen at the one SYSENTER instruction
15692 @@ -1291,7 +1553,7 @@ debug_stack_correct:
15693 call do_debug
15694 jmp ret_from_exception
15695 CFI_ENDPROC
15696 -END(debug)
15697 +ENDPROC(debug)
15698
15699 /*
15700 * NMI is doubly nasty. It can happen _while_ we're handling
15701 @@ -1328,6 +1590,9 @@ nmi_stack_correct:
15702 xorl %edx,%edx # zero error code
15703 movl %esp,%eax # pt_regs pointer
15704 call do_nmi
15705 +
15706 + pax_exit_kernel
15707 +
15708 jmp restore_all_notrace
15709 CFI_ENDPROC
15710
15711 @@ -1364,12 +1629,15 @@ nmi_espfix_stack:
15712 FIXUP_ESPFIX_STACK # %eax == %esp
15713 xorl %edx,%edx # zero error code
15714 call do_nmi
15715 +
15716 + pax_exit_kernel
15717 +
15718 RESTORE_REGS
15719 lss 12+4(%esp), %esp # back to espfix stack
15720 CFI_ADJUST_CFA_OFFSET -24
15721 jmp irq_return
15722 CFI_ENDPROC
15723 -END(nmi)
15724 +ENDPROC(nmi)
15725
15726 ENTRY(int3)
15727 RING0_INT_FRAME
15728 @@ -1381,14 +1649,14 @@ ENTRY(int3)
15729 call do_int3
15730 jmp ret_from_exception
15731 CFI_ENDPROC
15732 -END(int3)
15733 +ENDPROC(int3)
15734
15735 ENTRY(general_protection)
15736 RING0_EC_FRAME
15737 pushl_cfi $do_general_protection
15738 jmp error_code
15739 CFI_ENDPROC
15740 -END(general_protection)
15741 +ENDPROC(general_protection)
15742
15743 #ifdef CONFIG_KVM_GUEST
15744 ENTRY(async_page_fault)
15745 @@ -1396,7 +1664,7 @@ ENTRY(async_page_fault)
15746 pushl_cfi $do_async_page_fault
15747 jmp error_code
15748 CFI_ENDPROC
15749 -END(async_page_fault)
15750 +ENDPROC(async_page_fault)
15751 #endif
15752
15753 /*
15754 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
15755 index 7d65133..c888d5f 100644
15756 --- a/arch/x86/kernel/entry_64.S
15757 +++ b/arch/x86/kernel/entry_64.S
15758 @@ -57,6 +57,8 @@
15759 #include <asm/percpu.h>
15760 #include <asm/asm.h>
15761 #include <linux/err.h>
15762 +#include <asm/pgtable.h>
15763 +#include <asm/alternative-asm.h>
15764
15765 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
15766 #include <linux/elf-em.h>
15767 @@ -70,8 +72,9 @@
15768 #ifdef CONFIG_FUNCTION_TRACER
15769 #ifdef CONFIG_DYNAMIC_FTRACE
15770 ENTRY(mcount)
15771 + pax_force_retaddr
15772 retq
15773 -END(mcount)
15774 +ENDPROC(mcount)
15775
15776 ENTRY(ftrace_caller)
15777 cmpl $0, function_trace_stop
15778 @@ -94,8 +97,9 @@ GLOBAL(ftrace_graph_call)
15779 #endif
15780
15781 GLOBAL(ftrace_stub)
15782 + pax_force_retaddr
15783 retq
15784 -END(ftrace_caller)
15785 +ENDPROC(ftrace_caller)
15786
15787 #else /* ! CONFIG_DYNAMIC_FTRACE */
15788 ENTRY(mcount)
15789 @@ -114,6 +118,7 @@ ENTRY(mcount)
15790 #endif
15791
15792 GLOBAL(ftrace_stub)
15793 + pax_force_retaddr
15794 retq
15795
15796 trace:
15797 @@ -123,12 +128,13 @@ trace:
15798 movq 8(%rbp), %rsi
15799 subq $MCOUNT_INSN_SIZE, %rdi
15800
15801 + pax_force_fptr ftrace_trace_function
15802 call *ftrace_trace_function
15803
15804 MCOUNT_RESTORE_FRAME
15805
15806 jmp ftrace_stub
15807 -END(mcount)
15808 +ENDPROC(mcount)
15809 #endif /* CONFIG_DYNAMIC_FTRACE */
15810 #endif /* CONFIG_FUNCTION_TRACER */
15811
15812 @@ -148,8 +154,9 @@ ENTRY(ftrace_graph_caller)
15813
15814 MCOUNT_RESTORE_FRAME
15815
15816 + pax_force_retaddr
15817 retq
15818 -END(ftrace_graph_caller)
15819 +ENDPROC(ftrace_graph_caller)
15820
15821 GLOBAL(return_to_handler)
15822 subq $24, %rsp
15823 @@ -165,6 +172,7 @@ GLOBAL(return_to_handler)
15824 movq 8(%rsp), %rdx
15825 movq (%rsp), %rax
15826 addq $24, %rsp
15827 + pax_force_fptr %rdi
15828 jmp *%rdi
15829 #endif
15830
15831 @@ -180,6 +188,280 @@ ENTRY(native_usergs_sysret64)
15832 ENDPROC(native_usergs_sysret64)
15833 #endif /* CONFIG_PARAVIRT */
15834
15835 + .macro ljmpq sel, off
15836 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
15837 + .byte 0x48; ljmp *1234f(%rip)
15838 + .pushsection .rodata
15839 + .align 16
15840 + 1234: .quad \off; .word \sel
15841 + .popsection
15842 +#else
15843 + pushq $\sel
15844 + pushq $\off
15845 + lretq
15846 +#endif
15847 + .endm
15848 +
15849 + .macro pax_enter_kernel
15850 + pax_set_fptr_mask
15851 +#ifdef CONFIG_PAX_KERNEXEC
15852 + call pax_enter_kernel
15853 +#endif
15854 + .endm
15855 +
15856 + .macro pax_exit_kernel
15857 +#ifdef CONFIG_PAX_KERNEXEC
15858 + call pax_exit_kernel
15859 +#endif
15860 + .endm
15861 +
15862 +#ifdef CONFIG_PAX_KERNEXEC
15863 +ENTRY(pax_enter_kernel)
15864 + pushq %rdi
15865 +
15866 +#ifdef CONFIG_PARAVIRT
15867 + PV_SAVE_REGS(CLBR_RDI)
15868 +#endif
15869 +
15870 + GET_CR0_INTO_RDI
15871 + bts $16,%rdi
15872 + jnc 3f
15873 + mov %cs,%edi
15874 + cmp $__KERNEL_CS,%edi
15875 + jnz 2f
15876 +1:
15877 +
15878 +#ifdef CONFIG_PARAVIRT
15879 + PV_RESTORE_REGS(CLBR_RDI)
15880 +#endif
15881 +
15882 + popq %rdi
15883 + pax_force_retaddr
15884 + retq
15885 +
15886 +2: ljmpq __KERNEL_CS,1f
15887 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
15888 +4: SET_RDI_INTO_CR0
15889 + jmp 1b
15890 +ENDPROC(pax_enter_kernel)
15891 +
15892 +ENTRY(pax_exit_kernel)
15893 + pushq %rdi
15894 +
15895 +#ifdef CONFIG_PARAVIRT
15896 + PV_SAVE_REGS(CLBR_RDI)
15897 +#endif
15898 +
15899 + mov %cs,%rdi
15900 + cmp $__KERNEXEC_KERNEL_CS,%edi
15901 + jz 2f
15902 +1:
15903 +
15904 +#ifdef CONFIG_PARAVIRT
15905 + PV_RESTORE_REGS(CLBR_RDI);
15906 +#endif
15907 +
15908 + popq %rdi
15909 + pax_force_retaddr
15910 + retq
15911 +
15912 +2: GET_CR0_INTO_RDI
15913 + btr $16,%rdi
15914 + ljmpq __KERNEL_CS,3f
15915 +3: SET_RDI_INTO_CR0
15916 + jmp 1b
15917 +#ifdef CONFIG_PARAVIRT
15918 + PV_RESTORE_REGS(CLBR_RDI);
15919 +#endif
15920 +
15921 + popq %rdi
15922 + pax_force_retaddr
15923 + retq
15924 +ENDPROC(pax_exit_kernel)
15925 +#endif
15926 +
15927 + .macro pax_enter_kernel_user
15928 + pax_set_fptr_mask
15929 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15930 + call pax_enter_kernel_user
15931 +#endif
15932 + .endm
15933 +
15934 + .macro pax_exit_kernel_user
15935 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15936 + call pax_exit_kernel_user
15937 +#endif
15938 +#ifdef CONFIG_PAX_RANDKSTACK
15939 + pushq %rax
15940 + call pax_randomize_kstack
15941 + popq %rax
15942 +#endif
15943 + .endm
15944 +
15945 +#ifdef CONFIG_PAX_MEMORY_UDEREF
15946 +ENTRY(pax_enter_kernel_user)
15947 + pushq %rdi
15948 + pushq %rbx
15949 +
15950 +#ifdef CONFIG_PARAVIRT
15951 + PV_SAVE_REGS(CLBR_RDI)
15952 +#endif
15953 +
15954 + GET_CR3_INTO_RDI
15955 + mov %rdi,%rbx
15956 + add $__START_KERNEL_map,%rbx
15957 + sub phys_base(%rip),%rbx
15958 +
15959 +#ifdef CONFIG_PARAVIRT
15960 + pushq %rdi
15961 + cmpl $0, pv_info+PARAVIRT_enabled
15962 + jz 1f
15963 + i = 0
15964 + .rept USER_PGD_PTRS
15965 + mov i*8(%rbx),%rsi
15966 + mov $0,%sil
15967 + lea i*8(%rbx),%rdi
15968 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
15969 + i = i + 1
15970 + .endr
15971 + jmp 2f
15972 +1:
15973 +#endif
15974 +
15975 + i = 0
15976 + .rept USER_PGD_PTRS
15977 + movb $0,i*8(%rbx)
15978 + i = i + 1
15979 + .endr
15980 +
15981 +#ifdef CONFIG_PARAVIRT
15982 +2: popq %rdi
15983 +#endif
15984 + SET_RDI_INTO_CR3
15985 +
15986 +#ifdef CONFIG_PAX_KERNEXEC
15987 + GET_CR0_INTO_RDI
15988 + bts $16,%rdi
15989 + SET_RDI_INTO_CR0
15990 +#endif
15991 +
15992 +#ifdef CONFIG_PARAVIRT
15993 + PV_RESTORE_REGS(CLBR_RDI)
15994 +#endif
15995 +
15996 + popq %rbx
15997 + popq %rdi
15998 + pax_force_retaddr
15999 + retq
16000 +ENDPROC(pax_enter_kernel_user)
16001 +
16002 +ENTRY(pax_exit_kernel_user)
16003 + push %rdi
16004 +
16005 +#ifdef CONFIG_PARAVIRT
16006 + pushq %rbx
16007 + PV_SAVE_REGS(CLBR_RDI)
16008 +#endif
16009 +
16010 +#ifdef CONFIG_PAX_KERNEXEC
16011 + GET_CR0_INTO_RDI
16012 + btr $16,%rdi
16013 + SET_RDI_INTO_CR0
16014 +#endif
16015 +
16016 + GET_CR3_INTO_RDI
16017 + add $__START_KERNEL_map,%rdi
16018 + sub phys_base(%rip),%rdi
16019 +
16020 +#ifdef CONFIG_PARAVIRT
16021 + cmpl $0, pv_info+PARAVIRT_enabled
16022 + jz 1f
16023 + mov %rdi,%rbx
16024 + i = 0
16025 + .rept USER_PGD_PTRS
16026 + mov i*8(%rbx),%rsi
16027 + mov $0x67,%sil
16028 + lea i*8(%rbx),%rdi
16029 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
16030 + i = i + 1
16031 + .endr
16032 + jmp 2f
16033 +1:
16034 +#endif
16035 +
16036 + i = 0
16037 + .rept USER_PGD_PTRS
16038 + movb $0x67,i*8(%rdi)
16039 + i = i + 1
16040 + .endr
16041 +
16042 +#ifdef CONFIG_PARAVIRT
16043 +2: PV_RESTORE_REGS(CLBR_RDI)
16044 + popq %rbx
16045 +#endif
16046 +
16047 + popq %rdi
16048 + pax_force_retaddr
16049 + retq
16050 +ENDPROC(pax_exit_kernel_user)
16051 +#endif
16052 +
16053 +.macro pax_erase_kstack
16054 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16055 + call pax_erase_kstack
16056 +#endif
16057 +.endm
16058 +
16059 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
16060 +ENTRY(pax_erase_kstack)
16061 + pushq %rdi
16062 + pushq %rcx
16063 + pushq %rax
16064 + pushq %r11
16065 +
16066 + GET_THREAD_INFO(%r11)
16067 + mov TI_lowest_stack(%r11), %rdi
16068 + mov $-0xBEEF, %rax
16069 + std
16070 +
16071 +1: mov %edi, %ecx
16072 + and $THREAD_SIZE_asm - 1, %ecx
16073 + shr $3, %ecx
16074 + repne scasq
16075 + jecxz 2f
16076 +
16077 + cmp $2*8, %ecx
16078 + jc 2f
16079 +
16080 + mov $2*8, %ecx
16081 + repe scasq
16082 + jecxz 2f
16083 + jne 1b
16084 +
16085 +2: cld
16086 + mov %esp, %ecx
16087 + sub %edi, %ecx
16088 +
16089 + cmp $THREAD_SIZE_asm, %rcx
16090 + jb 3f
16091 + ud2
16092 +3:
16093 +
16094 + shr $3, %ecx
16095 + rep stosq
16096 +
16097 + mov TI_task_thread_sp0(%r11), %rdi
16098 + sub $256, %rdi
16099 + mov %rdi, TI_lowest_stack(%r11)
16100 +
16101 + popq %r11
16102 + popq %rax
16103 + popq %rcx
16104 + popq %rdi
16105 + pax_force_retaddr
16106 + ret
16107 +ENDPROC(pax_erase_kstack)
16108 +#endif
16109
16110 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
16111 #ifdef CONFIG_TRACE_IRQFLAGS
16112 @@ -271,8 +553,8 @@ ENDPROC(native_usergs_sysret64)
16113 .endm
16114
16115 .macro UNFAKE_STACK_FRAME
16116 - addq $8*6, %rsp
16117 - CFI_ADJUST_CFA_OFFSET -(6*8)
16118 + addq $8*6 + ARG_SKIP, %rsp
16119 + CFI_ADJUST_CFA_OFFSET -(6*8 + ARG_SKIP)
16120 .endm
16121
16122 /*
16123 @@ -359,7 +641,7 @@ ENDPROC(native_usergs_sysret64)
16124 movq %rsp, %rsi
16125
16126 leaq -RBP(%rsp),%rdi /* arg1 for handler */
16127 - testl $3, CS-RBP(%rsi)
16128 + testb $3, CS-RBP(%rsi)
16129 je 1f
16130 SWAPGS
16131 /*
16132 @@ -394,9 +676,10 @@ ENTRY(save_rest)
16133 movq_cfi r15, R15+16
16134 movq %r11, 8(%rsp) /* return address */
16135 FIXUP_TOP_OF_STACK %r11, 16
16136 + pax_force_retaddr
16137 ret
16138 CFI_ENDPROC
16139 -END(save_rest)
16140 +ENDPROC(save_rest)
16141
16142 /* save complete stack frame */
16143 .pushsection .kprobes.text, "ax"
16144 @@ -425,9 +708,10 @@ ENTRY(save_paranoid)
16145 js 1f /* negative -> in kernel */
16146 SWAPGS
16147 xorl %ebx,%ebx
16148 -1: ret
16149 +1: pax_force_retaddr_bts
16150 + ret
16151 CFI_ENDPROC
16152 -END(save_paranoid)
16153 +ENDPROC(save_paranoid)
16154 .popsection
16155
16156 /*
16157 @@ -449,7 +733,7 @@ ENTRY(ret_from_fork)
16158
16159 RESTORE_REST
16160
16161 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16162 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
16163 jz retint_restore_args
16164
16165 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
16166 @@ -459,7 +743,7 @@ ENTRY(ret_from_fork)
16167 jmp ret_from_sys_call # go to the SYSRET fastpath
16168
16169 CFI_ENDPROC
16170 -END(ret_from_fork)
16171 +ENDPROC(ret_from_fork)
16172
16173 /*
16174 * System call entry. Up to 6 arguments in registers are supported.
16175 @@ -495,7 +779,7 @@ END(ret_from_fork)
16176 ENTRY(system_call)
16177 CFI_STARTPROC simple
16178 CFI_SIGNAL_FRAME
16179 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
16180 + CFI_DEF_CFA rsp,0
16181 CFI_REGISTER rip,rcx
16182 /*CFI_REGISTER rflags,r11*/
16183 SWAPGS_UNSAFE_STACK
16184 @@ -508,16 +792,23 @@ GLOBAL(system_call_after_swapgs)
16185
16186 movq %rsp,PER_CPU_VAR(old_rsp)
16187 movq PER_CPU_VAR(kernel_stack),%rsp
16188 + SAVE_ARGS 8*6,0
16189 + pax_enter_kernel_user
16190 +
16191 +#ifdef CONFIG_PAX_RANDKSTACK
16192 + pax_erase_kstack
16193 +#endif
16194 +
16195 /*
16196 * No need to follow this irqs off/on section - it's straight
16197 * and short:
16198 */
16199 ENABLE_INTERRUPTS(CLBR_NONE)
16200 - SAVE_ARGS 8,0
16201 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
16202 movq %rcx,RIP-ARGOFFSET(%rsp)
16203 CFI_REL_OFFSET rip,RIP-ARGOFFSET
16204 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16205 + GET_THREAD_INFO(%rcx)
16206 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
16207 jnz tracesys
16208 system_call_fastpath:
16209 #if __SYSCALL_MASK == ~0
16210 @@ -527,7 +818,7 @@ system_call_fastpath:
16211 cmpl $__NR_syscall_max,%eax
16212 #endif
16213 ja badsys
16214 - movq %r10,%rcx
16215 + movq R10-ARGOFFSET(%rsp),%rcx
16216 call *sys_call_table(,%rax,8) # XXX: rip relative
16217 movq %rax,RAX-ARGOFFSET(%rsp)
16218 /*
16219 @@ -541,10 +832,13 @@ sysret_check:
16220 LOCKDEP_SYS_EXIT
16221 DISABLE_INTERRUPTS(CLBR_NONE)
16222 TRACE_IRQS_OFF
16223 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
16224 + GET_THREAD_INFO(%rcx)
16225 + movl TI_flags(%rcx),%edx
16226 andl %edi,%edx
16227 jnz sysret_careful
16228 CFI_REMEMBER_STATE
16229 + pax_exit_kernel_user
16230 + pax_erase_kstack
16231 /*
16232 * sysretq will re-enable interrupts:
16233 */
16234 @@ -596,14 +890,18 @@ badsys:
16235 * jump back to the normal fast path.
16236 */
16237 auditsys:
16238 - movq %r10,%r9 /* 6th arg: 4th syscall arg */
16239 + movq R10-ARGOFFSET(%rsp),%r9 /* 6th arg: 4th syscall arg */
16240 movq %rdx,%r8 /* 5th arg: 3rd syscall arg */
16241 movq %rsi,%rcx /* 4th arg: 2nd syscall arg */
16242 movq %rdi,%rdx /* 3rd arg: 1st syscall arg */
16243 movq %rax,%rsi /* 2nd arg: syscall number */
16244 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
16245 call __audit_syscall_entry
16246 +
16247 + pax_erase_kstack
16248 +
16249 LOAD_ARGS 0 /* reload call-clobbered registers */
16250 + pax_set_fptr_mask
16251 jmp system_call_fastpath
16252
16253 /*
16254 @@ -624,7 +922,7 @@ sysret_audit:
16255 /* Do syscall tracing */
16256 tracesys:
16257 #ifdef CONFIG_AUDITSYSCALL
16258 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
16259 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
16260 jz auditsys
16261 #endif
16262 SAVE_REST
16263 @@ -632,12 +930,16 @@ tracesys:
16264 FIXUP_TOP_OF_STACK %rdi
16265 movq %rsp,%rdi
16266 call syscall_trace_enter
16267 +
16268 + pax_erase_kstack
16269 +
16270 /*
16271 * Reload arg registers from stack in case ptrace changed them.
16272 * We don't reload %rax because syscall_trace_enter() returned
16273 * the value it wants us to use in the table lookup.
16274 */
16275 LOAD_ARGS ARGOFFSET, 1
16276 + pax_set_fptr_mask
16277 RESTORE_REST
16278 #if __SYSCALL_MASK == ~0
16279 cmpq $__NR_syscall_max,%rax
16280 @@ -646,7 +948,7 @@ tracesys:
16281 cmpl $__NR_syscall_max,%eax
16282 #endif
16283 ja int_ret_from_sys_call /* RAX(%rsp) set to -ENOSYS above */
16284 - movq %r10,%rcx /* fixup for C */
16285 + movq R10-ARGOFFSET(%rsp),%rcx /* fixup for C */
16286 call *sys_call_table(,%rax,8)
16287 movq %rax,RAX-ARGOFFSET(%rsp)
16288 /* Use IRET because user could have changed frame */
16289 @@ -667,7 +969,9 @@ GLOBAL(int_with_check)
16290 andl %edi,%edx
16291 jnz int_careful
16292 andl $~TS_COMPAT,TI_status(%rcx)
16293 - jmp retint_swapgs
16294 + pax_exit_kernel_user
16295 + pax_erase_kstack
16296 + jmp retint_swapgs_pax
16297
16298 /* Either reschedule or signal or syscall exit tracking needed. */
16299 /* First do a reschedule test. */
16300 @@ -713,7 +1017,7 @@ int_restore_rest:
16301 TRACE_IRQS_OFF
16302 jmp int_with_check
16303 CFI_ENDPROC
16304 -END(system_call)
16305 +ENDPROC(system_call)
16306
16307 /*
16308 * Certain special system calls that need to save a complete full stack frame.
16309 @@ -729,7 +1033,7 @@ ENTRY(\label)
16310 call \func
16311 jmp ptregscall_common
16312 CFI_ENDPROC
16313 -END(\label)
16314 +ENDPROC(\label)
16315 .endm
16316
16317 PTREGSCALL stub_clone, sys_clone, %r8
16318 @@ -747,9 +1051,10 @@ ENTRY(ptregscall_common)
16319 movq_cfi_restore R12+8, r12
16320 movq_cfi_restore RBP+8, rbp
16321 movq_cfi_restore RBX+8, rbx
16322 + pax_force_retaddr
16323 ret $REST_SKIP /* pop extended registers */
16324 CFI_ENDPROC
16325 -END(ptregscall_common)
16326 +ENDPROC(ptregscall_common)
16327
16328 ENTRY(stub_execve)
16329 CFI_STARTPROC
16330 @@ -764,7 +1069,7 @@ ENTRY(stub_execve)
16331 RESTORE_REST
16332 jmp int_ret_from_sys_call
16333 CFI_ENDPROC
16334 -END(stub_execve)
16335 +ENDPROC(stub_execve)
16336
16337 /*
16338 * sigreturn is special because it needs to restore all registers on return.
16339 @@ -782,7 +1087,7 @@ ENTRY(stub_rt_sigreturn)
16340 RESTORE_REST
16341 jmp int_ret_from_sys_call
16342 CFI_ENDPROC
16343 -END(stub_rt_sigreturn)
16344 +ENDPROC(stub_rt_sigreturn)
16345
16346 #ifdef CONFIG_X86_X32_ABI
16347 PTREGSCALL stub_x32_sigaltstack, sys32_sigaltstack, %rdx
16348 @@ -851,7 +1156,7 @@ vector=vector+1
16349 2: jmp common_interrupt
16350 .endr
16351 CFI_ENDPROC
16352 -END(irq_entries_start)
16353 +ENDPROC(irq_entries_start)
16354
16355 .previous
16356 END(interrupt)
16357 @@ -871,6 +1176,16 @@ END(interrupt)
16358 subq $ORIG_RAX-RBP, %rsp
16359 CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
16360 SAVE_ARGS_IRQ
16361 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16362 + testb $3, CS(%rdi)
16363 + jnz 1f
16364 + pax_enter_kernel
16365 + jmp 2f
16366 +1: pax_enter_kernel_user
16367 +2:
16368 +#else
16369 + pax_enter_kernel
16370 +#endif
16371 call \func
16372 .endm
16373
16374 @@ -902,7 +1217,7 @@ ret_from_intr:
16375
16376 exit_intr:
16377 GET_THREAD_INFO(%rcx)
16378 - testl $3,CS-ARGOFFSET(%rsp)
16379 + testb $3,CS-ARGOFFSET(%rsp)
16380 je retint_kernel
16381
16382 /* Interrupt came from user space */
16383 @@ -924,12 +1239,16 @@ retint_swapgs: /* return to user-space */
16384 * The iretq could re-enable interrupts:
16385 */
16386 DISABLE_INTERRUPTS(CLBR_ANY)
16387 + pax_exit_kernel_user
16388 +retint_swapgs_pax:
16389 TRACE_IRQS_IRETQ
16390 SWAPGS
16391 jmp restore_args
16392
16393 retint_restore_args: /* return to kernel space */
16394 DISABLE_INTERRUPTS(CLBR_ANY)
16395 + pax_exit_kernel
16396 + pax_force_retaddr RIP-ARGOFFSET
16397 /*
16398 * The iretq could re-enable interrupts:
16399 */
16400 @@ -1012,7 +1331,7 @@ ENTRY(retint_kernel)
16401 #endif
16402
16403 CFI_ENDPROC
16404 -END(common_interrupt)
16405 +ENDPROC(common_interrupt)
16406 /*
16407 * End of kprobes section
16408 */
16409 @@ -1029,7 +1348,7 @@ ENTRY(\sym)
16410 interrupt \do_sym
16411 jmp ret_from_intr
16412 CFI_ENDPROC
16413 -END(\sym)
16414 +ENDPROC(\sym)
16415 .endm
16416
16417 #ifdef CONFIG_SMP
16418 @@ -1102,12 +1421,22 @@ ENTRY(\sym)
16419 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16420 call error_entry
16421 DEFAULT_FRAME 0
16422 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16423 + testb $3, CS(%rsp)
16424 + jnz 1f
16425 + pax_enter_kernel
16426 + jmp 2f
16427 +1: pax_enter_kernel_user
16428 +2:
16429 +#else
16430 + pax_enter_kernel
16431 +#endif
16432 movq %rsp,%rdi /* pt_regs pointer */
16433 xorl %esi,%esi /* no error code */
16434 call \do_sym
16435 jmp error_exit /* %ebx: no swapgs flag */
16436 CFI_ENDPROC
16437 -END(\sym)
16438 +ENDPROC(\sym)
16439 .endm
16440
16441 .macro paranoidzeroentry sym do_sym
16442 @@ -1119,15 +1448,25 @@ ENTRY(\sym)
16443 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16444 call save_paranoid
16445 TRACE_IRQS_OFF
16446 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16447 + testb $3, CS(%rsp)
16448 + jnz 1f
16449 + pax_enter_kernel
16450 + jmp 2f
16451 +1: pax_enter_kernel_user
16452 +2:
16453 +#else
16454 + pax_enter_kernel
16455 +#endif
16456 movq %rsp,%rdi /* pt_regs pointer */
16457 xorl %esi,%esi /* no error code */
16458 call \do_sym
16459 jmp paranoid_exit /* %ebx: no swapgs flag */
16460 CFI_ENDPROC
16461 -END(\sym)
16462 +ENDPROC(\sym)
16463 .endm
16464
16465 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
16466 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r12)
16467 .macro paranoidzeroentry_ist sym do_sym ist
16468 ENTRY(\sym)
16469 INTR_FRAME
16470 @@ -1137,14 +1476,30 @@ ENTRY(\sym)
16471 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16472 call save_paranoid
16473 TRACE_IRQS_OFF_DEBUG
16474 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16475 + testb $3, CS(%rsp)
16476 + jnz 1f
16477 + pax_enter_kernel
16478 + jmp 2f
16479 +1: pax_enter_kernel_user
16480 +2:
16481 +#else
16482 + pax_enter_kernel
16483 +#endif
16484 movq %rsp,%rdi /* pt_regs pointer */
16485 xorl %esi,%esi /* no error code */
16486 +#ifdef CONFIG_SMP
16487 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r12d
16488 + lea init_tss(%r12), %r12
16489 +#else
16490 + lea init_tss(%rip), %r12
16491 +#endif
16492 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16493 call \do_sym
16494 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
16495 jmp paranoid_exit /* %ebx: no swapgs flag */
16496 CFI_ENDPROC
16497 -END(\sym)
16498 +ENDPROC(\sym)
16499 .endm
16500
16501 .macro errorentry sym do_sym
16502 @@ -1155,13 +1510,23 @@ ENTRY(\sym)
16503 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
16504 call error_entry
16505 DEFAULT_FRAME 0
16506 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16507 + testb $3, CS(%rsp)
16508 + jnz 1f
16509 + pax_enter_kernel
16510 + jmp 2f
16511 +1: pax_enter_kernel_user
16512 +2:
16513 +#else
16514 + pax_enter_kernel
16515 +#endif
16516 movq %rsp,%rdi /* pt_regs pointer */
16517 movq ORIG_RAX(%rsp),%rsi /* get error code */
16518 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16519 call \do_sym
16520 jmp error_exit /* %ebx: no swapgs flag */
16521 CFI_ENDPROC
16522 -END(\sym)
16523 +ENDPROC(\sym)
16524 .endm
16525
16526 /* error code is on the stack already */
16527 @@ -1174,13 +1539,23 @@ ENTRY(\sym)
16528 call save_paranoid
16529 DEFAULT_FRAME 0
16530 TRACE_IRQS_OFF
16531 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16532 + testb $3, CS(%rsp)
16533 + jnz 1f
16534 + pax_enter_kernel
16535 + jmp 2f
16536 +1: pax_enter_kernel_user
16537 +2:
16538 +#else
16539 + pax_enter_kernel
16540 +#endif
16541 movq %rsp,%rdi /* pt_regs pointer */
16542 movq ORIG_RAX(%rsp),%rsi /* get error code */
16543 movq $-1,ORIG_RAX(%rsp) /* no syscall to restart */
16544 call \do_sym
16545 jmp paranoid_exit /* %ebx: no swapgs flag */
16546 CFI_ENDPROC
16547 -END(\sym)
16548 +ENDPROC(\sym)
16549 .endm
16550
16551 zeroentry divide_error do_divide_error
16552 @@ -1210,9 +1585,10 @@ gs_change:
16553 2: mfence /* workaround */
16554 SWAPGS
16555 popfq_cfi
16556 + pax_force_retaddr
16557 ret
16558 CFI_ENDPROC
16559 -END(native_load_gs_index)
16560 +ENDPROC(native_load_gs_index)
16561
16562 _ASM_EXTABLE(gs_change,bad_gs)
16563 .section .fixup,"ax"
16564 @@ -1231,13 +1607,14 @@ ENTRY(kernel_thread_helper)
16565 * Here we are in the child and the registers are set as they were
16566 * at kernel_thread() invocation in the parent.
16567 */
16568 + pax_force_fptr %rsi
16569 call *%rsi
16570 # exit
16571 mov %eax, %edi
16572 call do_exit
16573 ud2 # padding for call trace
16574 CFI_ENDPROC
16575 -END(kernel_thread_helper)
16576 +ENDPROC(kernel_thread_helper)
16577
16578 /*
16579 * execve(). This function needs to use IRET, not SYSRET, to set up all state properly.
16580 @@ -1264,11 +1641,11 @@ ENTRY(kernel_execve)
16581 RESTORE_REST
16582 testq %rax,%rax
16583 je int_ret_from_sys_call
16584 - RESTORE_ARGS
16585 UNFAKE_STACK_FRAME
16586 + pax_force_retaddr
16587 ret
16588 CFI_ENDPROC
16589 -END(kernel_execve)
16590 +ENDPROC(kernel_execve)
16591
16592 /* Call softirq on interrupt stack. Interrupts are off. */
16593 ENTRY(call_softirq)
16594 @@ -1286,9 +1663,10 @@ ENTRY(call_softirq)
16595 CFI_DEF_CFA_REGISTER rsp
16596 CFI_ADJUST_CFA_OFFSET -8
16597 decl PER_CPU_VAR(irq_count)
16598 + pax_force_retaddr
16599 ret
16600 CFI_ENDPROC
16601 -END(call_softirq)
16602 +ENDPROC(call_softirq)
16603
16604 #ifdef CONFIG_XEN
16605 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
16606 @@ -1326,7 +1704,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
16607 decl PER_CPU_VAR(irq_count)
16608 jmp error_exit
16609 CFI_ENDPROC
16610 -END(xen_do_hypervisor_callback)
16611 +ENDPROC(xen_do_hypervisor_callback)
16612
16613 /*
16614 * Hypervisor uses this for application faults while it executes.
16615 @@ -1385,7 +1763,7 @@ ENTRY(xen_failsafe_callback)
16616 SAVE_ALL
16617 jmp error_exit
16618 CFI_ENDPROC
16619 -END(xen_failsafe_callback)
16620 +ENDPROC(xen_failsafe_callback)
16621
16622 apicinterrupt XEN_HVM_EVTCHN_CALLBACK \
16623 xen_hvm_callback_vector xen_evtchn_do_upcall
16624 @@ -1434,16 +1812,31 @@ ENTRY(paranoid_exit)
16625 TRACE_IRQS_OFF_DEBUG
16626 testl %ebx,%ebx /* swapgs needed? */
16627 jnz paranoid_restore
16628 - testl $3,CS(%rsp)
16629 + testb $3,CS(%rsp)
16630 jnz paranoid_userspace
16631 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16632 + pax_exit_kernel
16633 + TRACE_IRQS_IRETQ 0
16634 + SWAPGS_UNSAFE_STACK
16635 + RESTORE_ALL 8
16636 + pax_force_retaddr_bts
16637 + jmp irq_return
16638 +#endif
16639 paranoid_swapgs:
16640 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16641 + pax_exit_kernel_user
16642 +#else
16643 + pax_exit_kernel
16644 +#endif
16645 TRACE_IRQS_IRETQ 0
16646 SWAPGS_UNSAFE_STACK
16647 RESTORE_ALL 8
16648 jmp irq_return
16649 paranoid_restore:
16650 + pax_exit_kernel
16651 TRACE_IRQS_IRETQ_DEBUG 0
16652 RESTORE_ALL 8
16653 + pax_force_retaddr_bts
16654 jmp irq_return
16655 paranoid_userspace:
16656 GET_THREAD_INFO(%rcx)
16657 @@ -1472,7 +1865,7 @@ paranoid_schedule:
16658 TRACE_IRQS_OFF
16659 jmp paranoid_userspace
16660 CFI_ENDPROC
16661 -END(paranoid_exit)
16662 +ENDPROC(paranoid_exit)
16663
16664 /*
16665 * Exception entry point. This expects an error code/orig_rax on the stack.
16666 @@ -1499,12 +1892,13 @@ ENTRY(error_entry)
16667 movq_cfi r14, R14+8
16668 movq_cfi r15, R15+8
16669 xorl %ebx,%ebx
16670 - testl $3,CS+8(%rsp)
16671 + testb $3,CS+8(%rsp)
16672 je error_kernelspace
16673 error_swapgs:
16674 SWAPGS
16675 error_sti:
16676 TRACE_IRQS_OFF
16677 + pax_force_retaddr_bts
16678 ret
16679
16680 /*
16681 @@ -1531,7 +1925,7 @@ bstep_iret:
16682 movq %rcx,RIP+8(%rsp)
16683 jmp error_swapgs
16684 CFI_ENDPROC
16685 -END(error_entry)
16686 +ENDPROC(error_entry)
16687
16688
16689 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
16690 @@ -1551,7 +1945,7 @@ ENTRY(error_exit)
16691 jnz retint_careful
16692 jmp retint_swapgs
16693 CFI_ENDPROC
16694 -END(error_exit)
16695 +ENDPROC(error_exit)
16696
16697 /*
16698 * Test if a given stack is an NMI stack or not.
16699 @@ -1609,9 +2003,11 @@ ENTRY(nmi)
16700 * If %cs was not the kernel segment, then the NMI triggered in user
16701 * space, which means it is definitely not nested.
16702 */
16703 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
16704 + je 1f
16705 cmpl $__KERNEL_CS, 16(%rsp)
16706 jne first_nmi
16707 -
16708 +1:
16709 /*
16710 * Check the special variable on the stack to see if NMIs are
16711 * executing.
16712 @@ -1758,6 +2154,16 @@ end_repeat_nmi:
16713 */
16714 call save_paranoid
16715 DEFAULT_FRAME 0
16716 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16717 + testb $3, CS(%rsp)
16718 + jnz 1f
16719 + pax_enter_kernel
16720 + jmp 2f
16721 +1: pax_enter_kernel_user
16722 +2:
16723 +#else
16724 + pax_enter_kernel
16725 +#endif
16726 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
16727 movq %rsp,%rdi
16728 movq $-1,%rsi
16729 @@ -1765,21 +2171,32 @@ end_repeat_nmi:
16730 testl %ebx,%ebx /* swapgs needed? */
16731 jnz nmi_restore
16732 nmi_swapgs:
16733 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16734 + pax_exit_kernel_user
16735 +#else
16736 + pax_exit_kernel
16737 +#endif
16738 SWAPGS_UNSAFE_STACK
16739 + RESTORE_ALL 8
16740 + /* Clear the NMI executing stack variable */
16741 + movq $0, 10*8(%rsp)
16742 + jmp irq_return
16743 nmi_restore:
16744 + pax_exit_kernel
16745 RESTORE_ALL 8
16746 + pax_force_retaddr_bts
16747 /* Clear the NMI executing stack variable */
16748 movq $0, 10*8(%rsp)
16749 jmp irq_return
16750 CFI_ENDPROC
16751 -END(nmi)
16752 +ENDPROC(nmi)
16753
16754 ENTRY(ignore_sysret)
16755 CFI_STARTPROC
16756 mov $-ENOSYS,%eax
16757 sysret
16758 CFI_ENDPROC
16759 -END(ignore_sysret)
16760 +ENDPROC(ignore_sysret)
16761
16762 /*
16763 * End of kprobes section
16764 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
16765 index c3a7cb4..3ad00dc 100644
16766 --- a/arch/x86/kernel/ftrace.c
16767 +++ b/arch/x86/kernel/ftrace.c
16768 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
16769 {
16770 unsigned char replaced[MCOUNT_INSN_SIZE];
16771
16772 + ip = ktla_ktva(ip);
16773 +
16774 /*
16775 * Note: Due to modules and __init, code can
16776 * disappear and change, we need to protect against faulting
16777 @@ -212,7 +214,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
16778 unsigned char old[MCOUNT_INSN_SIZE], *new;
16779 int ret;
16780
16781 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
16782 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
16783 new = ftrace_call_replace(ip, (unsigned long)func);
16784
16785 /* See comment above by declaration of modifying_ftrace_code */
16786 @@ -605,6 +607,8 @@ static int ftrace_mod_jmp(unsigned long ip,
16787 {
16788 unsigned char code[MCOUNT_INSN_SIZE];
16789
16790 + ip = ktla_ktva(ip);
16791 +
16792 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
16793 return -EFAULT;
16794
16795 diff --git a/arch/x86/kernel/head32.c b/arch/x86/kernel/head32.c
16796 index c18f59d..9c0c9f6 100644
16797 --- a/arch/x86/kernel/head32.c
16798 +++ b/arch/x86/kernel/head32.c
16799 @@ -18,6 +18,7 @@
16800 #include <asm/io_apic.h>
16801 #include <asm/bios_ebda.h>
16802 #include <asm/tlbflush.h>
16803 +#include <asm/boot.h>
16804
16805 static void __init i386_default_early_setup(void)
16806 {
16807 @@ -30,8 +31,7 @@ static void __init i386_default_early_setup(void)
16808
16809 void __init i386_start_kernel(void)
16810 {
16811 - memblock_reserve(__pa_symbol(&_text),
16812 - __pa_symbol(&__bss_stop) - __pa_symbol(&_text));
16813 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(&__bss_stop) - LOAD_PHYSICAL_ADDR);
16814
16815 #ifdef CONFIG_BLK_DEV_INITRD
16816 /* Reserve INITRD */
16817 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
16818 index d42ab17..cb1b997 100644
16819 --- a/arch/x86/kernel/head_32.S
16820 +++ b/arch/x86/kernel/head_32.S
16821 @@ -26,6 +26,12 @@
16822 /* Physical address */
16823 #define pa(X) ((X) - __PAGE_OFFSET)
16824
16825 +#ifdef CONFIG_PAX_KERNEXEC
16826 +#define ta(X) (X)
16827 +#else
16828 +#define ta(X) ((X) - __PAGE_OFFSET)
16829 +#endif
16830 +
16831 /*
16832 * References to members of the new_cpu_data structure.
16833 */
16834 @@ -55,11 +61,7 @@
16835 * and small than max_low_pfn, otherwise will waste some page table entries
16836 */
16837
16838 -#if PTRS_PER_PMD > 1
16839 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
16840 -#else
16841 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
16842 -#endif
16843 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
16844
16845 /* Number of possible pages in the lowmem region */
16846 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
16847 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
16848 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16849
16850 /*
16851 + * Real beginning of normal "text" segment
16852 + */
16853 +ENTRY(stext)
16854 +ENTRY(_stext)
16855 +
16856 +/*
16857 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
16858 * %esi points to the real-mode code as a 32-bit pointer.
16859 * CS and DS must be 4 GB flat segments, but we don't depend on
16860 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
16861 * can.
16862 */
16863 __HEAD
16864 +
16865 +#ifdef CONFIG_PAX_KERNEXEC
16866 + jmp startup_32
16867 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
16868 +.fill PAGE_SIZE-5,1,0xcc
16869 +#endif
16870 +
16871 ENTRY(startup_32)
16872 movl pa(stack_start),%ecx
16873
16874 @@ -106,6 +121,57 @@ ENTRY(startup_32)
16875 2:
16876 leal -__PAGE_OFFSET(%ecx),%esp
16877
16878 +#ifdef CONFIG_SMP
16879 + movl $pa(cpu_gdt_table),%edi
16880 + movl $__per_cpu_load,%eax
16881 + movw %ax,__KERNEL_PERCPU + 2(%edi)
16882 + rorl $16,%eax
16883 + movb %al,__KERNEL_PERCPU + 4(%edi)
16884 + movb %ah,__KERNEL_PERCPU + 7(%edi)
16885 + movl $__per_cpu_end - 1,%eax
16886 + subl $__per_cpu_start,%eax
16887 + movw %ax,__KERNEL_PERCPU + 0(%edi)
16888 +#endif
16889 +
16890 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16891 + movl $NR_CPUS,%ecx
16892 + movl $pa(cpu_gdt_table),%edi
16893 +1:
16894 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
16895 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
16896 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
16897 + addl $PAGE_SIZE_asm,%edi
16898 + loop 1b
16899 +#endif
16900 +
16901 +#ifdef CONFIG_PAX_KERNEXEC
16902 + movl $pa(boot_gdt),%edi
16903 + movl $__LOAD_PHYSICAL_ADDR,%eax
16904 + movw %ax,__BOOT_CS + 2(%edi)
16905 + rorl $16,%eax
16906 + movb %al,__BOOT_CS + 4(%edi)
16907 + movb %ah,__BOOT_CS + 7(%edi)
16908 + rorl $16,%eax
16909 +
16910 + ljmp $(__BOOT_CS),$1f
16911 +1:
16912 +
16913 + movl $NR_CPUS,%ecx
16914 + movl $pa(cpu_gdt_table),%edi
16915 + addl $__PAGE_OFFSET,%eax
16916 +1:
16917 + movw %ax,__KERNEL_CS + 2(%edi)
16918 + movw %ax,__KERNEXEC_KERNEL_CS + 2(%edi)
16919 + rorl $16,%eax
16920 + movb %al,__KERNEL_CS + 4(%edi)
16921 + movb %al,__KERNEXEC_KERNEL_CS + 4(%edi)
16922 + movb %ah,__KERNEL_CS + 7(%edi)
16923 + movb %ah,__KERNEXEC_KERNEL_CS + 7(%edi)
16924 + rorl $16,%eax
16925 + addl $PAGE_SIZE_asm,%edi
16926 + loop 1b
16927 +#endif
16928 +
16929 /*
16930 * Clear BSS first so that there are no surprises...
16931 */
16932 @@ -196,8 +262,11 @@ ENTRY(startup_32)
16933 movl %eax, pa(max_pfn_mapped)
16934
16935 /* Do early initialization of the fixmap area */
16936 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16937 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
16938 +#ifdef CONFIG_COMPAT_VDSO
16939 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
16940 +#else
16941 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
16942 +#endif
16943 #else /* Not PAE */
16944
16945 page_pde_offset = (__PAGE_OFFSET >> 20);
16946 @@ -227,8 +296,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16947 movl %eax, pa(max_pfn_mapped)
16948
16949 /* Do early initialization of the fixmap area */
16950 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
16951 - movl %eax,pa(initial_page_table+0xffc)
16952 +#ifdef CONFIG_COMPAT_VDSO
16953 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
16954 +#else
16955 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
16956 +#endif
16957 #endif
16958
16959 #ifdef CONFIG_PARAVIRT
16960 @@ -242,9 +314,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
16961 cmpl $num_subarch_entries, %eax
16962 jae bad_subarch
16963
16964 - movl pa(subarch_entries)(,%eax,4), %eax
16965 - subl $__PAGE_OFFSET, %eax
16966 - jmp *%eax
16967 + jmp *pa(subarch_entries)(,%eax,4)
16968
16969 bad_subarch:
16970 WEAK(lguest_entry)
16971 @@ -256,10 +326,10 @@ WEAK(xen_entry)
16972 __INITDATA
16973
16974 subarch_entries:
16975 - .long default_entry /* normal x86/PC */
16976 - .long lguest_entry /* lguest hypervisor */
16977 - .long xen_entry /* Xen hypervisor */
16978 - .long default_entry /* Moorestown MID */
16979 + .long ta(default_entry) /* normal x86/PC */
16980 + .long ta(lguest_entry) /* lguest hypervisor */
16981 + .long ta(xen_entry) /* Xen hypervisor */
16982 + .long ta(default_entry) /* Moorestown MID */
16983 num_subarch_entries = (. - subarch_entries) / 4
16984 .previous
16985 #else
16986 @@ -310,6 +380,7 @@ default_entry:
16987 orl %edx,%eax
16988 movl %eax,%cr4
16989
16990 +#ifdef CONFIG_X86_PAE
16991 testb $X86_CR4_PAE, %al # check if PAE is enabled
16992 jz 6f
16993
16994 @@ -338,6 +409,9 @@ default_entry:
16995 /* Make changes effective */
16996 wrmsr
16997
16998 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
16999 +#endif
17000 +
17001 6:
17002
17003 /*
17004 @@ -436,14 +510,20 @@ is386: movl $2,%ecx # set MP
17005 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
17006 movl %eax,%ss # after changing gdt.
17007
17008 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
17009 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
17010 movl %eax,%ds
17011 movl %eax,%es
17012
17013 movl $(__KERNEL_PERCPU), %eax
17014 movl %eax,%fs # set this cpu's percpu
17015
17016 +#ifdef CONFIG_CC_STACKPROTECTOR
17017 movl $(__KERNEL_STACK_CANARY),%eax
17018 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
17019 + movl $(__USER_DS),%eax
17020 +#else
17021 + xorl %eax,%eax
17022 +#endif
17023 movl %eax,%gs
17024
17025 xorl %eax,%eax # Clear LDT
17026 @@ -520,8 +600,11 @@ setup_once:
17027 * relocation. Manually set base address in stack canary
17028 * segment descriptor.
17029 */
17030 - movl $gdt_page,%eax
17031 + movl $cpu_gdt_table,%eax
17032 movl $stack_canary,%ecx
17033 +#ifdef CONFIG_SMP
17034 + addl $__per_cpu_load,%ecx
17035 +#endif
17036 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
17037 shrl $16, %ecx
17038 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
17039 @@ -552,7 +635,7 @@ ENDPROC(early_idt_handlers)
17040 /* This is global to keep gas from relaxing the jumps */
17041 ENTRY(early_idt_handler)
17042 cld
17043 - cmpl $2,%ss:early_recursion_flag
17044 + cmpl $1,%ss:early_recursion_flag
17045 je hlt_loop
17046 incl %ss:early_recursion_flag
17047
17048 @@ -590,8 +673,8 @@ ENTRY(early_idt_handler)
17049 pushl (20+6*4)(%esp) /* trapno */
17050 pushl $fault_msg
17051 call printk
17052 -#endif
17053 call dump_stack
17054 +#endif
17055 hlt_loop:
17056 hlt
17057 jmp hlt_loop
17058 @@ -610,8 +693,11 @@ ENDPROC(early_idt_handler)
17059 /* This is the default interrupt "handler" :-) */
17060 ALIGN
17061 ignore_int:
17062 - cld
17063 #ifdef CONFIG_PRINTK
17064 + cmpl $2,%ss:early_recursion_flag
17065 + je hlt_loop
17066 + incl %ss:early_recursion_flag
17067 + cld
17068 pushl %eax
17069 pushl %ecx
17070 pushl %edx
17071 @@ -620,9 +706,6 @@ ignore_int:
17072 movl $(__KERNEL_DS),%eax
17073 movl %eax,%ds
17074 movl %eax,%es
17075 - cmpl $2,early_recursion_flag
17076 - je hlt_loop
17077 - incl early_recursion_flag
17078 pushl 16(%esp)
17079 pushl 24(%esp)
17080 pushl 32(%esp)
17081 @@ -656,29 +739,43 @@ ENTRY(setup_once_ref)
17082 /*
17083 * BSS section
17084 */
17085 -__PAGE_ALIGNED_BSS
17086 - .align PAGE_SIZE
17087 #ifdef CONFIG_X86_PAE
17088 +.section .initial_pg_pmd,"a",@progbits
17089 initial_pg_pmd:
17090 .fill 1024*KPMDS,4,0
17091 #else
17092 +.section .initial_page_table,"a",@progbits
17093 ENTRY(initial_page_table)
17094 .fill 1024,4,0
17095 #endif
17096 +.section .initial_pg_fixmap,"a",@progbits
17097 initial_pg_fixmap:
17098 .fill 1024,4,0
17099 +.section .empty_zero_page,"a",@progbits
17100 ENTRY(empty_zero_page)
17101 .fill 4096,1,0
17102 +.section .swapper_pg_dir,"a",@progbits
17103 ENTRY(swapper_pg_dir)
17104 +#ifdef CONFIG_X86_PAE
17105 + .fill 4,8,0
17106 +#else
17107 .fill 1024,4,0
17108 +#endif
17109 +
17110 +/*
17111 + * The IDT has to be page-aligned to simplify the Pentium
17112 + * F0 0F bug workaround.. We have a special link segment
17113 + * for this.
17114 + */
17115 +.section .idt,"a",@progbits
17116 +ENTRY(idt_table)
17117 + .fill 256,8,0
17118
17119 /*
17120 * This starts the data section.
17121 */
17122 #ifdef CONFIG_X86_PAE
17123 -__PAGE_ALIGNED_DATA
17124 - /* Page-aligned for the benefit of paravirt? */
17125 - .align PAGE_SIZE
17126 +.section .initial_page_table,"a",@progbits
17127 ENTRY(initial_page_table)
17128 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
17129 # if KPMDS == 3
17130 @@ -697,12 +794,20 @@ ENTRY(initial_page_table)
17131 # error "Kernel PMDs should be 1, 2 or 3"
17132 # endif
17133 .align PAGE_SIZE /* needs to be page-sized too */
17134 +
17135 +#ifdef CONFIG_PAX_PER_CPU_PGD
17136 +ENTRY(cpu_pgd)
17137 + .rept NR_CPUS
17138 + .fill 4,8,0
17139 + .endr
17140 +#endif
17141 +
17142 #endif
17143
17144 .data
17145 .balign 4
17146 ENTRY(stack_start)
17147 - .long init_thread_union+THREAD_SIZE
17148 + .long init_thread_union+THREAD_SIZE-8
17149
17150 __INITRODATA
17151 int_msg:
17152 @@ -730,7 +835,7 @@ fault_msg:
17153 * segment size, and 32-bit linear address value:
17154 */
17155
17156 - .data
17157 +.section .rodata,"a",@progbits
17158 .globl boot_gdt_descr
17159 .globl idt_descr
17160
17161 @@ -739,7 +844,7 @@ fault_msg:
17162 .word 0 # 32 bit align gdt_desc.address
17163 boot_gdt_descr:
17164 .word __BOOT_DS+7
17165 - .long boot_gdt - __PAGE_OFFSET
17166 + .long pa(boot_gdt)
17167
17168 .word 0 # 32-bit align idt_desc.address
17169 idt_descr:
17170 @@ -750,7 +855,7 @@ idt_descr:
17171 .word 0 # 32 bit align gdt_desc.address
17172 ENTRY(early_gdt_descr)
17173 .word GDT_ENTRIES*8-1
17174 - .long gdt_page /* Overwritten for secondary CPUs */
17175 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
17176
17177 /*
17178 * The boot_gdt must mirror the equivalent in setup.S and is
17179 @@ -759,5 +864,65 @@ ENTRY(early_gdt_descr)
17180 .align L1_CACHE_BYTES
17181 ENTRY(boot_gdt)
17182 .fill GDT_ENTRY_BOOT_CS,8,0
17183 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
17184 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
17185 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
17186 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
17187 +
17188 + .align PAGE_SIZE_asm
17189 +ENTRY(cpu_gdt_table)
17190 + .rept NR_CPUS
17191 + .quad 0x0000000000000000 /* NULL descriptor */
17192 + .quad 0x0000000000000000 /* 0x0b reserved */
17193 + .quad 0x0000000000000000 /* 0x13 reserved */
17194 + .quad 0x0000000000000000 /* 0x1b reserved */
17195 +
17196 +#ifdef CONFIG_PAX_KERNEXEC
17197 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
17198 +#else
17199 + .quad 0x0000000000000000 /* 0x20 unused */
17200 +#endif
17201 +
17202 + .quad 0x0000000000000000 /* 0x28 unused */
17203 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
17204 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
17205 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
17206 + .quad 0x0000000000000000 /* 0x4b reserved */
17207 + .quad 0x0000000000000000 /* 0x53 reserved */
17208 + .quad 0x0000000000000000 /* 0x5b reserved */
17209 +
17210 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
17211 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
17212 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
17213 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
17214 +
17215 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
17216 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
17217 +
17218 + /*
17219 + * Segments used for calling PnP BIOS have byte granularity.
17220 + * The code segments and data segments have fixed 64k limits,
17221 + * the transfer segment sizes are set at run time.
17222 + */
17223 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
17224 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
17225 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
17226 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
17227 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
17228 +
17229 + /*
17230 + * The APM segments have byte granularity and their bases
17231 + * are set at run time. All have 64k limits.
17232 + */
17233 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
17234 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
17235 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
17236 +
17237 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
17238 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
17239 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
17240 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
17241 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
17242 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
17243 +
17244 + /* Be sure this is zeroed to avoid false validations in Xen */
17245 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
17246 + .endr
17247 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
17248 index 94bf9cc..400455a 100644
17249 --- a/arch/x86/kernel/head_64.S
17250 +++ b/arch/x86/kernel/head_64.S
17251 @@ -20,6 +20,8 @@
17252 #include <asm/processor-flags.h>
17253 #include <asm/percpu.h>
17254 #include <asm/nops.h>
17255 +#include <asm/cpufeature.h>
17256 +#include <asm/alternative-asm.h>
17257
17258 #ifdef CONFIG_PARAVIRT
17259 #include <asm/asm-offsets.h>
17260 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
17261 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
17262 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
17263 L3_START_KERNEL = pud_index(__START_KERNEL_map)
17264 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
17265 +L3_VMALLOC_START = pud_index(VMALLOC_START)
17266 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
17267 +L3_VMALLOC_END = pud_index(VMALLOC_END)
17268 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
17269 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
17270
17271 .text
17272 __HEAD
17273 @@ -88,35 +96,23 @@ startup_64:
17274 */
17275 addq %rbp, init_level4_pgt + 0(%rip)
17276 addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
17277 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
17278 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
17279 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
17280 addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
17281
17282 addq %rbp, level3_ident_pgt + 0(%rip)
17283 +#ifndef CONFIG_XEN
17284 + addq %rbp, level3_ident_pgt + 8(%rip)
17285 +#endif
17286
17287 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
17288 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
17289 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
17290 +
17291 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
17292 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8+8)(%rip)
17293
17294 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
17295 -
17296 - /* Add an Identity mapping if I am above 1G */
17297 - leaq _text(%rip), %rdi
17298 - andq $PMD_PAGE_MASK, %rdi
17299 -
17300 - movq %rdi, %rax
17301 - shrq $PUD_SHIFT, %rax
17302 - andq $(PTRS_PER_PUD - 1), %rax
17303 - jz ident_complete
17304 -
17305 - leaq (level2_spare_pgt - __START_KERNEL_map + _KERNPG_TABLE)(%rbp), %rdx
17306 - leaq level3_ident_pgt(%rip), %rbx
17307 - movq %rdx, 0(%rbx, %rax, 8)
17308 -
17309 - movq %rdi, %rax
17310 - shrq $PMD_SHIFT, %rax
17311 - andq $(PTRS_PER_PMD - 1), %rax
17312 - leaq __PAGE_KERNEL_IDENT_LARGE_EXEC(%rdi), %rdx
17313 - leaq level2_spare_pgt(%rip), %rbx
17314 - movq %rdx, 0(%rbx, %rax, 8)
17315 -ident_complete:
17316 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
17317
17318 /*
17319 * Fixup the kernel text+data virtual addresses. Note that
17320 @@ -159,8 +155,8 @@ ENTRY(secondary_startup_64)
17321 * after the boot processor executes this code.
17322 */
17323
17324 - /* Enable PAE mode and PGE */
17325 - movl $(X86_CR4_PAE | X86_CR4_PGE), %eax
17326 + /* Enable PAE mode and PSE/PGE */
17327 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %eax
17328 movq %rax, %cr4
17329
17330 /* Setup early boot stage 4 level pagetables. */
17331 @@ -182,9 +178,17 @@ ENTRY(secondary_startup_64)
17332 movl $MSR_EFER, %ecx
17333 rdmsr
17334 btsl $_EFER_SCE, %eax /* Enable System Call */
17335 - btl $20,%edi /* No Execute supported? */
17336 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
17337 jnc 1f
17338 btsl $_EFER_NX, %eax
17339 + leaq init_level4_pgt(%rip), %rdi
17340 +#ifndef CONFIG_EFI
17341 + btsq $_PAGE_BIT_NX, 8*L4_PAGE_OFFSET(%rdi)
17342 +#endif
17343 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_START(%rdi)
17344 + btsq $_PAGE_BIT_NX, 8*L4_VMALLOC_END(%rdi)
17345 + btsq $_PAGE_BIT_NX, 8*L4_VMEMMAP_START(%rdi)
17346 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
17347 1: wrmsr /* Make changes effective */
17348
17349 /* Setup cr0 */
17350 @@ -246,6 +250,7 @@ ENTRY(secondary_startup_64)
17351 * jump. In addition we need to ensure %cs is set so we make this
17352 * a far return.
17353 */
17354 + pax_set_fptr_mask
17355 movq initial_code(%rip),%rax
17356 pushq $0 # fake return address to stop unwinder
17357 pushq $__KERNEL_CS # set correct cs
17358 @@ -268,7 +273,7 @@ ENTRY(secondary_startup_64)
17359 bad_address:
17360 jmp bad_address
17361
17362 - .section ".init.text","ax"
17363 + __INIT
17364 .globl early_idt_handlers
17365 early_idt_handlers:
17366 # 104(%rsp) %rflags
17367 @@ -347,11 +352,15 @@ ENTRY(early_idt_handler)
17368 addq $16,%rsp # drop vector number and error code
17369 decl early_recursion_flag(%rip)
17370 INTERRUPT_RETURN
17371 + .previous
17372
17373 + __INITDATA
17374 .balign 4
17375 early_recursion_flag:
17376 .long 0
17377 + .previous
17378
17379 + .section .rodata,"a",@progbits
17380 #ifdef CONFIG_EARLY_PRINTK
17381 early_idt_msg:
17382 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
17383 @@ -360,6 +369,7 @@ early_idt_ripmsg:
17384 #endif /* CONFIG_EARLY_PRINTK */
17385 .previous
17386
17387 + .section .rodata,"a",@progbits
17388 #define NEXT_PAGE(name) \
17389 .balign PAGE_SIZE; \
17390 ENTRY(name)
17391 @@ -372,7 +382,6 @@ ENTRY(name)
17392 i = i + 1 ; \
17393 .endr
17394
17395 - .data
17396 /*
17397 * This default setting generates an ident mapping at address 0x100000
17398 * and a mapping for the kernel that precisely maps virtual address
17399 @@ -383,13 +392,41 @@ NEXT_PAGE(init_level4_pgt)
17400 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17401 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
17402 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17403 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
17404 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
17405 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
17406 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
17407 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
17408 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17409 .org init_level4_pgt + L4_START_KERNEL*8, 0
17410 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
17411 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
17412
17413 +#ifdef CONFIG_PAX_PER_CPU_PGD
17414 +NEXT_PAGE(cpu_pgd)
17415 + .rept NR_CPUS
17416 + .fill 512,8,0
17417 + .endr
17418 +#endif
17419 +
17420 NEXT_PAGE(level3_ident_pgt)
17421 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
17422 +#ifdef CONFIG_XEN
17423 .fill 511,8,0
17424 +#else
17425 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
17426 + .fill 510,8,0
17427 +#endif
17428 +
17429 +NEXT_PAGE(level3_vmalloc_start_pgt)
17430 + .fill 512,8,0
17431 +
17432 +NEXT_PAGE(level3_vmalloc_end_pgt)
17433 + .fill 512,8,0
17434 +
17435 +NEXT_PAGE(level3_vmemmap_pgt)
17436 + .fill L3_VMEMMAP_START,8,0
17437 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
17438
17439 NEXT_PAGE(level3_kernel_pgt)
17440 .fill L3_START_KERNEL,8,0
17441 @@ -397,20 +434,23 @@ NEXT_PAGE(level3_kernel_pgt)
17442 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
17443 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17444
17445 +NEXT_PAGE(level2_vmemmap_pgt)
17446 + .fill 512,8,0
17447 +
17448 NEXT_PAGE(level2_fixmap_pgt)
17449 - .fill 506,8,0
17450 - .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
17451 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
17452 - .fill 5,8,0
17453 + .fill 507,8,0
17454 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
17455 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
17456 + .fill 4,8,0
17457
17458 -NEXT_PAGE(level1_fixmap_pgt)
17459 +NEXT_PAGE(level1_vsyscall_pgt)
17460 .fill 512,8,0
17461
17462 -NEXT_PAGE(level2_ident_pgt)
17463 - /* Since I easily can, map the first 1G.
17464 + /* Since I easily can, map the first 2G.
17465 * Don't set NX because code runs from these pages.
17466 */
17467 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
17468 +NEXT_PAGE(level2_ident_pgt)
17469 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
17470
17471 NEXT_PAGE(level2_kernel_pgt)
17472 /*
17473 @@ -423,37 +463,59 @@ NEXT_PAGE(level2_kernel_pgt)
17474 * If you want to increase this then increase MODULES_VADDR
17475 * too.)
17476 */
17477 - PMDS(0, __PAGE_KERNEL_LARGE_EXEC,
17478 - KERNEL_IMAGE_SIZE/PMD_SIZE)
17479 -
17480 -NEXT_PAGE(level2_spare_pgt)
17481 - .fill 512, 8, 0
17482 + PMDS(0, __PAGE_KERNEL_LARGE_EXEC, KERNEL_IMAGE_SIZE/PMD_SIZE)
17483
17484 #undef PMDS
17485 #undef NEXT_PAGE
17486
17487 - .data
17488 + .align PAGE_SIZE
17489 +ENTRY(cpu_gdt_table)
17490 + .rept NR_CPUS
17491 + .quad 0x0000000000000000 /* NULL descriptor */
17492 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
17493 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
17494 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
17495 + .quad 0x00cffb000000ffff /* __USER32_CS */
17496 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
17497 + .quad 0x00affb000000ffff /* __USER_CS */
17498 +
17499 +#ifdef CONFIG_PAX_KERNEXEC
17500 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
17501 +#else
17502 + .quad 0x0 /* unused */
17503 +#endif
17504 +
17505 + .quad 0,0 /* TSS */
17506 + .quad 0,0 /* LDT */
17507 + .quad 0,0,0 /* three TLS descriptors */
17508 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
17509 + /* asm/segment.h:GDT_ENTRIES must match this */
17510 +
17511 + /* zero the remaining page */
17512 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
17513 + .endr
17514 +
17515 .align 16
17516 .globl early_gdt_descr
17517 early_gdt_descr:
17518 .word GDT_ENTRIES*8-1
17519 early_gdt_descr_base:
17520 - .quad INIT_PER_CPU_VAR(gdt_page)
17521 + .quad cpu_gdt_table
17522
17523 ENTRY(phys_base)
17524 /* This must match the first entry in level2_kernel_pgt */
17525 .quad 0x0000000000000000
17526
17527 #include "../../x86/xen/xen-head.S"
17528 -
17529 - .section .bss, "aw", @nobits
17530 +
17531 + .section .rodata,"a",@progbits
17532 .align L1_CACHE_BYTES
17533 ENTRY(idt_table)
17534 - .skip IDT_ENTRIES * 16
17535 + .fill 512,8,0
17536
17537 .align L1_CACHE_BYTES
17538 ENTRY(nmi_idt_table)
17539 - .skip IDT_ENTRIES * 16
17540 + .fill 512,8,0
17541
17542 __PAGE_ALIGNED_BSS
17543 .align PAGE_SIZE
17544 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
17545 index 9c3bd4a..e1d9b35 100644
17546 --- a/arch/x86/kernel/i386_ksyms_32.c
17547 +++ b/arch/x86/kernel/i386_ksyms_32.c
17548 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
17549 EXPORT_SYMBOL(cmpxchg8b_emu);
17550 #endif
17551
17552 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
17553 +
17554 /* Networking helper routines. */
17555 EXPORT_SYMBOL(csum_partial_copy_generic);
17556 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
17557 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
17558
17559 EXPORT_SYMBOL(__get_user_1);
17560 EXPORT_SYMBOL(__get_user_2);
17561 @@ -36,3 +40,7 @@ EXPORT_SYMBOL(strstr);
17562
17563 EXPORT_SYMBOL(csum_partial);
17564 EXPORT_SYMBOL(empty_zero_page);
17565 +
17566 +#ifdef CONFIG_PAX_KERNEXEC
17567 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
17568 +#endif
17569 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
17570 index f250431..54097e7 100644
17571 --- a/arch/x86/kernel/i387.c
17572 +++ b/arch/x86/kernel/i387.c
17573 @@ -59,7 +59,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
17574 static inline bool interrupted_user_mode(void)
17575 {
17576 struct pt_regs *regs = get_irq_regs();
17577 - return regs && user_mode_vm(regs);
17578 + return regs && user_mode(regs);
17579 }
17580
17581 /*
17582 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
17583 index 36d1853..bf25736 100644
17584 --- a/arch/x86/kernel/i8259.c
17585 +++ b/arch/x86/kernel/i8259.c
17586 @@ -209,7 +209,7 @@ spurious_8259A_irq:
17587 "spurious 8259A interrupt: IRQ%d.\n", irq);
17588 spurious_irq_mask |= irqmask;
17589 }
17590 - atomic_inc(&irq_err_count);
17591 + atomic_inc_unchecked(&irq_err_count);
17592 /*
17593 * Theoretically we do not have to handle this IRQ,
17594 * but in Linux this does not cause problems and is
17595 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
17596 index 8c96897..be66bfa 100644
17597 --- a/arch/x86/kernel/ioport.c
17598 +++ b/arch/x86/kernel/ioport.c
17599 @@ -6,6 +6,7 @@
17600 #include <linux/sched.h>
17601 #include <linux/kernel.h>
17602 #include <linux/capability.h>
17603 +#include <linux/security.h>
17604 #include <linux/errno.h>
17605 #include <linux/types.h>
17606 #include <linux/ioport.h>
17607 @@ -28,6 +29,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17608
17609 if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
17610 return -EINVAL;
17611 +#ifdef CONFIG_GRKERNSEC_IO
17612 + if (turn_on && grsec_disable_privio) {
17613 + gr_handle_ioperm();
17614 + return -EPERM;
17615 + }
17616 +#endif
17617 if (turn_on && !capable(CAP_SYS_RAWIO))
17618 return -EPERM;
17619
17620 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
17621 * because the ->io_bitmap_max value must match the bitmap
17622 * contents:
17623 */
17624 - tss = &per_cpu(init_tss, get_cpu());
17625 + tss = init_tss + get_cpu();
17626
17627 if (turn_on)
17628 bitmap_clear(t->io_bitmap_ptr, from, num);
17629 @@ -102,6 +109,12 @@ long sys_iopl(unsigned int level, struct pt_regs *regs)
17630 return -EINVAL;
17631 /* Trying to gain more privileges? */
17632 if (level > old) {
17633 +#ifdef CONFIG_GRKERNSEC_IO
17634 + if (grsec_disable_privio) {
17635 + gr_handle_iopl();
17636 + return -EPERM;
17637 + }
17638 +#endif
17639 if (!capable(CAP_SYS_RAWIO))
17640 return -EPERM;
17641 }
17642 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
17643 index 3dafc60..aa8e9c4 100644
17644 --- a/arch/x86/kernel/irq.c
17645 +++ b/arch/x86/kernel/irq.c
17646 @@ -18,7 +18,7 @@
17647 #include <asm/mce.h>
17648 #include <asm/hw_irq.h>
17649
17650 -atomic_t irq_err_count;
17651 +atomic_unchecked_t irq_err_count;
17652
17653 /* Function pointer for generic interrupt vector handling */
17654 void (*x86_platform_ipi_callback)(void) = NULL;
17655 @@ -121,9 +121,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
17656 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
17657 seq_printf(p, " Machine check polls\n");
17658 #endif
17659 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
17660 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
17661 #if defined(CONFIG_X86_IO_APIC)
17662 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
17663 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
17664 #endif
17665 return 0;
17666 }
17667 @@ -164,10 +164,10 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
17668
17669 u64 arch_irq_stat(void)
17670 {
17671 - u64 sum = atomic_read(&irq_err_count);
17672 + u64 sum = atomic_read_unchecked(&irq_err_count);
17673
17674 #ifdef CONFIG_X86_IO_APIC
17675 - sum += atomic_read(&irq_mis_count);
17676 + sum += atomic_read_unchecked(&irq_mis_count);
17677 #endif
17678 return sum;
17679 }
17680 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
17681 index 344faf8..355f60d 100644
17682 --- a/arch/x86/kernel/irq_32.c
17683 +++ b/arch/x86/kernel/irq_32.c
17684 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
17685 __asm__ __volatile__("andl %%esp,%0" :
17686 "=r" (sp) : "0" (THREAD_SIZE - 1));
17687
17688 - return sp < (sizeof(struct thread_info) + STACK_WARN);
17689 + return sp < STACK_WARN;
17690 }
17691
17692 static void print_stack_overflow(void)
17693 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
17694 * per-CPU IRQ handling contexts (thread information and stack)
17695 */
17696 union irq_ctx {
17697 - struct thread_info tinfo;
17698 - u32 stack[THREAD_SIZE/sizeof(u32)];
17699 + unsigned long previous_esp;
17700 + u32 stack[THREAD_SIZE/sizeof(u32)];
17701 } __attribute__((aligned(THREAD_SIZE)));
17702
17703 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
17704 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
17705 static inline int
17706 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17707 {
17708 - union irq_ctx *curctx, *irqctx;
17709 + union irq_ctx *irqctx;
17710 u32 *isp, arg1, arg2;
17711
17712 - curctx = (union irq_ctx *) current_thread_info();
17713 irqctx = __this_cpu_read(hardirq_ctx);
17714
17715 /*
17716 @@ -92,16 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17717 * handler) we can't do that and just have to keep using the
17718 * current stack (which is the irq stack already after all)
17719 */
17720 - if (unlikely(curctx == irqctx))
17721 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
17722 return 0;
17723
17724 /* build the stack frame on the IRQ stack */
17725 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17726 - irqctx->tinfo.task = curctx->tinfo.task;
17727 - irqctx->tinfo.previous_esp = current_stack_pointer;
17728 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17729 + irqctx->previous_esp = current_stack_pointer;
17730
17731 - /* Copy the preempt_count so that the [soft]irq checks work. */
17732 - irqctx->tinfo.preempt_count = curctx->tinfo.preempt_count;
17733 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17734 + __set_fs(MAKE_MM_SEG(0));
17735 +#endif
17736
17737 if (unlikely(overflow))
17738 call_on_stack(print_stack_overflow, isp);
17739 @@ -113,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17740 : "0" (irq), "1" (desc), "2" (isp),
17741 "D" (desc->handle_irq)
17742 : "memory", "cc", "ecx");
17743 +
17744 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17745 + __set_fs(current_thread_info()->addr_limit);
17746 +#endif
17747 +
17748 return 1;
17749 }
17750
17751 @@ -121,29 +125,14 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
17752 */
17753 void __cpuinit irq_ctx_init(int cpu)
17754 {
17755 - union irq_ctx *irqctx;
17756 -
17757 if (per_cpu(hardirq_ctx, cpu))
17758 return;
17759
17760 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17761 - THREADINFO_GFP,
17762 - THREAD_SIZE_ORDER));
17763 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17764 - irqctx->tinfo.cpu = cpu;
17765 - irqctx->tinfo.preempt_count = HARDIRQ_OFFSET;
17766 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17767 -
17768 - per_cpu(hardirq_ctx, cpu) = irqctx;
17769 -
17770 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
17771 - THREADINFO_GFP,
17772 - THREAD_SIZE_ORDER));
17773 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
17774 - irqctx->tinfo.cpu = cpu;
17775 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
17776 -
17777 - per_cpu(softirq_ctx, cpu) = irqctx;
17778 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17779 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
17780 +
17781 + printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17782 + cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17783
17784 printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
17785 cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
17786 @@ -152,7 +141,6 @@ void __cpuinit irq_ctx_init(int cpu)
17787 asmlinkage void do_softirq(void)
17788 {
17789 unsigned long flags;
17790 - struct thread_info *curctx;
17791 union irq_ctx *irqctx;
17792 u32 *isp;
17793
17794 @@ -162,15 +150,22 @@ asmlinkage void do_softirq(void)
17795 local_irq_save(flags);
17796
17797 if (local_softirq_pending()) {
17798 - curctx = current_thread_info();
17799 irqctx = __this_cpu_read(softirq_ctx);
17800 - irqctx->tinfo.task = curctx->task;
17801 - irqctx->tinfo.previous_esp = current_stack_pointer;
17802 + irqctx->previous_esp = current_stack_pointer;
17803
17804 /* build the stack frame on the softirq stack */
17805 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
17806 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
17807 +
17808 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17809 + __set_fs(MAKE_MM_SEG(0));
17810 +#endif
17811
17812 call_on_stack(__do_softirq, isp);
17813 +
17814 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17815 + __set_fs(current_thread_info()->addr_limit);
17816 +#endif
17817 +
17818 /*
17819 * Shouldn't happen, we returned above if in_interrupt():
17820 */
17821 @@ -191,7 +186,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
17822 if (unlikely(!desc))
17823 return false;
17824
17825 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17826 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
17827 if (unlikely(overflow))
17828 print_stack_overflow();
17829 desc->handle_irq(irq, desc);
17830 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
17831 index d04d3ec..ea4b374 100644
17832 --- a/arch/x86/kernel/irq_64.c
17833 +++ b/arch/x86/kernel/irq_64.c
17834 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
17835 u64 estack_top, estack_bottom;
17836 u64 curbase = (u64)task_stack_page(current);
17837
17838 - if (user_mode_vm(regs))
17839 + if (user_mode(regs))
17840 return;
17841
17842 if (regs->sp >= curbase + sizeof(struct thread_info) +
17843 diff --git a/arch/x86/kernel/kdebugfs.c b/arch/x86/kernel/kdebugfs.c
17844 index 1d5d31e..72731d4 100644
17845 --- a/arch/x86/kernel/kdebugfs.c
17846 +++ b/arch/x86/kernel/kdebugfs.c
17847 @@ -27,7 +27,7 @@ struct setup_data_node {
17848 u32 len;
17849 };
17850
17851 -static ssize_t setup_data_read(struct file *file, char __user *user_buf,
17852 +static ssize_t __size_overflow(3) setup_data_read(struct file *file, char __user *user_buf,
17853 size_t count, loff_t *ppos)
17854 {
17855 struct setup_data_node *node = file->private_data;
17856 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
17857 index 3f61904..873cea9 100644
17858 --- a/arch/x86/kernel/kgdb.c
17859 +++ b/arch/x86/kernel/kgdb.c
17860 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
17861 #ifdef CONFIG_X86_32
17862 switch (regno) {
17863 case GDB_SS:
17864 - if (!user_mode_vm(regs))
17865 + if (!user_mode(regs))
17866 *(unsigned long *)mem = __KERNEL_DS;
17867 break;
17868 case GDB_SP:
17869 - if (!user_mode_vm(regs))
17870 + if (!user_mode(regs))
17871 *(unsigned long *)mem = kernel_stack_pointer(regs);
17872 break;
17873 case GDB_GS:
17874 @@ -476,12 +476,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
17875 case 'k':
17876 /* clear the trace bit */
17877 linux_regs->flags &= ~X86_EFLAGS_TF;
17878 - atomic_set(&kgdb_cpu_doing_single_step, -1);
17879 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
17880
17881 /* set the trace bit if we're stepping */
17882 if (remcomInBuffer[0] == 's') {
17883 linux_regs->flags |= X86_EFLAGS_TF;
17884 - atomic_set(&kgdb_cpu_doing_single_step,
17885 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
17886 raw_smp_processor_id());
17887 }
17888
17889 @@ -546,7 +546,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
17890
17891 switch (cmd) {
17892 case DIE_DEBUG:
17893 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
17894 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
17895 if (user_mode(regs))
17896 return single_step_cont(regs, args);
17897 break;
17898 diff --git a/arch/x86/kernel/kprobes-opt.c b/arch/x86/kernel/kprobes-opt.c
17899 index c5e410e..da6aaf9 100644
17900 --- a/arch/x86/kernel/kprobes-opt.c
17901 +++ b/arch/x86/kernel/kprobes-opt.c
17902 @@ -338,7 +338,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17903 * Verify if the address gap is in 2GB range, because this uses
17904 * a relative jump.
17905 */
17906 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
17907 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
17908 if (abs(rel) > 0x7fffffff)
17909 return -ERANGE;
17910
17911 @@ -359,11 +359,11 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
17912 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
17913
17914 /* Set probe function call */
17915 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
17916 + synthesize_relcall(buf + TMPL_CALL_IDX, ktla_ktva(optimized_callback));
17917
17918 /* Set returning jmp instruction at the tail of out-of-line buffer */
17919 synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
17920 - (u8 *)op->kp.addr + op->optinsn.size);
17921 + (u8 *)ktla_ktva(op->kp.addr) + op->optinsn.size);
17922
17923 flush_icache_range((unsigned long) buf,
17924 (unsigned long) buf + TMPL_END_IDX +
17925 @@ -385,7 +385,7 @@ static void __kprobes setup_optimize_kprobe(struct text_poke_param *tprm,
17926 ((long)op->kp.addr + RELATIVEJUMP_SIZE));
17927
17928 /* Backup instructions which will be replaced by jump address */
17929 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
17930 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
17931 RELATIVE_ADDR_SIZE);
17932
17933 insn_buf[0] = RELATIVEJUMP_OPCODE;
17934 diff --git a/arch/x86/kernel/kprobes.c b/arch/x86/kernel/kprobes.c
17935 index e2f751e..dffa2a0 100644
17936 --- a/arch/x86/kernel/kprobes.c
17937 +++ b/arch/x86/kernel/kprobes.c
17938 @@ -120,8 +120,11 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
17939 } __attribute__((packed)) *insn;
17940
17941 insn = (struct __arch_relative_insn *)from;
17942 +
17943 + pax_open_kernel();
17944 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
17945 insn->op = op;
17946 + pax_close_kernel();
17947 }
17948
17949 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
17950 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
17951 kprobe_opcode_t opcode;
17952 kprobe_opcode_t *orig_opcodes = opcodes;
17953
17954 - if (search_exception_tables((unsigned long)opcodes))
17955 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
17956 return 0; /* Page fault may occur on this address. */
17957
17958 retry:
17959 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17960 /* Another subsystem puts a breakpoint, failed to recover */
17961 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
17962 return 0;
17963 + pax_open_kernel();
17964 memcpy(dest, insn.kaddr, insn.length);
17965 + pax_close_kernel();
17966
17967 #ifdef CONFIG_X86_64
17968 if (insn_rip_relative(&insn)) {
17969 @@ -355,7 +360,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
17970 newdisp = (u8 *) src + (s64) insn.displacement.value - (u8 *) dest;
17971 BUG_ON((s64) (s32) newdisp != newdisp); /* Sanity check. */
17972 disp = (u8 *) dest + insn_offset_displacement(&insn);
17973 + pax_open_kernel();
17974 *(s32 *) disp = (s32) newdisp;
17975 + pax_close_kernel();
17976 }
17977 #endif
17978 return insn.length;
17979 @@ -485,7 +492,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17980 * nor set current_kprobe, because it doesn't use single
17981 * stepping.
17982 */
17983 - regs->ip = (unsigned long)p->ainsn.insn;
17984 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17985 preempt_enable_no_resched();
17986 return;
17987 }
17988 @@ -504,7 +511,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
17989 if (p->opcode == BREAKPOINT_INSTRUCTION)
17990 regs->ip = (unsigned long)p->addr;
17991 else
17992 - regs->ip = (unsigned long)p->ainsn.insn;
17993 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
17994 }
17995
17996 /*
17997 @@ -583,7 +590,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
17998 setup_singlestep(p, regs, kcb, 0);
17999 return 1;
18000 }
18001 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
18002 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
18003 /*
18004 * The breakpoint instruction was removed right
18005 * after we hit it. Another cpu has removed
18006 @@ -628,6 +635,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
18007 " movq %rax, 152(%rsp)\n"
18008 RESTORE_REGS_STRING
18009 " popfq\n"
18010 +#ifdef KERNEXEC_PLUGIN
18011 + " btsq $63,(%rsp)\n"
18012 +#endif
18013 #else
18014 " pushf\n"
18015 SAVE_REGS_STRING
18016 @@ -765,7 +775,7 @@ static void __kprobes
18017 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
18018 {
18019 unsigned long *tos = stack_addr(regs);
18020 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
18021 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
18022 unsigned long orig_ip = (unsigned long)p->addr;
18023 kprobe_opcode_t *insn = p->ainsn.insn;
18024
18025 @@ -947,7 +957,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
18026 struct die_args *args = data;
18027 int ret = NOTIFY_DONE;
18028
18029 - if (args->regs && user_mode_vm(args->regs))
18030 + if (args->regs && user_mode(args->regs))
18031 return ret;
18032
18033 switch (val) {
18034 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
18035 index ebc9873..1b9724b 100644
18036 --- a/arch/x86/kernel/ldt.c
18037 +++ b/arch/x86/kernel/ldt.c
18038 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
18039 if (reload) {
18040 #ifdef CONFIG_SMP
18041 preempt_disable();
18042 - load_LDT(pc);
18043 + load_LDT_nolock(pc);
18044 if (!cpumask_equal(mm_cpumask(current->mm),
18045 cpumask_of(smp_processor_id())))
18046 smp_call_function(flush_ldt, current->mm, 1);
18047 preempt_enable();
18048 #else
18049 - load_LDT(pc);
18050 + load_LDT_nolock(pc);
18051 #endif
18052 }
18053 if (oldsize) {
18054 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
18055 return err;
18056
18057 for (i = 0; i < old->size; i++)
18058 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
18059 + write_ldt_entry(new->ldt, i, old->ldt + i);
18060 return 0;
18061 }
18062
18063 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
18064 retval = copy_ldt(&mm->context, &old_mm->context);
18065 mutex_unlock(&old_mm->context.lock);
18066 }
18067 +
18068 + if (tsk == current) {
18069 + mm->context.vdso = 0;
18070 +
18071 +#ifdef CONFIG_X86_32
18072 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
18073 + mm->context.user_cs_base = 0UL;
18074 + mm->context.user_cs_limit = ~0UL;
18075 +
18076 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
18077 + cpus_clear(mm->context.cpu_user_cs_mask);
18078 +#endif
18079 +
18080 +#endif
18081 +#endif
18082 +
18083 + }
18084 +
18085 return retval;
18086 }
18087
18088 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
18089 }
18090 }
18091
18092 +#ifdef CONFIG_PAX_SEGMEXEC
18093 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
18094 + error = -EINVAL;
18095 + goto out_unlock;
18096 + }
18097 +#endif
18098 +
18099 fill_ldt(&ldt, &ldt_info);
18100 if (oldmode)
18101 ldt.avl = 0;
18102 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
18103 index 5b19e4d..6476a76 100644
18104 --- a/arch/x86/kernel/machine_kexec_32.c
18105 +++ b/arch/x86/kernel/machine_kexec_32.c
18106 @@ -26,7 +26,7 @@
18107 #include <asm/cacheflush.h>
18108 #include <asm/debugreg.h>
18109
18110 -static void set_idt(void *newidt, __u16 limit)
18111 +static void set_idt(struct desc_struct *newidt, __u16 limit)
18112 {
18113 struct desc_ptr curidt;
18114
18115 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
18116 }
18117
18118
18119 -static void set_gdt(void *newgdt, __u16 limit)
18120 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
18121 {
18122 struct desc_ptr curgdt;
18123
18124 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
18125 }
18126
18127 control_page = page_address(image->control_code_page);
18128 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
18129 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
18130
18131 relocate_kernel_ptr = control_page;
18132 page_list[PA_CONTROL_PAGE] = __pa(control_page);
18133 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
18134 index 0327e2b..e43737b 100644
18135 --- a/arch/x86/kernel/microcode_intel.c
18136 +++ b/arch/x86/kernel/microcode_intel.c
18137 @@ -430,13 +430,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device)
18138
18139 static int get_ucode_user(void *to, const void *from, size_t n)
18140 {
18141 - return copy_from_user(to, from, n);
18142 + return copy_from_user(to, (const void __force_user *)from, n);
18143 }
18144
18145 static enum ucode_state
18146 request_microcode_user(int cpu, const void __user *buf, size_t size)
18147 {
18148 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
18149 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
18150 }
18151
18152 static void microcode_fini_cpu(int cpu)
18153 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
18154 index f21fd94..61565cd 100644
18155 --- a/arch/x86/kernel/module.c
18156 +++ b/arch/x86/kernel/module.c
18157 @@ -35,15 +35,60 @@
18158 #define DEBUGP(fmt...)
18159 #endif
18160
18161 -void *module_alloc(unsigned long size)
18162 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
18163 {
18164 - if (PAGE_ALIGN(size) > MODULES_LEN)
18165 + if (size == 0 || PAGE_ALIGN(size) > MODULES_LEN)
18166 return NULL;
18167 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
18168 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
18169 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
18170 -1, __builtin_return_address(0));
18171 }
18172
18173 +void *module_alloc(unsigned long size)
18174 +{
18175 +
18176 +#ifdef CONFIG_PAX_KERNEXEC
18177 + return __module_alloc(size, PAGE_KERNEL);
18178 +#else
18179 + return __module_alloc(size, PAGE_KERNEL_EXEC);
18180 +#endif
18181 +
18182 +}
18183 +
18184 +#ifdef CONFIG_PAX_KERNEXEC
18185 +#ifdef CONFIG_X86_32
18186 +void *module_alloc_exec(unsigned long size)
18187 +{
18188 + struct vm_struct *area;
18189 +
18190 + if (size == 0)
18191 + return NULL;
18192 +
18193 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
18194 + return area ? area->addr : NULL;
18195 +}
18196 +EXPORT_SYMBOL(module_alloc_exec);
18197 +
18198 +void module_free_exec(struct module *mod, void *module_region)
18199 +{
18200 + vunmap(module_region);
18201 +}
18202 +EXPORT_SYMBOL(module_free_exec);
18203 +#else
18204 +void module_free_exec(struct module *mod, void *module_region)
18205 +{
18206 + module_free(mod, module_region);
18207 +}
18208 +EXPORT_SYMBOL(module_free_exec);
18209 +
18210 +void *module_alloc_exec(unsigned long size)
18211 +{
18212 + return __module_alloc(size, PAGE_KERNEL_RX);
18213 +}
18214 +EXPORT_SYMBOL(module_alloc_exec);
18215 +#endif
18216 +#endif
18217 +
18218 #ifdef CONFIG_X86_32
18219 int apply_relocate(Elf32_Shdr *sechdrs,
18220 const char *strtab,
18221 @@ -54,14 +99,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18222 unsigned int i;
18223 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
18224 Elf32_Sym *sym;
18225 - uint32_t *location;
18226 + uint32_t *plocation, location;
18227
18228 DEBUGP("Applying relocate section %u to %u\n", relsec,
18229 sechdrs[relsec].sh_info);
18230 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
18231 /* This is where to make the change */
18232 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
18233 - + rel[i].r_offset;
18234 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
18235 + location = (uint32_t)plocation;
18236 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
18237 + plocation = ktla_ktva((void *)plocation);
18238 /* This is the symbol it is referring to. Note that all
18239 undefined symbols have been resolved. */
18240 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
18241 @@ -70,11 +117,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
18242 switch (ELF32_R_TYPE(rel[i].r_info)) {
18243 case R_386_32:
18244 /* We add the value into the location given */
18245 - *location += sym->st_value;
18246 + pax_open_kernel();
18247 + *plocation += sym->st_value;
18248 + pax_close_kernel();
18249 break;
18250 case R_386_PC32:
18251 /* Add the value, subtract its postition */
18252 - *location += sym->st_value - (uint32_t)location;
18253 + pax_open_kernel();
18254 + *plocation += sym->st_value - location;
18255 + pax_close_kernel();
18256 break;
18257 default:
18258 printk(KERN_ERR "module %s: Unknown relocation: %u\n",
18259 @@ -119,21 +170,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
18260 case R_X86_64_NONE:
18261 break;
18262 case R_X86_64_64:
18263 + pax_open_kernel();
18264 *(u64 *)loc = val;
18265 + pax_close_kernel();
18266 break;
18267 case R_X86_64_32:
18268 + pax_open_kernel();
18269 *(u32 *)loc = val;
18270 + pax_close_kernel();
18271 if (val != *(u32 *)loc)
18272 goto overflow;
18273 break;
18274 case R_X86_64_32S:
18275 + pax_open_kernel();
18276 *(s32 *)loc = val;
18277 + pax_close_kernel();
18278 if ((s64)val != *(s32 *)loc)
18279 goto overflow;
18280 break;
18281 case R_X86_64_PC32:
18282 val -= (u64)loc;
18283 + pax_open_kernel();
18284 *(u32 *)loc = val;
18285 + pax_close_kernel();
18286 +
18287 #if 0
18288 if ((s64)val != *(s32 *)loc)
18289 goto overflow;
18290 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
18291 index a0b2f84..875ab81 100644
18292 --- a/arch/x86/kernel/nmi.c
18293 +++ b/arch/x86/kernel/nmi.c
18294 @@ -460,6 +460,17 @@ static inline void nmi_nesting_postprocess(void)
18295 dotraplinkage notrace __kprobes void
18296 do_nmi(struct pt_regs *regs, long error_code)
18297 {
18298 +
18299 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18300 + if (!user_mode(regs)) {
18301 + unsigned long cs = regs->cs & 0xFFFF;
18302 + unsigned long ip = ktva_ktla(regs->ip);
18303 +
18304 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
18305 + regs->ip = ip;
18306 + }
18307 +#endif
18308 +
18309 nmi_nesting_preprocess(regs);
18310
18311 nmi_enter();
18312 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
18313 index 676b8c7..870ba04 100644
18314 --- a/arch/x86/kernel/paravirt-spinlocks.c
18315 +++ b/arch/x86/kernel/paravirt-spinlocks.c
18316 @@ -13,7 +13,7 @@ default_spin_lock_flags(arch_spinlock_t *lock, unsigned long flags)
18317 arch_spin_lock(lock);
18318 }
18319
18320 -struct pv_lock_ops pv_lock_ops = {
18321 +struct pv_lock_ops pv_lock_ops __read_only = {
18322 #ifdef CONFIG_SMP
18323 .spin_is_locked = __ticket_spin_is_locked,
18324 .spin_is_contended = __ticket_spin_is_contended,
18325 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
18326 index 9ce8859..b49bf51 100644
18327 --- a/arch/x86/kernel/paravirt.c
18328 +++ b/arch/x86/kernel/paravirt.c
18329 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
18330 {
18331 return x;
18332 }
18333 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18334 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
18335 +#endif
18336
18337 void __init default_banner(void)
18338 {
18339 @@ -147,15 +150,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
18340 if (opfunc == NULL)
18341 /* If there's no function, patch it with a ud2a (BUG) */
18342 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
18343 - else if (opfunc == _paravirt_nop)
18344 + else if (opfunc == (void *)_paravirt_nop)
18345 /* If the operation is a nop, then nop the callsite */
18346 ret = paravirt_patch_nop();
18347
18348 /* identity functions just return their single argument */
18349 - else if (opfunc == _paravirt_ident_32)
18350 + else if (opfunc == (void *)_paravirt_ident_32)
18351 ret = paravirt_patch_ident_32(insnbuf, len);
18352 - else if (opfunc == _paravirt_ident_64)
18353 + else if (opfunc == (void *)_paravirt_ident_64)
18354 ret = paravirt_patch_ident_64(insnbuf, len);
18355 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
18356 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
18357 + ret = paravirt_patch_ident_64(insnbuf, len);
18358 +#endif
18359
18360 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
18361 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
18362 @@ -180,7 +187,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
18363 if (insn_len > len || start == NULL)
18364 insn_len = len;
18365 else
18366 - memcpy(insnbuf, start, insn_len);
18367 + memcpy(insnbuf, ktla_ktva(start), insn_len);
18368
18369 return insn_len;
18370 }
18371 @@ -304,7 +311,7 @@ void arch_flush_lazy_mmu_mode(void)
18372 preempt_enable();
18373 }
18374
18375 -struct pv_info pv_info = {
18376 +struct pv_info pv_info __read_only = {
18377 .name = "bare hardware",
18378 .paravirt_enabled = 0,
18379 .kernel_rpl = 0,
18380 @@ -315,16 +322,16 @@ struct pv_info pv_info = {
18381 #endif
18382 };
18383
18384 -struct pv_init_ops pv_init_ops = {
18385 +struct pv_init_ops pv_init_ops __read_only = {
18386 .patch = native_patch,
18387 };
18388
18389 -struct pv_time_ops pv_time_ops = {
18390 +struct pv_time_ops pv_time_ops __read_only = {
18391 .sched_clock = native_sched_clock,
18392 .steal_clock = native_steal_clock,
18393 };
18394
18395 -struct pv_irq_ops pv_irq_ops = {
18396 +struct pv_irq_ops pv_irq_ops __read_only = {
18397 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
18398 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
18399 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
18400 @@ -336,7 +343,7 @@ struct pv_irq_ops pv_irq_ops = {
18401 #endif
18402 };
18403
18404 -struct pv_cpu_ops pv_cpu_ops = {
18405 +struct pv_cpu_ops pv_cpu_ops __read_only = {
18406 .cpuid = native_cpuid,
18407 .get_debugreg = native_get_debugreg,
18408 .set_debugreg = native_set_debugreg,
18409 @@ -397,21 +404,26 @@ struct pv_cpu_ops pv_cpu_ops = {
18410 .end_context_switch = paravirt_nop,
18411 };
18412
18413 -struct pv_apic_ops pv_apic_ops = {
18414 +struct pv_apic_ops pv_apic_ops __read_only = {
18415 #ifdef CONFIG_X86_LOCAL_APIC
18416 .startup_ipi_hook = paravirt_nop,
18417 #endif
18418 };
18419
18420 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
18421 +#ifdef CONFIG_X86_32
18422 +#ifdef CONFIG_X86_PAE
18423 +/* 64-bit pagetable entries */
18424 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
18425 +#else
18426 /* 32-bit pagetable entries */
18427 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
18428 +#endif
18429 #else
18430 /* 64-bit pagetable entries */
18431 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
18432 #endif
18433
18434 -struct pv_mmu_ops pv_mmu_ops = {
18435 +struct pv_mmu_ops pv_mmu_ops __read_only = {
18436
18437 .read_cr2 = native_read_cr2,
18438 .write_cr2 = native_write_cr2,
18439 @@ -461,6 +473,7 @@ struct pv_mmu_ops pv_mmu_ops = {
18440 .make_pud = PTE_IDENT,
18441
18442 .set_pgd = native_set_pgd,
18443 + .set_pgd_batched = native_set_pgd_batched,
18444 #endif
18445 #endif /* PAGETABLE_LEVELS >= 3 */
18446
18447 @@ -480,6 +493,12 @@ struct pv_mmu_ops pv_mmu_ops = {
18448 },
18449
18450 .set_fixmap = native_set_fixmap,
18451 +
18452 +#ifdef CONFIG_PAX_KERNEXEC
18453 + .pax_open_kernel = native_pax_open_kernel,
18454 + .pax_close_kernel = native_pax_close_kernel,
18455 +#endif
18456 +
18457 };
18458
18459 EXPORT_SYMBOL_GPL(pv_time_ops);
18460 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
18461 index 35ccf75..7a15747 100644
18462 --- a/arch/x86/kernel/pci-iommu_table.c
18463 +++ b/arch/x86/kernel/pci-iommu_table.c
18464 @@ -2,7 +2,7 @@
18465 #include <asm/iommu_table.h>
18466 #include <linux/string.h>
18467 #include <linux/kallsyms.h>
18468 -
18469 +#include <linux/sched.h>
18470
18471 #define DEBUG 1
18472
18473 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
18474 index 735279e..5008677 100644
18475 --- a/arch/x86/kernel/process.c
18476 +++ b/arch/x86/kernel/process.c
18477 @@ -34,7 +34,8 @@
18478 * section. Since TSS's are completely CPU-local, we want them
18479 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
18480 */
18481 -DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
18482 +struct tss_struct init_tss[NR_CPUS] ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
18483 +EXPORT_SYMBOL(init_tss);
18484
18485 #ifdef CONFIG_X86_64
18486 static DEFINE_PER_CPU(unsigned char, is_idle);
18487 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
18488 task_xstate_cachep =
18489 kmem_cache_create("task_xstate", xstate_size,
18490 __alignof__(union thread_xstate),
18491 - SLAB_PANIC | SLAB_NOTRACK, NULL);
18492 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
18493 }
18494
18495 static inline void drop_fpu(struct task_struct *tsk)
18496 @@ -115,7 +116,7 @@ void exit_thread(void)
18497 unsigned long *bp = t->io_bitmap_ptr;
18498
18499 if (bp) {
18500 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
18501 + struct tss_struct *tss = init_tss + get_cpu();
18502
18503 t->io_bitmap_ptr = NULL;
18504 clear_thread_flag(TIF_IO_BITMAP);
18505 @@ -147,7 +148,7 @@ void show_regs_common(void)
18506
18507 printk(KERN_CONT "\n");
18508 printk(KERN_DEFAULT "Pid: %d, comm: %.20s %s %s %.*s",
18509 - current->pid, current->comm, print_tainted(),
18510 + task_pid_nr(current), current->comm, print_tainted(),
18511 init_utsname()->release,
18512 (int)strcspn(init_utsname()->version, " "),
18513 init_utsname()->version);
18514 @@ -161,6 +162,9 @@ void flush_thread(void)
18515 {
18516 struct task_struct *tsk = current;
18517
18518 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18519 + loadsegment(gs, 0);
18520 +#endif
18521 flush_ptrace_hw_breakpoint(tsk);
18522 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
18523 drop_fpu(tsk);
18524 @@ -318,10 +322,10 @@ int kernel_thread(int (*fn)(void *), void *arg, unsigned long flags)
18525 regs.di = (unsigned long) arg;
18526
18527 #ifdef CONFIG_X86_32
18528 - regs.ds = __USER_DS;
18529 - regs.es = __USER_DS;
18530 + regs.ds = __KERNEL_DS;
18531 + regs.es = __KERNEL_DS;
18532 regs.fs = __KERNEL_PERCPU;
18533 - regs.gs = __KERNEL_STACK_CANARY;
18534 + savesegment(gs, regs.gs);
18535 #else
18536 regs.ss = __KERNEL_DS;
18537 #endif
18538 @@ -407,7 +411,7 @@ static void __exit_idle(void)
18539 void exit_idle(void)
18540 {
18541 /* idle loop has pid 0 */
18542 - if (current->pid)
18543 + if (task_pid_nr(current))
18544 return;
18545 __exit_idle();
18546 }
18547 @@ -516,7 +520,7 @@ bool set_pm_idle_to_default(void)
18548
18549 return ret;
18550 }
18551 -void stop_this_cpu(void *dummy)
18552 +__noreturn void stop_this_cpu(void *dummy)
18553 {
18554 local_irq_disable();
18555 /*
18556 @@ -746,16 +750,37 @@ static int __init idle_setup(char *str)
18557 }
18558 early_param("idle", idle_setup);
18559
18560 -unsigned long arch_align_stack(unsigned long sp)
18561 +#ifdef CONFIG_PAX_RANDKSTACK
18562 +void pax_randomize_kstack(struct pt_regs *regs)
18563 {
18564 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
18565 - sp -= get_random_int() % 8192;
18566 - return sp & ~0xf;
18567 -}
18568 + struct thread_struct *thread = &current->thread;
18569 + unsigned long time;
18570
18571 -unsigned long arch_randomize_brk(struct mm_struct *mm)
18572 -{
18573 - unsigned long range_end = mm->brk + 0x02000000;
18574 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
18575 -}
18576 + if (!randomize_va_space)
18577 + return;
18578 +
18579 + if (v8086_mode(regs))
18580 + return;
18581
18582 + rdtscl(time);
18583 +
18584 + /* P4 seems to return a 0 LSB, ignore it */
18585 +#ifdef CONFIG_MPENTIUM4
18586 + time &= 0x3EUL;
18587 + time <<= 2;
18588 +#elif defined(CONFIG_X86_64)
18589 + time &= 0xFUL;
18590 + time <<= 4;
18591 +#else
18592 + time &= 0x1FUL;
18593 + time <<= 3;
18594 +#endif
18595 +
18596 + thread->sp0 ^= time;
18597 + load_sp0(init_tss + smp_processor_id(), thread);
18598 +
18599 +#ifdef CONFIG_X86_64
18600 + this_cpu_write(kernel_stack, thread->sp0);
18601 +#endif
18602 +}
18603 +#endif
18604 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
18605 index 516fa18..80bd9e6 100644
18606 --- a/arch/x86/kernel/process_32.c
18607 +++ b/arch/x86/kernel/process_32.c
18608 @@ -64,6 +64,7 @@ asmlinkage void ret_from_fork(void) __asm__("ret_from_fork");
18609 unsigned long thread_saved_pc(struct task_struct *tsk)
18610 {
18611 return ((unsigned long *)tsk->thread.sp)[3];
18612 +//XXX return tsk->thread.eip;
18613 }
18614
18615 void __show_regs(struct pt_regs *regs, int all)
18616 @@ -73,15 +74,14 @@ void __show_regs(struct pt_regs *regs, int all)
18617 unsigned long sp;
18618 unsigned short ss, gs;
18619
18620 - if (user_mode_vm(regs)) {
18621 + if (user_mode(regs)) {
18622 sp = regs->sp;
18623 ss = regs->ss & 0xffff;
18624 - gs = get_user_gs(regs);
18625 } else {
18626 sp = kernel_stack_pointer(regs);
18627 savesegment(ss, ss);
18628 - savesegment(gs, gs);
18629 }
18630 + gs = get_user_gs(regs);
18631
18632 show_regs_common();
18633
18634 @@ -134,13 +134,14 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18635 struct task_struct *tsk;
18636 int err;
18637
18638 - childregs = task_pt_regs(p);
18639 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
18640 *childregs = *regs;
18641 childregs->ax = 0;
18642 childregs->sp = sp;
18643
18644 p->thread.sp = (unsigned long) childregs;
18645 p->thread.sp0 = (unsigned long) (childregs+1);
18646 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18647
18648 p->thread.ip = (unsigned long) ret_from_fork;
18649
18650 @@ -231,7 +232,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18651 struct thread_struct *prev = &prev_p->thread,
18652 *next = &next_p->thread;
18653 int cpu = smp_processor_id();
18654 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18655 + struct tss_struct *tss = init_tss + cpu;
18656 fpu_switch_t fpu;
18657
18658 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
18659 @@ -255,6 +256,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18660 */
18661 lazy_save_gs(prev->gs);
18662
18663 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18664 + __set_fs(task_thread_info(next_p)->addr_limit);
18665 +#endif
18666 +
18667 /*
18668 * Load the per-thread Thread-Local Storage descriptor.
18669 */
18670 @@ -285,6 +290,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18671 */
18672 arch_end_context_switch(next_p);
18673
18674 + this_cpu_write(current_task, next_p);
18675 + this_cpu_write(current_tinfo, &next_p->tinfo);
18676 +
18677 /*
18678 * Restore %gs if needed (which is common)
18679 */
18680 @@ -293,8 +301,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18681
18682 switch_fpu_finish(next_p, fpu);
18683
18684 - this_cpu_write(current_task, next_p);
18685 -
18686 return prev_p;
18687 }
18688
18689 @@ -324,4 +330,3 @@ unsigned long get_wchan(struct task_struct *p)
18690 } while (count++ < 16);
18691 return 0;
18692 }
18693 -
18694 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
18695 index 61cdf7f..797f06a 100644
18696 --- a/arch/x86/kernel/process_64.c
18697 +++ b/arch/x86/kernel/process_64.c
18698 @@ -153,8 +153,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18699 struct pt_regs *childregs;
18700 struct task_struct *me = current;
18701
18702 - childregs = ((struct pt_regs *)
18703 - (THREAD_SIZE + task_stack_page(p))) - 1;
18704 + childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 16;
18705 *childregs = *regs;
18706
18707 childregs->ax = 0;
18708 @@ -166,6 +165,7 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
18709 p->thread.sp = (unsigned long) childregs;
18710 p->thread.sp0 = (unsigned long) (childregs+1);
18711 p->thread.usersp = me->thread.usersp;
18712 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
18713
18714 set_tsk_thread_flag(p, TIF_FORK);
18715
18716 @@ -271,7 +271,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18717 struct thread_struct *prev = &prev_p->thread;
18718 struct thread_struct *next = &next_p->thread;
18719 int cpu = smp_processor_id();
18720 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
18721 + struct tss_struct *tss = init_tss + cpu;
18722 unsigned fsindex, gsindex;
18723 fpu_switch_t fpu;
18724
18725 @@ -353,10 +353,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
18726 prev->usersp = this_cpu_read(old_rsp);
18727 this_cpu_write(old_rsp, next->usersp);
18728 this_cpu_write(current_task, next_p);
18729 + this_cpu_write(current_tinfo, &next_p->tinfo);
18730
18731 - this_cpu_write(kernel_stack,
18732 - (unsigned long)task_stack_page(next_p) +
18733 - THREAD_SIZE - KERNEL_STACK_OFFSET);
18734 + this_cpu_write(kernel_stack, next->sp0);
18735
18736 /*
18737 * Now maybe reload the debug registers and handle I/O bitmaps
18738 @@ -425,12 +424,11 @@ unsigned long get_wchan(struct task_struct *p)
18739 if (!p || p == current || p->state == TASK_RUNNING)
18740 return 0;
18741 stack = (unsigned long)task_stack_page(p);
18742 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
18743 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
18744 return 0;
18745 fp = *(u64 *)(p->thread.sp);
18746 do {
18747 - if (fp < (unsigned long)stack ||
18748 - fp >= (unsigned long)stack+THREAD_SIZE)
18749 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
18750 return 0;
18751 ip = *(u64 *)(fp+8);
18752 if (!in_sched_functions(ip))
18753 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
18754 index c4c6a5c..905f440 100644
18755 --- a/arch/x86/kernel/ptrace.c
18756 +++ b/arch/x86/kernel/ptrace.c
18757 @@ -824,7 +824,7 @@ long arch_ptrace(struct task_struct *child, long request,
18758 unsigned long addr, unsigned long data)
18759 {
18760 int ret;
18761 - unsigned long __user *datap = (unsigned long __user *)data;
18762 + unsigned long __user *datap = (__force unsigned long __user *)data;
18763
18764 switch (request) {
18765 /* read the word at location addr in the USER area. */
18766 @@ -909,14 +909,14 @@ long arch_ptrace(struct task_struct *child, long request,
18767 if ((int) addr < 0)
18768 return -EIO;
18769 ret = do_get_thread_area(child, addr,
18770 - (struct user_desc __user *)data);
18771 + (__force struct user_desc __user *) data);
18772 break;
18773
18774 case PTRACE_SET_THREAD_AREA:
18775 if ((int) addr < 0)
18776 return -EIO;
18777 ret = do_set_thread_area(child, addr,
18778 - (struct user_desc __user *)data, 0);
18779 + (__force struct user_desc __user *) data, 0);
18780 break;
18781 #endif
18782
18783 @@ -1426,7 +1426,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
18784 memset(info, 0, sizeof(*info));
18785 info->si_signo = SIGTRAP;
18786 info->si_code = si_code;
18787 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
18788 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
18789 }
18790
18791 void user_single_step_siginfo(struct task_struct *tsk,
18792 @@ -1455,6 +1455,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
18793 # define IS_IA32 0
18794 #endif
18795
18796 +#ifdef CONFIG_GRKERNSEC_SETXID
18797 +extern void gr_delayed_cred_worker(void);
18798 +#endif
18799 +
18800 /*
18801 * We must return the syscall number to actually look up in the table.
18802 * This can be -1L to skip running any syscall at all.
18803 @@ -1463,6 +1467,11 @@ long syscall_trace_enter(struct pt_regs *regs)
18804 {
18805 long ret = 0;
18806
18807 +#ifdef CONFIG_GRKERNSEC_SETXID
18808 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18809 + gr_delayed_cred_worker();
18810 +#endif
18811 +
18812 /*
18813 * If we stepped into a sysenter/syscall insn, it trapped in
18814 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
18815 @@ -1511,6 +1520,11 @@ void syscall_trace_leave(struct pt_regs *regs)
18816 {
18817 bool step;
18818
18819 +#ifdef CONFIG_GRKERNSEC_SETXID
18820 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
18821 + gr_delayed_cred_worker();
18822 +#endif
18823 +
18824 audit_syscall_exit(regs);
18825
18826 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
18827 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
18828 index 42eb330..139955c 100644
18829 --- a/arch/x86/kernel/pvclock.c
18830 +++ b/arch/x86/kernel/pvclock.c
18831 @@ -81,11 +81,11 @@ unsigned long pvclock_tsc_khz(struct pvclock_vcpu_time_info *src)
18832 return pv_tsc_khz;
18833 }
18834
18835 -static atomic64_t last_value = ATOMIC64_INIT(0);
18836 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
18837
18838 void pvclock_resume(void)
18839 {
18840 - atomic64_set(&last_value, 0);
18841 + atomic64_set_unchecked(&last_value, 0);
18842 }
18843
18844 cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18845 @@ -121,11 +121,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
18846 * updating at the same time, and one of them could be slightly behind,
18847 * making the assumption that last_value always go forward fail to hold.
18848 */
18849 - last = atomic64_read(&last_value);
18850 + last = atomic64_read_unchecked(&last_value);
18851 do {
18852 if (ret < last)
18853 return last;
18854 - last = atomic64_cmpxchg(&last_value, last, ret);
18855 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
18856 } while (unlikely(last != ret));
18857
18858 return ret;
18859 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
18860 index 5de92f1..776788d 100644
18861 --- a/arch/x86/kernel/reboot.c
18862 +++ b/arch/x86/kernel/reboot.c
18863 @@ -36,7 +36,7 @@ void (*pm_power_off)(void);
18864 EXPORT_SYMBOL(pm_power_off);
18865
18866 static const struct desc_ptr no_idt = {};
18867 -static int reboot_mode;
18868 +static unsigned short reboot_mode;
18869 enum reboot_type reboot_type = BOOT_ACPI;
18870 int reboot_force;
18871
18872 @@ -157,11 +157,15 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
18873 return 0;
18874 }
18875
18876 -void machine_real_restart(unsigned int type)
18877 +__noreturn void machine_real_restart(unsigned int type)
18878 {
18879 void (*restart_lowmem)(unsigned int) = (void (*)(unsigned int))
18880 real_mode_header->machine_real_restart_asm;
18881
18882 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18883 + struct desc_struct *gdt;
18884 +#endif
18885 +
18886 local_irq_disable();
18887
18888 /*
18889 @@ -189,10 +193,38 @@ void machine_real_restart(unsigned int type)
18890 * boot)". This seems like a fairly standard thing that gets set by
18891 * REBOOT.COM programs, and the previous reset routine did this
18892 * too. */
18893 - *((unsigned short *)0x472) = reboot_mode;
18894 + *(unsigned short *)(__va(0x472)) = reboot_mode;
18895
18896 /* Jump to the identity-mapped low memory code */
18897 +
18898 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
18899 + gdt = get_cpu_gdt_table(smp_processor_id());
18900 + pax_open_kernel();
18901 +#ifdef CONFIG_PAX_MEMORY_UDEREF
18902 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
18903 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
18904 + loadsegment(ds, __KERNEL_DS);
18905 + loadsegment(es, __KERNEL_DS);
18906 + loadsegment(ss, __KERNEL_DS);
18907 +#endif
18908 +#ifdef CONFIG_PAX_KERNEXEC
18909 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
18910 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
18911 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
18912 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
18913 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
18914 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
18915 +#endif
18916 + pax_close_kernel();
18917 +#endif
18918 +
18919 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
18920 + asm volatile("push %0; push %1; lret\n" : : "i" (__KERNEL_CS), "rm" (restart_lowmem), "a" (type));
18921 + unreachable();
18922 +#else
18923 restart_lowmem(type);
18924 +#endif
18925 +
18926 }
18927 #ifdef CONFIG_APM_MODULE
18928 EXPORT_SYMBOL(machine_real_restart);
18929 @@ -543,7 +575,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
18930 * try to force a triple fault and then cycle between hitting the keyboard
18931 * controller and doing that
18932 */
18933 -static void native_machine_emergency_restart(void)
18934 +static void __noreturn native_machine_emergency_restart(void)
18935 {
18936 int i;
18937 int attempt = 0;
18938 @@ -670,13 +702,13 @@ void native_machine_shutdown(void)
18939 #endif
18940 }
18941
18942 -static void __machine_emergency_restart(int emergency)
18943 +static __noreturn void __machine_emergency_restart(int emergency)
18944 {
18945 reboot_emergency = emergency;
18946 machine_ops.emergency_restart();
18947 }
18948
18949 -static void native_machine_restart(char *__unused)
18950 +static void __noreturn native_machine_restart(char *__unused)
18951 {
18952 printk("machine restart\n");
18953
18954 @@ -685,7 +717,7 @@ static void native_machine_restart(char *__unused)
18955 __machine_emergency_restart(0);
18956 }
18957
18958 -static void native_machine_halt(void)
18959 +static void __noreturn native_machine_halt(void)
18960 {
18961 /* Stop other cpus and apics */
18962 machine_shutdown();
18963 @@ -695,7 +727,7 @@ static void native_machine_halt(void)
18964 stop_this_cpu(NULL);
18965 }
18966
18967 -static void native_machine_power_off(void)
18968 +static void __noreturn native_machine_power_off(void)
18969 {
18970 if (pm_power_off) {
18971 if (!reboot_force)
18972 @@ -704,6 +736,7 @@ static void native_machine_power_off(void)
18973 }
18974 /* A fallback in case there is no PM info available */
18975 tboot_shutdown(TB_SHUTDOWN_HALT);
18976 + unreachable();
18977 }
18978
18979 struct machine_ops machine_ops = {
18980 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
18981 index 7a6f3b3..bed145d7 100644
18982 --- a/arch/x86/kernel/relocate_kernel_64.S
18983 +++ b/arch/x86/kernel/relocate_kernel_64.S
18984 @@ -11,6 +11,7 @@
18985 #include <asm/kexec.h>
18986 #include <asm/processor-flags.h>
18987 #include <asm/pgtable_types.h>
18988 +#include <asm/alternative-asm.h>
18989
18990 /*
18991 * Must be relocatable PIC code callable as a C function
18992 @@ -160,13 +161,14 @@ identity_mapped:
18993 xorq %rbp, %rbp
18994 xorq %r8, %r8
18995 xorq %r9, %r9
18996 - xorq %r10, %r9
18997 + xorq %r10, %r10
18998 xorq %r11, %r11
18999 xorq %r12, %r12
19000 xorq %r13, %r13
19001 xorq %r14, %r14
19002 xorq %r15, %r15
19003
19004 + pax_force_retaddr 0, 1
19005 ret
19006
19007 1:
19008 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
19009 index 16be6dc..4686132 100644
19010 --- a/arch/x86/kernel/setup.c
19011 +++ b/arch/x86/kernel/setup.c
19012 @@ -440,7 +440,7 @@ static void __init parse_setup_data(void)
19013
19014 switch (data->type) {
19015 case SETUP_E820_EXT:
19016 - parse_e820_ext(data);
19017 + parse_e820_ext((struct setup_data __force_kernel *)data);
19018 break;
19019 case SETUP_DTB:
19020 add_dtb(pa_data);
19021 @@ -632,7 +632,7 @@ static void __init trim_bios_range(void)
19022 * area (640->1Mb) as ram even though it is not.
19023 * take them out.
19024 */
19025 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
19026 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
19027 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
19028 }
19029
19030 @@ -755,14 +755,14 @@ void __init setup_arch(char **cmdline_p)
19031
19032 if (!boot_params.hdr.root_flags)
19033 root_mountflags &= ~MS_RDONLY;
19034 - init_mm.start_code = (unsigned long) _text;
19035 - init_mm.end_code = (unsigned long) _etext;
19036 + init_mm.start_code = ktla_ktva((unsigned long) _text);
19037 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
19038 init_mm.end_data = (unsigned long) _edata;
19039 init_mm.brk = _brk_end;
19040
19041 - code_resource.start = virt_to_phys(_text);
19042 - code_resource.end = virt_to_phys(_etext)-1;
19043 - data_resource.start = virt_to_phys(_etext);
19044 + code_resource.start = virt_to_phys(ktla_ktva(_text));
19045 + code_resource.end = virt_to_phys(ktla_ktva(_etext))-1;
19046 + data_resource.start = virt_to_phys(_sdata);
19047 data_resource.end = virt_to_phys(_edata)-1;
19048 bss_resource.start = virt_to_phys(&__bss_start);
19049 bss_resource.end = virt_to_phys(&__bss_stop)-1;
19050 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
19051 index 5a98aa2..2f9288d 100644
19052 --- a/arch/x86/kernel/setup_percpu.c
19053 +++ b/arch/x86/kernel/setup_percpu.c
19054 @@ -21,19 +21,17 @@
19055 #include <asm/cpu.h>
19056 #include <asm/stackprotector.h>
19057
19058 -DEFINE_PER_CPU(int, cpu_number);
19059 +#ifdef CONFIG_SMP
19060 +DEFINE_PER_CPU(unsigned int, cpu_number);
19061 EXPORT_PER_CPU_SYMBOL(cpu_number);
19062 +#endif
19063
19064 -#ifdef CONFIG_X86_64
19065 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
19066 -#else
19067 -#define BOOT_PERCPU_OFFSET 0
19068 -#endif
19069
19070 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
19071 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
19072
19073 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
19074 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
19075 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
19076 };
19077 EXPORT_SYMBOL(__per_cpu_offset);
19078 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
19079 {
19080 #ifdef CONFIG_X86_32
19081 struct desc_struct gdt;
19082 + unsigned long base = per_cpu_offset(cpu);
19083
19084 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
19085 - 0x2 | DESCTYPE_S, 0x8);
19086 - gdt.s = 1;
19087 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
19088 + 0x83 | DESCTYPE_S, 0xC);
19089 write_gdt_entry(get_cpu_gdt_table(cpu),
19090 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
19091 #endif
19092 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
19093 /* alrighty, percpu areas up and running */
19094 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
19095 for_each_possible_cpu(cpu) {
19096 +#ifdef CONFIG_CC_STACKPROTECTOR
19097 +#ifdef CONFIG_X86_32
19098 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
19099 +#endif
19100 +#endif
19101 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
19102 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
19103 per_cpu(cpu_number, cpu) = cpu;
19104 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
19105 */
19106 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
19107 #endif
19108 +#ifdef CONFIG_CC_STACKPROTECTOR
19109 +#ifdef CONFIG_X86_32
19110 + if (!cpu)
19111 + per_cpu(stack_canary.canary, cpu) = canary;
19112 +#endif
19113 +#endif
19114 /*
19115 * Up to this point, the boot CPU has been using .init.data
19116 * area. Reload any changed state for the boot CPU.
19117 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
19118 index 21af737..fb45e22 100644
19119 --- a/arch/x86/kernel/signal.c
19120 +++ b/arch/x86/kernel/signal.c
19121 @@ -191,7 +191,7 @@ static unsigned long align_sigframe(unsigned long sp)
19122 * Align the stack pointer according to the i386 ABI,
19123 * i.e. so that on function entry ((sp + 4) & 15) == 0.
19124 */
19125 - sp = ((sp + 4) & -16ul) - 4;
19126 + sp = ((sp - 12) & -16ul) - 4;
19127 #else /* !CONFIG_X86_32 */
19128 sp = round_down(sp, 16) - 8;
19129 #endif
19130 @@ -242,11 +242,11 @@ get_sigframe(struct k_sigaction *ka, struct pt_regs *regs, size_t frame_size,
19131 * Return an always-bogus address instead so we will die with SIGSEGV.
19132 */
19133 if (onsigstack && !likely(on_sig_stack(sp)))
19134 - return (void __user *)-1L;
19135 + return (__force void __user *)-1L;
19136
19137 /* save i387 state */
19138 if (used_math() && save_i387_xstate(*fpstate) < 0)
19139 - return (void __user *)-1L;
19140 + return (__force void __user *)-1L;
19141
19142 return (void __user *)sp;
19143 }
19144 @@ -301,9 +301,9 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19145 }
19146
19147 if (current->mm->context.vdso)
19148 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19149 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
19150 else
19151 - restorer = &frame->retcode;
19152 + restorer = (void __user *)&frame->retcode;
19153 if (ka->sa.sa_flags & SA_RESTORER)
19154 restorer = ka->sa.sa_restorer;
19155
19156 @@ -317,7 +317,7 @@ __setup_frame(int sig, struct k_sigaction *ka, sigset_t *set,
19157 * reasons and because gdb uses it as a signature to notice
19158 * signal handler stack frames.
19159 */
19160 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
19161 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
19162
19163 if (err)
19164 return -EFAULT;
19165 @@ -371,7 +371,10 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19166 err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
19167
19168 /* Set up to return from userspace. */
19169 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19170 + if (current->mm->context.vdso)
19171 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
19172 + else
19173 + restorer = (void __user *)&frame->retcode;
19174 if (ka->sa.sa_flags & SA_RESTORER)
19175 restorer = ka->sa.sa_restorer;
19176 put_user_ex(restorer, &frame->pretcode);
19177 @@ -383,7 +386,7 @@ static int __setup_rt_frame(int sig, struct k_sigaction *ka, siginfo_t *info,
19178 * reasons and because gdb uses it as a signature to notice
19179 * signal handler stack frames.
19180 */
19181 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
19182 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
19183 } put_user_catch(err);
19184
19185 if (err)
19186 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
19187 index 7bd8a08..2659b5b 100644
19188 --- a/arch/x86/kernel/smpboot.c
19189 +++ b/arch/x86/kernel/smpboot.c
19190 @@ -679,6 +679,7 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19191 idle->thread.sp = (unsigned long) (((struct pt_regs *)
19192 (THREAD_SIZE + task_stack_page(idle))) - 1);
19193 per_cpu(current_task, cpu) = idle;
19194 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
19195
19196 #ifdef CONFIG_X86_32
19197 /* Stack for startup_32 can be just as for start_secondary onwards */
19198 @@ -686,11 +687,13 @@ static int __cpuinit do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
19199 #else
19200 clear_tsk_thread_flag(idle, TIF_FORK);
19201 initial_gs = per_cpu_offset(cpu);
19202 - per_cpu(kernel_stack, cpu) =
19203 - (unsigned long)task_stack_page(idle) -
19204 - KERNEL_STACK_OFFSET + THREAD_SIZE;
19205 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
19206 #endif
19207 +
19208 + pax_open_kernel();
19209 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
19210 + pax_close_kernel();
19211 +
19212 initial_code = (unsigned long)start_secondary;
19213 stack_start = idle->thread.sp;
19214
19215 @@ -826,6 +829,12 @@ int __cpuinit native_cpu_up(unsigned int cpu, struct task_struct *tidle)
19216
19217 per_cpu(cpu_state, cpu) = CPU_UP_PREPARE;
19218
19219 +#ifdef CONFIG_PAX_PER_CPU_PGD
19220 + clone_pgd_range(get_cpu_pgd(cpu) + KERNEL_PGD_BOUNDARY,
19221 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
19222 + KERNEL_PGD_PTRS);
19223 +#endif
19224 +
19225 err = do_boot_cpu(apicid, cpu, tidle);
19226 if (err) {
19227 pr_debug("do_boot_cpu failed %d\n", err);
19228 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
19229 index c346d11..d43b163 100644
19230 --- a/arch/x86/kernel/step.c
19231 +++ b/arch/x86/kernel/step.c
19232 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19233 struct desc_struct *desc;
19234 unsigned long base;
19235
19236 - seg &= ~7UL;
19237 + seg >>= 3;
19238
19239 mutex_lock(&child->mm->context.lock);
19240 - if (unlikely((seg >> 3) >= child->mm->context.size))
19241 + if (unlikely(seg >= child->mm->context.size))
19242 addr = -1L; /* bogus selector, access would fault */
19243 else {
19244 desc = child->mm->context.ldt + seg;
19245 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
19246 addr += base;
19247 }
19248 mutex_unlock(&child->mm->context.lock);
19249 - }
19250 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
19251 + addr = ktla_ktva(addr);
19252
19253 return addr;
19254 }
19255 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
19256 unsigned char opcode[15];
19257 unsigned long addr = convert_ip_to_linear(child, regs);
19258
19259 + if (addr == -EINVAL)
19260 + return 0;
19261 +
19262 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
19263 for (i = 0; i < copied; i++) {
19264 switch (opcode[i]) {
19265 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
19266 index 0b0cb5f..db6b9ed 100644
19267 --- a/arch/x86/kernel/sys_i386_32.c
19268 +++ b/arch/x86/kernel/sys_i386_32.c
19269 @@ -24,17 +24,224 @@
19270
19271 #include <asm/syscalls.h>
19272
19273 -/*
19274 - * Do a system call from kernel instead of calling sys_execve so we
19275 - * end up with proper pt_regs.
19276 - */
19277 -int kernel_execve(const char *filename,
19278 - const char *const argv[],
19279 - const char *const envp[])
19280 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
19281 {
19282 - long __res;
19283 - asm volatile ("int $0x80"
19284 - : "=a" (__res)
19285 - : "0" (__NR_execve), "b" (filename), "c" (argv), "d" (envp) : "memory");
19286 - return __res;
19287 + unsigned long pax_task_size = TASK_SIZE;
19288 +
19289 +#ifdef CONFIG_PAX_SEGMEXEC
19290 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
19291 + pax_task_size = SEGMEXEC_TASK_SIZE;
19292 +#endif
19293 +
19294 + if (len > pax_task_size || addr > pax_task_size - len)
19295 + return -EINVAL;
19296 +
19297 + return 0;
19298 +}
19299 +
19300 +unsigned long
19301 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
19302 + unsigned long len, unsigned long pgoff, unsigned long flags)
19303 +{
19304 + struct mm_struct *mm = current->mm;
19305 + struct vm_area_struct *vma;
19306 + unsigned long start_addr, pax_task_size = TASK_SIZE;
19307 +
19308 +#ifdef CONFIG_PAX_SEGMEXEC
19309 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19310 + pax_task_size = SEGMEXEC_TASK_SIZE;
19311 +#endif
19312 +
19313 + pax_task_size -= PAGE_SIZE;
19314 +
19315 + if (len > pax_task_size)
19316 + return -ENOMEM;
19317 +
19318 + if (flags & MAP_FIXED)
19319 + return addr;
19320 +
19321 +#ifdef CONFIG_PAX_RANDMMAP
19322 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19323 +#endif
19324 +
19325 + if (addr) {
19326 + addr = PAGE_ALIGN(addr);
19327 + if (pax_task_size - len >= addr) {
19328 + vma = find_vma(mm, addr);
19329 + if (check_heap_stack_gap(vma, addr, len))
19330 + return addr;
19331 + }
19332 + }
19333 + if (len > mm->cached_hole_size) {
19334 + start_addr = addr = mm->free_area_cache;
19335 + } else {
19336 + start_addr = addr = mm->mmap_base;
19337 + mm->cached_hole_size = 0;
19338 + }
19339 +
19340 +#ifdef CONFIG_PAX_PAGEEXEC
19341 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE) && start_addr >= mm->mmap_base) {
19342 + start_addr = 0x00110000UL;
19343 +
19344 +#ifdef CONFIG_PAX_RANDMMAP
19345 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19346 + start_addr += mm->delta_mmap & 0x03FFF000UL;
19347 +#endif
19348 +
19349 + if (mm->start_brk <= start_addr && start_addr < mm->mmap_base)
19350 + start_addr = addr = mm->mmap_base;
19351 + else
19352 + addr = start_addr;
19353 + }
19354 +#endif
19355 +
19356 +full_search:
19357 + for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
19358 + /* At this point: (!vma || addr < vma->vm_end). */
19359 + if (pax_task_size - len < addr) {
19360 + /*
19361 + * Start a new search - just in case we missed
19362 + * some holes.
19363 + */
19364 + if (start_addr != mm->mmap_base) {
19365 + start_addr = addr = mm->mmap_base;
19366 + mm->cached_hole_size = 0;
19367 + goto full_search;
19368 + }
19369 + return -ENOMEM;
19370 + }
19371 + if (check_heap_stack_gap(vma, addr, len))
19372 + break;
19373 + if (addr + mm->cached_hole_size < vma->vm_start)
19374 + mm->cached_hole_size = vma->vm_start - addr;
19375 + addr = vma->vm_end;
19376 + if (mm->start_brk <= addr && addr < mm->mmap_base) {
19377 + start_addr = addr = mm->mmap_base;
19378 + mm->cached_hole_size = 0;
19379 + goto full_search;
19380 + }
19381 + }
19382 +
19383 + /*
19384 + * Remember the place where we stopped the search:
19385 + */
19386 + mm->free_area_cache = addr + len;
19387 + return addr;
19388 +}
19389 +
19390 +unsigned long
19391 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19392 + const unsigned long len, const unsigned long pgoff,
19393 + const unsigned long flags)
19394 +{
19395 + struct vm_area_struct *vma;
19396 + struct mm_struct *mm = current->mm;
19397 + unsigned long base = mm->mmap_base, addr = addr0, pax_task_size = TASK_SIZE;
19398 +
19399 +#ifdef CONFIG_PAX_SEGMEXEC
19400 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19401 + pax_task_size = SEGMEXEC_TASK_SIZE;
19402 +#endif
19403 +
19404 + pax_task_size -= PAGE_SIZE;
19405 +
19406 + /* requested length too big for entire address space */
19407 + if (len > pax_task_size)
19408 + return -ENOMEM;
19409 +
19410 + if (flags & MAP_FIXED)
19411 + return addr;
19412 +
19413 +#ifdef CONFIG_PAX_PAGEEXEC
19414 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
19415 + goto bottomup;
19416 +#endif
19417 +
19418 +#ifdef CONFIG_PAX_RANDMMAP
19419 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19420 +#endif
19421 +
19422 + /* requesting a specific address */
19423 + if (addr) {
19424 + addr = PAGE_ALIGN(addr);
19425 + if (pax_task_size - len >= addr) {
19426 + vma = find_vma(mm, addr);
19427 + if (check_heap_stack_gap(vma, addr, len))
19428 + return addr;
19429 + }
19430 + }
19431 +
19432 + /* check if free_area_cache is useful for us */
19433 + if (len <= mm->cached_hole_size) {
19434 + mm->cached_hole_size = 0;
19435 + mm->free_area_cache = mm->mmap_base;
19436 + }
19437 +
19438 + /* either no address requested or can't fit in requested address hole */
19439 + addr = mm->free_area_cache;
19440 +
19441 + /* make sure it can fit in the remaining address space */
19442 + if (addr > len) {
19443 + vma = find_vma(mm, addr-len);
19444 + if (check_heap_stack_gap(vma, addr - len, len))
19445 + /* remember the address as a hint for next time */
19446 + return (mm->free_area_cache = addr-len);
19447 + }
19448 +
19449 + if (mm->mmap_base < len)
19450 + goto bottomup;
19451 +
19452 + addr = mm->mmap_base-len;
19453 +
19454 + do {
19455 + /*
19456 + * Lookup failure means no vma is above this address,
19457 + * else if new region fits below vma->vm_start,
19458 + * return with success:
19459 + */
19460 + vma = find_vma(mm, addr);
19461 + if (check_heap_stack_gap(vma, addr, len))
19462 + /* remember the address as a hint for next time */
19463 + return (mm->free_area_cache = addr);
19464 +
19465 + /* remember the largest hole we saw so far */
19466 + if (addr + mm->cached_hole_size < vma->vm_start)
19467 + mm->cached_hole_size = vma->vm_start - addr;
19468 +
19469 + /* try just below the current vma->vm_start */
19470 + addr = skip_heap_stack_gap(vma, len);
19471 + } while (!IS_ERR_VALUE(addr));
19472 +
19473 +bottomup:
19474 + /*
19475 + * A failed mmap() very likely causes application failure,
19476 + * so fall back to the bottom-up function here. This scenario
19477 + * can happen with large stack limits and large mmap()
19478 + * allocations.
19479 + */
19480 +
19481 +#ifdef CONFIG_PAX_SEGMEXEC
19482 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
19483 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
19484 + else
19485 +#endif
19486 +
19487 + mm->mmap_base = TASK_UNMAPPED_BASE;
19488 +
19489 +#ifdef CONFIG_PAX_RANDMMAP
19490 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19491 + mm->mmap_base += mm->delta_mmap;
19492 +#endif
19493 +
19494 + mm->free_area_cache = mm->mmap_base;
19495 + mm->cached_hole_size = ~0UL;
19496 + addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19497 + /*
19498 + * Restore the topdown base:
19499 + */
19500 + mm->mmap_base = base;
19501 + mm->free_area_cache = base;
19502 + mm->cached_hole_size = ~0UL;
19503 +
19504 + return addr;
19505 }
19506 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
19507 index b4d3c39..82bb73b 100644
19508 --- a/arch/x86/kernel/sys_x86_64.c
19509 +++ b/arch/x86/kernel/sys_x86_64.c
19510 @@ -95,8 +95,8 @@ out:
19511 return error;
19512 }
19513
19514 -static void find_start_end(unsigned long flags, unsigned long *begin,
19515 - unsigned long *end)
19516 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
19517 + unsigned long *begin, unsigned long *end)
19518 {
19519 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
19520 unsigned long new_begin;
19521 @@ -115,7 +115,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
19522 *begin = new_begin;
19523 }
19524 } else {
19525 - *begin = TASK_UNMAPPED_BASE;
19526 + *begin = mm->mmap_base;
19527 *end = TASK_SIZE;
19528 }
19529 }
19530 @@ -132,16 +132,19 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
19531 if (flags & MAP_FIXED)
19532 return addr;
19533
19534 - find_start_end(flags, &begin, &end);
19535 + find_start_end(mm, flags, &begin, &end);
19536
19537 if (len > end)
19538 return -ENOMEM;
19539
19540 +#ifdef CONFIG_PAX_RANDMMAP
19541 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19542 +#endif
19543 +
19544 if (addr) {
19545 addr = PAGE_ALIGN(addr);
19546 vma = find_vma(mm, addr);
19547 - if (end - len >= addr &&
19548 - (!vma || addr + len <= vma->vm_start))
19549 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len))
19550 return addr;
19551 }
19552 if (((flags & MAP_32BIT) || test_thread_flag(TIF_ADDR32))
19553 @@ -172,7 +175,7 @@ full_search:
19554 }
19555 return -ENOMEM;
19556 }
19557 - if (!vma || addr + len <= vma->vm_start) {
19558 + if (check_heap_stack_gap(vma, addr, len)) {
19559 /*
19560 * Remember the place where we stopped the search:
19561 */
19562 @@ -195,7 +198,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19563 {
19564 struct vm_area_struct *vma;
19565 struct mm_struct *mm = current->mm;
19566 - unsigned long addr = addr0, start_addr;
19567 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
19568
19569 /* requested length too big for entire address space */
19570 if (len > TASK_SIZE)
19571 @@ -208,13 +211,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
19572 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
19573 goto bottomup;
19574
19575 +#ifdef CONFIG_PAX_RANDMMAP
19576 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
19577 +#endif
19578 +
19579 /* requesting a specific address */
19580 if (addr) {
19581 addr = PAGE_ALIGN(addr);
19582 - vma = find_vma(mm, addr);
19583 - if (TASK_SIZE - len >= addr &&
19584 - (!vma || addr + len <= vma->vm_start))
19585 - return addr;
19586 + if (TASK_SIZE - len >= addr) {
19587 + vma = find_vma(mm, addr);
19588 + if (check_heap_stack_gap(vma, addr, len))
19589 + return addr;
19590 + }
19591 }
19592
19593 /* check if free_area_cache is useful for us */
19594 @@ -240,7 +248,7 @@ try_again:
19595 * return with success:
19596 */
19597 vma = find_vma(mm, addr);
19598 - if (!vma || addr+len <= vma->vm_start)
19599 + if (check_heap_stack_gap(vma, addr, len))
19600 /* remember the address as a hint for next time */
19601 return mm->free_area_cache = addr;
19602
19603 @@ -249,8 +257,8 @@ try_again:
19604 mm->cached_hole_size = vma->vm_start - addr;
19605
19606 /* try just below the current vma->vm_start */
19607 - addr = vma->vm_start-len;
19608 - } while (len < vma->vm_start);
19609 + addr = skip_heap_stack_gap(vma, len);
19610 + } while (!IS_ERR_VALUE(addr));
19611
19612 fail:
19613 /*
19614 @@ -270,13 +278,21 @@ bottomup:
19615 * can happen with large stack limits and large mmap()
19616 * allocations.
19617 */
19618 + mm->mmap_base = TASK_UNMAPPED_BASE;
19619 +
19620 +#ifdef CONFIG_PAX_RANDMMAP
19621 + if (mm->pax_flags & MF_PAX_RANDMMAP)
19622 + mm->mmap_base += mm->delta_mmap;
19623 +#endif
19624 +
19625 + mm->free_area_cache = mm->mmap_base;
19626 mm->cached_hole_size = ~0UL;
19627 - mm->free_area_cache = TASK_UNMAPPED_BASE;
19628 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
19629 /*
19630 * Restore the topdown base:
19631 */
19632 - mm->free_area_cache = mm->mmap_base;
19633 + mm->mmap_base = base;
19634 + mm->free_area_cache = base;
19635 mm->cached_hole_size = ~0UL;
19636
19637 return addr;
19638 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
19639 index f84fe00..93fe08f 100644
19640 --- a/arch/x86/kernel/tboot.c
19641 +++ b/arch/x86/kernel/tboot.c
19642 @@ -220,7 +220,7 @@ static int tboot_setup_sleep(void)
19643
19644 void tboot_shutdown(u32 shutdown_type)
19645 {
19646 - void (*shutdown)(void);
19647 + void (* __noreturn shutdown)(void);
19648
19649 if (!tboot_enabled())
19650 return;
19651 @@ -242,7 +242,7 @@ void tboot_shutdown(u32 shutdown_type)
19652
19653 switch_to_tboot_pt();
19654
19655 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
19656 + shutdown = (void *)tboot->shutdown_entry;
19657 shutdown();
19658
19659 /* should not reach here */
19660 @@ -300,7 +300,7 @@ static int tboot_sleep(u8 sleep_state, u32 pm1a_control, u32 pm1b_control)
19661 return 0;
19662 }
19663
19664 -static atomic_t ap_wfs_count;
19665 +static atomic_unchecked_t ap_wfs_count;
19666
19667 static int tboot_wait_for_aps(int num_aps)
19668 {
19669 @@ -324,9 +324,9 @@ static int __cpuinit tboot_cpu_callback(struct notifier_block *nfb,
19670 {
19671 switch (action) {
19672 case CPU_DYING:
19673 - atomic_inc(&ap_wfs_count);
19674 + atomic_inc_unchecked(&ap_wfs_count);
19675 if (num_online_cpus() == 1)
19676 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
19677 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
19678 return NOTIFY_BAD;
19679 break;
19680 }
19681 @@ -345,7 +345,7 @@ static __init int tboot_late_init(void)
19682
19683 tboot_create_trampoline();
19684
19685 - atomic_set(&ap_wfs_count, 0);
19686 + atomic_set_unchecked(&ap_wfs_count, 0);
19687 register_hotcpu_notifier(&tboot_cpu_notifier);
19688
19689 acpi_os_set_prepare_sleep(&tboot_sleep);
19690 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
19691 index 24d3c91..d06b473 100644
19692 --- a/arch/x86/kernel/time.c
19693 +++ b/arch/x86/kernel/time.c
19694 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
19695 {
19696 unsigned long pc = instruction_pointer(regs);
19697
19698 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
19699 + if (!user_mode(regs) && in_lock_functions(pc)) {
19700 #ifdef CONFIG_FRAME_POINTER
19701 - return *(unsigned long *)(regs->bp + sizeof(long));
19702 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
19703 #else
19704 unsigned long *sp =
19705 (unsigned long *)kernel_stack_pointer(regs);
19706 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
19707 * or above a saved flags. Eflags has bits 22-31 zero,
19708 * kernel addresses don't.
19709 */
19710 +
19711 +#ifdef CONFIG_PAX_KERNEXEC
19712 + return ktla_ktva(sp[0]);
19713 +#else
19714 if (sp[0] >> 22)
19715 return sp[0];
19716 if (sp[1] >> 22)
19717 return sp[1];
19718 #endif
19719 +
19720 +#endif
19721 }
19722 return pc;
19723 }
19724 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
19725 index 9d9d2f9..cad418a 100644
19726 --- a/arch/x86/kernel/tls.c
19727 +++ b/arch/x86/kernel/tls.c
19728 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
19729 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
19730 return -EINVAL;
19731
19732 +#ifdef CONFIG_PAX_SEGMEXEC
19733 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
19734 + return -EINVAL;
19735 +#endif
19736 +
19737 set_tls_desc(p, idx, &info, 1);
19738
19739 return 0;
19740 @@ -204,7 +209,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
19741
19742 if (kbuf)
19743 info = kbuf;
19744 - else if (__copy_from_user(infobuf, ubuf, count))
19745 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
19746 return -EFAULT;
19747 else
19748 info = infobuf;
19749 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
19750 index 05b31d9..501d3ba 100644
19751 --- a/arch/x86/kernel/traps.c
19752 +++ b/arch/x86/kernel/traps.c
19753 @@ -67,12 +67,6 @@ asmlinkage int system_call(void);
19754
19755 /* Do we ignore FPU interrupts ? */
19756 char ignore_fpu_irq;
19757 -
19758 -/*
19759 - * The IDT has to be page-aligned to simplify the Pentium
19760 - * F0 0F bug workaround.
19761 - */
19762 -gate_desc idt_table[NR_VECTORS] __page_aligned_data = { { { { 0, 0 } } }, };
19763 #endif
19764
19765 DECLARE_BITMAP(used_vectors, NR_VECTORS);
19766 @@ -105,13 +99,13 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
19767 }
19768
19769 static void __kprobes
19770 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19771 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
19772 long error_code, siginfo_t *info)
19773 {
19774 struct task_struct *tsk = current;
19775
19776 #ifdef CONFIG_X86_32
19777 - if (regs->flags & X86_VM_MASK) {
19778 + if (v8086_mode(regs)) {
19779 /*
19780 * traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
19781 * On nmi (interrupt 2), do_trap should not be called.
19782 @@ -122,7 +116,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
19783 }
19784 #endif
19785
19786 - if (!user_mode(regs))
19787 + if (!user_mode_novm(regs))
19788 goto kernel_trap;
19789
19790 #ifdef CONFIG_X86_32
19791 @@ -145,7 +139,7 @@ trap_signal:
19792 printk_ratelimit()) {
19793 printk(KERN_INFO
19794 "%s[%d] trap %s ip:%lx sp:%lx error:%lx",
19795 - tsk->comm, tsk->pid, str,
19796 + tsk->comm, task_pid_nr(tsk), str,
19797 regs->ip, regs->sp, error_code);
19798 print_vma_addr(" in ", regs->ip);
19799 printk("\n");
19800 @@ -162,8 +156,20 @@ kernel_trap:
19801 if (!fixup_exception(regs)) {
19802 tsk->thread.error_code = error_code;
19803 tsk->thread.trap_nr = trapnr;
19804 +
19805 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19806 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
19807 + str = "PAX: suspicious stack segment fault";
19808 +#endif
19809 +
19810 die(str, regs, error_code);
19811 }
19812 +
19813 +#ifdef CONFIG_PAX_REFCOUNT
19814 + if (trapnr == 4)
19815 + pax_report_refcount_overflow(regs);
19816 +#endif
19817 +
19818 return;
19819
19820 #ifdef CONFIG_X86_32
19821 @@ -256,14 +262,30 @@ do_general_protection(struct pt_regs *regs, long error_code)
19822 conditional_sti(regs);
19823
19824 #ifdef CONFIG_X86_32
19825 - if (regs->flags & X86_VM_MASK)
19826 + if (v8086_mode(regs))
19827 goto gp_in_vm86;
19828 #endif
19829
19830 tsk = current;
19831 - if (!user_mode(regs))
19832 + if (!user_mode_novm(regs))
19833 goto gp_in_kernel;
19834
19835 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
19836 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
19837 + struct mm_struct *mm = tsk->mm;
19838 + unsigned long limit;
19839 +
19840 + down_write(&mm->mmap_sem);
19841 + limit = mm->context.user_cs_limit;
19842 + if (limit < TASK_SIZE) {
19843 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
19844 + up_write(&mm->mmap_sem);
19845 + return;
19846 + }
19847 + up_write(&mm->mmap_sem);
19848 + }
19849 +#endif
19850 +
19851 tsk->thread.error_code = error_code;
19852 tsk->thread.trap_nr = X86_TRAP_GP;
19853
19854 @@ -296,6 +318,13 @@ gp_in_kernel:
19855 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
19856 X86_TRAP_GP, SIGSEGV) == NOTIFY_STOP)
19857 return;
19858 +
19859 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19860 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
19861 + die("PAX: suspicious general protection fault", regs, error_code);
19862 + else
19863 +#endif
19864 +
19865 die("general protection fault", regs, error_code);
19866 }
19867
19868 @@ -431,7 +460,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19869 /* It's safe to allow irq's after DR6 has been saved */
19870 preempt_conditional_sti(regs);
19871
19872 - if (regs->flags & X86_VM_MASK) {
19873 + if (v8086_mode(regs)) {
19874 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
19875 X86_TRAP_DB);
19876 preempt_conditional_cli(regs);
19877 @@ -446,7 +475,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
19878 * We already checked v86 mode above, so we can check for kernel mode
19879 * by just checking the CPL of CS.
19880 */
19881 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
19882 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
19883 tsk->thread.debugreg6 &= ~DR_STEP;
19884 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
19885 regs->flags &= ~X86_EFLAGS_TF;
19886 @@ -477,7 +506,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
19887 return;
19888 conditional_sti(regs);
19889
19890 - if (!user_mode_vm(regs))
19891 + if (!user_mode(regs))
19892 {
19893 if (!fixup_exception(regs)) {
19894 task->thread.error_code = error_code;
19895 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
19896 index dc4e910..c9dedab 100644
19897 --- a/arch/x86/kernel/uprobes.c
19898 +++ b/arch/x86/kernel/uprobes.c
19899 @@ -606,7 +606,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
19900 int ret = NOTIFY_DONE;
19901
19902 /* We are only interested in userspace traps */
19903 - if (regs && !user_mode_vm(regs))
19904 + if (regs && !user_mode(regs))
19905 return NOTIFY_DONE;
19906
19907 switch (val) {
19908 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
19909 index b9242ba..50c5edd 100644
19910 --- a/arch/x86/kernel/verify_cpu.S
19911 +++ b/arch/x86/kernel/verify_cpu.S
19912 @@ -20,6 +20,7 @@
19913 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
19914 * arch/x86/kernel/trampoline_64.S: secondary processor verification
19915 * arch/x86/kernel/head_32.S: processor startup
19916 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
19917 *
19918 * verify_cpu, returns the status of longmode and SSE in register %eax.
19919 * 0: Success 1: Failure
19920 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
19921 index 255f58a..5e91150 100644
19922 --- a/arch/x86/kernel/vm86_32.c
19923 +++ b/arch/x86/kernel/vm86_32.c
19924 @@ -41,6 +41,7 @@
19925 #include <linux/ptrace.h>
19926 #include <linux/audit.h>
19927 #include <linux/stddef.h>
19928 +#include <linux/grsecurity.h>
19929
19930 #include <asm/uaccess.h>
19931 #include <asm/io.h>
19932 @@ -148,7 +149,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
19933 do_exit(SIGSEGV);
19934 }
19935
19936 - tss = &per_cpu(init_tss, get_cpu());
19937 + tss = init_tss + get_cpu();
19938 current->thread.sp0 = current->thread.saved_sp0;
19939 current->thread.sysenter_cs = __KERNEL_CS;
19940 load_sp0(tss, &current->thread);
19941 @@ -210,6 +211,13 @@ int sys_vm86old(struct vm86_struct __user *v86, struct pt_regs *regs)
19942 struct task_struct *tsk;
19943 int tmp, ret = -EPERM;
19944
19945 +#ifdef CONFIG_GRKERNSEC_VM86
19946 + if (!capable(CAP_SYS_RAWIO)) {
19947 + gr_handle_vm86();
19948 + goto out;
19949 + }
19950 +#endif
19951 +
19952 tsk = current;
19953 if (tsk->thread.saved_sp0)
19954 goto out;
19955 @@ -240,6 +248,14 @@ int sys_vm86(unsigned long cmd, unsigned long arg, struct pt_regs *regs)
19956 int tmp, ret;
19957 struct vm86plus_struct __user *v86;
19958
19959 +#ifdef CONFIG_GRKERNSEC_VM86
19960 + if (!capable(CAP_SYS_RAWIO)) {
19961 + gr_handle_vm86();
19962 + ret = -EPERM;
19963 + goto out;
19964 + }
19965 +#endif
19966 +
19967 tsk = current;
19968 switch (cmd) {
19969 case VM86_REQUEST_IRQ:
19970 @@ -326,7 +342,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
19971 tsk->thread.saved_fs = info->regs32->fs;
19972 tsk->thread.saved_gs = get_user_gs(info->regs32);
19973
19974 - tss = &per_cpu(init_tss, get_cpu());
19975 + tss = init_tss + get_cpu();
19976 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
19977 if (cpu_has_sep)
19978 tsk->thread.sysenter_cs = 0;
19979 @@ -533,7 +549,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
19980 goto cannot_handle;
19981 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
19982 goto cannot_handle;
19983 - intr_ptr = (unsigned long __user *) (i << 2);
19984 + intr_ptr = (__force unsigned long __user *) (i << 2);
19985 if (get_user(segoffs, intr_ptr))
19986 goto cannot_handle;
19987 if ((segoffs >> 16) == BIOSSEG)
19988 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
19989 index 22a1530..8fbaaad 100644
19990 --- a/arch/x86/kernel/vmlinux.lds.S
19991 +++ b/arch/x86/kernel/vmlinux.lds.S
19992 @@ -26,6 +26,13 @@
19993 #include <asm/page_types.h>
19994 #include <asm/cache.h>
19995 #include <asm/boot.h>
19996 +#include <asm/segment.h>
19997 +
19998 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19999 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
20000 +#else
20001 +#define __KERNEL_TEXT_OFFSET 0
20002 +#endif
20003
20004 #undef i386 /* in case the preprocessor is a 32bit one */
20005
20006 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
20007
20008 PHDRS {
20009 text PT_LOAD FLAGS(5); /* R_E */
20010 +#ifdef CONFIG_X86_32
20011 + module PT_LOAD FLAGS(5); /* R_E */
20012 +#endif
20013 +#ifdef CONFIG_XEN
20014 + rodata PT_LOAD FLAGS(5); /* R_E */
20015 +#else
20016 + rodata PT_LOAD FLAGS(4); /* R__ */
20017 +#endif
20018 data PT_LOAD FLAGS(6); /* RW_ */
20019 -#ifdef CONFIG_X86_64
20020 + init.begin PT_LOAD FLAGS(6); /* RW_ */
20021 #ifdef CONFIG_SMP
20022 percpu PT_LOAD FLAGS(6); /* RW_ */
20023 #endif
20024 + text.init PT_LOAD FLAGS(5); /* R_E */
20025 + text.exit PT_LOAD FLAGS(5); /* R_E */
20026 init PT_LOAD FLAGS(7); /* RWE */
20027 -#endif
20028 note PT_NOTE FLAGS(0); /* ___ */
20029 }
20030
20031 SECTIONS
20032 {
20033 #ifdef CONFIG_X86_32
20034 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
20035 - phys_startup_32 = startup_32 - LOAD_OFFSET;
20036 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
20037 #else
20038 - . = __START_KERNEL;
20039 - phys_startup_64 = startup_64 - LOAD_OFFSET;
20040 + . = __START_KERNEL;
20041 #endif
20042
20043 /* Text and read-only data */
20044 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
20045 - _text = .;
20046 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20047 /* bootstrapping code */
20048 +#ifdef CONFIG_X86_32
20049 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20050 +#else
20051 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20052 +#endif
20053 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
20054 + _text = .;
20055 HEAD_TEXT
20056 #ifdef CONFIG_X86_32
20057 . = ALIGN(PAGE_SIZE);
20058 @@ -108,13 +128,48 @@ SECTIONS
20059 IRQENTRY_TEXT
20060 *(.fixup)
20061 *(.gnu.warning)
20062 - /* End of text section */
20063 - _etext = .;
20064 } :text = 0x9090
20065
20066 - NOTES :text :note
20067 + . += __KERNEL_TEXT_OFFSET;
20068
20069 - EXCEPTION_TABLE(16) :text = 0x9090
20070 +#ifdef CONFIG_X86_32
20071 + . = ALIGN(PAGE_SIZE);
20072 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
20073 +
20074 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_MODULES)
20075 + MODULES_EXEC_VADDR = .;
20076 + BYTE(0)
20077 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
20078 + . = ALIGN(HPAGE_SIZE) - 1;
20079 + MODULES_EXEC_END = .;
20080 +#endif
20081 +
20082 + } :module
20083 +#endif
20084 +
20085 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
20086 + /* End of text section */
20087 + BYTE(0)
20088 + _etext = . - __KERNEL_TEXT_OFFSET;
20089 + }
20090 +
20091 +#ifdef CONFIG_X86_32
20092 + . = ALIGN(PAGE_SIZE);
20093 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
20094 + *(.idt)
20095 + . = ALIGN(PAGE_SIZE);
20096 + *(.empty_zero_page)
20097 + *(.initial_pg_fixmap)
20098 + *(.initial_pg_pmd)
20099 + *(.initial_page_table)
20100 + *(.swapper_pg_dir)
20101 + } :rodata
20102 +#endif
20103 +
20104 + . = ALIGN(PAGE_SIZE);
20105 + NOTES :rodata :note
20106 +
20107 + EXCEPTION_TABLE(16) :rodata
20108
20109 #if defined(CONFIG_DEBUG_RODATA)
20110 /* .text should occupy whole number of pages */
20111 @@ -126,16 +181,20 @@ SECTIONS
20112
20113 /* Data */
20114 .data : AT(ADDR(.data) - LOAD_OFFSET) {
20115 +
20116 +#ifdef CONFIG_PAX_KERNEXEC
20117 + . = ALIGN(HPAGE_SIZE);
20118 +#else
20119 + . = ALIGN(PAGE_SIZE);
20120 +#endif
20121 +
20122 /* Start of data section */
20123 _sdata = .;
20124
20125 /* init_task */
20126 INIT_TASK_DATA(THREAD_SIZE)
20127
20128 -#ifdef CONFIG_X86_32
20129 - /* 32 bit has nosave before _edata */
20130 NOSAVE_DATA
20131 -#endif
20132
20133 PAGE_ALIGNED_DATA(PAGE_SIZE)
20134
20135 @@ -176,12 +235,19 @@ SECTIONS
20136 #endif /* CONFIG_X86_64 */
20137
20138 /* Init code and data - will be freed after init */
20139 - . = ALIGN(PAGE_SIZE);
20140 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
20141 + BYTE(0)
20142 +
20143 +#ifdef CONFIG_PAX_KERNEXEC
20144 + . = ALIGN(HPAGE_SIZE);
20145 +#else
20146 + . = ALIGN(PAGE_SIZE);
20147 +#endif
20148 +
20149 __init_begin = .; /* paired with __init_end */
20150 - }
20151 + } :init.begin
20152
20153 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
20154 +#ifdef CONFIG_SMP
20155 /*
20156 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
20157 * output PHDR, so the next output section - .init.text - should
20158 @@ -190,12 +256,27 @@ SECTIONS
20159 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
20160 #endif
20161
20162 - INIT_TEXT_SECTION(PAGE_SIZE)
20163 -#ifdef CONFIG_X86_64
20164 - :init
20165 -#endif
20166 + . = ALIGN(PAGE_SIZE);
20167 + init_begin = .;
20168 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
20169 + VMLINUX_SYMBOL(_sinittext) = .;
20170 + INIT_TEXT
20171 + VMLINUX_SYMBOL(_einittext) = .;
20172 + . = ALIGN(PAGE_SIZE);
20173 + } :text.init
20174
20175 - INIT_DATA_SECTION(16)
20176 + /*
20177 + * .exit.text is discard at runtime, not link time, to deal with
20178 + * references from .altinstructions and .eh_frame
20179 + */
20180 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
20181 + EXIT_TEXT
20182 + . = ALIGN(16);
20183 + } :text.exit
20184 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
20185 +
20186 + . = ALIGN(PAGE_SIZE);
20187 + INIT_DATA_SECTION(16) :init
20188
20189 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
20190 __x86_cpu_dev_start = .;
20191 @@ -257,19 +338,12 @@ SECTIONS
20192 }
20193
20194 . = ALIGN(8);
20195 - /*
20196 - * .exit.text is discard at runtime, not link time, to deal with
20197 - * references from .altinstructions and .eh_frame
20198 - */
20199 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
20200 - EXIT_TEXT
20201 - }
20202
20203 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
20204 EXIT_DATA
20205 }
20206
20207 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
20208 +#ifndef CONFIG_SMP
20209 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
20210 #endif
20211
20212 @@ -288,16 +362,10 @@ SECTIONS
20213 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
20214 __smp_locks = .;
20215 *(.smp_locks)
20216 - . = ALIGN(PAGE_SIZE);
20217 __smp_locks_end = .;
20218 + . = ALIGN(PAGE_SIZE);
20219 }
20220
20221 -#ifdef CONFIG_X86_64
20222 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
20223 - NOSAVE_DATA
20224 - }
20225 -#endif
20226 -
20227 /* BSS */
20228 . = ALIGN(PAGE_SIZE);
20229 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
20230 @@ -313,6 +381,7 @@ SECTIONS
20231 __brk_base = .;
20232 . += 64 * 1024; /* 64k alignment slop space */
20233 *(.brk_reservation) /* areas brk users have reserved */
20234 + . = ALIGN(HPAGE_SIZE);
20235 __brk_limit = .;
20236 }
20237
20238 @@ -339,13 +408,12 @@ SECTIONS
20239 * for the boot processor.
20240 */
20241 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
20242 -INIT_PER_CPU(gdt_page);
20243 INIT_PER_CPU(irq_stack_union);
20244
20245 /*
20246 * Build-time check on the image size:
20247 */
20248 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
20249 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
20250 "kernel image bigger than KERNEL_IMAGE_SIZE");
20251
20252 #ifdef CONFIG_SMP
20253 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
20254 index 5db36ca..2938af9 100644
20255 --- a/arch/x86/kernel/vsyscall_64.c
20256 +++ b/arch/x86/kernel/vsyscall_64.c
20257 @@ -54,15 +54,13 @@
20258 DEFINE_VVAR(int, vgetcpu_mode);
20259 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
20260
20261 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
20262 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
20263
20264 static int __init vsyscall_setup(char *str)
20265 {
20266 if (str) {
20267 if (!strcmp("emulate", str))
20268 vsyscall_mode = EMULATE;
20269 - else if (!strcmp("native", str))
20270 - vsyscall_mode = NATIVE;
20271 else if (!strcmp("none", str))
20272 vsyscall_mode = NONE;
20273 else
20274 @@ -309,8 +307,7 @@ done:
20275 return true;
20276
20277 sigsegv:
20278 - force_sig(SIGSEGV, current);
20279 - return true;
20280 + do_group_exit(SIGKILL);
20281 }
20282
20283 /*
20284 @@ -363,10 +360,7 @@ void __init map_vsyscall(void)
20285 extern char __vvar_page;
20286 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
20287
20288 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
20289 - vsyscall_mode == NATIVE
20290 - ? PAGE_KERNEL_VSYSCALL
20291 - : PAGE_KERNEL_VVAR);
20292 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
20293 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
20294 (unsigned long)VSYSCALL_START);
20295
20296 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
20297 index 9796c2f..f686fbf 100644
20298 --- a/arch/x86/kernel/x8664_ksyms_64.c
20299 +++ b/arch/x86/kernel/x8664_ksyms_64.c
20300 @@ -29,8 +29,6 @@ EXPORT_SYMBOL(__put_user_8);
20301 EXPORT_SYMBOL(copy_user_generic_string);
20302 EXPORT_SYMBOL(copy_user_generic_unrolled);
20303 EXPORT_SYMBOL(__copy_user_nocache);
20304 -EXPORT_SYMBOL(_copy_from_user);
20305 -EXPORT_SYMBOL(_copy_to_user);
20306
20307 EXPORT_SYMBOL(copy_page);
20308 EXPORT_SYMBOL(clear_page);
20309 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
20310 index bd18149..2ea0183 100644
20311 --- a/arch/x86/kernel/xsave.c
20312 +++ b/arch/x86/kernel/xsave.c
20313 @@ -129,7 +129,7 @@ int check_for_xstate(struct i387_fxsave_struct __user *buf,
20314 fx_sw_user->xstate_size > fx_sw_user->extended_size)
20315 return -EINVAL;
20316
20317 - err = __get_user(magic2, (__u32 *) (((void *)fpstate) +
20318 + err = __get_user(magic2, (__u32 __user *) (((void __user *)fpstate) +
20319 fx_sw_user->extended_size -
20320 FP_XSTATE_MAGIC2_SIZE));
20321 if (err)
20322 @@ -265,7 +265,7 @@ fx_only:
20323 * the other extended state.
20324 */
20325 xrstor_state(init_xstate_buf, pcntxt_mask & ~XSTATE_FPSSE);
20326 - return fxrstor_checking((__force struct i387_fxsave_struct *)buf);
20327 + return fxrstor_checking((struct i387_fxsave_struct __force_kernel *)buf);
20328 }
20329
20330 /*
20331 @@ -294,7 +294,7 @@ int restore_i387_xstate(void __user *buf)
20332 if (use_xsave())
20333 err = restore_user_xstate(buf);
20334 else
20335 - err = fxrstor_checking((__force struct i387_fxsave_struct *)
20336 + err = fxrstor_checking((struct i387_fxsave_struct __force_kernel *)
20337 buf);
20338 if (unlikely(err)) {
20339 /*
20340 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
20341 index 7df1c6d..9ea7c79 100644
20342 --- a/arch/x86/kvm/cpuid.c
20343 +++ b/arch/x86/kvm/cpuid.c
20344 @@ -124,15 +124,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
20345 struct kvm_cpuid2 *cpuid,
20346 struct kvm_cpuid_entry2 __user *entries)
20347 {
20348 - int r;
20349 + int r, i;
20350
20351 r = -E2BIG;
20352 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
20353 goto out;
20354 r = -EFAULT;
20355 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
20356 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20357 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
20358 goto out;
20359 + for (i = 0; i < cpuid->nent; ++i) {
20360 + struct kvm_cpuid_entry2 cpuid_entry;
20361 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
20362 + goto out;
20363 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
20364 + }
20365 vcpu->arch.cpuid_nent = cpuid->nent;
20366 kvm_apic_set_version(vcpu);
20367 kvm_x86_ops->cpuid_update(vcpu);
20368 @@ -147,15 +152,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
20369 struct kvm_cpuid2 *cpuid,
20370 struct kvm_cpuid_entry2 __user *entries)
20371 {
20372 - int r;
20373 + int r, i;
20374
20375 r = -E2BIG;
20376 if (cpuid->nent < vcpu->arch.cpuid_nent)
20377 goto out;
20378 r = -EFAULT;
20379 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
20380 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20381 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
20382 goto out;
20383 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
20384 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
20385 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
20386 + goto out;
20387 + }
20388 return 0;
20389
20390 out:
20391 diff --git a/arch/x86/kvm/emulate.c b/arch/x86/kvm/emulate.c
20392 index 4837375..2cc9722 100644
20393 --- a/arch/x86/kvm/emulate.c
20394 +++ b/arch/x86/kvm/emulate.c
20395 @@ -256,6 +256,7 @@ struct gprefix {
20396
20397 #define ____emulate_2op(ctxt, _op, _x, _y, _suffix, _dsttype) \
20398 do { \
20399 + unsigned long _tmp; \
20400 __asm__ __volatile__ ( \
20401 _PRE_EFLAGS("0", "4", "2") \
20402 _op _suffix " %"_x"3,%1; " \
20403 @@ -270,8 +271,6 @@ struct gprefix {
20404 /* Raw emulation: instruction has two explicit operands. */
20405 #define __emulate_2op_nobyte(ctxt,_op,_wx,_wy,_lx,_ly,_qx,_qy) \
20406 do { \
20407 - unsigned long _tmp; \
20408 - \
20409 switch ((ctxt)->dst.bytes) { \
20410 case 2: \
20411 ____emulate_2op(ctxt,_op,_wx,_wy,"w",u16); \
20412 @@ -287,7 +286,6 @@ struct gprefix {
20413
20414 #define __emulate_2op(ctxt,_op,_bx,_by,_wx,_wy,_lx,_ly,_qx,_qy) \
20415 do { \
20416 - unsigned long _tmp; \
20417 switch ((ctxt)->dst.bytes) { \
20418 case 1: \
20419 ____emulate_2op(ctxt,_op,_bx,_by,"b",u8); \
20420 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
20421 index 93c1574..d6097dc 100644
20422 --- a/arch/x86/kvm/lapic.c
20423 +++ b/arch/x86/kvm/lapic.c
20424 @@ -54,7 +54,7 @@
20425 #define APIC_BUS_CYCLE_NS 1
20426
20427 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
20428 -#define apic_debug(fmt, arg...)
20429 +#define apic_debug(fmt, arg...) do {} while (0)
20430
20431 #define APIC_LVT_NUM 6
20432 /* 14 is the version for Xeon and Pentium 8.4.8*/
20433 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
20434 index 34f9709..8eca2d5 100644
20435 --- a/arch/x86/kvm/paging_tmpl.h
20436 +++ b/arch/x86/kvm/paging_tmpl.h
20437 @@ -197,7 +197,7 @@ retry_walk:
20438 if (unlikely(kvm_is_error_hva(host_addr)))
20439 goto error;
20440
20441 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
20442 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
20443 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
20444 goto error;
20445
20446 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
20447 index f75af40..285b18f 100644
20448 --- a/arch/x86/kvm/svm.c
20449 +++ b/arch/x86/kvm/svm.c
20450 @@ -3516,7 +3516,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
20451 int cpu = raw_smp_processor_id();
20452
20453 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
20454 +
20455 + pax_open_kernel();
20456 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
20457 + pax_close_kernel();
20458 +
20459 load_TR_desc();
20460 }
20461
20462 @@ -3894,6 +3898,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
20463 #endif
20464 #endif
20465
20466 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
20467 + __set_fs(current_thread_info()->addr_limit);
20468 +#endif
20469 +
20470 reload_tss(vcpu);
20471
20472 local_irq_disable();
20473 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
20474 index 86c8704..d9277bb 100644
20475 --- a/arch/x86/kvm/vmx.c
20476 +++ b/arch/x86/kvm/vmx.c
20477 @@ -1317,7 +1317,11 @@ static void reload_tss(void)
20478 struct desc_struct *descs;
20479
20480 descs = (void *)gdt->address;
20481 +
20482 + pax_open_kernel();
20483 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
20484 + pax_close_kernel();
20485 +
20486 load_TR_desc();
20487 }
20488
20489 @@ -1527,6 +1531,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
20490 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
20491 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
20492
20493 +#ifdef CONFIG_PAX_PER_CPU_PGD
20494 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20495 +#endif
20496 +
20497 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
20498 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
20499 vmx->loaded_vmcs->cpu = cpu;
20500 @@ -2650,8 +2658,11 @@ static __init int hardware_setup(void)
20501 if (!cpu_has_vmx_flexpriority())
20502 flexpriority_enabled = 0;
20503
20504 - if (!cpu_has_vmx_tpr_shadow())
20505 - kvm_x86_ops->update_cr8_intercept = NULL;
20506 + if (!cpu_has_vmx_tpr_shadow()) {
20507 + pax_open_kernel();
20508 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
20509 + pax_close_kernel();
20510 + }
20511
20512 if (enable_ept && !cpu_has_vmx_ept_2m_page())
20513 kvm_disable_largepages();
20514 @@ -3697,7 +3708,10 @@ static void vmx_set_constant_host_state(void)
20515
20516 vmcs_writel(HOST_CR0, read_cr0() | X86_CR0_TS); /* 22.2.3 */
20517 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
20518 +
20519 +#ifndef CONFIG_PAX_PER_CPU_PGD
20520 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
20521 +#endif
20522
20523 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
20524 #ifdef CONFIG_X86_64
20525 @@ -3719,7 +3733,7 @@ static void vmx_set_constant_host_state(void)
20526 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
20527
20528 asm("mov $.Lkvm_vmx_return, %0" : "=r"(tmpl));
20529 - vmcs_writel(HOST_RIP, tmpl); /* 22.2.5 */
20530 + vmcs_writel(HOST_RIP, ktla_ktva(tmpl)); /* 22.2.5 */
20531
20532 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
20533 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
20534 @@ -6257,6 +6271,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20535 "jmp .Lkvm_vmx_return \n\t"
20536 ".Llaunched: " __ex(ASM_VMX_VMRESUME) "\n\t"
20537 ".Lkvm_vmx_return: "
20538 +
20539 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20540 + "ljmp %[cs],$.Lkvm_vmx_return2\n\t"
20541 + ".Lkvm_vmx_return2: "
20542 +#endif
20543 +
20544 /* Save guest registers, load host registers, keep flags */
20545 "mov %0, %c[wordsize](%%"R"sp) \n\t"
20546 "pop %0 \n\t"
20547 @@ -6305,6 +6325,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20548 #endif
20549 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
20550 [wordsize]"i"(sizeof(ulong))
20551 +
20552 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
20553 + ,[cs]"i"(__KERNEL_CS)
20554 +#endif
20555 +
20556 : "cc", "memory"
20557 , R"ax", R"bx", R"di", R"si"
20558 #ifdef CONFIG_X86_64
20559 @@ -6312,7 +6337,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20560 #endif
20561 );
20562
20563 -#ifndef CONFIG_X86_64
20564 +#ifdef CONFIG_X86_32
20565 /*
20566 * The sysexit path does not restore ds/es, so we must set them to
20567 * a reasonable value ourselves.
20568 @@ -6321,8 +6346,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
20569 * may be executed in interrupt context, which saves and restore segments
20570 * around it, nullifying its effect.
20571 */
20572 - loadsegment(ds, __USER_DS);
20573 - loadsegment(es, __USER_DS);
20574 + loadsegment(ds, __KERNEL_DS);
20575 + loadsegment(es, __KERNEL_DS);
20576 + loadsegment(ss, __KERNEL_DS);
20577 +
20578 +#ifdef CONFIG_PAX_KERNEXEC
20579 + loadsegment(fs, __KERNEL_PERCPU);
20580 +#endif
20581 +
20582 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20583 + __set_fs(current_thread_info()->addr_limit);
20584 +#endif
20585 +
20586 #endif
20587
20588 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
20589 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
20590 index 14c290d..0dae6e5 100644
20591 --- a/arch/x86/kvm/x86.c
20592 +++ b/arch/x86/kvm/x86.c
20593 @@ -1361,8 +1361,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
20594 {
20595 struct kvm *kvm = vcpu->kvm;
20596 int lm = is_long_mode(vcpu);
20597 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20598 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20599 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
20600 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
20601 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
20602 : kvm->arch.xen_hvm_config.blob_size_32;
20603 u32 page_num = data & ~PAGE_MASK;
20604 @@ -2218,6 +2218,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
20605 if (n < msr_list.nmsrs)
20606 goto out;
20607 r = -EFAULT;
20608 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
20609 + goto out;
20610 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
20611 num_msrs_to_save * sizeof(u32)))
20612 goto out;
20613 @@ -2343,7 +2345,7 @@ static int kvm_vcpu_ioctl_set_lapic(struct kvm_vcpu *vcpu,
20614 static int kvm_vcpu_ioctl_interrupt(struct kvm_vcpu *vcpu,
20615 struct kvm_interrupt *irq)
20616 {
20617 - if (irq->irq < 0 || irq->irq >= 256)
20618 + if (irq->irq >= 256)
20619 return -EINVAL;
20620 if (irqchip_in_kernel(vcpu->kvm))
20621 return -ENXIO;
20622 @@ -4880,7 +4882,7 @@ static void kvm_set_mmio_spte_mask(void)
20623 kvm_mmu_set_mmio_spte_mask(mask);
20624 }
20625
20626 -int kvm_arch_init(void *opaque)
20627 +int kvm_arch_init(const void *opaque)
20628 {
20629 int r;
20630 struct kvm_x86_ops *ops = (struct kvm_x86_ops *)opaque;
20631 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
20632 index 642d880..cc9ebac 100644
20633 --- a/arch/x86/lguest/boot.c
20634 +++ b/arch/x86/lguest/boot.c
20635 @@ -1116,12 +1116,12 @@ static u32 lguest_apic_safe_wait_icr_idle(void)
20636
20637 static void set_lguest_basic_apic_ops(void)
20638 {
20639 - apic->read = lguest_apic_read;
20640 - apic->write = lguest_apic_write;
20641 - apic->icr_read = lguest_apic_icr_read;
20642 - apic->icr_write = lguest_apic_icr_write;
20643 - apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20644 - apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20645 + *(void **)&apic->read = lguest_apic_read;
20646 + *(void **)&apic->write = lguest_apic_write;
20647 + *(void **)&apic->icr_read = lguest_apic_icr_read;
20648 + *(void **)&apic->icr_write = lguest_apic_icr_write;
20649 + *(void **)&apic->wait_icr_idle = lguest_apic_wait_icr_idle;
20650 + *(void **)&apic->safe_wait_icr_idle = lguest_apic_safe_wait_icr_idle;
20651 };
20652 #endif
20653
20654 @@ -1200,9 +1200,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
20655 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
20656 * Launcher to reboot us.
20657 */
20658 -static void lguest_restart(char *reason)
20659 +static __noreturn void lguest_restart(char *reason)
20660 {
20661 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
20662 + BUG();
20663 }
20664
20665 /*G:050
20666 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
20667 index 00933d5..3a64af9 100644
20668 --- a/arch/x86/lib/atomic64_386_32.S
20669 +++ b/arch/x86/lib/atomic64_386_32.S
20670 @@ -48,6 +48,10 @@ BEGIN(read)
20671 movl (v), %eax
20672 movl 4(v), %edx
20673 RET_ENDP
20674 +BEGIN(read_unchecked)
20675 + movl (v), %eax
20676 + movl 4(v), %edx
20677 +RET_ENDP
20678 #undef v
20679
20680 #define v %esi
20681 @@ -55,6 +59,10 @@ BEGIN(set)
20682 movl %ebx, (v)
20683 movl %ecx, 4(v)
20684 RET_ENDP
20685 +BEGIN(set_unchecked)
20686 + movl %ebx, (v)
20687 + movl %ecx, 4(v)
20688 +RET_ENDP
20689 #undef v
20690
20691 #define v %esi
20692 @@ -70,6 +78,20 @@ RET_ENDP
20693 BEGIN(add)
20694 addl %eax, (v)
20695 adcl %edx, 4(v)
20696 +
20697 +#ifdef CONFIG_PAX_REFCOUNT
20698 + jno 0f
20699 + subl %eax, (v)
20700 + sbbl %edx, 4(v)
20701 + int $4
20702 +0:
20703 + _ASM_EXTABLE(0b, 0b)
20704 +#endif
20705 +
20706 +RET_ENDP
20707 +BEGIN(add_unchecked)
20708 + addl %eax, (v)
20709 + adcl %edx, 4(v)
20710 RET_ENDP
20711 #undef v
20712
20713 @@ -77,6 +99,24 @@ RET_ENDP
20714 BEGIN(add_return)
20715 addl (v), %eax
20716 adcl 4(v), %edx
20717 +
20718 +#ifdef CONFIG_PAX_REFCOUNT
20719 + into
20720 +1234:
20721 + _ASM_EXTABLE(1234b, 2f)
20722 +#endif
20723 +
20724 + movl %eax, (v)
20725 + movl %edx, 4(v)
20726 +
20727 +#ifdef CONFIG_PAX_REFCOUNT
20728 +2:
20729 +#endif
20730 +
20731 +RET_ENDP
20732 +BEGIN(add_return_unchecked)
20733 + addl (v), %eax
20734 + adcl 4(v), %edx
20735 movl %eax, (v)
20736 movl %edx, 4(v)
20737 RET_ENDP
20738 @@ -86,6 +126,20 @@ RET_ENDP
20739 BEGIN(sub)
20740 subl %eax, (v)
20741 sbbl %edx, 4(v)
20742 +
20743 +#ifdef CONFIG_PAX_REFCOUNT
20744 + jno 0f
20745 + addl %eax, (v)
20746 + adcl %edx, 4(v)
20747 + int $4
20748 +0:
20749 + _ASM_EXTABLE(0b, 0b)
20750 +#endif
20751 +
20752 +RET_ENDP
20753 +BEGIN(sub_unchecked)
20754 + subl %eax, (v)
20755 + sbbl %edx, 4(v)
20756 RET_ENDP
20757 #undef v
20758
20759 @@ -96,6 +150,27 @@ BEGIN(sub_return)
20760 sbbl $0, %edx
20761 addl (v), %eax
20762 adcl 4(v), %edx
20763 +
20764 +#ifdef CONFIG_PAX_REFCOUNT
20765 + into
20766 +1234:
20767 + _ASM_EXTABLE(1234b, 2f)
20768 +#endif
20769 +
20770 + movl %eax, (v)
20771 + movl %edx, 4(v)
20772 +
20773 +#ifdef CONFIG_PAX_REFCOUNT
20774 +2:
20775 +#endif
20776 +
20777 +RET_ENDP
20778 +BEGIN(sub_return_unchecked)
20779 + negl %edx
20780 + negl %eax
20781 + sbbl $0, %edx
20782 + addl (v), %eax
20783 + adcl 4(v), %edx
20784 movl %eax, (v)
20785 movl %edx, 4(v)
20786 RET_ENDP
20787 @@ -105,6 +180,20 @@ RET_ENDP
20788 BEGIN(inc)
20789 addl $1, (v)
20790 adcl $0, 4(v)
20791 +
20792 +#ifdef CONFIG_PAX_REFCOUNT
20793 + jno 0f
20794 + subl $1, (v)
20795 + sbbl $0, 4(v)
20796 + int $4
20797 +0:
20798 + _ASM_EXTABLE(0b, 0b)
20799 +#endif
20800 +
20801 +RET_ENDP
20802 +BEGIN(inc_unchecked)
20803 + addl $1, (v)
20804 + adcl $0, 4(v)
20805 RET_ENDP
20806 #undef v
20807
20808 @@ -114,6 +203,26 @@ BEGIN(inc_return)
20809 movl 4(v), %edx
20810 addl $1, %eax
20811 adcl $0, %edx
20812 +
20813 +#ifdef CONFIG_PAX_REFCOUNT
20814 + into
20815 +1234:
20816 + _ASM_EXTABLE(1234b, 2f)
20817 +#endif
20818 +
20819 + movl %eax, (v)
20820 + movl %edx, 4(v)
20821 +
20822 +#ifdef CONFIG_PAX_REFCOUNT
20823 +2:
20824 +#endif
20825 +
20826 +RET_ENDP
20827 +BEGIN(inc_return_unchecked)
20828 + movl (v), %eax
20829 + movl 4(v), %edx
20830 + addl $1, %eax
20831 + adcl $0, %edx
20832 movl %eax, (v)
20833 movl %edx, 4(v)
20834 RET_ENDP
20835 @@ -123,6 +232,20 @@ RET_ENDP
20836 BEGIN(dec)
20837 subl $1, (v)
20838 sbbl $0, 4(v)
20839 +
20840 +#ifdef CONFIG_PAX_REFCOUNT
20841 + jno 0f
20842 + addl $1, (v)
20843 + adcl $0, 4(v)
20844 + int $4
20845 +0:
20846 + _ASM_EXTABLE(0b, 0b)
20847 +#endif
20848 +
20849 +RET_ENDP
20850 +BEGIN(dec_unchecked)
20851 + subl $1, (v)
20852 + sbbl $0, 4(v)
20853 RET_ENDP
20854 #undef v
20855
20856 @@ -132,6 +255,26 @@ BEGIN(dec_return)
20857 movl 4(v), %edx
20858 subl $1, %eax
20859 sbbl $0, %edx
20860 +
20861 +#ifdef CONFIG_PAX_REFCOUNT
20862 + into
20863 +1234:
20864 + _ASM_EXTABLE(1234b, 2f)
20865 +#endif
20866 +
20867 + movl %eax, (v)
20868 + movl %edx, 4(v)
20869 +
20870 +#ifdef CONFIG_PAX_REFCOUNT
20871 +2:
20872 +#endif
20873 +
20874 +RET_ENDP
20875 +BEGIN(dec_return_unchecked)
20876 + movl (v), %eax
20877 + movl 4(v), %edx
20878 + subl $1, %eax
20879 + sbbl $0, %edx
20880 movl %eax, (v)
20881 movl %edx, 4(v)
20882 RET_ENDP
20883 @@ -143,6 +286,13 @@ BEGIN(add_unless)
20884 adcl %edx, %edi
20885 addl (v), %eax
20886 adcl 4(v), %edx
20887 +
20888 +#ifdef CONFIG_PAX_REFCOUNT
20889 + into
20890 +1234:
20891 + _ASM_EXTABLE(1234b, 2f)
20892 +#endif
20893 +
20894 cmpl %eax, %ecx
20895 je 3f
20896 1:
20897 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
20898 1:
20899 addl $1, %eax
20900 adcl $0, %edx
20901 +
20902 +#ifdef CONFIG_PAX_REFCOUNT
20903 + into
20904 +1234:
20905 + _ASM_EXTABLE(1234b, 2f)
20906 +#endif
20907 +
20908 movl %eax, (v)
20909 movl %edx, 4(v)
20910 movl $1, %eax
20911 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
20912 movl 4(v), %edx
20913 subl $1, %eax
20914 sbbl $0, %edx
20915 +
20916 +#ifdef CONFIG_PAX_REFCOUNT
20917 + into
20918 +1234:
20919 + _ASM_EXTABLE(1234b, 1f)
20920 +#endif
20921 +
20922 js 1f
20923 movl %eax, (v)
20924 movl %edx, 4(v)
20925 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
20926 index f5cc9eb..51fa319 100644
20927 --- a/arch/x86/lib/atomic64_cx8_32.S
20928 +++ b/arch/x86/lib/atomic64_cx8_32.S
20929 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
20930 CFI_STARTPROC
20931
20932 read64 %ecx
20933 + pax_force_retaddr
20934 ret
20935 CFI_ENDPROC
20936 ENDPROC(atomic64_read_cx8)
20937
20938 +ENTRY(atomic64_read_unchecked_cx8)
20939 + CFI_STARTPROC
20940 +
20941 + read64 %ecx
20942 + pax_force_retaddr
20943 + ret
20944 + CFI_ENDPROC
20945 +ENDPROC(atomic64_read_unchecked_cx8)
20946 +
20947 ENTRY(atomic64_set_cx8)
20948 CFI_STARTPROC
20949
20950 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
20951 cmpxchg8b (%esi)
20952 jne 1b
20953
20954 + pax_force_retaddr
20955 ret
20956 CFI_ENDPROC
20957 ENDPROC(atomic64_set_cx8)
20958
20959 +ENTRY(atomic64_set_unchecked_cx8)
20960 + CFI_STARTPROC
20961 +
20962 +1:
20963 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
20964 + * are atomic on 586 and newer */
20965 + cmpxchg8b (%esi)
20966 + jne 1b
20967 +
20968 + pax_force_retaddr
20969 + ret
20970 + CFI_ENDPROC
20971 +ENDPROC(atomic64_set_unchecked_cx8)
20972 +
20973 ENTRY(atomic64_xchg_cx8)
20974 CFI_STARTPROC
20975
20976 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
20977 cmpxchg8b (%esi)
20978 jne 1b
20979
20980 + pax_force_retaddr
20981 ret
20982 CFI_ENDPROC
20983 ENDPROC(atomic64_xchg_cx8)
20984
20985 -.macro addsub_return func ins insc
20986 -ENTRY(atomic64_\func\()_return_cx8)
20987 +.macro addsub_return func ins insc unchecked=""
20988 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
20989 CFI_STARTPROC
20990 SAVE ebp
20991 SAVE ebx
20992 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
20993 movl %edx, %ecx
20994 \ins\()l %esi, %ebx
20995 \insc\()l %edi, %ecx
20996 +
20997 +.ifb \unchecked
20998 +#ifdef CONFIG_PAX_REFCOUNT
20999 + into
21000 +2:
21001 + _ASM_EXTABLE(2b, 3f)
21002 +#endif
21003 +.endif
21004 +
21005 LOCK_PREFIX
21006 cmpxchg8b (%ebp)
21007 jne 1b
21008 -
21009 -10:
21010 movl %ebx, %eax
21011 movl %ecx, %edx
21012 +
21013 +.ifb \unchecked
21014 +#ifdef CONFIG_PAX_REFCOUNT
21015 +3:
21016 +#endif
21017 +.endif
21018 +
21019 RESTORE edi
21020 RESTORE esi
21021 RESTORE ebx
21022 RESTORE ebp
21023 + pax_force_retaddr
21024 ret
21025 CFI_ENDPROC
21026 -ENDPROC(atomic64_\func\()_return_cx8)
21027 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21028 .endm
21029
21030 addsub_return add add adc
21031 addsub_return sub sub sbb
21032 +addsub_return add add adc _unchecked
21033 +addsub_return sub sub sbb _unchecked
21034
21035 -.macro incdec_return func ins insc
21036 -ENTRY(atomic64_\func\()_return_cx8)
21037 +.macro incdec_return func ins insc unchecked=""
21038 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
21039 CFI_STARTPROC
21040 SAVE ebx
21041
21042 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
21043 movl %edx, %ecx
21044 \ins\()l $1, %ebx
21045 \insc\()l $0, %ecx
21046 +
21047 +.ifb \unchecked
21048 +#ifdef CONFIG_PAX_REFCOUNT
21049 + into
21050 +2:
21051 + _ASM_EXTABLE(2b, 3f)
21052 +#endif
21053 +.endif
21054 +
21055 LOCK_PREFIX
21056 cmpxchg8b (%esi)
21057 jne 1b
21058
21059 -10:
21060 movl %ebx, %eax
21061 movl %ecx, %edx
21062 +
21063 +.ifb \unchecked
21064 +#ifdef CONFIG_PAX_REFCOUNT
21065 +3:
21066 +#endif
21067 +.endif
21068 +
21069 RESTORE ebx
21070 + pax_force_retaddr
21071 ret
21072 CFI_ENDPROC
21073 -ENDPROC(atomic64_\func\()_return_cx8)
21074 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
21075 .endm
21076
21077 incdec_return inc add adc
21078 incdec_return dec sub sbb
21079 +incdec_return inc add adc _unchecked
21080 +incdec_return dec sub sbb _unchecked
21081
21082 ENTRY(atomic64_dec_if_positive_cx8)
21083 CFI_STARTPROC
21084 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
21085 movl %edx, %ecx
21086 subl $1, %ebx
21087 sbb $0, %ecx
21088 +
21089 +#ifdef CONFIG_PAX_REFCOUNT
21090 + into
21091 +1234:
21092 + _ASM_EXTABLE(1234b, 2f)
21093 +#endif
21094 +
21095 js 2f
21096 LOCK_PREFIX
21097 cmpxchg8b (%esi)
21098 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
21099 movl %ebx, %eax
21100 movl %ecx, %edx
21101 RESTORE ebx
21102 + pax_force_retaddr
21103 ret
21104 CFI_ENDPROC
21105 ENDPROC(atomic64_dec_if_positive_cx8)
21106 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
21107 movl %edx, %ecx
21108 addl %ebp, %ebx
21109 adcl %edi, %ecx
21110 +
21111 +#ifdef CONFIG_PAX_REFCOUNT
21112 + into
21113 +1234:
21114 + _ASM_EXTABLE(1234b, 3f)
21115 +#endif
21116 +
21117 LOCK_PREFIX
21118 cmpxchg8b (%esi)
21119 jne 1b
21120 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
21121 CFI_ADJUST_CFA_OFFSET -8
21122 RESTORE ebx
21123 RESTORE ebp
21124 + pax_force_retaddr
21125 ret
21126 4:
21127 cmpl %edx, 4(%esp)
21128 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
21129 xorl %ecx, %ecx
21130 addl $1, %ebx
21131 adcl %edx, %ecx
21132 +
21133 +#ifdef CONFIG_PAX_REFCOUNT
21134 + into
21135 +1234:
21136 + _ASM_EXTABLE(1234b, 3f)
21137 +#endif
21138 +
21139 LOCK_PREFIX
21140 cmpxchg8b (%esi)
21141 jne 1b
21142 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
21143 movl $1, %eax
21144 3:
21145 RESTORE ebx
21146 + pax_force_retaddr
21147 ret
21148 CFI_ENDPROC
21149 ENDPROC(atomic64_inc_not_zero_cx8)
21150 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
21151 index 2af5df3..62b1a5a 100644
21152 --- a/arch/x86/lib/checksum_32.S
21153 +++ b/arch/x86/lib/checksum_32.S
21154 @@ -29,7 +29,8 @@
21155 #include <asm/dwarf2.h>
21156 #include <asm/errno.h>
21157 #include <asm/asm.h>
21158 -
21159 +#include <asm/segment.h>
21160 +
21161 /*
21162 * computes a partial checksum, e.g. for TCP/UDP fragments
21163 */
21164 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
21165
21166 #define ARGBASE 16
21167 #define FP 12
21168 -
21169 -ENTRY(csum_partial_copy_generic)
21170 +
21171 +ENTRY(csum_partial_copy_generic_to_user)
21172 CFI_STARTPROC
21173 +
21174 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21175 + pushl_cfi %gs
21176 + popl_cfi %es
21177 + jmp csum_partial_copy_generic
21178 +#endif
21179 +
21180 +ENTRY(csum_partial_copy_generic_from_user)
21181 +
21182 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21183 + pushl_cfi %gs
21184 + popl_cfi %ds
21185 +#endif
21186 +
21187 +ENTRY(csum_partial_copy_generic)
21188 subl $4,%esp
21189 CFI_ADJUST_CFA_OFFSET 4
21190 pushl_cfi %edi
21191 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
21192 jmp 4f
21193 SRC(1: movw (%esi), %bx )
21194 addl $2, %esi
21195 -DST( movw %bx, (%edi) )
21196 +DST( movw %bx, %es:(%edi) )
21197 addl $2, %edi
21198 addw %bx, %ax
21199 adcl $0, %eax
21200 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
21201 SRC(1: movl (%esi), %ebx )
21202 SRC( movl 4(%esi), %edx )
21203 adcl %ebx, %eax
21204 -DST( movl %ebx, (%edi) )
21205 +DST( movl %ebx, %es:(%edi) )
21206 adcl %edx, %eax
21207 -DST( movl %edx, 4(%edi) )
21208 +DST( movl %edx, %es:4(%edi) )
21209
21210 SRC( movl 8(%esi), %ebx )
21211 SRC( movl 12(%esi), %edx )
21212 adcl %ebx, %eax
21213 -DST( movl %ebx, 8(%edi) )
21214 +DST( movl %ebx, %es:8(%edi) )
21215 adcl %edx, %eax
21216 -DST( movl %edx, 12(%edi) )
21217 +DST( movl %edx, %es:12(%edi) )
21218
21219 SRC( movl 16(%esi), %ebx )
21220 SRC( movl 20(%esi), %edx )
21221 adcl %ebx, %eax
21222 -DST( movl %ebx, 16(%edi) )
21223 +DST( movl %ebx, %es:16(%edi) )
21224 adcl %edx, %eax
21225 -DST( movl %edx, 20(%edi) )
21226 +DST( movl %edx, %es:20(%edi) )
21227
21228 SRC( movl 24(%esi), %ebx )
21229 SRC( movl 28(%esi), %edx )
21230 adcl %ebx, %eax
21231 -DST( movl %ebx, 24(%edi) )
21232 +DST( movl %ebx, %es:24(%edi) )
21233 adcl %edx, %eax
21234 -DST( movl %edx, 28(%edi) )
21235 +DST( movl %edx, %es:28(%edi) )
21236
21237 lea 32(%esi), %esi
21238 lea 32(%edi), %edi
21239 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
21240 shrl $2, %edx # This clears CF
21241 SRC(3: movl (%esi), %ebx )
21242 adcl %ebx, %eax
21243 -DST( movl %ebx, (%edi) )
21244 +DST( movl %ebx, %es:(%edi) )
21245 lea 4(%esi), %esi
21246 lea 4(%edi), %edi
21247 dec %edx
21248 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
21249 jb 5f
21250 SRC( movw (%esi), %cx )
21251 leal 2(%esi), %esi
21252 -DST( movw %cx, (%edi) )
21253 +DST( movw %cx, %es:(%edi) )
21254 leal 2(%edi), %edi
21255 je 6f
21256 shll $16,%ecx
21257 SRC(5: movb (%esi), %cl )
21258 -DST( movb %cl, (%edi) )
21259 +DST( movb %cl, %es:(%edi) )
21260 6: addl %ecx, %eax
21261 adcl $0, %eax
21262 7:
21263 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
21264
21265 6001:
21266 movl ARGBASE+20(%esp), %ebx # src_err_ptr
21267 - movl $-EFAULT, (%ebx)
21268 + movl $-EFAULT, %ss:(%ebx)
21269
21270 # zero the complete destination - computing the rest
21271 # is too much work
21272 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
21273
21274 6002:
21275 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21276 - movl $-EFAULT,(%ebx)
21277 + movl $-EFAULT,%ss:(%ebx)
21278 jmp 5000b
21279
21280 .previous
21281
21282 + pushl_cfi %ss
21283 + popl_cfi %ds
21284 + pushl_cfi %ss
21285 + popl_cfi %es
21286 popl_cfi %ebx
21287 CFI_RESTORE ebx
21288 popl_cfi %esi
21289 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
21290 popl_cfi %ecx # equivalent to addl $4,%esp
21291 ret
21292 CFI_ENDPROC
21293 -ENDPROC(csum_partial_copy_generic)
21294 +ENDPROC(csum_partial_copy_generic_to_user)
21295
21296 #else
21297
21298 /* Version for PentiumII/PPro */
21299
21300 #define ROUND1(x) \
21301 + nop; nop; nop; \
21302 SRC(movl x(%esi), %ebx ) ; \
21303 addl %ebx, %eax ; \
21304 - DST(movl %ebx, x(%edi) ) ;
21305 + DST(movl %ebx, %es:x(%edi)) ;
21306
21307 #define ROUND(x) \
21308 + nop; nop; nop; \
21309 SRC(movl x(%esi), %ebx ) ; \
21310 adcl %ebx, %eax ; \
21311 - DST(movl %ebx, x(%edi) ) ;
21312 + DST(movl %ebx, %es:x(%edi)) ;
21313
21314 #define ARGBASE 12
21315 -
21316 -ENTRY(csum_partial_copy_generic)
21317 +
21318 +ENTRY(csum_partial_copy_generic_to_user)
21319 CFI_STARTPROC
21320 +
21321 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21322 + pushl_cfi %gs
21323 + popl_cfi %es
21324 + jmp csum_partial_copy_generic
21325 +#endif
21326 +
21327 +ENTRY(csum_partial_copy_generic_from_user)
21328 +
21329 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21330 + pushl_cfi %gs
21331 + popl_cfi %ds
21332 +#endif
21333 +
21334 +ENTRY(csum_partial_copy_generic)
21335 pushl_cfi %ebx
21336 CFI_REL_OFFSET ebx, 0
21337 pushl_cfi %edi
21338 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
21339 subl %ebx, %edi
21340 lea -1(%esi),%edx
21341 andl $-32,%edx
21342 - lea 3f(%ebx,%ebx), %ebx
21343 + lea 3f(%ebx,%ebx,2), %ebx
21344 testl %esi, %esi
21345 jmp *%ebx
21346 1: addl $64,%esi
21347 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
21348 jb 5f
21349 SRC( movw (%esi), %dx )
21350 leal 2(%esi), %esi
21351 -DST( movw %dx, (%edi) )
21352 +DST( movw %dx, %es:(%edi) )
21353 leal 2(%edi), %edi
21354 je 6f
21355 shll $16,%edx
21356 5:
21357 SRC( movb (%esi), %dl )
21358 -DST( movb %dl, (%edi) )
21359 +DST( movb %dl, %es:(%edi) )
21360 6: addl %edx, %eax
21361 adcl $0, %eax
21362 7:
21363 .section .fixup, "ax"
21364 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
21365 - movl $-EFAULT, (%ebx)
21366 + movl $-EFAULT, %ss:(%ebx)
21367 # zero the complete destination (computing the rest is too much work)
21368 movl ARGBASE+8(%esp),%edi # dst
21369 movl ARGBASE+12(%esp),%ecx # len
21370 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
21371 rep; stosb
21372 jmp 7b
21373 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
21374 - movl $-EFAULT, (%ebx)
21375 + movl $-EFAULT, %ss:(%ebx)
21376 jmp 7b
21377 .previous
21378
21379 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21380 + pushl_cfi %ss
21381 + popl_cfi %ds
21382 + pushl_cfi %ss
21383 + popl_cfi %es
21384 +#endif
21385 +
21386 popl_cfi %esi
21387 CFI_RESTORE esi
21388 popl_cfi %edi
21389 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
21390 CFI_RESTORE ebx
21391 ret
21392 CFI_ENDPROC
21393 -ENDPROC(csum_partial_copy_generic)
21394 +ENDPROC(csum_partial_copy_generic_to_user)
21395
21396 #undef ROUND
21397 #undef ROUND1
21398 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
21399 index f2145cf..cea889d 100644
21400 --- a/arch/x86/lib/clear_page_64.S
21401 +++ b/arch/x86/lib/clear_page_64.S
21402 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
21403 movl $4096/8,%ecx
21404 xorl %eax,%eax
21405 rep stosq
21406 + pax_force_retaddr
21407 ret
21408 CFI_ENDPROC
21409 ENDPROC(clear_page_c)
21410 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
21411 movl $4096,%ecx
21412 xorl %eax,%eax
21413 rep stosb
21414 + pax_force_retaddr
21415 ret
21416 CFI_ENDPROC
21417 ENDPROC(clear_page_c_e)
21418 @@ -43,6 +45,7 @@ ENTRY(clear_page)
21419 leaq 64(%rdi),%rdi
21420 jnz .Lloop
21421 nop
21422 + pax_force_retaddr
21423 ret
21424 CFI_ENDPROC
21425 .Lclear_page_end:
21426 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
21427
21428 #include <asm/cpufeature.h>
21429
21430 - .section .altinstr_replacement,"ax"
21431 + .section .altinstr_replacement,"a"
21432 1: .byte 0xeb /* jmp <disp8> */
21433 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
21434 2: .byte 0xeb /* jmp <disp8> */
21435 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
21436 index 1e572c5..2a162cd 100644
21437 --- a/arch/x86/lib/cmpxchg16b_emu.S
21438 +++ b/arch/x86/lib/cmpxchg16b_emu.S
21439 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
21440
21441 popf
21442 mov $1, %al
21443 + pax_force_retaddr
21444 ret
21445
21446 not_same:
21447 popf
21448 xor %al,%al
21449 + pax_force_retaddr
21450 ret
21451
21452 CFI_ENDPROC
21453 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
21454 index 6b34d04..dccb07f 100644
21455 --- a/arch/x86/lib/copy_page_64.S
21456 +++ b/arch/x86/lib/copy_page_64.S
21457 @@ -9,6 +9,7 @@ copy_page_c:
21458 CFI_STARTPROC
21459 movl $4096/8,%ecx
21460 rep movsq
21461 + pax_force_retaddr
21462 ret
21463 CFI_ENDPROC
21464 ENDPROC(copy_page_c)
21465 @@ -20,12 +21,14 @@ ENDPROC(copy_page_c)
21466
21467 ENTRY(copy_page)
21468 CFI_STARTPROC
21469 - subq $2*8,%rsp
21470 - CFI_ADJUST_CFA_OFFSET 2*8
21471 + subq $3*8,%rsp
21472 + CFI_ADJUST_CFA_OFFSET 3*8
21473 movq %rbx,(%rsp)
21474 CFI_REL_OFFSET rbx, 0
21475 movq %r12,1*8(%rsp)
21476 CFI_REL_OFFSET r12, 1*8
21477 + movq %r13,2*8(%rsp)
21478 + CFI_REL_OFFSET r13, 2*8
21479
21480 movl $(4096/64)-5,%ecx
21481 .p2align 4
21482 @@ -37,7 +40,7 @@ ENTRY(copy_page)
21483 movq 16 (%rsi), %rdx
21484 movq 24 (%rsi), %r8
21485 movq 32 (%rsi), %r9
21486 - movq 40 (%rsi), %r10
21487 + movq 40 (%rsi), %r13
21488 movq 48 (%rsi), %r11
21489 movq 56 (%rsi), %r12
21490
21491 @@ -48,7 +51,7 @@ ENTRY(copy_page)
21492 movq %rdx, 16 (%rdi)
21493 movq %r8, 24 (%rdi)
21494 movq %r9, 32 (%rdi)
21495 - movq %r10, 40 (%rdi)
21496 + movq %r13, 40 (%rdi)
21497 movq %r11, 48 (%rdi)
21498 movq %r12, 56 (%rdi)
21499
21500 @@ -67,7 +70,7 @@ ENTRY(copy_page)
21501 movq 16 (%rsi), %rdx
21502 movq 24 (%rsi), %r8
21503 movq 32 (%rsi), %r9
21504 - movq 40 (%rsi), %r10
21505 + movq 40 (%rsi), %r13
21506 movq 48 (%rsi), %r11
21507 movq 56 (%rsi), %r12
21508
21509 @@ -76,7 +79,7 @@ ENTRY(copy_page)
21510 movq %rdx, 16 (%rdi)
21511 movq %r8, 24 (%rdi)
21512 movq %r9, 32 (%rdi)
21513 - movq %r10, 40 (%rdi)
21514 + movq %r13, 40 (%rdi)
21515 movq %r11, 48 (%rdi)
21516 movq %r12, 56 (%rdi)
21517
21518 @@ -89,8 +92,11 @@ ENTRY(copy_page)
21519 CFI_RESTORE rbx
21520 movq 1*8(%rsp),%r12
21521 CFI_RESTORE r12
21522 - addq $2*8,%rsp
21523 - CFI_ADJUST_CFA_OFFSET -2*8
21524 + movq 2*8(%rsp),%r13
21525 + CFI_RESTORE r13
21526 + addq $3*8,%rsp
21527 + CFI_ADJUST_CFA_OFFSET -3*8
21528 + pax_force_retaddr
21529 ret
21530 .Lcopy_page_end:
21531 CFI_ENDPROC
21532 @@ -101,7 +107,7 @@ ENDPROC(copy_page)
21533
21534 #include <asm/cpufeature.h>
21535
21536 - .section .altinstr_replacement,"ax"
21537 + .section .altinstr_replacement,"a"
21538 1: .byte 0xeb /* jmp <disp8> */
21539 .byte (copy_page_c - copy_page) - (2f - 1b) /* offset */
21540 2:
21541 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
21542 index 5b2995f..78e7644 100644
21543 --- a/arch/x86/lib/copy_user_64.S
21544 +++ b/arch/x86/lib/copy_user_64.S
21545 @@ -17,6 +17,7 @@
21546 #include <asm/cpufeature.h>
21547 #include <asm/alternative-asm.h>
21548 #include <asm/asm.h>
21549 +#include <asm/pgtable.h>
21550
21551 /*
21552 * By placing feature2 after feature1 in altinstructions section, we logically
21553 @@ -30,7 +31,7 @@
21554 .byte 0xe9 /* 32bit jump */
21555 .long \orig-1f /* by default jump to orig */
21556 1:
21557 - .section .altinstr_replacement,"ax"
21558 + .section .altinstr_replacement,"a"
21559 2: .byte 0xe9 /* near jump with 32bit immediate */
21560 .long \alt1-1b /* offset */ /* or alternatively to alt1 */
21561 3: .byte 0xe9 /* near jump with 32bit immediate */
21562 @@ -69,47 +70,20 @@
21563 #endif
21564 .endm
21565
21566 -/* Standard copy_to_user with segment limit checking */
21567 -ENTRY(_copy_to_user)
21568 - CFI_STARTPROC
21569 - GET_THREAD_INFO(%rax)
21570 - movq %rdi,%rcx
21571 - addq %rdx,%rcx
21572 - jc bad_to_user
21573 - cmpq TI_addr_limit(%rax),%rcx
21574 - ja bad_to_user
21575 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21576 - copy_user_generic_unrolled,copy_user_generic_string, \
21577 - copy_user_enhanced_fast_string
21578 - CFI_ENDPROC
21579 -ENDPROC(_copy_to_user)
21580 -
21581 -/* Standard copy_from_user with segment limit checking */
21582 -ENTRY(_copy_from_user)
21583 - CFI_STARTPROC
21584 - GET_THREAD_INFO(%rax)
21585 - movq %rsi,%rcx
21586 - addq %rdx,%rcx
21587 - jc bad_from_user
21588 - cmpq TI_addr_limit(%rax),%rcx
21589 - ja bad_from_user
21590 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
21591 - copy_user_generic_unrolled,copy_user_generic_string, \
21592 - copy_user_enhanced_fast_string
21593 - CFI_ENDPROC
21594 -ENDPROC(_copy_from_user)
21595 -
21596 .section .fixup,"ax"
21597 /* must zero dest */
21598 ENTRY(bad_from_user)
21599 bad_from_user:
21600 CFI_STARTPROC
21601 + testl %edx,%edx
21602 + js bad_to_user
21603 movl %edx,%ecx
21604 xorl %eax,%eax
21605 rep
21606 stosb
21607 bad_to_user:
21608 movl %edx,%eax
21609 + pax_force_retaddr
21610 ret
21611 CFI_ENDPROC
21612 ENDPROC(bad_from_user)
21613 @@ -139,19 +113,19 @@ ENTRY(copy_user_generic_unrolled)
21614 jz 17f
21615 1: movq (%rsi),%r8
21616 2: movq 1*8(%rsi),%r9
21617 -3: movq 2*8(%rsi),%r10
21618 +3: movq 2*8(%rsi),%rax
21619 4: movq 3*8(%rsi),%r11
21620 5: movq %r8,(%rdi)
21621 6: movq %r9,1*8(%rdi)
21622 -7: movq %r10,2*8(%rdi)
21623 +7: movq %rax,2*8(%rdi)
21624 8: movq %r11,3*8(%rdi)
21625 9: movq 4*8(%rsi),%r8
21626 10: movq 5*8(%rsi),%r9
21627 -11: movq 6*8(%rsi),%r10
21628 +11: movq 6*8(%rsi),%rax
21629 12: movq 7*8(%rsi),%r11
21630 13: movq %r8,4*8(%rdi)
21631 14: movq %r9,5*8(%rdi)
21632 -15: movq %r10,6*8(%rdi)
21633 +15: movq %rax,6*8(%rdi)
21634 16: movq %r11,7*8(%rdi)
21635 leaq 64(%rsi),%rsi
21636 leaq 64(%rdi),%rdi
21637 @@ -177,6 +151,7 @@ ENTRY(copy_user_generic_unrolled)
21638 decl %ecx
21639 jnz 21b
21640 23: xor %eax,%eax
21641 + pax_force_retaddr
21642 ret
21643
21644 .section .fixup,"ax"
21645 @@ -246,6 +221,7 @@ ENTRY(copy_user_generic_string)
21646 3: rep
21647 movsb
21648 4: xorl %eax,%eax
21649 + pax_force_retaddr
21650 ret
21651
21652 .section .fixup,"ax"
21653 @@ -279,6 +255,7 @@ ENTRY(copy_user_enhanced_fast_string)
21654 1: rep
21655 movsb
21656 2: xorl %eax,%eax
21657 + pax_force_retaddr
21658 ret
21659
21660 .section .fixup,"ax"
21661 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
21662 index cacddc7..09d49e4 100644
21663 --- a/arch/x86/lib/copy_user_nocache_64.S
21664 +++ b/arch/x86/lib/copy_user_nocache_64.S
21665 @@ -8,6 +8,7 @@
21666
21667 #include <linux/linkage.h>
21668 #include <asm/dwarf2.h>
21669 +#include <asm/alternative-asm.h>
21670
21671 #define FIX_ALIGNMENT 1
21672
21673 @@ -15,6 +16,7 @@
21674 #include <asm/asm-offsets.h>
21675 #include <asm/thread_info.h>
21676 #include <asm/asm.h>
21677 +#include <asm/pgtable.h>
21678
21679 .macro ALIGN_DESTINATION
21680 #ifdef FIX_ALIGNMENT
21681 @@ -48,6 +50,15 @@
21682 */
21683 ENTRY(__copy_user_nocache)
21684 CFI_STARTPROC
21685 +
21686 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21687 + mov $PAX_USER_SHADOW_BASE,%rcx
21688 + cmp %rcx,%rsi
21689 + jae 1f
21690 + add %rcx,%rsi
21691 +1:
21692 +#endif
21693 +
21694 cmpl $8,%edx
21695 jb 20f /* less then 8 bytes, go to byte copy loop */
21696 ALIGN_DESTINATION
21697 @@ -57,19 +68,19 @@ ENTRY(__copy_user_nocache)
21698 jz 17f
21699 1: movq (%rsi),%r8
21700 2: movq 1*8(%rsi),%r9
21701 -3: movq 2*8(%rsi),%r10
21702 +3: movq 2*8(%rsi),%rax
21703 4: movq 3*8(%rsi),%r11
21704 5: movnti %r8,(%rdi)
21705 6: movnti %r9,1*8(%rdi)
21706 -7: movnti %r10,2*8(%rdi)
21707 +7: movnti %rax,2*8(%rdi)
21708 8: movnti %r11,3*8(%rdi)
21709 9: movq 4*8(%rsi),%r8
21710 10: movq 5*8(%rsi),%r9
21711 -11: movq 6*8(%rsi),%r10
21712 +11: movq 6*8(%rsi),%rax
21713 12: movq 7*8(%rsi),%r11
21714 13: movnti %r8,4*8(%rdi)
21715 14: movnti %r9,5*8(%rdi)
21716 -15: movnti %r10,6*8(%rdi)
21717 +15: movnti %rax,6*8(%rdi)
21718 16: movnti %r11,7*8(%rdi)
21719 leaq 64(%rsi),%rsi
21720 leaq 64(%rdi),%rdi
21721 @@ -96,6 +107,7 @@ ENTRY(__copy_user_nocache)
21722 jnz 21b
21723 23: xorl %eax,%eax
21724 sfence
21725 + pax_force_retaddr
21726 ret
21727
21728 .section .fixup,"ax"
21729 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
21730 index 2419d5f..953ee51 100644
21731 --- a/arch/x86/lib/csum-copy_64.S
21732 +++ b/arch/x86/lib/csum-copy_64.S
21733 @@ -9,6 +9,7 @@
21734 #include <asm/dwarf2.h>
21735 #include <asm/errno.h>
21736 #include <asm/asm.h>
21737 +#include <asm/alternative-asm.h>
21738
21739 /*
21740 * Checksum copy with exception handling.
21741 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
21742 CFI_RESTORE rbp
21743 addq $7*8, %rsp
21744 CFI_ADJUST_CFA_OFFSET -7*8
21745 + pax_force_retaddr 0, 1
21746 ret
21747 CFI_RESTORE_STATE
21748
21749 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
21750 index 25b7ae8..3b52ccd 100644
21751 --- a/arch/x86/lib/csum-wrappers_64.c
21752 +++ b/arch/x86/lib/csum-wrappers_64.c
21753 @@ -52,7 +52,13 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
21754 len -= 2;
21755 }
21756 }
21757 - isum = csum_partial_copy_generic((__force const void *)src,
21758 +
21759 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21760 + if ((unsigned long)src < PAX_USER_SHADOW_BASE)
21761 + src += PAX_USER_SHADOW_BASE;
21762 +#endif
21763 +
21764 + isum = csum_partial_copy_generic((const void __force_kernel *)src,
21765 dst, len, isum, errp, NULL);
21766 if (unlikely(*errp))
21767 goto out_err;
21768 @@ -105,7 +111,13 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
21769 }
21770
21771 *errp = 0;
21772 - return csum_partial_copy_generic(src, (void __force *)dst,
21773 +
21774 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21775 + if ((unsigned long)dst < PAX_USER_SHADOW_BASE)
21776 + dst += PAX_USER_SHADOW_BASE;
21777 +#endif
21778 +
21779 + return csum_partial_copy_generic(src, (void __force_kernel *)dst,
21780 len, isum, NULL, errp);
21781 }
21782 EXPORT_SYMBOL(csum_partial_copy_to_user);
21783 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
21784 index b33b1fb..219f389 100644
21785 --- a/arch/x86/lib/getuser.S
21786 +++ b/arch/x86/lib/getuser.S
21787 @@ -33,15 +33,38 @@
21788 #include <asm/asm-offsets.h>
21789 #include <asm/thread_info.h>
21790 #include <asm/asm.h>
21791 +#include <asm/segment.h>
21792 +#include <asm/pgtable.h>
21793 +#include <asm/alternative-asm.h>
21794 +
21795 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
21796 +#define __copyuser_seg gs;
21797 +#else
21798 +#define __copyuser_seg
21799 +#endif
21800
21801 .text
21802 ENTRY(__get_user_1)
21803 CFI_STARTPROC
21804 +
21805 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21806 GET_THREAD_INFO(%_ASM_DX)
21807 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21808 jae bad_get_user
21809 -1: movzb (%_ASM_AX),%edx
21810 +
21811 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21812 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21813 + cmp %_ASM_DX,%_ASM_AX
21814 + jae 1234f
21815 + add %_ASM_DX,%_ASM_AX
21816 +1234:
21817 +#endif
21818 +
21819 +#endif
21820 +
21821 +1: __copyuser_seg movzb (%_ASM_AX),%edx
21822 xor %eax,%eax
21823 + pax_force_retaddr
21824 ret
21825 CFI_ENDPROC
21826 ENDPROC(__get_user_1)
21827 @@ -49,12 +72,26 @@ ENDPROC(__get_user_1)
21828 ENTRY(__get_user_2)
21829 CFI_STARTPROC
21830 add $1,%_ASM_AX
21831 +
21832 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21833 jc bad_get_user
21834 GET_THREAD_INFO(%_ASM_DX)
21835 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21836 jae bad_get_user
21837 -2: movzwl -1(%_ASM_AX),%edx
21838 +
21839 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21840 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21841 + cmp %_ASM_DX,%_ASM_AX
21842 + jae 1234f
21843 + add %_ASM_DX,%_ASM_AX
21844 +1234:
21845 +#endif
21846 +
21847 +#endif
21848 +
21849 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
21850 xor %eax,%eax
21851 + pax_force_retaddr
21852 ret
21853 CFI_ENDPROC
21854 ENDPROC(__get_user_2)
21855 @@ -62,12 +99,26 @@ ENDPROC(__get_user_2)
21856 ENTRY(__get_user_4)
21857 CFI_STARTPROC
21858 add $3,%_ASM_AX
21859 +
21860 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
21861 jc bad_get_user
21862 GET_THREAD_INFO(%_ASM_DX)
21863 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21864 jae bad_get_user
21865 -3: mov -3(%_ASM_AX),%edx
21866 +
21867 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
21868 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21869 + cmp %_ASM_DX,%_ASM_AX
21870 + jae 1234f
21871 + add %_ASM_DX,%_ASM_AX
21872 +1234:
21873 +#endif
21874 +
21875 +#endif
21876 +
21877 +3: __copyuser_seg mov -3(%_ASM_AX),%edx
21878 xor %eax,%eax
21879 + pax_force_retaddr
21880 ret
21881 CFI_ENDPROC
21882 ENDPROC(__get_user_4)
21883 @@ -80,8 +131,18 @@ ENTRY(__get_user_8)
21884 GET_THREAD_INFO(%_ASM_DX)
21885 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
21886 jae bad_get_user
21887 +
21888 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21889 + mov $PAX_USER_SHADOW_BASE,%_ASM_DX
21890 + cmp %_ASM_DX,%_ASM_AX
21891 + jae 1234f
21892 + add %_ASM_DX,%_ASM_AX
21893 +1234:
21894 +#endif
21895 +
21896 4: movq -7(%_ASM_AX),%_ASM_DX
21897 xor %eax,%eax
21898 + pax_force_retaddr
21899 ret
21900 CFI_ENDPROC
21901 ENDPROC(__get_user_8)
21902 @@ -91,6 +152,7 @@ bad_get_user:
21903 CFI_STARTPROC
21904 xor %edx,%edx
21905 mov $(-EFAULT),%_ASM_AX
21906 + pax_force_retaddr
21907 ret
21908 CFI_ENDPROC
21909 END(bad_get_user)
21910 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
21911 index b1e6c4b..21ae8fc 100644
21912 --- a/arch/x86/lib/insn.c
21913 +++ b/arch/x86/lib/insn.c
21914 @@ -21,6 +21,11 @@
21915 #include <linux/string.h>
21916 #include <asm/inat.h>
21917 #include <asm/insn.h>
21918 +#ifdef __KERNEL__
21919 +#include <asm/pgtable_types.h>
21920 +#else
21921 +#define ktla_ktva(addr) addr
21922 +#endif
21923
21924 /* Verify next sizeof(t) bytes can be on the same instruction */
21925 #define validate_next(t, insn, n) \
21926 @@ -49,8 +54,8 @@
21927 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
21928 {
21929 memset(insn, 0, sizeof(*insn));
21930 - insn->kaddr = kaddr;
21931 - insn->next_byte = kaddr;
21932 + insn->kaddr = ktla_ktva(kaddr);
21933 + insn->next_byte = ktla_ktva(kaddr);
21934 insn->x86_64 = x86_64 ? 1 : 0;
21935 insn->opnd_bytes = 4;
21936 if (x86_64)
21937 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
21938 index 05a95e7..326f2fa 100644
21939 --- a/arch/x86/lib/iomap_copy_64.S
21940 +++ b/arch/x86/lib/iomap_copy_64.S
21941 @@ -17,6 +17,7 @@
21942
21943 #include <linux/linkage.h>
21944 #include <asm/dwarf2.h>
21945 +#include <asm/alternative-asm.h>
21946
21947 /*
21948 * override generic version in lib/iomap_copy.c
21949 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
21950 CFI_STARTPROC
21951 movl %edx,%ecx
21952 rep movsd
21953 + pax_force_retaddr
21954 ret
21955 CFI_ENDPROC
21956 ENDPROC(__iowrite32_copy)
21957 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
21958 index 1c273be..da9cc0e 100644
21959 --- a/arch/x86/lib/memcpy_64.S
21960 +++ b/arch/x86/lib/memcpy_64.S
21961 @@ -33,6 +33,7 @@
21962 rep movsq
21963 movl %edx, %ecx
21964 rep movsb
21965 + pax_force_retaddr
21966 ret
21967 .Lmemcpy_e:
21968 .previous
21969 @@ -49,6 +50,7 @@
21970 movq %rdi, %rax
21971 movq %rdx, %rcx
21972 rep movsb
21973 + pax_force_retaddr
21974 ret
21975 .Lmemcpy_e_e:
21976 .previous
21977 @@ -76,13 +78,13 @@ ENTRY(memcpy)
21978 */
21979 movq 0*8(%rsi), %r8
21980 movq 1*8(%rsi), %r9
21981 - movq 2*8(%rsi), %r10
21982 + movq 2*8(%rsi), %rcx
21983 movq 3*8(%rsi), %r11
21984 leaq 4*8(%rsi), %rsi
21985
21986 movq %r8, 0*8(%rdi)
21987 movq %r9, 1*8(%rdi)
21988 - movq %r10, 2*8(%rdi)
21989 + movq %rcx, 2*8(%rdi)
21990 movq %r11, 3*8(%rdi)
21991 leaq 4*8(%rdi), %rdi
21992 jae .Lcopy_forward_loop
21993 @@ -105,12 +107,12 @@ ENTRY(memcpy)
21994 subq $0x20, %rdx
21995 movq -1*8(%rsi), %r8
21996 movq -2*8(%rsi), %r9
21997 - movq -3*8(%rsi), %r10
21998 + movq -3*8(%rsi), %rcx
21999 movq -4*8(%rsi), %r11
22000 leaq -4*8(%rsi), %rsi
22001 movq %r8, -1*8(%rdi)
22002 movq %r9, -2*8(%rdi)
22003 - movq %r10, -3*8(%rdi)
22004 + movq %rcx, -3*8(%rdi)
22005 movq %r11, -4*8(%rdi)
22006 leaq -4*8(%rdi), %rdi
22007 jae .Lcopy_backward_loop
22008 @@ -130,12 +132,13 @@ ENTRY(memcpy)
22009 */
22010 movq 0*8(%rsi), %r8
22011 movq 1*8(%rsi), %r9
22012 - movq -2*8(%rsi, %rdx), %r10
22013 + movq -2*8(%rsi, %rdx), %rcx
22014 movq -1*8(%rsi, %rdx), %r11
22015 movq %r8, 0*8(%rdi)
22016 movq %r9, 1*8(%rdi)
22017 - movq %r10, -2*8(%rdi, %rdx)
22018 + movq %rcx, -2*8(%rdi, %rdx)
22019 movq %r11, -1*8(%rdi, %rdx)
22020 + pax_force_retaddr
22021 retq
22022 .p2align 4
22023 .Lless_16bytes:
22024 @@ -148,6 +151,7 @@ ENTRY(memcpy)
22025 movq -1*8(%rsi, %rdx), %r9
22026 movq %r8, 0*8(%rdi)
22027 movq %r9, -1*8(%rdi, %rdx)
22028 + pax_force_retaddr
22029 retq
22030 .p2align 4
22031 .Lless_8bytes:
22032 @@ -161,6 +165,7 @@ ENTRY(memcpy)
22033 movl -4(%rsi, %rdx), %r8d
22034 movl %ecx, (%rdi)
22035 movl %r8d, -4(%rdi, %rdx)
22036 + pax_force_retaddr
22037 retq
22038 .p2align 4
22039 .Lless_3bytes:
22040 @@ -179,6 +184,7 @@ ENTRY(memcpy)
22041 movb %cl, (%rdi)
22042
22043 .Lend:
22044 + pax_force_retaddr
22045 retq
22046 CFI_ENDPROC
22047 ENDPROC(memcpy)
22048 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
22049 index ee16461..c39c199 100644
22050 --- a/arch/x86/lib/memmove_64.S
22051 +++ b/arch/x86/lib/memmove_64.S
22052 @@ -61,13 +61,13 @@ ENTRY(memmove)
22053 5:
22054 sub $0x20, %rdx
22055 movq 0*8(%rsi), %r11
22056 - movq 1*8(%rsi), %r10
22057 + movq 1*8(%rsi), %rcx
22058 movq 2*8(%rsi), %r9
22059 movq 3*8(%rsi), %r8
22060 leaq 4*8(%rsi), %rsi
22061
22062 movq %r11, 0*8(%rdi)
22063 - movq %r10, 1*8(%rdi)
22064 + movq %rcx, 1*8(%rdi)
22065 movq %r9, 2*8(%rdi)
22066 movq %r8, 3*8(%rdi)
22067 leaq 4*8(%rdi), %rdi
22068 @@ -81,10 +81,10 @@ ENTRY(memmove)
22069 4:
22070 movq %rdx, %rcx
22071 movq -8(%rsi, %rdx), %r11
22072 - lea -8(%rdi, %rdx), %r10
22073 + lea -8(%rdi, %rdx), %r9
22074 shrq $3, %rcx
22075 rep movsq
22076 - movq %r11, (%r10)
22077 + movq %r11, (%r9)
22078 jmp 13f
22079 .Lmemmove_end_forward:
22080
22081 @@ -95,14 +95,14 @@ ENTRY(memmove)
22082 7:
22083 movq %rdx, %rcx
22084 movq (%rsi), %r11
22085 - movq %rdi, %r10
22086 + movq %rdi, %r9
22087 leaq -8(%rsi, %rdx), %rsi
22088 leaq -8(%rdi, %rdx), %rdi
22089 shrq $3, %rcx
22090 std
22091 rep movsq
22092 cld
22093 - movq %r11, (%r10)
22094 + movq %r11, (%r9)
22095 jmp 13f
22096
22097 /*
22098 @@ -127,13 +127,13 @@ ENTRY(memmove)
22099 8:
22100 subq $0x20, %rdx
22101 movq -1*8(%rsi), %r11
22102 - movq -2*8(%rsi), %r10
22103 + movq -2*8(%rsi), %rcx
22104 movq -3*8(%rsi), %r9
22105 movq -4*8(%rsi), %r8
22106 leaq -4*8(%rsi), %rsi
22107
22108 movq %r11, -1*8(%rdi)
22109 - movq %r10, -2*8(%rdi)
22110 + movq %rcx, -2*8(%rdi)
22111 movq %r9, -3*8(%rdi)
22112 movq %r8, -4*8(%rdi)
22113 leaq -4*8(%rdi), %rdi
22114 @@ -151,11 +151,11 @@ ENTRY(memmove)
22115 * Move data from 16 bytes to 31 bytes.
22116 */
22117 movq 0*8(%rsi), %r11
22118 - movq 1*8(%rsi), %r10
22119 + movq 1*8(%rsi), %rcx
22120 movq -2*8(%rsi, %rdx), %r9
22121 movq -1*8(%rsi, %rdx), %r8
22122 movq %r11, 0*8(%rdi)
22123 - movq %r10, 1*8(%rdi)
22124 + movq %rcx, 1*8(%rdi)
22125 movq %r9, -2*8(%rdi, %rdx)
22126 movq %r8, -1*8(%rdi, %rdx)
22127 jmp 13f
22128 @@ -167,9 +167,9 @@ ENTRY(memmove)
22129 * Move data from 8 bytes to 15 bytes.
22130 */
22131 movq 0*8(%rsi), %r11
22132 - movq -1*8(%rsi, %rdx), %r10
22133 + movq -1*8(%rsi, %rdx), %r9
22134 movq %r11, 0*8(%rdi)
22135 - movq %r10, -1*8(%rdi, %rdx)
22136 + movq %r9, -1*8(%rdi, %rdx)
22137 jmp 13f
22138 10:
22139 cmpq $4, %rdx
22140 @@ -178,9 +178,9 @@ ENTRY(memmove)
22141 * Move data from 4 bytes to 7 bytes.
22142 */
22143 movl (%rsi), %r11d
22144 - movl -4(%rsi, %rdx), %r10d
22145 + movl -4(%rsi, %rdx), %r9d
22146 movl %r11d, (%rdi)
22147 - movl %r10d, -4(%rdi, %rdx)
22148 + movl %r9d, -4(%rdi, %rdx)
22149 jmp 13f
22150 11:
22151 cmp $2, %rdx
22152 @@ -189,9 +189,9 @@ ENTRY(memmove)
22153 * Move data from 2 bytes to 3 bytes.
22154 */
22155 movw (%rsi), %r11w
22156 - movw -2(%rsi, %rdx), %r10w
22157 + movw -2(%rsi, %rdx), %r9w
22158 movw %r11w, (%rdi)
22159 - movw %r10w, -2(%rdi, %rdx)
22160 + movw %r9w, -2(%rdi, %rdx)
22161 jmp 13f
22162 12:
22163 cmp $1, %rdx
22164 @@ -202,6 +202,7 @@ ENTRY(memmove)
22165 movb (%rsi), %r11b
22166 movb %r11b, (%rdi)
22167 13:
22168 + pax_force_retaddr
22169 retq
22170 CFI_ENDPROC
22171
22172 @@ -210,6 +211,7 @@ ENTRY(memmove)
22173 /* Forward moving data. */
22174 movq %rdx, %rcx
22175 rep movsb
22176 + pax_force_retaddr
22177 retq
22178 .Lmemmove_end_forward_efs:
22179 .previous
22180 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
22181 index 2dcb380..963660a 100644
22182 --- a/arch/x86/lib/memset_64.S
22183 +++ b/arch/x86/lib/memset_64.S
22184 @@ -30,6 +30,7 @@
22185 movl %edx,%ecx
22186 rep stosb
22187 movq %r9,%rax
22188 + pax_force_retaddr
22189 ret
22190 .Lmemset_e:
22191 .previous
22192 @@ -52,6 +53,7 @@
22193 movq %rdx,%rcx
22194 rep stosb
22195 movq %r9,%rax
22196 + pax_force_retaddr
22197 ret
22198 .Lmemset_e_e:
22199 .previous
22200 @@ -59,7 +61,7 @@
22201 ENTRY(memset)
22202 ENTRY(__memset)
22203 CFI_STARTPROC
22204 - movq %rdi,%r10
22205 + movq %rdi,%r11
22206
22207 /* expand byte value */
22208 movzbl %sil,%ecx
22209 @@ -117,7 +119,8 @@ ENTRY(__memset)
22210 jnz .Lloop_1
22211
22212 .Lende:
22213 - movq %r10,%rax
22214 + movq %r11,%rax
22215 + pax_force_retaddr
22216 ret
22217
22218 CFI_RESTORE_STATE
22219 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
22220 index c9f2d9b..e7fd2c0 100644
22221 --- a/arch/x86/lib/mmx_32.c
22222 +++ b/arch/x86/lib/mmx_32.c
22223 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22224 {
22225 void *p;
22226 int i;
22227 + unsigned long cr0;
22228
22229 if (unlikely(in_interrupt()))
22230 return __memcpy(to, from, len);
22231 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
22232 kernel_fpu_begin();
22233
22234 __asm__ __volatile__ (
22235 - "1: prefetch (%0)\n" /* This set is 28 bytes */
22236 - " prefetch 64(%0)\n"
22237 - " prefetch 128(%0)\n"
22238 - " prefetch 192(%0)\n"
22239 - " prefetch 256(%0)\n"
22240 + "1: prefetch (%1)\n" /* This set is 28 bytes */
22241 + " prefetch 64(%1)\n"
22242 + " prefetch 128(%1)\n"
22243 + " prefetch 192(%1)\n"
22244 + " prefetch 256(%1)\n"
22245 "2: \n"
22246 ".section .fixup, \"ax\"\n"
22247 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22248 + "3: \n"
22249 +
22250 +#ifdef CONFIG_PAX_KERNEXEC
22251 + " movl %%cr0, %0\n"
22252 + " movl %0, %%eax\n"
22253 + " andl $0xFFFEFFFF, %%eax\n"
22254 + " movl %%eax, %%cr0\n"
22255 +#endif
22256 +
22257 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22258 +
22259 +#ifdef CONFIG_PAX_KERNEXEC
22260 + " movl %0, %%cr0\n"
22261 +#endif
22262 +
22263 " jmp 2b\n"
22264 ".previous\n"
22265 _ASM_EXTABLE(1b, 3b)
22266 - : : "r" (from));
22267 + : "=&r" (cr0) : "r" (from) : "ax");
22268
22269 for ( ; i > 5; i--) {
22270 __asm__ __volatile__ (
22271 - "1: prefetch 320(%0)\n"
22272 - "2: movq (%0), %%mm0\n"
22273 - " movq 8(%0), %%mm1\n"
22274 - " movq 16(%0), %%mm2\n"
22275 - " movq 24(%0), %%mm3\n"
22276 - " movq %%mm0, (%1)\n"
22277 - " movq %%mm1, 8(%1)\n"
22278 - " movq %%mm2, 16(%1)\n"
22279 - " movq %%mm3, 24(%1)\n"
22280 - " movq 32(%0), %%mm0\n"
22281 - " movq 40(%0), %%mm1\n"
22282 - " movq 48(%0), %%mm2\n"
22283 - " movq 56(%0), %%mm3\n"
22284 - " movq %%mm0, 32(%1)\n"
22285 - " movq %%mm1, 40(%1)\n"
22286 - " movq %%mm2, 48(%1)\n"
22287 - " movq %%mm3, 56(%1)\n"
22288 + "1: prefetch 320(%1)\n"
22289 + "2: movq (%1), %%mm0\n"
22290 + " movq 8(%1), %%mm1\n"
22291 + " movq 16(%1), %%mm2\n"
22292 + " movq 24(%1), %%mm3\n"
22293 + " movq %%mm0, (%2)\n"
22294 + " movq %%mm1, 8(%2)\n"
22295 + " movq %%mm2, 16(%2)\n"
22296 + " movq %%mm3, 24(%2)\n"
22297 + " movq 32(%1), %%mm0\n"
22298 + " movq 40(%1), %%mm1\n"
22299 + " movq 48(%1), %%mm2\n"
22300 + " movq 56(%1), %%mm3\n"
22301 + " movq %%mm0, 32(%2)\n"
22302 + " movq %%mm1, 40(%2)\n"
22303 + " movq %%mm2, 48(%2)\n"
22304 + " movq %%mm3, 56(%2)\n"
22305 ".section .fixup, \"ax\"\n"
22306 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22307 + "3:\n"
22308 +
22309 +#ifdef CONFIG_PAX_KERNEXEC
22310 + " movl %%cr0, %0\n"
22311 + " movl %0, %%eax\n"
22312 + " andl $0xFFFEFFFF, %%eax\n"
22313 + " movl %%eax, %%cr0\n"
22314 +#endif
22315 +
22316 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22317 +
22318 +#ifdef CONFIG_PAX_KERNEXEC
22319 + " movl %0, %%cr0\n"
22320 +#endif
22321 +
22322 " jmp 2b\n"
22323 ".previous\n"
22324 _ASM_EXTABLE(1b, 3b)
22325 - : : "r" (from), "r" (to) : "memory");
22326 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22327
22328 from += 64;
22329 to += 64;
22330 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
22331 static void fast_copy_page(void *to, void *from)
22332 {
22333 int i;
22334 + unsigned long cr0;
22335
22336 kernel_fpu_begin();
22337
22338 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
22339 * but that is for later. -AV
22340 */
22341 __asm__ __volatile__(
22342 - "1: prefetch (%0)\n"
22343 - " prefetch 64(%0)\n"
22344 - " prefetch 128(%0)\n"
22345 - " prefetch 192(%0)\n"
22346 - " prefetch 256(%0)\n"
22347 + "1: prefetch (%1)\n"
22348 + " prefetch 64(%1)\n"
22349 + " prefetch 128(%1)\n"
22350 + " prefetch 192(%1)\n"
22351 + " prefetch 256(%1)\n"
22352 "2: \n"
22353 ".section .fixup, \"ax\"\n"
22354 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22355 + "3: \n"
22356 +
22357 +#ifdef CONFIG_PAX_KERNEXEC
22358 + " movl %%cr0, %0\n"
22359 + " movl %0, %%eax\n"
22360 + " andl $0xFFFEFFFF, %%eax\n"
22361 + " movl %%eax, %%cr0\n"
22362 +#endif
22363 +
22364 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22365 +
22366 +#ifdef CONFIG_PAX_KERNEXEC
22367 + " movl %0, %%cr0\n"
22368 +#endif
22369 +
22370 " jmp 2b\n"
22371 ".previous\n"
22372 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22373 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22374
22375 for (i = 0; i < (4096-320)/64; i++) {
22376 __asm__ __volatile__ (
22377 - "1: prefetch 320(%0)\n"
22378 - "2: movq (%0), %%mm0\n"
22379 - " movntq %%mm0, (%1)\n"
22380 - " movq 8(%0), %%mm1\n"
22381 - " movntq %%mm1, 8(%1)\n"
22382 - " movq 16(%0), %%mm2\n"
22383 - " movntq %%mm2, 16(%1)\n"
22384 - " movq 24(%0), %%mm3\n"
22385 - " movntq %%mm3, 24(%1)\n"
22386 - " movq 32(%0), %%mm4\n"
22387 - " movntq %%mm4, 32(%1)\n"
22388 - " movq 40(%0), %%mm5\n"
22389 - " movntq %%mm5, 40(%1)\n"
22390 - " movq 48(%0), %%mm6\n"
22391 - " movntq %%mm6, 48(%1)\n"
22392 - " movq 56(%0), %%mm7\n"
22393 - " movntq %%mm7, 56(%1)\n"
22394 + "1: prefetch 320(%1)\n"
22395 + "2: movq (%1), %%mm0\n"
22396 + " movntq %%mm0, (%2)\n"
22397 + " movq 8(%1), %%mm1\n"
22398 + " movntq %%mm1, 8(%2)\n"
22399 + " movq 16(%1), %%mm2\n"
22400 + " movntq %%mm2, 16(%2)\n"
22401 + " movq 24(%1), %%mm3\n"
22402 + " movntq %%mm3, 24(%2)\n"
22403 + " movq 32(%1), %%mm4\n"
22404 + " movntq %%mm4, 32(%2)\n"
22405 + " movq 40(%1), %%mm5\n"
22406 + " movntq %%mm5, 40(%2)\n"
22407 + " movq 48(%1), %%mm6\n"
22408 + " movntq %%mm6, 48(%2)\n"
22409 + " movq 56(%1), %%mm7\n"
22410 + " movntq %%mm7, 56(%2)\n"
22411 ".section .fixup, \"ax\"\n"
22412 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22413 + "3:\n"
22414 +
22415 +#ifdef CONFIG_PAX_KERNEXEC
22416 + " movl %%cr0, %0\n"
22417 + " movl %0, %%eax\n"
22418 + " andl $0xFFFEFFFF, %%eax\n"
22419 + " movl %%eax, %%cr0\n"
22420 +#endif
22421 +
22422 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22423 +
22424 +#ifdef CONFIG_PAX_KERNEXEC
22425 + " movl %0, %%cr0\n"
22426 +#endif
22427 +
22428 " jmp 2b\n"
22429 ".previous\n"
22430 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
22431 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22432
22433 from += 64;
22434 to += 64;
22435 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
22436 static void fast_copy_page(void *to, void *from)
22437 {
22438 int i;
22439 + unsigned long cr0;
22440
22441 kernel_fpu_begin();
22442
22443 __asm__ __volatile__ (
22444 - "1: prefetch (%0)\n"
22445 - " prefetch 64(%0)\n"
22446 - " prefetch 128(%0)\n"
22447 - " prefetch 192(%0)\n"
22448 - " prefetch 256(%0)\n"
22449 + "1: prefetch (%1)\n"
22450 + " prefetch 64(%1)\n"
22451 + " prefetch 128(%1)\n"
22452 + " prefetch 192(%1)\n"
22453 + " prefetch 256(%1)\n"
22454 "2: \n"
22455 ".section .fixup, \"ax\"\n"
22456 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22457 + "3: \n"
22458 +
22459 +#ifdef CONFIG_PAX_KERNEXEC
22460 + " movl %%cr0, %0\n"
22461 + " movl %0, %%eax\n"
22462 + " andl $0xFFFEFFFF, %%eax\n"
22463 + " movl %%eax, %%cr0\n"
22464 +#endif
22465 +
22466 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
22467 +
22468 +#ifdef CONFIG_PAX_KERNEXEC
22469 + " movl %0, %%cr0\n"
22470 +#endif
22471 +
22472 " jmp 2b\n"
22473 ".previous\n"
22474 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
22475 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
22476
22477 for (i = 0; i < 4096/64; i++) {
22478 __asm__ __volatile__ (
22479 - "1: prefetch 320(%0)\n"
22480 - "2: movq (%0), %%mm0\n"
22481 - " movq 8(%0), %%mm1\n"
22482 - " movq 16(%0), %%mm2\n"
22483 - " movq 24(%0), %%mm3\n"
22484 - " movq %%mm0, (%1)\n"
22485 - " movq %%mm1, 8(%1)\n"
22486 - " movq %%mm2, 16(%1)\n"
22487 - " movq %%mm3, 24(%1)\n"
22488 - " movq 32(%0), %%mm0\n"
22489 - " movq 40(%0), %%mm1\n"
22490 - " movq 48(%0), %%mm2\n"
22491 - " movq 56(%0), %%mm3\n"
22492 - " movq %%mm0, 32(%1)\n"
22493 - " movq %%mm1, 40(%1)\n"
22494 - " movq %%mm2, 48(%1)\n"
22495 - " movq %%mm3, 56(%1)\n"
22496 + "1: prefetch 320(%1)\n"
22497 + "2: movq (%1), %%mm0\n"
22498 + " movq 8(%1), %%mm1\n"
22499 + " movq 16(%1), %%mm2\n"
22500 + " movq 24(%1), %%mm3\n"
22501 + " movq %%mm0, (%2)\n"
22502 + " movq %%mm1, 8(%2)\n"
22503 + " movq %%mm2, 16(%2)\n"
22504 + " movq %%mm3, 24(%2)\n"
22505 + " movq 32(%1), %%mm0\n"
22506 + " movq 40(%1), %%mm1\n"
22507 + " movq 48(%1), %%mm2\n"
22508 + " movq 56(%1), %%mm3\n"
22509 + " movq %%mm0, 32(%2)\n"
22510 + " movq %%mm1, 40(%2)\n"
22511 + " movq %%mm2, 48(%2)\n"
22512 + " movq %%mm3, 56(%2)\n"
22513 ".section .fixup, \"ax\"\n"
22514 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22515 + "3:\n"
22516 +
22517 +#ifdef CONFIG_PAX_KERNEXEC
22518 + " movl %%cr0, %0\n"
22519 + " movl %0, %%eax\n"
22520 + " andl $0xFFFEFFFF, %%eax\n"
22521 + " movl %%eax, %%cr0\n"
22522 +#endif
22523 +
22524 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
22525 +
22526 +#ifdef CONFIG_PAX_KERNEXEC
22527 + " movl %0, %%cr0\n"
22528 +#endif
22529 +
22530 " jmp 2b\n"
22531 ".previous\n"
22532 _ASM_EXTABLE(1b, 3b)
22533 - : : "r" (from), "r" (to) : "memory");
22534 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
22535
22536 from += 64;
22537 to += 64;
22538 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
22539 index 69fa106..adda88b 100644
22540 --- a/arch/x86/lib/msr-reg.S
22541 +++ b/arch/x86/lib/msr-reg.S
22542 @@ -3,6 +3,7 @@
22543 #include <asm/dwarf2.h>
22544 #include <asm/asm.h>
22545 #include <asm/msr.h>
22546 +#include <asm/alternative-asm.h>
22547
22548 #ifdef CONFIG_X86_64
22549 /*
22550 @@ -16,7 +17,7 @@ ENTRY(native_\op\()_safe_regs)
22551 CFI_STARTPROC
22552 pushq_cfi %rbx
22553 pushq_cfi %rbp
22554 - movq %rdi, %r10 /* Save pointer */
22555 + movq %rdi, %r9 /* Save pointer */
22556 xorl %r11d, %r11d /* Return value */
22557 movl (%rdi), %eax
22558 movl 4(%rdi), %ecx
22559 @@ -27,16 +28,17 @@ ENTRY(native_\op\()_safe_regs)
22560 movl 28(%rdi), %edi
22561 CFI_REMEMBER_STATE
22562 1: \op
22563 -2: movl %eax, (%r10)
22564 +2: movl %eax, (%r9)
22565 movl %r11d, %eax /* Return value */
22566 - movl %ecx, 4(%r10)
22567 - movl %edx, 8(%r10)
22568 - movl %ebx, 12(%r10)
22569 - movl %ebp, 20(%r10)
22570 - movl %esi, 24(%r10)
22571 - movl %edi, 28(%r10)
22572 + movl %ecx, 4(%r9)
22573 + movl %edx, 8(%r9)
22574 + movl %ebx, 12(%r9)
22575 + movl %ebp, 20(%r9)
22576 + movl %esi, 24(%r9)
22577 + movl %edi, 28(%r9)
22578 popq_cfi %rbp
22579 popq_cfi %rbx
22580 + pax_force_retaddr
22581 ret
22582 3:
22583 CFI_RESTORE_STATE
22584 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
22585 index 7f951c8..ebd573a 100644
22586 --- a/arch/x86/lib/putuser.S
22587 +++ b/arch/x86/lib/putuser.S
22588 @@ -15,7 +15,9 @@
22589 #include <asm/thread_info.h>
22590 #include <asm/errno.h>
22591 #include <asm/asm.h>
22592 -
22593 +#include <asm/segment.h>
22594 +#include <asm/pgtable.h>
22595 +#include <asm/alternative-asm.h>
22596
22597 /*
22598 * __put_user_X
22599 @@ -29,52 +31,119 @@
22600 * as they get called from within inline assembly.
22601 */
22602
22603 -#define ENTER CFI_STARTPROC ; \
22604 - GET_THREAD_INFO(%_ASM_BX)
22605 -#define EXIT ret ; \
22606 +#define ENTER CFI_STARTPROC
22607 +#define EXIT pax_force_retaddr; ret ; \
22608 CFI_ENDPROC
22609
22610 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22611 +#define _DEST %_ASM_CX,%_ASM_BX
22612 +#else
22613 +#define _DEST %_ASM_CX
22614 +#endif
22615 +
22616 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
22617 +#define __copyuser_seg gs;
22618 +#else
22619 +#define __copyuser_seg
22620 +#endif
22621 +
22622 .text
22623 ENTRY(__put_user_1)
22624 ENTER
22625 +
22626 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22627 + GET_THREAD_INFO(%_ASM_BX)
22628 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
22629 jae bad_put_user
22630 -1: movb %al,(%_ASM_CX)
22631 +
22632 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22633 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22634 + cmp %_ASM_BX,%_ASM_CX
22635 + jb 1234f
22636 + xor %ebx,%ebx
22637 +1234:
22638 +#endif
22639 +
22640 +#endif
22641 +
22642 +1: __copyuser_seg movb %al,(_DEST)
22643 xor %eax,%eax
22644 EXIT
22645 ENDPROC(__put_user_1)
22646
22647 ENTRY(__put_user_2)
22648 ENTER
22649 +
22650 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22651 + GET_THREAD_INFO(%_ASM_BX)
22652 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22653 sub $1,%_ASM_BX
22654 cmp %_ASM_BX,%_ASM_CX
22655 jae bad_put_user
22656 -2: movw %ax,(%_ASM_CX)
22657 +
22658 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22659 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22660 + cmp %_ASM_BX,%_ASM_CX
22661 + jb 1234f
22662 + xor %ebx,%ebx
22663 +1234:
22664 +#endif
22665 +
22666 +#endif
22667 +
22668 +2: __copyuser_seg movw %ax,(_DEST)
22669 xor %eax,%eax
22670 EXIT
22671 ENDPROC(__put_user_2)
22672
22673 ENTRY(__put_user_4)
22674 ENTER
22675 +
22676 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22677 + GET_THREAD_INFO(%_ASM_BX)
22678 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22679 sub $3,%_ASM_BX
22680 cmp %_ASM_BX,%_ASM_CX
22681 jae bad_put_user
22682 -3: movl %eax,(%_ASM_CX)
22683 +
22684 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22685 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22686 + cmp %_ASM_BX,%_ASM_CX
22687 + jb 1234f
22688 + xor %ebx,%ebx
22689 +1234:
22690 +#endif
22691 +
22692 +#endif
22693 +
22694 +3: __copyuser_seg movl %eax,(_DEST)
22695 xor %eax,%eax
22696 EXIT
22697 ENDPROC(__put_user_4)
22698
22699 ENTRY(__put_user_8)
22700 ENTER
22701 +
22702 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
22703 + GET_THREAD_INFO(%_ASM_BX)
22704 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
22705 sub $7,%_ASM_BX
22706 cmp %_ASM_BX,%_ASM_CX
22707 jae bad_put_user
22708 -4: mov %_ASM_AX,(%_ASM_CX)
22709 +
22710 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
22711 + mov $PAX_USER_SHADOW_BASE,%_ASM_BX
22712 + cmp %_ASM_BX,%_ASM_CX
22713 + jb 1234f
22714 + xor %ebx,%ebx
22715 +1234:
22716 +#endif
22717 +
22718 +#endif
22719 +
22720 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
22721 #ifdef CONFIG_X86_32
22722 -5: movl %edx,4(%_ASM_CX)
22723 +5: __copyuser_seg movl %edx,4(_DEST)
22724 #endif
22725 xor %eax,%eax
22726 EXIT
22727 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
22728 index 1cad221..de671ee 100644
22729 --- a/arch/x86/lib/rwlock.S
22730 +++ b/arch/x86/lib/rwlock.S
22731 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
22732 FRAME
22733 0: LOCK_PREFIX
22734 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22735 +
22736 +#ifdef CONFIG_PAX_REFCOUNT
22737 + jno 1234f
22738 + LOCK_PREFIX
22739 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22740 + int $4
22741 +1234:
22742 + _ASM_EXTABLE(1234b, 1234b)
22743 +#endif
22744 +
22745 1: rep; nop
22746 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
22747 jne 1b
22748 LOCK_PREFIX
22749 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
22750 +
22751 +#ifdef CONFIG_PAX_REFCOUNT
22752 + jno 1234f
22753 + LOCK_PREFIX
22754 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
22755 + int $4
22756 +1234:
22757 + _ASM_EXTABLE(1234b, 1234b)
22758 +#endif
22759 +
22760 jnz 0b
22761 ENDFRAME
22762 + pax_force_retaddr
22763 ret
22764 CFI_ENDPROC
22765 END(__write_lock_failed)
22766 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
22767 FRAME
22768 0: LOCK_PREFIX
22769 READ_LOCK_SIZE(inc) (%__lock_ptr)
22770 +
22771 +#ifdef CONFIG_PAX_REFCOUNT
22772 + jno 1234f
22773 + LOCK_PREFIX
22774 + READ_LOCK_SIZE(dec) (%__lock_ptr)
22775 + int $4
22776 +1234:
22777 + _ASM_EXTABLE(1234b, 1234b)
22778 +#endif
22779 +
22780 1: rep; nop
22781 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
22782 js 1b
22783 LOCK_PREFIX
22784 READ_LOCK_SIZE(dec) (%__lock_ptr)
22785 +
22786 +#ifdef CONFIG_PAX_REFCOUNT
22787 + jno 1234f
22788 + LOCK_PREFIX
22789 + READ_LOCK_SIZE(inc) (%__lock_ptr)
22790 + int $4
22791 +1234:
22792 + _ASM_EXTABLE(1234b, 1234b)
22793 +#endif
22794 +
22795 js 0b
22796 ENDFRAME
22797 + pax_force_retaddr
22798 ret
22799 CFI_ENDPROC
22800 END(__read_lock_failed)
22801 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
22802 index 5dff5f0..cadebf4 100644
22803 --- a/arch/x86/lib/rwsem.S
22804 +++ b/arch/x86/lib/rwsem.S
22805 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
22806 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22807 CFI_RESTORE __ASM_REG(dx)
22808 restore_common_regs
22809 + pax_force_retaddr
22810 ret
22811 CFI_ENDPROC
22812 ENDPROC(call_rwsem_down_read_failed)
22813 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
22814 movq %rax,%rdi
22815 call rwsem_down_write_failed
22816 restore_common_regs
22817 + pax_force_retaddr
22818 ret
22819 CFI_ENDPROC
22820 ENDPROC(call_rwsem_down_write_failed)
22821 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
22822 movq %rax,%rdi
22823 call rwsem_wake
22824 restore_common_regs
22825 -1: ret
22826 +1: pax_force_retaddr
22827 + ret
22828 CFI_ENDPROC
22829 ENDPROC(call_rwsem_wake)
22830
22831 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
22832 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
22833 CFI_RESTORE __ASM_REG(dx)
22834 restore_common_regs
22835 + pax_force_retaddr
22836 ret
22837 CFI_ENDPROC
22838 ENDPROC(call_rwsem_downgrade_wake)
22839 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
22840 index a63efd6..ccecad8 100644
22841 --- a/arch/x86/lib/thunk_64.S
22842 +++ b/arch/x86/lib/thunk_64.S
22843 @@ -8,6 +8,7 @@
22844 #include <linux/linkage.h>
22845 #include <asm/dwarf2.h>
22846 #include <asm/calling.h>
22847 +#include <asm/alternative-asm.h>
22848
22849 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
22850 .macro THUNK name, func, put_ret_addr_in_rdi=0
22851 @@ -41,5 +42,6 @@
22852 SAVE_ARGS
22853 restore:
22854 RESTORE_ARGS
22855 + pax_force_retaddr
22856 ret
22857 CFI_ENDPROC
22858 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
22859 index 1781b2f..90368dd 100644
22860 --- a/arch/x86/lib/usercopy_32.c
22861 +++ b/arch/x86/lib/usercopy_32.c
22862 @@ -42,10 +42,12 @@ do { \
22863 int __d0; \
22864 might_fault(); \
22865 __asm__ __volatile__( \
22866 + __COPYUSER_SET_ES \
22867 "0: rep; stosl\n" \
22868 " movl %2,%0\n" \
22869 "1: rep; stosb\n" \
22870 "2:\n" \
22871 + __COPYUSER_RESTORE_ES \
22872 ".section .fixup,\"ax\"\n" \
22873 "3: lea 0(%2,%0,4),%0\n" \
22874 " jmp 2b\n" \
22875 @@ -97,7 +99,7 @@ EXPORT_SYMBOL(__clear_user);
22876
22877 #ifdef CONFIG_X86_INTEL_USERCOPY
22878 static unsigned long
22879 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
22880 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
22881 {
22882 int d0, d1;
22883 __asm__ __volatile__(
22884 @@ -109,36 +111,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22885 " .align 2,0x90\n"
22886 "3: movl 0(%4), %%eax\n"
22887 "4: movl 4(%4), %%edx\n"
22888 - "5: movl %%eax, 0(%3)\n"
22889 - "6: movl %%edx, 4(%3)\n"
22890 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
22891 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
22892 "7: movl 8(%4), %%eax\n"
22893 "8: movl 12(%4),%%edx\n"
22894 - "9: movl %%eax, 8(%3)\n"
22895 - "10: movl %%edx, 12(%3)\n"
22896 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
22897 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
22898 "11: movl 16(%4), %%eax\n"
22899 "12: movl 20(%4), %%edx\n"
22900 - "13: movl %%eax, 16(%3)\n"
22901 - "14: movl %%edx, 20(%3)\n"
22902 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
22903 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
22904 "15: movl 24(%4), %%eax\n"
22905 "16: movl 28(%4), %%edx\n"
22906 - "17: movl %%eax, 24(%3)\n"
22907 - "18: movl %%edx, 28(%3)\n"
22908 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
22909 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
22910 "19: movl 32(%4), %%eax\n"
22911 "20: movl 36(%4), %%edx\n"
22912 - "21: movl %%eax, 32(%3)\n"
22913 - "22: movl %%edx, 36(%3)\n"
22914 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
22915 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
22916 "23: movl 40(%4), %%eax\n"
22917 "24: movl 44(%4), %%edx\n"
22918 - "25: movl %%eax, 40(%3)\n"
22919 - "26: movl %%edx, 44(%3)\n"
22920 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
22921 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
22922 "27: movl 48(%4), %%eax\n"
22923 "28: movl 52(%4), %%edx\n"
22924 - "29: movl %%eax, 48(%3)\n"
22925 - "30: movl %%edx, 52(%3)\n"
22926 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
22927 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
22928 "31: movl 56(%4), %%eax\n"
22929 "32: movl 60(%4), %%edx\n"
22930 - "33: movl %%eax, 56(%3)\n"
22931 - "34: movl %%edx, 60(%3)\n"
22932 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
22933 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
22934 " addl $-64, %0\n"
22935 " addl $64, %4\n"
22936 " addl $64, %3\n"
22937 @@ -148,10 +150,12 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22938 " shrl $2, %0\n"
22939 " andl $3, %%eax\n"
22940 " cld\n"
22941 + __COPYUSER_SET_ES
22942 "99: rep; movsl\n"
22943 "36: movl %%eax, %0\n"
22944 "37: rep; movsb\n"
22945 "100:\n"
22946 + __COPYUSER_RESTORE_ES
22947 ".section .fixup,\"ax\"\n"
22948 "101: lea 0(%%eax,%0,4),%0\n"
22949 " jmp 100b\n"
22950 @@ -201,46 +205,150 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
22951 }
22952
22953 static unsigned long
22954 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
22955 +{
22956 + int d0, d1;
22957 + __asm__ __volatile__(
22958 + " .align 2,0x90\n"
22959 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
22960 + " cmpl $67, %0\n"
22961 + " jbe 3f\n"
22962 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
22963 + " .align 2,0x90\n"
22964 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
22965 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
22966 + "5: movl %%eax, 0(%3)\n"
22967 + "6: movl %%edx, 4(%3)\n"
22968 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
22969 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
22970 + "9: movl %%eax, 8(%3)\n"
22971 + "10: movl %%edx, 12(%3)\n"
22972 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
22973 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
22974 + "13: movl %%eax, 16(%3)\n"
22975 + "14: movl %%edx, 20(%3)\n"
22976 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
22977 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
22978 + "17: movl %%eax, 24(%3)\n"
22979 + "18: movl %%edx, 28(%3)\n"
22980 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
22981 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
22982 + "21: movl %%eax, 32(%3)\n"
22983 + "22: movl %%edx, 36(%3)\n"
22984 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
22985 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
22986 + "25: movl %%eax, 40(%3)\n"
22987 + "26: movl %%edx, 44(%3)\n"
22988 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
22989 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
22990 + "29: movl %%eax, 48(%3)\n"
22991 + "30: movl %%edx, 52(%3)\n"
22992 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
22993 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
22994 + "33: movl %%eax, 56(%3)\n"
22995 + "34: movl %%edx, 60(%3)\n"
22996 + " addl $-64, %0\n"
22997 + " addl $64, %4\n"
22998 + " addl $64, %3\n"
22999 + " cmpl $63, %0\n"
23000 + " ja 1b\n"
23001 + "35: movl %0, %%eax\n"
23002 + " shrl $2, %0\n"
23003 + " andl $3, %%eax\n"
23004 + " cld\n"
23005 + "99: rep; "__copyuser_seg" movsl\n"
23006 + "36: movl %%eax, %0\n"
23007 + "37: rep; "__copyuser_seg" movsb\n"
23008 + "100:\n"
23009 + ".section .fixup,\"ax\"\n"
23010 + "101: lea 0(%%eax,%0,4),%0\n"
23011 + " jmp 100b\n"
23012 + ".previous\n"
23013 + _ASM_EXTABLE(1b,100b)
23014 + _ASM_EXTABLE(2b,100b)
23015 + _ASM_EXTABLE(3b,100b)
23016 + _ASM_EXTABLE(4b,100b)
23017 + _ASM_EXTABLE(5b,100b)
23018 + _ASM_EXTABLE(6b,100b)
23019 + _ASM_EXTABLE(7b,100b)
23020 + _ASM_EXTABLE(8b,100b)
23021 + _ASM_EXTABLE(9b,100b)
23022 + _ASM_EXTABLE(10b,100b)
23023 + _ASM_EXTABLE(11b,100b)
23024 + _ASM_EXTABLE(12b,100b)
23025 + _ASM_EXTABLE(13b,100b)
23026 + _ASM_EXTABLE(14b,100b)
23027 + _ASM_EXTABLE(15b,100b)
23028 + _ASM_EXTABLE(16b,100b)
23029 + _ASM_EXTABLE(17b,100b)
23030 + _ASM_EXTABLE(18b,100b)
23031 + _ASM_EXTABLE(19b,100b)
23032 + _ASM_EXTABLE(20b,100b)
23033 + _ASM_EXTABLE(21b,100b)
23034 + _ASM_EXTABLE(22b,100b)
23035 + _ASM_EXTABLE(23b,100b)
23036 + _ASM_EXTABLE(24b,100b)
23037 + _ASM_EXTABLE(25b,100b)
23038 + _ASM_EXTABLE(26b,100b)
23039 + _ASM_EXTABLE(27b,100b)
23040 + _ASM_EXTABLE(28b,100b)
23041 + _ASM_EXTABLE(29b,100b)
23042 + _ASM_EXTABLE(30b,100b)
23043 + _ASM_EXTABLE(31b,100b)
23044 + _ASM_EXTABLE(32b,100b)
23045 + _ASM_EXTABLE(33b,100b)
23046 + _ASM_EXTABLE(34b,100b)
23047 + _ASM_EXTABLE(35b,100b)
23048 + _ASM_EXTABLE(36b,100b)
23049 + _ASM_EXTABLE(37b,100b)
23050 + _ASM_EXTABLE(99b,101b)
23051 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
23052 + : "1"(to), "2"(from), "0"(size)
23053 + : "eax", "edx", "memory");
23054 + return size;
23055 +}
23056 +
23057 +static unsigned long __size_overflow(3)
23058 __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23059 {
23060 int d0, d1;
23061 __asm__ __volatile__(
23062 " .align 2,0x90\n"
23063 - "0: movl 32(%4), %%eax\n"
23064 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23065 " cmpl $67, %0\n"
23066 " jbe 2f\n"
23067 - "1: movl 64(%4), %%eax\n"
23068 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23069 " .align 2,0x90\n"
23070 - "2: movl 0(%4), %%eax\n"
23071 - "21: movl 4(%4), %%edx\n"
23072 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23073 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23074 " movl %%eax, 0(%3)\n"
23075 " movl %%edx, 4(%3)\n"
23076 - "3: movl 8(%4), %%eax\n"
23077 - "31: movl 12(%4),%%edx\n"
23078 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23079 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23080 " movl %%eax, 8(%3)\n"
23081 " movl %%edx, 12(%3)\n"
23082 - "4: movl 16(%4), %%eax\n"
23083 - "41: movl 20(%4), %%edx\n"
23084 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23085 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23086 " movl %%eax, 16(%3)\n"
23087 " movl %%edx, 20(%3)\n"
23088 - "10: movl 24(%4), %%eax\n"
23089 - "51: movl 28(%4), %%edx\n"
23090 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23091 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23092 " movl %%eax, 24(%3)\n"
23093 " movl %%edx, 28(%3)\n"
23094 - "11: movl 32(%4), %%eax\n"
23095 - "61: movl 36(%4), %%edx\n"
23096 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23097 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23098 " movl %%eax, 32(%3)\n"
23099 " movl %%edx, 36(%3)\n"
23100 - "12: movl 40(%4), %%eax\n"
23101 - "71: movl 44(%4), %%edx\n"
23102 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23103 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23104 " movl %%eax, 40(%3)\n"
23105 " movl %%edx, 44(%3)\n"
23106 - "13: movl 48(%4), %%eax\n"
23107 - "81: movl 52(%4), %%edx\n"
23108 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23109 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23110 " movl %%eax, 48(%3)\n"
23111 " movl %%edx, 52(%3)\n"
23112 - "14: movl 56(%4), %%eax\n"
23113 - "91: movl 60(%4), %%edx\n"
23114 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23115 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23116 " movl %%eax, 56(%3)\n"
23117 " movl %%edx, 60(%3)\n"
23118 " addl $-64, %0\n"
23119 @@ -252,9 +360,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23120 " shrl $2, %0\n"
23121 " andl $3, %%eax\n"
23122 " cld\n"
23123 - "6: rep; movsl\n"
23124 + "6: rep; "__copyuser_seg" movsl\n"
23125 " movl %%eax,%0\n"
23126 - "7: rep; movsb\n"
23127 + "7: rep; "__copyuser_seg" movsb\n"
23128 "8:\n"
23129 ".section .fixup,\"ax\"\n"
23130 "9: lea 0(%%eax,%0,4),%0\n"
23131 @@ -297,48 +405,48 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
23132 * hyoshiok@miraclelinux.com
23133 */
23134
23135 -static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23136 +static unsigned long __size_overflow(3) __copy_user_zeroing_intel_nocache(void *to,
23137 const void __user *from, unsigned long size)
23138 {
23139 int d0, d1;
23140
23141 __asm__ __volatile__(
23142 " .align 2,0x90\n"
23143 - "0: movl 32(%4), %%eax\n"
23144 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23145 " cmpl $67, %0\n"
23146 " jbe 2f\n"
23147 - "1: movl 64(%4), %%eax\n"
23148 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23149 " .align 2,0x90\n"
23150 - "2: movl 0(%4), %%eax\n"
23151 - "21: movl 4(%4), %%edx\n"
23152 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23153 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23154 " movnti %%eax, 0(%3)\n"
23155 " movnti %%edx, 4(%3)\n"
23156 - "3: movl 8(%4), %%eax\n"
23157 - "31: movl 12(%4),%%edx\n"
23158 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23159 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23160 " movnti %%eax, 8(%3)\n"
23161 " movnti %%edx, 12(%3)\n"
23162 - "4: movl 16(%4), %%eax\n"
23163 - "41: movl 20(%4), %%edx\n"
23164 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23165 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23166 " movnti %%eax, 16(%3)\n"
23167 " movnti %%edx, 20(%3)\n"
23168 - "10: movl 24(%4), %%eax\n"
23169 - "51: movl 28(%4), %%edx\n"
23170 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23171 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23172 " movnti %%eax, 24(%3)\n"
23173 " movnti %%edx, 28(%3)\n"
23174 - "11: movl 32(%4), %%eax\n"
23175 - "61: movl 36(%4), %%edx\n"
23176 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23177 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23178 " movnti %%eax, 32(%3)\n"
23179 " movnti %%edx, 36(%3)\n"
23180 - "12: movl 40(%4), %%eax\n"
23181 - "71: movl 44(%4), %%edx\n"
23182 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23183 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23184 " movnti %%eax, 40(%3)\n"
23185 " movnti %%edx, 44(%3)\n"
23186 - "13: movl 48(%4), %%eax\n"
23187 - "81: movl 52(%4), %%edx\n"
23188 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23189 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23190 " movnti %%eax, 48(%3)\n"
23191 " movnti %%edx, 52(%3)\n"
23192 - "14: movl 56(%4), %%eax\n"
23193 - "91: movl 60(%4), %%edx\n"
23194 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23195 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23196 " movnti %%eax, 56(%3)\n"
23197 " movnti %%edx, 60(%3)\n"
23198 " addl $-64, %0\n"
23199 @@ -351,9 +459,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23200 " shrl $2, %0\n"
23201 " andl $3, %%eax\n"
23202 " cld\n"
23203 - "6: rep; movsl\n"
23204 + "6: rep; "__copyuser_seg" movsl\n"
23205 " movl %%eax,%0\n"
23206 - "7: rep; movsb\n"
23207 + "7: rep; "__copyuser_seg" movsb\n"
23208 "8:\n"
23209 ".section .fixup,\"ax\"\n"
23210 "9: lea 0(%%eax,%0,4),%0\n"
23211 @@ -391,48 +499,48 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
23212 return size;
23213 }
23214
23215 -static unsigned long __copy_user_intel_nocache(void *to,
23216 +static unsigned long __size_overflow(3) __copy_user_intel_nocache(void *to,
23217 const void __user *from, unsigned long size)
23218 {
23219 int d0, d1;
23220
23221 __asm__ __volatile__(
23222 " .align 2,0x90\n"
23223 - "0: movl 32(%4), %%eax\n"
23224 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
23225 " cmpl $67, %0\n"
23226 " jbe 2f\n"
23227 - "1: movl 64(%4), %%eax\n"
23228 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
23229 " .align 2,0x90\n"
23230 - "2: movl 0(%4), %%eax\n"
23231 - "21: movl 4(%4), %%edx\n"
23232 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
23233 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
23234 " movnti %%eax, 0(%3)\n"
23235 " movnti %%edx, 4(%3)\n"
23236 - "3: movl 8(%4), %%eax\n"
23237 - "31: movl 12(%4),%%edx\n"
23238 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
23239 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
23240 " movnti %%eax, 8(%3)\n"
23241 " movnti %%edx, 12(%3)\n"
23242 - "4: movl 16(%4), %%eax\n"
23243 - "41: movl 20(%4), %%edx\n"
23244 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
23245 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
23246 " movnti %%eax, 16(%3)\n"
23247 " movnti %%edx, 20(%3)\n"
23248 - "10: movl 24(%4), %%eax\n"
23249 - "51: movl 28(%4), %%edx\n"
23250 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
23251 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
23252 " movnti %%eax, 24(%3)\n"
23253 " movnti %%edx, 28(%3)\n"
23254 - "11: movl 32(%4), %%eax\n"
23255 - "61: movl 36(%4), %%edx\n"
23256 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
23257 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
23258 " movnti %%eax, 32(%3)\n"
23259 " movnti %%edx, 36(%3)\n"
23260 - "12: movl 40(%4), %%eax\n"
23261 - "71: movl 44(%4), %%edx\n"
23262 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
23263 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
23264 " movnti %%eax, 40(%3)\n"
23265 " movnti %%edx, 44(%3)\n"
23266 - "13: movl 48(%4), %%eax\n"
23267 - "81: movl 52(%4), %%edx\n"
23268 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
23269 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
23270 " movnti %%eax, 48(%3)\n"
23271 " movnti %%edx, 52(%3)\n"
23272 - "14: movl 56(%4), %%eax\n"
23273 - "91: movl 60(%4), %%edx\n"
23274 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
23275 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
23276 " movnti %%eax, 56(%3)\n"
23277 " movnti %%edx, 60(%3)\n"
23278 " addl $-64, %0\n"
23279 @@ -445,9 +553,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
23280 " shrl $2, %0\n"
23281 " andl $3, %%eax\n"
23282 " cld\n"
23283 - "6: rep; movsl\n"
23284 + "6: rep; "__copyuser_seg" movsl\n"
23285 " movl %%eax,%0\n"
23286 - "7: rep; movsb\n"
23287 + "7: rep; "__copyuser_seg" movsb\n"
23288 "8:\n"
23289 ".section .fixup,\"ax\"\n"
23290 "9: lea 0(%%eax,%0,4),%0\n"
23291 @@ -487,32 +595,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
23292 */
23293 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
23294 unsigned long size);
23295 -unsigned long __copy_user_intel(void __user *to, const void *from,
23296 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
23297 + unsigned long size);
23298 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
23299 unsigned long size);
23300 unsigned long __copy_user_zeroing_intel_nocache(void *to,
23301 const void __user *from, unsigned long size);
23302 #endif /* CONFIG_X86_INTEL_USERCOPY */
23303
23304 /* Generic arbitrary sized copy. */
23305 -#define __copy_user(to, from, size) \
23306 +#define __copy_user(to, from, size, prefix, set, restore) \
23307 do { \
23308 int __d0, __d1, __d2; \
23309 __asm__ __volatile__( \
23310 + set \
23311 " cmp $7,%0\n" \
23312 " jbe 1f\n" \
23313 " movl %1,%0\n" \
23314 " negl %0\n" \
23315 " andl $7,%0\n" \
23316 " subl %0,%3\n" \
23317 - "4: rep; movsb\n" \
23318 + "4: rep; "prefix"movsb\n" \
23319 " movl %3,%0\n" \
23320 " shrl $2,%0\n" \
23321 " andl $3,%3\n" \
23322 " .align 2,0x90\n" \
23323 - "0: rep; movsl\n" \
23324 + "0: rep; "prefix"movsl\n" \
23325 " movl %3,%0\n" \
23326 - "1: rep; movsb\n" \
23327 + "1: rep; "prefix"movsb\n" \
23328 "2:\n" \
23329 + restore \
23330 ".section .fixup,\"ax\"\n" \
23331 "5: addl %3,%0\n" \
23332 " jmp 2b\n" \
23333 @@ -537,14 +649,14 @@ do { \
23334 " negl %0\n" \
23335 " andl $7,%0\n" \
23336 " subl %0,%3\n" \
23337 - "4: rep; movsb\n" \
23338 + "4: rep; "__copyuser_seg"movsb\n" \
23339 " movl %3,%0\n" \
23340 " shrl $2,%0\n" \
23341 " andl $3,%3\n" \
23342 " .align 2,0x90\n" \
23343 - "0: rep; movsl\n" \
23344 + "0: rep; "__copyuser_seg"movsl\n" \
23345 " movl %3,%0\n" \
23346 - "1: rep; movsb\n" \
23347 + "1: rep; "__copyuser_seg"movsb\n" \
23348 "2:\n" \
23349 ".section .fixup,\"ax\"\n" \
23350 "5: addl %3,%0\n" \
23351 @@ -627,9 +739,9 @@ survive:
23352 }
23353 #endif
23354 if (movsl_is_ok(to, from, n))
23355 - __copy_user(to, from, n);
23356 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
23357 else
23358 - n = __copy_user_intel(to, from, n);
23359 + n = __generic_copy_to_user_intel(to, from, n);
23360 return n;
23361 }
23362 EXPORT_SYMBOL(__copy_to_user_ll);
23363 @@ -649,10 +761,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
23364 unsigned long n)
23365 {
23366 if (movsl_is_ok(to, from, n))
23367 - __copy_user(to, from, n);
23368 + __copy_user(to, from, n, __copyuser_seg, "", "");
23369 else
23370 - n = __copy_user_intel((void __user *)to,
23371 - (const void *)from, n);
23372 + n = __generic_copy_from_user_intel(to, from, n);
23373 return n;
23374 }
23375 EXPORT_SYMBOL(__copy_from_user_ll_nozero);
23376 @@ -679,65 +790,50 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
23377 if (n > 64 && cpu_has_xmm2)
23378 n = __copy_user_intel_nocache(to, from, n);
23379 else
23380 - __copy_user(to, from, n);
23381 + __copy_user(to, from, n, __copyuser_seg, "", "");
23382 #else
23383 - __copy_user(to, from, n);
23384 + __copy_user(to, from, n, __copyuser_seg, "", "");
23385 #endif
23386 return n;
23387 }
23388 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
23389
23390 -/**
23391 - * copy_to_user: - Copy a block of data into user space.
23392 - * @to: Destination address, in user space.
23393 - * @from: Source address, in kernel space.
23394 - * @n: Number of bytes to copy.
23395 - *
23396 - * Context: User context only. This function may sleep.
23397 - *
23398 - * Copy data from kernel space to user space.
23399 - *
23400 - * Returns number of bytes that could not be copied.
23401 - * On success, this will be zero.
23402 - */
23403 -unsigned long
23404 -copy_to_user(void __user *to, const void *from, unsigned long n)
23405 -{
23406 - if (access_ok(VERIFY_WRITE, to, n))
23407 - n = __copy_to_user(to, from, n);
23408 - return n;
23409 -}
23410 -EXPORT_SYMBOL(copy_to_user);
23411 -
23412 -/**
23413 - * copy_from_user: - Copy a block of data from user space.
23414 - * @to: Destination address, in kernel space.
23415 - * @from: Source address, in user space.
23416 - * @n: Number of bytes to copy.
23417 - *
23418 - * Context: User context only. This function may sleep.
23419 - *
23420 - * Copy data from user space to kernel space.
23421 - *
23422 - * Returns number of bytes that could not be copied.
23423 - * On success, this will be zero.
23424 - *
23425 - * If some data could not be copied, this function will pad the copied
23426 - * data to the requested size using zero bytes.
23427 - */
23428 -unsigned long
23429 -_copy_from_user(void *to, const void __user *from, unsigned long n)
23430 -{
23431 - if (access_ok(VERIFY_READ, from, n))
23432 - n = __copy_from_user(to, from, n);
23433 - else
23434 - memset(to, 0, n);
23435 - return n;
23436 -}
23437 -EXPORT_SYMBOL(_copy_from_user);
23438 -
23439 void copy_from_user_overflow(void)
23440 {
23441 WARN(1, "Buffer overflow detected!\n");
23442 }
23443 EXPORT_SYMBOL(copy_from_user_overflow);
23444 +
23445 +void copy_to_user_overflow(void)
23446 +{
23447 + WARN(1, "Buffer overflow detected!\n");
23448 +}
23449 +EXPORT_SYMBOL(copy_to_user_overflow);
23450 +
23451 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23452 +void __set_fs(mm_segment_t x)
23453 +{
23454 + switch (x.seg) {
23455 + case 0:
23456 + loadsegment(gs, 0);
23457 + break;
23458 + case TASK_SIZE_MAX:
23459 + loadsegment(gs, __USER_DS);
23460 + break;
23461 + case -1UL:
23462 + loadsegment(gs, __KERNEL_DS);
23463 + break;
23464 + default:
23465 + BUG();
23466 + }
23467 + return;
23468 +}
23469 +EXPORT_SYMBOL(__set_fs);
23470 +
23471 +void set_fs(mm_segment_t x)
23472 +{
23473 + current_thread_info()->addr_limit = x;
23474 + __set_fs(x);
23475 +}
23476 +EXPORT_SYMBOL(set_fs);
23477 +#endif
23478 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
23479 index e5b130b..6690d31 100644
23480 --- a/arch/x86/lib/usercopy_64.c
23481 +++ b/arch/x86/lib/usercopy_64.c
23482 @@ -16,6 +16,12 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
23483 {
23484 long __d0;
23485 might_fault();
23486 +
23487 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23488 + if ((unsigned long)addr < PAX_USER_SHADOW_BASE)
23489 + addr += PAX_USER_SHADOW_BASE;
23490 +#endif
23491 +
23492 /* no memory constraint because it doesn't change any memory gcc knows
23493 about */
23494 asm volatile(
23495 @@ -52,12 +58,20 @@ unsigned long clear_user(void __user *to, unsigned long n)
23496 }
23497 EXPORT_SYMBOL(clear_user);
23498
23499 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
23500 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
23501 {
23502 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23503 - return copy_user_generic((__force void *)to, (__force void *)from, len);
23504 - }
23505 - return len;
23506 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
23507 +
23508 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23509 + if ((unsigned long)to < PAX_USER_SHADOW_BASE)
23510 + to += PAX_USER_SHADOW_BASE;
23511 + if ((unsigned long)from < PAX_USER_SHADOW_BASE)
23512 + from += PAX_USER_SHADOW_BASE;
23513 +#endif
23514 +
23515 + return copy_user_generic((void __force_kernel *)to, (void __force_kernel *)from, len);
23516 + }
23517 + return len;
23518 }
23519 EXPORT_SYMBOL(copy_in_user);
23520
23521 @@ -67,7 +81,7 @@ EXPORT_SYMBOL(copy_in_user);
23522 * it is not necessary to optimize tail handling.
23523 */
23524 unsigned long
23525 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23526 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
23527 {
23528 char c;
23529 unsigned zero_len;
23530 @@ -84,3 +98,15 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
23531 break;
23532 return len;
23533 }
23534 +
23535 +void copy_from_user_overflow(void)
23536 +{
23537 + WARN(1, "Buffer overflow detected!\n");
23538 +}
23539 +EXPORT_SYMBOL(copy_from_user_overflow);
23540 +
23541 +void copy_to_user_overflow(void)
23542 +{
23543 + WARN(1, "Buffer overflow detected!\n");
23544 +}
23545 +EXPORT_SYMBOL(copy_to_user_overflow);
23546 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
23547 index 903ec1e..c4166b2 100644
23548 --- a/arch/x86/mm/extable.c
23549 +++ b/arch/x86/mm/extable.c
23550 @@ -6,12 +6,24 @@
23551 static inline unsigned long
23552 ex_insn_addr(const struct exception_table_entry *x)
23553 {
23554 - return (unsigned long)&x->insn + x->insn;
23555 + unsigned long reloc = 0;
23556 +
23557 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23558 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23559 +#endif
23560 +
23561 + return (unsigned long)&x->insn + x->insn + reloc;
23562 }
23563 static inline unsigned long
23564 ex_fixup_addr(const struct exception_table_entry *x)
23565 {
23566 - return (unsigned long)&x->fixup + x->fixup;
23567 + unsigned long reloc = 0;
23568 +
23569 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23570 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23571 +#endif
23572 +
23573 + return (unsigned long)&x->fixup + x->fixup + reloc;
23574 }
23575
23576 int fixup_exception(struct pt_regs *regs)
23577 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
23578 unsigned long new_ip;
23579
23580 #ifdef CONFIG_PNPBIOS
23581 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
23582 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
23583 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
23584 extern u32 pnp_bios_is_utter_crap;
23585 pnp_bios_is_utter_crap = 1;
23586 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
23587 i += 4;
23588 p->fixup -= i;
23589 i += 4;
23590 +
23591 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
23592 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
23593 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23594 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
23595 +#endif
23596 +
23597 }
23598 }
23599
23600 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
23601 index 76dcd9d..e9dffde 100644
23602 --- a/arch/x86/mm/fault.c
23603 +++ b/arch/x86/mm/fault.c
23604 @@ -13,11 +13,18 @@
23605 #include <linux/perf_event.h> /* perf_sw_event */
23606 #include <linux/hugetlb.h> /* hstate_index_to_shift */
23607 #include <linux/prefetch.h> /* prefetchw */
23608 +#include <linux/unistd.h>
23609 +#include <linux/compiler.h>
23610
23611 #include <asm/traps.h> /* dotraplinkage, ... */
23612 #include <asm/pgalloc.h> /* pgd_*(), ... */
23613 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
23614 #include <asm/fixmap.h> /* VSYSCALL_START */
23615 +#include <asm/tlbflush.h>
23616 +
23617 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23618 +#include <asm/stacktrace.h>
23619 +#endif
23620
23621 /*
23622 * Page fault error code bits:
23623 @@ -55,7 +62,7 @@ static inline int __kprobes notify_page_fault(struct pt_regs *regs)
23624 int ret = 0;
23625
23626 /* kprobe_running() needs smp_processor_id() */
23627 - if (kprobes_built_in() && !user_mode_vm(regs)) {
23628 + if (kprobes_built_in() && !user_mode(regs)) {
23629 preempt_disable();
23630 if (kprobe_running() && kprobe_fault_handler(regs, 14))
23631 ret = 1;
23632 @@ -116,7 +123,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
23633 return !instr_lo || (instr_lo>>1) == 1;
23634 case 0x00:
23635 /* Prefetch instruction is 0x0F0D or 0x0F18 */
23636 - if (probe_kernel_address(instr, opcode))
23637 + if (user_mode(regs)) {
23638 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23639 + return 0;
23640 + } else if (probe_kernel_address(instr, opcode))
23641 return 0;
23642
23643 *prefetch = (instr_lo == 0xF) &&
23644 @@ -150,7 +160,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
23645 while (instr < max_instr) {
23646 unsigned char opcode;
23647
23648 - if (probe_kernel_address(instr, opcode))
23649 + if (user_mode(regs)) {
23650 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
23651 + break;
23652 + } else if (probe_kernel_address(instr, opcode))
23653 break;
23654
23655 instr++;
23656 @@ -181,6 +194,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
23657 force_sig_info(si_signo, &info, tsk);
23658 }
23659
23660 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23661 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
23662 +#endif
23663 +
23664 +#ifdef CONFIG_PAX_EMUTRAMP
23665 +static int pax_handle_fetch_fault(struct pt_regs *regs);
23666 +#endif
23667 +
23668 +#ifdef CONFIG_PAX_PAGEEXEC
23669 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
23670 +{
23671 + pgd_t *pgd;
23672 + pud_t *pud;
23673 + pmd_t *pmd;
23674 +
23675 + pgd = pgd_offset(mm, address);
23676 + if (!pgd_present(*pgd))
23677 + return NULL;
23678 + pud = pud_offset(pgd, address);
23679 + if (!pud_present(*pud))
23680 + return NULL;
23681 + pmd = pmd_offset(pud, address);
23682 + if (!pmd_present(*pmd))
23683 + return NULL;
23684 + return pmd;
23685 +}
23686 +#endif
23687 +
23688 DEFINE_SPINLOCK(pgd_lock);
23689 LIST_HEAD(pgd_list);
23690
23691 @@ -231,10 +272,22 @@ void vmalloc_sync_all(void)
23692 for (address = VMALLOC_START & PMD_MASK;
23693 address >= TASK_SIZE && address < FIXADDR_TOP;
23694 address += PMD_SIZE) {
23695 +
23696 +#ifdef CONFIG_PAX_PER_CPU_PGD
23697 + unsigned long cpu;
23698 +#else
23699 struct page *page;
23700 +#endif
23701
23702 spin_lock(&pgd_lock);
23703 +
23704 +#ifdef CONFIG_PAX_PER_CPU_PGD
23705 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
23706 + pgd_t *pgd = get_cpu_pgd(cpu);
23707 + pmd_t *ret;
23708 +#else
23709 list_for_each_entry(page, &pgd_list, lru) {
23710 + pgd_t *pgd = page_address(page);
23711 spinlock_t *pgt_lock;
23712 pmd_t *ret;
23713
23714 @@ -242,8 +295,13 @@ void vmalloc_sync_all(void)
23715 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
23716
23717 spin_lock(pgt_lock);
23718 - ret = vmalloc_sync_one(page_address(page), address);
23719 +#endif
23720 +
23721 + ret = vmalloc_sync_one(pgd, address);
23722 +
23723 +#ifndef CONFIG_PAX_PER_CPU_PGD
23724 spin_unlock(pgt_lock);
23725 +#endif
23726
23727 if (!ret)
23728 break;
23729 @@ -277,6 +335,11 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23730 * an interrupt in the middle of a task switch..
23731 */
23732 pgd_paddr = read_cr3();
23733 +
23734 +#ifdef CONFIG_PAX_PER_CPU_PGD
23735 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (pgd_paddr & PHYSICAL_PAGE_MASK));
23736 +#endif
23737 +
23738 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
23739 if (!pmd_k)
23740 return -1;
23741 @@ -372,7 +435,14 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
23742 * happen within a race in page table update. In the later
23743 * case just flush:
23744 */
23745 +
23746 +#ifdef CONFIG_PAX_PER_CPU_PGD
23747 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id())) != (read_cr3() & PHYSICAL_PAGE_MASK));
23748 + pgd = pgd_offset_cpu(smp_processor_id(), address);
23749 +#else
23750 pgd = pgd_offset(current->active_mm, address);
23751 +#endif
23752 +
23753 pgd_ref = pgd_offset_k(address);
23754 if (pgd_none(*pgd_ref))
23755 return -1;
23756 @@ -540,7 +610,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
23757 static int is_errata100(struct pt_regs *regs, unsigned long address)
23758 {
23759 #ifdef CONFIG_X86_64
23760 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
23761 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
23762 return 1;
23763 #endif
23764 return 0;
23765 @@ -567,7 +637,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
23766 }
23767
23768 static const char nx_warning[] = KERN_CRIT
23769 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
23770 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
23771
23772 static void
23773 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23774 @@ -576,15 +646,26 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
23775 if (!oops_may_print())
23776 return;
23777
23778 - if (error_code & PF_INSTR) {
23779 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
23780 unsigned int level;
23781
23782 pte_t *pte = lookup_address(address, &level);
23783
23784 if (pte && pte_present(*pte) && !pte_exec(*pte))
23785 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
23786 + printk(nx_warning, from_kuid(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
23787 }
23788
23789 +#ifdef CONFIG_PAX_KERNEXEC
23790 + if (init_mm.start_code <= address && address < init_mm.end_code) {
23791 + if (current->signal->curr_ip)
23792 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23793 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
23794 + else
23795 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
23796 + current->comm, task_pid_nr(current), current_uid(), current_euid());
23797 + }
23798 +#endif
23799 +
23800 printk(KERN_ALERT "BUG: unable to handle kernel ");
23801 if (address < PAGE_SIZE)
23802 printk(KERN_CONT "NULL pointer dereference");
23803 @@ -748,6 +829,21 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
23804 }
23805 #endif
23806
23807 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
23808 + if (pax_is_fetch_fault(regs, error_code, address)) {
23809 +
23810 +#ifdef CONFIG_PAX_EMUTRAMP
23811 + switch (pax_handle_fetch_fault(regs)) {
23812 + case 2:
23813 + return;
23814 + }
23815 +#endif
23816 +
23817 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23818 + do_group_exit(SIGKILL);
23819 + }
23820 +#endif
23821 +
23822 if (unlikely(show_unhandled_signals))
23823 show_signal_msg(regs, error_code, address, tsk);
23824
23825 @@ -844,7 +940,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
23826 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
23827 printk(KERN_ERR
23828 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
23829 - tsk->comm, tsk->pid, address);
23830 + tsk->comm, task_pid_nr(tsk), address);
23831 code = BUS_MCEERR_AR;
23832 }
23833 #endif
23834 @@ -900,6 +996,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
23835 return 1;
23836 }
23837
23838 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23839 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
23840 +{
23841 + pte_t *pte;
23842 + pmd_t *pmd;
23843 + spinlock_t *ptl;
23844 + unsigned char pte_mask;
23845 +
23846 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
23847 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
23848 + return 0;
23849 +
23850 + /* PaX: it's our fault, let's handle it if we can */
23851 +
23852 + /* PaX: take a look at read faults before acquiring any locks */
23853 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
23854 + /* instruction fetch attempt from a protected page in user mode */
23855 + up_read(&mm->mmap_sem);
23856 +
23857 +#ifdef CONFIG_PAX_EMUTRAMP
23858 + switch (pax_handle_fetch_fault(regs)) {
23859 + case 2:
23860 + return 1;
23861 + }
23862 +#endif
23863 +
23864 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
23865 + do_group_exit(SIGKILL);
23866 + }
23867 +
23868 + pmd = pax_get_pmd(mm, address);
23869 + if (unlikely(!pmd))
23870 + return 0;
23871 +
23872 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
23873 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
23874 + pte_unmap_unlock(pte, ptl);
23875 + return 0;
23876 + }
23877 +
23878 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
23879 + /* write attempt to a protected page in user mode */
23880 + pte_unmap_unlock(pte, ptl);
23881 + return 0;
23882 + }
23883 +
23884 +#ifdef CONFIG_SMP
23885 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
23886 +#else
23887 + if (likely(address > get_limit(regs->cs)))
23888 +#endif
23889 + {
23890 + set_pte(pte, pte_mkread(*pte));
23891 + __flush_tlb_one(address);
23892 + pte_unmap_unlock(pte, ptl);
23893 + up_read(&mm->mmap_sem);
23894 + return 1;
23895 + }
23896 +
23897 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
23898 +
23899 + /*
23900 + * PaX: fill DTLB with user rights and retry
23901 + */
23902 + __asm__ __volatile__ (
23903 + "orb %2,(%1)\n"
23904 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
23905 +/*
23906 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
23907 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
23908 + * page fault when examined during a TLB load attempt. this is true not only
23909 + * for PTEs holding a non-present entry but also present entries that will
23910 + * raise a page fault (such as those set up by PaX, or the copy-on-write
23911 + * mechanism). in effect it means that we do *not* need to flush the TLBs
23912 + * for our target pages since their PTEs are simply not in the TLBs at all.
23913 +
23914 + * the best thing in omitting it is that we gain around 15-20% speed in the
23915 + * fast path of the page fault handler and can get rid of tracing since we
23916 + * can no longer flush unintended entries.
23917 + */
23918 + "invlpg (%0)\n"
23919 +#endif
23920 + __copyuser_seg"testb $0,(%0)\n"
23921 + "xorb %3,(%1)\n"
23922 + :
23923 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
23924 + : "memory", "cc");
23925 + pte_unmap_unlock(pte, ptl);
23926 + up_read(&mm->mmap_sem);
23927 + return 1;
23928 +}
23929 +#endif
23930 +
23931 /*
23932 * Handle a spurious fault caused by a stale TLB entry.
23933 *
23934 @@ -972,6 +1161,9 @@ int show_unhandled_signals = 1;
23935 static inline int
23936 access_error(unsigned long error_code, struct vm_area_struct *vma)
23937 {
23938 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
23939 + return 1;
23940 +
23941 if (error_code & PF_WRITE) {
23942 /* write, present and write, not present: */
23943 if (unlikely(!(vma->vm_flags & VM_WRITE)))
23944 @@ -1005,18 +1197,33 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23945 {
23946 struct vm_area_struct *vma;
23947 struct task_struct *tsk;
23948 - unsigned long address;
23949 struct mm_struct *mm;
23950 int fault;
23951 int write = error_code & PF_WRITE;
23952 unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE |
23953 (write ? FAULT_FLAG_WRITE : 0);
23954
23955 - tsk = current;
23956 - mm = tsk->mm;
23957 -
23958 /* Get the faulting address: */
23959 - address = read_cr2();
23960 + unsigned long address = read_cr2();
23961 +
23962 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
23963 + if (!user_mode(regs) && address < 2 * PAX_USER_SHADOW_BASE) {
23964 + if (!search_exception_tables(regs->ip)) {
23965 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23966 + bad_area_nosemaphore(regs, error_code, address);
23967 + return;
23968 + }
23969 + if (address < PAX_USER_SHADOW_BASE) {
23970 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
23971 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
23972 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
23973 + } else
23974 + address -= PAX_USER_SHADOW_BASE;
23975 + }
23976 +#endif
23977 +
23978 + tsk = current;
23979 + mm = tsk->mm;
23980
23981 /*
23982 * Detect and handle instructions that would cause a page fault for
23983 @@ -1077,7 +1284,7 @@ do_page_fault(struct pt_regs *regs, unsigned long error_code)
23984 * User-mode registers count as a user access even for any
23985 * potential system fault or CPU buglet:
23986 */
23987 - if (user_mode_vm(regs)) {
23988 + if (user_mode(regs)) {
23989 local_irq_enable();
23990 error_code |= PF_USER;
23991 } else {
23992 @@ -1132,6 +1339,11 @@ retry:
23993 might_sleep();
23994 }
23995
23996 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
23997 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
23998 + return;
23999 +#endif
24000 +
24001 vma = find_vma(mm, address);
24002 if (unlikely(!vma)) {
24003 bad_area(regs, error_code, address);
24004 @@ -1143,18 +1355,24 @@ retry:
24005 bad_area(regs, error_code, address);
24006 return;
24007 }
24008 - if (error_code & PF_USER) {
24009 - /*
24010 - * Accessing the stack below %sp is always a bug.
24011 - * The large cushion allows instructions like enter
24012 - * and pusha to work. ("enter $65535, $31" pushes
24013 - * 32 pointers and then decrements %sp by 65535.)
24014 - */
24015 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
24016 - bad_area(regs, error_code, address);
24017 - return;
24018 - }
24019 + /*
24020 + * Accessing the stack below %sp is always a bug.
24021 + * The large cushion allows instructions like enter
24022 + * and pusha to work. ("enter $65535, $31" pushes
24023 + * 32 pointers and then decrements %sp by 65535.)
24024 + */
24025 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
24026 + bad_area(regs, error_code, address);
24027 + return;
24028 }
24029 +
24030 +#ifdef CONFIG_PAX_SEGMEXEC
24031 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
24032 + bad_area(regs, error_code, address);
24033 + return;
24034 + }
24035 +#endif
24036 +
24037 if (unlikely(expand_stack(vma, address))) {
24038 bad_area(regs, error_code, address);
24039 return;
24040 @@ -1209,3 +1427,292 @@ good_area:
24041
24042 up_read(&mm->mmap_sem);
24043 }
24044 +
24045 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24046 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
24047 +{
24048 + struct mm_struct *mm = current->mm;
24049 + unsigned long ip = regs->ip;
24050 +
24051 + if (v8086_mode(regs))
24052 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
24053 +
24054 +#ifdef CONFIG_PAX_PAGEEXEC
24055 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
24056 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
24057 + return true;
24058 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
24059 + return true;
24060 + return false;
24061 + }
24062 +#endif
24063 +
24064 +#ifdef CONFIG_PAX_SEGMEXEC
24065 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
24066 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
24067 + return true;
24068 + return false;
24069 + }
24070 +#endif
24071 +
24072 + return false;
24073 +}
24074 +#endif
24075 +
24076 +#ifdef CONFIG_PAX_EMUTRAMP
24077 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
24078 +{
24079 + int err;
24080 +
24081 + do { /* PaX: libffi trampoline emulation */
24082 + unsigned char mov, jmp;
24083 + unsigned int addr1, addr2;
24084 +
24085 +#ifdef CONFIG_X86_64
24086 + if ((regs->ip + 9) >> 32)
24087 + break;
24088 +#endif
24089 +
24090 + err = get_user(mov, (unsigned char __user *)regs->ip);
24091 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24092 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24093 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24094 +
24095 + if (err)
24096 + break;
24097 +
24098 + if (mov == 0xB8 && jmp == 0xE9) {
24099 + regs->ax = addr1;
24100 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24101 + return 2;
24102 + }
24103 + } while (0);
24104 +
24105 + do { /* PaX: gcc trampoline emulation #1 */
24106 + unsigned char mov1, mov2;
24107 + unsigned short jmp;
24108 + unsigned int addr1, addr2;
24109 +
24110 +#ifdef CONFIG_X86_64
24111 + if ((regs->ip + 11) >> 32)
24112 + break;
24113 +#endif
24114 +
24115 + err = get_user(mov1, (unsigned char __user *)regs->ip);
24116 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24117 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
24118 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24119 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
24120 +
24121 + if (err)
24122 + break;
24123 +
24124 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
24125 + regs->cx = addr1;
24126 + regs->ax = addr2;
24127 + regs->ip = addr2;
24128 + return 2;
24129 + }
24130 + } while (0);
24131 +
24132 + do { /* PaX: gcc trampoline emulation #2 */
24133 + unsigned char mov, jmp;
24134 + unsigned int addr1, addr2;
24135 +
24136 +#ifdef CONFIG_X86_64
24137 + if ((regs->ip + 9) >> 32)
24138 + break;
24139 +#endif
24140 +
24141 + err = get_user(mov, (unsigned char __user *)regs->ip);
24142 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
24143 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
24144 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
24145 +
24146 + if (err)
24147 + break;
24148 +
24149 + if (mov == 0xB9 && jmp == 0xE9) {
24150 + regs->cx = addr1;
24151 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
24152 + return 2;
24153 + }
24154 + } while (0);
24155 +
24156 + return 1; /* PaX in action */
24157 +}
24158 +
24159 +#ifdef CONFIG_X86_64
24160 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
24161 +{
24162 + int err;
24163 +
24164 + do { /* PaX: libffi trampoline emulation */
24165 + unsigned short mov1, mov2, jmp1;
24166 + unsigned char stcclc, jmp2;
24167 + unsigned long addr1, addr2;
24168 +
24169 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24170 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24171 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24172 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24173 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
24174 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
24175 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
24176 +
24177 + if (err)
24178 + break;
24179 +
24180 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24181 + regs->r11 = addr1;
24182 + regs->r10 = addr2;
24183 + if (stcclc == 0xF8)
24184 + regs->flags &= ~X86_EFLAGS_CF;
24185 + else
24186 + regs->flags |= X86_EFLAGS_CF;
24187 + regs->ip = addr1;
24188 + return 2;
24189 + }
24190 + } while (0);
24191 +
24192 + do { /* PaX: gcc trampoline emulation #1 */
24193 + unsigned short mov1, mov2, jmp1;
24194 + unsigned char jmp2;
24195 + unsigned int addr1;
24196 + unsigned long addr2;
24197 +
24198 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24199 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
24200 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
24201 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
24202 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
24203 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
24204 +
24205 + if (err)
24206 + break;
24207 +
24208 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24209 + regs->r11 = addr1;
24210 + regs->r10 = addr2;
24211 + regs->ip = addr1;
24212 + return 2;
24213 + }
24214 + } while (0);
24215 +
24216 + do { /* PaX: gcc trampoline emulation #2 */
24217 + unsigned short mov1, mov2, jmp1;
24218 + unsigned char jmp2;
24219 + unsigned long addr1, addr2;
24220 +
24221 + err = get_user(mov1, (unsigned short __user *)regs->ip);
24222 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
24223 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
24224 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
24225 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
24226 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
24227 +
24228 + if (err)
24229 + break;
24230 +
24231 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
24232 + regs->r11 = addr1;
24233 + regs->r10 = addr2;
24234 + regs->ip = addr1;
24235 + return 2;
24236 + }
24237 + } while (0);
24238 +
24239 + return 1; /* PaX in action */
24240 +}
24241 +#endif
24242 +
24243 +/*
24244 + * PaX: decide what to do with offenders (regs->ip = fault address)
24245 + *
24246 + * returns 1 when task should be killed
24247 + * 2 when gcc trampoline was detected
24248 + */
24249 +static int pax_handle_fetch_fault(struct pt_regs *regs)
24250 +{
24251 + if (v8086_mode(regs))
24252 + return 1;
24253 +
24254 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
24255 + return 1;
24256 +
24257 +#ifdef CONFIG_X86_32
24258 + return pax_handle_fetch_fault_32(regs);
24259 +#else
24260 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
24261 + return pax_handle_fetch_fault_32(regs);
24262 + else
24263 + return pax_handle_fetch_fault_64(regs);
24264 +#endif
24265 +}
24266 +#endif
24267 +
24268 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24269 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
24270 +{
24271 + long i;
24272 +
24273 + printk(KERN_ERR "PAX: bytes at PC: ");
24274 + for (i = 0; i < 20; i++) {
24275 + unsigned char c;
24276 + if (get_user(c, (unsigned char __force_user *)pc+i))
24277 + printk(KERN_CONT "?? ");
24278 + else
24279 + printk(KERN_CONT "%02x ", c);
24280 + }
24281 + printk("\n");
24282 +
24283 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
24284 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
24285 + unsigned long c;
24286 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
24287 +#ifdef CONFIG_X86_32
24288 + printk(KERN_CONT "???????? ");
24289 +#else
24290 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
24291 + printk(KERN_CONT "???????? ???????? ");
24292 + else
24293 + printk(KERN_CONT "???????????????? ");
24294 +#endif
24295 + } else {
24296 +#ifdef CONFIG_X86_64
24297 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
24298 + printk(KERN_CONT "%08x ", (unsigned int)c);
24299 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
24300 + } else
24301 +#endif
24302 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
24303 + }
24304 + }
24305 + printk("\n");
24306 +}
24307 +#endif
24308 +
24309 +/**
24310 + * probe_kernel_write(): safely attempt to write to a location
24311 + * @dst: address to write to
24312 + * @src: pointer to the data that shall be written
24313 + * @size: size of the data chunk
24314 + *
24315 + * Safely write to address @dst from the buffer at @src. If a kernel fault
24316 + * happens, handle that and return -EFAULT.
24317 + */
24318 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
24319 +{
24320 + long ret;
24321 + mm_segment_t old_fs = get_fs();
24322 +
24323 + set_fs(KERNEL_DS);
24324 + pagefault_disable();
24325 + pax_open_kernel();
24326 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
24327 + pax_close_kernel();
24328 + pagefault_enable();
24329 + set_fs(old_fs);
24330 +
24331 + return ret ? -EFAULT : 0;
24332 +}
24333 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
24334 index dd74e46..7d26398 100644
24335 --- a/arch/x86/mm/gup.c
24336 +++ b/arch/x86/mm/gup.c
24337 @@ -255,7 +255,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
24338 addr = start;
24339 len = (unsigned long) nr_pages << PAGE_SHIFT;
24340 end = start + len;
24341 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24342 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
24343 (void __user *)start, len)))
24344 return 0;
24345
24346 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
24347 index 6f31ee5..8ee4164 100644
24348 --- a/arch/x86/mm/highmem_32.c
24349 +++ b/arch/x86/mm/highmem_32.c
24350 @@ -44,7 +44,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
24351 idx = type + KM_TYPE_NR*smp_processor_id();
24352 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
24353 BUG_ON(!pte_none(*(kmap_pte-idx)));
24354 +
24355 + pax_open_kernel();
24356 set_pte(kmap_pte-idx, mk_pte(page, prot));
24357 + pax_close_kernel();
24358 +
24359 arch_flush_lazy_mmu_mode();
24360
24361 return (void *)vaddr;
24362 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
24363 index b91e485..d00e7c9 100644
24364 --- a/arch/x86/mm/hugetlbpage.c
24365 +++ b/arch/x86/mm/hugetlbpage.c
24366 @@ -277,13 +277,20 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
24367 struct hstate *h = hstate_file(file);
24368 struct mm_struct *mm = current->mm;
24369 struct vm_area_struct *vma;
24370 - unsigned long start_addr;
24371 + unsigned long start_addr, pax_task_size = TASK_SIZE;
24372 +
24373 +#ifdef CONFIG_PAX_SEGMEXEC
24374 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24375 + pax_task_size = SEGMEXEC_TASK_SIZE;
24376 +#endif
24377 +
24378 + pax_task_size -= PAGE_SIZE;
24379
24380 if (len > mm->cached_hole_size) {
24381 - start_addr = mm->free_area_cache;
24382 + start_addr = mm->free_area_cache;
24383 } else {
24384 - start_addr = TASK_UNMAPPED_BASE;
24385 - mm->cached_hole_size = 0;
24386 + start_addr = mm->mmap_base;
24387 + mm->cached_hole_size = 0;
24388 }
24389
24390 full_search:
24391 @@ -291,26 +298,27 @@ full_search:
24392
24393 for (vma = find_vma(mm, addr); ; vma = vma->vm_next) {
24394 /* At this point: (!vma || addr < vma->vm_end). */
24395 - if (TASK_SIZE - len < addr) {
24396 + if (pax_task_size - len < addr) {
24397 /*
24398 * Start a new search - just in case we missed
24399 * some holes.
24400 */
24401 - if (start_addr != TASK_UNMAPPED_BASE) {
24402 - start_addr = TASK_UNMAPPED_BASE;
24403 + if (start_addr != mm->mmap_base) {
24404 + start_addr = mm->mmap_base;
24405 mm->cached_hole_size = 0;
24406 goto full_search;
24407 }
24408 return -ENOMEM;
24409 }
24410 - if (!vma || addr + len <= vma->vm_start) {
24411 - mm->free_area_cache = addr + len;
24412 - return addr;
24413 - }
24414 + if (check_heap_stack_gap(vma, addr, len))
24415 + break;
24416 if (addr + mm->cached_hole_size < vma->vm_start)
24417 mm->cached_hole_size = vma->vm_start - addr;
24418 addr = ALIGN(vma->vm_end, huge_page_size(h));
24419 }
24420 +
24421 + mm->free_area_cache = addr + len;
24422 + return addr;
24423 }
24424
24425 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24426 @@ -321,9 +329,8 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24427 struct mm_struct *mm = current->mm;
24428 struct vm_area_struct *vma;
24429 unsigned long base = mm->mmap_base;
24430 - unsigned long addr = addr0;
24431 + unsigned long addr;
24432 unsigned long largest_hole = mm->cached_hole_size;
24433 - unsigned long start_addr;
24434
24435 /* don't allow allocations above current base */
24436 if (mm->free_area_cache > base)
24437 @@ -333,16 +340,15 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
24438 largest_hole = 0;
24439 mm->free_area_cache = base;
24440 }
24441 -try_again:
24442 - start_addr = mm->free_area_cache;
24443
24444 /* make sure it can fit in the remaining address space */
24445 if (mm->free_area_cache < len)
24446 goto fail;
24447
24448 /* either no address requested or can't fit in requested address hole */
24449 - addr = (mm->free_area_cache - len) & huge_page_mask(h);
24450 + addr = mm->free_area_cache - len;
24451 do {
24452 + addr &= huge_page_mask(h);
24453 /*
24454 * Lookup failure means no vma is above this address,
24455 * i.e. return with success:
24456 @@ -351,10 +357,10 @@ try_again:
24457 if (!vma)
24458 return addr;
24459
24460 - if (addr + len <= vma->vm_start) {
24461 + if (check_heap_stack_gap(vma, addr, len)) {
24462 /* remember the address as a hint for next time */
24463 - mm->cached_hole_size = largest_hole;
24464 - return (mm->free_area_cache = addr);
24465 + mm->cached_hole_size = largest_hole;
24466 + return (mm->free_area_cache = addr);
24467 } else if (mm->free_area_cache == vma->vm_end) {
24468 /* pull free_area_cache down to the first hole */
24469 mm->free_area_cache = vma->vm_start;
24470 @@ -363,29 +369,34 @@ try_again:
24471
24472 /* remember the largest hole we saw so far */
24473 if (addr + largest_hole < vma->vm_start)
24474 - largest_hole = vma->vm_start - addr;
24475 + largest_hole = vma->vm_start - addr;
24476
24477 /* try just below the current vma->vm_start */
24478 - addr = (vma->vm_start - len) & huge_page_mask(h);
24479 - } while (len <= vma->vm_start);
24480 + addr = skip_heap_stack_gap(vma, len);
24481 + } while (!IS_ERR_VALUE(addr));
24482
24483 fail:
24484 /*
24485 - * if hint left us with no space for the requested
24486 - * mapping then try again:
24487 - */
24488 - if (start_addr != base) {
24489 - mm->free_area_cache = base;
24490 - largest_hole = 0;
24491 - goto try_again;
24492 - }
24493 - /*
24494 * A failed mmap() very likely causes application failure,
24495 * so fall back to the bottom-up function here. This scenario
24496 * can happen with large stack limits and large mmap()
24497 * allocations.
24498 */
24499 - mm->free_area_cache = TASK_UNMAPPED_BASE;
24500 +
24501 +#ifdef CONFIG_PAX_SEGMEXEC
24502 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24503 + mm->mmap_base = SEGMEXEC_TASK_UNMAPPED_BASE;
24504 + else
24505 +#endif
24506 +
24507 + mm->mmap_base = TASK_UNMAPPED_BASE;
24508 +
24509 +#ifdef CONFIG_PAX_RANDMMAP
24510 + if (mm->pax_flags & MF_PAX_RANDMMAP)
24511 + mm->mmap_base += mm->delta_mmap;
24512 +#endif
24513 +
24514 + mm->free_area_cache = mm->mmap_base;
24515 mm->cached_hole_size = ~0UL;
24516 addr = hugetlb_get_unmapped_area_bottomup(file, addr0,
24517 len, pgoff, flags);
24518 @@ -393,6 +404,7 @@ fail:
24519 /*
24520 * Restore the topdown base:
24521 */
24522 + mm->mmap_base = base;
24523 mm->free_area_cache = base;
24524 mm->cached_hole_size = ~0UL;
24525
24526 @@ -406,10 +418,19 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24527 struct hstate *h = hstate_file(file);
24528 struct mm_struct *mm = current->mm;
24529 struct vm_area_struct *vma;
24530 + unsigned long pax_task_size = TASK_SIZE;
24531
24532 if (len & ~huge_page_mask(h))
24533 return -EINVAL;
24534 - if (len > TASK_SIZE)
24535 +
24536 +#ifdef CONFIG_PAX_SEGMEXEC
24537 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
24538 + pax_task_size = SEGMEXEC_TASK_SIZE;
24539 +#endif
24540 +
24541 + pax_task_size -= PAGE_SIZE;
24542 +
24543 + if (len > pax_task_size)
24544 return -ENOMEM;
24545
24546 if (flags & MAP_FIXED) {
24547 @@ -421,8 +442,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
24548 if (addr) {
24549 addr = ALIGN(addr, huge_page_size(h));
24550 vma = find_vma(mm, addr);
24551 - if (TASK_SIZE - len >= addr &&
24552 - (!vma || addr + len <= vma->vm_start))
24553 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len))
24554 return addr;
24555 }
24556 if (mm->get_unmapped_area == arch_get_unmapped_area)
24557 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
24558 index bc4e9d8..ca4c14b 100644
24559 --- a/arch/x86/mm/init.c
24560 +++ b/arch/x86/mm/init.c
24561 @@ -16,6 +16,8 @@
24562 #include <asm/tlb.h>
24563 #include <asm/proto.h>
24564 #include <asm/dma.h> /* for MAX_DMA_PFN */
24565 +#include <asm/desc.h>
24566 +#include <asm/bios_ebda.h>
24567
24568 unsigned long __initdata pgt_buf_start;
24569 unsigned long __meminitdata pgt_buf_end;
24570 @@ -38,7 +40,7 @@ struct map_range {
24571 static void __init find_early_table_space(struct map_range *mr, unsigned long end,
24572 int use_pse, int use_gbpages)
24573 {
24574 - unsigned long puds, pmds, ptes, tables, start = 0, good_end = end;
24575 + unsigned long puds, pmds, ptes, tables, start = 0x100000, good_end = end;
24576 phys_addr_t base;
24577
24578 puds = (end + PUD_SIZE - 1) >> PUD_SHIFT;
24579 @@ -317,10 +319,37 @@ unsigned long __init_refok init_memory_mapping(unsigned long start,
24580 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
24581 * mmio resources as well as potential bios/acpi data regions.
24582 */
24583 +
24584 +#ifdef CONFIG_GRKERNSEC_KMEM
24585 +static unsigned int ebda_start __read_only;
24586 +static unsigned int ebda_end __read_only;
24587 +#endif
24588 +
24589 int devmem_is_allowed(unsigned long pagenr)
24590 {
24591 +#ifdef CONFIG_GRKERNSEC_KMEM
24592 + /* allow BDA */
24593 + if (!pagenr)
24594 + return 1;
24595 + /* allow EBDA */
24596 + if (pagenr >= ebda_start && pagenr < ebda_end)
24597 + return 1;
24598 +#else
24599 + if (!pagenr)
24600 + return 1;
24601 +#ifdef CONFIG_VM86
24602 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
24603 + return 1;
24604 +#endif
24605 +#endif
24606 +
24607 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
24608 + return 1;
24609 +#ifdef CONFIG_GRKERNSEC_KMEM
24610 + /* throw out everything else below 1MB */
24611 if (pagenr <= 256)
24612 - return 1;
24613 + return 0;
24614 +#endif
24615 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
24616 return 0;
24617 if (!page_is_ram(pagenr))
24618 @@ -377,8 +406,116 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
24619 #endif
24620 }
24621
24622 +#ifdef CONFIG_GRKERNSEC_KMEM
24623 +static inline void gr_init_ebda(void)
24624 +{
24625 + unsigned int ebda_addr;
24626 + unsigned int ebda_size = 0;
24627 +
24628 + ebda_addr = get_bios_ebda();
24629 + if (ebda_addr) {
24630 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
24631 + ebda_size <<= 10;
24632 + }
24633 + if (ebda_addr && ebda_size) {
24634 + ebda_start = ebda_addr >> PAGE_SHIFT;
24635 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
24636 + } else {
24637 + ebda_start = 0x9f000 >> PAGE_SHIFT;
24638 + ebda_end = 0xa0000 >> PAGE_SHIFT;
24639 + }
24640 +}
24641 +#else
24642 +static inline void gr_init_ebda(void) { }
24643 +#endif
24644 +
24645 void free_initmem(void)
24646 {
24647 +#ifdef CONFIG_PAX_KERNEXEC
24648 +#ifdef CONFIG_X86_32
24649 + /* PaX: limit KERNEL_CS to actual size */
24650 + unsigned long addr, limit;
24651 + struct desc_struct d;
24652 + int cpu;
24653 +#else
24654 + pgd_t *pgd;
24655 + pud_t *pud;
24656 + pmd_t *pmd;
24657 + unsigned long addr, end;
24658 +#endif
24659 +#endif
24660 +
24661 + gr_init_ebda();
24662 +
24663 +#ifdef CONFIG_PAX_KERNEXEC
24664 +#ifdef CONFIG_X86_32
24665 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
24666 + limit = (limit - 1UL) >> PAGE_SHIFT;
24667 +
24668 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
24669 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
24670 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
24671 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
24672 + }
24673 +
24674 + /* PaX: make KERNEL_CS read-only */
24675 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
24676 + if (!paravirt_enabled())
24677 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
24678 +/*
24679 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
24680 + pgd = pgd_offset_k(addr);
24681 + pud = pud_offset(pgd, addr);
24682 + pmd = pmd_offset(pud, addr);
24683 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24684 + }
24685 +*/
24686 +#ifdef CONFIG_X86_PAE
24687 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
24688 +/*
24689 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
24690 + pgd = pgd_offset_k(addr);
24691 + pud = pud_offset(pgd, addr);
24692 + pmd = pmd_offset(pud, addr);
24693 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24694 + }
24695 +*/
24696 +#endif
24697 +
24698 +#ifdef CONFIG_MODULES
24699 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
24700 +#endif
24701 +
24702 +#else
24703 + /* PaX: make kernel code/rodata read-only, rest non-executable */
24704 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
24705 + pgd = pgd_offset_k(addr);
24706 + pud = pud_offset(pgd, addr);
24707 + pmd = pmd_offset(pud, addr);
24708 + if (!pmd_present(*pmd))
24709 + continue;
24710 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
24711 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24712 + else
24713 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
24714 + }
24715 +
24716 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
24717 + end = addr + KERNEL_IMAGE_SIZE;
24718 + for (; addr < end; addr += PMD_SIZE) {
24719 + pgd = pgd_offset_k(addr);
24720 + pud = pud_offset(pgd, addr);
24721 + pmd = pmd_offset(pud, addr);
24722 + if (!pmd_present(*pmd))
24723 + continue;
24724 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
24725 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
24726 + }
24727 +#endif
24728 +
24729 + flush_tlb_all();
24730 +#endif
24731 +
24732 free_init_pages("unused kernel memory",
24733 (unsigned long)(&__init_begin),
24734 (unsigned long)(&__init_end));
24735 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
24736 index 575d86f..4987469 100644
24737 --- a/arch/x86/mm/init_32.c
24738 +++ b/arch/x86/mm/init_32.c
24739 @@ -73,36 +73,6 @@ static __init void *alloc_low_page(void)
24740 }
24741
24742 /*
24743 - * Creates a middle page table and puts a pointer to it in the
24744 - * given global directory entry. This only returns the gd entry
24745 - * in non-PAE compilation mode, since the middle layer is folded.
24746 - */
24747 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
24748 -{
24749 - pud_t *pud;
24750 - pmd_t *pmd_table;
24751 -
24752 -#ifdef CONFIG_X86_PAE
24753 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
24754 - if (after_bootmem)
24755 - pmd_table = (pmd_t *)alloc_bootmem_pages(PAGE_SIZE);
24756 - else
24757 - pmd_table = (pmd_t *)alloc_low_page();
24758 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
24759 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
24760 - pud = pud_offset(pgd, 0);
24761 - BUG_ON(pmd_table != pmd_offset(pud, 0));
24762 -
24763 - return pmd_table;
24764 - }
24765 -#endif
24766 - pud = pud_offset(pgd, 0);
24767 - pmd_table = pmd_offset(pud, 0);
24768 -
24769 - return pmd_table;
24770 -}
24771 -
24772 -/*
24773 * Create a page table and place a pointer to it in a middle page
24774 * directory entry:
24775 */
24776 @@ -122,13 +92,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
24777 page_table = (pte_t *)alloc_low_page();
24778
24779 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
24780 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24781 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
24782 +#else
24783 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
24784 +#endif
24785 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
24786 }
24787
24788 return pte_offset_kernel(pmd, 0);
24789 }
24790
24791 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
24792 +{
24793 + pud_t *pud;
24794 + pmd_t *pmd_table;
24795 +
24796 + pud = pud_offset(pgd, 0);
24797 + pmd_table = pmd_offset(pud, 0);
24798 +
24799 + return pmd_table;
24800 +}
24801 +
24802 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
24803 {
24804 int pgd_idx = pgd_index(vaddr);
24805 @@ -202,6 +187,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24806 int pgd_idx, pmd_idx;
24807 unsigned long vaddr;
24808 pgd_t *pgd;
24809 + pud_t *pud;
24810 pmd_t *pmd;
24811 pte_t *pte = NULL;
24812
24813 @@ -211,8 +197,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24814 pgd = pgd_base + pgd_idx;
24815
24816 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
24817 - pmd = one_md_table_init(pgd);
24818 - pmd = pmd + pmd_index(vaddr);
24819 + pud = pud_offset(pgd, vaddr);
24820 + pmd = pmd_offset(pud, vaddr);
24821 +
24822 +#ifdef CONFIG_X86_PAE
24823 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24824 +#endif
24825 +
24826 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
24827 pmd++, pmd_idx++) {
24828 pte = page_table_kmap_check(one_page_table_init(pmd),
24829 @@ -224,11 +215,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
24830 }
24831 }
24832
24833 -static inline int is_kernel_text(unsigned long addr)
24834 +static inline int is_kernel_text(unsigned long start, unsigned long end)
24835 {
24836 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
24837 - return 1;
24838 - return 0;
24839 + if ((start > ktla_ktva((unsigned long)_etext) ||
24840 + end <= ktla_ktva((unsigned long)_stext)) &&
24841 + (start > ktla_ktva((unsigned long)_einittext) ||
24842 + end <= ktla_ktva((unsigned long)_sinittext)) &&
24843 +
24844 +#ifdef CONFIG_ACPI_SLEEP
24845 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
24846 +#endif
24847 +
24848 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
24849 + return 0;
24850 + return 1;
24851 }
24852
24853 /*
24854 @@ -245,9 +245,10 @@ kernel_physical_mapping_init(unsigned long start,
24855 unsigned long last_map_addr = end;
24856 unsigned long start_pfn, end_pfn;
24857 pgd_t *pgd_base = swapper_pg_dir;
24858 - int pgd_idx, pmd_idx, pte_ofs;
24859 + unsigned int pgd_idx, pmd_idx, pte_ofs;
24860 unsigned long pfn;
24861 pgd_t *pgd;
24862 + pud_t *pud;
24863 pmd_t *pmd;
24864 pte_t *pte;
24865 unsigned pages_2m, pages_4k;
24866 @@ -280,8 +281,13 @@ repeat:
24867 pfn = start_pfn;
24868 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24869 pgd = pgd_base + pgd_idx;
24870 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
24871 - pmd = one_md_table_init(pgd);
24872 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
24873 + pud = pud_offset(pgd, 0);
24874 + pmd = pmd_offset(pud, 0);
24875 +
24876 +#ifdef CONFIG_X86_PAE
24877 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
24878 +#endif
24879
24880 if (pfn >= end_pfn)
24881 continue;
24882 @@ -293,14 +299,13 @@ repeat:
24883 #endif
24884 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
24885 pmd++, pmd_idx++) {
24886 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
24887 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
24888
24889 /*
24890 * Map with big pages if possible, otherwise
24891 * create normal page tables:
24892 */
24893 if (use_pse) {
24894 - unsigned int addr2;
24895 pgprot_t prot = PAGE_KERNEL_LARGE;
24896 /*
24897 * first pass will use the same initial
24898 @@ -310,11 +315,7 @@ repeat:
24899 __pgprot(PTE_IDENT_ATTR |
24900 _PAGE_PSE);
24901
24902 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
24903 - PAGE_OFFSET + PAGE_SIZE-1;
24904 -
24905 - if (is_kernel_text(addr) ||
24906 - is_kernel_text(addr2))
24907 + if (is_kernel_text(address, address + PMD_SIZE))
24908 prot = PAGE_KERNEL_LARGE_EXEC;
24909
24910 pages_2m++;
24911 @@ -331,7 +332,7 @@ repeat:
24912 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
24913 pte += pte_ofs;
24914 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
24915 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
24916 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
24917 pgprot_t prot = PAGE_KERNEL;
24918 /*
24919 * first pass will use the same initial
24920 @@ -339,7 +340,7 @@ repeat:
24921 */
24922 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
24923
24924 - if (is_kernel_text(addr))
24925 + if (is_kernel_text(address, address + PAGE_SIZE))
24926 prot = PAGE_KERNEL_EXEC;
24927
24928 pages_4k++;
24929 @@ -465,7 +466,7 @@ void __init native_pagetable_setup_start(pgd_t *base)
24930
24931 pud = pud_offset(pgd, va);
24932 pmd = pmd_offset(pud, va);
24933 - if (!pmd_present(*pmd))
24934 + if (!pmd_present(*pmd) || pmd_huge(*pmd))
24935 break;
24936
24937 pte = pte_offset_kernel(pmd, va);
24938 @@ -517,12 +518,10 @@ void __init early_ioremap_page_table_range_init(void)
24939
24940 static void __init pagetable_init(void)
24941 {
24942 - pgd_t *pgd_base = swapper_pg_dir;
24943 -
24944 - permanent_kmaps_init(pgd_base);
24945 + permanent_kmaps_init(swapper_pg_dir);
24946 }
24947
24948 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24949 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
24950 EXPORT_SYMBOL_GPL(__supported_pte_mask);
24951
24952 /* user-defined highmem size */
24953 @@ -734,6 +733,12 @@ void __init mem_init(void)
24954
24955 pci_iommu_alloc();
24956
24957 +#ifdef CONFIG_PAX_PER_CPU_PGD
24958 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
24959 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
24960 + KERNEL_PGD_PTRS);
24961 +#endif
24962 +
24963 #ifdef CONFIG_FLATMEM
24964 BUG_ON(!mem_map);
24965 #endif
24966 @@ -760,7 +765,7 @@ void __init mem_init(void)
24967 reservedpages++;
24968
24969 codesize = (unsigned long) &_etext - (unsigned long) &_text;
24970 - datasize = (unsigned long) &_edata - (unsigned long) &_etext;
24971 + datasize = (unsigned long) &_edata - (unsigned long) &_sdata;
24972 initsize = (unsigned long) &__init_end - (unsigned long) &__init_begin;
24973
24974 printk(KERN_INFO "Memory: %luk/%luk available (%dk kernel code, "
24975 @@ -801,10 +806,10 @@ void __init mem_init(void)
24976 ((unsigned long)&__init_end -
24977 (unsigned long)&__init_begin) >> 10,
24978
24979 - (unsigned long)&_etext, (unsigned long)&_edata,
24980 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
24981 + (unsigned long)&_sdata, (unsigned long)&_edata,
24982 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
24983
24984 - (unsigned long)&_text, (unsigned long)&_etext,
24985 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
24986 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
24987
24988 /*
24989 @@ -882,6 +887,7 @@ void set_kernel_text_rw(void)
24990 if (!kernel_set_to_readonly)
24991 return;
24992
24993 + start = ktla_ktva(start);
24994 pr_debug("Set kernel text: %lx - %lx for read write\n",
24995 start, start+size);
24996
24997 @@ -896,6 +902,7 @@ void set_kernel_text_ro(void)
24998 if (!kernel_set_to_readonly)
24999 return;
25000
25001 + start = ktla_ktva(start);
25002 pr_debug("Set kernel text: %lx - %lx for read only\n",
25003 start, start+size);
25004
25005 @@ -924,6 +931,7 @@ void mark_rodata_ro(void)
25006 unsigned long start = PFN_ALIGN(_text);
25007 unsigned long size = PFN_ALIGN(_etext) - start;
25008
25009 + start = ktla_ktva(start);
25010 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
25011 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
25012 size >> 10);
25013 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
25014 index 2b6b4a3..c17210d 100644
25015 --- a/arch/x86/mm/init_64.c
25016 +++ b/arch/x86/mm/init_64.c
25017 @@ -74,7 +74,7 @@ early_param("gbpages", parse_direct_gbpages_on);
25018 * around without checking the pgd every time.
25019 */
25020
25021 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
25022 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
25023 EXPORT_SYMBOL_GPL(__supported_pte_mask);
25024
25025 int force_personality32;
25026 @@ -107,12 +107,22 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25027
25028 for (address = start; address <= end; address += PGDIR_SIZE) {
25029 const pgd_t *pgd_ref = pgd_offset_k(address);
25030 +
25031 +#ifdef CONFIG_PAX_PER_CPU_PGD
25032 + unsigned long cpu;
25033 +#else
25034 struct page *page;
25035 +#endif
25036
25037 if (pgd_none(*pgd_ref))
25038 continue;
25039
25040 spin_lock(&pgd_lock);
25041 +
25042 +#ifdef CONFIG_PAX_PER_CPU_PGD
25043 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25044 + pgd_t *pgd = pgd_offset_cpu(cpu, address);
25045 +#else
25046 list_for_each_entry(page, &pgd_list, lru) {
25047 pgd_t *pgd;
25048 spinlock_t *pgt_lock;
25049 @@ -121,6 +131,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25050 /* the pgt_lock only for Xen */
25051 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
25052 spin_lock(pgt_lock);
25053 +#endif
25054
25055 if (pgd_none(*pgd))
25056 set_pgd(pgd, *pgd_ref);
25057 @@ -128,7 +139,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
25058 BUG_ON(pgd_page_vaddr(*pgd)
25059 != pgd_page_vaddr(*pgd_ref));
25060
25061 +#ifndef CONFIG_PAX_PER_CPU_PGD
25062 spin_unlock(pgt_lock);
25063 +#endif
25064 +
25065 }
25066 spin_unlock(&pgd_lock);
25067 }
25068 @@ -161,7 +175,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
25069 {
25070 if (pgd_none(*pgd)) {
25071 pud_t *pud = (pud_t *)spp_getpage();
25072 - pgd_populate(&init_mm, pgd, pud);
25073 + pgd_populate_kernel(&init_mm, pgd, pud);
25074 if (pud != pud_offset(pgd, 0))
25075 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
25076 pud, pud_offset(pgd, 0));
25077 @@ -173,7 +187,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
25078 {
25079 if (pud_none(*pud)) {
25080 pmd_t *pmd = (pmd_t *) spp_getpage();
25081 - pud_populate(&init_mm, pud, pmd);
25082 + pud_populate_kernel(&init_mm, pud, pmd);
25083 if (pmd != pmd_offset(pud, 0))
25084 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
25085 pmd, pmd_offset(pud, 0));
25086 @@ -202,7 +216,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
25087 pmd = fill_pmd(pud, vaddr);
25088 pte = fill_pte(pmd, vaddr);
25089
25090 + pax_open_kernel();
25091 set_pte(pte, new_pte);
25092 + pax_close_kernel();
25093
25094 /*
25095 * It's enough to flush this one mapping.
25096 @@ -261,14 +277,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
25097 pgd = pgd_offset_k((unsigned long)__va(phys));
25098 if (pgd_none(*pgd)) {
25099 pud = (pud_t *) spp_getpage();
25100 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
25101 - _PAGE_USER));
25102 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
25103 }
25104 pud = pud_offset(pgd, (unsigned long)__va(phys));
25105 if (pud_none(*pud)) {
25106 pmd = (pmd_t *) spp_getpage();
25107 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
25108 - _PAGE_USER));
25109 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
25110 }
25111 pmd = pmd_offset(pud, phys);
25112 BUG_ON(!pmd_none(*pmd));
25113 @@ -329,7 +343,7 @@ static __ref void *alloc_low_page(unsigned long *phys)
25114 if (pfn >= pgt_buf_top)
25115 panic("alloc_low_page: ran out of memory");
25116
25117 - adr = early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25118 + adr = (void __force_kernel *)early_memremap(pfn * PAGE_SIZE, PAGE_SIZE);
25119 clear_page(adr);
25120 *phys = pfn * PAGE_SIZE;
25121 return adr;
25122 @@ -345,7 +359,7 @@ static __ref void *map_low_page(void *virt)
25123
25124 phys = __pa(virt);
25125 left = phys & (PAGE_SIZE - 1);
25126 - adr = early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25127 + adr = (void __force_kernel *)early_memremap(phys & PAGE_MASK, PAGE_SIZE);
25128 adr = (void *)(((unsigned long)adr) | left);
25129
25130 return adr;
25131 @@ -548,7 +562,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
25132 unmap_low_page(pmd);
25133
25134 spin_lock(&init_mm.page_table_lock);
25135 - pud_populate(&init_mm, pud, __va(pmd_phys));
25136 + pud_populate_kernel(&init_mm, pud, __va(pmd_phys));
25137 spin_unlock(&init_mm.page_table_lock);
25138 }
25139 __flush_tlb_all();
25140 @@ -594,7 +608,7 @@ kernel_physical_mapping_init(unsigned long start,
25141 unmap_low_page(pud);
25142
25143 spin_lock(&init_mm.page_table_lock);
25144 - pgd_populate(&init_mm, pgd, __va(pud_phys));
25145 + pgd_populate_kernel(&init_mm, pgd, __va(pud_phys));
25146 spin_unlock(&init_mm.page_table_lock);
25147 pgd_changed = true;
25148 }
25149 @@ -686,6 +700,12 @@ void __init mem_init(void)
25150
25151 pci_iommu_alloc();
25152
25153 +#ifdef CONFIG_PAX_PER_CPU_PGD
25154 + clone_pgd_range(get_cpu_pgd(0) + KERNEL_PGD_BOUNDARY,
25155 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
25156 + KERNEL_PGD_PTRS);
25157 +#endif
25158 +
25159 /* clear_bss() already clear the empty_zero_page */
25160
25161 reservedpages = 0;
25162 @@ -846,8 +866,8 @@ int kern_addr_valid(unsigned long addr)
25163 static struct vm_area_struct gate_vma = {
25164 .vm_start = VSYSCALL_START,
25165 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
25166 - .vm_page_prot = PAGE_READONLY_EXEC,
25167 - .vm_flags = VM_READ | VM_EXEC
25168 + .vm_page_prot = PAGE_READONLY,
25169 + .vm_flags = VM_READ
25170 };
25171
25172 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
25173 @@ -881,7 +901,7 @@ int in_gate_area_no_mm(unsigned long addr)
25174
25175 const char *arch_vma_name(struct vm_area_struct *vma)
25176 {
25177 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
25178 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
25179 return "[vdso]";
25180 if (vma == &gate_vma)
25181 return "[vsyscall]";
25182 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
25183 index 7b179b4..6bd1777 100644
25184 --- a/arch/x86/mm/iomap_32.c
25185 +++ b/arch/x86/mm/iomap_32.c
25186 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
25187 type = kmap_atomic_idx_push();
25188 idx = type + KM_TYPE_NR * smp_processor_id();
25189 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
25190 +
25191 + pax_open_kernel();
25192 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
25193 + pax_close_kernel();
25194 +
25195 arch_flush_lazy_mmu_mode();
25196
25197 return (void *)vaddr;
25198 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
25199 index 78fe3f1..8293b6f 100644
25200 --- a/arch/x86/mm/ioremap.c
25201 +++ b/arch/x86/mm/ioremap.c
25202 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
25203 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
25204 int is_ram = page_is_ram(pfn);
25205
25206 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
25207 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
25208 return NULL;
25209 WARN_ON_ONCE(is_ram);
25210 }
25211 @@ -315,6 +315,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
25212
25213 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
25214 if (page_is_ram(start >> PAGE_SHIFT))
25215 +#ifdef CONFIG_HIGHMEM
25216 + if ((start >> PAGE_SHIFT) < max_low_pfn)
25217 +#endif
25218 return __va(phys);
25219
25220 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
25221 @@ -344,7 +347,7 @@ static int __init early_ioremap_debug_setup(char *str)
25222 early_param("early_ioremap_debug", early_ioremap_debug_setup);
25223
25224 static __initdata int after_paging_init;
25225 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
25226 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
25227
25228 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
25229 {
25230 @@ -381,8 +384,7 @@ void __init early_ioremap_init(void)
25231 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
25232
25233 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
25234 - memset(bm_pte, 0, sizeof(bm_pte));
25235 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
25236 + pmd_populate_user(&init_mm, pmd, bm_pte);
25237
25238 /*
25239 * The boot-ioremap range spans multiple pmds, for which
25240 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
25241 index d87dd6d..bf3fa66 100644
25242 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
25243 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
25244 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
25245 * memory (e.g. tracked pages)? For now, we need this to avoid
25246 * invoking kmemcheck for PnP BIOS calls.
25247 */
25248 - if (regs->flags & X86_VM_MASK)
25249 + if (v8086_mode(regs))
25250 return false;
25251 - if (regs->cs != __KERNEL_CS)
25252 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
25253 return false;
25254
25255 pte = kmemcheck_pte_lookup(address);
25256 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
25257 index 845df68..1d8d29f 100644
25258 --- a/arch/x86/mm/mmap.c
25259 +++ b/arch/x86/mm/mmap.c
25260 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
25261 * Leave an at least ~128 MB hole with possible stack randomization.
25262 */
25263 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
25264 -#define MAX_GAP (TASK_SIZE/6*5)
25265 +#define MAX_GAP (pax_task_size/6*5)
25266
25267 static int mmap_is_legacy(void)
25268 {
25269 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
25270 return rnd << PAGE_SHIFT;
25271 }
25272
25273 -static unsigned long mmap_base(void)
25274 +static unsigned long mmap_base(struct mm_struct *mm)
25275 {
25276 unsigned long gap = rlimit(RLIMIT_STACK);
25277 + unsigned long pax_task_size = TASK_SIZE;
25278 +
25279 +#ifdef CONFIG_PAX_SEGMEXEC
25280 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25281 + pax_task_size = SEGMEXEC_TASK_SIZE;
25282 +#endif
25283
25284 if (gap < MIN_GAP)
25285 gap = MIN_GAP;
25286 else if (gap > MAX_GAP)
25287 gap = MAX_GAP;
25288
25289 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
25290 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
25291 }
25292
25293 /*
25294 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
25295 * does, but not when emulating X86_32
25296 */
25297 -static unsigned long mmap_legacy_base(void)
25298 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
25299 {
25300 - if (mmap_is_ia32())
25301 + if (mmap_is_ia32()) {
25302 +
25303 +#ifdef CONFIG_PAX_SEGMEXEC
25304 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
25305 + return SEGMEXEC_TASK_UNMAPPED_BASE;
25306 + else
25307 +#endif
25308 +
25309 return TASK_UNMAPPED_BASE;
25310 - else
25311 + } else
25312 return TASK_UNMAPPED_BASE + mmap_rnd();
25313 }
25314
25315 @@ -113,11 +126,23 @@ static unsigned long mmap_legacy_base(void)
25316 void arch_pick_mmap_layout(struct mm_struct *mm)
25317 {
25318 if (mmap_is_legacy()) {
25319 - mm->mmap_base = mmap_legacy_base();
25320 + mm->mmap_base = mmap_legacy_base(mm);
25321 +
25322 +#ifdef CONFIG_PAX_RANDMMAP
25323 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25324 + mm->mmap_base += mm->delta_mmap;
25325 +#endif
25326 +
25327 mm->get_unmapped_area = arch_get_unmapped_area;
25328 mm->unmap_area = arch_unmap_area;
25329 } else {
25330 - mm->mmap_base = mmap_base();
25331 + mm->mmap_base = mmap_base(mm);
25332 +
25333 +#ifdef CONFIG_PAX_RANDMMAP
25334 + if (mm->pax_flags & MF_PAX_RANDMMAP)
25335 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
25336 +#endif
25337 +
25338 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
25339 mm->unmap_area = arch_unmap_area_topdown;
25340 }
25341 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
25342 index dc0b727..dc9d71a 100644
25343 --- a/arch/x86/mm/mmio-mod.c
25344 +++ b/arch/x86/mm/mmio-mod.c
25345 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
25346 break;
25347 default:
25348 {
25349 - unsigned char *ip = (unsigned char *)instptr;
25350 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
25351 my_trace->opcode = MMIO_UNKNOWN_OP;
25352 my_trace->width = 0;
25353 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
25354 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
25355 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25356 void __iomem *addr)
25357 {
25358 - static atomic_t next_id;
25359 + static atomic_unchecked_t next_id;
25360 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
25361 /* These are page-unaligned. */
25362 struct mmiotrace_map map = {
25363 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
25364 .private = trace
25365 },
25366 .phys = offset,
25367 - .id = atomic_inc_return(&next_id)
25368 + .id = atomic_inc_return_unchecked(&next_id)
25369 };
25370 map.map_id = trace->id;
25371
25372 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
25373 index b008656..773eac2 100644
25374 --- a/arch/x86/mm/pageattr-test.c
25375 +++ b/arch/x86/mm/pageattr-test.c
25376 @@ -36,7 +36,7 @@ enum {
25377
25378 static int pte_testbit(pte_t pte)
25379 {
25380 - return pte_flags(pte) & _PAGE_UNUSED1;
25381 + return pte_flags(pte) & _PAGE_CPA_TEST;
25382 }
25383
25384 struct split_state {
25385 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
25386 index a718e0d..45efc32 100644
25387 --- a/arch/x86/mm/pageattr.c
25388 +++ b/arch/x86/mm/pageattr.c
25389 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25390 */
25391 #ifdef CONFIG_PCI_BIOS
25392 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
25393 - pgprot_val(forbidden) |= _PAGE_NX;
25394 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25395 #endif
25396
25397 /*
25398 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25399 * Does not cover __inittext since that is gone later on. On
25400 * 64bit we do not enforce !NX on the low mapping
25401 */
25402 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
25403 - pgprot_val(forbidden) |= _PAGE_NX;
25404 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
25405 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25406
25407 +#ifdef CONFIG_DEBUG_RODATA
25408 /*
25409 * The .rodata section needs to be read-only. Using the pfn
25410 * catches all aliases.
25411 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25412 if (within(pfn, __pa((unsigned long)__start_rodata) >> PAGE_SHIFT,
25413 __pa((unsigned long)__end_rodata) >> PAGE_SHIFT))
25414 pgprot_val(forbidden) |= _PAGE_RW;
25415 +#endif
25416
25417 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
25418 /*
25419 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
25420 }
25421 #endif
25422
25423 +#ifdef CONFIG_PAX_KERNEXEC
25424 + if (within(pfn, __pa((unsigned long)&_text), __pa((unsigned long)&_sdata))) {
25425 + pgprot_val(forbidden) |= _PAGE_RW;
25426 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
25427 + }
25428 +#endif
25429 +
25430 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
25431
25432 return prot;
25433 @@ -369,23 +378,37 @@ EXPORT_SYMBOL_GPL(lookup_address);
25434 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
25435 {
25436 /* change init_mm */
25437 + pax_open_kernel();
25438 set_pte_atomic(kpte, pte);
25439 +
25440 #ifdef CONFIG_X86_32
25441 if (!SHARED_KERNEL_PMD) {
25442 +
25443 +#ifdef CONFIG_PAX_PER_CPU_PGD
25444 + unsigned long cpu;
25445 +#else
25446 struct page *page;
25447 +#endif
25448
25449 +#ifdef CONFIG_PAX_PER_CPU_PGD
25450 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
25451 + pgd_t *pgd = get_cpu_pgd(cpu);
25452 +#else
25453 list_for_each_entry(page, &pgd_list, lru) {
25454 - pgd_t *pgd;
25455 + pgd_t *pgd = (pgd_t *)page_address(page);
25456 +#endif
25457 +
25458 pud_t *pud;
25459 pmd_t *pmd;
25460
25461 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
25462 + pgd += pgd_index(address);
25463 pud = pud_offset(pgd, address);
25464 pmd = pmd_offset(pud, address);
25465 set_pte_atomic((pte_t *)pmd, pte);
25466 }
25467 }
25468 #endif
25469 + pax_close_kernel();
25470 }
25471
25472 static int
25473 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
25474 index 3d68ef6..7f69136 100644
25475 --- a/arch/x86/mm/pat.c
25476 +++ b/arch/x86/mm/pat.c
25477 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
25478
25479 if (!entry) {
25480 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
25481 - current->comm, current->pid, start, end - 1);
25482 + current->comm, task_pid_nr(current), start, end - 1);
25483 return -EINVAL;
25484 }
25485
25486 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
25487
25488 while (cursor < to) {
25489 if (!devmem_is_allowed(pfn)) {
25490 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
25491 - current->comm, from, to - 1);
25492 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
25493 + current->comm, from, to - 1, cursor);
25494 return 0;
25495 }
25496 cursor += PAGE_SIZE;
25497 @@ -570,7 +570,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
25498 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
25499 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
25500 "for [mem %#010Lx-%#010Lx]\n",
25501 - current->comm, current->pid,
25502 + current->comm, task_pid_nr(current),
25503 cattr_name(flags),
25504 base, (unsigned long long)(base + size-1));
25505 return -EINVAL;
25506 @@ -605,7 +605,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25507 flags = lookup_memtype(paddr);
25508 if (want_flags != flags) {
25509 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
25510 - current->comm, current->pid,
25511 + current->comm, task_pid_nr(current),
25512 cattr_name(want_flags),
25513 (unsigned long long)paddr,
25514 (unsigned long long)(paddr + size - 1),
25515 @@ -627,7 +627,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
25516 free_memtype(paddr, paddr + size);
25517 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
25518 " for [mem %#010Lx-%#010Lx], got %s\n",
25519 - current->comm, current->pid,
25520 + current->comm, task_pid_nr(current),
25521 cattr_name(want_flags),
25522 (unsigned long long)paddr,
25523 (unsigned long long)(paddr + size - 1),
25524 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
25525 index 9f0614d..92ae64a 100644
25526 --- a/arch/x86/mm/pf_in.c
25527 +++ b/arch/x86/mm/pf_in.c
25528 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
25529 int i;
25530 enum reason_type rv = OTHERS;
25531
25532 - p = (unsigned char *)ins_addr;
25533 + p = (unsigned char *)ktla_ktva(ins_addr);
25534 p += skip_prefix(p, &prf);
25535 p += get_opcode(p, &opcode);
25536
25537 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
25538 struct prefix_bits prf;
25539 int i;
25540
25541 - p = (unsigned char *)ins_addr;
25542 + p = (unsigned char *)ktla_ktva(ins_addr);
25543 p += skip_prefix(p, &prf);
25544 p += get_opcode(p, &opcode);
25545
25546 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
25547 struct prefix_bits prf;
25548 int i;
25549
25550 - p = (unsigned char *)ins_addr;
25551 + p = (unsigned char *)ktla_ktva(ins_addr);
25552 p += skip_prefix(p, &prf);
25553 p += get_opcode(p, &opcode);
25554
25555 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
25556 struct prefix_bits prf;
25557 int i;
25558
25559 - p = (unsigned char *)ins_addr;
25560 + p = (unsigned char *)ktla_ktva(ins_addr);
25561 p += skip_prefix(p, &prf);
25562 p += get_opcode(p, &opcode);
25563 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
25564 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
25565 struct prefix_bits prf;
25566 int i;
25567
25568 - p = (unsigned char *)ins_addr;
25569 + p = (unsigned char *)ktla_ktva(ins_addr);
25570 p += skip_prefix(p, &prf);
25571 p += get_opcode(p, &opcode);
25572 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
25573 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
25574 index 8573b83..4f3ed7e 100644
25575 --- a/arch/x86/mm/pgtable.c
25576 +++ b/arch/x86/mm/pgtable.c
25577 @@ -84,10 +84,64 @@ static inline void pgd_list_del(pgd_t *pgd)
25578 list_del(&page->lru);
25579 }
25580
25581 -#define UNSHARED_PTRS_PER_PGD \
25582 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25583 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25584 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
25585
25586 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
25587 +{
25588 + unsigned int count = USER_PGD_PTRS;
25589
25590 + while (count--)
25591 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
25592 +}
25593 +#endif
25594 +
25595 +#ifdef CONFIG_PAX_PER_CPU_PGD
25596 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
25597 +{
25598 + unsigned int count = USER_PGD_PTRS;
25599 +
25600 + while (count--) {
25601 + pgd_t pgd;
25602 +
25603 +#ifdef CONFIG_X86_64
25604 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
25605 +#else
25606 + pgd = *src++;
25607 +#endif
25608 +
25609 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
25610 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
25611 +#endif
25612 +
25613 + *dst++ = pgd;
25614 + }
25615 +
25616 +}
25617 +#endif
25618 +
25619 +#ifdef CONFIG_X86_64
25620 +#define pxd_t pud_t
25621 +#define pyd_t pgd_t
25622 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
25623 +#define pxd_free(mm, pud) pud_free((mm), (pud))
25624 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
25625 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
25626 +#define PYD_SIZE PGDIR_SIZE
25627 +#else
25628 +#define pxd_t pmd_t
25629 +#define pyd_t pud_t
25630 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
25631 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
25632 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
25633 +#define pyd_offset(mm, address) pud_offset((mm), (address))
25634 +#define PYD_SIZE PUD_SIZE
25635 +#endif
25636 +
25637 +#ifdef CONFIG_PAX_PER_CPU_PGD
25638 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
25639 +static inline void pgd_dtor(pgd_t *pgd) {}
25640 +#else
25641 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
25642 {
25643 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
25644 @@ -128,6 +182,7 @@ static void pgd_dtor(pgd_t *pgd)
25645 pgd_list_del(pgd);
25646 spin_unlock(&pgd_lock);
25647 }
25648 +#endif
25649
25650 /*
25651 * List of all pgd's needed for non-PAE so it can invalidate entries
25652 @@ -140,7 +195,7 @@ static void pgd_dtor(pgd_t *pgd)
25653 * -- wli
25654 */
25655
25656 -#ifdef CONFIG_X86_PAE
25657 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25658 /*
25659 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
25660 * updating the top-level pagetable entries to guarantee the
25661 @@ -152,7 +207,7 @@ static void pgd_dtor(pgd_t *pgd)
25662 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
25663 * and initialize the kernel pmds here.
25664 */
25665 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
25666 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
25667
25668 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25669 {
25670 @@ -170,36 +225,38 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
25671 */
25672 flush_tlb_mm(mm);
25673 }
25674 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
25675 +#define PREALLOCATED_PXDS USER_PGD_PTRS
25676 #else /* !CONFIG_X86_PAE */
25677
25678 /* No need to prepopulate any pagetable entries in non-PAE modes. */
25679 -#define PREALLOCATED_PMDS 0
25680 +#define PREALLOCATED_PXDS 0
25681
25682 #endif /* CONFIG_X86_PAE */
25683
25684 -static void free_pmds(pmd_t *pmds[])
25685 +static void free_pxds(pxd_t *pxds[])
25686 {
25687 int i;
25688
25689 - for(i = 0; i < PREALLOCATED_PMDS; i++)
25690 - if (pmds[i])
25691 - free_page((unsigned long)pmds[i]);
25692 + for(i = 0; i < PREALLOCATED_PXDS; i++)
25693 + if (pxds[i])
25694 + free_page((unsigned long)pxds[i]);
25695 }
25696
25697 -static int preallocate_pmds(pmd_t *pmds[])
25698 +static int preallocate_pxds(pxd_t *pxds[])
25699 {
25700 int i;
25701 bool failed = false;
25702
25703 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25704 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
25705 - if (pmd == NULL)
25706 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25707 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
25708 + if (pxd == NULL)
25709 failed = true;
25710 - pmds[i] = pmd;
25711 + pxds[i] = pxd;
25712 }
25713
25714 if (failed) {
25715 - free_pmds(pmds);
25716 + free_pxds(pxds);
25717 return -ENOMEM;
25718 }
25719
25720 @@ -212,51 +269,55 @@ static int preallocate_pmds(pmd_t *pmds[])
25721 * preallocate which never got a corresponding vma will need to be
25722 * freed manually.
25723 */
25724 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
25725 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
25726 {
25727 int i;
25728
25729 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
25730 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
25731 pgd_t pgd = pgdp[i];
25732
25733 if (pgd_val(pgd) != 0) {
25734 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
25735 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
25736
25737 - pgdp[i] = native_make_pgd(0);
25738 + set_pgd(pgdp + i, native_make_pgd(0));
25739
25740 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
25741 - pmd_free(mm, pmd);
25742 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
25743 + pxd_free(mm, pxd);
25744 }
25745 }
25746 }
25747
25748 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
25749 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
25750 {
25751 - pud_t *pud;
25752 + pyd_t *pyd;
25753 unsigned long addr;
25754 int i;
25755
25756 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
25757 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
25758 return;
25759
25760 - pud = pud_offset(pgd, 0);
25761 +#ifdef CONFIG_X86_64
25762 + pyd = pyd_offset(mm, 0L);
25763 +#else
25764 + pyd = pyd_offset(pgd, 0L);
25765 +#endif
25766
25767 - for (addr = i = 0; i < PREALLOCATED_PMDS;
25768 - i++, pud++, addr += PUD_SIZE) {
25769 - pmd_t *pmd = pmds[i];
25770 + for (addr = i = 0; i < PREALLOCATED_PXDS;
25771 + i++, pyd++, addr += PYD_SIZE) {
25772 + pxd_t *pxd = pxds[i];
25773
25774 if (i >= KERNEL_PGD_BOUNDARY)
25775 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25776 - sizeof(pmd_t) * PTRS_PER_PMD);
25777 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
25778 + sizeof(pxd_t) * PTRS_PER_PMD);
25779
25780 - pud_populate(mm, pud, pmd);
25781 + pyd_populate(mm, pyd, pxd);
25782 }
25783 }
25784
25785 pgd_t *pgd_alloc(struct mm_struct *mm)
25786 {
25787 pgd_t *pgd;
25788 - pmd_t *pmds[PREALLOCATED_PMDS];
25789 + pxd_t *pxds[PREALLOCATED_PXDS];
25790
25791 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
25792
25793 @@ -265,11 +326,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25794
25795 mm->pgd = pgd;
25796
25797 - if (preallocate_pmds(pmds) != 0)
25798 + if (preallocate_pxds(pxds) != 0)
25799 goto out_free_pgd;
25800
25801 if (paravirt_pgd_alloc(mm) != 0)
25802 - goto out_free_pmds;
25803 + goto out_free_pxds;
25804
25805 /*
25806 * Make sure that pre-populating the pmds is atomic with
25807 @@ -279,14 +340,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
25808 spin_lock(&pgd_lock);
25809
25810 pgd_ctor(mm, pgd);
25811 - pgd_prepopulate_pmd(mm, pgd, pmds);
25812 + pgd_prepopulate_pxd(mm, pgd, pxds);
25813
25814 spin_unlock(&pgd_lock);
25815
25816 return pgd;
25817
25818 -out_free_pmds:
25819 - free_pmds(pmds);
25820 +out_free_pxds:
25821 + free_pxds(pxds);
25822 out_free_pgd:
25823 free_page((unsigned long)pgd);
25824 out:
25825 @@ -295,7 +356,7 @@ out:
25826
25827 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
25828 {
25829 - pgd_mop_up_pmds(mm, pgd);
25830 + pgd_mop_up_pxds(mm, pgd);
25831 pgd_dtor(pgd);
25832 paravirt_pgd_free(mm, pgd);
25833 free_page((unsigned long)pgd);
25834 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
25835 index a69bcb8..19068ab 100644
25836 --- a/arch/x86/mm/pgtable_32.c
25837 +++ b/arch/x86/mm/pgtable_32.c
25838 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
25839 return;
25840 }
25841 pte = pte_offset_kernel(pmd, vaddr);
25842 +
25843 + pax_open_kernel();
25844 if (pte_val(pteval))
25845 set_pte_at(&init_mm, vaddr, pte, pteval);
25846 else
25847 pte_clear(&init_mm, vaddr, pte);
25848 + pax_close_kernel();
25849
25850 /*
25851 * It's enough to flush this one mapping.
25852 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
25853 index 410531d..0f16030 100644
25854 --- a/arch/x86/mm/setup_nx.c
25855 +++ b/arch/x86/mm/setup_nx.c
25856 @@ -5,8 +5,10 @@
25857 #include <asm/pgtable.h>
25858 #include <asm/proto.h>
25859
25860 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25861 static int disable_nx __cpuinitdata;
25862
25863 +#ifndef CONFIG_PAX_PAGEEXEC
25864 /*
25865 * noexec = on|off
25866 *
25867 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
25868 return 0;
25869 }
25870 early_param("noexec", noexec_setup);
25871 +#endif
25872 +
25873 +#endif
25874
25875 void __cpuinit x86_configure_nx(void)
25876 {
25877 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
25878 if (cpu_has_nx && !disable_nx)
25879 __supported_pte_mask |= _PAGE_NX;
25880 else
25881 +#endif
25882 __supported_pte_mask &= ~_PAGE_NX;
25883 }
25884
25885 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
25886 index 5e57e11..64874249 100644
25887 --- a/arch/x86/mm/tlb.c
25888 +++ b/arch/x86/mm/tlb.c
25889 @@ -66,7 +66,11 @@ void leave_mm(int cpu)
25890 BUG();
25891 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
25892 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
25893 +
25894 +#ifndef CONFIG_PAX_PER_CPU_PGD
25895 load_cr3(swapper_pg_dir);
25896 +#endif
25897 +
25898 }
25899 }
25900 EXPORT_SYMBOL_GPL(leave_mm);
25901 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
25902 index 877b9a1..a8ecf42 100644
25903 --- a/arch/x86/net/bpf_jit.S
25904 +++ b/arch/x86/net/bpf_jit.S
25905 @@ -9,6 +9,7 @@
25906 */
25907 #include <linux/linkage.h>
25908 #include <asm/dwarf2.h>
25909 +#include <asm/alternative-asm.h>
25910
25911 /*
25912 * Calling convention :
25913 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
25914 jle bpf_slow_path_word
25915 mov (SKBDATA,%rsi),%eax
25916 bswap %eax /* ntohl() */
25917 + pax_force_retaddr
25918 ret
25919
25920 sk_load_half:
25921 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
25922 jle bpf_slow_path_half
25923 movzwl (SKBDATA,%rsi),%eax
25924 rol $8,%ax # ntohs()
25925 + pax_force_retaddr
25926 ret
25927
25928 sk_load_byte:
25929 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
25930 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
25931 jle bpf_slow_path_byte
25932 movzbl (SKBDATA,%rsi),%eax
25933 + pax_force_retaddr
25934 ret
25935
25936 /**
25937 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
25938 movzbl (SKBDATA,%rsi),%ebx
25939 and $15,%bl
25940 shl $2,%bl
25941 + pax_force_retaddr
25942 ret
25943
25944 /* rsi contains offset and can be scratched */
25945 @@ -109,6 +114,7 @@ bpf_slow_path_word:
25946 js bpf_error
25947 mov -12(%rbp),%eax
25948 bswap %eax
25949 + pax_force_retaddr
25950 ret
25951
25952 bpf_slow_path_half:
25953 @@ -117,12 +123,14 @@ bpf_slow_path_half:
25954 mov -12(%rbp),%ax
25955 rol $8,%ax
25956 movzwl %ax,%eax
25957 + pax_force_retaddr
25958 ret
25959
25960 bpf_slow_path_byte:
25961 bpf_slow_path_common(1)
25962 js bpf_error
25963 movzbl -12(%rbp),%eax
25964 + pax_force_retaddr
25965 ret
25966
25967 bpf_slow_path_byte_msh:
25968 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
25969 and $15,%al
25970 shl $2,%al
25971 xchg %eax,%ebx
25972 + pax_force_retaddr
25973 ret
25974
25975 #define sk_negative_common(SIZE) \
25976 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
25977 sk_negative_common(4)
25978 mov (%rax), %eax
25979 bswap %eax
25980 + pax_force_retaddr
25981 ret
25982
25983 bpf_slow_path_half_neg:
25984 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
25985 mov (%rax),%ax
25986 rol $8,%ax
25987 movzwl %ax,%eax
25988 + pax_force_retaddr
25989 ret
25990
25991 bpf_slow_path_byte_neg:
25992 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
25993 .globl sk_load_byte_negative_offset
25994 sk_negative_common(1)
25995 movzbl (%rax), %eax
25996 + pax_force_retaddr
25997 ret
25998
25999 bpf_slow_path_byte_msh_neg:
26000 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
26001 and $15,%al
26002 shl $2,%al
26003 xchg %eax,%ebx
26004 + pax_force_retaddr
26005 ret
26006
26007 bpf_error:
26008 @@ -197,4 +210,5 @@ bpf_error:
26009 xor %eax,%eax
26010 mov -8(%rbp),%rbx
26011 leaveq
26012 + pax_force_retaddr
26013 ret
26014 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
26015 index 0597f95..a12c36e 100644
26016 --- a/arch/x86/net/bpf_jit_comp.c
26017 +++ b/arch/x86/net/bpf_jit_comp.c
26018 @@ -120,6 +120,11 @@ static inline void bpf_flush_icache(void *start, void *end)
26019 set_fs(old_fs);
26020 }
26021
26022 +struct bpf_jit_work {
26023 + struct work_struct work;
26024 + void *image;
26025 +};
26026 +
26027 #define CHOOSE_LOAD_FUNC(K, func) \
26028 ((int)K < 0 ? ((int)K >= SKF_LL_OFF ? func##_negative_offset : func) : func##_positive_offset)
26029
26030 @@ -146,6 +151,10 @@ void bpf_jit_compile(struct sk_filter *fp)
26031 if (addrs == NULL)
26032 return;
26033
26034 + fp->work = kmalloc(sizeof(*fp->work), GFP_KERNEL);
26035 + if (!fp->work)
26036 + goto out;
26037 +
26038 /* Before first pass, make a rough estimation of addrs[]
26039 * each bpf instruction is translated to less than 64 bytes
26040 */
26041 @@ -589,17 +598,18 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26042 break;
26043 default:
26044 /* hmm, too complex filter, give up with jit compiler */
26045 - goto out;
26046 + goto error;
26047 }
26048 ilen = prog - temp;
26049 if (image) {
26050 if (unlikely(proglen + ilen > oldproglen)) {
26051 pr_err("bpb_jit_compile fatal error\n");
26052 - kfree(addrs);
26053 - module_free(NULL, image);
26054 - return;
26055 + module_free_exec(NULL, image);
26056 + goto error;
26057 }
26058 + pax_open_kernel();
26059 memcpy(image + proglen, temp, ilen);
26060 + pax_close_kernel();
26061 }
26062 proglen += ilen;
26063 addrs[i] = proglen;
26064 @@ -620,11 +630,9 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26065 break;
26066 }
26067 if (proglen == oldproglen) {
26068 - image = module_alloc(max_t(unsigned int,
26069 - proglen,
26070 - sizeof(struct work_struct)));
26071 + image = module_alloc_exec(proglen);
26072 if (!image)
26073 - goto out;
26074 + goto error;
26075 }
26076 oldproglen = proglen;
26077 }
26078 @@ -640,7 +648,10 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
26079 bpf_flush_icache(image, image + proglen);
26080
26081 fp->bpf_func = (void *)image;
26082 - }
26083 + } else
26084 +error:
26085 + kfree(fp->work);
26086 +
26087 out:
26088 kfree(addrs);
26089 return;
26090 @@ -648,18 +659,20 @@ out:
26091
26092 static void jit_free_defer(struct work_struct *arg)
26093 {
26094 - module_free(NULL, arg);
26095 + module_free_exec(NULL, ((struct bpf_jit_work *)arg)->image);
26096 + kfree(arg);
26097 }
26098
26099 /* run from softirq, we must use a work_struct to call
26100 - * module_free() from process context
26101 + * module_free_exec() from process context
26102 */
26103 void bpf_jit_free(struct sk_filter *fp)
26104 {
26105 if (fp->bpf_func != sk_run_filter) {
26106 - struct work_struct *work = (struct work_struct *)fp->bpf_func;
26107 + struct work_struct *work = &fp->work->work;
26108
26109 INIT_WORK(work, jit_free_defer);
26110 + fp->work->image = fp->bpf_func;
26111 schedule_work(work);
26112 }
26113 }
26114 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
26115 index d6aa6e8..266395a 100644
26116 --- a/arch/x86/oprofile/backtrace.c
26117 +++ b/arch/x86/oprofile/backtrace.c
26118 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
26119 struct stack_frame_ia32 *fp;
26120 unsigned long bytes;
26121
26122 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26123 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26124 if (bytes != sizeof(bufhead))
26125 return NULL;
26126
26127 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
26128 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
26129
26130 oprofile_add_trace(bufhead[0].return_address);
26131
26132 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
26133 struct stack_frame bufhead[2];
26134 unsigned long bytes;
26135
26136 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
26137 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
26138 if (bytes != sizeof(bufhead))
26139 return NULL;
26140
26141 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
26142 {
26143 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
26144
26145 - if (!user_mode_vm(regs)) {
26146 + if (!user_mode(regs)) {
26147 unsigned long stack = kernel_stack_pointer(regs);
26148 if (depth)
26149 dump_trace(NULL, regs, (unsigned long *)stack, 0,
26150 diff --git a/arch/x86/pci/mrst.c b/arch/x86/pci/mrst.c
26151 index 140942f..8a5cc55 100644
26152 --- a/arch/x86/pci/mrst.c
26153 +++ b/arch/x86/pci/mrst.c
26154 @@ -238,7 +238,9 @@ int __init pci_mrst_init(void)
26155 printk(KERN_INFO "Intel MID platform detected, using MID PCI ops\n");
26156 pci_mmcfg_late_init();
26157 pcibios_enable_irq = mrst_pci_irq_enable;
26158 - pci_root_ops = pci_mrst_ops;
26159 + pax_open_kernel();
26160 + memcpy((void *)&pci_root_ops, &pci_mrst_ops, sizeof(pci_mrst_ops));
26161 + pax_close_kernel();
26162 pci_soc_mode = 1;
26163 /* Continue with standard init */
26164 return 1;
26165 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
26166 index da8fe05..7ee6704 100644
26167 --- a/arch/x86/pci/pcbios.c
26168 +++ b/arch/x86/pci/pcbios.c
26169 @@ -79,50 +79,93 @@ union bios32 {
26170 static struct {
26171 unsigned long address;
26172 unsigned short segment;
26173 -} bios32_indirect = { 0, __KERNEL_CS };
26174 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
26175
26176 /*
26177 * Returns the entry point for the given service, NULL on error
26178 */
26179
26180 -static unsigned long bios32_service(unsigned long service)
26181 +static unsigned long __devinit bios32_service(unsigned long service)
26182 {
26183 unsigned char return_code; /* %al */
26184 unsigned long address; /* %ebx */
26185 unsigned long length; /* %ecx */
26186 unsigned long entry; /* %edx */
26187 unsigned long flags;
26188 + struct desc_struct d, *gdt;
26189
26190 local_irq_save(flags);
26191 - __asm__("lcall *(%%edi); cld"
26192 +
26193 + gdt = get_cpu_gdt_table(smp_processor_id());
26194 +
26195 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
26196 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26197 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
26198 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26199 +
26200 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
26201 : "=a" (return_code),
26202 "=b" (address),
26203 "=c" (length),
26204 "=d" (entry)
26205 : "0" (service),
26206 "1" (0),
26207 - "D" (&bios32_indirect));
26208 + "D" (&bios32_indirect),
26209 + "r"(__PCIBIOS_DS)
26210 + : "memory");
26211 +
26212 + pax_open_kernel();
26213 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
26214 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
26215 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
26216 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
26217 + pax_close_kernel();
26218 +
26219 local_irq_restore(flags);
26220
26221 switch (return_code) {
26222 - case 0:
26223 - return address + entry;
26224 - case 0x80: /* Not present */
26225 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26226 - return 0;
26227 - default: /* Shouldn't happen */
26228 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26229 - service, return_code);
26230 + case 0: {
26231 + int cpu;
26232 + unsigned char flags;
26233 +
26234 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
26235 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
26236 + printk(KERN_WARNING "bios32_service: not valid\n");
26237 return 0;
26238 + }
26239 + address = address + PAGE_OFFSET;
26240 + length += 16UL; /* some BIOSs underreport this... */
26241 + flags = 4;
26242 + if (length >= 64*1024*1024) {
26243 + length >>= PAGE_SHIFT;
26244 + flags |= 8;
26245 + }
26246 +
26247 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
26248 + gdt = get_cpu_gdt_table(cpu);
26249 + pack_descriptor(&d, address, length, 0x9b, flags);
26250 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
26251 + pack_descriptor(&d, address, length, 0x93, flags);
26252 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
26253 + }
26254 + return entry;
26255 + }
26256 + case 0x80: /* Not present */
26257 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
26258 + return 0;
26259 + default: /* Shouldn't happen */
26260 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
26261 + service, return_code);
26262 + return 0;
26263 }
26264 }
26265
26266 static struct {
26267 unsigned long address;
26268 unsigned short segment;
26269 -} pci_indirect = { 0, __KERNEL_CS };
26270 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
26271
26272 -static int pci_bios_present;
26273 +static int pci_bios_present __read_only;
26274
26275 static int __devinit check_pcibios(void)
26276 {
26277 @@ -131,11 +174,13 @@ static int __devinit check_pcibios(void)
26278 unsigned long flags, pcibios_entry;
26279
26280 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
26281 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
26282 + pci_indirect.address = pcibios_entry;
26283
26284 local_irq_save(flags);
26285 - __asm__(
26286 - "lcall *(%%edi); cld\n\t"
26287 + __asm__("movw %w6, %%ds\n\t"
26288 + "lcall *%%ss:(%%edi); cld\n\t"
26289 + "push %%ss\n\t"
26290 + "pop %%ds\n\t"
26291 "jc 1f\n\t"
26292 "xor %%ah, %%ah\n"
26293 "1:"
26294 @@ -144,7 +189,8 @@ static int __devinit check_pcibios(void)
26295 "=b" (ebx),
26296 "=c" (ecx)
26297 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
26298 - "D" (&pci_indirect)
26299 + "D" (&pci_indirect),
26300 + "r" (__PCIBIOS_DS)
26301 : "memory");
26302 local_irq_restore(flags);
26303
26304 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26305
26306 switch (len) {
26307 case 1:
26308 - __asm__("lcall *(%%esi); cld\n\t"
26309 + __asm__("movw %w6, %%ds\n\t"
26310 + "lcall *%%ss:(%%esi); cld\n\t"
26311 + "push %%ss\n\t"
26312 + "pop %%ds\n\t"
26313 "jc 1f\n\t"
26314 "xor %%ah, %%ah\n"
26315 "1:"
26316 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26317 : "1" (PCIBIOS_READ_CONFIG_BYTE),
26318 "b" (bx),
26319 "D" ((long)reg),
26320 - "S" (&pci_indirect));
26321 + "S" (&pci_indirect),
26322 + "r" (__PCIBIOS_DS));
26323 /*
26324 * Zero-extend the result beyond 8 bits, do not trust the
26325 * BIOS having done it:
26326 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26327 *value &= 0xff;
26328 break;
26329 case 2:
26330 - __asm__("lcall *(%%esi); cld\n\t"
26331 + __asm__("movw %w6, %%ds\n\t"
26332 + "lcall *%%ss:(%%esi); cld\n\t"
26333 + "push %%ss\n\t"
26334 + "pop %%ds\n\t"
26335 "jc 1f\n\t"
26336 "xor %%ah, %%ah\n"
26337 "1:"
26338 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26339 : "1" (PCIBIOS_READ_CONFIG_WORD),
26340 "b" (bx),
26341 "D" ((long)reg),
26342 - "S" (&pci_indirect));
26343 + "S" (&pci_indirect),
26344 + "r" (__PCIBIOS_DS));
26345 /*
26346 * Zero-extend the result beyond 16 bits, do not trust the
26347 * BIOS having done it:
26348 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26349 *value &= 0xffff;
26350 break;
26351 case 4:
26352 - __asm__("lcall *(%%esi); cld\n\t"
26353 + __asm__("movw %w6, %%ds\n\t"
26354 + "lcall *%%ss:(%%esi); cld\n\t"
26355 + "push %%ss\n\t"
26356 + "pop %%ds\n\t"
26357 "jc 1f\n\t"
26358 "xor %%ah, %%ah\n"
26359 "1:"
26360 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
26361 : "1" (PCIBIOS_READ_CONFIG_DWORD),
26362 "b" (bx),
26363 "D" ((long)reg),
26364 - "S" (&pci_indirect));
26365 + "S" (&pci_indirect),
26366 + "r" (__PCIBIOS_DS));
26367 break;
26368 }
26369
26370 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26371
26372 switch (len) {
26373 case 1:
26374 - __asm__("lcall *(%%esi); cld\n\t"
26375 + __asm__("movw %w6, %%ds\n\t"
26376 + "lcall *%%ss:(%%esi); cld\n\t"
26377 + "push %%ss\n\t"
26378 + "pop %%ds\n\t"
26379 "jc 1f\n\t"
26380 "xor %%ah, %%ah\n"
26381 "1:"
26382 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26383 "c" (value),
26384 "b" (bx),
26385 "D" ((long)reg),
26386 - "S" (&pci_indirect));
26387 + "S" (&pci_indirect),
26388 + "r" (__PCIBIOS_DS));
26389 break;
26390 case 2:
26391 - __asm__("lcall *(%%esi); cld\n\t"
26392 + __asm__("movw %w6, %%ds\n\t"
26393 + "lcall *%%ss:(%%esi); cld\n\t"
26394 + "push %%ss\n\t"
26395 + "pop %%ds\n\t"
26396 "jc 1f\n\t"
26397 "xor %%ah, %%ah\n"
26398 "1:"
26399 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26400 "c" (value),
26401 "b" (bx),
26402 "D" ((long)reg),
26403 - "S" (&pci_indirect));
26404 + "S" (&pci_indirect),
26405 + "r" (__PCIBIOS_DS));
26406 break;
26407 case 4:
26408 - __asm__("lcall *(%%esi); cld\n\t"
26409 + __asm__("movw %w6, %%ds\n\t"
26410 + "lcall *%%ss:(%%esi); cld\n\t"
26411 + "push %%ss\n\t"
26412 + "pop %%ds\n\t"
26413 "jc 1f\n\t"
26414 "xor %%ah, %%ah\n"
26415 "1:"
26416 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
26417 "c" (value),
26418 "b" (bx),
26419 "D" ((long)reg),
26420 - "S" (&pci_indirect));
26421 + "S" (&pci_indirect),
26422 + "r" (__PCIBIOS_DS));
26423 break;
26424 }
26425
26426 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26427
26428 DBG("PCI: Fetching IRQ routing table... ");
26429 __asm__("push %%es\n\t"
26430 + "movw %w8, %%ds\n\t"
26431 "push %%ds\n\t"
26432 "pop %%es\n\t"
26433 - "lcall *(%%esi); cld\n\t"
26434 + "lcall *%%ss:(%%esi); cld\n\t"
26435 "pop %%es\n\t"
26436 + "push %%ss\n\t"
26437 + "pop %%ds\n"
26438 "jc 1f\n\t"
26439 "xor %%ah, %%ah\n"
26440 "1:"
26441 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
26442 "1" (0),
26443 "D" ((long) &opt),
26444 "S" (&pci_indirect),
26445 - "m" (opt)
26446 + "m" (opt),
26447 + "r" (__PCIBIOS_DS)
26448 : "memory");
26449 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
26450 if (ret & 0xff00)
26451 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26452 {
26453 int ret;
26454
26455 - __asm__("lcall *(%%esi); cld\n\t"
26456 + __asm__("movw %w5, %%ds\n\t"
26457 + "lcall *%%ss:(%%esi); cld\n\t"
26458 + "push %%ss\n\t"
26459 + "pop %%ds\n"
26460 "jc 1f\n\t"
26461 "xor %%ah, %%ah\n"
26462 "1:"
26463 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
26464 : "0" (PCIBIOS_SET_PCI_HW_INT),
26465 "b" ((dev->bus->number << 8) | dev->devfn),
26466 "c" ((irq << 8) | (pin + 10)),
26467 - "S" (&pci_indirect));
26468 + "S" (&pci_indirect),
26469 + "r" (__PCIBIOS_DS));
26470 return !(ret & 0xff00);
26471 }
26472 EXPORT_SYMBOL(pcibios_set_irq_routing);
26473 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
26474 index 40e4469..1ab536e 100644
26475 --- a/arch/x86/platform/efi/efi_32.c
26476 +++ b/arch/x86/platform/efi/efi_32.c
26477 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
26478 {
26479 struct desc_ptr gdt_descr;
26480
26481 +#ifdef CONFIG_PAX_KERNEXEC
26482 + struct desc_struct d;
26483 +#endif
26484 +
26485 local_irq_save(efi_rt_eflags);
26486
26487 load_cr3(initial_page_table);
26488 __flush_tlb_all();
26489
26490 +#ifdef CONFIG_PAX_KERNEXEC
26491 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
26492 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26493 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
26494 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26495 +#endif
26496 +
26497 gdt_descr.address = __pa(get_cpu_gdt_table(0));
26498 gdt_descr.size = GDT_SIZE - 1;
26499 load_gdt(&gdt_descr);
26500 @@ -58,6 +69,14 @@ void efi_call_phys_epilog(void)
26501 {
26502 struct desc_ptr gdt_descr;
26503
26504 +#ifdef CONFIG_PAX_KERNEXEC
26505 + struct desc_struct d;
26506 +
26507 + memset(&d, 0, sizeof d);
26508 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
26509 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
26510 +#endif
26511 +
26512 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
26513 gdt_descr.size = GDT_SIZE - 1;
26514 load_gdt(&gdt_descr);
26515 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
26516 index fbe66e6..eae5e38 100644
26517 --- a/arch/x86/platform/efi/efi_stub_32.S
26518 +++ b/arch/x86/platform/efi/efi_stub_32.S
26519 @@ -6,7 +6,9 @@
26520 */
26521
26522 #include <linux/linkage.h>
26523 +#include <linux/init.h>
26524 #include <asm/page_types.h>
26525 +#include <asm/segment.h>
26526
26527 /*
26528 * efi_call_phys(void *, ...) is a function with variable parameters.
26529 @@ -20,7 +22,7 @@
26530 * service functions will comply with gcc calling convention, too.
26531 */
26532
26533 -.text
26534 +__INIT
26535 ENTRY(efi_call_phys)
26536 /*
26537 * 0. The function can only be called in Linux kernel. So CS has been
26538 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
26539 * The mapping of lower virtual memory has been created in prelog and
26540 * epilog.
26541 */
26542 - movl $1f, %edx
26543 - subl $__PAGE_OFFSET, %edx
26544 - jmp *%edx
26545 +#ifdef CONFIG_PAX_KERNEXEC
26546 + movl $(__KERNEXEC_EFI_DS), %edx
26547 + mov %edx, %ds
26548 + mov %edx, %es
26549 + mov %edx, %ss
26550 + addl $2f,(1f)
26551 + ljmp *(1f)
26552 +
26553 +__INITDATA
26554 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
26555 +.previous
26556 +
26557 +2:
26558 + subl $2b,(1b)
26559 +#else
26560 + jmp 1f-__PAGE_OFFSET
26561 1:
26562 +#endif
26563
26564 /*
26565 * 2. Now on the top of stack is the return
26566 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
26567 * parameter 2, ..., param n. To make things easy, we save the return
26568 * address of efi_call_phys in a global variable.
26569 */
26570 - popl %edx
26571 - movl %edx, saved_return_addr
26572 - /* get the function pointer into ECX*/
26573 - popl %ecx
26574 - movl %ecx, efi_rt_function_ptr
26575 - movl $2f, %edx
26576 - subl $__PAGE_OFFSET, %edx
26577 - pushl %edx
26578 + popl (saved_return_addr)
26579 + popl (efi_rt_function_ptr)
26580
26581 /*
26582 * 3. Clear PG bit in %CR0.
26583 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
26584 /*
26585 * 5. Call the physical function.
26586 */
26587 - jmp *%ecx
26588 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
26589
26590 -2:
26591 /*
26592 * 6. After EFI runtime service returns, control will return to
26593 * following instruction. We'd better readjust stack pointer first.
26594 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
26595 movl %cr0, %edx
26596 orl $0x80000000, %edx
26597 movl %edx, %cr0
26598 - jmp 1f
26599 -1:
26600 +
26601 /*
26602 * 8. Now restore the virtual mode from flat mode by
26603 * adding EIP with PAGE_OFFSET.
26604 */
26605 - movl $1f, %edx
26606 - jmp *%edx
26607 +#ifdef CONFIG_PAX_KERNEXEC
26608 + movl $(__KERNEL_DS), %edx
26609 + mov %edx, %ds
26610 + mov %edx, %es
26611 + mov %edx, %ss
26612 + ljmp $(__KERNEL_CS),$1f
26613 +#else
26614 + jmp 1f+__PAGE_OFFSET
26615 +#endif
26616 1:
26617
26618 /*
26619 * 9. Balance the stack. And because EAX contain the return value,
26620 * we'd better not clobber it.
26621 */
26622 - leal efi_rt_function_ptr, %edx
26623 - movl (%edx), %ecx
26624 - pushl %ecx
26625 + pushl (efi_rt_function_ptr)
26626
26627 /*
26628 - * 10. Push the saved return address onto the stack and return.
26629 + * 10. Return to the saved return address.
26630 */
26631 - leal saved_return_addr, %edx
26632 - movl (%edx), %ecx
26633 - pushl %ecx
26634 - ret
26635 + jmpl *(saved_return_addr)
26636 ENDPROC(efi_call_phys)
26637 .previous
26638
26639 -.data
26640 +__INITDATA
26641 saved_return_addr:
26642 .long 0
26643 efi_rt_function_ptr:
26644 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
26645 index 4c07cca..2c8427d 100644
26646 --- a/arch/x86/platform/efi/efi_stub_64.S
26647 +++ b/arch/x86/platform/efi/efi_stub_64.S
26648 @@ -7,6 +7,7 @@
26649 */
26650
26651 #include <linux/linkage.h>
26652 +#include <asm/alternative-asm.h>
26653
26654 #define SAVE_XMM \
26655 mov %rsp, %rax; \
26656 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
26657 call *%rdi
26658 addq $32, %rsp
26659 RESTORE_XMM
26660 + pax_force_retaddr 0, 1
26661 ret
26662 ENDPROC(efi_call0)
26663
26664 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
26665 call *%rdi
26666 addq $32, %rsp
26667 RESTORE_XMM
26668 + pax_force_retaddr 0, 1
26669 ret
26670 ENDPROC(efi_call1)
26671
26672 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
26673 call *%rdi
26674 addq $32, %rsp
26675 RESTORE_XMM
26676 + pax_force_retaddr 0, 1
26677 ret
26678 ENDPROC(efi_call2)
26679
26680 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
26681 call *%rdi
26682 addq $32, %rsp
26683 RESTORE_XMM
26684 + pax_force_retaddr 0, 1
26685 ret
26686 ENDPROC(efi_call3)
26687
26688 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
26689 call *%rdi
26690 addq $32, %rsp
26691 RESTORE_XMM
26692 + pax_force_retaddr 0, 1
26693 ret
26694 ENDPROC(efi_call4)
26695
26696 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
26697 call *%rdi
26698 addq $48, %rsp
26699 RESTORE_XMM
26700 + pax_force_retaddr 0, 1
26701 ret
26702 ENDPROC(efi_call5)
26703
26704 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
26705 call *%rdi
26706 addq $48, %rsp
26707 RESTORE_XMM
26708 + pax_force_retaddr 0, 1
26709 ret
26710 ENDPROC(efi_call6)
26711 diff --git a/arch/x86/platform/mrst/mrst.c b/arch/x86/platform/mrst/mrst.c
26712 index fd41a92..9c33628 100644
26713 --- a/arch/x86/platform/mrst/mrst.c
26714 +++ b/arch/x86/platform/mrst/mrst.c
26715 @@ -78,13 +78,15 @@ struct sfi_rtc_table_entry sfi_mrtc_array[SFI_MRTC_MAX];
26716 EXPORT_SYMBOL_GPL(sfi_mrtc_array);
26717 int sfi_mrtc_num;
26718
26719 -static void mrst_power_off(void)
26720 +static __noreturn void mrst_power_off(void)
26721 {
26722 + BUG();
26723 }
26724
26725 -static void mrst_reboot(void)
26726 +static __noreturn void mrst_reboot(void)
26727 {
26728 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
26729 + BUG();
26730 }
26731
26732 /* parse all the mtimer info to a static mtimer array */
26733 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
26734 index 218cdb1..fd55c08 100644
26735 --- a/arch/x86/power/cpu.c
26736 +++ b/arch/x86/power/cpu.c
26737 @@ -132,7 +132,7 @@ static void do_fpu_end(void)
26738 static void fix_processor_context(void)
26739 {
26740 int cpu = smp_processor_id();
26741 - struct tss_struct *t = &per_cpu(init_tss, cpu);
26742 + struct tss_struct *t = init_tss + cpu;
26743
26744 set_tss_desc(cpu, t); /*
26745 * This just modifies memory; should not be
26746 @@ -142,7 +142,9 @@ static void fix_processor_context(void)
26747 */
26748
26749 #ifdef CONFIG_X86_64
26750 + pax_open_kernel();
26751 get_cpu_gdt_table(cpu)[GDT_ENTRY_TSS].type = 9;
26752 + pax_close_kernel();
26753
26754 syscall_init(); /* This sets MSR_*STAR and related */
26755 #endif
26756 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
26757 index cbca565..bae7133 100644
26758 --- a/arch/x86/realmode/init.c
26759 +++ b/arch/x86/realmode/init.c
26760 @@ -62,7 +62,13 @@ void __init setup_real_mode(void)
26761 __va(real_mode_header->trampoline_header);
26762
26763 #ifdef CONFIG_X86_32
26764 - trampoline_header->start = __pa(startup_32_smp);
26765 + trampoline_header->start = __pa(ktla_ktva(startup_32_smp));
26766 +
26767 +#ifdef CONFIG_PAX_KERNEXEC
26768 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
26769 +#endif
26770 +
26771 + trampoline_header->boot_cs = __BOOT_CS;
26772 trampoline_header->gdt_limit = __BOOT_DS + 7;
26773 trampoline_header->gdt_base = __pa(boot_gdt);
26774 #else
26775 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
26776 index 5b84a2d..be46798 100644
26777 --- a/arch/x86/realmode/rm/Makefile
26778 +++ b/arch/x86/realmode/rm/Makefile
26779 @@ -78,5 +78,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
26780 $(call cc-option, -fno-unit-at-a-time)) \
26781 $(call cc-option, -fno-stack-protector) \
26782 $(call cc-option, -mpreferred-stack-boundary=2)
26783 +ifdef CONSTIFY_PLUGIN
26784 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
26785 +endif
26786 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
26787 GCOV_PROFILE := n
26788 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
26789 index c1b2791..f9e31c7 100644
26790 --- a/arch/x86/realmode/rm/trampoline_32.S
26791 +++ b/arch/x86/realmode/rm/trampoline_32.S
26792 @@ -25,6 +25,12 @@
26793 #include <asm/page_types.h>
26794 #include "realmode.h"
26795
26796 +#ifdef CONFIG_PAX_KERNEXEC
26797 +#define ta(X) (X)
26798 +#else
26799 +#define ta(X) (pa_ ## X)
26800 +#endif
26801 +
26802 .text
26803 .code16
26804
26805 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
26806
26807 cli # We should be safe anyway
26808
26809 - movl tr_start, %eax # where we need to go
26810 -
26811 movl $0xA5A5A5A5, trampoline_status
26812 # write marker for master knows we're running
26813
26814 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
26815 movw $1, %dx # protected mode (PE) bit
26816 lmsw %dx # into protected mode
26817
26818 - ljmpl $__BOOT_CS, $pa_startup_32
26819 + ljmpl *(trampoline_header)
26820
26821 .section ".text32","ax"
26822 .code32
26823 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
26824 .balign 8
26825 GLOBAL(trampoline_header)
26826 tr_start: .space 4
26827 - tr_gdt_pad: .space 2
26828 + tr_boot_cs: .space 2
26829 tr_gdt: .space 6
26830 END(trampoline_header)
26831
26832 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
26833 index bb360dc..3e5945f 100644
26834 --- a/arch/x86/realmode/rm/trampoline_64.S
26835 +++ b/arch/x86/realmode/rm/trampoline_64.S
26836 @@ -107,7 +107,7 @@ ENTRY(startup_32)
26837 wrmsr
26838
26839 # Enable paging and in turn activate Long Mode
26840 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
26841 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
26842 movl %eax, %cr0
26843
26844 /*
26845 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
26846 index 5a1847d..deccb30 100644
26847 --- a/arch/x86/tools/relocs.c
26848 +++ b/arch/x86/tools/relocs.c
26849 @@ -12,10 +12,13 @@
26850 #include <regex.h>
26851 #include <tools/le_byteshift.h>
26852
26853 +#include "../../../include/generated/autoconf.h"
26854 +
26855 static void die(char *fmt, ...);
26856
26857 #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
26858 static Elf32_Ehdr ehdr;
26859 +static Elf32_Phdr *phdr;
26860 static unsigned long reloc_count, reloc_idx;
26861 static unsigned long *relocs;
26862 static unsigned long reloc16_count, reloc16_idx;
26863 @@ -330,9 +333,39 @@ static void read_ehdr(FILE *fp)
26864 }
26865 }
26866
26867 +static void read_phdrs(FILE *fp)
26868 +{
26869 + unsigned int i;
26870 +
26871 + phdr = calloc(ehdr.e_phnum, sizeof(Elf32_Phdr));
26872 + if (!phdr) {
26873 + die("Unable to allocate %d program headers\n",
26874 + ehdr.e_phnum);
26875 + }
26876 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
26877 + die("Seek to %d failed: %s\n",
26878 + ehdr.e_phoff, strerror(errno));
26879 + }
26880 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
26881 + die("Cannot read ELF program headers: %s\n",
26882 + strerror(errno));
26883 + }
26884 + for(i = 0; i < ehdr.e_phnum; i++) {
26885 + phdr[i].p_type = elf32_to_cpu(phdr[i].p_type);
26886 + phdr[i].p_offset = elf32_to_cpu(phdr[i].p_offset);
26887 + phdr[i].p_vaddr = elf32_to_cpu(phdr[i].p_vaddr);
26888 + phdr[i].p_paddr = elf32_to_cpu(phdr[i].p_paddr);
26889 + phdr[i].p_filesz = elf32_to_cpu(phdr[i].p_filesz);
26890 + phdr[i].p_memsz = elf32_to_cpu(phdr[i].p_memsz);
26891 + phdr[i].p_flags = elf32_to_cpu(phdr[i].p_flags);
26892 + phdr[i].p_align = elf32_to_cpu(phdr[i].p_align);
26893 + }
26894 +
26895 +}
26896 +
26897 static void read_shdrs(FILE *fp)
26898 {
26899 - int i;
26900 + unsigned int i;
26901 Elf32_Shdr shdr;
26902
26903 secs = calloc(ehdr.e_shnum, sizeof(struct section));
26904 @@ -367,7 +400,7 @@ static void read_shdrs(FILE *fp)
26905
26906 static void read_strtabs(FILE *fp)
26907 {
26908 - int i;
26909 + unsigned int i;
26910 for (i = 0; i < ehdr.e_shnum; i++) {
26911 struct section *sec = &secs[i];
26912 if (sec->shdr.sh_type != SHT_STRTAB) {
26913 @@ -392,7 +425,7 @@ static void read_strtabs(FILE *fp)
26914
26915 static void read_symtabs(FILE *fp)
26916 {
26917 - int i,j;
26918 + unsigned int i,j;
26919 for (i = 0; i < ehdr.e_shnum; i++) {
26920 struct section *sec = &secs[i];
26921 if (sec->shdr.sh_type != SHT_SYMTAB) {
26922 @@ -423,9 +456,11 @@ static void read_symtabs(FILE *fp)
26923 }
26924
26925
26926 -static void read_relocs(FILE *fp)
26927 +static void read_relocs(FILE *fp, int use_real_mode)
26928 {
26929 - int i,j;
26930 + unsigned int i,j;
26931 + uint32_t base;
26932 +
26933 for (i = 0; i < ehdr.e_shnum; i++) {
26934 struct section *sec = &secs[i];
26935 if (sec->shdr.sh_type != SHT_REL) {
26936 @@ -445,9 +480,22 @@ static void read_relocs(FILE *fp)
26937 die("Cannot read symbol table: %s\n",
26938 strerror(errno));
26939 }
26940 + base = 0;
26941 +
26942 +#ifdef CONFIG_X86_32
26943 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
26944 + if (phdr[j].p_type != PT_LOAD )
26945 + continue;
26946 + 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)
26947 + continue;
26948 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
26949 + break;
26950 + }
26951 +#endif
26952 +
26953 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf32_Rel); j++) {
26954 Elf32_Rel *rel = &sec->reltab[j];
26955 - rel->r_offset = elf32_to_cpu(rel->r_offset);
26956 + rel->r_offset = elf32_to_cpu(rel->r_offset) + base;
26957 rel->r_info = elf32_to_cpu(rel->r_info);
26958 }
26959 }
26960 @@ -456,13 +504,13 @@ static void read_relocs(FILE *fp)
26961
26962 static void print_absolute_symbols(void)
26963 {
26964 - int i;
26965 + unsigned int i;
26966 printf("Absolute symbols\n");
26967 printf(" Num: Value Size Type Bind Visibility Name\n");
26968 for (i = 0; i < ehdr.e_shnum; i++) {
26969 struct section *sec = &secs[i];
26970 char *sym_strtab;
26971 - int j;
26972 + unsigned int j;
26973
26974 if (sec->shdr.sh_type != SHT_SYMTAB) {
26975 continue;
26976 @@ -489,14 +537,14 @@ static void print_absolute_symbols(void)
26977
26978 static void print_absolute_relocs(void)
26979 {
26980 - int i, printed = 0;
26981 + unsigned int i, printed = 0;
26982
26983 for (i = 0; i < ehdr.e_shnum; i++) {
26984 struct section *sec = &secs[i];
26985 struct section *sec_applies, *sec_symtab;
26986 char *sym_strtab;
26987 Elf32_Sym *sh_symtab;
26988 - int j;
26989 + unsigned int j;
26990 if (sec->shdr.sh_type != SHT_REL) {
26991 continue;
26992 }
26993 @@ -558,13 +606,13 @@ static void print_absolute_relocs(void)
26994 static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
26995 int use_real_mode)
26996 {
26997 - int i;
26998 + unsigned int i;
26999 /* Walk through the relocations */
27000 for (i = 0; i < ehdr.e_shnum; i++) {
27001 char *sym_strtab;
27002 Elf32_Sym *sh_symtab;
27003 struct section *sec_applies, *sec_symtab;
27004 - int j;
27005 + unsigned int j;
27006 struct section *sec = &secs[i];
27007
27008 if (sec->shdr.sh_type != SHT_REL) {
27009 @@ -588,6 +636,24 @@ static void walk_relocs(void (*visit)(Elf32_Rel *rel, Elf32_Sym *sym),
27010 sym = &sh_symtab[ELF32_R_SYM(rel->r_info)];
27011 r_type = ELF32_R_TYPE(rel->r_info);
27012
27013 + if (!use_real_mode) {
27014 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
27015 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
27016 + continue;
27017 +
27018 +#if defined(CONFIG_PAX_KERNEXEC) && defined(CONFIG_X86_32)
27019 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
27020 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
27021 + continue;
27022 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
27023 + continue;
27024 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
27025 + continue;
27026 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
27027 + continue;
27028 +#endif
27029 + }
27030 +
27031 shn_abs = sym->st_shndx == SHN_ABS;
27032
27033 switch (r_type) {
27034 @@ -681,7 +747,7 @@ static int write32(unsigned int v, FILE *f)
27035
27036 static void emit_relocs(int as_text, int use_real_mode)
27037 {
27038 - int i;
27039 + unsigned int i;
27040 /* Count how many relocations I have and allocate space for them. */
27041 reloc_count = 0;
27042 walk_relocs(count_reloc, use_real_mode);
27043 @@ -808,10 +874,11 @@ int main(int argc, char **argv)
27044 fname, strerror(errno));
27045 }
27046 read_ehdr(fp);
27047 + read_phdrs(fp);
27048 read_shdrs(fp);
27049 read_strtabs(fp);
27050 read_symtabs(fp);
27051 - read_relocs(fp);
27052 + read_relocs(fp, use_real_mode);
27053 if (show_absolute_syms) {
27054 print_absolute_symbols();
27055 return 0;
27056 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
27057 index fd14be1..e3c79c0 100644
27058 --- a/arch/x86/vdso/Makefile
27059 +++ b/arch/x86/vdso/Makefile
27060 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
27061 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
27062 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
27063
27064 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27065 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
27066 GCOV_PROFILE := n
27067
27068 #
27069 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
27070 index 66e6d93..587f435 100644
27071 --- a/arch/x86/vdso/vdso32-setup.c
27072 +++ b/arch/x86/vdso/vdso32-setup.c
27073 @@ -25,6 +25,7 @@
27074 #include <asm/tlbflush.h>
27075 #include <asm/vdso.h>
27076 #include <asm/proto.h>
27077 +#include <asm/mman.h>
27078
27079 enum {
27080 VDSO_DISABLED = 0,
27081 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
27082 void enable_sep_cpu(void)
27083 {
27084 int cpu = get_cpu();
27085 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
27086 + struct tss_struct *tss = init_tss + cpu;
27087
27088 if (!boot_cpu_has(X86_FEATURE_SEP)) {
27089 put_cpu();
27090 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
27091 gate_vma.vm_start = FIXADDR_USER_START;
27092 gate_vma.vm_end = FIXADDR_USER_END;
27093 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
27094 - gate_vma.vm_page_prot = __P101;
27095 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
27096
27097 return 0;
27098 }
27099 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27100 if (compat)
27101 addr = VDSO_HIGH_BASE;
27102 else {
27103 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
27104 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
27105 if (IS_ERR_VALUE(addr)) {
27106 ret = addr;
27107 goto up_fail;
27108 }
27109 }
27110
27111 - current->mm->context.vdso = (void *)addr;
27112 + current->mm->context.vdso = addr;
27113
27114 if (compat_uses_vma || !compat) {
27115 /*
27116 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27117 }
27118
27119 current_thread_info()->sysenter_return =
27120 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27121 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
27122
27123 up_fail:
27124 if (ret)
27125 - current->mm->context.vdso = NULL;
27126 + current->mm->context.vdso = 0;
27127
27128 up_write(&mm->mmap_sem);
27129
27130 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
27131
27132 const char *arch_vma_name(struct vm_area_struct *vma)
27133 {
27134 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
27135 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
27136 return "[vdso]";
27137 +
27138 +#ifdef CONFIG_PAX_SEGMEXEC
27139 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
27140 + return "[vdso]";
27141 +#endif
27142 +
27143 return NULL;
27144 }
27145
27146 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
27147 * Check to see if the corresponding task was created in compat vdso
27148 * mode.
27149 */
27150 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
27151 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
27152 return &gate_vma;
27153 return NULL;
27154 }
27155 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
27156 index 00aaf04..4a26505 100644
27157 --- a/arch/x86/vdso/vma.c
27158 +++ b/arch/x86/vdso/vma.c
27159 @@ -16,8 +16,6 @@
27160 #include <asm/vdso.h>
27161 #include <asm/page.h>
27162
27163 -unsigned int __read_mostly vdso_enabled = 1;
27164 -
27165 extern char vdso_start[], vdso_end[];
27166 extern unsigned short vdso_sync_cpuid;
27167
27168 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
27169 * unaligned here as a result of stack start randomization.
27170 */
27171 addr = PAGE_ALIGN(addr);
27172 - addr = align_addr(addr, NULL, ALIGN_VDSO);
27173
27174 return addr;
27175 }
27176 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
27177 unsigned size)
27178 {
27179 struct mm_struct *mm = current->mm;
27180 - unsigned long addr;
27181 + unsigned long addr = 0;
27182 int ret;
27183
27184 - if (!vdso_enabled)
27185 - return 0;
27186 -
27187 down_write(&mm->mmap_sem);
27188 +
27189 +#ifdef CONFIG_PAX_RANDMMAP
27190 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
27191 +#endif
27192 +
27193 addr = vdso_addr(mm->start_stack, size);
27194 + addr = align_addr(addr, NULL, ALIGN_VDSO);
27195 addr = get_unmapped_area(NULL, addr, size, 0, 0);
27196 if (IS_ERR_VALUE(addr)) {
27197 ret = addr;
27198 goto up_fail;
27199 }
27200
27201 - current->mm->context.vdso = (void *)addr;
27202 + mm->context.vdso = addr;
27203
27204 ret = install_special_mapping(mm, addr, size,
27205 VM_READ|VM_EXEC|
27206 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
27207 pages);
27208 - if (ret) {
27209 - current->mm->context.vdso = NULL;
27210 - goto up_fail;
27211 - }
27212 + if (ret)
27213 + mm->context.vdso = 0;
27214
27215 up_fail:
27216 up_write(&mm->mmap_sem);
27217 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
27218 vdsox32_size);
27219 }
27220 #endif
27221 -
27222 -static __init int vdso_setup(char *s)
27223 -{
27224 - vdso_enabled = simple_strtoul(s, NULL, 0);
27225 - return 0;
27226 -}
27227 -__setup("vdso=", vdso_setup);
27228 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
27229 index 405307f..7ecf7b0 100644
27230 --- a/arch/x86/xen/enlighten.c
27231 +++ b/arch/x86/xen/enlighten.c
27232 @@ -97,8 +97,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
27233
27234 struct shared_info xen_dummy_shared_info;
27235
27236 -void *xen_initial_gdt;
27237 -
27238 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
27239 __read_mostly int xen_have_vector_callback;
27240 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
27241 @@ -885,21 +883,21 @@ static u32 xen_safe_apic_wait_icr_idle(void)
27242
27243 static void set_xen_basic_apic_ops(void)
27244 {
27245 - apic->read = xen_apic_read;
27246 - apic->write = xen_apic_write;
27247 - apic->icr_read = xen_apic_icr_read;
27248 - apic->icr_write = xen_apic_icr_write;
27249 - apic->wait_icr_idle = xen_apic_wait_icr_idle;
27250 - apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27251 - apic->set_apic_id = xen_set_apic_id;
27252 - apic->get_apic_id = xen_get_apic_id;
27253 + *(void **)&apic->read = xen_apic_read;
27254 + *(void **)&apic->write = xen_apic_write;
27255 + *(void **)&apic->icr_read = xen_apic_icr_read;
27256 + *(void **)&apic->icr_write = xen_apic_icr_write;
27257 + *(void **)&apic->wait_icr_idle = xen_apic_wait_icr_idle;
27258 + *(void **)&apic->safe_wait_icr_idle = xen_safe_apic_wait_icr_idle;
27259 + *(void **)&apic->set_apic_id = xen_set_apic_id;
27260 + *(void **)&apic->get_apic_id = xen_get_apic_id;
27261
27262 #ifdef CONFIG_SMP
27263 - apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27264 - apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27265 - apic->send_IPI_mask = xen_send_IPI_mask;
27266 - apic->send_IPI_all = xen_send_IPI_all;
27267 - apic->send_IPI_self = xen_send_IPI_self;
27268 + *(void **)&apic->send_IPI_allbutself = xen_send_IPI_allbutself;
27269 + *(void **)&apic->send_IPI_mask_allbutself = xen_send_IPI_mask_allbutself;
27270 + *(void **)&apic->send_IPI_mask = xen_send_IPI_mask;
27271 + *(void **)&apic->send_IPI_all = xen_send_IPI_all;
27272 + *(void **)&apic->send_IPI_self = xen_send_IPI_self;
27273 #endif
27274 }
27275
27276 @@ -1175,30 +1173,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
27277 #endif
27278 };
27279
27280 -static void xen_reboot(int reason)
27281 +static __noreturn void xen_reboot(int reason)
27282 {
27283 struct sched_shutdown r = { .reason = reason };
27284
27285 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
27286 - BUG();
27287 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
27288 + BUG();
27289 }
27290
27291 -static void xen_restart(char *msg)
27292 +static __noreturn void xen_restart(char *msg)
27293 {
27294 xen_reboot(SHUTDOWN_reboot);
27295 }
27296
27297 -static void xen_emergency_restart(void)
27298 +static __noreturn void xen_emergency_restart(void)
27299 {
27300 xen_reboot(SHUTDOWN_reboot);
27301 }
27302
27303 -static void xen_machine_halt(void)
27304 +static __noreturn void xen_machine_halt(void)
27305 {
27306 xen_reboot(SHUTDOWN_poweroff);
27307 }
27308
27309 -static void xen_machine_power_off(void)
27310 +static __noreturn void xen_machine_power_off(void)
27311 {
27312 if (pm_power_off)
27313 pm_power_off();
27314 @@ -1301,7 +1299,17 @@ asmlinkage void __init xen_start_kernel(void)
27315 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
27316
27317 /* Work out if we support NX */
27318 - x86_configure_nx();
27319 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
27320 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
27321 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
27322 + unsigned l, h;
27323 +
27324 + __supported_pte_mask |= _PAGE_NX;
27325 + rdmsr(MSR_EFER, l, h);
27326 + l |= EFER_NX;
27327 + wrmsr(MSR_EFER, l, h);
27328 + }
27329 +#endif
27330
27331 xen_setup_features();
27332
27333 @@ -1332,13 +1340,6 @@ asmlinkage void __init xen_start_kernel(void)
27334
27335 machine_ops = xen_machine_ops;
27336
27337 - /*
27338 - * The only reliable way to retain the initial address of the
27339 - * percpu gdt_page is to remember it here, so we can go and
27340 - * mark it RW later, when the initial percpu area is freed.
27341 - */
27342 - xen_initial_gdt = &per_cpu(gdt_page, 0);
27343 -
27344 xen_smp_init();
27345
27346 #ifdef CONFIG_ACPI_NUMA
27347 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
27348 index 3a73785..0d30df2 100644
27349 --- a/arch/x86/xen/mmu.c
27350 +++ b/arch/x86/xen/mmu.c
27351 @@ -1738,6 +1738,9 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27352 convert_pfn_mfn(init_level4_pgt);
27353 convert_pfn_mfn(level3_ident_pgt);
27354 convert_pfn_mfn(level3_kernel_pgt);
27355 + convert_pfn_mfn(level3_vmalloc_start_pgt);
27356 + convert_pfn_mfn(level3_vmalloc_end_pgt);
27357 + convert_pfn_mfn(level3_vmemmap_pgt);
27358
27359 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
27360 l2 = m2v(l3[pud_index(__START_KERNEL_map)].pud);
27361 @@ -1756,7 +1759,11 @@ pgd_t * __init xen_setup_kernel_pagetable(pgd_t *pgd,
27362 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
27363 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
27364 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
27365 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
27366 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
27367 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
27368 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
27369 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
27370 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
27371 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
27372
27373 @@ -1940,6 +1947,7 @@ static void __init xen_post_allocator_init(void)
27374 pv_mmu_ops.set_pud = xen_set_pud;
27375 #if PAGETABLE_LEVELS == 4
27376 pv_mmu_ops.set_pgd = xen_set_pgd;
27377 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
27378 #endif
27379
27380 /* This will work as long as patching hasn't happened yet
27381 @@ -2021,6 +2029,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
27382 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
27383 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
27384 .set_pgd = xen_set_pgd_hyper,
27385 + .set_pgd_batched = xen_set_pgd_hyper,
27386
27387 .alloc_pud = xen_alloc_pmd_init,
27388 .release_pud = xen_release_pmd_init,
27389 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
27390 index afb250d..627075f 100644
27391 --- a/arch/x86/xen/smp.c
27392 +++ b/arch/x86/xen/smp.c
27393 @@ -231,11 +231,6 @@ static void __init xen_smp_prepare_boot_cpu(void)
27394 {
27395 BUG_ON(smp_processor_id() != 0);
27396 native_smp_prepare_boot_cpu();
27397 -
27398 - /* We've switched to the "real" per-cpu gdt, so make sure the
27399 - old memory can be recycled */
27400 - make_lowmem_page_readwrite(xen_initial_gdt);
27401 -
27402 xen_filter_cpu_maps();
27403 xen_setup_vcpu_info_placement();
27404 }
27405 @@ -302,12 +297,12 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
27406 gdt = get_cpu_gdt_table(cpu);
27407
27408 ctxt->flags = VGCF_IN_KERNEL;
27409 - ctxt->user_regs.ds = __USER_DS;
27410 - ctxt->user_regs.es = __USER_DS;
27411 + ctxt->user_regs.ds = __KERNEL_DS;
27412 + ctxt->user_regs.es = __KERNEL_DS;
27413 ctxt->user_regs.ss = __KERNEL_DS;
27414 #ifdef CONFIG_X86_32
27415 ctxt->user_regs.fs = __KERNEL_PERCPU;
27416 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
27417 + savesegment(gs, ctxt->user_regs.gs);
27418 #else
27419 ctxt->gs_base_kernel = per_cpu_offset(cpu);
27420 #endif
27421 @@ -357,13 +352,12 @@ static int __cpuinit xen_cpu_up(unsigned int cpu, struct task_struct *idle)
27422 int rc;
27423
27424 per_cpu(current_task, cpu) = idle;
27425 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
27426 #ifdef CONFIG_X86_32
27427 irq_ctx_init(cpu);
27428 #else
27429 clear_tsk_thread_flag(idle, TIF_FORK);
27430 - per_cpu(kernel_stack, cpu) =
27431 - (unsigned long)task_stack_page(idle) -
27432 - KERNEL_STACK_OFFSET + THREAD_SIZE;
27433 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
27434 #endif
27435 xen_setup_runstate_info(cpu);
27436 xen_setup_timer(cpu);
27437 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
27438 index f9643fc..602e8af 100644
27439 --- a/arch/x86/xen/xen-asm_32.S
27440 +++ b/arch/x86/xen/xen-asm_32.S
27441 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
27442 ESP_OFFSET=4 # bytes pushed onto stack
27443
27444 /*
27445 - * Store vcpu_info pointer for easy access. Do it this way to
27446 - * avoid having to reload %fs
27447 + * Store vcpu_info pointer for easy access.
27448 */
27449 #ifdef CONFIG_SMP
27450 - GET_THREAD_INFO(%eax)
27451 - movl TI_cpu(%eax), %eax
27452 - movl __per_cpu_offset(,%eax,4), %eax
27453 - mov xen_vcpu(%eax), %eax
27454 + push %fs
27455 + mov $(__KERNEL_PERCPU), %eax
27456 + mov %eax, %fs
27457 + mov PER_CPU_VAR(xen_vcpu), %eax
27458 + pop %fs
27459 #else
27460 movl xen_vcpu, %eax
27461 #endif
27462 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
27463 index aaa7291..3f77960 100644
27464 --- a/arch/x86/xen/xen-head.S
27465 +++ b/arch/x86/xen/xen-head.S
27466 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
27467 #ifdef CONFIG_X86_32
27468 mov %esi,xen_start_info
27469 mov $init_thread_union+THREAD_SIZE,%esp
27470 +#ifdef CONFIG_SMP
27471 + movl $cpu_gdt_table,%edi
27472 + movl $__per_cpu_load,%eax
27473 + movw %ax,__KERNEL_PERCPU + 2(%edi)
27474 + rorl $16,%eax
27475 + movb %al,__KERNEL_PERCPU + 4(%edi)
27476 + movb %ah,__KERNEL_PERCPU + 7(%edi)
27477 + movl $__per_cpu_end - 1,%eax
27478 + subl $__per_cpu_start,%eax
27479 + movw %ax,__KERNEL_PERCPU + 0(%edi)
27480 +#endif
27481 #else
27482 mov %rsi,xen_start_info
27483 mov $init_thread_union+THREAD_SIZE,%rsp
27484 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
27485 index 202d4c1..99b072a 100644
27486 --- a/arch/x86/xen/xen-ops.h
27487 +++ b/arch/x86/xen/xen-ops.h
27488 @@ -10,8 +10,6 @@
27489 extern const char xen_hypervisor_callback[];
27490 extern const char xen_failsafe_callback[];
27491
27492 -extern void *xen_initial_gdt;
27493 -
27494 struct trap_info;
27495 void xen_copy_trap_info(struct trap_info *traps);
27496
27497 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
27498 index 525bd3d..ef888b1 100644
27499 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
27500 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
27501 @@ -119,9 +119,9 @@
27502 ----------------------------------------------------------------------*/
27503
27504 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
27505 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
27506 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
27507 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
27508 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27509
27510 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
27511 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
27512 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
27513 index 2f33760..835e50a 100644
27514 --- a/arch/xtensa/variants/fsf/include/variant/core.h
27515 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
27516 @@ -11,6 +11,7 @@
27517 #ifndef _XTENSA_CORE_H
27518 #define _XTENSA_CORE_H
27519
27520 +#include <linux/const.h>
27521
27522 /****************************************************************************
27523 Parameters Useful for Any Code, USER or PRIVILEGED
27524 @@ -112,9 +113,9 @@
27525 ----------------------------------------------------------------------*/
27526
27527 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27528 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27529 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27530 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27531 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27532
27533 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
27534 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
27535 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
27536 index af00795..2bb8105 100644
27537 --- a/arch/xtensa/variants/s6000/include/variant/core.h
27538 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
27539 @@ -11,6 +11,7 @@
27540 #ifndef _XTENSA_CORE_CONFIGURATION_H
27541 #define _XTENSA_CORE_CONFIGURATION_H
27542
27543 +#include <linux/const.h>
27544
27545 /****************************************************************************
27546 Parameters Useful for Any Code, USER or PRIVILEGED
27547 @@ -118,9 +119,9 @@
27548 ----------------------------------------------------------------------*/
27549
27550 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
27551 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
27552 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
27553 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
27554 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
27555
27556 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
27557 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
27558 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
27559 index 58916af..9cb880b 100644
27560 --- a/block/blk-iopoll.c
27561 +++ b/block/blk-iopoll.c
27562 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
27563 }
27564 EXPORT_SYMBOL(blk_iopoll_complete);
27565
27566 -static void blk_iopoll_softirq(struct softirq_action *h)
27567 +static void blk_iopoll_softirq(void)
27568 {
27569 struct list_head *list = &__get_cpu_var(blk_cpu_iopoll);
27570 int rearm = 0, budget = blk_iopoll_budget;
27571 diff --git a/block/blk-map.c b/block/blk-map.c
27572 index 623e1cd..ca1e109 100644
27573 --- a/block/blk-map.c
27574 +++ b/block/blk-map.c
27575 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
27576 if (!len || !kbuf)
27577 return -EINVAL;
27578
27579 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
27580 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
27581 if (do_copy)
27582 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
27583 else
27584 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
27585 index 467c8de..4bddc6d 100644
27586 --- a/block/blk-softirq.c
27587 +++ b/block/blk-softirq.c
27588 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
27589 * Softirq action handler - move entries to local list and loop over them
27590 * while passing them to the queue registered handler.
27591 */
27592 -static void blk_done_softirq(struct softirq_action *h)
27593 +static void blk_done_softirq(void)
27594 {
27595 struct list_head *cpu_list, local_list;
27596
27597 diff --git a/block/bsg.c b/block/bsg.c
27598 index ff64ae3..593560c 100644
27599 --- a/block/bsg.c
27600 +++ b/block/bsg.c
27601 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
27602 struct sg_io_v4 *hdr, struct bsg_device *bd,
27603 fmode_t has_write_perm)
27604 {
27605 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27606 + unsigned char *cmdptr;
27607 +
27608 if (hdr->request_len > BLK_MAX_CDB) {
27609 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
27610 if (!rq->cmd)
27611 return -ENOMEM;
27612 - }
27613 + cmdptr = rq->cmd;
27614 + } else
27615 + cmdptr = tmpcmd;
27616
27617 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
27618 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
27619 hdr->request_len))
27620 return -EFAULT;
27621
27622 + if (cmdptr != rq->cmd)
27623 + memcpy(rq->cmd, cmdptr, hdr->request_len);
27624 +
27625 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
27626 if (blk_verify_command(rq->cmd, has_write_perm))
27627 return -EPERM;
27628 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
27629 index 7c668c8..db3521c 100644
27630 --- a/block/compat_ioctl.c
27631 +++ b/block/compat_ioctl.c
27632 @@ -340,7 +340,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
27633 err |= __get_user(f->spec1, &uf->spec1);
27634 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
27635 err |= __get_user(name, &uf->name);
27636 - f->name = compat_ptr(name);
27637 + f->name = (void __force_kernel *)compat_ptr(name);
27638 if (err) {
27639 err = -EFAULT;
27640 goto out;
27641 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
27642 index 6296b40..417c00f 100644
27643 --- a/block/partitions/efi.c
27644 +++ b/block/partitions/efi.c
27645 @@ -234,14 +234,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
27646 if (!gpt)
27647 return NULL;
27648
27649 + if (!le32_to_cpu(gpt->num_partition_entries))
27650 + return NULL;
27651 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
27652 + if (!pte)
27653 + return NULL;
27654 +
27655 count = le32_to_cpu(gpt->num_partition_entries) *
27656 le32_to_cpu(gpt->sizeof_partition_entry);
27657 - if (!count)
27658 - return NULL;
27659 - pte = kzalloc(count, GFP_KERNEL);
27660 - if (!pte)
27661 - return NULL;
27662 -
27663 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
27664 (u8 *) pte,
27665 count) < count) {
27666 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
27667 index 9a87daa..fb17486 100644
27668 --- a/block/scsi_ioctl.c
27669 +++ b/block/scsi_ioctl.c
27670 @@ -223,8 +223,20 @@ EXPORT_SYMBOL(blk_verify_command);
27671 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
27672 struct sg_io_hdr *hdr, fmode_t mode)
27673 {
27674 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
27675 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27676 + unsigned char *cmdptr;
27677 +
27678 + if (rq->cmd != rq->__cmd)
27679 + cmdptr = rq->cmd;
27680 + else
27681 + cmdptr = tmpcmd;
27682 +
27683 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
27684 return -EFAULT;
27685 +
27686 + if (cmdptr != rq->cmd)
27687 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
27688 +
27689 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
27690 return -EPERM;
27691
27692 @@ -433,6 +445,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27693 int err;
27694 unsigned int in_len, out_len, bytes, opcode, cmdlen;
27695 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
27696 + unsigned char tmpcmd[sizeof(rq->__cmd)];
27697 + unsigned char *cmdptr;
27698
27699 if (!sic)
27700 return -EINVAL;
27701 @@ -466,9 +480,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
27702 */
27703 err = -EFAULT;
27704 rq->cmd_len = cmdlen;
27705 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
27706 +
27707 + if (rq->cmd != rq->__cmd)
27708 + cmdptr = rq->cmd;
27709 + else
27710 + cmdptr = tmpcmd;
27711 +
27712 + if (copy_from_user(cmdptr, sic->data, cmdlen))
27713 goto error;
27714
27715 + if (rq->cmd != cmdptr)
27716 + memcpy(rq->cmd, cmdptr, cmdlen);
27717 +
27718 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
27719 goto error;
27720
27721 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
27722 index 671d4d6..5f24030 100644
27723 --- a/crypto/cryptd.c
27724 +++ b/crypto/cryptd.c
27725 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
27726
27727 struct cryptd_blkcipher_request_ctx {
27728 crypto_completion_t complete;
27729 -};
27730 +} __no_const;
27731
27732 struct cryptd_hash_ctx {
27733 struct crypto_shash *child;
27734 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
27735
27736 struct cryptd_aead_request_ctx {
27737 crypto_completion_t complete;
27738 -};
27739 +} __no_const;
27740
27741 static void cryptd_queue_worker(struct work_struct *work);
27742
27743 diff --git a/drivers/acpi/apei/cper.c b/drivers/acpi/apei/cper.c
27744 index e6defd8..c26a225 100644
27745 --- a/drivers/acpi/apei/cper.c
27746 +++ b/drivers/acpi/apei/cper.c
27747 @@ -38,12 +38,12 @@
27748 */
27749 u64 cper_next_record_id(void)
27750 {
27751 - static atomic64_t seq;
27752 + static atomic64_unchecked_t seq;
27753
27754 - if (!atomic64_read(&seq))
27755 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
27756 + if (!atomic64_read_unchecked(&seq))
27757 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
27758
27759 - return atomic64_inc_return(&seq);
27760 + return atomic64_inc_return_unchecked(&seq);
27761 }
27762 EXPORT_SYMBOL_GPL(cper_next_record_id);
27763
27764 diff --git a/drivers/acpi/ec_sys.c b/drivers/acpi/ec_sys.c
27765 index 7586544..636a2f0 100644
27766 --- a/drivers/acpi/ec_sys.c
27767 +++ b/drivers/acpi/ec_sys.c
27768 @@ -12,6 +12,7 @@
27769 #include <linux/acpi.h>
27770 #include <linux/debugfs.h>
27771 #include <linux/module.h>
27772 +#include <linux/uaccess.h>
27773 #include "internal.h"
27774
27775 MODULE_AUTHOR("Thomas Renninger <trenn@suse.de>");
27776 @@ -34,7 +35,7 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27777 * struct acpi_ec *ec = ((struct seq_file *)f->private_data)->private;
27778 */
27779 unsigned int size = EC_SPACE_SIZE;
27780 - u8 *data = (u8 *) buf;
27781 + u8 data;
27782 loff_t init_off = *off;
27783 int err = 0;
27784
27785 @@ -47,9 +48,11 @@ static ssize_t acpi_ec_read_io(struct file *f, char __user *buf,
27786 size = count;
27787
27788 while (size) {
27789 - err = ec_read(*off, &data[*off - init_off]);
27790 + err = ec_read(*off, &data);
27791 if (err)
27792 return err;
27793 + if (put_user(data, &buf[*off - init_off]))
27794 + return -EFAULT;
27795 *off += 1;
27796 size--;
27797 }
27798 @@ -65,7 +68,6 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27799
27800 unsigned int size = count;
27801 loff_t init_off = *off;
27802 - u8 *data = (u8 *) buf;
27803 int err = 0;
27804
27805 if (*off >= EC_SPACE_SIZE)
27806 @@ -76,7 +78,9 @@ static ssize_t acpi_ec_write_io(struct file *f, const char __user *buf,
27807 }
27808
27809 while (size) {
27810 - u8 byte_write = data[*off - init_off];
27811 + u8 byte_write;
27812 + if (get_user(byte_write, &buf[*off - init_off]))
27813 + return -EFAULT;
27814 err = ec_write(*off, byte_write);
27815 if (err)
27816 return err;
27817 diff --git a/drivers/acpi/proc.c b/drivers/acpi/proc.c
27818 index 251c7b62..000462d 100644
27819 --- a/drivers/acpi/proc.c
27820 +++ b/drivers/acpi/proc.c
27821 @@ -343,19 +343,13 @@ acpi_system_write_wakeup_device(struct file *file,
27822 size_t count, loff_t * ppos)
27823 {
27824 struct list_head *node, *next;
27825 - char strbuf[5];
27826 - char str[5] = "";
27827 - unsigned int len = count;
27828 + char strbuf[5] = {0};
27829
27830 - if (len > 4)
27831 - len = 4;
27832 - if (len < 0)
27833 + if (count > 4)
27834 + count = 4;
27835 + if (copy_from_user(strbuf, buffer, count))
27836 return -EFAULT;
27837 -
27838 - if (copy_from_user(strbuf, buffer, len))
27839 - return -EFAULT;
27840 - strbuf[len] = '\0';
27841 - sscanf(strbuf, "%s", str);
27842 + strbuf[count] = '\0';
27843
27844 mutex_lock(&acpi_device_lock);
27845 list_for_each_safe(node, next, &acpi_wakeup_device_list) {
27846 @@ -364,7 +358,7 @@ acpi_system_write_wakeup_device(struct file *file,
27847 if (!dev->wakeup.flags.valid)
27848 continue;
27849
27850 - if (!strncmp(dev->pnp.bus_id, str, 4)) {
27851 + if (!strncmp(dev->pnp.bus_id, strbuf, 4)) {
27852 if (device_can_wakeup(&dev->dev)) {
27853 bool enable = !device_may_wakeup(&dev->dev);
27854 device_set_wakeup_enable(&dev->dev, enable);
27855 diff --git a/drivers/acpi/processor_driver.c b/drivers/acpi/processor_driver.c
27856 index bbac51e..4c094f9 100644
27857 --- a/drivers/acpi/processor_driver.c
27858 +++ b/drivers/acpi/processor_driver.c
27859 @@ -556,7 +556,7 @@ static int __cpuinit acpi_processor_add(struct acpi_device *device)
27860 return 0;
27861 #endif
27862
27863 - BUG_ON((pr->id >= nr_cpu_ids) || (pr->id < 0));
27864 + BUG_ON(pr->id >= nr_cpu_ids);
27865
27866 /*
27867 * Buggy BIOS check
27868 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
27869 index 71e8385..98d1e14 100644
27870 --- a/drivers/ata/libata-core.c
27871 +++ b/drivers/ata/libata-core.c
27872 @@ -4744,7 +4744,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
27873 struct ata_port *ap;
27874 unsigned int tag;
27875
27876 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27877 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27878 ap = qc->ap;
27879
27880 qc->flags = 0;
27881 @@ -4760,7 +4760,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
27882 struct ata_port *ap;
27883 struct ata_link *link;
27884
27885 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27886 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
27887 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
27888 ap = qc->ap;
27889 link = qc->dev->link;
27890 @@ -5824,6 +5824,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27891 return;
27892
27893 spin_lock(&lock);
27894 + pax_open_kernel();
27895
27896 for (cur = ops->inherits; cur; cur = cur->inherits) {
27897 void **inherit = (void **)cur;
27898 @@ -5837,8 +5838,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
27899 if (IS_ERR(*pp))
27900 *pp = NULL;
27901
27902 - ops->inherits = NULL;
27903 + *(struct ata_port_operations **)&ops->inherits = NULL;
27904
27905 + pax_close_kernel();
27906 spin_unlock(&lock);
27907 }
27908
27909 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
27910 index ac6a5be..c7176b1 100644
27911 --- a/drivers/ata/pata_arasan_cf.c
27912 +++ b/drivers/ata/pata_arasan_cf.c
27913 @@ -862,7 +862,9 @@ static int __devinit arasan_cf_probe(struct platform_device *pdev)
27914 /* Handle platform specific quirks */
27915 if (pdata->quirk) {
27916 if (pdata->quirk & CF_BROKEN_PIO) {
27917 - ap->ops->set_piomode = NULL;
27918 + pax_open_kernel();
27919 + *(void **)&ap->ops->set_piomode = NULL;
27920 + pax_close_kernel();
27921 ap->pio_mask = 0;
27922 }
27923 if (pdata->quirk & CF_BROKEN_MWDMA)
27924 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
27925 index f9b983a..887b9d8 100644
27926 --- a/drivers/atm/adummy.c
27927 +++ b/drivers/atm/adummy.c
27928 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
27929 vcc->pop(vcc, skb);
27930 else
27931 dev_kfree_skb_any(skb);
27932 - atomic_inc(&vcc->stats->tx);
27933 + atomic_inc_unchecked(&vcc->stats->tx);
27934
27935 return 0;
27936 }
27937 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
27938 index 89b30f3..7964211 100644
27939 --- a/drivers/atm/ambassador.c
27940 +++ b/drivers/atm/ambassador.c
27941 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
27942 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
27943
27944 // VC layer stats
27945 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
27946 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
27947
27948 // free the descriptor
27949 kfree (tx_descr);
27950 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27951 dump_skb ("<<<", vc, skb);
27952
27953 // VC layer stats
27954 - atomic_inc(&atm_vcc->stats->rx);
27955 + atomic_inc_unchecked(&atm_vcc->stats->rx);
27956 __net_timestamp(skb);
27957 // end of our responsibility
27958 atm_vcc->push (atm_vcc, skb);
27959 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
27960 } else {
27961 PRINTK (KERN_INFO, "dropped over-size frame");
27962 // should we count this?
27963 - atomic_inc(&atm_vcc->stats->rx_drop);
27964 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
27965 }
27966
27967 } else {
27968 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
27969 }
27970
27971 if (check_area (skb->data, skb->len)) {
27972 - atomic_inc(&atm_vcc->stats->tx_err);
27973 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
27974 return -ENOMEM; // ?
27975 }
27976
27977 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
27978 index b22d71c..d6e1049 100644
27979 --- a/drivers/atm/atmtcp.c
27980 +++ b/drivers/atm/atmtcp.c
27981 @@ -207,7 +207,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27982 if (vcc->pop) vcc->pop(vcc,skb);
27983 else dev_kfree_skb(skb);
27984 if (dev_data) return 0;
27985 - atomic_inc(&vcc->stats->tx_err);
27986 + atomic_inc_unchecked(&vcc->stats->tx_err);
27987 return -ENOLINK;
27988 }
27989 size = skb->len+sizeof(struct atmtcp_hdr);
27990 @@ -215,7 +215,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
27991 if (!new_skb) {
27992 if (vcc->pop) vcc->pop(vcc,skb);
27993 else dev_kfree_skb(skb);
27994 - atomic_inc(&vcc->stats->tx_err);
27995 + atomic_inc_unchecked(&vcc->stats->tx_err);
27996 return -ENOBUFS;
27997 }
27998 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
27999 @@ -226,8 +226,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
28000 if (vcc->pop) vcc->pop(vcc,skb);
28001 else dev_kfree_skb(skb);
28002 out_vcc->push(out_vcc,new_skb);
28003 - atomic_inc(&vcc->stats->tx);
28004 - atomic_inc(&out_vcc->stats->rx);
28005 + atomic_inc_unchecked(&vcc->stats->tx);
28006 + atomic_inc_unchecked(&out_vcc->stats->rx);
28007 return 0;
28008 }
28009
28010 @@ -301,7 +301,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28011 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
28012 read_unlock(&vcc_sklist_lock);
28013 if (!out_vcc) {
28014 - atomic_inc(&vcc->stats->tx_err);
28015 + atomic_inc_unchecked(&vcc->stats->tx_err);
28016 goto done;
28017 }
28018 skb_pull(skb,sizeof(struct atmtcp_hdr));
28019 @@ -313,8 +313,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
28020 __net_timestamp(new_skb);
28021 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
28022 out_vcc->push(out_vcc,new_skb);
28023 - atomic_inc(&vcc->stats->tx);
28024 - atomic_inc(&out_vcc->stats->rx);
28025 + atomic_inc_unchecked(&vcc->stats->tx);
28026 + atomic_inc_unchecked(&out_vcc->stats->rx);
28027 done:
28028 if (vcc->pop) vcc->pop(vcc,skb);
28029 else dev_kfree_skb(skb);
28030 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
28031 index 2059ee4..faf51c7 100644
28032 --- a/drivers/atm/eni.c
28033 +++ b/drivers/atm/eni.c
28034 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
28035 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
28036 vcc->dev->number);
28037 length = 0;
28038 - atomic_inc(&vcc->stats->rx_err);
28039 + atomic_inc_unchecked(&vcc->stats->rx_err);
28040 }
28041 else {
28042 length = ATM_CELL_SIZE-1; /* no HEC */
28043 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28044 size);
28045 }
28046 eff = length = 0;
28047 - atomic_inc(&vcc->stats->rx_err);
28048 + atomic_inc_unchecked(&vcc->stats->rx_err);
28049 }
28050 else {
28051 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
28052 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
28053 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
28054 vcc->dev->number,vcc->vci,length,size << 2,descr);
28055 length = eff = 0;
28056 - atomic_inc(&vcc->stats->rx_err);
28057 + atomic_inc_unchecked(&vcc->stats->rx_err);
28058 }
28059 }
28060 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
28061 @@ -767,7 +767,7 @@ rx_dequeued++;
28062 vcc->push(vcc,skb);
28063 pushed++;
28064 }
28065 - atomic_inc(&vcc->stats->rx);
28066 + atomic_inc_unchecked(&vcc->stats->rx);
28067 }
28068 wake_up(&eni_dev->rx_wait);
28069 }
28070 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
28071 PCI_DMA_TODEVICE);
28072 if (vcc->pop) vcc->pop(vcc,skb);
28073 else dev_kfree_skb_irq(skb);
28074 - atomic_inc(&vcc->stats->tx);
28075 + atomic_inc_unchecked(&vcc->stats->tx);
28076 wake_up(&eni_dev->tx_wait);
28077 dma_complete++;
28078 }
28079 @@ -1567,7 +1567,7 @@ tx_complete++;
28080 /*--------------------------------- entries ---------------------------------*/
28081
28082
28083 -static const char *media_name[] __devinitdata = {
28084 +static const char *media_name[] __devinitconst = {
28085 "MMF", "SMF", "MMF", "03?", /* 0- 3 */
28086 "UTP", "05?", "06?", "07?", /* 4- 7 */
28087 "TAXI","09?", "10?", "11?", /* 8-11 */
28088 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
28089 index 86fed1b..6dc4721 100644
28090 --- a/drivers/atm/firestream.c
28091 +++ b/drivers/atm/firestream.c
28092 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
28093 }
28094 }
28095
28096 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28097 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28098
28099 fs_dprintk (FS_DEBUG_TXMEM, "i");
28100 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
28101 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28102 #endif
28103 skb_put (skb, qe->p1 & 0xffff);
28104 ATM_SKB(skb)->vcc = atm_vcc;
28105 - atomic_inc(&atm_vcc->stats->rx);
28106 + atomic_inc_unchecked(&atm_vcc->stats->rx);
28107 __net_timestamp(skb);
28108 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
28109 atm_vcc->push (atm_vcc, skb);
28110 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
28111 kfree (pe);
28112 }
28113 if (atm_vcc)
28114 - atomic_inc(&atm_vcc->stats->rx_drop);
28115 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28116 break;
28117 case 0x1f: /* Reassembly abort: no buffers. */
28118 /* Silently increment error counter. */
28119 if (atm_vcc)
28120 - atomic_inc(&atm_vcc->stats->rx_drop);
28121 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
28122 break;
28123 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
28124 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
28125 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
28126 index 361f5ae..7fc552d 100644
28127 --- a/drivers/atm/fore200e.c
28128 +++ b/drivers/atm/fore200e.c
28129 @@ -933,9 +933,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
28130 #endif
28131 /* check error condition */
28132 if (*entry->status & STATUS_ERROR)
28133 - atomic_inc(&vcc->stats->tx_err);
28134 + atomic_inc_unchecked(&vcc->stats->tx_err);
28135 else
28136 - atomic_inc(&vcc->stats->tx);
28137 + atomic_inc_unchecked(&vcc->stats->tx);
28138 }
28139 }
28140
28141 @@ -1084,7 +1084,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28142 if (skb == NULL) {
28143 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
28144
28145 - atomic_inc(&vcc->stats->rx_drop);
28146 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28147 return -ENOMEM;
28148 }
28149
28150 @@ -1127,14 +1127,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
28151
28152 dev_kfree_skb_any(skb);
28153
28154 - atomic_inc(&vcc->stats->rx_drop);
28155 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28156 return -ENOMEM;
28157 }
28158
28159 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28160
28161 vcc->push(vcc, skb);
28162 - atomic_inc(&vcc->stats->rx);
28163 + atomic_inc_unchecked(&vcc->stats->rx);
28164
28165 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
28166
28167 @@ -1212,7 +1212,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
28168 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
28169 fore200e->atm_dev->number,
28170 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
28171 - atomic_inc(&vcc->stats->rx_err);
28172 + atomic_inc_unchecked(&vcc->stats->rx_err);
28173 }
28174 }
28175
28176 @@ -1657,7 +1657,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
28177 goto retry_here;
28178 }
28179
28180 - atomic_inc(&vcc->stats->tx_err);
28181 + atomic_inc_unchecked(&vcc->stats->tx_err);
28182
28183 fore200e->tx_sat++;
28184 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
28185 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
28186 index b182c2f..1c6fa8a 100644
28187 --- a/drivers/atm/he.c
28188 +++ b/drivers/atm/he.c
28189 @@ -1709,7 +1709,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28190
28191 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
28192 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
28193 - atomic_inc(&vcc->stats->rx_drop);
28194 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28195 goto return_host_buffers;
28196 }
28197
28198 @@ -1736,7 +1736,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28199 RBRQ_LEN_ERR(he_dev->rbrq_head)
28200 ? "LEN_ERR" : "",
28201 vcc->vpi, vcc->vci);
28202 - atomic_inc(&vcc->stats->rx_err);
28203 + atomic_inc_unchecked(&vcc->stats->rx_err);
28204 goto return_host_buffers;
28205 }
28206
28207 @@ -1788,7 +1788,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
28208 vcc->push(vcc, skb);
28209 spin_lock(&he_dev->global_lock);
28210
28211 - atomic_inc(&vcc->stats->rx);
28212 + atomic_inc_unchecked(&vcc->stats->rx);
28213
28214 return_host_buffers:
28215 ++pdus_assembled;
28216 @@ -2114,7 +2114,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
28217 tpd->vcc->pop(tpd->vcc, tpd->skb);
28218 else
28219 dev_kfree_skb_any(tpd->skb);
28220 - atomic_inc(&tpd->vcc->stats->tx_err);
28221 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
28222 }
28223 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
28224 return;
28225 @@ -2526,7 +2526,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28226 vcc->pop(vcc, skb);
28227 else
28228 dev_kfree_skb_any(skb);
28229 - atomic_inc(&vcc->stats->tx_err);
28230 + atomic_inc_unchecked(&vcc->stats->tx_err);
28231 return -EINVAL;
28232 }
28233
28234 @@ -2537,7 +2537,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28235 vcc->pop(vcc, skb);
28236 else
28237 dev_kfree_skb_any(skb);
28238 - atomic_inc(&vcc->stats->tx_err);
28239 + atomic_inc_unchecked(&vcc->stats->tx_err);
28240 return -EINVAL;
28241 }
28242 #endif
28243 @@ -2549,7 +2549,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28244 vcc->pop(vcc, skb);
28245 else
28246 dev_kfree_skb_any(skb);
28247 - atomic_inc(&vcc->stats->tx_err);
28248 + atomic_inc_unchecked(&vcc->stats->tx_err);
28249 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28250 return -ENOMEM;
28251 }
28252 @@ -2591,7 +2591,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28253 vcc->pop(vcc, skb);
28254 else
28255 dev_kfree_skb_any(skb);
28256 - atomic_inc(&vcc->stats->tx_err);
28257 + atomic_inc_unchecked(&vcc->stats->tx_err);
28258 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28259 return -ENOMEM;
28260 }
28261 @@ -2622,7 +2622,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
28262 __enqueue_tpd(he_dev, tpd, cid);
28263 spin_unlock_irqrestore(&he_dev->global_lock, flags);
28264
28265 - atomic_inc(&vcc->stats->tx);
28266 + atomic_inc_unchecked(&vcc->stats->tx);
28267
28268 return 0;
28269 }
28270 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
28271 index 7d01c2a..4e3ac01 100644
28272 --- a/drivers/atm/horizon.c
28273 +++ b/drivers/atm/horizon.c
28274 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
28275 {
28276 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
28277 // VC layer stats
28278 - atomic_inc(&vcc->stats->rx);
28279 + atomic_inc_unchecked(&vcc->stats->rx);
28280 __net_timestamp(skb);
28281 // end of our responsibility
28282 vcc->push (vcc, skb);
28283 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
28284 dev->tx_iovec = NULL;
28285
28286 // VC layer stats
28287 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
28288 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
28289
28290 // free the skb
28291 hrz_kfree_skb (skb);
28292 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
28293 index 8974bd2..b856f85 100644
28294 --- a/drivers/atm/idt77252.c
28295 +++ b/drivers/atm/idt77252.c
28296 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
28297 else
28298 dev_kfree_skb(skb);
28299
28300 - atomic_inc(&vcc->stats->tx);
28301 + atomic_inc_unchecked(&vcc->stats->tx);
28302 }
28303
28304 atomic_dec(&scq->used);
28305 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28306 if ((sb = dev_alloc_skb(64)) == NULL) {
28307 printk("%s: Can't allocate buffers for aal0.\n",
28308 card->name);
28309 - atomic_add(i, &vcc->stats->rx_drop);
28310 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28311 break;
28312 }
28313 if (!atm_charge(vcc, sb->truesize)) {
28314 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
28315 card->name);
28316 - atomic_add(i - 1, &vcc->stats->rx_drop);
28317 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
28318 dev_kfree_skb(sb);
28319 break;
28320 }
28321 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28322 ATM_SKB(sb)->vcc = vcc;
28323 __net_timestamp(sb);
28324 vcc->push(vcc, sb);
28325 - atomic_inc(&vcc->stats->rx);
28326 + atomic_inc_unchecked(&vcc->stats->rx);
28327
28328 cell += ATM_CELL_PAYLOAD;
28329 }
28330 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28331 "(CDC: %08x)\n",
28332 card->name, len, rpp->len, readl(SAR_REG_CDC));
28333 recycle_rx_pool_skb(card, rpp);
28334 - atomic_inc(&vcc->stats->rx_err);
28335 + atomic_inc_unchecked(&vcc->stats->rx_err);
28336 return;
28337 }
28338 if (stat & SAR_RSQE_CRC) {
28339 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
28340 recycle_rx_pool_skb(card, rpp);
28341 - atomic_inc(&vcc->stats->rx_err);
28342 + atomic_inc_unchecked(&vcc->stats->rx_err);
28343 return;
28344 }
28345 if (skb_queue_len(&rpp->queue) > 1) {
28346 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28347 RXPRINTK("%s: Can't alloc RX skb.\n",
28348 card->name);
28349 recycle_rx_pool_skb(card, rpp);
28350 - atomic_inc(&vcc->stats->rx_err);
28351 + atomic_inc_unchecked(&vcc->stats->rx_err);
28352 return;
28353 }
28354 if (!atm_charge(vcc, skb->truesize)) {
28355 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28356 __net_timestamp(skb);
28357
28358 vcc->push(vcc, skb);
28359 - atomic_inc(&vcc->stats->rx);
28360 + atomic_inc_unchecked(&vcc->stats->rx);
28361
28362 return;
28363 }
28364 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
28365 __net_timestamp(skb);
28366
28367 vcc->push(vcc, skb);
28368 - atomic_inc(&vcc->stats->rx);
28369 + atomic_inc_unchecked(&vcc->stats->rx);
28370
28371 if (skb->truesize > SAR_FB_SIZE_3)
28372 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
28373 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
28374 if (vcc->qos.aal != ATM_AAL0) {
28375 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
28376 card->name, vpi, vci);
28377 - atomic_inc(&vcc->stats->rx_drop);
28378 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28379 goto drop;
28380 }
28381
28382 if ((sb = dev_alloc_skb(64)) == NULL) {
28383 printk("%s: Can't allocate buffers for AAL0.\n",
28384 card->name);
28385 - atomic_inc(&vcc->stats->rx_err);
28386 + atomic_inc_unchecked(&vcc->stats->rx_err);
28387 goto drop;
28388 }
28389
28390 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
28391 ATM_SKB(sb)->vcc = vcc;
28392 __net_timestamp(sb);
28393 vcc->push(vcc, sb);
28394 - atomic_inc(&vcc->stats->rx);
28395 + atomic_inc_unchecked(&vcc->stats->rx);
28396
28397 drop:
28398 skb_pull(queue, 64);
28399 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28400
28401 if (vc == NULL) {
28402 printk("%s: NULL connection in send().\n", card->name);
28403 - atomic_inc(&vcc->stats->tx_err);
28404 + atomic_inc_unchecked(&vcc->stats->tx_err);
28405 dev_kfree_skb(skb);
28406 return -EINVAL;
28407 }
28408 if (!test_bit(VCF_TX, &vc->flags)) {
28409 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
28410 - atomic_inc(&vcc->stats->tx_err);
28411 + atomic_inc_unchecked(&vcc->stats->tx_err);
28412 dev_kfree_skb(skb);
28413 return -EINVAL;
28414 }
28415 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28416 break;
28417 default:
28418 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
28419 - atomic_inc(&vcc->stats->tx_err);
28420 + atomic_inc_unchecked(&vcc->stats->tx_err);
28421 dev_kfree_skb(skb);
28422 return -EINVAL;
28423 }
28424
28425 if (skb_shinfo(skb)->nr_frags != 0) {
28426 printk("%s: No scatter-gather yet.\n", card->name);
28427 - atomic_inc(&vcc->stats->tx_err);
28428 + atomic_inc_unchecked(&vcc->stats->tx_err);
28429 dev_kfree_skb(skb);
28430 return -EINVAL;
28431 }
28432 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
28433
28434 err = queue_skb(card, vc, skb, oam);
28435 if (err) {
28436 - atomic_inc(&vcc->stats->tx_err);
28437 + atomic_inc_unchecked(&vcc->stats->tx_err);
28438 dev_kfree_skb(skb);
28439 return err;
28440 }
28441 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
28442 skb = dev_alloc_skb(64);
28443 if (!skb) {
28444 printk("%s: Out of memory in send_oam().\n", card->name);
28445 - atomic_inc(&vcc->stats->tx_err);
28446 + atomic_inc_unchecked(&vcc->stats->tx_err);
28447 return -ENOMEM;
28448 }
28449 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
28450 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
28451 index d438601..8b98495 100644
28452 --- a/drivers/atm/iphase.c
28453 +++ b/drivers/atm/iphase.c
28454 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
28455 status = (u_short) (buf_desc_ptr->desc_mode);
28456 if (status & (RX_CER | RX_PTE | RX_OFL))
28457 {
28458 - atomic_inc(&vcc->stats->rx_err);
28459 + atomic_inc_unchecked(&vcc->stats->rx_err);
28460 IF_ERR(printk("IA: bad packet, dropping it");)
28461 if (status & RX_CER) {
28462 IF_ERR(printk(" cause: packet CRC error\n");)
28463 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
28464 len = dma_addr - buf_addr;
28465 if (len > iadev->rx_buf_sz) {
28466 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
28467 - atomic_inc(&vcc->stats->rx_err);
28468 + atomic_inc_unchecked(&vcc->stats->rx_err);
28469 goto out_free_desc;
28470 }
28471
28472 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28473 ia_vcc = INPH_IA_VCC(vcc);
28474 if (ia_vcc == NULL)
28475 {
28476 - atomic_inc(&vcc->stats->rx_err);
28477 + atomic_inc_unchecked(&vcc->stats->rx_err);
28478 atm_return(vcc, skb->truesize);
28479 dev_kfree_skb_any(skb);
28480 goto INCR_DLE;
28481 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28482 if ((length > iadev->rx_buf_sz) || (length >
28483 (skb->len - sizeof(struct cpcs_trailer))))
28484 {
28485 - atomic_inc(&vcc->stats->rx_err);
28486 + atomic_inc_unchecked(&vcc->stats->rx_err);
28487 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
28488 length, skb->len);)
28489 atm_return(vcc, skb->truesize);
28490 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
28491
28492 IF_RX(printk("rx_dle_intr: skb push");)
28493 vcc->push(vcc,skb);
28494 - atomic_inc(&vcc->stats->rx);
28495 + atomic_inc_unchecked(&vcc->stats->rx);
28496 iadev->rx_pkt_cnt++;
28497 }
28498 INCR_DLE:
28499 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
28500 {
28501 struct k_sonet_stats *stats;
28502 stats = &PRIV(_ia_dev[board])->sonet_stats;
28503 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
28504 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
28505 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
28506 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
28507 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
28508 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
28509 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
28510 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
28511 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
28512 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
28513 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
28514 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
28515 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
28516 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
28517 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
28518 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
28519 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
28520 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
28521 }
28522 ia_cmds.status = 0;
28523 break;
28524 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28525 if ((desc == 0) || (desc > iadev->num_tx_desc))
28526 {
28527 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
28528 - atomic_inc(&vcc->stats->tx);
28529 + atomic_inc_unchecked(&vcc->stats->tx);
28530 if (vcc->pop)
28531 vcc->pop(vcc, skb);
28532 else
28533 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
28534 ATM_DESC(skb) = vcc->vci;
28535 skb_queue_tail(&iadev->tx_dma_q, skb);
28536
28537 - atomic_inc(&vcc->stats->tx);
28538 + atomic_inc_unchecked(&vcc->stats->tx);
28539 iadev->tx_pkt_cnt++;
28540 /* Increment transaction counter */
28541 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
28542
28543 #if 0
28544 /* add flow control logic */
28545 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
28546 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
28547 if (iavcc->vc_desc_cnt > 10) {
28548 vcc->tx_quota = vcc->tx_quota * 3 / 4;
28549 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
28550 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
28551 index 68c7588..7036683 100644
28552 --- a/drivers/atm/lanai.c
28553 +++ b/drivers/atm/lanai.c
28554 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
28555 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
28556 lanai_endtx(lanai, lvcc);
28557 lanai_free_skb(lvcc->tx.atmvcc, skb);
28558 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
28559 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
28560 }
28561
28562 /* Try to fill the buffer - don't call unless there is backlog */
28563 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
28564 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
28565 __net_timestamp(skb);
28566 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
28567 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
28568 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
28569 out:
28570 lvcc->rx.buf.ptr = end;
28571 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
28572 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28573 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
28574 "vcc %d\n", lanai->number, (unsigned int) s, vci);
28575 lanai->stats.service_rxnotaal5++;
28576 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28577 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28578 return 0;
28579 }
28580 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
28581 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28582 int bytes;
28583 read_unlock(&vcc_sklist_lock);
28584 DPRINTK("got trashed rx pdu on vci %d\n", vci);
28585 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28586 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28587 lvcc->stats.x.aal5.service_trash++;
28588 bytes = (SERVICE_GET_END(s) * 16) -
28589 (((unsigned long) lvcc->rx.buf.ptr) -
28590 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28591 }
28592 if (s & SERVICE_STREAM) {
28593 read_unlock(&vcc_sklist_lock);
28594 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28595 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28596 lvcc->stats.x.aal5.service_stream++;
28597 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
28598 "PDU on VCI %d!\n", lanai->number, vci);
28599 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
28600 return 0;
28601 }
28602 DPRINTK("got rx crc error on vci %d\n", vci);
28603 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
28604 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
28605 lvcc->stats.x.aal5.service_rxcrc++;
28606 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
28607 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
28608 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
28609 index 1c70c45..300718d 100644
28610 --- a/drivers/atm/nicstar.c
28611 +++ b/drivers/atm/nicstar.c
28612 @@ -1654,7 +1654,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28613 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
28614 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
28615 card->index);
28616 - atomic_inc(&vcc->stats->tx_err);
28617 + atomic_inc_unchecked(&vcc->stats->tx_err);
28618 dev_kfree_skb_any(skb);
28619 return -EINVAL;
28620 }
28621 @@ -1662,7 +1662,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28622 if (!vc->tx) {
28623 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
28624 card->index);
28625 - atomic_inc(&vcc->stats->tx_err);
28626 + atomic_inc_unchecked(&vcc->stats->tx_err);
28627 dev_kfree_skb_any(skb);
28628 return -EINVAL;
28629 }
28630 @@ -1670,14 +1670,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28631 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
28632 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
28633 card->index);
28634 - atomic_inc(&vcc->stats->tx_err);
28635 + atomic_inc_unchecked(&vcc->stats->tx_err);
28636 dev_kfree_skb_any(skb);
28637 return -EINVAL;
28638 }
28639
28640 if (skb_shinfo(skb)->nr_frags != 0) {
28641 printk("nicstar%d: No scatter-gather yet.\n", card->index);
28642 - atomic_inc(&vcc->stats->tx_err);
28643 + atomic_inc_unchecked(&vcc->stats->tx_err);
28644 dev_kfree_skb_any(skb);
28645 return -EINVAL;
28646 }
28647 @@ -1725,11 +1725,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
28648 }
28649
28650 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
28651 - atomic_inc(&vcc->stats->tx_err);
28652 + atomic_inc_unchecked(&vcc->stats->tx_err);
28653 dev_kfree_skb_any(skb);
28654 return -EIO;
28655 }
28656 - atomic_inc(&vcc->stats->tx);
28657 + atomic_inc_unchecked(&vcc->stats->tx);
28658
28659 return 0;
28660 }
28661 @@ -2046,14 +2046,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28662 printk
28663 ("nicstar%d: Can't allocate buffers for aal0.\n",
28664 card->index);
28665 - atomic_add(i, &vcc->stats->rx_drop);
28666 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
28667 break;
28668 }
28669 if (!atm_charge(vcc, sb->truesize)) {
28670 RXPRINTK
28671 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
28672 card->index);
28673 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28674 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
28675 dev_kfree_skb_any(sb);
28676 break;
28677 }
28678 @@ -2068,7 +2068,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28679 ATM_SKB(sb)->vcc = vcc;
28680 __net_timestamp(sb);
28681 vcc->push(vcc, sb);
28682 - atomic_inc(&vcc->stats->rx);
28683 + atomic_inc_unchecked(&vcc->stats->rx);
28684 cell += ATM_CELL_PAYLOAD;
28685 }
28686
28687 @@ -2085,7 +2085,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28688 if (iovb == NULL) {
28689 printk("nicstar%d: Out of iovec buffers.\n",
28690 card->index);
28691 - atomic_inc(&vcc->stats->rx_drop);
28692 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28693 recycle_rx_buf(card, skb);
28694 return;
28695 }
28696 @@ -2109,7 +2109,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28697 small or large buffer itself. */
28698 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
28699 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
28700 - atomic_inc(&vcc->stats->rx_err);
28701 + atomic_inc_unchecked(&vcc->stats->rx_err);
28702 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28703 NS_MAX_IOVECS);
28704 NS_PRV_IOVCNT(iovb) = 0;
28705 @@ -2129,7 +2129,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28706 ("nicstar%d: Expected a small buffer, and this is not one.\n",
28707 card->index);
28708 which_list(card, skb);
28709 - atomic_inc(&vcc->stats->rx_err);
28710 + atomic_inc_unchecked(&vcc->stats->rx_err);
28711 recycle_rx_buf(card, skb);
28712 vc->rx_iov = NULL;
28713 recycle_iov_buf(card, iovb);
28714 @@ -2142,7 +2142,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28715 ("nicstar%d: Expected a large buffer, and this is not one.\n",
28716 card->index);
28717 which_list(card, skb);
28718 - atomic_inc(&vcc->stats->rx_err);
28719 + atomic_inc_unchecked(&vcc->stats->rx_err);
28720 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28721 NS_PRV_IOVCNT(iovb));
28722 vc->rx_iov = NULL;
28723 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28724 printk(" - PDU size mismatch.\n");
28725 else
28726 printk(".\n");
28727 - atomic_inc(&vcc->stats->rx_err);
28728 + atomic_inc_unchecked(&vcc->stats->rx_err);
28729 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
28730 NS_PRV_IOVCNT(iovb));
28731 vc->rx_iov = NULL;
28732 @@ -2179,7 +2179,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28733 /* skb points to a small buffer */
28734 if (!atm_charge(vcc, skb->truesize)) {
28735 push_rxbufs(card, skb);
28736 - atomic_inc(&vcc->stats->rx_drop);
28737 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28738 } else {
28739 skb_put(skb, len);
28740 dequeue_sm_buf(card, skb);
28741 @@ -2189,7 +2189,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28742 ATM_SKB(skb)->vcc = vcc;
28743 __net_timestamp(skb);
28744 vcc->push(vcc, skb);
28745 - atomic_inc(&vcc->stats->rx);
28746 + atomic_inc_unchecked(&vcc->stats->rx);
28747 }
28748 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
28749 struct sk_buff *sb;
28750 @@ -2200,7 +2200,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28751 if (len <= NS_SMBUFSIZE) {
28752 if (!atm_charge(vcc, sb->truesize)) {
28753 push_rxbufs(card, sb);
28754 - atomic_inc(&vcc->stats->rx_drop);
28755 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28756 } else {
28757 skb_put(sb, len);
28758 dequeue_sm_buf(card, sb);
28759 @@ -2210,7 +2210,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28760 ATM_SKB(sb)->vcc = vcc;
28761 __net_timestamp(sb);
28762 vcc->push(vcc, sb);
28763 - atomic_inc(&vcc->stats->rx);
28764 + atomic_inc_unchecked(&vcc->stats->rx);
28765 }
28766
28767 push_rxbufs(card, skb);
28768 @@ -2219,7 +2219,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28769
28770 if (!atm_charge(vcc, skb->truesize)) {
28771 push_rxbufs(card, skb);
28772 - atomic_inc(&vcc->stats->rx_drop);
28773 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28774 } else {
28775 dequeue_lg_buf(card, skb);
28776 #ifdef NS_USE_DESTRUCTORS
28777 @@ -2232,7 +2232,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28778 ATM_SKB(skb)->vcc = vcc;
28779 __net_timestamp(skb);
28780 vcc->push(vcc, skb);
28781 - atomic_inc(&vcc->stats->rx);
28782 + atomic_inc_unchecked(&vcc->stats->rx);
28783 }
28784
28785 push_rxbufs(card, sb);
28786 @@ -2253,7 +2253,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28787 printk
28788 ("nicstar%d: Out of huge buffers.\n",
28789 card->index);
28790 - atomic_inc(&vcc->stats->rx_drop);
28791 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28792 recycle_iovec_rx_bufs(card,
28793 (struct iovec *)
28794 iovb->data,
28795 @@ -2304,7 +2304,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28796 card->hbpool.count++;
28797 } else
28798 dev_kfree_skb_any(hb);
28799 - atomic_inc(&vcc->stats->rx_drop);
28800 + atomic_inc_unchecked(&vcc->stats->rx_drop);
28801 } else {
28802 /* Copy the small buffer to the huge buffer */
28803 sb = (struct sk_buff *)iov->iov_base;
28804 @@ -2341,7 +2341,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
28805 #endif /* NS_USE_DESTRUCTORS */
28806 __net_timestamp(hb);
28807 vcc->push(vcc, hb);
28808 - atomic_inc(&vcc->stats->rx);
28809 + atomic_inc_unchecked(&vcc->stats->rx);
28810 }
28811 }
28812
28813 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
28814 index 9851093..adb2b1e 100644
28815 --- a/drivers/atm/solos-pci.c
28816 +++ b/drivers/atm/solos-pci.c
28817 @@ -714,7 +714,7 @@ void solos_bh(unsigned long card_arg)
28818 }
28819 atm_charge(vcc, skb->truesize);
28820 vcc->push(vcc, skb);
28821 - atomic_inc(&vcc->stats->rx);
28822 + atomic_inc_unchecked(&vcc->stats->rx);
28823 break;
28824
28825 case PKT_STATUS:
28826 @@ -1009,7 +1009,7 @@ static uint32_t fpga_tx(struct solos_card *card)
28827 vcc = SKB_CB(oldskb)->vcc;
28828
28829 if (vcc) {
28830 - atomic_inc(&vcc->stats->tx);
28831 + atomic_inc_unchecked(&vcc->stats->tx);
28832 solos_pop(vcc, oldskb);
28833 } else
28834 dev_kfree_skb_irq(oldskb);
28835 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
28836 index 0215934..ce9f5b1 100644
28837 --- a/drivers/atm/suni.c
28838 +++ b/drivers/atm/suni.c
28839 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
28840
28841
28842 #define ADD_LIMITED(s,v) \
28843 - atomic_add((v),&stats->s); \
28844 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
28845 + atomic_add_unchecked((v),&stats->s); \
28846 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
28847
28848
28849 static void suni_hz(unsigned long from_timer)
28850 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
28851 index 5120a96..e2572bd 100644
28852 --- a/drivers/atm/uPD98402.c
28853 +++ b/drivers/atm/uPD98402.c
28854 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
28855 struct sonet_stats tmp;
28856 int error = 0;
28857
28858 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28859 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
28860 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
28861 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
28862 if (zero && !error) {
28863 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
28864
28865
28866 #define ADD_LIMITED(s,v) \
28867 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
28868 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
28869 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28870 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
28871 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
28872 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
28873
28874
28875 static void stat_event(struct atm_dev *dev)
28876 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
28877 if (reason & uPD98402_INT_PFM) stat_event(dev);
28878 if (reason & uPD98402_INT_PCO) {
28879 (void) GET(PCOCR); /* clear interrupt cause */
28880 - atomic_add(GET(HECCT),
28881 + atomic_add_unchecked(GET(HECCT),
28882 &PRIV(dev)->sonet_stats.uncorr_hcs);
28883 }
28884 if ((reason & uPD98402_INT_RFO) &&
28885 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
28886 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
28887 uPD98402_INT_LOS),PIMR); /* enable them */
28888 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
28889 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28890 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
28891 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
28892 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
28893 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
28894 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
28895 return 0;
28896 }
28897
28898 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
28899 index abe4e20..83c4727 100644
28900 --- a/drivers/atm/zatm.c
28901 +++ b/drivers/atm/zatm.c
28902 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28903 }
28904 if (!size) {
28905 dev_kfree_skb_irq(skb);
28906 - if (vcc) atomic_inc(&vcc->stats->rx_err);
28907 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
28908 continue;
28909 }
28910 if (!atm_charge(vcc,skb->truesize)) {
28911 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
28912 skb->len = size;
28913 ATM_SKB(skb)->vcc = vcc;
28914 vcc->push(vcc,skb);
28915 - atomic_inc(&vcc->stats->rx);
28916 + atomic_inc_unchecked(&vcc->stats->rx);
28917 }
28918 zout(pos & 0xffff,MTA(mbx));
28919 #if 0 /* probably a stupid idea */
28920 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
28921 skb_queue_head(&zatm_vcc->backlog,skb);
28922 break;
28923 }
28924 - atomic_inc(&vcc->stats->tx);
28925 + atomic_inc_unchecked(&vcc->stats->tx);
28926 wake_up(&zatm_vcc->tx_wait);
28927 }
28928
28929 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
28930 index 765c3a2..771ace6 100644
28931 --- a/drivers/base/devtmpfs.c
28932 +++ b/drivers/base/devtmpfs.c
28933 @@ -368,7 +368,7 @@ int devtmpfs_mount(const char *mntdir)
28934 if (!thread)
28935 return 0;
28936
28937 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
28938 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
28939 if (err)
28940 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
28941 else
28942 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
28943 index cbb463b..babe2cf 100644
28944 --- a/drivers/base/power/wakeup.c
28945 +++ b/drivers/base/power/wakeup.c
28946 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
28947 * They need to be modified together atomically, so it's better to use one
28948 * atomic variable to hold them both.
28949 */
28950 -static atomic_t combined_event_count = ATOMIC_INIT(0);
28951 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
28952
28953 #define IN_PROGRESS_BITS (sizeof(int) * 4)
28954 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
28955
28956 static void split_counters(unsigned int *cnt, unsigned int *inpr)
28957 {
28958 - unsigned int comb = atomic_read(&combined_event_count);
28959 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
28960
28961 *cnt = (comb >> IN_PROGRESS_BITS);
28962 *inpr = comb & MAX_IN_PROGRESS;
28963 @@ -385,7 +385,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
28964 ws->start_prevent_time = ws->last_time;
28965
28966 /* Increment the counter of events in progress. */
28967 - cec = atomic_inc_return(&combined_event_count);
28968 + cec = atomic_inc_return_unchecked(&combined_event_count);
28969
28970 trace_wakeup_source_activate(ws->name, cec);
28971 }
28972 @@ -511,7 +511,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
28973 * Increment the counter of registered wakeup events and decrement the
28974 * couter of wakeup events in progress simultaneously.
28975 */
28976 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
28977 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
28978 trace_wakeup_source_deactivate(ws->name, cec);
28979
28980 split_counters(&cnt, &inpr);
28981 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
28982 index b0f553b..77b928b 100644
28983 --- a/drivers/block/cciss.c
28984 +++ b/drivers/block/cciss.c
28985 @@ -1198,6 +1198,8 @@ static int cciss_ioctl32_passthru(struct block_device *bdev, fmode_t mode,
28986 int err;
28987 u32 cp;
28988
28989 + memset(&arg64, 0, sizeof(arg64));
28990 +
28991 err = 0;
28992 err |=
28993 copy_from_user(&arg64.LUN_info, &arg32->LUN_info,
28994 @@ -3007,7 +3009,7 @@ static void start_io(ctlr_info_t *h)
28995 while (!list_empty(&h->reqQ)) {
28996 c = list_entry(h->reqQ.next, CommandList_struct, list);
28997 /* can't do anything if fifo is full */
28998 - if ((h->access.fifo_full(h))) {
28999 + if ((h->access->fifo_full(h))) {
29000 dev_warn(&h->pdev->dev, "fifo full\n");
29001 break;
29002 }
29003 @@ -3017,7 +3019,7 @@ static void start_io(ctlr_info_t *h)
29004 h->Qdepth--;
29005
29006 /* Tell the controller execute command */
29007 - h->access.submit_command(h, c);
29008 + h->access->submit_command(h, c);
29009
29010 /* Put job onto the completed Q */
29011 addQ(&h->cmpQ, c);
29012 @@ -3443,17 +3445,17 @@ startio:
29013
29014 static inline unsigned long get_next_completion(ctlr_info_t *h)
29015 {
29016 - return h->access.command_completed(h);
29017 + return h->access->command_completed(h);
29018 }
29019
29020 static inline int interrupt_pending(ctlr_info_t *h)
29021 {
29022 - return h->access.intr_pending(h);
29023 + return h->access->intr_pending(h);
29024 }
29025
29026 static inline long interrupt_not_for_us(ctlr_info_t *h)
29027 {
29028 - return ((h->access.intr_pending(h) == 0) ||
29029 + return ((h->access->intr_pending(h) == 0) ||
29030 (h->interrupts_enabled == 0));
29031 }
29032
29033 @@ -3486,7 +3488,7 @@ static inline u32 next_command(ctlr_info_t *h)
29034 u32 a;
29035
29036 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
29037 - return h->access.command_completed(h);
29038 + return h->access->command_completed(h);
29039
29040 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
29041 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
29042 @@ -4044,7 +4046,7 @@ static void __devinit cciss_put_controller_into_performant_mode(ctlr_info_t *h)
29043 trans_support & CFGTBL_Trans_use_short_tags);
29044
29045 /* Change the access methods to the performant access methods */
29046 - h->access = SA5_performant_access;
29047 + h->access = &SA5_performant_access;
29048 h->transMethod = CFGTBL_Trans_Performant;
29049
29050 return;
29051 @@ -4316,7 +4318,7 @@ static int __devinit cciss_pci_init(ctlr_info_t *h)
29052 if (prod_index < 0)
29053 return -ENODEV;
29054 h->product_name = products[prod_index].product_name;
29055 - h->access = *(products[prod_index].access);
29056 + h->access = products[prod_index].access;
29057
29058 if (cciss_board_disabled(h)) {
29059 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
29060 @@ -5041,7 +5043,7 @@ reinit_after_soft_reset:
29061 }
29062
29063 /* make sure the board interrupts are off */
29064 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29065 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29066 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
29067 if (rc)
29068 goto clean2;
29069 @@ -5093,7 +5095,7 @@ reinit_after_soft_reset:
29070 * fake ones to scoop up any residual completions.
29071 */
29072 spin_lock_irqsave(&h->lock, flags);
29073 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29074 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29075 spin_unlock_irqrestore(&h->lock, flags);
29076 free_irq(h->intr[h->intr_mode], h);
29077 rc = cciss_request_irq(h, cciss_msix_discard_completions,
29078 @@ -5113,9 +5115,9 @@ reinit_after_soft_reset:
29079 dev_info(&h->pdev->dev, "Board READY.\n");
29080 dev_info(&h->pdev->dev,
29081 "Waiting for stale completions to drain.\n");
29082 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29083 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29084 msleep(10000);
29085 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29086 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29087
29088 rc = controller_reset_failed(h->cfgtable);
29089 if (rc)
29090 @@ -5138,7 +5140,7 @@ reinit_after_soft_reset:
29091 cciss_scsi_setup(h);
29092
29093 /* Turn the interrupts on so we can service requests */
29094 - h->access.set_intr_mask(h, CCISS_INTR_ON);
29095 + h->access->set_intr_mask(h, CCISS_INTR_ON);
29096
29097 /* Get the firmware version */
29098 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
29099 @@ -5211,7 +5213,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
29100 kfree(flush_buf);
29101 if (return_code != IO_OK)
29102 dev_warn(&h->pdev->dev, "Error flushing cache\n");
29103 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
29104 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
29105 free_irq(h->intr[h->intr_mode], h);
29106 }
29107
29108 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
29109 index 7fda30e..eb5dfe0 100644
29110 --- a/drivers/block/cciss.h
29111 +++ b/drivers/block/cciss.h
29112 @@ -101,7 +101,7 @@ struct ctlr_info
29113 /* information about each logical volume */
29114 drive_info_struct *drv[CISS_MAX_LUN];
29115
29116 - struct access_method access;
29117 + struct access_method *access;
29118
29119 /* queue and queue Info */
29120 struct list_head reqQ;
29121 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
29122 index 9125bbe..eede5c8 100644
29123 --- a/drivers/block/cpqarray.c
29124 +++ b/drivers/block/cpqarray.c
29125 @@ -404,7 +404,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29126 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
29127 goto Enomem4;
29128 }
29129 - hba[i]->access.set_intr_mask(hba[i], 0);
29130 + hba[i]->access->set_intr_mask(hba[i], 0);
29131 if (request_irq(hba[i]->intr, do_ida_intr,
29132 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
29133 {
29134 @@ -459,7 +459,7 @@ static int __devinit cpqarray_register_ctlr( int i, struct pci_dev *pdev)
29135 add_timer(&hba[i]->timer);
29136
29137 /* Enable IRQ now that spinlock and rate limit timer are set up */
29138 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29139 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
29140
29141 for(j=0; j<NWD; j++) {
29142 struct gendisk *disk = ida_gendisk[i][j];
29143 @@ -694,7 +694,7 @@ DBGINFO(
29144 for(i=0; i<NR_PRODUCTS; i++) {
29145 if (board_id == products[i].board_id) {
29146 c->product_name = products[i].product_name;
29147 - c->access = *(products[i].access);
29148 + c->access = products[i].access;
29149 break;
29150 }
29151 }
29152 @@ -792,7 +792,7 @@ static int __devinit cpqarray_eisa_detect(void)
29153 hba[ctlr]->intr = intr;
29154 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
29155 hba[ctlr]->product_name = products[j].product_name;
29156 - hba[ctlr]->access = *(products[j].access);
29157 + hba[ctlr]->access = products[j].access;
29158 hba[ctlr]->ctlr = ctlr;
29159 hba[ctlr]->board_id = board_id;
29160 hba[ctlr]->pci_dev = NULL; /* not PCI */
29161 @@ -980,7 +980,7 @@ static void start_io(ctlr_info_t *h)
29162
29163 while((c = h->reqQ) != NULL) {
29164 /* Can't do anything if we're busy */
29165 - if (h->access.fifo_full(h) == 0)
29166 + if (h->access->fifo_full(h) == 0)
29167 return;
29168
29169 /* Get the first entry from the request Q */
29170 @@ -988,7 +988,7 @@ static void start_io(ctlr_info_t *h)
29171 h->Qdepth--;
29172
29173 /* Tell the controller to do our bidding */
29174 - h->access.submit_command(h, c);
29175 + h->access->submit_command(h, c);
29176
29177 /* Get onto the completion Q */
29178 addQ(&h->cmpQ, c);
29179 @@ -1050,7 +1050,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29180 unsigned long flags;
29181 __u32 a,a1;
29182
29183 - istat = h->access.intr_pending(h);
29184 + istat = h->access->intr_pending(h);
29185 /* Is this interrupt for us? */
29186 if (istat == 0)
29187 return IRQ_NONE;
29188 @@ -1061,7 +1061,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
29189 */
29190 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
29191 if (istat & FIFO_NOT_EMPTY) {
29192 - while((a = h->access.command_completed(h))) {
29193 + while((a = h->access->command_completed(h))) {
29194 a1 = a; a &= ~3;
29195 if ((c = h->cmpQ) == NULL)
29196 {
29197 @@ -1449,11 +1449,11 @@ static int sendcmd(
29198 /*
29199 * Disable interrupt
29200 */
29201 - info_p->access.set_intr_mask(info_p, 0);
29202 + info_p->access->set_intr_mask(info_p, 0);
29203 /* Make sure there is room in the command FIFO */
29204 /* Actually it should be completely empty at this time. */
29205 for (i = 200000; i > 0; i--) {
29206 - temp = info_p->access.fifo_full(info_p);
29207 + temp = info_p->access->fifo_full(info_p);
29208 if (temp != 0) {
29209 break;
29210 }
29211 @@ -1466,7 +1466,7 @@ DBG(
29212 /*
29213 * Send the cmd
29214 */
29215 - info_p->access.submit_command(info_p, c);
29216 + info_p->access->submit_command(info_p, c);
29217 complete = pollcomplete(ctlr);
29218
29219 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
29220 @@ -1549,9 +1549,9 @@ static int revalidate_allvol(ctlr_info_t *host)
29221 * we check the new geometry. Then turn interrupts back on when
29222 * we're done.
29223 */
29224 - host->access.set_intr_mask(host, 0);
29225 + host->access->set_intr_mask(host, 0);
29226 getgeometry(ctlr);
29227 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
29228 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
29229
29230 for(i=0; i<NWD; i++) {
29231 struct gendisk *disk = ida_gendisk[ctlr][i];
29232 @@ -1591,7 +1591,7 @@ static int pollcomplete(int ctlr)
29233 /* Wait (up to 2 seconds) for a command to complete */
29234
29235 for (i = 200000; i > 0; i--) {
29236 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
29237 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
29238 if (done == 0) {
29239 udelay(10); /* a short fixed delay */
29240 } else
29241 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
29242 index be73e9d..7fbf140 100644
29243 --- a/drivers/block/cpqarray.h
29244 +++ b/drivers/block/cpqarray.h
29245 @@ -99,7 +99,7 @@ struct ctlr_info {
29246 drv_info_t drv[NWD];
29247 struct proc_dir_entry *proc;
29248
29249 - struct access_method access;
29250 + struct access_method *access;
29251
29252 cmdlist_t *reqQ;
29253 cmdlist_t *cmpQ;
29254 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
29255 index 02f013a..afeba24 100644
29256 --- a/drivers/block/drbd/drbd_int.h
29257 +++ b/drivers/block/drbd/drbd_int.h
29258 @@ -735,7 +735,7 @@ struct drbd_request;
29259 struct drbd_epoch {
29260 struct list_head list;
29261 unsigned int barrier_nr;
29262 - atomic_t epoch_size; /* increased on every request added. */
29263 + atomic_unchecked_t epoch_size; /* increased on every request added. */
29264 atomic_t active; /* increased on every req. added, and dec on every finished. */
29265 unsigned long flags;
29266 };
29267 @@ -1110,7 +1110,7 @@ struct drbd_conf {
29268 void *int_dig_in;
29269 void *int_dig_vv;
29270 wait_queue_head_t seq_wait;
29271 - atomic_t packet_seq;
29272 + atomic_unchecked_t packet_seq;
29273 unsigned int peer_seq;
29274 spinlock_t peer_seq_lock;
29275 unsigned int minor;
29276 @@ -1651,30 +1651,30 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
29277
29278 static inline void drbd_tcp_cork(struct socket *sock)
29279 {
29280 - int __user val = 1;
29281 + int val = 1;
29282 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29283 - (char __user *)&val, sizeof(val));
29284 + (char __force_user *)&val, sizeof(val));
29285 }
29286
29287 static inline void drbd_tcp_uncork(struct socket *sock)
29288 {
29289 - int __user val = 0;
29290 + int val = 0;
29291 (void) drbd_setsockopt(sock, SOL_TCP, TCP_CORK,
29292 - (char __user *)&val, sizeof(val));
29293 + (char __force_user *)&val, sizeof(val));
29294 }
29295
29296 static inline void drbd_tcp_nodelay(struct socket *sock)
29297 {
29298 - int __user val = 1;
29299 + int val = 1;
29300 (void) drbd_setsockopt(sock, SOL_TCP, TCP_NODELAY,
29301 - (char __user *)&val, sizeof(val));
29302 + (char __force_user *)&val, sizeof(val));
29303 }
29304
29305 static inline void drbd_tcp_quickack(struct socket *sock)
29306 {
29307 - int __user val = 2;
29308 + int val = 2;
29309 (void) drbd_setsockopt(sock, SOL_TCP, TCP_QUICKACK,
29310 - (char __user *)&val, sizeof(val));
29311 + (char __force_user *)&val, sizeof(val));
29312 }
29313
29314 void drbd_bump_write_ordering(struct drbd_conf *mdev, enum write_ordering_e wo);
29315 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
29316 index 920ede2..cb827ba 100644
29317 --- a/drivers/block/drbd/drbd_main.c
29318 +++ b/drivers/block/drbd/drbd_main.c
29319 @@ -2555,7 +2555,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packets cmd,
29320 p.sector = sector;
29321 p.block_id = block_id;
29322 p.blksize = blksize;
29323 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29324 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29325
29326 if (!mdev->meta.socket || mdev->state.conn < C_CONNECTED)
29327 return false;
29328 @@ -2853,7 +2853,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
29329
29330 p.sector = cpu_to_be64(req->sector);
29331 p.block_id = (unsigned long)req;
29332 - p.seq_num = cpu_to_be32(atomic_add_return(1, &mdev->packet_seq));
29333 + p.seq_num = cpu_to_be32(atomic_add_return_unchecked(1, &mdev->packet_seq));
29334
29335 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
29336
29337 @@ -3138,7 +3138,7 @@ void drbd_init_set_defaults(struct drbd_conf *mdev)
29338 atomic_set(&mdev->unacked_cnt, 0);
29339 atomic_set(&mdev->local_cnt, 0);
29340 atomic_set(&mdev->net_cnt, 0);
29341 - atomic_set(&mdev->packet_seq, 0);
29342 + atomic_set_unchecked(&mdev->packet_seq, 0);
29343 atomic_set(&mdev->pp_in_use, 0);
29344 atomic_set(&mdev->pp_in_use_by_net, 0);
29345 atomic_set(&mdev->rs_sect_in, 0);
29346 @@ -3220,8 +3220,8 @@ void drbd_mdev_cleanup(struct drbd_conf *mdev)
29347 mdev->receiver.t_state);
29348
29349 /* no need to lock it, I'm the only thread alive */
29350 - if (atomic_read(&mdev->current_epoch->epoch_size) != 0)
29351 - dev_err(DEV, "epoch_size:%d\n", atomic_read(&mdev->current_epoch->epoch_size));
29352 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size) != 0)
29353 + dev_err(DEV, "epoch_size:%d\n", atomic_read_unchecked(&mdev->current_epoch->epoch_size));
29354 mdev->al_writ_cnt =
29355 mdev->bm_writ_cnt =
29356 mdev->read_cnt =
29357 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
29358 index 6d4de6a..7b7ad4b 100644
29359 --- a/drivers/block/drbd/drbd_nl.c
29360 +++ b/drivers/block/drbd/drbd_nl.c
29361 @@ -2387,7 +2387,7 @@ static void drbd_connector_callback(struct cn_msg *req, struct netlink_skb_parms
29362 module_put(THIS_MODULE);
29363 }
29364
29365 -static atomic_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29366 +static atomic_unchecked_t drbd_nl_seq = ATOMIC_INIT(2); /* two. */
29367
29368 static unsigned short *
29369 __tl_add_blob(unsigned short *tl, enum drbd_tags tag, const void *data,
29370 @@ -2458,7 +2458,7 @@ void drbd_bcast_state(struct drbd_conf *mdev, union drbd_state state)
29371 cn_reply->id.idx = CN_IDX_DRBD;
29372 cn_reply->id.val = CN_VAL_DRBD;
29373
29374 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29375 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29376 cn_reply->ack = 0; /* not used here. */
29377 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29378 (int)((char *)tl - (char *)reply->tag_list);
29379 @@ -2490,7 +2490,7 @@ void drbd_bcast_ev_helper(struct drbd_conf *mdev, char *helper_name)
29380 cn_reply->id.idx = CN_IDX_DRBD;
29381 cn_reply->id.val = CN_VAL_DRBD;
29382
29383 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29384 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29385 cn_reply->ack = 0; /* not used here. */
29386 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29387 (int)((char *)tl - (char *)reply->tag_list);
29388 @@ -2568,7 +2568,7 @@ void drbd_bcast_ee(struct drbd_conf *mdev,
29389 cn_reply->id.idx = CN_IDX_DRBD;
29390 cn_reply->id.val = CN_VAL_DRBD;
29391
29392 - cn_reply->seq = atomic_add_return(1,&drbd_nl_seq);
29393 + cn_reply->seq = atomic_add_return_unchecked(1,&drbd_nl_seq);
29394 cn_reply->ack = 0; // not used here.
29395 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29396 (int)((char*)tl - (char*)reply->tag_list);
29397 @@ -2607,7 +2607,7 @@ void drbd_bcast_sync_progress(struct drbd_conf *mdev)
29398 cn_reply->id.idx = CN_IDX_DRBD;
29399 cn_reply->id.val = CN_VAL_DRBD;
29400
29401 - cn_reply->seq = atomic_add_return(1, &drbd_nl_seq);
29402 + cn_reply->seq = atomic_add_return_unchecked(1, &drbd_nl_seq);
29403 cn_reply->ack = 0; /* not used here. */
29404 cn_reply->len = sizeof(struct drbd_nl_cfg_reply) +
29405 (int)((char *)tl - (char *)reply->tag_list);
29406 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
29407 index ea4836e..272d72a 100644
29408 --- a/drivers/block/drbd/drbd_receiver.c
29409 +++ b/drivers/block/drbd/drbd_receiver.c
29410 @@ -893,7 +893,7 @@ retry:
29411 sock->sk->sk_sndtimeo = mdev->net_conf->timeout*HZ/10;
29412 sock->sk->sk_rcvtimeo = MAX_SCHEDULE_TIMEOUT;
29413
29414 - atomic_set(&mdev->packet_seq, 0);
29415 + atomic_set_unchecked(&mdev->packet_seq, 0);
29416 mdev->peer_seq = 0;
29417
29418 if (drbd_send_protocol(mdev) == -1)
29419 @@ -994,7 +994,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29420 do {
29421 next_epoch = NULL;
29422
29423 - epoch_size = atomic_read(&epoch->epoch_size);
29424 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
29425
29426 switch (ev & ~EV_CLEANUP) {
29427 case EV_PUT:
29428 @@ -1030,7 +1030,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_conf *mdev,
29429 rv = FE_DESTROYED;
29430 } else {
29431 epoch->flags = 0;
29432 - atomic_set(&epoch->epoch_size, 0);
29433 + atomic_set_unchecked(&epoch->epoch_size, 0);
29434 /* atomic_set(&epoch->active, 0); is already zero */
29435 if (rv == FE_STILL_LIVE)
29436 rv = FE_RECYCLED;
29437 @@ -1205,14 +1205,14 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29438 drbd_wait_ee_list_empty(mdev, &mdev->active_ee);
29439 drbd_flush(mdev);
29440
29441 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29442 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29443 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
29444 if (epoch)
29445 break;
29446 }
29447
29448 epoch = mdev->current_epoch;
29449 - wait_event(mdev->ee_wait, atomic_read(&epoch->epoch_size) == 0);
29450 + wait_event(mdev->ee_wait, atomic_read_unchecked(&epoch->epoch_size) == 0);
29451
29452 D_ASSERT(atomic_read(&epoch->active) == 0);
29453 D_ASSERT(epoch->flags == 0);
29454 @@ -1224,11 +1224,11 @@ static int receive_Barrier(struct drbd_conf *mdev, enum drbd_packets cmd, unsign
29455 }
29456
29457 epoch->flags = 0;
29458 - atomic_set(&epoch->epoch_size, 0);
29459 + atomic_set_unchecked(&epoch->epoch_size, 0);
29460 atomic_set(&epoch->active, 0);
29461
29462 spin_lock(&mdev->epoch_lock);
29463 - if (atomic_read(&mdev->current_epoch->epoch_size)) {
29464 + if (atomic_read_unchecked(&mdev->current_epoch->epoch_size)) {
29465 list_add(&epoch->list, &mdev->current_epoch->list);
29466 mdev->current_epoch = epoch;
29467 mdev->epochs++;
29468 @@ -1695,7 +1695,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29469 spin_unlock(&mdev->peer_seq_lock);
29470
29471 drbd_send_ack_dp(mdev, P_NEG_ACK, p, data_size);
29472 - atomic_inc(&mdev->current_epoch->epoch_size);
29473 + atomic_inc_unchecked(&mdev->current_epoch->epoch_size);
29474 return drbd_drain_block(mdev, data_size);
29475 }
29476
29477 @@ -1721,7 +1721,7 @@ static int receive_Data(struct drbd_conf *mdev, enum drbd_packets cmd, unsigned
29478
29479 spin_lock(&mdev->epoch_lock);
29480 e->epoch = mdev->current_epoch;
29481 - atomic_inc(&e->epoch->epoch_size);
29482 + atomic_inc_unchecked(&e->epoch->epoch_size);
29483 atomic_inc(&e->epoch->active);
29484 spin_unlock(&mdev->epoch_lock);
29485
29486 @@ -3936,7 +3936,7 @@ static void drbd_disconnect(struct drbd_conf *mdev)
29487 D_ASSERT(list_empty(&mdev->done_ee));
29488
29489 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
29490 - atomic_set(&mdev->current_epoch->epoch_size, 0);
29491 + atomic_set_unchecked(&mdev->current_epoch->epoch_size, 0);
29492 D_ASSERT(list_empty(&mdev->current_epoch->list));
29493 }
29494
29495 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
29496 index 3bba655..6151b66 100644
29497 --- a/drivers/block/loop.c
29498 +++ b/drivers/block/loop.c
29499 @@ -226,7 +226,7 @@ static int __do_lo_send_write(struct file *file,
29500 mm_segment_t old_fs = get_fs();
29501
29502 set_fs(get_ds());
29503 - bw = file->f_op->write(file, buf, len, &pos);
29504 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
29505 set_fs(old_fs);
29506 if (likely(bw == len))
29507 return 0;
29508 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
29509 index ea6f632..eafb192 100644
29510 --- a/drivers/char/Kconfig
29511 +++ b/drivers/char/Kconfig
29512 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
29513
29514 config DEVKMEM
29515 bool "/dev/kmem virtual device support"
29516 - default y
29517 + default n
29518 + depends on !GRKERNSEC_KMEM
29519 help
29520 Say Y here if you want to support the /dev/kmem device. The
29521 /dev/kmem device is rarely used, but can be used for certain
29522 @@ -581,6 +582,7 @@ config DEVPORT
29523 bool
29524 depends on !M68K
29525 depends on ISA || PCI
29526 + depends on !GRKERNSEC_KMEM
29527 default y
29528
29529 source "drivers/s390/char/Kconfig"
29530 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
29531 index 2e04433..22afc64 100644
29532 --- a/drivers/char/agp/frontend.c
29533 +++ b/drivers/char/agp/frontend.c
29534 @@ -817,7 +817,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
29535 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
29536 return -EFAULT;
29537
29538 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
29539 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
29540 return -EFAULT;
29541
29542 client = agp_find_client_by_pid(reserve.pid);
29543 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
29544 index 21cb980..f15107c 100644
29545 --- a/drivers/char/genrtc.c
29546 +++ b/drivers/char/genrtc.c
29547 @@ -272,6 +272,7 @@ static int gen_rtc_ioctl(struct file *file,
29548 switch (cmd) {
29549
29550 case RTC_PLL_GET:
29551 + memset(&pll, 0, sizeof(pll));
29552 if (get_rtc_pll(&pll))
29553 return -EINVAL;
29554 else
29555 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
29556 index dfd7876..c0b0885 100644
29557 --- a/drivers/char/hpet.c
29558 +++ b/drivers/char/hpet.c
29559 @@ -571,7 +571,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
29560 }
29561
29562 static int
29563 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
29564 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
29565 struct hpet_info *info)
29566 {
29567 struct hpet_timer __iomem *timer;
29568 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
29569 index 2c29942..604c5ba 100644
29570 --- a/drivers/char/ipmi/ipmi_msghandler.c
29571 +++ b/drivers/char/ipmi/ipmi_msghandler.c
29572 @@ -420,7 +420,7 @@ struct ipmi_smi {
29573 struct proc_dir_entry *proc_dir;
29574 char proc_dir_name[10];
29575
29576 - atomic_t stats[IPMI_NUM_STATS];
29577 + atomic_unchecked_t stats[IPMI_NUM_STATS];
29578
29579 /*
29580 * run_to_completion duplicate of smb_info, smi_info
29581 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
29582
29583
29584 #define ipmi_inc_stat(intf, stat) \
29585 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
29586 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
29587 #define ipmi_get_stat(intf, stat) \
29588 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
29589 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
29590
29591 static int is_lan_addr(struct ipmi_addr *addr)
29592 {
29593 @@ -2884,7 +2884,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
29594 INIT_LIST_HEAD(&intf->cmd_rcvrs);
29595 init_waitqueue_head(&intf->waitq);
29596 for (i = 0; i < IPMI_NUM_STATS; i++)
29597 - atomic_set(&intf->stats[i], 0);
29598 + atomic_set_unchecked(&intf->stats[i], 0);
29599
29600 intf->proc_dir = NULL;
29601
29602 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
29603 index 1e638ff..a869ef5 100644
29604 --- a/drivers/char/ipmi/ipmi_si_intf.c
29605 +++ b/drivers/char/ipmi/ipmi_si_intf.c
29606 @@ -275,7 +275,7 @@ struct smi_info {
29607 unsigned char slave_addr;
29608
29609 /* Counters and things for the proc filesystem. */
29610 - atomic_t stats[SI_NUM_STATS];
29611 + atomic_unchecked_t stats[SI_NUM_STATS];
29612
29613 struct task_struct *thread;
29614
29615 @@ -284,9 +284,9 @@ struct smi_info {
29616 };
29617
29618 #define smi_inc_stat(smi, stat) \
29619 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
29620 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
29621 #define smi_get_stat(smi, stat) \
29622 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
29623 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
29624
29625 #define SI_MAX_PARMS 4
29626
29627 @@ -3209,7 +3209,7 @@ static int try_smi_init(struct smi_info *new_smi)
29628 atomic_set(&new_smi->req_events, 0);
29629 new_smi->run_to_completion = 0;
29630 for (i = 0; i < SI_NUM_STATS; i++)
29631 - atomic_set(&new_smi->stats[i], 0);
29632 + atomic_set_unchecked(&new_smi->stats[i], 0);
29633
29634 new_smi->interrupt_disabled = 1;
29635 atomic_set(&new_smi->stop_operation, 0);
29636 diff --git a/drivers/char/mbcs.c b/drivers/char/mbcs.c
29637 index 47ff7e4..0c7d340 100644
29638 --- a/drivers/char/mbcs.c
29639 +++ b/drivers/char/mbcs.c
29640 @@ -799,7 +799,7 @@ static int mbcs_remove(struct cx_dev *dev)
29641 return 0;
29642 }
29643
29644 -static const struct cx_device_id __devinitdata mbcs_id_table[] = {
29645 +static const struct cx_device_id __devinitconst mbcs_id_table[] = {
29646 {
29647 .part_num = MBCS_PART_NUM,
29648 .mfg_num = MBCS_MFG_NUM,
29649 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
29650 index 67c3371..ba8429d 100644
29651 --- a/drivers/char/mem.c
29652 +++ b/drivers/char/mem.c
29653 @@ -18,6 +18,7 @@
29654 #include <linux/raw.h>
29655 #include <linux/tty.h>
29656 #include <linux/capability.h>
29657 +#include <linux/security.h>
29658 #include <linux/ptrace.h>
29659 #include <linux/device.h>
29660 #include <linux/highmem.h>
29661 @@ -35,6 +36,10 @@
29662 # include <linux/efi.h>
29663 #endif
29664
29665 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29666 +extern const struct file_operations grsec_fops;
29667 +#endif
29668 +
29669 static inline unsigned long size_inside_page(unsigned long start,
29670 unsigned long size)
29671 {
29672 @@ -66,9 +71,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29673
29674 while (cursor < to) {
29675 if (!devmem_is_allowed(pfn)) {
29676 +#ifdef CONFIG_GRKERNSEC_KMEM
29677 + gr_handle_mem_readwrite(from, to);
29678 +#else
29679 printk(KERN_INFO
29680 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
29681 current->comm, from, to);
29682 +#endif
29683 return 0;
29684 }
29685 cursor += PAGE_SIZE;
29686 @@ -76,6 +85,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29687 }
29688 return 1;
29689 }
29690 +#elif defined(CONFIG_GRKERNSEC_KMEM)
29691 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29692 +{
29693 + return 0;
29694 +}
29695 #else
29696 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
29697 {
29698 @@ -118,6 +132,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29699
29700 while (count > 0) {
29701 unsigned long remaining;
29702 + char *temp;
29703
29704 sz = size_inside_page(p, count);
29705
29706 @@ -133,7 +148,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
29707 if (!ptr)
29708 return -EFAULT;
29709
29710 - remaining = copy_to_user(buf, ptr, sz);
29711 +#ifdef CONFIG_PAX_USERCOPY
29712 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29713 + if (!temp) {
29714 + unxlate_dev_mem_ptr(p, ptr);
29715 + return -ENOMEM;
29716 + }
29717 + memcpy(temp, ptr, sz);
29718 +#else
29719 + temp = ptr;
29720 +#endif
29721 +
29722 + remaining = copy_to_user(buf, temp, sz);
29723 +
29724 +#ifdef CONFIG_PAX_USERCOPY
29725 + kfree(temp);
29726 +#endif
29727 +
29728 unxlate_dev_mem_ptr(p, ptr);
29729 if (remaining)
29730 return -EFAULT;
29731 @@ -396,9 +427,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29732 size_t count, loff_t *ppos)
29733 {
29734 unsigned long p = *ppos;
29735 - ssize_t low_count, read, sz;
29736 + ssize_t low_count, read, sz, err = 0;
29737 char * kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
29738 - int err = 0;
29739
29740 read = 0;
29741 if (p < (unsigned long) high_memory) {
29742 @@ -420,6 +450,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29743 }
29744 #endif
29745 while (low_count > 0) {
29746 + char *temp;
29747 +
29748 sz = size_inside_page(p, low_count);
29749
29750 /*
29751 @@ -429,7 +461,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
29752 */
29753 kbuf = xlate_dev_kmem_ptr((char *)p);
29754
29755 - if (copy_to_user(buf, kbuf, sz))
29756 +#ifdef CONFIG_PAX_USERCOPY
29757 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
29758 + if (!temp)
29759 + return -ENOMEM;
29760 + memcpy(temp, kbuf, sz);
29761 +#else
29762 + temp = kbuf;
29763 +#endif
29764 +
29765 + err = copy_to_user(buf, temp, sz);
29766 +
29767 +#ifdef CONFIG_PAX_USERCOPY
29768 + kfree(temp);
29769 +#endif
29770 +
29771 + if (err)
29772 return -EFAULT;
29773 buf += sz;
29774 p += sz;
29775 @@ -831,6 +878,9 @@ static const struct memdev {
29776 #ifdef CONFIG_CRASH_DUMP
29777 [12] = { "oldmem", 0, &oldmem_fops, NULL },
29778 #endif
29779 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
29780 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
29781 +#endif
29782 };
29783
29784 static int memory_open(struct inode *inode, struct file *filp)
29785 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
29786 index 9df78e2..01ba9ae 100644
29787 --- a/drivers/char/nvram.c
29788 +++ b/drivers/char/nvram.c
29789 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
29790
29791 spin_unlock_irq(&rtc_lock);
29792
29793 - if (copy_to_user(buf, contents, tmp - contents))
29794 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
29795 return -EFAULT;
29796
29797 *ppos = i;
29798 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
29799 index 0a484b4..f48ccd1 100644
29800 --- a/drivers/char/pcmcia/synclink_cs.c
29801 +++ b/drivers/char/pcmcia/synclink_cs.c
29802 @@ -2340,9 +2340,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29803
29804 if (debug_level >= DEBUG_LEVEL_INFO)
29805 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
29806 - __FILE__,__LINE__, info->device_name, port->count);
29807 + __FILE__,__LINE__, info->device_name, atomic_read(&port->count));
29808
29809 - WARN_ON(!port->count);
29810 + WARN_ON(!atomic_read(&port->count));
29811
29812 if (tty_port_close_start(port, tty, filp) == 0)
29813 goto cleanup;
29814 @@ -2360,7 +2360,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
29815 cleanup:
29816 if (debug_level >= DEBUG_LEVEL_INFO)
29817 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__,__LINE__,
29818 - tty->driver->name, port->count);
29819 + tty->driver->name, atomic_read(&port->count));
29820 }
29821
29822 /* Wait until the transmitter is empty.
29823 @@ -2502,7 +2502,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29824
29825 if (debug_level >= DEBUG_LEVEL_INFO)
29826 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
29827 - __FILE__,__LINE__,tty->driver->name, port->count);
29828 + __FILE__,__LINE__,tty->driver->name, atomic_read(&port->count));
29829
29830 /* If port is closing, signal caller to try again */
29831 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
29832 @@ -2522,11 +2522,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
29833 goto cleanup;
29834 }
29835 spin_lock(&port->lock);
29836 - port->count++;
29837 + atomic_inc(&port->count);
29838 spin_unlock(&port->lock);
29839 spin_unlock_irqrestore(&info->netlock, flags);
29840
29841 - if (port->count == 1) {
29842 + if (atomic_read(&port->count) == 1) {
29843 /* 1st open on this device, init hardware */
29844 retval = startup(info, tty);
29845 if (retval < 0)
29846 @@ -3891,7 +3891,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
29847 unsigned short new_crctype;
29848
29849 /* return error if TTY interface open */
29850 - if (info->port.count)
29851 + if (atomic_read(&info->port.count))
29852 return -EBUSY;
29853
29854 switch (encoding)
29855 @@ -3994,7 +3994,7 @@ static int hdlcdev_open(struct net_device *dev)
29856
29857 /* arbitrate between network and tty opens */
29858 spin_lock_irqsave(&info->netlock, flags);
29859 - if (info->port.count != 0 || info->netcount != 0) {
29860 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
29861 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
29862 spin_unlock_irqrestore(&info->netlock, flags);
29863 return -EBUSY;
29864 @@ -4083,7 +4083,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
29865 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
29866
29867 /* return error if TTY interface open */
29868 - if (info->port.count)
29869 + if (atomic_read(&info->port.count))
29870 return -EBUSY;
29871
29872 if (cmd != SIOCWANDEV)
29873 diff --git a/drivers/char/random.c b/drivers/char/random.c
29874 index d98b2a6..f0ceb97 100644
29875 --- a/drivers/char/random.c
29876 +++ b/drivers/char/random.c
29877 @@ -272,8 +272,13 @@
29878 /*
29879 * Configuration information
29880 */
29881 +#ifdef CONFIG_GRKERNSEC_RANDNET
29882 +#define INPUT_POOL_WORDS 512
29883 +#define OUTPUT_POOL_WORDS 128
29884 +#else
29885 #define INPUT_POOL_WORDS 128
29886 #define OUTPUT_POOL_WORDS 32
29887 +#endif
29888 #define SEC_XFER_SIZE 512
29889 #define EXTRACT_SIZE 10
29890
29891 @@ -313,10 +318,17 @@ static struct poolinfo {
29892 int poolwords;
29893 int tap1, tap2, tap3, tap4, tap5;
29894 } poolinfo_table[] = {
29895 +#ifdef CONFIG_GRKERNSEC_RANDNET
29896 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
29897 + { 512, 411, 308, 208, 104, 1 },
29898 + /* x^128 + x^103 + x^76 + x^51 + x^25 + x + 1 -- 105 */
29899 + { 128, 103, 76, 51, 25, 1 },
29900 +#else
29901 /* x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 -- 105 */
29902 { 128, 103, 76, 51, 25, 1 },
29903 /* x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 -- 15 */
29904 { 32, 26, 20, 14, 7, 1 },
29905 +#endif
29906 #if 0
29907 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
29908 { 2048, 1638, 1231, 819, 411, 1 },
29909 @@ -527,8 +539,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
29910 input_rotate += i ? 7 : 14;
29911 }
29912
29913 - ACCESS_ONCE(r->input_rotate) = input_rotate;
29914 - ACCESS_ONCE(r->add_ptr) = i;
29915 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
29916 + ACCESS_ONCE_RW(r->add_ptr) = i;
29917 smp_wmb();
29918
29919 if (out)
29920 @@ -799,6 +811,17 @@ void add_disk_randomness(struct gendisk *disk)
29921 }
29922 #endif
29923
29924 +#ifdef CONFIG_PAX_LATENT_ENTROPY
29925 +u64 latent_entropy;
29926 +
29927 +__init void transfer_latent_entropy(void)
29928 +{
29929 + mix_pool_bytes(&input_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29930 + mix_pool_bytes(&nonblocking_pool, &latent_entropy, sizeof(latent_entropy), NULL);
29931 +// printk(KERN_INFO "PAX: transferring latent entropy: %16llx\n", latent_entropy);
29932 +}
29933 +#endif
29934 +
29935 /*********************************************************************
29936 *
29937 * Entropy extraction routines
29938 @@ -1008,7 +1031,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
29939
29940 extract_buf(r, tmp);
29941 i = min_t(int, nbytes, EXTRACT_SIZE);
29942 - if (copy_to_user(buf, tmp, i)) {
29943 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
29944 ret = -EFAULT;
29945 break;
29946 }
29947 @@ -1342,7 +1365,7 @@ EXPORT_SYMBOL(generate_random_uuid);
29948 #include <linux/sysctl.h>
29949
29950 static int min_read_thresh = 8, min_write_thresh;
29951 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
29952 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
29953 static int max_write_thresh = INPUT_POOL_WORDS * 32;
29954 static char sysctl_bootid[16];
29955
29956 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
29957 index 45713f0..8286d21 100644
29958 --- a/drivers/char/sonypi.c
29959 +++ b/drivers/char/sonypi.c
29960 @@ -54,6 +54,7 @@
29961
29962 #include <asm/uaccess.h>
29963 #include <asm/io.h>
29964 +#include <asm/local.h>
29965
29966 #include <linux/sonypi.h>
29967
29968 @@ -490,7 +491,7 @@ static struct sonypi_device {
29969 spinlock_t fifo_lock;
29970 wait_queue_head_t fifo_proc_list;
29971 struct fasync_struct *fifo_async;
29972 - int open_count;
29973 + local_t open_count;
29974 int model;
29975 struct input_dev *input_jog_dev;
29976 struct input_dev *input_key_dev;
29977 @@ -897,7 +898,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
29978 static int sonypi_misc_release(struct inode *inode, struct file *file)
29979 {
29980 mutex_lock(&sonypi_device.lock);
29981 - sonypi_device.open_count--;
29982 + local_dec(&sonypi_device.open_count);
29983 mutex_unlock(&sonypi_device.lock);
29984 return 0;
29985 }
29986 @@ -906,9 +907,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
29987 {
29988 mutex_lock(&sonypi_device.lock);
29989 /* Flush input queue on first open */
29990 - if (!sonypi_device.open_count)
29991 + if (!local_read(&sonypi_device.open_count))
29992 kfifo_reset(&sonypi_device.fifo);
29993 - sonypi_device.open_count++;
29994 + local_inc(&sonypi_device.open_count);
29995 mutex_unlock(&sonypi_device.lock);
29996
29997 return 0;
29998 diff --git a/drivers/char/tpm/tpm.c b/drivers/char/tpm/tpm.c
29999 index 08427ab..1ab10b7 100644
30000 --- a/drivers/char/tpm/tpm.c
30001 +++ b/drivers/char/tpm/tpm.c
30002 @@ -415,7 +415,7 @@ static ssize_t tpm_transmit(struct tpm_chip *chip, const char *buf,
30003 chip->vendor.req_complete_val)
30004 goto out_recv;
30005
30006 - if ((status == chip->vendor.req_canceled)) {
30007 + if (status == chip->vendor.req_canceled) {
30008 dev_err(chip->dev, "Operation Canceled\n");
30009 rc = -ECANCELED;
30010 goto out;
30011 diff --git a/drivers/char/tpm/tpm_bios.c b/drivers/char/tpm/tpm_bios.c
30012 index 0636520..169c1d0 100644
30013 --- a/drivers/char/tpm/tpm_bios.c
30014 +++ b/drivers/char/tpm/tpm_bios.c
30015 @@ -173,7 +173,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
30016 event = addr;
30017
30018 if ((event->event_type == 0 && event->event_size == 0) ||
30019 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
30020 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
30021 return NULL;
30022
30023 return addr;
30024 @@ -198,7 +198,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
30025 return NULL;
30026
30027 if ((event->event_type == 0 && event->event_size == 0) ||
30028 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
30029 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
30030 return NULL;
30031
30032 (*pos)++;
30033 @@ -291,7 +291,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
30034 int i;
30035
30036 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
30037 - seq_putc(m, data[i]);
30038 + if (!seq_putc(m, data[i]))
30039 + return -EFAULT;
30040
30041 return 0;
30042 }
30043 @@ -410,8 +411,13 @@ static int read_log(struct tpm_bios_log *log)
30044 log->bios_event_log_end = log->bios_event_log + len;
30045
30046 virt = acpi_os_map_memory(start, len);
30047 + if (!virt) {
30048 + kfree(log->bios_event_log);
30049 + log->bios_event_log = NULL;
30050 + return -EFAULT;
30051 + }
30052
30053 - memcpy(log->bios_event_log, virt, len);
30054 + memcpy(log->bios_event_log, (const char __force_kernel *)virt, len);
30055
30056 acpi_os_unmap_memory(virt, len);
30057 return 0;
30058 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
30059 index cdf2f54..e55c197 100644
30060 --- a/drivers/char/virtio_console.c
30061 +++ b/drivers/char/virtio_console.c
30062 @@ -563,7 +563,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
30063 if (to_user) {
30064 ssize_t ret;
30065
30066 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
30067 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
30068 if (ret)
30069 return -EFAULT;
30070 } else {
30071 @@ -662,7 +662,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
30072 if (!port_has_data(port) && !port->host_connected)
30073 return 0;
30074
30075 - return fill_readbuf(port, ubuf, count, true);
30076 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
30077 }
30078
30079 static ssize_t port_fops_write(struct file *filp, const char __user *ubuf,
30080 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
30081 index 97f5064..202b6e6 100644
30082 --- a/drivers/edac/edac_pci_sysfs.c
30083 +++ b/drivers/edac/edac_pci_sysfs.c
30084 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
30085 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
30086 static int edac_pci_poll_msec = 1000; /* one second workq period */
30087
30088 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
30089 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
30090 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
30091 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
30092
30093 static struct kobject *edac_pci_top_main_kobj;
30094 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
30095 @@ -582,7 +582,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30096 edac_printk(KERN_CRIT, EDAC_PCI,
30097 "Signaled System Error on %s\n",
30098 pci_name(dev));
30099 - atomic_inc(&pci_nonparity_count);
30100 + atomic_inc_unchecked(&pci_nonparity_count);
30101 }
30102
30103 if (status & (PCI_STATUS_PARITY)) {
30104 @@ -590,7 +590,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30105 "Master Data Parity Error on %s\n",
30106 pci_name(dev));
30107
30108 - atomic_inc(&pci_parity_count);
30109 + atomic_inc_unchecked(&pci_parity_count);
30110 }
30111
30112 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30113 @@ -598,7 +598,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30114 "Detected Parity Error on %s\n",
30115 pci_name(dev));
30116
30117 - atomic_inc(&pci_parity_count);
30118 + atomic_inc_unchecked(&pci_parity_count);
30119 }
30120 }
30121
30122 @@ -619,7 +619,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30123 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
30124 "Signaled System Error on %s\n",
30125 pci_name(dev));
30126 - atomic_inc(&pci_nonparity_count);
30127 + atomic_inc_unchecked(&pci_nonparity_count);
30128 }
30129
30130 if (status & (PCI_STATUS_PARITY)) {
30131 @@ -627,7 +627,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30132 "Master Data Parity Error on "
30133 "%s\n", pci_name(dev));
30134
30135 - atomic_inc(&pci_parity_count);
30136 + atomic_inc_unchecked(&pci_parity_count);
30137 }
30138
30139 if (status & (PCI_STATUS_DETECTED_PARITY)) {
30140 @@ -635,7 +635,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
30141 "Detected Parity Error on %s\n",
30142 pci_name(dev));
30143
30144 - atomic_inc(&pci_parity_count);
30145 + atomic_inc_unchecked(&pci_parity_count);
30146 }
30147 }
30148 }
30149 @@ -677,7 +677,7 @@ void edac_pci_do_parity_check(void)
30150 if (!check_pci_errors)
30151 return;
30152
30153 - before_count = atomic_read(&pci_parity_count);
30154 + before_count = atomic_read_unchecked(&pci_parity_count);
30155
30156 /* scan all PCI devices looking for a Parity Error on devices and
30157 * bridges.
30158 @@ -689,7 +689,7 @@ void edac_pci_do_parity_check(void)
30159 /* Only if operator has selected panic on PCI Error */
30160 if (edac_pci_get_panic_on_pe()) {
30161 /* If the count is different 'after' from 'before' */
30162 - if (before_count != atomic_read(&pci_parity_count))
30163 + if (before_count != atomic_read_unchecked(&pci_parity_count))
30164 panic("EDAC: PCI Parity Error");
30165 }
30166 }
30167 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
30168 index 8c87a5e..a19cbd7 100644
30169 --- a/drivers/edac/mce_amd.h
30170 +++ b/drivers/edac/mce_amd.h
30171 @@ -80,7 +80,7 @@ extern const char * const ii_msgs[];
30172 struct amd_decoder_ops {
30173 bool (*dc_mce)(u16, u8);
30174 bool (*ic_mce)(u16, u8);
30175 -};
30176 +} __no_const;
30177
30178 void amd_report_gart_errors(bool);
30179 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
30180 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
30181 index 57ea7f4..789e3c3 100644
30182 --- a/drivers/firewire/core-card.c
30183 +++ b/drivers/firewire/core-card.c
30184 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
30185
30186 void fw_core_remove_card(struct fw_card *card)
30187 {
30188 - struct fw_card_driver dummy_driver = dummy_driver_template;
30189 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
30190
30191 card->driver->update_phy_reg(card, 4,
30192 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
30193 diff --git a/drivers/firewire/core-cdev.c b/drivers/firewire/core-cdev.c
30194 index 2783f69..9f4b0cc 100644
30195 --- a/drivers/firewire/core-cdev.c
30196 +++ b/drivers/firewire/core-cdev.c
30197 @@ -1365,8 +1365,7 @@ static int init_iso_resource(struct client *client,
30198 int ret;
30199
30200 if ((request->channels == 0 && request->bandwidth == 0) ||
30201 - request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL ||
30202 - request->bandwidth < 0)
30203 + request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL)
30204 return -EINVAL;
30205
30206 r = kmalloc(sizeof(*r), GFP_KERNEL);
30207 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
30208 index 780708d..ad60a66 100644
30209 --- a/drivers/firewire/core-transaction.c
30210 +++ b/drivers/firewire/core-transaction.c
30211 @@ -37,6 +37,7 @@
30212 #include <linux/timer.h>
30213 #include <linux/types.h>
30214 #include <linux/workqueue.h>
30215 +#include <linux/sched.h>
30216
30217 #include <asm/byteorder.h>
30218
30219 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
30220 index 515a42c..5ecf3ba 100644
30221 --- a/drivers/firewire/core.h
30222 +++ b/drivers/firewire/core.h
30223 @@ -111,6 +111,7 @@ struct fw_card_driver {
30224
30225 int (*stop_iso)(struct fw_iso_context *ctx);
30226 };
30227 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
30228
30229 void fw_card_initialize(struct fw_card *card,
30230 const struct fw_card_driver *driver, struct device *device);
30231 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
30232 index b298158..7ed8432 100644
30233 --- a/drivers/firmware/dmi_scan.c
30234 +++ b/drivers/firmware/dmi_scan.c
30235 @@ -452,11 +452,6 @@ void __init dmi_scan_machine(void)
30236 }
30237 }
30238 else {
30239 - /*
30240 - * no iounmap() for that ioremap(); it would be a no-op, but
30241 - * it's so early in setup that sucker gets confused into doing
30242 - * what it shouldn't if we actually call it.
30243 - */
30244 p = dmi_ioremap(0xF0000, 0x10000);
30245 if (p == NULL)
30246 goto error;
30247 @@ -726,7 +721,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
30248 if (buf == NULL)
30249 return -1;
30250
30251 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
30252 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
30253
30254 iounmap(buf);
30255 return 0;
30256 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
30257 index 82d5c20..44a7177 100644
30258 --- a/drivers/gpio/gpio-vr41xx.c
30259 +++ b/drivers/gpio/gpio-vr41xx.c
30260 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
30261 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
30262 maskl, pendl, maskh, pendh);
30263
30264 - atomic_inc(&irq_err_count);
30265 + atomic_inc_unchecked(&irq_err_count);
30266
30267 return -EINVAL;
30268 }
30269 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
30270 index 3252e70..b5314ace 100644
30271 --- a/drivers/gpu/drm/drm_crtc_helper.c
30272 +++ b/drivers/gpu/drm/drm_crtc_helper.c
30273 @@ -286,7 +286,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
30274 struct drm_crtc *tmp;
30275 int crtc_mask = 1;
30276
30277 - WARN(!crtc, "checking null crtc?\n");
30278 + BUG_ON(!crtc);
30279
30280 dev = crtc->dev;
30281
30282 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
30283 index 8a9d079..606cdd5 100644
30284 --- a/drivers/gpu/drm/drm_drv.c
30285 +++ b/drivers/gpu/drm/drm_drv.c
30286 @@ -318,7 +318,7 @@ module_exit(drm_core_exit);
30287 /**
30288 * Copy and IOCTL return string to user space
30289 */
30290 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
30291 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
30292 {
30293 int len;
30294
30295 @@ -401,7 +401,7 @@ long drm_ioctl(struct file *filp,
30296 return -ENODEV;
30297
30298 atomic_inc(&dev->ioctl_count);
30299 - atomic_inc(&dev->counts[_DRM_STAT_IOCTLS]);
30300 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_IOCTLS]);
30301 ++file_priv->ioctl_count;
30302
30303 DRM_DEBUG("pid=%d, cmd=0x%02x, nr=0x%02x, dev 0x%lx, auth=%d\n",
30304 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
30305 index 123de28..43a0897 100644
30306 --- a/drivers/gpu/drm/drm_fops.c
30307 +++ b/drivers/gpu/drm/drm_fops.c
30308 @@ -71,7 +71,7 @@ static int drm_setup(struct drm_device * dev)
30309 }
30310
30311 for (i = 0; i < ARRAY_SIZE(dev->counts); i++)
30312 - atomic_set(&dev->counts[i], 0);
30313 + atomic_set_unchecked(&dev->counts[i], 0);
30314
30315 dev->sigdata.lock = NULL;
30316
30317 @@ -138,8 +138,8 @@ int drm_open(struct inode *inode, struct file *filp)
30318
30319 retcode = drm_open_helper(inode, filp, dev);
30320 if (!retcode) {
30321 - atomic_inc(&dev->counts[_DRM_STAT_OPENS]);
30322 - if (!dev->open_count++)
30323 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_OPENS]);
30324 + if (local_inc_return(&dev->open_count) == 1)
30325 retcode = drm_setup(dev);
30326 }
30327 if (!retcode) {
30328 @@ -482,7 +482,7 @@ int drm_release(struct inode *inode, struct file *filp)
30329
30330 mutex_lock(&drm_global_mutex);
30331
30332 - DRM_DEBUG("open_count = %d\n", dev->open_count);
30333 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
30334
30335 if (dev->driver->preclose)
30336 dev->driver->preclose(dev, file_priv);
30337 @@ -491,10 +491,10 @@ int drm_release(struct inode *inode, struct file *filp)
30338 * Begin inline drm_release
30339 */
30340
30341 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
30342 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
30343 task_pid_nr(current),
30344 (long)old_encode_dev(file_priv->minor->device),
30345 - dev->open_count);
30346 + local_read(&dev->open_count));
30347
30348 /* Release any auth tokens that might point to this file_priv,
30349 (do that under the drm_global_mutex) */
30350 @@ -584,8 +584,8 @@ int drm_release(struct inode *inode, struct file *filp)
30351 * End inline drm_release
30352 */
30353
30354 - atomic_inc(&dev->counts[_DRM_STAT_CLOSES]);
30355 - if (!--dev->open_count) {
30356 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_CLOSES]);
30357 + if (local_dec_and_test(&dev->open_count)) {
30358 if (atomic_read(&dev->ioctl_count)) {
30359 DRM_ERROR("Device busy: %d\n",
30360 atomic_read(&dev->ioctl_count));
30361 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
30362 index c87dc96..326055d 100644
30363 --- a/drivers/gpu/drm/drm_global.c
30364 +++ b/drivers/gpu/drm/drm_global.c
30365 @@ -36,7 +36,7 @@
30366 struct drm_global_item {
30367 struct mutex mutex;
30368 void *object;
30369 - int refcount;
30370 + atomic_t refcount;
30371 };
30372
30373 static struct drm_global_item glob[DRM_GLOBAL_NUM];
30374 @@ -49,7 +49,7 @@ void drm_global_init(void)
30375 struct drm_global_item *item = &glob[i];
30376 mutex_init(&item->mutex);
30377 item->object = NULL;
30378 - item->refcount = 0;
30379 + atomic_set(&item->refcount, 0);
30380 }
30381 }
30382
30383 @@ -59,7 +59,7 @@ void drm_global_release(void)
30384 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
30385 struct drm_global_item *item = &glob[i];
30386 BUG_ON(item->object != NULL);
30387 - BUG_ON(item->refcount != 0);
30388 + BUG_ON(atomic_read(&item->refcount) != 0);
30389 }
30390 }
30391
30392 @@ -70,7 +70,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30393 void *object;
30394
30395 mutex_lock(&item->mutex);
30396 - if (item->refcount == 0) {
30397 + if (atomic_read(&item->refcount) == 0) {
30398 item->object = kzalloc(ref->size, GFP_KERNEL);
30399 if (unlikely(item->object == NULL)) {
30400 ret = -ENOMEM;
30401 @@ -83,7 +83,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
30402 goto out_err;
30403
30404 }
30405 - ++item->refcount;
30406 + atomic_inc(&item->refcount);
30407 ref->object = item->object;
30408 object = item->object;
30409 mutex_unlock(&item->mutex);
30410 @@ -100,9 +100,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
30411 struct drm_global_item *item = &glob[ref->global_type];
30412
30413 mutex_lock(&item->mutex);
30414 - BUG_ON(item->refcount == 0);
30415 + BUG_ON(atomic_read(&item->refcount) == 0);
30416 BUG_ON(ref->object != item->object);
30417 - if (--item->refcount == 0) {
30418 + if (atomic_dec_and_test(&item->refcount)) {
30419 ref->release(ref);
30420 item->object = NULL;
30421 }
30422 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
30423 index ab1162d..42587b2 100644
30424 --- a/drivers/gpu/drm/drm_info.c
30425 +++ b/drivers/gpu/drm/drm_info.c
30426 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
30427 struct drm_local_map *map;
30428 struct drm_map_list *r_list;
30429
30430 - /* Hardcoded from _DRM_FRAME_BUFFER,
30431 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
30432 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
30433 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
30434 + static const char * const types[] = {
30435 + [_DRM_FRAME_BUFFER] = "FB",
30436 + [_DRM_REGISTERS] = "REG",
30437 + [_DRM_SHM] = "SHM",
30438 + [_DRM_AGP] = "AGP",
30439 + [_DRM_SCATTER_GATHER] = "SG",
30440 + [_DRM_CONSISTENT] = "PCI",
30441 + [_DRM_GEM] = "GEM" };
30442 const char *type;
30443 int i;
30444
30445 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
30446 map = r_list->map;
30447 if (!map)
30448 continue;
30449 - if (map->type < 0 || map->type > 5)
30450 + if (map->type >= ARRAY_SIZE(types))
30451 type = "??";
30452 else
30453 type = types[map->type];
30454 @@ -290,7 +294,11 @@ int drm_vma_info(struct seq_file *m, void *data)
30455 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
30456 vma->vm_flags & VM_LOCKED ? 'l' : '-',
30457 vma->vm_flags & VM_IO ? 'i' : '-',
30458 +#ifdef CONFIG_GRKERNSEC_HIDESYM
30459 + 0);
30460 +#else
30461 vma->vm_pgoff);
30462 +#endif
30463
30464 #if defined(__i386__)
30465 pgprot = pgprot_val(vma->vm_page_prot);
30466 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
30467 index 637fcc3..e890b33 100644
30468 --- a/drivers/gpu/drm/drm_ioc32.c
30469 +++ b/drivers/gpu/drm/drm_ioc32.c
30470 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
30471 request = compat_alloc_user_space(nbytes);
30472 if (!access_ok(VERIFY_WRITE, request, nbytes))
30473 return -EFAULT;
30474 - list = (struct drm_buf_desc *) (request + 1);
30475 + list = (struct drm_buf_desc __user *) (request + 1);
30476
30477 if (__put_user(count, &request->count)
30478 || __put_user(list, &request->list))
30479 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
30480 request = compat_alloc_user_space(nbytes);
30481 if (!access_ok(VERIFY_WRITE, request, nbytes))
30482 return -EFAULT;
30483 - list = (struct drm_buf_pub *) (request + 1);
30484 + list = (struct drm_buf_pub __user *) (request + 1);
30485
30486 if (__put_user(count, &request->count)
30487 || __put_user(list, &request->list))
30488 diff --git a/drivers/gpu/drm/drm_ioctl.c b/drivers/gpu/drm/drm_ioctl.c
30489 index 64a62c6..ceab35e 100644
30490 --- a/drivers/gpu/drm/drm_ioctl.c
30491 +++ b/drivers/gpu/drm/drm_ioctl.c
30492 @@ -252,7 +252,7 @@ int drm_getstats(struct drm_device *dev, void *data,
30493 stats->data[i].value =
30494 (file_priv->master->lock.hw_lock ? file_priv->master->lock.hw_lock->lock : 0);
30495 else
30496 - stats->data[i].value = atomic_read(&dev->counts[i]);
30497 + stats->data[i].value = atomic_read_unchecked(&dev->counts[i]);
30498 stats->data[i].type = dev->types[i];
30499 }
30500
30501 diff --git a/drivers/gpu/drm/drm_lock.c b/drivers/gpu/drm/drm_lock.c
30502 index 5211520..c744d85 100644
30503 --- a/drivers/gpu/drm/drm_lock.c
30504 +++ b/drivers/gpu/drm/drm_lock.c
30505 @@ -90,7 +90,7 @@ int drm_lock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30506 if (drm_lock_take(&master->lock, lock->context)) {
30507 master->lock.file_priv = file_priv;
30508 master->lock.lock_time = jiffies;
30509 - atomic_inc(&dev->counts[_DRM_STAT_LOCKS]);
30510 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_LOCKS]);
30511 break; /* Got lock */
30512 }
30513
30514 @@ -161,7 +161,7 @@ int drm_unlock(struct drm_device *dev, void *data, struct drm_file *file_priv)
30515 return -EINVAL;
30516 }
30517
30518 - atomic_inc(&dev->counts[_DRM_STAT_UNLOCKS]);
30519 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_UNLOCKS]);
30520
30521 if (drm_lock_free(&master->lock, lock->context)) {
30522 /* FIXME: Should really bail out here. */
30523 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
30524 index 21bcd4a..8e074e0 100644
30525 --- a/drivers/gpu/drm/drm_stub.c
30526 +++ b/drivers/gpu/drm/drm_stub.c
30527 @@ -511,7 +511,7 @@ void drm_unplug_dev(struct drm_device *dev)
30528
30529 drm_device_set_unplugged(dev);
30530
30531 - if (dev->open_count == 0) {
30532 + if (local_read(&dev->open_count) == 0) {
30533 drm_put_dev(dev);
30534 }
30535 mutex_unlock(&drm_global_mutex);
30536 diff --git a/drivers/gpu/drm/i810/i810_dma.c b/drivers/gpu/drm/i810/i810_dma.c
30537 index fa94391..ed26ec8 100644
30538 --- a/drivers/gpu/drm/i810/i810_dma.c
30539 +++ b/drivers/gpu/drm/i810/i810_dma.c
30540 @@ -943,8 +943,8 @@ static int i810_dma_vertex(struct drm_device *dev, void *data,
30541 dma->buflist[vertex->idx],
30542 vertex->discard, vertex->used);
30543
30544 - atomic_add(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30545 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30546 + atomic_add_unchecked(vertex->used, &dev->counts[_DRM_STAT_SECONDARY]);
30547 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30548 sarea_priv->last_enqueue = dev_priv->counter - 1;
30549 sarea_priv->last_dispatch = (int)hw_status[5];
30550
30551 @@ -1104,8 +1104,8 @@ static int i810_dma_mc(struct drm_device *dev, void *data,
30552 i810_dma_dispatch_mc(dev, dma->buflist[mc->idx], mc->used,
30553 mc->last_render);
30554
30555 - atomic_add(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30556 - atomic_inc(&dev->counts[_DRM_STAT_DMA]);
30557 + atomic_add_unchecked(mc->used, &dev->counts[_DRM_STAT_SECONDARY]);
30558 + atomic_inc_unchecked(&dev->counts[_DRM_STAT_DMA]);
30559 sarea_priv->last_enqueue = dev_priv->counter - 1;
30560 sarea_priv->last_dispatch = (int)hw_status[5];
30561
30562 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
30563 index c9339f4..f5e1b9d 100644
30564 --- a/drivers/gpu/drm/i810/i810_drv.h
30565 +++ b/drivers/gpu/drm/i810/i810_drv.h
30566 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
30567 int page_flipping;
30568
30569 wait_queue_head_t irq_queue;
30570 - atomic_t irq_received;
30571 - atomic_t irq_emitted;
30572 + atomic_unchecked_t irq_received;
30573 + atomic_unchecked_t irq_emitted;
30574
30575 int front_offset;
30576 } drm_i810_private_t;
30577 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
30578 index 5363e9c..59360d1 100644
30579 --- a/drivers/gpu/drm/i915/i915_debugfs.c
30580 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
30581 @@ -518,7 +518,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
30582 I915_READ(GTIMR));
30583 }
30584 seq_printf(m, "Interrupts received: %d\n",
30585 - atomic_read(&dev_priv->irq_received));
30586 + atomic_read_unchecked(&dev_priv->irq_received));
30587 for (i = 0; i < I915_NUM_RINGS; i++) {
30588 if (IS_GEN6(dev) || IS_GEN7(dev)) {
30589 seq_printf(m, "Graphics Interrupt mask (%s): %08x\n",
30590 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
30591 index 36822b9..b725e1b 100644
30592 --- a/drivers/gpu/drm/i915/i915_dma.c
30593 +++ b/drivers/gpu/drm/i915/i915_dma.c
30594 @@ -1266,7 +1266,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
30595 bool can_switch;
30596
30597 spin_lock(&dev->count_lock);
30598 - can_switch = (dev->open_count == 0);
30599 + can_switch = (local_read(&dev->open_count) == 0);
30600 spin_unlock(&dev->count_lock);
30601 return can_switch;
30602 }
30603 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
30604 index b0b676a..d107105 100644
30605 --- a/drivers/gpu/drm/i915/i915_drv.h
30606 +++ b/drivers/gpu/drm/i915/i915_drv.h
30607 @@ -268,7 +268,7 @@ struct drm_i915_display_funcs {
30608 /* render clock increase/decrease */
30609 /* display clock increase/decrease */
30610 /* pll clock increase/decrease */
30611 -};
30612 +} __no_const;
30613
30614 struct intel_device_info {
30615 u8 gen;
30616 @@ -386,7 +386,7 @@ typedef struct drm_i915_private {
30617 int current_page;
30618 int page_flipping;
30619
30620 - atomic_t irq_received;
30621 + atomic_unchecked_t irq_received;
30622
30623 /* protects the irq masks */
30624 spinlock_t irq_lock;
30625 @@ -985,7 +985,7 @@ struct drm_i915_gem_object {
30626 * will be page flipped away on the next vblank. When it
30627 * reaches 0, dev_priv->pending_flip_queue will be woken up.
30628 */
30629 - atomic_t pending_flip;
30630 + atomic_unchecked_t pending_flip;
30631 };
30632
30633 #define to_intel_bo(x) container_of(x, struct drm_i915_gem_object, base)
30634 @@ -1434,7 +1434,7 @@ extern struct i2c_adapter *intel_gmbus_get_adapter(
30635 struct drm_i915_private *dev_priv, unsigned port);
30636 extern void intel_gmbus_set_speed(struct i2c_adapter *adapter, int speed);
30637 extern void intel_gmbus_force_bit(struct i2c_adapter *adapter, bool force_bit);
30638 -extern inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30639 +static inline bool intel_gmbus_is_forced_bit(struct i2c_adapter *adapter)
30640 {
30641 return container_of(adapter, struct intel_gmbus, adapter)->force_bit;
30642 }
30643 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30644 index 974a9f1..b3ebd45 100644
30645 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30646 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
30647 @@ -189,7 +189,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_i915_gem_object *obj,
30648 i915_gem_clflush_object(obj);
30649
30650 if (obj->base.pending_write_domain)
30651 - cd->flips |= atomic_read(&obj->pending_flip);
30652 + cd->flips |= atomic_read_unchecked(&obj->pending_flip);
30653
30654 /* The actual obj->write_domain will be updated with
30655 * pending_write_domain after we emit the accumulated flush for all
30656 @@ -916,9 +916,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
30657
30658 static int
30659 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
30660 - int count)
30661 + unsigned int count)
30662 {
30663 - int i;
30664 + unsigned int i;
30665
30666 for (i = 0; i < count; i++) {
30667 char __user *ptr = (char __user *)(uintptr_t)exec[i].relocs_ptr;
30668 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
30669 index acc91b1..f383084 100644
30670 --- a/drivers/gpu/drm/i915/i915_irq.c
30671 +++ b/drivers/gpu/drm/i915/i915_irq.c
30672 @@ -433,7 +433,7 @@ static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS)
30673 int vblank = 0;
30674 bool blc_event;
30675
30676 - atomic_inc(&dev_priv->irq_received);
30677 + atomic_inc_unchecked(&dev_priv->irq_received);
30678
30679 vblank_status = PIPE_START_VBLANK_INTERRUPT_STATUS |
30680 PIPE_VBLANK_INTERRUPT_STATUS;
30681 @@ -586,7 +586,7 @@ static irqreturn_t ivybridge_irq_handler(DRM_IRQ_ARGS)
30682 irqreturn_t ret = IRQ_NONE;
30683 int i;
30684
30685 - atomic_inc(&dev_priv->irq_received);
30686 + atomic_inc_unchecked(&dev_priv->irq_received);
30687
30688 /* disable master interrupt before clearing iir */
30689 de_ier = I915_READ(DEIER);
30690 @@ -661,7 +661,7 @@ static irqreturn_t ironlake_irq_handler(DRM_IRQ_ARGS)
30691 u32 de_iir, gt_iir, de_ier, pch_iir, pm_iir;
30692 u32 hotplug_mask;
30693
30694 - atomic_inc(&dev_priv->irq_received);
30695 + atomic_inc_unchecked(&dev_priv->irq_received);
30696
30697 /* disable master interrupt before clearing iir */
30698 de_ier = I915_READ(DEIER);
30699 @@ -1646,7 +1646,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
30700 {
30701 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30702
30703 - atomic_set(&dev_priv->irq_received, 0);
30704 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30705
30706
30707 I915_WRITE(HWSTAM, 0xeffe);
30708 @@ -1673,7 +1673,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
30709 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30710 int pipe;
30711
30712 - atomic_set(&dev_priv->irq_received, 0);
30713 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30714
30715 /* VLV magic */
30716 I915_WRITE(VLV_IMR, 0);
30717 @@ -1969,7 +1969,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
30718 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30719 int pipe;
30720
30721 - atomic_set(&dev_priv->irq_received, 0);
30722 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30723
30724 for_each_pipe(pipe)
30725 I915_WRITE(PIPESTAT(pipe), 0);
30726 @@ -2020,7 +2020,7 @@ static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS)
30727 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
30728 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
30729
30730 - atomic_inc(&dev_priv->irq_received);
30731 + atomic_inc_unchecked(&dev_priv->irq_received);
30732
30733 iir = I915_READ16(IIR);
30734 if (iir == 0)
30735 @@ -2105,7 +2105,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
30736 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30737 int pipe;
30738
30739 - atomic_set(&dev_priv->irq_received, 0);
30740 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30741
30742 if (I915_HAS_HOTPLUG(dev)) {
30743 I915_WRITE(PORT_HOTPLUG_EN, 0);
30744 @@ -2200,7 +2200,7 @@ static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS)
30745 };
30746 int pipe, ret = IRQ_NONE;
30747
30748 - atomic_inc(&dev_priv->irq_received);
30749 + atomic_inc_unchecked(&dev_priv->irq_received);
30750
30751 iir = I915_READ(IIR);
30752 do {
30753 @@ -2326,7 +2326,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
30754 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
30755 int pipe;
30756
30757 - atomic_set(&dev_priv->irq_received, 0);
30758 + atomic_set_unchecked(&dev_priv->irq_received, 0);
30759
30760 if (I915_HAS_HOTPLUG(dev)) {
30761 I915_WRITE(PORT_HOTPLUG_EN, 0);
30762 @@ -2436,7 +2436,7 @@ static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS)
30763 int irq_received;
30764 int ret = IRQ_NONE, pipe;
30765
30766 - atomic_inc(&dev_priv->irq_received);
30767 + atomic_inc_unchecked(&dev_priv->irq_received);
30768
30769 iir = I915_READ(IIR);
30770
30771 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
30772 index 2f22bea..bc9e330 100644
30773 --- a/drivers/gpu/drm/i915/intel_display.c
30774 +++ b/drivers/gpu/drm/i915/intel_display.c
30775 @@ -2000,7 +2000,7 @@ intel_finish_fb(struct drm_framebuffer *old_fb)
30776
30777 wait_event(dev_priv->pending_flip_queue,
30778 atomic_read(&dev_priv->mm.wedged) ||
30779 - atomic_read(&obj->pending_flip) == 0);
30780 + atomic_read_unchecked(&obj->pending_flip) == 0);
30781
30782 /* Big Hammer, we also need to ensure that any pending
30783 * MI_WAIT_FOR_EVENT inside a user batch buffer on the
30784 @@ -5914,9 +5914,8 @@ static void do_intel_finish_page_flip(struct drm_device *dev,
30785
30786 obj = work->old_fb_obj;
30787
30788 - atomic_clear_mask(1 << intel_crtc->plane,
30789 - &obj->pending_flip.counter);
30790 - if (atomic_read(&obj->pending_flip) == 0)
30791 + atomic_clear_mask_unchecked(1 << intel_crtc->plane, &obj->pending_flip);
30792 + if (atomic_read_unchecked(&obj->pending_flip) == 0)
30793 wake_up(&dev_priv->pending_flip_queue);
30794
30795 schedule_work(&work->work);
30796 @@ -6253,7 +6252,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30797 /* Block clients from rendering to the new back buffer until
30798 * the flip occurs and the object is no longer visible.
30799 */
30800 - atomic_add(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30801 + atomic_add_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30802
30803 ret = dev_priv->display.queue_flip(dev, crtc, fb, obj);
30804 if (ret)
30805 @@ -6268,7 +6267,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc,
30806 return 0;
30807
30808 cleanup_pending:
30809 - atomic_sub(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30810 + atomic_sub_unchecked(1 << intel_crtc->plane, &work->old_fb_obj->pending_flip);
30811 drm_gem_object_unreference(&work->old_fb_obj->base);
30812 drm_gem_object_unreference(&obj->base);
30813 mutex_unlock(&dev->struct_mutex);
30814 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
30815 index 54558a0..2d97005 100644
30816 --- a/drivers/gpu/drm/mga/mga_drv.h
30817 +++ b/drivers/gpu/drm/mga/mga_drv.h
30818 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
30819 u32 clear_cmd;
30820 u32 maccess;
30821
30822 - atomic_t vbl_received; /**< Number of vblanks received. */
30823 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
30824 wait_queue_head_t fence_queue;
30825 - atomic_t last_fence_retired;
30826 + atomic_unchecked_t last_fence_retired;
30827 u32 next_fence_to_post;
30828
30829 unsigned int fb_cpp;
30830 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
30831 index 2581202..f230a8d9 100644
30832 --- a/drivers/gpu/drm/mga/mga_irq.c
30833 +++ b/drivers/gpu/drm/mga/mga_irq.c
30834 @@ -44,7 +44,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
30835 if (crtc != 0)
30836 return 0;
30837
30838 - return atomic_read(&dev_priv->vbl_received);
30839 + return atomic_read_unchecked(&dev_priv->vbl_received);
30840 }
30841
30842
30843 @@ -60,7 +60,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30844 /* VBLANK interrupt */
30845 if (status & MGA_VLINEPEN) {
30846 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
30847 - atomic_inc(&dev_priv->vbl_received);
30848 + atomic_inc_unchecked(&dev_priv->vbl_received);
30849 drm_handle_vblank(dev, 0);
30850 handled = 1;
30851 }
30852 @@ -79,7 +79,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
30853 if ((prim_start & ~0x03) != (prim_end & ~0x03))
30854 MGA_WRITE(MGA_PRIMEND, prim_end);
30855
30856 - atomic_inc(&dev_priv->last_fence_retired);
30857 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
30858 DRM_WAKEUP(&dev_priv->fence_queue);
30859 handled = 1;
30860 }
30861 @@ -130,7 +130,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
30862 * using fences.
30863 */
30864 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
30865 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
30866 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
30867 - *sequence) <= (1 << 23)));
30868
30869 *sequence = cur_fence;
30870 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
30871 index 2f11e16..191267e 100644
30872 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
30873 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
30874 @@ -5340,7 +5340,7 @@ parse_bit_U_tbl_entry(struct drm_device *dev, struct nvbios *bios,
30875 struct bit_table {
30876 const char id;
30877 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
30878 -};
30879 +} __no_const;
30880
30881 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
30882
30883 diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h
30884 index b863a3a..c55e0dc 100644
30885 --- a/drivers/gpu/drm/nouveau/nouveau_drv.h
30886 +++ b/drivers/gpu/drm/nouveau/nouveau_drv.h
30887 @@ -302,7 +302,7 @@ struct nouveau_exec_engine {
30888 u32 handle, u16 class);
30889 void (*set_tile_region)(struct drm_device *dev, int i);
30890 void (*tlb_flush)(struct drm_device *, int engine);
30891 -};
30892 +} __no_const;
30893
30894 struct nouveau_instmem_engine {
30895 void *priv;
30896 @@ -324,13 +324,13 @@ struct nouveau_instmem_engine {
30897 struct nouveau_mc_engine {
30898 int (*init)(struct drm_device *dev);
30899 void (*takedown)(struct drm_device *dev);
30900 -};
30901 +} __no_const;
30902
30903 struct nouveau_timer_engine {
30904 int (*init)(struct drm_device *dev);
30905 void (*takedown)(struct drm_device *dev);
30906 uint64_t (*read)(struct drm_device *dev);
30907 -};
30908 +} __no_const;
30909
30910 struct nouveau_fb_engine {
30911 int num_tiles;
30912 @@ -547,7 +547,7 @@ struct nouveau_vram_engine {
30913 void (*put)(struct drm_device *, struct nouveau_mem **);
30914
30915 bool (*flags_valid)(struct drm_device *, u32 tile_flags);
30916 -};
30917 +} __no_const;
30918
30919 struct nouveau_engine {
30920 struct nouveau_instmem_engine instmem;
30921 @@ -693,7 +693,7 @@ struct drm_nouveau_private {
30922 struct drm_global_reference mem_global_ref;
30923 struct ttm_bo_global_ref bo_global_ref;
30924 struct ttm_bo_device bdev;
30925 - atomic_t validate_sequence;
30926 + atomic_unchecked_t validate_sequence;
30927 int (*move)(struct nouveau_channel *,
30928 struct ttm_buffer_object *,
30929 struct ttm_mem_reg *, struct ttm_mem_reg *);
30930 diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c
30931 index 30f5423..abca136 100644
30932 --- a/drivers/gpu/drm/nouveau/nouveau_gem.c
30933 +++ b/drivers/gpu/drm/nouveau/nouveau_gem.c
30934 @@ -319,7 +319,7 @@ validate_init(struct nouveau_channel *chan, struct drm_file *file_priv,
30935 int trycnt = 0;
30936 int ret, i;
30937
30938 - sequence = atomic_add_return(1, &dev_priv->ttm.validate_sequence);
30939 + sequence = atomic_add_return_unchecked(1, &dev_priv->ttm.validate_sequence);
30940 retry:
30941 if (++trycnt > 100000) {
30942 NV_ERROR(dev, "%s failed and gave up.\n", __func__);
30943 diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c
30944 index 22a90a0..8ccea014 100644
30945 --- a/drivers/gpu/drm/nouveau/nouveau_state.c
30946 +++ b/drivers/gpu/drm/nouveau/nouveau_state.c
30947 @@ -490,7 +490,7 @@ static bool nouveau_switcheroo_can_switch(struct pci_dev *pdev)
30948 bool can_switch;
30949
30950 spin_lock(&dev->count_lock);
30951 - can_switch = (dev->open_count == 0);
30952 + can_switch = (local_read(&dev->open_count) == 0);
30953 spin_unlock(&dev->count_lock);
30954 return can_switch;
30955 }
30956 diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c
30957 index a9514ea..369d511 100644
30958 --- a/drivers/gpu/drm/nouveau/nv50_sor.c
30959 +++ b/drivers/gpu/drm/nouveau/nv50_sor.c
30960 @@ -304,7 +304,7 @@ nv50_sor_dpms(struct drm_encoder *encoder, int mode)
30961 }
30962
30963 if (nv_encoder->dcb->type == OUTPUT_DP) {
30964 - struct dp_train_func func = {
30965 + static struct dp_train_func func = {
30966 .link_set = nv50_sor_dp_link_set,
30967 .train_set = nv50_sor_dp_train_set,
30968 .train_adj = nv50_sor_dp_train_adj
30969 diff --git a/drivers/gpu/drm/nouveau/nvd0_display.c b/drivers/gpu/drm/nouveau/nvd0_display.c
30970 index c50b075..6b07dfc 100644
30971 --- a/drivers/gpu/drm/nouveau/nvd0_display.c
30972 +++ b/drivers/gpu/drm/nouveau/nvd0_display.c
30973 @@ -1366,7 +1366,7 @@ nvd0_sor_dpms(struct drm_encoder *encoder, int mode)
30974 nv_wait(dev, 0x61c030 + (or * 0x0800), 0x10000000, 0x00000000);
30975
30976 if (nv_encoder->dcb->type == OUTPUT_DP) {
30977 - struct dp_train_func func = {
30978 + static struct dp_train_func func = {
30979 .link_set = nvd0_sor_dp_link_set,
30980 .train_set = nvd0_sor_dp_train_set,
30981 .train_adj = nvd0_sor_dp_train_adj
30982 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
30983 index bcac90b..53bfc76 100644
30984 --- a/drivers/gpu/drm/r128/r128_cce.c
30985 +++ b/drivers/gpu/drm/r128/r128_cce.c
30986 @@ -378,7 +378,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
30987
30988 /* GH: Simple idle check.
30989 */
30990 - atomic_set(&dev_priv->idle_count, 0);
30991 + atomic_set_unchecked(&dev_priv->idle_count, 0);
30992
30993 /* We don't support anything other than bus-mastering ring mode,
30994 * but the ring can be in either AGP or PCI space for the ring
30995 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
30996 index 930c71b..499aded 100644
30997 --- a/drivers/gpu/drm/r128/r128_drv.h
30998 +++ b/drivers/gpu/drm/r128/r128_drv.h
30999 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
31000 int is_pci;
31001 unsigned long cce_buffers_offset;
31002
31003 - atomic_t idle_count;
31004 + atomic_unchecked_t idle_count;
31005
31006 int page_flipping;
31007 int current_page;
31008 u32 crtc_offset;
31009 u32 crtc_offset_cntl;
31010
31011 - atomic_t vbl_received;
31012 + atomic_unchecked_t vbl_received;
31013
31014 u32 color_fmt;
31015 unsigned int front_offset;
31016 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
31017 index 429d5a0..7e899ed 100644
31018 --- a/drivers/gpu/drm/r128/r128_irq.c
31019 +++ b/drivers/gpu/drm/r128/r128_irq.c
31020 @@ -42,7 +42,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
31021 if (crtc != 0)
31022 return 0;
31023
31024 - return atomic_read(&dev_priv->vbl_received);
31025 + return atomic_read_unchecked(&dev_priv->vbl_received);
31026 }
31027
31028 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31029 @@ -56,7 +56,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
31030 /* VBLANK interrupt */
31031 if (status & R128_CRTC_VBLANK_INT) {
31032 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
31033 - atomic_inc(&dev_priv->vbl_received);
31034 + atomic_inc_unchecked(&dev_priv->vbl_received);
31035 drm_handle_vblank(dev, 0);
31036 return IRQ_HANDLED;
31037 }
31038 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
31039 index a9e33ce..09edd4b 100644
31040 --- a/drivers/gpu/drm/r128/r128_state.c
31041 +++ b/drivers/gpu/drm/r128/r128_state.c
31042 @@ -321,10 +321,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
31043
31044 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
31045 {
31046 - if (atomic_read(&dev_priv->idle_count) == 0)
31047 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
31048 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
31049 else
31050 - atomic_set(&dev_priv->idle_count, 0);
31051 + atomic_set_unchecked(&dev_priv->idle_count, 0);
31052 }
31053
31054 #endif
31055 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
31056 index 5a82b6b..9e69c73 100644
31057 --- a/drivers/gpu/drm/radeon/mkregtable.c
31058 +++ b/drivers/gpu/drm/radeon/mkregtable.c
31059 @@ -637,14 +637,14 @@ static int parser_auth(struct table *t, const char *filename)
31060 regex_t mask_rex;
31061 regmatch_t match[4];
31062 char buf[1024];
31063 - size_t end;
31064 + long end;
31065 int len;
31066 int done = 0;
31067 int r;
31068 unsigned o;
31069 struct offset *offset;
31070 char last_reg_s[10];
31071 - int last_reg;
31072 + unsigned long last_reg;
31073
31074 if (regcomp
31075 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
31076 diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
31077 index 5c8a0bf..b7a311c 100644
31078 --- a/drivers/gpu/drm/radeon/radeon.h
31079 +++ b/drivers/gpu/drm/radeon/radeon.h
31080 @@ -729,7 +729,7 @@ struct r600_blit_cp_primitives {
31081 int x2, int y2);
31082 void (*draw_auto)(struct radeon_device *rdev);
31083 void (*set_default_state)(struct radeon_device *rdev);
31084 -};
31085 +} __no_const;
31086
31087 struct r600_blit {
31088 struct radeon_bo *shader_obj;
31089 @@ -1230,7 +1230,7 @@ struct radeon_asic {
31090 u32 (*page_flip)(struct radeon_device *rdev, int crtc, u64 crtc_base);
31091 void (*post_page_flip)(struct radeon_device *rdev, int crtc);
31092 } pflip;
31093 -};
31094 +} __no_const;
31095
31096 /*
31097 * Asic structures
31098 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
31099 index 8867400..72761bc 100644
31100 --- a/drivers/gpu/drm/radeon/radeon_device.c
31101 +++ b/drivers/gpu/drm/radeon/radeon_device.c
31102 @@ -692,7 +692,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
31103 bool can_switch;
31104
31105 spin_lock(&dev->count_lock);
31106 - can_switch = (dev->open_count == 0);
31107 + can_switch = (local_read(&dev->open_count) == 0);
31108 spin_unlock(&dev->count_lock);
31109 return can_switch;
31110 }
31111 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
31112 index a1b59ca..86f2d44 100644
31113 --- a/drivers/gpu/drm/radeon/radeon_drv.h
31114 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
31115 @@ -255,7 +255,7 @@ typedef struct drm_radeon_private {
31116
31117 /* SW interrupt */
31118 wait_queue_head_t swi_queue;
31119 - atomic_t swi_emitted;
31120 + atomic_unchecked_t swi_emitted;
31121 int vblank_crtc;
31122 uint32_t irq_enable_reg;
31123 uint32_t r500_disp_irq_reg;
31124 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
31125 index 48b7cea..342236f 100644
31126 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
31127 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
31128 @@ -359,7 +359,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
31129 request = compat_alloc_user_space(sizeof(*request));
31130 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
31131 || __put_user(req32.param, &request->param)
31132 - || __put_user((void __user *)(unsigned long)req32.value,
31133 + || __put_user((unsigned long)req32.value,
31134 &request->value))
31135 return -EFAULT;
31136
31137 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
31138 index 00da384..32f972d 100644
31139 --- a/drivers/gpu/drm/radeon/radeon_irq.c
31140 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
31141 @@ -225,8 +225,8 @@ static int radeon_emit_irq(struct drm_device * dev)
31142 unsigned int ret;
31143 RING_LOCALS;
31144
31145 - atomic_inc(&dev_priv->swi_emitted);
31146 - ret = atomic_read(&dev_priv->swi_emitted);
31147 + atomic_inc_unchecked(&dev_priv->swi_emitted);
31148 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
31149
31150 BEGIN_RING(4);
31151 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
31152 @@ -352,7 +352,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
31153 drm_radeon_private_t *dev_priv =
31154 (drm_radeon_private_t *) dev->dev_private;
31155
31156 - atomic_set(&dev_priv->swi_emitted, 0);
31157 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
31158 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
31159
31160 dev->max_vblank_count = 0x001fffff;
31161 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
31162 index e8422ae..d22d4a8 100644
31163 --- a/drivers/gpu/drm/radeon/radeon_state.c
31164 +++ b/drivers/gpu/drm/radeon/radeon_state.c
31165 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
31166 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
31167 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
31168
31169 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31170 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
31171 sarea_priv->nbox * sizeof(depth_boxes[0])))
31172 return -EFAULT;
31173
31174 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
31175 {
31176 drm_radeon_private_t *dev_priv = dev->dev_private;
31177 drm_radeon_getparam_t *param = data;
31178 - int value;
31179 + int value = 0;
31180
31181 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
31182
31183 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
31184 index c94a225..5795d34 100644
31185 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
31186 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
31187 @@ -852,8 +852,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
31188 }
31189 if (unlikely(ttm_vm_ops == NULL)) {
31190 ttm_vm_ops = vma->vm_ops;
31191 - radeon_ttm_vm_ops = *ttm_vm_ops;
31192 - radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31193 + pax_open_kernel();
31194 + memcpy((void *)&radeon_ttm_vm_ops, ttm_vm_ops, sizeof(radeon_ttm_vm_ops));
31195 + *(void **)&radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
31196 + pax_close_kernel();
31197 }
31198 vma->vm_ops = &radeon_ttm_vm_ops;
31199 return 0;
31200 diff --git a/drivers/gpu/drm/radeon/rs690.c b/drivers/gpu/drm/radeon/rs690.c
31201 index 159b6a4..fa82487 100644
31202 --- a/drivers/gpu/drm/radeon/rs690.c
31203 +++ b/drivers/gpu/drm/radeon/rs690.c
31204 @@ -304,9 +304,11 @@ void rs690_crtc_bandwidth_compute(struct radeon_device *rdev,
31205 if (rdev->pm.max_bandwidth.full > rdev->pm.sideport_bandwidth.full &&
31206 rdev->pm.sideport_bandwidth.full)
31207 rdev->pm.max_bandwidth = rdev->pm.sideport_bandwidth;
31208 - read_delay_latency.full = dfixed_const(370 * 800 * 1000);
31209 + read_delay_latency.full = dfixed_const(800 * 1000);
31210 read_delay_latency.full = dfixed_div(read_delay_latency,
31211 rdev->pm.igp_sideport_mclk);
31212 + a.full = dfixed_const(370);
31213 + read_delay_latency.full = dfixed_mul(read_delay_latency, a);
31214 } else {
31215 if (rdev->pm.max_bandwidth.full > rdev->pm.k8_bandwidth.full &&
31216 rdev->pm.k8_bandwidth.full)
31217 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31218 index ebc6fac..a8313ed 100644
31219 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
31220 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
31221 @@ -394,9 +394,9 @@ static int ttm_pool_get_num_unused_pages(void)
31222 static int ttm_pool_mm_shrink(struct shrinker *shrink,
31223 struct shrink_control *sc)
31224 {
31225 - static atomic_t start_pool = ATOMIC_INIT(0);
31226 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
31227 unsigned i;
31228 - unsigned pool_offset = atomic_add_return(1, &start_pool);
31229 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
31230 struct ttm_page_pool *pool;
31231 int shrink_pages = sc->nr_to_scan;
31232
31233 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
31234 index 88edacc..1e5412b 100644
31235 --- a/drivers/gpu/drm/via/via_drv.h
31236 +++ b/drivers/gpu/drm/via/via_drv.h
31237 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
31238 typedef uint32_t maskarray_t[5];
31239
31240 typedef struct drm_via_irq {
31241 - atomic_t irq_received;
31242 + atomic_unchecked_t irq_received;
31243 uint32_t pending_mask;
31244 uint32_t enable_mask;
31245 wait_queue_head_t irq_queue;
31246 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
31247 struct timeval last_vblank;
31248 int last_vblank_valid;
31249 unsigned usec_per_vblank;
31250 - atomic_t vbl_received;
31251 + atomic_unchecked_t vbl_received;
31252 drm_via_state_t hc_state;
31253 char pci_buf[VIA_PCI_BUF_SIZE];
31254 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
31255 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
31256 index d391f48..10c8ca3 100644
31257 --- a/drivers/gpu/drm/via/via_irq.c
31258 +++ b/drivers/gpu/drm/via/via_irq.c
31259 @@ -102,7 +102,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
31260 if (crtc != 0)
31261 return 0;
31262
31263 - return atomic_read(&dev_priv->vbl_received);
31264 + return atomic_read_unchecked(&dev_priv->vbl_received);
31265 }
31266
31267 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31268 @@ -117,8 +117,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31269
31270 status = VIA_READ(VIA_REG_INTERRUPT);
31271 if (status & VIA_IRQ_VBLANK_PENDING) {
31272 - atomic_inc(&dev_priv->vbl_received);
31273 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
31274 + atomic_inc_unchecked(&dev_priv->vbl_received);
31275 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
31276 do_gettimeofday(&cur_vblank);
31277 if (dev_priv->last_vblank_valid) {
31278 dev_priv->usec_per_vblank =
31279 @@ -128,7 +128,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31280 dev_priv->last_vblank = cur_vblank;
31281 dev_priv->last_vblank_valid = 1;
31282 }
31283 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
31284 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
31285 DRM_DEBUG("US per vblank is: %u\n",
31286 dev_priv->usec_per_vblank);
31287 }
31288 @@ -138,7 +138,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
31289
31290 for (i = 0; i < dev_priv->num_irqs; ++i) {
31291 if (status & cur_irq->pending_mask) {
31292 - atomic_inc(&cur_irq->irq_received);
31293 + atomic_inc_unchecked(&cur_irq->irq_received);
31294 DRM_WAKEUP(&cur_irq->irq_queue);
31295 handled = 1;
31296 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
31297 @@ -243,11 +243,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
31298 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31299 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
31300 masks[irq][4]));
31301 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
31302 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
31303 } else {
31304 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
31305 (((cur_irq_sequence =
31306 - atomic_read(&cur_irq->irq_received)) -
31307 + atomic_read_unchecked(&cur_irq->irq_received)) -
31308 *sequence) <= (1 << 23)));
31309 }
31310 *sequence = cur_irq_sequence;
31311 @@ -285,7 +285,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
31312 }
31313
31314 for (i = 0; i < dev_priv->num_irqs; ++i) {
31315 - atomic_set(&cur_irq->irq_received, 0);
31316 + atomic_set_unchecked(&cur_irq->irq_received, 0);
31317 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
31318 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
31319 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
31320 @@ -367,7 +367,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
31321 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
31322 case VIA_IRQ_RELATIVE:
31323 irqwait->request.sequence +=
31324 - atomic_read(&cur_irq->irq_received);
31325 + atomic_read_unchecked(&cur_irq->irq_received);
31326 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
31327 case VIA_IRQ_ABSOLUTE:
31328 break;
31329 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31330 index 29c984f..4084f1a 100644
31331 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31332 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
31333 @@ -263,7 +263,7 @@ struct vmw_private {
31334 * Fencing and IRQs.
31335 */
31336
31337 - atomic_t marker_seq;
31338 + atomic_unchecked_t marker_seq;
31339 wait_queue_head_t fence_queue;
31340 wait_queue_head_t fifo_queue;
31341 int fence_queue_waiters; /* Protected by hw_mutex */
31342 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31343 index a0c2f12..68ae6cb 100644
31344 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31345 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
31346 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
31347 (unsigned int) min,
31348 (unsigned int) fifo->capabilities);
31349
31350 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31351 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
31352 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
31353 vmw_marker_queue_init(&fifo->marker_queue);
31354 return vmw_fifo_send_fence(dev_priv, &dummy);
31355 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
31356 if (reserveable)
31357 iowrite32(bytes, fifo_mem +
31358 SVGA_FIFO_RESERVED);
31359 - return fifo_mem + (next_cmd >> 2);
31360 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
31361 } else {
31362 need_bounce = true;
31363 }
31364 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31365
31366 fm = vmw_fifo_reserve(dev_priv, bytes);
31367 if (unlikely(fm == NULL)) {
31368 - *seqno = atomic_read(&dev_priv->marker_seq);
31369 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31370 ret = -ENOMEM;
31371 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
31372 false, 3*HZ);
31373 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
31374 }
31375
31376 do {
31377 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
31378 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
31379 } while (*seqno == 0);
31380
31381 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
31382 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31383 index cabc95f..14b3d77 100644
31384 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31385 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
31386 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
31387 * emitted. Then the fence is stale and signaled.
31388 */
31389
31390 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
31391 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
31392 > VMW_FENCE_WRAP);
31393
31394 return ret;
31395 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
31396
31397 if (fifo_idle)
31398 down_read(&fifo_state->rwsem);
31399 - signal_seq = atomic_read(&dev_priv->marker_seq);
31400 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
31401 ret = 0;
31402
31403 for (;;) {
31404 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31405 index 8a8725c..afed796 100644
31406 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31407 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
31408 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
31409 while (!vmw_lag_lt(queue, us)) {
31410 spin_lock(&queue->lock);
31411 if (list_empty(&queue->head))
31412 - seqno = atomic_read(&dev_priv->marker_seq);
31413 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
31414 else {
31415 marker = list_first_entry(&queue->head,
31416 struct vmw_marker, head);
31417 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
31418 index 1f6957c..b579481 100644
31419 --- a/drivers/hid/hid-core.c
31420 +++ b/drivers/hid/hid-core.c
31421 @@ -2153,7 +2153,7 @@ static bool hid_ignore(struct hid_device *hdev)
31422
31423 int hid_add_device(struct hid_device *hdev)
31424 {
31425 - static atomic_t id = ATOMIC_INIT(0);
31426 + static atomic_unchecked_t id = ATOMIC_INIT(0);
31427 int ret;
31428
31429 if (WARN_ON(hdev->status & HID_STAT_ADDED))
31430 @@ -2188,7 +2188,7 @@ int hid_add_device(struct hid_device *hdev)
31431 /* XXX hack, any other cleaner solution after the driver core
31432 * is converted to allow more than 20 bytes as the device name? */
31433 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
31434 - hdev->vendor, hdev->product, atomic_inc_return(&id));
31435 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
31436
31437 hid_debug_register(hdev, dev_name(&hdev->dev));
31438 ret = device_add(&hdev->dev);
31439 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
31440 index eec3291..8ed706b 100644
31441 --- a/drivers/hid/hid-wiimote-debug.c
31442 +++ b/drivers/hid/hid-wiimote-debug.c
31443 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
31444 else if (size == 0)
31445 return -EIO;
31446
31447 - if (copy_to_user(u, buf, size))
31448 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
31449 return -EFAULT;
31450
31451 *off += size;
31452 diff --git a/drivers/hid/usbhid/hiddev.c b/drivers/hid/usbhid/hiddev.c
31453 index 14599e2..711c965 100644
31454 --- a/drivers/hid/usbhid/hiddev.c
31455 +++ b/drivers/hid/usbhid/hiddev.c
31456 @@ -625,7 +625,7 @@ static long hiddev_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
31457 break;
31458
31459 case HIDIOCAPPLICATION:
31460 - if (arg < 0 || arg >= hid->maxapplication)
31461 + if (arg >= hid->maxapplication)
31462 break;
31463
31464 for (i = 0; i < hid->maxcollection; i++)
31465 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
31466 index 4065374..10ed7dc 100644
31467 --- a/drivers/hv/channel.c
31468 +++ b/drivers/hv/channel.c
31469 @@ -400,8 +400,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
31470 int ret = 0;
31471 int t;
31472
31473 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
31474 - atomic_inc(&vmbus_connection.next_gpadl_handle);
31475 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
31476 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
31477
31478 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
31479 if (ret)
31480 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
31481 index 86f8885..ab9cb2b 100644
31482 --- a/drivers/hv/hv.c
31483 +++ b/drivers/hv/hv.c
31484 @@ -132,7 +132,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
31485 u64 output_address = (output) ? virt_to_phys(output) : 0;
31486 u32 output_address_hi = output_address >> 32;
31487 u32 output_address_lo = output_address & 0xFFFFFFFF;
31488 - void *hypercall_page = hv_context.hypercall_page;
31489 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
31490
31491 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
31492 "=a"(hv_status_lo) : "d" (control_hi),
31493 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
31494 index b9426a6..677ce34 100644
31495 --- a/drivers/hv/hyperv_vmbus.h
31496 +++ b/drivers/hv/hyperv_vmbus.h
31497 @@ -555,7 +555,7 @@ enum vmbus_connect_state {
31498 struct vmbus_connection {
31499 enum vmbus_connect_state conn_state;
31500
31501 - atomic_t next_gpadl_handle;
31502 + atomic_unchecked_t next_gpadl_handle;
31503
31504 /*
31505 * Represents channel interrupts. Each bit position represents a
31506 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
31507 index a220e57..428f54d 100644
31508 --- a/drivers/hv/vmbus_drv.c
31509 +++ b/drivers/hv/vmbus_drv.c
31510 @@ -663,10 +663,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
31511 {
31512 int ret = 0;
31513
31514 - static atomic_t device_num = ATOMIC_INIT(0);
31515 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
31516
31517 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
31518 - atomic_inc_return(&device_num));
31519 + atomic_inc_return_unchecked(&device_num));
31520
31521 child_device_obj->device.bus = &hv_bus;
31522 child_device_obj->device.parent = &hv_acpi_dev->dev;
31523 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
31524 index 34ad5a2..e2b0ae8 100644
31525 --- a/drivers/hwmon/acpi_power_meter.c
31526 +++ b/drivers/hwmon/acpi_power_meter.c
31527 @@ -308,8 +308,6 @@ static ssize_t set_trip(struct device *dev, struct device_attribute *devattr,
31528 return res;
31529
31530 temp /= 1000;
31531 - if (temp < 0)
31532 - return -EINVAL;
31533
31534 mutex_lock(&resource->lock);
31535 resource->trip[attr->index - 7] = temp;
31536 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
31537 index 8b011d0..3de24a1 100644
31538 --- a/drivers/hwmon/sht15.c
31539 +++ b/drivers/hwmon/sht15.c
31540 @@ -166,7 +166,7 @@ struct sht15_data {
31541 int supply_uV;
31542 bool supply_uV_valid;
31543 struct work_struct update_supply_work;
31544 - atomic_t interrupt_handled;
31545 + atomic_unchecked_t interrupt_handled;
31546 };
31547
31548 /**
31549 @@ -509,13 +509,13 @@ static int sht15_measurement(struct sht15_data *data,
31550 return ret;
31551
31552 gpio_direction_input(data->pdata->gpio_data);
31553 - atomic_set(&data->interrupt_handled, 0);
31554 + atomic_set_unchecked(&data->interrupt_handled, 0);
31555
31556 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31557 if (gpio_get_value(data->pdata->gpio_data) == 0) {
31558 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
31559 /* Only relevant if the interrupt hasn't occurred. */
31560 - if (!atomic_read(&data->interrupt_handled))
31561 + if (!atomic_read_unchecked(&data->interrupt_handled))
31562 schedule_work(&data->read_work);
31563 }
31564 ret = wait_event_timeout(data->wait_queue,
31565 @@ -782,7 +782,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
31566
31567 /* First disable the interrupt */
31568 disable_irq_nosync(irq);
31569 - atomic_inc(&data->interrupt_handled);
31570 + atomic_inc_unchecked(&data->interrupt_handled);
31571 /* Then schedule a reading work struct */
31572 if (data->state != SHT15_READING_NOTHING)
31573 schedule_work(&data->read_work);
31574 @@ -804,11 +804,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
31575 * If not, then start the interrupt again - care here as could
31576 * have gone low in meantime so verify it hasn't!
31577 */
31578 - atomic_set(&data->interrupt_handled, 0);
31579 + atomic_set_unchecked(&data->interrupt_handled, 0);
31580 enable_irq(gpio_to_irq(data->pdata->gpio_data));
31581 /* If still not occurred or another handler was scheduled */
31582 if (gpio_get_value(data->pdata->gpio_data)
31583 - || atomic_read(&data->interrupt_handled))
31584 + || atomic_read_unchecked(&data->interrupt_handled))
31585 return;
31586 }
31587
31588 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
31589 index 378fcb5..5e91fa8 100644
31590 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
31591 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
31592 @@ -43,7 +43,7 @@
31593 extern struct i2c_adapter amd756_smbus;
31594
31595 static struct i2c_adapter *s4882_adapter;
31596 -static struct i2c_algorithm *s4882_algo;
31597 +static i2c_algorithm_no_const *s4882_algo;
31598
31599 /* Wrapper access functions for multiplexed SMBus */
31600 static DEFINE_MUTEX(amd756_lock);
31601 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
31602 index 29015eb..af2d8e9 100644
31603 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
31604 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
31605 @@ -41,7 +41,7 @@
31606 extern struct i2c_adapter *nforce2_smbus;
31607
31608 static struct i2c_adapter *s4985_adapter;
31609 -static struct i2c_algorithm *s4985_algo;
31610 +static i2c_algorithm_no_const *s4985_algo;
31611
31612 /* Wrapper access functions for multiplexed SMBus */
31613 static DEFINE_MUTEX(nforce2_lock);
31614 diff --git a/drivers/i2c/i2c-mux.c b/drivers/i2c/i2c-mux.c
31615 index 1038c38..eb92f51 100644
31616 --- a/drivers/i2c/i2c-mux.c
31617 +++ b/drivers/i2c/i2c-mux.c
31618 @@ -30,7 +30,7 @@
31619 /* multiplexer per channel data */
31620 struct i2c_mux_priv {
31621 struct i2c_adapter adap;
31622 - struct i2c_algorithm algo;
31623 + i2c_algorithm_no_const algo;
31624
31625 struct i2c_adapter *parent;
31626 void *mux_priv; /* the mux chip/device */
31627 diff --git a/drivers/ide/aec62xx.c b/drivers/ide/aec62xx.c
31628 index 57d00ca..0145194 100644
31629 --- a/drivers/ide/aec62xx.c
31630 +++ b/drivers/ide/aec62xx.c
31631 @@ -181,7 +181,7 @@ static const struct ide_port_ops atp86x_port_ops = {
31632 .cable_detect = atp86x_cable_detect,
31633 };
31634
31635 -static const struct ide_port_info aec62xx_chipsets[] __devinitdata = {
31636 +static const struct ide_port_info aec62xx_chipsets[] __devinitconst = {
31637 { /* 0: AEC6210 */
31638 .name = DRV_NAME,
31639 .init_chipset = init_chipset_aec62xx,
31640 diff --git a/drivers/ide/alim15x3.c b/drivers/ide/alim15x3.c
31641 index 2c8016a..911a27c 100644
31642 --- a/drivers/ide/alim15x3.c
31643 +++ b/drivers/ide/alim15x3.c
31644 @@ -512,7 +512,7 @@ static const struct ide_dma_ops ali_dma_ops = {
31645 .dma_sff_read_status = ide_dma_sff_read_status,
31646 };
31647
31648 -static const struct ide_port_info ali15x3_chipset __devinitdata = {
31649 +static const struct ide_port_info ali15x3_chipset __devinitconst = {
31650 .name = DRV_NAME,
31651 .init_chipset = init_chipset_ali15x3,
31652 .init_hwif = init_hwif_ali15x3,
31653 diff --git a/drivers/ide/amd74xx.c b/drivers/ide/amd74xx.c
31654 index 3747b25..56fc995 100644
31655 --- a/drivers/ide/amd74xx.c
31656 +++ b/drivers/ide/amd74xx.c
31657 @@ -223,7 +223,7 @@ static const struct ide_port_ops amd_port_ops = {
31658 .udma_mask = udma, \
31659 }
31660
31661 -static const struct ide_port_info amd74xx_chipsets[] __devinitdata = {
31662 +static const struct ide_port_info amd74xx_chipsets[] __devinitconst = {
31663 /* 0: AMD7401 */ DECLARE_AMD_DEV(0x00, ATA_UDMA2),
31664 /* 1: AMD7409 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA4),
31665 /* 2: AMD7411/7441 */ DECLARE_AMD_DEV(ATA_SWDMA2, ATA_UDMA5),
31666 diff --git a/drivers/ide/atiixp.c b/drivers/ide/atiixp.c
31667 index 15f0ead..cb43480 100644
31668 --- a/drivers/ide/atiixp.c
31669 +++ b/drivers/ide/atiixp.c
31670 @@ -139,7 +139,7 @@ static const struct ide_port_ops atiixp_port_ops = {
31671 .cable_detect = atiixp_cable_detect,
31672 };
31673
31674 -static const struct ide_port_info atiixp_pci_info[] __devinitdata = {
31675 +static const struct ide_port_info atiixp_pci_info[] __devinitconst = {
31676 { /* 0: IXP200/300/400/700 */
31677 .name = DRV_NAME,
31678 .enablebits = {{0x48,0x01,0x00}, {0x48,0x08,0x00}},
31679 diff --git a/drivers/ide/cmd64x.c b/drivers/ide/cmd64x.c
31680 index 5f80312..d1fc438 100644
31681 --- a/drivers/ide/cmd64x.c
31682 +++ b/drivers/ide/cmd64x.c
31683 @@ -327,7 +327,7 @@ static const struct ide_dma_ops cmd646_rev1_dma_ops = {
31684 .dma_sff_read_status = ide_dma_sff_read_status,
31685 };
31686
31687 -static const struct ide_port_info cmd64x_chipsets[] __devinitdata = {
31688 +static const struct ide_port_info cmd64x_chipsets[] __devinitconst = {
31689 { /* 0: CMD643 */
31690 .name = DRV_NAME,
31691 .init_chipset = init_chipset_cmd64x,
31692 diff --git a/drivers/ide/cs5520.c b/drivers/ide/cs5520.c
31693 index 2c1e5f7..1444762 100644
31694 --- a/drivers/ide/cs5520.c
31695 +++ b/drivers/ide/cs5520.c
31696 @@ -94,7 +94,7 @@ static const struct ide_port_ops cs5520_port_ops = {
31697 .set_dma_mode = cs5520_set_dma_mode,
31698 };
31699
31700 -static const struct ide_port_info cyrix_chipset __devinitdata = {
31701 +static const struct ide_port_info cyrix_chipset __devinitconst = {
31702 .name = DRV_NAME,
31703 .enablebits = { { 0x60, 0x01, 0x01 }, { 0x60, 0x02, 0x02 } },
31704 .port_ops = &cs5520_port_ops,
31705 diff --git a/drivers/ide/cs5530.c b/drivers/ide/cs5530.c
31706 index 4dc4eb9..49b40ad 100644
31707 --- a/drivers/ide/cs5530.c
31708 +++ b/drivers/ide/cs5530.c
31709 @@ -245,7 +245,7 @@ static const struct ide_port_ops cs5530_port_ops = {
31710 .udma_filter = cs5530_udma_filter,
31711 };
31712
31713 -static const struct ide_port_info cs5530_chipset __devinitdata = {
31714 +static const struct ide_port_info cs5530_chipset __devinitconst = {
31715 .name = DRV_NAME,
31716 .init_chipset = init_chipset_cs5530,
31717 .init_hwif = init_hwif_cs5530,
31718 diff --git a/drivers/ide/cs5535.c b/drivers/ide/cs5535.c
31719 index 5059faf..18d4c85 100644
31720 --- a/drivers/ide/cs5535.c
31721 +++ b/drivers/ide/cs5535.c
31722 @@ -170,7 +170,7 @@ static const struct ide_port_ops cs5535_port_ops = {
31723 .cable_detect = cs5535_cable_detect,
31724 };
31725
31726 -static const struct ide_port_info cs5535_chipset __devinitdata = {
31727 +static const struct ide_port_info cs5535_chipset __devinitconst = {
31728 .name = DRV_NAME,
31729 .port_ops = &cs5535_port_ops,
31730 .host_flags = IDE_HFLAG_SINGLE | IDE_HFLAG_POST_SET_MODE,
31731 diff --git a/drivers/ide/cy82c693.c b/drivers/ide/cy82c693.c
31732 index 847553f..3ffb49d 100644
31733 --- a/drivers/ide/cy82c693.c
31734 +++ b/drivers/ide/cy82c693.c
31735 @@ -163,7 +163,7 @@ static const struct ide_port_ops cy82c693_port_ops = {
31736 .set_dma_mode = cy82c693_set_dma_mode,
31737 };
31738
31739 -static const struct ide_port_info cy82c693_chipset __devinitdata = {
31740 +static const struct ide_port_info cy82c693_chipset __devinitconst = {
31741 .name = DRV_NAME,
31742 .init_iops = init_iops_cy82c693,
31743 .port_ops = &cy82c693_port_ops,
31744 diff --git a/drivers/ide/hpt366.c b/drivers/ide/hpt366.c
31745 index 58c51cd..4aec3b8 100644
31746 --- a/drivers/ide/hpt366.c
31747 +++ b/drivers/ide/hpt366.c
31748 @@ -443,7 +443,7 @@ static struct hpt_timings hpt37x_timings = {
31749 }
31750 };
31751
31752 -static const struct hpt_info hpt36x __devinitdata = {
31753 +static const struct hpt_info hpt36x __devinitconst = {
31754 .chip_name = "HPT36x",
31755 .chip_type = HPT36x,
31756 .udma_mask = HPT366_ALLOW_ATA66_3 ? (HPT366_ALLOW_ATA66_4 ? ATA_UDMA4 : ATA_UDMA3) : ATA_UDMA2,
31757 @@ -451,7 +451,7 @@ static const struct hpt_info hpt36x __devinitdata = {
31758 .timings = &hpt36x_timings
31759 };
31760
31761 -static const struct hpt_info hpt370 __devinitdata = {
31762 +static const struct hpt_info hpt370 __devinitconst = {
31763 .chip_name = "HPT370",
31764 .chip_type = HPT370,
31765 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31766 @@ -459,7 +459,7 @@ static const struct hpt_info hpt370 __devinitdata = {
31767 .timings = &hpt37x_timings
31768 };
31769
31770 -static const struct hpt_info hpt370a __devinitdata = {
31771 +static const struct hpt_info hpt370a __devinitconst = {
31772 .chip_name = "HPT370A",
31773 .chip_type = HPT370A,
31774 .udma_mask = HPT370_ALLOW_ATA100_5 ? ATA_UDMA5 : ATA_UDMA4,
31775 @@ -467,7 +467,7 @@ static const struct hpt_info hpt370a __devinitdata = {
31776 .timings = &hpt37x_timings
31777 };
31778
31779 -static const struct hpt_info hpt374 __devinitdata = {
31780 +static const struct hpt_info hpt374 __devinitconst = {
31781 .chip_name = "HPT374",
31782 .chip_type = HPT374,
31783 .udma_mask = ATA_UDMA5,
31784 @@ -475,7 +475,7 @@ static const struct hpt_info hpt374 __devinitdata = {
31785 .timings = &hpt37x_timings
31786 };
31787
31788 -static const struct hpt_info hpt372 __devinitdata = {
31789 +static const struct hpt_info hpt372 __devinitconst = {
31790 .chip_name = "HPT372",
31791 .chip_type = HPT372,
31792 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31793 @@ -483,7 +483,7 @@ static const struct hpt_info hpt372 __devinitdata = {
31794 .timings = &hpt37x_timings
31795 };
31796
31797 -static const struct hpt_info hpt372a __devinitdata = {
31798 +static const struct hpt_info hpt372a __devinitconst = {
31799 .chip_name = "HPT372A",
31800 .chip_type = HPT372A,
31801 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31802 @@ -491,7 +491,7 @@ static const struct hpt_info hpt372a __devinitdata = {
31803 .timings = &hpt37x_timings
31804 };
31805
31806 -static const struct hpt_info hpt302 __devinitdata = {
31807 +static const struct hpt_info hpt302 __devinitconst = {
31808 .chip_name = "HPT302",
31809 .chip_type = HPT302,
31810 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31811 @@ -499,7 +499,7 @@ static const struct hpt_info hpt302 __devinitdata = {
31812 .timings = &hpt37x_timings
31813 };
31814
31815 -static const struct hpt_info hpt371 __devinitdata = {
31816 +static const struct hpt_info hpt371 __devinitconst = {
31817 .chip_name = "HPT371",
31818 .chip_type = HPT371,
31819 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31820 @@ -507,7 +507,7 @@ static const struct hpt_info hpt371 __devinitdata = {
31821 .timings = &hpt37x_timings
31822 };
31823
31824 -static const struct hpt_info hpt372n __devinitdata = {
31825 +static const struct hpt_info hpt372n __devinitconst = {
31826 .chip_name = "HPT372N",
31827 .chip_type = HPT372N,
31828 .udma_mask = HPT372_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31829 @@ -515,7 +515,7 @@ static const struct hpt_info hpt372n __devinitdata = {
31830 .timings = &hpt37x_timings
31831 };
31832
31833 -static const struct hpt_info hpt302n __devinitdata = {
31834 +static const struct hpt_info hpt302n __devinitconst = {
31835 .chip_name = "HPT302N",
31836 .chip_type = HPT302N,
31837 .udma_mask = HPT302_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31838 @@ -523,7 +523,7 @@ static const struct hpt_info hpt302n __devinitdata = {
31839 .timings = &hpt37x_timings
31840 };
31841
31842 -static const struct hpt_info hpt371n __devinitdata = {
31843 +static const struct hpt_info hpt371n __devinitconst = {
31844 .chip_name = "HPT371N",
31845 .chip_type = HPT371N,
31846 .udma_mask = HPT371_ALLOW_ATA133_6 ? ATA_UDMA6 : ATA_UDMA5,
31847 @@ -1361,7 +1361,7 @@ static const struct ide_dma_ops hpt36x_dma_ops = {
31848 .dma_sff_read_status = ide_dma_sff_read_status,
31849 };
31850
31851 -static const struct ide_port_info hpt366_chipsets[] __devinitdata = {
31852 +static const struct ide_port_info hpt366_chipsets[] __devinitconst = {
31853 { /* 0: HPT36x */
31854 .name = DRV_NAME,
31855 .init_chipset = init_chipset_hpt366,
31856 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
31857 index 8126824..55a2798 100644
31858 --- a/drivers/ide/ide-cd.c
31859 +++ b/drivers/ide/ide-cd.c
31860 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
31861 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
31862 if ((unsigned long)buf & alignment
31863 || blk_rq_bytes(rq) & q->dma_pad_mask
31864 - || object_is_on_stack(buf))
31865 + || object_starts_on_stack(buf))
31866 drive->dma = 0;
31867 }
31868 }
31869 diff --git a/drivers/ide/ide-pci-generic.c b/drivers/ide/ide-pci-generic.c
31870 index 7f56b73..dab5b67 100644
31871 --- a/drivers/ide/ide-pci-generic.c
31872 +++ b/drivers/ide/ide-pci-generic.c
31873 @@ -53,7 +53,7 @@ static const struct ide_port_ops netcell_port_ops = {
31874 .udma_mask = ATA_UDMA6, \
31875 }
31876
31877 -static const struct ide_port_info generic_chipsets[] __devinitdata = {
31878 +static const struct ide_port_info generic_chipsets[] __devinitconst = {
31879 /* 0: Unknown */
31880 DECLARE_GENERIC_PCI_DEV(0),
31881
31882 diff --git a/drivers/ide/it8172.c b/drivers/ide/it8172.c
31883 index 560e66d..d5dd180 100644
31884 --- a/drivers/ide/it8172.c
31885 +++ b/drivers/ide/it8172.c
31886 @@ -115,7 +115,7 @@ static const struct ide_port_ops it8172_port_ops = {
31887 .set_dma_mode = it8172_set_dma_mode,
31888 };
31889
31890 -static const struct ide_port_info it8172_port_info __devinitdata = {
31891 +static const struct ide_port_info it8172_port_info __devinitconst = {
31892 .name = DRV_NAME,
31893 .port_ops = &it8172_port_ops,
31894 .enablebits = { {0x41, 0x80, 0x80}, {0x00, 0x00, 0x00} },
31895 diff --git a/drivers/ide/it8213.c b/drivers/ide/it8213.c
31896 index 46816ba..1847aeb 100644
31897 --- a/drivers/ide/it8213.c
31898 +++ b/drivers/ide/it8213.c
31899 @@ -156,7 +156,7 @@ static const struct ide_port_ops it8213_port_ops = {
31900 .cable_detect = it8213_cable_detect,
31901 };
31902
31903 -static const struct ide_port_info it8213_chipset __devinitdata = {
31904 +static const struct ide_port_info it8213_chipset __devinitconst = {
31905 .name = DRV_NAME,
31906 .enablebits = { {0x41, 0x80, 0x80} },
31907 .port_ops = &it8213_port_ops,
31908 diff --git a/drivers/ide/it821x.c b/drivers/ide/it821x.c
31909 index 2e3169f..c5611db 100644
31910 --- a/drivers/ide/it821x.c
31911 +++ b/drivers/ide/it821x.c
31912 @@ -630,7 +630,7 @@ static const struct ide_port_ops it821x_port_ops = {
31913 .cable_detect = it821x_cable_detect,
31914 };
31915
31916 -static const struct ide_port_info it821x_chipset __devinitdata = {
31917 +static const struct ide_port_info it821x_chipset __devinitconst = {
31918 .name = DRV_NAME,
31919 .init_chipset = init_chipset_it821x,
31920 .init_hwif = init_hwif_it821x,
31921 diff --git a/drivers/ide/jmicron.c b/drivers/ide/jmicron.c
31922 index 74c2c4a..efddd7d 100644
31923 --- a/drivers/ide/jmicron.c
31924 +++ b/drivers/ide/jmicron.c
31925 @@ -102,7 +102,7 @@ static const struct ide_port_ops jmicron_port_ops = {
31926 .cable_detect = jmicron_cable_detect,
31927 };
31928
31929 -static const struct ide_port_info jmicron_chipset __devinitdata = {
31930 +static const struct ide_port_info jmicron_chipset __devinitconst = {
31931 .name = DRV_NAME,
31932 .enablebits = { { 0x40, 0x01, 0x01 }, { 0x40, 0x10, 0x10 } },
31933 .port_ops = &jmicron_port_ops,
31934 diff --git a/drivers/ide/ns87415.c b/drivers/ide/ns87415.c
31935 index 95327a2..73f78d8 100644
31936 --- a/drivers/ide/ns87415.c
31937 +++ b/drivers/ide/ns87415.c
31938 @@ -293,7 +293,7 @@ static const struct ide_dma_ops ns87415_dma_ops = {
31939 .dma_sff_read_status = superio_dma_sff_read_status,
31940 };
31941
31942 -static const struct ide_port_info ns87415_chipset __devinitdata = {
31943 +static const struct ide_port_info ns87415_chipset __devinitconst = {
31944 .name = DRV_NAME,
31945 .init_hwif = init_hwif_ns87415,
31946 .tp_ops = &ns87415_tp_ops,
31947 diff --git a/drivers/ide/opti621.c b/drivers/ide/opti621.c
31948 index 1a53a4c..39edc66 100644
31949 --- a/drivers/ide/opti621.c
31950 +++ b/drivers/ide/opti621.c
31951 @@ -131,7 +131,7 @@ static const struct ide_port_ops opti621_port_ops = {
31952 .set_pio_mode = opti621_set_pio_mode,
31953 };
31954
31955 -static const struct ide_port_info opti621_chipset __devinitdata = {
31956 +static const struct ide_port_info opti621_chipset __devinitconst = {
31957 .name = DRV_NAME,
31958 .enablebits = { {0x45, 0x80, 0x00}, {0x40, 0x08, 0x00} },
31959 .port_ops = &opti621_port_ops,
31960 diff --git a/drivers/ide/pdc202xx_new.c b/drivers/ide/pdc202xx_new.c
31961 index 9546fe2..2e5ceb6 100644
31962 --- a/drivers/ide/pdc202xx_new.c
31963 +++ b/drivers/ide/pdc202xx_new.c
31964 @@ -465,7 +465,7 @@ static const struct ide_port_ops pdcnew_port_ops = {
31965 .udma_mask = udma, \
31966 }
31967
31968 -static const struct ide_port_info pdcnew_chipsets[] __devinitdata = {
31969 +static const struct ide_port_info pdcnew_chipsets[] __devinitconst = {
31970 /* 0: PDC202{68,70} */ DECLARE_PDCNEW_DEV(ATA_UDMA5),
31971 /* 1: PDC202{69,71,75,76,77} */ DECLARE_PDCNEW_DEV(ATA_UDMA6),
31972 };
31973 diff --git a/drivers/ide/pdc202xx_old.c b/drivers/ide/pdc202xx_old.c
31974 index 3a35ec6..5634510 100644
31975 --- a/drivers/ide/pdc202xx_old.c
31976 +++ b/drivers/ide/pdc202xx_old.c
31977 @@ -270,7 +270,7 @@ static const struct ide_dma_ops pdc2026x_dma_ops = {
31978 .max_sectors = sectors, \
31979 }
31980
31981 -static const struct ide_port_info pdc202xx_chipsets[] __devinitdata = {
31982 +static const struct ide_port_info pdc202xx_chipsets[] __devinitconst = {
31983 { /* 0: PDC20246 */
31984 .name = DRV_NAME,
31985 .init_chipset = init_chipset_pdc202xx,
31986 diff --git a/drivers/ide/piix.c b/drivers/ide/piix.c
31987 index 1892e81..fe0fd60 100644
31988 --- a/drivers/ide/piix.c
31989 +++ b/drivers/ide/piix.c
31990 @@ -344,7 +344,7 @@ static const struct ide_port_ops ich_port_ops = {
31991 .udma_mask = udma, \
31992 }
31993
31994 -static const struct ide_port_info piix_pci_info[] __devinitdata = {
31995 +static const struct ide_port_info piix_pci_info[] __devinitconst = {
31996 /* 0: MPIIX */
31997 { /*
31998 * MPIIX actually has only a single IDE channel mapped to
31999 diff --git a/drivers/ide/rz1000.c b/drivers/ide/rz1000.c
32000 index a6414a8..c04173e 100644
32001 --- a/drivers/ide/rz1000.c
32002 +++ b/drivers/ide/rz1000.c
32003 @@ -38,7 +38,7 @@ static int __devinit rz1000_disable_readahead(struct pci_dev *dev)
32004 }
32005 }
32006
32007 -static const struct ide_port_info rz1000_chipset __devinitdata = {
32008 +static const struct ide_port_info rz1000_chipset __devinitconst = {
32009 .name = DRV_NAME,
32010 .host_flags = IDE_HFLAG_NO_DMA,
32011 };
32012 diff --git a/drivers/ide/sc1200.c b/drivers/ide/sc1200.c
32013 index 356b9b5..d4758eb 100644
32014 --- a/drivers/ide/sc1200.c
32015 +++ b/drivers/ide/sc1200.c
32016 @@ -291,7 +291,7 @@ static const struct ide_dma_ops sc1200_dma_ops = {
32017 .dma_sff_read_status = ide_dma_sff_read_status,
32018 };
32019
32020 -static const struct ide_port_info sc1200_chipset __devinitdata = {
32021 +static const struct ide_port_info sc1200_chipset __devinitconst = {
32022 .name = DRV_NAME,
32023 .port_ops = &sc1200_port_ops,
32024 .dma_ops = &sc1200_dma_ops,
32025 diff --git a/drivers/ide/scc_pata.c b/drivers/ide/scc_pata.c
32026 index b7f5b0c..9701038 100644
32027 --- a/drivers/ide/scc_pata.c
32028 +++ b/drivers/ide/scc_pata.c
32029 @@ -811,7 +811,7 @@ static const struct ide_dma_ops scc_dma_ops = {
32030 .dma_sff_read_status = scc_dma_sff_read_status,
32031 };
32032
32033 -static const struct ide_port_info scc_chipset __devinitdata = {
32034 +static const struct ide_port_info scc_chipset __devinitconst = {
32035 .name = "sccIDE",
32036 .init_iops = init_iops_scc,
32037 .init_dma = scc_init_dma,
32038 diff --git a/drivers/ide/serverworks.c b/drivers/ide/serverworks.c
32039 index 35fb8da..24d72ef 100644
32040 --- a/drivers/ide/serverworks.c
32041 +++ b/drivers/ide/serverworks.c
32042 @@ -337,7 +337,7 @@ static const struct ide_port_ops svwks_port_ops = {
32043 .cable_detect = svwks_cable_detect,
32044 };
32045
32046 -static const struct ide_port_info serverworks_chipsets[] __devinitdata = {
32047 +static const struct ide_port_info serverworks_chipsets[] __devinitconst = {
32048 { /* 0: OSB4 */
32049 .name = DRV_NAME,
32050 .init_chipset = init_chipset_svwks,
32051 diff --git a/drivers/ide/siimage.c b/drivers/ide/siimage.c
32052 index ddeda44..46f7e30 100644
32053 --- a/drivers/ide/siimage.c
32054 +++ b/drivers/ide/siimage.c
32055 @@ -719,7 +719,7 @@ static const struct ide_dma_ops sil_dma_ops = {
32056 .udma_mask = ATA_UDMA6, \
32057 }
32058
32059 -static const struct ide_port_info siimage_chipsets[] __devinitdata = {
32060 +static const struct ide_port_info siimage_chipsets[] __devinitconst = {
32061 /* 0: SiI680 */ DECLARE_SII_DEV(&sil_pata_port_ops),
32062 /* 1: SiI3112 */ DECLARE_SII_DEV(&sil_sata_port_ops)
32063 };
32064 diff --git a/drivers/ide/sis5513.c b/drivers/ide/sis5513.c
32065 index 4a00225..09e61b4 100644
32066 --- a/drivers/ide/sis5513.c
32067 +++ b/drivers/ide/sis5513.c
32068 @@ -563,7 +563,7 @@ static const struct ide_port_ops sis_ata133_port_ops = {
32069 .cable_detect = sis_cable_detect,
32070 };
32071
32072 -static const struct ide_port_info sis5513_chipset __devinitdata = {
32073 +static const struct ide_port_info sis5513_chipset __devinitconst = {
32074 .name = DRV_NAME,
32075 .init_chipset = init_chipset_sis5513,
32076 .enablebits = { {0x4a, 0x02, 0x02}, {0x4a, 0x04, 0x04} },
32077 diff --git a/drivers/ide/sl82c105.c b/drivers/ide/sl82c105.c
32078 index f21dc2a..d051cd2 100644
32079 --- a/drivers/ide/sl82c105.c
32080 +++ b/drivers/ide/sl82c105.c
32081 @@ -299,7 +299,7 @@ static const struct ide_dma_ops sl82c105_dma_ops = {
32082 .dma_sff_read_status = ide_dma_sff_read_status,
32083 };
32084
32085 -static const struct ide_port_info sl82c105_chipset __devinitdata = {
32086 +static const struct ide_port_info sl82c105_chipset __devinitconst = {
32087 .name = DRV_NAME,
32088 .init_chipset = init_chipset_sl82c105,
32089 .enablebits = {{0x40,0x01,0x01}, {0x40,0x10,0x10}},
32090 diff --git a/drivers/ide/slc90e66.c b/drivers/ide/slc90e66.c
32091 index 864ffe0..863a5e9 100644
32092 --- a/drivers/ide/slc90e66.c
32093 +++ b/drivers/ide/slc90e66.c
32094 @@ -132,7 +132,7 @@ static const struct ide_port_ops slc90e66_port_ops = {
32095 .cable_detect = slc90e66_cable_detect,
32096 };
32097
32098 -static const struct ide_port_info slc90e66_chipset __devinitdata = {
32099 +static const struct ide_port_info slc90e66_chipset __devinitconst = {
32100 .name = DRV_NAME,
32101 .enablebits = { {0x41, 0x80, 0x80}, {0x43, 0x80, 0x80} },
32102 .port_ops = &slc90e66_port_ops,
32103 diff --git a/drivers/ide/tc86c001.c b/drivers/ide/tc86c001.c
32104 index 4799d5c..1794678 100644
32105 --- a/drivers/ide/tc86c001.c
32106 +++ b/drivers/ide/tc86c001.c
32107 @@ -192,7 +192,7 @@ static const struct ide_dma_ops tc86c001_dma_ops = {
32108 .dma_sff_read_status = ide_dma_sff_read_status,
32109 };
32110
32111 -static const struct ide_port_info tc86c001_chipset __devinitdata = {
32112 +static const struct ide_port_info tc86c001_chipset __devinitconst = {
32113 .name = DRV_NAME,
32114 .init_hwif = init_hwif_tc86c001,
32115 .port_ops = &tc86c001_port_ops,
32116 diff --git a/drivers/ide/triflex.c b/drivers/ide/triflex.c
32117 index 281c914..55ce1b8 100644
32118 --- a/drivers/ide/triflex.c
32119 +++ b/drivers/ide/triflex.c
32120 @@ -92,7 +92,7 @@ static const struct ide_port_ops triflex_port_ops = {
32121 .set_dma_mode = triflex_set_mode,
32122 };
32123
32124 -static const struct ide_port_info triflex_device __devinitdata = {
32125 +static const struct ide_port_info triflex_device __devinitconst = {
32126 .name = DRV_NAME,
32127 .enablebits = {{0x80, 0x01, 0x01}, {0x80, 0x02, 0x02}},
32128 .port_ops = &triflex_port_ops,
32129 diff --git a/drivers/ide/trm290.c b/drivers/ide/trm290.c
32130 index 4b42ca0..e494a98 100644
32131 --- a/drivers/ide/trm290.c
32132 +++ b/drivers/ide/trm290.c
32133 @@ -324,7 +324,7 @@ static struct ide_dma_ops trm290_dma_ops = {
32134 .dma_check = trm290_dma_check,
32135 };
32136
32137 -static const struct ide_port_info trm290_chipset __devinitdata = {
32138 +static const struct ide_port_info trm290_chipset __devinitconst = {
32139 .name = DRV_NAME,
32140 .init_hwif = init_hwif_trm290,
32141 .tp_ops = &trm290_tp_ops,
32142 diff --git a/drivers/ide/via82cxxx.c b/drivers/ide/via82cxxx.c
32143 index f46f49c..eb77678 100644
32144 --- a/drivers/ide/via82cxxx.c
32145 +++ b/drivers/ide/via82cxxx.c
32146 @@ -403,7 +403,7 @@ static const struct ide_port_ops via_port_ops = {
32147 .cable_detect = via82cxxx_cable_detect,
32148 };
32149
32150 -static const struct ide_port_info via82cxxx_chipset __devinitdata = {
32151 +static const struct ide_port_info via82cxxx_chipset __devinitconst = {
32152 .name = DRV_NAME,
32153 .init_chipset = init_chipset_via82cxxx,
32154 .enablebits = { { 0x40, 0x02, 0x02 }, { 0x40, 0x01, 0x01 } },
32155 diff --git a/drivers/ieee802154/fakehard.c b/drivers/ieee802154/fakehard.c
32156 index 73d4531..c90cd2d 100644
32157 --- a/drivers/ieee802154/fakehard.c
32158 +++ b/drivers/ieee802154/fakehard.c
32159 @@ -386,7 +386,7 @@ static int __devinit ieee802154fake_probe(struct platform_device *pdev)
32160 phy->transmit_power = 0xbf;
32161
32162 dev->netdev_ops = &fake_ops;
32163 - dev->ml_priv = &fake_mlme;
32164 + dev->ml_priv = (void *)&fake_mlme;
32165
32166 priv = netdev_priv(dev);
32167 priv->phy = phy;
32168 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
32169 index c889aae..6cf5aa7 100644
32170 --- a/drivers/infiniband/core/cm.c
32171 +++ b/drivers/infiniband/core/cm.c
32172 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
32173
32174 struct cm_counter_group {
32175 struct kobject obj;
32176 - atomic_long_t counter[CM_ATTR_COUNT];
32177 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
32178 };
32179
32180 struct cm_counter_attribute {
32181 @@ -1394,7 +1394,7 @@ static void cm_dup_req_handler(struct cm_work *work,
32182 struct ib_mad_send_buf *msg = NULL;
32183 int ret;
32184
32185 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32186 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32187 counter[CM_REQ_COUNTER]);
32188
32189 /* Quick state check to discard duplicate REQs. */
32190 @@ -1778,7 +1778,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
32191 if (!cm_id_priv)
32192 return;
32193
32194 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32195 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32196 counter[CM_REP_COUNTER]);
32197 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
32198 if (ret)
32199 @@ -1945,7 +1945,7 @@ static int cm_rtu_handler(struct cm_work *work)
32200 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
32201 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
32202 spin_unlock_irq(&cm_id_priv->lock);
32203 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32204 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32205 counter[CM_RTU_COUNTER]);
32206 goto out;
32207 }
32208 @@ -2128,7 +2128,7 @@ static int cm_dreq_handler(struct cm_work *work)
32209 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
32210 dreq_msg->local_comm_id);
32211 if (!cm_id_priv) {
32212 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32213 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32214 counter[CM_DREQ_COUNTER]);
32215 cm_issue_drep(work->port, work->mad_recv_wc);
32216 return -EINVAL;
32217 @@ -2153,7 +2153,7 @@ static int cm_dreq_handler(struct cm_work *work)
32218 case IB_CM_MRA_REP_RCVD:
32219 break;
32220 case IB_CM_TIMEWAIT:
32221 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32222 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32223 counter[CM_DREQ_COUNTER]);
32224 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32225 goto unlock;
32226 @@ -2167,7 +2167,7 @@ static int cm_dreq_handler(struct cm_work *work)
32227 cm_free_msg(msg);
32228 goto deref;
32229 case IB_CM_DREQ_RCVD:
32230 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32231 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32232 counter[CM_DREQ_COUNTER]);
32233 goto unlock;
32234 default:
32235 @@ -2534,7 +2534,7 @@ static int cm_mra_handler(struct cm_work *work)
32236 ib_modify_mad(cm_id_priv->av.port->mad_agent,
32237 cm_id_priv->msg, timeout)) {
32238 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
32239 - atomic_long_inc(&work->port->
32240 + atomic_long_inc_unchecked(&work->port->
32241 counter_group[CM_RECV_DUPLICATES].
32242 counter[CM_MRA_COUNTER]);
32243 goto out;
32244 @@ -2543,7 +2543,7 @@ static int cm_mra_handler(struct cm_work *work)
32245 break;
32246 case IB_CM_MRA_REQ_RCVD:
32247 case IB_CM_MRA_REP_RCVD:
32248 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32249 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32250 counter[CM_MRA_COUNTER]);
32251 /* fall through */
32252 default:
32253 @@ -2705,7 +2705,7 @@ static int cm_lap_handler(struct cm_work *work)
32254 case IB_CM_LAP_IDLE:
32255 break;
32256 case IB_CM_MRA_LAP_SENT:
32257 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32258 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32259 counter[CM_LAP_COUNTER]);
32260 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
32261 goto unlock;
32262 @@ -2721,7 +2721,7 @@ static int cm_lap_handler(struct cm_work *work)
32263 cm_free_msg(msg);
32264 goto deref;
32265 case IB_CM_LAP_RCVD:
32266 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32267 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32268 counter[CM_LAP_COUNTER]);
32269 goto unlock;
32270 default:
32271 @@ -3005,7 +3005,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
32272 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
32273 if (cur_cm_id_priv) {
32274 spin_unlock_irq(&cm.lock);
32275 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
32276 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
32277 counter[CM_SIDR_REQ_COUNTER]);
32278 goto out; /* Duplicate message. */
32279 }
32280 @@ -3217,10 +3217,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
32281 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
32282 msg->retries = 1;
32283
32284 - atomic_long_add(1 + msg->retries,
32285 + atomic_long_add_unchecked(1 + msg->retries,
32286 &port->counter_group[CM_XMIT].counter[attr_index]);
32287 if (msg->retries)
32288 - atomic_long_add(msg->retries,
32289 + atomic_long_add_unchecked(msg->retries,
32290 &port->counter_group[CM_XMIT_RETRIES].
32291 counter[attr_index]);
32292
32293 @@ -3430,7 +3430,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
32294 }
32295
32296 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
32297 - atomic_long_inc(&port->counter_group[CM_RECV].
32298 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
32299 counter[attr_id - CM_ATTR_ID_OFFSET]);
32300
32301 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
32302 @@ -3635,7 +3635,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
32303 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
32304
32305 return sprintf(buf, "%ld\n",
32306 - atomic_long_read(&group->counter[cm_attr->index]));
32307 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
32308 }
32309
32310 static const struct sysfs_ops cm_counter_ops = {
32311 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
32312 index 176c8f9..2627b62 100644
32313 --- a/drivers/infiniband/core/fmr_pool.c
32314 +++ b/drivers/infiniband/core/fmr_pool.c
32315 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
32316
32317 struct task_struct *thread;
32318
32319 - atomic_t req_ser;
32320 - atomic_t flush_ser;
32321 + atomic_unchecked_t req_ser;
32322 + atomic_unchecked_t flush_ser;
32323
32324 wait_queue_head_t force_wait;
32325 };
32326 @@ -180,10 +180,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32327 struct ib_fmr_pool *pool = pool_ptr;
32328
32329 do {
32330 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
32331 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
32332 ib_fmr_batch_release(pool);
32333
32334 - atomic_inc(&pool->flush_ser);
32335 + atomic_inc_unchecked(&pool->flush_ser);
32336 wake_up_interruptible(&pool->force_wait);
32337
32338 if (pool->flush_function)
32339 @@ -191,7 +191,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
32340 }
32341
32342 set_current_state(TASK_INTERRUPTIBLE);
32343 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
32344 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
32345 !kthread_should_stop())
32346 schedule();
32347 __set_current_state(TASK_RUNNING);
32348 @@ -283,8 +283,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
32349 pool->dirty_watermark = params->dirty_watermark;
32350 pool->dirty_len = 0;
32351 spin_lock_init(&pool->pool_lock);
32352 - atomic_set(&pool->req_ser, 0);
32353 - atomic_set(&pool->flush_ser, 0);
32354 + atomic_set_unchecked(&pool->req_ser, 0);
32355 + atomic_set_unchecked(&pool->flush_ser, 0);
32356 init_waitqueue_head(&pool->force_wait);
32357
32358 pool->thread = kthread_run(ib_fmr_cleanup_thread,
32359 @@ -412,11 +412,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
32360 }
32361 spin_unlock_irq(&pool->pool_lock);
32362
32363 - serial = atomic_inc_return(&pool->req_ser);
32364 + serial = atomic_inc_return_unchecked(&pool->req_ser);
32365 wake_up_process(pool->thread);
32366
32367 if (wait_event_interruptible(pool->force_wait,
32368 - atomic_read(&pool->flush_ser) - serial >= 0))
32369 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
32370 return -EINTR;
32371
32372 return 0;
32373 @@ -526,7 +526,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
32374 } else {
32375 list_add_tail(&fmr->list, &pool->dirty_list);
32376 if (++pool->dirty_len >= pool->dirty_watermark) {
32377 - atomic_inc(&pool->req_ser);
32378 + atomic_inc_unchecked(&pool->req_ser);
32379 wake_up_process(pool->thread);
32380 }
32381 }
32382 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
32383 index 57e07c6..56d09d4 100644
32384 --- a/drivers/infiniband/hw/cxgb4/mem.c
32385 +++ b/drivers/infiniband/hw/cxgb4/mem.c
32386 @@ -122,7 +122,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32387 int err;
32388 struct fw_ri_tpte tpt;
32389 u32 stag_idx;
32390 - static atomic_t key;
32391 + static atomic_unchecked_t key;
32392
32393 if (c4iw_fatal_error(rdev))
32394 return -EIO;
32395 @@ -139,7 +139,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
32396 if (rdev->stats.stag.cur > rdev->stats.stag.max)
32397 rdev->stats.stag.max = rdev->stats.stag.cur;
32398 mutex_unlock(&rdev->stats.lock);
32399 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
32400 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
32401 }
32402 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
32403 __func__, stag_state, type, pdid, stag_idx);
32404 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
32405 index 79b3dbc..96e5fcc 100644
32406 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
32407 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
32408 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32409 struct ib_atomic_eth *ateth;
32410 struct ipath_ack_entry *e;
32411 u64 vaddr;
32412 - atomic64_t *maddr;
32413 + atomic64_unchecked_t *maddr;
32414 u64 sdata;
32415 u32 rkey;
32416 u8 next;
32417 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
32418 IB_ACCESS_REMOTE_ATOMIC)))
32419 goto nack_acc_unlck;
32420 /* Perform atomic OP and save result. */
32421 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32422 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32423 sdata = be64_to_cpu(ateth->swap_data);
32424 e = &qp->s_ack_queue[qp->r_head_ack_queue];
32425 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
32426 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32427 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32428 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32429 be64_to_cpu(ateth->compare_data),
32430 sdata);
32431 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
32432 index 1f95bba..9530f87 100644
32433 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
32434 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
32435 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
32436 unsigned long flags;
32437 struct ib_wc wc;
32438 u64 sdata;
32439 - atomic64_t *maddr;
32440 + atomic64_unchecked_t *maddr;
32441 enum ib_wc_status send_status;
32442
32443 /*
32444 @@ -382,11 +382,11 @@ again:
32445 IB_ACCESS_REMOTE_ATOMIC)))
32446 goto acc_err;
32447 /* Perform atomic OP and save result. */
32448 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
32449 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
32450 sdata = wqe->wr.wr.atomic.compare_add;
32451 *(u64 *) sqp->s_sge.sge.vaddr =
32452 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
32453 - (u64) atomic64_add_return(sdata, maddr) - sdata :
32454 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
32455 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
32456 sdata, wqe->wr.wr.atomic.swap);
32457 goto send_comp;
32458 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
32459 index 7140199..da60063 100644
32460 --- a/drivers/infiniband/hw/nes/nes.c
32461 +++ b/drivers/infiniband/hw/nes/nes.c
32462 @@ -103,7 +103,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
32463 LIST_HEAD(nes_adapter_list);
32464 static LIST_HEAD(nes_dev_list);
32465
32466 -atomic_t qps_destroyed;
32467 +atomic_unchecked_t qps_destroyed;
32468
32469 static unsigned int ee_flsh_adapter;
32470 static unsigned int sysfs_nonidx_addr;
32471 @@ -272,7 +272,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
32472 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
32473 struct nes_adapter *nesadapter = nesdev->nesadapter;
32474
32475 - atomic_inc(&qps_destroyed);
32476 + atomic_inc_unchecked(&qps_destroyed);
32477
32478 /* Free the control structures */
32479
32480 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
32481 index c438e46..ca30356 100644
32482 --- a/drivers/infiniband/hw/nes/nes.h
32483 +++ b/drivers/infiniband/hw/nes/nes.h
32484 @@ -178,17 +178,17 @@ extern unsigned int nes_debug_level;
32485 extern unsigned int wqm_quanta;
32486 extern struct list_head nes_adapter_list;
32487
32488 -extern atomic_t cm_connects;
32489 -extern atomic_t cm_accepts;
32490 -extern atomic_t cm_disconnects;
32491 -extern atomic_t cm_closes;
32492 -extern atomic_t cm_connecteds;
32493 -extern atomic_t cm_connect_reqs;
32494 -extern atomic_t cm_rejects;
32495 -extern atomic_t mod_qp_timouts;
32496 -extern atomic_t qps_created;
32497 -extern atomic_t qps_destroyed;
32498 -extern atomic_t sw_qps_destroyed;
32499 +extern atomic_unchecked_t cm_connects;
32500 +extern atomic_unchecked_t cm_accepts;
32501 +extern atomic_unchecked_t cm_disconnects;
32502 +extern atomic_unchecked_t cm_closes;
32503 +extern atomic_unchecked_t cm_connecteds;
32504 +extern atomic_unchecked_t cm_connect_reqs;
32505 +extern atomic_unchecked_t cm_rejects;
32506 +extern atomic_unchecked_t mod_qp_timouts;
32507 +extern atomic_unchecked_t qps_created;
32508 +extern atomic_unchecked_t qps_destroyed;
32509 +extern atomic_unchecked_t sw_qps_destroyed;
32510 extern u32 mh_detected;
32511 extern u32 mh_pauses_sent;
32512 extern u32 cm_packets_sent;
32513 @@ -197,16 +197,16 @@ extern u32 cm_packets_created;
32514 extern u32 cm_packets_received;
32515 extern u32 cm_packets_dropped;
32516 extern u32 cm_packets_retrans;
32517 -extern atomic_t cm_listens_created;
32518 -extern atomic_t cm_listens_destroyed;
32519 +extern atomic_unchecked_t cm_listens_created;
32520 +extern atomic_unchecked_t cm_listens_destroyed;
32521 extern u32 cm_backlog_drops;
32522 -extern atomic_t cm_loopbacks;
32523 -extern atomic_t cm_nodes_created;
32524 -extern atomic_t cm_nodes_destroyed;
32525 -extern atomic_t cm_accel_dropped_pkts;
32526 -extern atomic_t cm_resets_recvd;
32527 -extern atomic_t pau_qps_created;
32528 -extern atomic_t pau_qps_destroyed;
32529 +extern atomic_unchecked_t cm_loopbacks;
32530 +extern atomic_unchecked_t cm_nodes_created;
32531 +extern atomic_unchecked_t cm_nodes_destroyed;
32532 +extern atomic_unchecked_t cm_accel_dropped_pkts;
32533 +extern atomic_unchecked_t cm_resets_recvd;
32534 +extern atomic_unchecked_t pau_qps_created;
32535 +extern atomic_unchecked_t pau_qps_destroyed;
32536
32537 extern u32 int_mod_timer_init;
32538 extern u32 int_mod_cq_depth_256;
32539 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
32540 index 020e95c..fbb3450 100644
32541 --- a/drivers/infiniband/hw/nes/nes_cm.c
32542 +++ b/drivers/infiniband/hw/nes/nes_cm.c
32543 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
32544 u32 cm_packets_retrans;
32545 u32 cm_packets_created;
32546 u32 cm_packets_received;
32547 -atomic_t cm_listens_created;
32548 -atomic_t cm_listens_destroyed;
32549 +atomic_unchecked_t cm_listens_created;
32550 +atomic_unchecked_t cm_listens_destroyed;
32551 u32 cm_backlog_drops;
32552 -atomic_t cm_loopbacks;
32553 -atomic_t cm_nodes_created;
32554 -atomic_t cm_nodes_destroyed;
32555 -atomic_t cm_accel_dropped_pkts;
32556 -atomic_t cm_resets_recvd;
32557 +atomic_unchecked_t cm_loopbacks;
32558 +atomic_unchecked_t cm_nodes_created;
32559 +atomic_unchecked_t cm_nodes_destroyed;
32560 +atomic_unchecked_t cm_accel_dropped_pkts;
32561 +atomic_unchecked_t cm_resets_recvd;
32562
32563 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
32564 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
32565 @@ -148,13 +148,13 @@ static struct nes_cm_ops nes_cm_api = {
32566
32567 static struct nes_cm_core *g_cm_core;
32568
32569 -atomic_t cm_connects;
32570 -atomic_t cm_accepts;
32571 -atomic_t cm_disconnects;
32572 -atomic_t cm_closes;
32573 -atomic_t cm_connecteds;
32574 -atomic_t cm_connect_reqs;
32575 -atomic_t cm_rejects;
32576 +atomic_unchecked_t cm_connects;
32577 +atomic_unchecked_t cm_accepts;
32578 +atomic_unchecked_t cm_disconnects;
32579 +atomic_unchecked_t cm_closes;
32580 +atomic_unchecked_t cm_connecteds;
32581 +atomic_unchecked_t cm_connect_reqs;
32582 +atomic_unchecked_t cm_rejects;
32583
32584 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
32585 {
32586 @@ -1279,7 +1279,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
32587 kfree(listener);
32588 listener = NULL;
32589 ret = 0;
32590 - atomic_inc(&cm_listens_destroyed);
32591 + atomic_inc_unchecked(&cm_listens_destroyed);
32592 } else {
32593 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
32594 }
32595 @@ -1482,7 +1482,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
32596 cm_node->rem_mac);
32597
32598 add_hte_node(cm_core, cm_node);
32599 - atomic_inc(&cm_nodes_created);
32600 + atomic_inc_unchecked(&cm_nodes_created);
32601
32602 return cm_node;
32603 }
32604 @@ -1540,7 +1540,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
32605 }
32606
32607 atomic_dec(&cm_core->node_cnt);
32608 - atomic_inc(&cm_nodes_destroyed);
32609 + atomic_inc_unchecked(&cm_nodes_destroyed);
32610 nesqp = cm_node->nesqp;
32611 if (nesqp) {
32612 nesqp->cm_node = NULL;
32613 @@ -1604,7 +1604,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
32614
32615 static void drop_packet(struct sk_buff *skb)
32616 {
32617 - atomic_inc(&cm_accel_dropped_pkts);
32618 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32619 dev_kfree_skb_any(skb);
32620 }
32621
32622 @@ -1667,7 +1667,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
32623 {
32624
32625 int reset = 0; /* whether to send reset in case of err.. */
32626 - atomic_inc(&cm_resets_recvd);
32627 + atomic_inc_unchecked(&cm_resets_recvd);
32628 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
32629 " refcnt=%d\n", cm_node, cm_node->state,
32630 atomic_read(&cm_node->ref_count));
32631 @@ -2308,7 +2308,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
32632 rem_ref_cm_node(cm_node->cm_core, cm_node);
32633 return NULL;
32634 }
32635 - atomic_inc(&cm_loopbacks);
32636 + atomic_inc_unchecked(&cm_loopbacks);
32637 loopbackremotenode->loopbackpartner = cm_node;
32638 loopbackremotenode->tcp_cntxt.rcv_wscale =
32639 NES_CM_DEFAULT_RCV_WND_SCALE;
32640 @@ -2583,7 +2583,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
32641 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
32642 else {
32643 rem_ref_cm_node(cm_core, cm_node);
32644 - atomic_inc(&cm_accel_dropped_pkts);
32645 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
32646 dev_kfree_skb_any(skb);
32647 }
32648 break;
32649 @@ -2891,7 +2891,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32650
32651 if ((cm_id) && (cm_id->event_handler)) {
32652 if (issue_disconn) {
32653 - atomic_inc(&cm_disconnects);
32654 + atomic_inc_unchecked(&cm_disconnects);
32655 cm_event.event = IW_CM_EVENT_DISCONNECT;
32656 cm_event.status = disconn_status;
32657 cm_event.local_addr = cm_id->local_addr;
32658 @@ -2913,7 +2913,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
32659 }
32660
32661 if (issue_close) {
32662 - atomic_inc(&cm_closes);
32663 + atomic_inc_unchecked(&cm_closes);
32664 nes_disconnect(nesqp, 1);
32665
32666 cm_id->provider_data = nesqp;
32667 @@ -3049,7 +3049,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32668
32669 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
32670 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
32671 - atomic_inc(&cm_accepts);
32672 + atomic_inc_unchecked(&cm_accepts);
32673
32674 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
32675 netdev_refcnt_read(nesvnic->netdev));
32676 @@ -3251,7 +3251,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
32677 struct nes_cm_core *cm_core;
32678 u8 *start_buff;
32679
32680 - atomic_inc(&cm_rejects);
32681 + atomic_inc_unchecked(&cm_rejects);
32682 cm_node = (struct nes_cm_node *)cm_id->provider_data;
32683 loopback = cm_node->loopbackpartner;
32684 cm_core = cm_node->cm_core;
32685 @@ -3311,7 +3311,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
32686 ntohl(cm_id->local_addr.sin_addr.s_addr),
32687 ntohs(cm_id->local_addr.sin_port));
32688
32689 - atomic_inc(&cm_connects);
32690 + atomic_inc_unchecked(&cm_connects);
32691 nesqp->active_conn = 1;
32692
32693 /* cache the cm_id in the qp */
32694 @@ -3421,7 +3421,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
32695 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
32696 return err;
32697 }
32698 - atomic_inc(&cm_listens_created);
32699 + atomic_inc_unchecked(&cm_listens_created);
32700 }
32701
32702 cm_id->add_ref(cm_id);
32703 @@ -3522,7 +3522,7 @@ static void cm_event_connected(struct nes_cm_event *event)
32704
32705 if (nesqp->destroyed)
32706 return;
32707 - atomic_inc(&cm_connecteds);
32708 + atomic_inc_unchecked(&cm_connecteds);
32709 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
32710 " local port 0x%04X. jiffies = %lu.\n",
32711 nesqp->hwqp.qp_id,
32712 @@ -3709,7 +3709,7 @@ static void cm_event_reset(struct nes_cm_event *event)
32713
32714 cm_id->add_ref(cm_id);
32715 ret = cm_id->event_handler(cm_id, &cm_event);
32716 - atomic_inc(&cm_closes);
32717 + atomic_inc_unchecked(&cm_closes);
32718 cm_event.event = IW_CM_EVENT_CLOSE;
32719 cm_event.status = 0;
32720 cm_event.provider_data = cm_id->provider_data;
32721 @@ -3745,7 +3745,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
32722 return;
32723 cm_id = cm_node->cm_id;
32724
32725 - atomic_inc(&cm_connect_reqs);
32726 + atomic_inc_unchecked(&cm_connect_reqs);
32727 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32728 cm_node, cm_id, jiffies);
32729
32730 @@ -3785,7 +3785,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
32731 return;
32732 cm_id = cm_node->cm_id;
32733
32734 - atomic_inc(&cm_connect_reqs);
32735 + atomic_inc_unchecked(&cm_connect_reqs);
32736 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
32737 cm_node, cm_id, jiffies);
32738
32739 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
32740 index 3ba7be3..c81f6ff 100644
32741 --- a/drivers/infiniband/hw/nes/nes_mgt.c
32742 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
32743 @@ -40,8 +40,8 @@
32744 #include "nes.h"
32745 #include "nes_mgt.h"
32746
32747 -atomic_t pau_qps_created;
32748 -atomic_t pau_qps_destroyed;
32749 +atomic_unchecked_t pau_qps_created;
32750 +atomic_unchecked_t pau_qps_destroyed;
32751
32752 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
32753 {
32754 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
32755 {
32756 struct sk_buff *skb;
32757 unsigned long flags;
32758 - atomic_inc(&pau_qps_destroyed);
32759 + atomic_inc_unchecked(&pau_qps_destroyed);
32760
32761 /* Free packets that have not yet been forwarded */
32762 /* Lock is acquired by skb_dequeue when removing the skb */
32763 @@ -812,7 +812,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
32764 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
32765 skb_queue_head_init(&nesqp->pau_list);
32766 spin_lock_init(&nesqp->pau_lock);
32767 - atomic_inc(&pau_qps_created);
32768 + atomic_inc_unchecked(&pau_qps_created);
32769 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
32770 }
32771
32772 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
32773 index f3a3ecf..57d311d 100644
32774 --- a/drivers/infiniband/hw/nes/nes_nic.c
32775 +++ b/drivers/infiniband/hw/nes/nes_nic.c
32776 @@ -1277,39 +1277,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
32777 target_stat_values[++index] = mh_detected;
32778 target_stat_values[++index] = mh_pauses_sent;
32779 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
32780 - target_stat_values[++index] = atomic_read(&cm_connects);
32781 - target_stat_values[++index] = atomic_read(&cm_accepts);
32782 - target_stat_values[++index] = atomic_read(&cm_disconnects);
32783 - target_stat_values[++index] = atomic_read(&cm_connecteds);
32784 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
32785 - target_stat_values[++index] = atomic_read(&cm_rejects);
32786 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
32787 - target_stat_values[++index] = atomic_read(&qps_created);
32788 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
32789 - target_stat_values[++index] = atomic_read(&qps_destroyed);
32790 - target_stat_values[++index] = atomic_read(&cm_closes);
32791 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
32792 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
32793 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
32794 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
32795 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
32796 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
32797 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
32798 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
32799 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
32800 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
32801 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
32802 target_stat_values[++index] = cm_packets_sent;
32803 target_stat_values[++index] = cm_packets_bounced;
32804 target_stat_values[++index] = cm_packets_created;
32805 target_stat_values[++index] = cm_packets_received;
32806 target_stat_values[++index] = cm_packets_dropped;
32807 target_stat_values[++index] = cm_packets_retrans;
32808 - target_stat_values[++index] = atomic_read(&cm_listens_created);
32809 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
32810 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
32811 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
32812 target_stat_values[++index] = cm_backlog_drops;
32813 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
32814 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
32815 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
32816 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
32817 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
32818 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
32819 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
32820 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
32821 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
32822 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
32823 target_stat_values[++index] = nesadapter->free_4kpbl;
32824 target_stat_values[++index] = nesadapter->free_256pbl;
32825 target_stat_values[++index] = int_mod_timer_init;
32826 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
32827 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
32828 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
32829 - target_stat_values[++index] = atomic_read(&pau_qps_created);
32830 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
32831 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
32832 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
32833 }
32834
32835 /**
32836 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
32837 index 8b8812d..a5e1133 100644
32838 --- a/drivers/infiniband/hw/nes/nes_verbs.c
32839 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
32840 @@ -46,9 +46,9 @@
32841
32842 #include <rdma/ib_umem.h>
32843
32844 -atomic_t mod_qp_timouts;
32845 -atomic_t qps_created;
32846 -atomic_t sw_qps_destroyed;
32847 +atomic_unchecked_t mod_qp_timouts;
32848 +atomic_unchecked_t qps_created;
32849 +atomic_unchecked_t sw_qps_destroyed;
32850
32851 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
32852
32853 @@ -1131,7 +1131,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
32854 if (init_attr->create_flags)
32855 return ERR_PTR(-EINVAL);
32856
32857 - atomic_inc(&qps_created);
32858 + atomic_inc_unchecked(&qps_created);
32859 switch (init_attr->qp_type) {
32860 case IB_QPT_RC:
32861 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
32862 @@ -1460,7 +1460,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
32863 struct iw_cm_event cm_event;
32864 int ret = 0;
32865
32866 - atomic_inc(&sw_qps_destroyed);
32867 + atomic_inc_unchecked(&sw_qps_destroyed);
32868 nesqp->destroyed = 1;
32869
32870 /* Blow away the connection if it exists. */
32871 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
32872 index 7e62f41..4c2b8e2 100644
32873 --- a/drivers/infiniband/hw/qib/qib.h
32874 +++ b/drivers/infiniband/hw/qib/qib.h
32875 @@ -51,6 +51,7 @@
32876 #include <linux/completion.h>
32877 #include <linux/kref.h>
32878 #include <linux/sched.h>
32879 +#include <linux/slab.h>
32880
32881 #include "qib_common.h"
32882 #include "qib_verbs.h"
32883 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
32884 index da739d9..da1c7f4 100644
32885 --- a/drivers/input/gameport/gameport.c
32886 +++ b/drivers/input/gameport/gameport.c
32887 @@ -487,14 +487,14 @@ EXPORT_SYMBOL(gameport_set_phys);
32888 */
32889 static void gameport_init_port(struct gameport *gameport)
32890 {
32891 - static atomic_t gameport_no = ATOMIC_INIT(0);
32892 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
32893
32894 __module_get(THIS_MODULE);
32895
32896 mutex_init(&gameport->drv_mutex);
32897 device_initialize(&gameport->dev);
32898 dev_set_name(&gameport->dev, "gameport%lu",
32899 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
32900 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
32901 gameport->dev.bus = &gameport_bus;
32902 gameport->dev.release = gameport_release_port;
32903 if (gameport->parent)
32904 diff --git a/drivers/input/input.c b/drivers/input/input.c
32905 index 8921c61..f5cd63d 100644
32906 --- a/drivers/input/input.c
32907 +++ b/drivers/input/input.c
32908 @@ -1814,7 +1814,7 @@ static void input_cleanse_bitmasks(struct input_dev *dev)
32909 */
32910 int input_register_device(struct input_dev *dev)
32911 {
32912 - static atomic_t input_no = ATOMIC_INIT(0);
32913 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
32914 struct input_handler *handler;
32915 const char *path;
32916 int error;
32917 @@ -1851,7 +1851,7 @@ int input_register_device(struct input_dev *dev)
32918 dev->setkeycode = input_default_setkeycode;
32919
32920 dev_set_name(&dev->dev, "input%ld",
32921 - (unsigned long) atomic_inc_return(&input_no) - 1);
32922 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
32923
32924 error = device_add(&dev->dev);
32925 if (error)
32926 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
32927 index 04c69af..5f92d00 100644
32928 --- a/drivers/input/joystick/sidewinder.c
32929 +++ b/drivers/input/joystick/sidewinder.c
32930 @@ -30,6 +30,7 @@
32931 #include <linux/kernel.h>
32932 #include <linux/module.h>
32933 #include <linux/slab.h>
32934 +#include <linux/sched.h>
32935 #include <linux/init.h>
32936 #include <linux/input.h>
32937 #include <linux/gameport.h>
32938 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
32939 index 83811e4..0822b90 100644
32940 --- a/drivers/input/joystick/xpad.c
32941 +++ b/drivers/input/joystick/xpad.c
32942 @@ -726,7 +726,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
32943
32944 static int xpad_led_probe(struct usb_xpad *xpad)
32945 {
32946 - static atomic_t led_seq = ATOMIC_INIT(0);
32947 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
32948 long led_no;
32949 struct xpad_led *led;
32950 struct led_classdev *led_cdev;
32951 @@ -739,7 +739,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
32952 if (!led)
32953 return -ENOMEM;
32954
32955 - led_no = (long)atomic_inc_return(&led_seq) - 1;
32956 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
32957
32958 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
32959 led->xpad = xpad;
32960 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
32961 index 0110b5a..d3ad144 100644
32962 --- a/drivers/input/mousedev.c
32963 +++ b/drivers/input/mousedev.c
32964 @@ -763,7 +763,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
32965
32966 spin_unlock_irq(&client->packet_lock);
32967
32968 - if (copy_to_user(buffer, data, count))
32969 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
32970 return -EFAULT;
32971
32972 return count;
32973 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
32974 index d0f7533..fb8215b 100644
32975 --- a/drivers/input/serio/serio.c
32976 +++ b/drivers/input/serio/serio.c
32977 @@ -496,7 +496,7 @@ static void serio_release_port(struct device *dev)
32978 */
32979 static void serio_init_port(struct serio *serio)
32980 {
32981 - static atomic_t serio_no = ATOMIC_INIT(0);
32982 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
32983
32984 __module_get(THIS_MODULE);
32985
32986 @@ -507,7 +507,7 @@ static void serio_init_port(struct serio *serio)
32987 mutex_init(&serio->drv_mutex);
32988 device_initialize(&serio->dev);
32989 dev_set_name(&serio->dev, "serio%ld",
32990 - (long)atomic_inc_return(&serio_no) - 1);
32991 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
32992 serio->dev.bus = &serio_bus;
32993 serio->dev.release = serio_release_port;
32994 serio->dev.groups = serio_device_attr_groups;
32995 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
32996 index 38c4bd8..58965d9 100644
32997 --- a/drivers/isdn/capi/capi.c
32998 +++ b/drivers/isdn/capi/capi.c
32999 @@ -83,8 +83,8 @@ struct capiminor {
33000
33001 struct capi20_appl *ap;
33002 u32 ncci;
33003 - atomic_t datahandle;
33004 - atomic_t msgid;
33005 + atomic_unchecked_t datahandle;
33006 + atomic_unchecked_t msgid;
33007
33008 struct tty_port port;
33009 int ttyinstop;
33010 @@ -392,7 +392,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
33011 capimsg_setu16(s, 2, mp->ap->applid);
33012 capimsg_setu8 (s, 4, CAPI_DATA_B3);
33013 capimsg_setu8 (s, 5, CAPI_RESP);
33014 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
33015 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
33016 capimsg_setu32(s, 8, mp->ncci);
33017 capimsg_setu16(s, 12, datahandle);
33018 }
33019 @@ -513,14 +513,14 @@ static void handle_minor_send(struct capiminor *mp)
33020 mp->outbytes -= len;
33021 spin_unlock_bh(&mp->outlock);
33022
33023 - datahandle = atomic_inc_return(&mp->datahandle);
33024 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
33025 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
33026 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33027 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
33028 capimsg_setu16(skb->data, 2, mp->ap->applid);
33029 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
33030 capimsg_setu8 (skb->data, 5, CAPI_REQ);
33031 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
33032 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
33033 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
33034 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
33035 capimsg_setu16(skb->data, 16, len); /* Data length */
33036 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
33037 index a6d9fd2..afdb8a3 100644
33038 --- a/drivers/isdn/gigaset/interface.c
33039 +++ b/drivers/isdn/gigaset/interface.c
33040 @@ -160,9 +160,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
33041 }
33042 tty->driver_data = cs;
33043
33044 - ++cs->port.count;
33045 + atomic_inc(&cs->port.count);
33046
33047 - if (cs->port.count == 1) {
33048 + if (atomic_read(&cs->port.count) == 1) {
33049 tty_port_tty_set(&cs->port, tty);
33050 tty->low_latency = 1;
33051 }
33052 @@ -186,9 +186,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
33053
33054 if (!cs->connected)
33055 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
33056 - else if (!cs->port.count)
33057 + else if (!atomic_read(&cs->port.count))
33058 dev_warn(cs->dev, "%s: device not opened\n", __func__);
33059 - else if (!--cs->port.count)
33060 + else if (!atomic_dec_return(&cs->port.count))
33061 tty_port_tty_set(&cs->port, NULL);
33062
33063 mutex_unlock(&cs->mutex);
33064 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
33065 index 821f7ac..28d4030 100644
33066 --- a/drivers/isdn/hardware/avm/b1.c
33067 +++ b/drivers/isdn/hardware/avm/b1.c
33068 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
33069 }
33070 if (left) {
33071 if (t4file->user) {
33072 - if (copy_from_user(buf, dp, left))
33073 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33074 return -EFAULT;
33075 } else {
33076 memcpy(buf, dp, left);
33077 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
33078 }
33079 if (left) {
33080 if (config->user) {
33081 - if (copy_from_user(buf, dp, left))
33082 + if (left > sizeof buf || copy_from_user(buf, dp, left))
33083 return -EFAULT;
33084 } else {
33085 memcpy(buf, dp, left);
33086 diff --git a/drivers/isdn/hardware/eicon/divasync.h b/drivers/isdn/hardware/eicon/divasync.h
33087 index dd6b53a..19d9ee6 100644
33088 --- a/drivers/isdn/hardware/eicon/divasync.h
33089 +++ b/drivers/isdn/hardware/eicon/divasync.h
33090 @@ -146,7 +146,7 @@ typedef struct _diva_didd_add_adapter {
33091 } diva_didd_add_adapter_t;
33092 typedef struct _diva_didd_remove_adapter {
33093 IDI_CALL p_request;
33094 -} diva_didd_remove_adapter_t;
33095 +} __no_const diva_didd_remove_adapter_t;
33096 typedef struct _diva_didd_read_adapter_array {
33097 void *buffer;
33098 dword length;
33099 diff --git a/drivers/isdn/hardware/eicon/xdi_adapter.h b/drivers/isdn/hardware/eicon/xdi_adapter.h
33100 index d303e65..28bcb7b 100644
33101 --- a/drivers/isdn/hardware/eicon/xdi_adapter.h
33102 +++ b/drivers/isdn/hardware/eicon/xdi_adapter.h
33103 @@ -44,7 +44,7 @@ typedef struct _xdi_mbox_t {
33104 typedef struct _diva_os_idi_adapter_interface {
33105 diva_init_card_proc_t cleanup_adapter_proc;
33106 diva_cmd_card_proc_t cmd_proc;
33107 -} diva_os_idi_adapter_interface_t;
33108 +} __no_const diva_os_idi_adapter_interface_t;
33109
33110 typedef struct _diva_os_xdi_adapter {
33111 struct list_head link;
33112 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
33113 index 7bc5067..fd36232 100644
33114 --- a/drivers/isdn/i4l/isdn_tty.c
33115 +++ b/drivers/isdn/i4l/isdn_tty.c
33116 @@ -1505,9 +1505,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
33117 port = &info->port;
33118 #ifdef ISDN_DEBUG_MODEM_OPEN
33119 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
33120 - port->count);
33121 + atomic_read(&port->count))
33122 #endif
33123 - port->count++;
33124 + atomic_inc(&port->count);
33125 tty->driver_data = info;
33126 port->tty = tty;
33127 tty->port = port;
33128 @@ -1553,7 +1553,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33129 #endif
33130 return;
33131 }
33132 - if ((tty->count == 1) && (port->count != 1)) {
33133 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
33134 /*
33135 * Uh, oh. tty->count is 1, which means that the tty
33136 * structure will be freed. Info->count should always
33137 @@ -1562,15 +1562,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
33138 * serial port won't be shutdown.
33139 */
33140 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
33141 - "info->count is %d\n", port->count);
33142 - port->count = 1;
33143 + "info->count is %d\n", atomic_read(&port->count));
33144 + atomic_set(&port->count, 1);
33145 }
33146 - if (--port->count < 0) {
33147 + if (atomic_dec_return(&port->count) < 0) {
33148 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
33149 - info->line, port->count);
33150 - port->count = 0;
33151 + info->line, atomic_read(&port->count));
33152 + atomic_set(&port->count, 0);
33153 }
33154 - if (port->count) {
33155 + if (atomic_read(&port->count)) {
33156 #ifdef ISDN_DEBUG_MODEM_OPEN
33157 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
33158 #endif
33159 @@ -1624,7 +1624,7 @@ isdn_tty_hangup(struct tty_struct *tty)
33160 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
33161 return;
33162 isdn_tty_shutdown(info);
33163 - port->count = 0;
33164 + atomic_set(&port->count, 0);
33165 port->flags &= ~ASYNC_NORMAL_ACTIVE;
33166 port->tty = NULL;
33167 wake_up_interruptible(&port->open_wait);
33168 @@ -1964,7 +1964,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
33169 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
33170 modem_info *info = &dev->mdm.info[i];
33171
33172 - if (info->port.count == 0)
33173 + if (atomic_read(&info->port.count) == 0)
33174 continue;
33175 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
33176 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
33177 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
33178 index e74df7c..03a03ba 100644
33179 --- a/drivers/isdn/icn/icn.c
33180 +++ b/drivers/isdn/icn/icn.c
33181 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
33182 if (count > len)
33183 count = len;
33184 if (user) {
33185 - if (copy_from_user(msg, buf, count))
33186 + if (count > sizeof msg || copy_from_user(msg, buf, count))
33187 return -EFAULT;
33188 } else
33189 memcpy(msg, buf, count);
33190 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
33191 index b5fdcb7..5b6c59f 100644
33192 --- a/drivers/lguest/core.c
33193 +++ b/drivers/lguest/core.c
33194 @@ -92,9 +92,17 @@ static __init int map_switcher(void)
33195 * it's worked so far. The end address needs +1 because __get_vm_area
33196 * allocates an extra guard page, so we need space for that.
33197 */
33198 +
33199 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
33200 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33201 + VM_ALLOC | VM_KERNEXEC, SWITCHER_ADDR, SWITCHER_ADDR
33202 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33203 +#else
33204 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
33205 VM_ALLOC, SWITCHER_ADDR, SWITCHER_ADDR
33206 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
33207 +#endif
33208 +
33209 if (!switcher_vma) {
33210 err = -ENOMEM;
33211 printk("lguest: could not map switcher pages high\n");
33212 @@ -119,7 +127,7 @@ static __init int map_switcher(void)
33213 * Now the Switcher is mapped at the right address, we can't fail!
33214 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
33215 */
33216 - memcpy(switcher_vma->addr, start_switcher_text,
33217 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
33218 end_switcher_text - start_switcher_text);
33219
33220 printk(KERN_INFO "lguest: mapped switcher at %p\n",
33221 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
33222 index 39809035..ce25c5e 100644
33223 --- a/drivers/lguest/x86/core.c
33224 +++ b/drivers/lguest/x86/core.c
33225 @@ -59,7 +59,7 @@ static struct {
33226 /* Offset from where switcher.S was compiled to where we've copied it */
33227 static unsigned long switcher_offset(void)
33228 {
33229 - return SWITCHER_ADDR - (unsigned long)start_switcher_text;
33230 + return SWITCHER_ADDR - (unsigned long)ktla_ktva(start_switcher_text);
33231 }
33232
33233 /* This cpu's struct lguest_pages. */
33234 @@ -100,7 +100,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
33235 * These copies are pretty cheap, so we do them unconditionally: */
33236 /* Save the current Host top-level page directory.
33237 */
33238 +
33239 +#ifdef CONFIG_PAX_PER_CPU_PGD
33240 + pages->state.host_cr3 = read_cr3();
33241 +#else
33242 pages->state.host_cr3 = __pa(current->mm->pgd);
33243 +#endif
33244 +
33245 /*
33246 * Set up the Guest's page tables to see this CPU's pages (and no
33247 * other CPU's pages).
33248 @@ -472,7 +478,7 @@ void __init lguest_arch_host_init(void)
33249 * compiled-in switcher code and the high-mapped copy we just made.
33250 */
33251 for (i = 0; i < IDT_ENTRIES; i++)
33252 - default_idt_entries[i] += switcher_offset();
33253 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
33254
33255 /*
33256 * Set up the Switcher's per-cpu areas.
33257 @@ -555,7 +561,7 @@ void __init lguest_arch_host_init(void)
33258 * it will be undisturbed when we switch. To change %cs and jump we
33259 * need this structure to feed to Intel's "lcall" instruction.
33260 */
33261 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
33262 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
33263 lguest_entry.segment = LGUEST_CS;
33264
33265 /*
33266 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
33267 index 40634b0..4f5855e 100644
33268 --- a/drivers/lguest/x86/switcher_32.S
33269 +++ b/drivers/lguest/x86/switcher_32.S
33270 @@ -87,6 +87,7 @@
33271 #include <asm/page.h>
33272 #include <asm/segment.h>
33273 #include <asm/lguest.h>
33274 +#include <asm/processor-flags.h>
33275
33276 // We mark the start of the code to copy
33277 // It's placed in .text tho it's never run here
33278 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
33279 // Changes type when we load it: damn Intel!
33280 // For after we switch over our page tables
33281 // That entry will be read-only: we'd crash.
33282 +
33283 +#ifdef CONFIG_PAX_KERNEXEC
33284 + mov %cr0, %edx
33285 + xor $X86_CR0_WP, %edx
33286 + mov %edx, %cr0
33287 +#endif
33288 +
33289 movl $(GDT_ENTRY_TSS*8), %edx
33290 ltr %dx
33291
33292 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
33293 // Let's clear it again for our return.
33294 // The GDT descriptor of the Host
33295 // Points to the table after two "size" bytes
33296 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
33297 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
33298 // Clear "used" from type field (byte 5, bit 2)
33299 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
33300 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
33301 +
33302 +#ifdef CONFIG_PAX_KERNEXEC
33303 + mov %cr0, %eax
33304 + xor $X86_CR0_WP, %eax
33305 + mov %eax, %cr0
33306 +#endif
33307
33308 // Once our page table's switched, the Guest is live!
33309 // The Host fades as we run this final step.
33310 @@ -295,13 +309,12 @@ deliver_to_host:
33311 // I consulted gcc, and it gave
33312 // These instructions, which I gladly credit:
33313 leal (%edx,%ebx,8), %eax
33314 - movzwl (%eax),%edx
33315 - movl 4(%eax), %eax
33316 - xorw %ax, %ax
33317 - orl %eax, %edx
33318 + movl 4(%eax), %edx
33319 + movw (%eax), %dx
33320 // Now the address of the handler's in %edx
33321 // We call it now: its "iret" drops us home.
33322 - jmp *%edx
33323 + ljmp $__KERNEL_CS, $1f
33324 +1: jmp *%edx
33325
33326 // Every interrupt can come to us here
33327 // But we must truly tell each apart.
33328 diff --git a/drivers/macintosh/macio_asic.c b/drivers/macintosh/macio_asic.c
33329 index 20e5c2c..9e849a9 100644
33330 --- a/drivers/macintosh/macio_asic.c
33331 +++ b/drivers/macintosh/macio_asic.c
33332 @@ -748,7 +748,7 @@ static void __devexit macio_pci_remove(struct pci_dev* pdev)
33333 * MacIO is matched against any Apple ID, it's probe() function
33334 * will then decide wether it applies or not
33335 */
33336 -static const struct pci_device_id __devinitdata pci_ids [] = { {
33337 +static const struct pci_device_id __devinitconst pci_ids [] = { {
33338 .vendor = PCI_VENDOR_ID_APPLE,
33339 .device = PCI_ANY_ID,
33340 .subvendor = PCI_ANY_ID,
33341 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
33342 index 15dbe03..743fc65 100644
33343 --- a/drivers/md/bitmap.c
33344 +++ b/drivers/md/bitmap.c
33345 @@ -1786,7 +1786,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
33346 chunk_kb ? "KB" : "B");
33347 if (bitmap->storage.file) {
33348 seq_printf(seq, ", file: ");
33349 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
33350 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
33351 }
33352
33353 seq_printf(seq, "\n");
33354 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
33355 index a1a3e6d..1918bfc 100644
33356 --- a/drivers/md/dm-ioctl.c
33357 +++ b/drivers/md/dm-ioctl.c
33358 @@ -1590,7 +1590,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
33359 cmd == DM_LIST_VERSIONS_CMD)
33360 return 0;
33361
33362 - if ((cmd == DM_DEV_CREATE_CMD)) {
33363 + if (cmd == DM_DEV_CREATE_CMD) {
33364 if (!*param->name) {
33365 DMWARN("name not supplied when creating device");
33366 return -EINVAL;
33367 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
33368 index b58b7a3..8018b19 100644
33369 --- a/drivers/md/dm-raid1.c
33370 +++ b/drivers/md/dm-raid1.c
33371 @@ -40,7 +40,7 @@ enum dm_raid1_error {
33372
33373 struct mirror {
33374 struct mirror_set *ms;
33375 - atomic_t error_count;
33376 + atomic_unchecked_t error_count;
33377 unsigned long error_type;
33378 struct dm_dev *dev;
33379 sector_t offset;
33380 @@ -185,7 +185,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
33381 struct mirror *m;
33382
33383 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
33384 - if (!atomic_read(&m->error_count))
33385 + if (!atomic_read_unchecked(&m->error_count))
33386 return m;
33387
33388 return NULL;
33389 @@ -217,7 +217,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
33390 * simple way to tell if a device has encountered
33391 * errors.
33392 */
33393 - atomic_inc(&m->error_count);
33394 + atomic_inc_unchecked(&m->error_count);
33395
33396 if (test_and_set_bit(error_type, &m->error_type))
33397 return;
33398 @@ -408,7 +408,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
33399 struct mirror *m = get_default_mirror(ms);
33400
33401 do {
33402 - if (likely(!atomic_read(&m->error_count)))
33403 + if (likely(!atomic_read_unchecked(&m->error_count)))
33404 return m;
33405
33406 if (m-- == ms->mirror)
33407 @@ -422,7 +422,7 @@ static int default_ok(struct mirror *m)
33408 {
33409 struct mirror *default_mirror = get_default_mirror(m->ms);
33410
33411 - return !atomic_read(&default_mirror->error_count);
33412 + return !atomic_read_unchecked(&default_mirror->error_count);
33413 }
33414
33415 static int mirror_available(struct mirror_set *ms, struct bio *bio)
33416 @@ -559,7 +559,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
33417 */
33418 if (likely(region_in_sync(ms, region, 1)))
33419 m = choose_mirror(ms, bio->bi_sector);
33420 - else if (m && atomic_read(&m->error_count))
33421 + else if (m && atomic_read_unchecked(&m->error_count))
33422 m = NULL;
33423
33424 if (likely(m))
33425 @@ -938,7 +938,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
33426 }
33427
33428 ms->mirror[mirror].ms = ms;
33429 - atomic_set(&(ms->mirror[mirror].error_count), 0);
33430 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
33431 ms->mirror[mirror].error_type = 0;
33432 ms->mirror[mirror].offset = offset;
33433
33434 @@ -1352,7 +1352,7 @@ static void mirror_resume(struct dm_target *ti)
33435 */
33436 static char device_status_char(struct mirror *m)
33437 {
33438 - if (!atomic_read(&(m->error_count)))
33439 + if (!atomic_read_unchecked(&(m->error_count)))
33440 return 'A';
33441
33442 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
33443 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
33444 index 35c94ff..20d4c17 100644
33445 --- a/drivers/md/dm-stripe.c
33446 +++ b/drivers/md/dm-stripe.c
33447 @@ -20,7 +20,7 @@ struct stripe {
33448 struct dm_dev *dev;
33449 sector_t physical_start;
33450
33451 - atomic_t error_count;
33452 + atomic_unchecked_t error_count;
33453 };
33454
33455 struct stripe_c {
33456 @@ -193,7 +193,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
33457 kfree(sc);
33458 return r;
33459 }
33460 - atomic_set(&(sc->stripe[i].error_count), 0);
33461 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
33462 }
33463
33464 ti->private = sc;
33465 @@ -315,7 +315,7 @@ static int stripe_status(struct dm_target *ti,
33466 DMEMIT("%d ", sc->stripes);
33467 for (i = 0; i < sc->stripes; i++) {
33468 DMEMIT("%s ", sc->stripe[i].dev->name);
33469 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
33470 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
33471 'D' : 'A';
33472 }
33473 buffer[i] = '\0';
33474 @@ -362,8 +362,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio,
33475 */
33476 for (i = 0; i < sc->stripes; i++)
33477 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
33478 - atomic_inc(&(sc->stripe[i].error_count));
33479 - if (atomic_read(&(sc->stripe[i].error_count)) <
33480 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
33481 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
33482 DM_IO_ERROR_THRESHOLD)
33483 schedule_work(&sc->trigger_event);
33484 }
33485 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
33486 index 2e227fb..44ead1f 100644
33487 --- a/drivers/md/dm-table.c
33488 +++ b/drivers/md/dm-table.c
33489 @@ -390,7 +390,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
33490 if (!dev_size)
33491 return 0;
33492
33493 - if ((start >= dev_size) || (start + len > dev_size)) {
33494 + if ((start >= dev_size) || (len > dev_size - start)) {
33495 DMWARN("%s: %s too small for target: "
33496 "start=%llu, len=%llu, dev_size=%llu",
33497 dm_device_name(ti->table->md), bdevname(bdev, b),
33498 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
33499 index 3e2907f..c28851a 100644
33500 --- a/drivers/md/dm-thin-metadata.c
33501 +++ b/drivers/md/dm-thin-metadata.c
33502 @@ -432,7 +432,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33503
33504 pmd->info.tm = tm;
33505 pmd->info.levels = 2;
33506 - pmd->info.value_type.context = pmd->data_sm;
33507 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33508 pmd->info.value_type.size = sizeof(__le64);
33509 pmd->info.value_type.inc = data_block_inc;
33510 pmd->info.value_type.dec = data_block_dec;
33511 @@ -451,7 +451,7 @@ static int init_pmd(struct dm_pool_metadata *pmd,
33512
33513 pmd->bl_info.tm = tm;
33514 pmd->bl_info.levels = 1;
33515 - pmd->bl_info.value_type.context = pmd->data_sm;
33516 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
33517 pmd->bl_info.value_type.size = sizeof(__le64);
33518 pmd->bl_info.value_type.inc = data_block_inc;
33519 pmd->bl_info.value_type.dec = data_block_dec;
33520 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
33521 index e24143c..ce2f21a1 100644
33522 --- a/drivers/md/dm.c
33523 +++ b/drivers/md/dm.c
33524 @@ -176,9 +176,9 @@ struct mapped_device {
33525 /*
33526 * Event handling.
33527 */
33528 - atomic_t event_nr;
33529 + atomic_unchecked_t event_nr;
33530 wait_queue_head_t eventq;
33531 - atomic_t uevent_seq;
33532 + atomic_unchecked_t uevent_seq;
33533 struct list_head uevent_list;
33534 spinlock_t uevent_lock; /* Protect access to uevent_list */
33535
33536 @@ -1845,8 +1845,8 @@ static struct mapped_device *alloc_dev(int minor)
33537 rwlock_init(&md->map_lock);
33538 atomic_set(&md->holders, 1);
33539 atomic_set(&md->open_count, 0);
33540 - atomic_set(&md->event_nr, 0);
33541 - atomic_set(&md->uevent_seq, 0);
33542 + atomic_set_unchecked(&md->event_nr, 0);
33543 + atomic_set_unchecked(&md->uevent_seq, 0);
33544 INIT_LIST_HEAD(&md->uevent_list);
33545 spin_lock_init(&md->uevent_lock);
33546
33547 @@ -1980,7 +1980,7 @@ static void event_callback(void *context)
33548
33549 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
33550
33551 - atomic_inc(&md->event_nr);
33552 + atomic_inc_unchecked(&md->event_nr);
33553 wake_up(&md->eventq);
33554 }
33555
33556 @@ -2622,18 +2622,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
33557
33558 uint32_t dm_next_uevent_seq(struct mapped_device *md)
33559 {
33560 - return atomic_add_return(1, &md->uevent_seq);
33561 + return atomic_add_return_unchecked(1, &md->uevent_seq);
33562 }
33563
33564 uint32_t dm_get_event_nr(struct mapped_device *md)
33565 {
33566 - return atomic_read(&md->event_nr);
33567 + return atomic_read_unchecked(&md->event_nr);
33568 }
33569
33570 int dm_wait_event(struct mapped_device *md, int event_nr)
33571 {
33572 return wait_event_interruptible(md->eventq,
33573 - (event_nr != atomic_read(&md->event_nr)));
33574 + (event_nr != atomic_read_unchecked(&md->event_nr)));
33575 }
33576
33577 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
33578 diff --git a/drivers/md/md.c b/drivers/md/md.c
33579 index 6fc0c26..0c864b6 100644
33580 --- a/drivers/md/md.c
33581 +++ b/drivers/md/md.c
33582 @@ -277,10 +277,10 @@ EXPORT_SYMBOL_GPL(md_trim_bio);
33583 * start build, activate spare
33584 */
33585 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
33586 -static atomic_t md_event_count;
33587 +static atomic_unchecked_t md_event_count;
33588 void md_new_event(struct mddev *mddev)
33589 {
33590 - atomic_inc(&md_event_count);
33591 + atomic_inc_unchecked(&md_event_count);
33592 wake_up(&md_event_waiters);
33593 }
33594 EXPORT_SYMBOL_GPL(md_new_event);
33595 @@ -290,7 +290,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
33596 */
33597 static void md_new_event_inintr(struct mddev *mddev)
33598 {
33599 - atomic_inc(&md_event_count);
33600 + atomic_inc_unchecked(&md_event_count);
33601 wake_up(&md_event_waiters);
33602 }
33603
33604 @@ -1568,7 +1568,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
33605 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
33606 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
33607 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
33608 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33609 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
33610
33611 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
33612 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
33613 @@ -1812,7 +1812,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
33614 else
33615 sb->resync_offset = cpu_to_le64(0);
33616
33617 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
33618 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
33619
33620 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
33621 sb->size = cpu_to_le64(mddev->dev_sectors);
33622 @@ -2806,7 +2806,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
33623 static ssize_t
33624 errors_show(struct md_rdev *rdev, char *page)
33625 {
33626 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
33627 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
33628 }
33629
33630 static ssize_t
33631 @@ -2815,7 +2815,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
33632 char *e;
33633 unsigned long n = simple_strtoul(buf, &e, 10);
33634 if (*buf && (*e == 0 || *e == '\n')) {
33635 - atomic_set(&rdev->corrected_errors, n);
33636 + atomic_set_unchecked(&rdev->corrected_errors, n);
33637 return len;
33638 }
33639 return -EINVAL;
33640 @@ -3262,8 +3262,8 @@ int md_rdev_init(struct md_rdev *rdev)
33641 rdev->sb_loaded = 0;
33642 rdev->bb_page = NULL;
33643 atomic_set(&rdev->nr_pending, 0);
33644 - atomic_set(&rdev->read_errors, 0);
33645 - atomic_set(&rdev->corrected_errors, 0);
33646 + atomic_set_unchecked(&rdev->read_errors, 0);
33647 + atomic_set_unchecked(&rdev->corrected_errors, 0);
33648
33649 INIT_LIST_HEAD(&rdev->same_set);
33650 init_waitqueue_head(&rdev->blocked_wait);
33651 @@ -7000,7 +7000,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
33652
33653 spin_unlock(&pers_lock);
33654 seq_printf(seq, "\n");
33655 - seq->poll_event = atomic_read(&md_event_count);
33656 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33657 return 0;
33658 }
33659 if (v == (void*)2) {
33660 @@ -7103,7 +7103,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
33661 return error;
33662
33663 seq = file->private_data;
33664 - seq->poll_event = atomic_read(&md_event_count);
33665 + seq->poll_event = atomic_read_unchecked(&md_event_count);
33666 return error;
33667 }
33668
33669 @@ -7117,7 +7117,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
33670 /* always allow read */
33671 mask = POLLIN | POLLRDNORM;
33672
33673 - if (seq->poll_event != atomic_read(&md_event_count))
33674 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
33675 mask |= POLLERR | POLLPRI;
33676 return mask;
33677 }
33678 @@ -7161,7 +7161,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
33679 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
33680 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
33681 (int)part_stat_read(&disk->part0, sectors[1]) -
33682 - atomic_read(&disk->sync_io);
33683 + atomic_read_unchecked(&disk->sync_io);
33684 /* sync IO will cause sync_io to increase before the disk_stats
33685 * as sync_io is counted when a request starts, and
33686 * disk_stats is counted when it completes.
33687 diff --git a/drivers/md/md.h b/drivers/md/md.h
33688 index 7b4a3c3..994ad4f 100644
33689 --- a/drivers/md/md.h
33690 +++ b/drivers/md/md.h
33691 @@ -94,13 +94,13 @@ struct md_rdev {
33692 * only maintained for arrays that
33693 * support hot removal
33694 */
33695 - atomic_t read_errors; /* number of consecutive read errors that
33696 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
33697 * we have tried to ignore.
33698 */
33699 struct timespec last_read_error; /* monotonic time since our
33700 * last read error
33701 */
33702 - atomic_t corrected_errors; /* number of corrected read errors,
33703 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
33704 * for reporting to userspace and storing
33705 * in superblock.
33706 */
33707 @@ -435,7 +435,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
33708
33709 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
33710 {
33711 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33712 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
33713 }
33714
33715 struct md_personality
33716 diff --git a/drivers/md/persistent-data/dm-space-map-checker.c b/drivers/md/persistent-data/dm-space-map-checker.c
33717 index fc90c11..c8cd9a9 100644
33718 --- a/drivers/md/persistent-data/dm-space-map-checker.c
33719 +++ b/drivers/md/persistent-data/dm-space-map-checker.c
33720 @@ -167,7 +167,7 @@ static int ca_commit(struct count_array *old, struct count_array *new)
33721 /*----------------------------------------------------------------*/
33722
33723 struct sm_checker {
33724 - struct dm_space_map sm;
33725 + dm_space_map_no_const sm;
33726
33727 struct count_array old_counts;
33728 struct count_array counts;
33729 diff --git a/drivers/md/persistent-data/dm-space-map-disk.c b/drivers/md/persistent-data/dm-space-map-disk.c
33730 index 3d0ed53..35dc592 100644
33731 --- a/drivers/md/persistent-data/dm-space-map-disk.c
33732 +++ b/drivers/md/persistent-data/dm-space-map-disk.c
33733 @@ -23,7 +23,7 @@
33734 * Space map interface.
33735 */
33736 struct sm_disk {
33737 - struct dm_space_map sm;
33738 + dm_space_map_no_const sm;
33739
33740 struct ll_disk ll;
33741 struct ll_disk old_ll;
33742 diff --git a/drivers/md/persistent-data/dm-space-map-metadata.c b/drivers/md/persistent-data/dm-space-map-metadata.c
33743 index e89ae5e..062e4c2 100644
33744 --- a/drivers/md/persistent-data/dm-space-map-metadata.c
33745 +++ b/drivers/md/persistent-data/dm-space-map-metadata.c
33746 @@ -43,7 +43,7 @@ struct block_op {
33747 };
33748
33749 struct sm_metadata {
33750 - struct dm_space_map sm;
33751 + dm_space_map_no_const sm;
33752
33753 struct ll_disk ll;
33754 struct ll_disk old_ll;
33755 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
33756 index 1cbfc6b..56e1dbb 100644
33757 --- a/drivers/md/persistent-data/dm-space-map.h
33758 +++ b/drivers/md/persistent-data/dm-space-map.h
33759 @@ -60,6 +60,7 @@ struct dm_space_map {
33760 int (*root_size)(struct dm_space_map *sm, size_t *result);
33761 int (*copy_root)(struct dm_space_map *sm, void *copy_to_here_le, size_t len);
33762 };
33763 +typedef struct dm_space_map __no_const dm_space_map_no_const;
33764
33765 /*----------------------------------------------------------------*/
33766
33767 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
33768 index 53aec45..250851c 100644
33769 --- a/drivers/md/raid1.c
33770 +++ b/drivers/md/raid1.c
33771 @@ -1685,7 +1685,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
33772 if (r1_sync_page_io(rdev, sect, s,
33773 bio->bi_io_vec[idx].bv_page,
33774 READ) != 0)
33775 - atomic_add(s, &rdev->corrected_errors);
33776 + atomic_add_unchecked(s, &rdev->corrected_errors);
33777 }
33778 sectors -= s;
33779 sect += s;
33780 @@ -1907,7 +1907,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
33781 test_bit(In_sync, &rdev->flags)) {
33782 if (r1_sync_page_io(rdev, sect, s,
33783 conf->tmppage, READ)) {
33784 - atomic_add(s, &rdev->corrected_errors);
33785 + atomic_add_unchecked(s, &rdev->corrected_errors);
33786 printk(KERN_INFO
33787 "md/raid1:%s: read error corrected "
33788 "(%d sectors at %llu on %s)\n",
33789 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
33790 index e987da4..83649e4 100644
33791 --- a/drivers/md/raid10.c
33792 +++ b/drivers/md/raid10.c
33793 @@ -1790,7 +1790,7 @@ static void end_sync_read(struct bio *bio, int error)
33794 /* The write handler will notice the lack of
33795 * R10BIO_Uptodate and record any errors etc
33796 */
33797 - atomic_add(r10_bio->sectors,
33798 + atomic_add_unchecked(r10_bio->sectors,
33799 &conf->mirrors[d].rdev->corrected_errors);
33800
33801 /* for reconstruct, we always reschedule after a read.
33802 @@ -2139,7 +2139,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33803 {
33804 struct timespec cur_time_mon;
33805 unsigned long hours_since_last;
33806 - unsigned int read_errors = atomic_read(&rdev->read_errors);
33807 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
33808
33809 ktime_get_ts(&cur_time_mon);
33810
33811 @@ -2161,9 +2161,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
33812 * overflowing the shift of read_errors by hours_since_last.
33813 */
33814 if (hours_since_last >= 8 * sizeof(read_errors))
33815 - atomic_set(&rdev->read_errors, 0);
33816 + atomic_set_unchecked(&rdev->read_errors, 0);
33817 else
33818 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
33819 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
33820 }
33821
33822 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
33823 @@ -2217,8 +2217,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33824 return;
33825
33826 check_decay_read_errors(mddev, rdev);
33827 - atomic_inc(&rdev->read_errors);
33828 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
33829 + atomic_inc_unchecked(&rdev->read_errors);
33830 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
33831 char b[BDEVNAME_SIZE];
33832 bdevname(rdev->bdev, b);
33833
33834 @@ -2226,7 +2226,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33835 "md/raid10:%s: %s: Raid device exceeded "
33836 "read_error threshold [cur %d:max %d]\n",
33837 mdname(mddev), b,
33838 - atomic_read(&rdev->read_errors), max_read_errors);
33839 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
33840 printk(KERN_NOTICE
33841 "md/raid10:%s: %s: Failing raid device\n",
33842 mdname(mddev), b);
33843 @@ -2381,7 +2381,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
33844 sect +
33845 choose_data_offset(r10_bio, rdev)),
33846 bdevname(rdev->bdev, b));
33847 - atomic_add(s, &rdev->corrected_errors);
33848 + atomic_add_unchecked(s, &rdev->corrected_errors);
33849 }
33850
33851 rdev_dec_pending(rdev, mddev);
33852 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
33853 index bcd096b..c24f08f 100644
33854 --- a/drivers/md/raid5.c
33855 +++ b/drivers/md/raid5.c
33856 @@ -1740,19 +1740,19 @@ static void raid5_end_read_request(struct bio * bi, int error)
33857 mdname(conf->mddev), STRIPE_SECTORS,
33858 (unsigned long long)s,
33859 bdevname(rdev->bdev, b));
33860 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
33861 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
33862 clear_bit(R5_ReadError, &sh->dev[i].flags);
33863 clear_bit(R5_ReWrite, &sh->dev[i].flags);
33864 }
33865 - if (atomic_read(&rdev->read_errors))
33866 - atomic_set(&rdev->read_errors, 0);
33867 + if (atomic_read_unchecked(&rdev->read_errors))
33868 + atomic_set_unchecked(&rdev->read_errors, 0);
33869 } else {
33870 const char *bdn = bdevname(rdev->bdev, b);
33871 int retry = 0;
33872 int set_bad = 0;
33873
33874 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
33875 - atomic_inc(&rdev->read_errors);
33876 + atomic_inc_unchecked(&rdev->read_errors);
33877 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
33878 printk_ratelimited(
33879 KERN_WARNING
33880 @@ -1780,7 +1780,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
33881 mdname(conf->mddev),
33882 (unsigned long long)s,
33883 bdn);
33884 - } else if (atomic_read(&rdev->read_errors)
33885 + } else if (atomic_read_unchecked(&rdev->read_errors)
33886 > conf->max_nr_stripes)
33887 printk(KERN_WARNING
33888 "md/raid:%s: Too many read errors, failing device %s.\n",
33889 diff --git a/drivers/media/dvb/ddbridge/ddbridge-core.c b/drivers/media/dvb/ddbridge/ddbridge-core.c
33890 index 131b938..8572ed1 100644
33891 --- a/drivers/media/dvb/ddbridge/ddbridge-core.c
33892 +++ b/drivers/media/dvb/ddbridge/ddbridge-core.c
33893 @@ -1678,7 +1678,7 @@ static struct ddb_info ddb_v6 = {
33894 .subvendor = _subvend, .subdevice = _subdev, \
33895 .driver_data = (unsigned long)&_driverdata }
33896
33897 -static const struct pci_device_id ddb_id_tbl[] __devinitdata = {
33898 +static const struct pci_device_id ddb_id_tbl[] __devinitconst = {
33899 DDB_ID(DDVID, 0x0002, DDVID, 0x0001, ddb_octopus),
33900 DDB_ID(DDVID, 0x0003, DDVID, 0x0001, ddb_octopus),
33901 DDB_ID(DDVID, 0x0003, DDVID, 0x0002, ddb_octopus_le),
33902 diff --git a/drivers/media/dvb/dvb-core/dvb_demux.h b/drivers/media/dvb/dvb-core/dvb_demux.h
33903 index fa7188a..04a045e 100644
33904 --- a/drivers/media/dvb/dvb-core/dvb_demux.h
33905 +++ b/drivers/media/dvb/dvb-core/dvb_demux.h
33906 @@ -73,7 +73,7 @@ struct dvb_demux_feed {
33907 union {
33908 dmx_ts_cb ts;
33909 dmx_section_cb sec;
33910 - } cb;
33911 + } __no_const cb;
33912
33913 struct dvb_demux *demux;
33914 void *priv;
33915 diff --git a/drivers/media/dvb/dvb-core/dvbdev.c b/drivers/media/dvb/dvb-core/dvbdev.c
33916 index 39eab73..60033e7 100644
33917 --- a/drivers/media/dvb/dvb-core/dvbdev.c
33918 +++ b/drivers/media/dvb/dvb-core/dvbdev.c
33919 @@ -192,7 +192,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
33920 const struct dvb_device *template, void *priv, int type)
33921 {
33922 struct dvb_device *dvbdev;
33923 - struct file_operations *dvbdevfops;
33924 + file_operations_no_const *dvbdevfops;
33925 struct device *clsdev;
33926 int minor;
33927 int id;
33928 diff --git a/drivers/media/dvb/dvb-usb/az6007.c b/drivers/media/dvb/dvb-usb/az6007.c
33929 index 4008b9c..ce714f5 100644
33930 --- a/drivers/media/dvb/dvb-usb/az6007.c
33931 +++ b/drivers/media/dvb/dvb-usb/az6007.c
33932 @@ -590,7 +590,7 @@ static int az6007_read_mac_addr(struct dvb_usb_device *d, u8 mac[6])
33933 int ret;
33934
33935 ret = az6007_read(d, AZ6007_READ_DATA, 6, 0, st->data, 6);
33936 - memcpy(mac, st->data, sizeof(mac));
33937 + memcpy(mac, st->data, 6);
33938
33939 if (ret > 0)
33940 deb_info("%s: mac is %02x:%02x:%02x:%02x:%02x:%02x\n",
33941 diff --git a/drivers/media/dvb/dvb-usb/cxusb.c b/drivers/media/dvb/dvb-usb/cxusb.c
33942 index 3940bb0..fb3952a 100644
33943 --- a/drivers/media/dvb/dvb-usb/cxusb.c
33944 +++ b/drivers/media/dvb/dvb-usb/cxusb.c
33945 @@ -1068,7 +1068,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
33946
33947 struct dib0700_adapter_state {
33948 int (*set_param_save) (struct dvb_frontend *);
33949 -};
33950 +} __no_const;
33951
33952 static int dib7070_set_param_override(struct dvb_frontend *fe)
33953 {
33954 diff --git a/drivers/media/dvb/dvb-usb/dw2102.c b/drivers/media/dvb/dvb-usb/dw2102.c
33955 index 9382895..ac8093c 100644
33956 --- a/drivers/media/dvb/dvb-usb/dw2102.c
33957 +++ b/drivers/media/dvb/dvb-usb/dw2102.c
33958 @@ -95,7 +95,7 @@ struct su3000_state {
33959
33960 struct s6x0_state {
33961 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
33962 -};
33963 +} __no_const;
33964
33965 /* debug */
33966 static int dvb_usb_dw2102_debug;
33967 diff --git a/drivers/media/dvb/frontends/dib3000.h b/drivers/media/dvb/frontends/dib3000.h
33968 index 404f63a..4796533 100644
33969 --- a/drivers/media/dvb/frontends/dib3000.h
33970 +++ b/drivers/media/dvb/frontends/dib3000.h
33971 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
33972 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
33973 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
33974 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
33975 -};
33976 +} __no_const;
33977
33978 #if defined(CONFIG_DVB_DIB3000MB) || (defined(CONFIG_DVB_DIB3000MB_MODULE) && defined(MODULE))
33979 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
33980 diff --git a/drivers/media/dvb/ngene/ngene-cards.c b/drivers/media/dvb/ngene/ngene-cards.c
33981 index 7539a5d..06531a6 100644
33982 --- a/drivers/media/dvb/ngene/ngene-cards.c
33983 +++ b/drivers/media/dvb/ngene/ngene-cards.c
33984 @@ -478,7 +478,7 @@ static struct ngene_info ngene_info_m780 = {
33985
33986 /****************************************************************************/
33987
33988 -static const struct pci_device_id ngene_id_tbl[] __devinitdata = {
33989 +static const struct pci_device_id ngene_id_tbl[] __devinitconst = {
33990 NGENE_ID(0x18c3, 0xabc3, ngene_info_cineS2),
33991 NGENE_ID(0x18c3, 0xabc4, ngene_info_cineS2),
33992 NGENE_ID(0x18c3, 0xdb01, ngene_info_satixS2),
33993 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
33994 index 16a089f..1661b11 100644
33995 --- a/drivers/media/radio/radio-cadet.c
33996 +++ b/drivers/media/radio/radio-cadet.c
33997 @@ -326,6 +326,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
33998 unsigned char readbuf[RDS_BUFFER];
33999 int i = 0;
34000
34001 + if (count > RDS_BUFFER)
34002 + return -EFAULT;
34003 mutex_lock(&dev->lock);
34004 if (dev->rdsstat == 0) {
34005 dev->rdsstat = 1;
34006 @@ -347,7 +349,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
34007 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
34008 mutex_unlock(&dev->lock);
34009
34010 - if (copy_to_user(data, readbuf, i))
34011 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
34012 return -EFAULT;
34013 return i;
34014 }
34015 diff --git a/drivers/media/video/au0828/au0828.h b/drivers/media/video/au0828/au0828.h
34016 index 9cde353..8c6a1c3 100644
34017 --- a/drivers/media/video/au0828/au0828.h
34018 +++ b/drivers/media/video/au0828/au0828.h
34019 @@ -191,7 +191,7 @@ struct au0828_dev {
34020
34021 /* I2C */
34022 struct i2c_adapter i2c_adap;
34023 - struct i2c_algorithm i2c_algo;
34024 + i2c_algorithm_no_const i2c_algo;
34025 struct i2c_client i2c_client;
34026 u32 i2c_rc;
34027
34028 diff --git a/drivers/media/video/cx88/cx88-alsa.c b/drivers/media/video/cx88/cx88-alsa.c
34029 index 04bf662..e0ac026 100644
34030 --- a/drivers/media/video/cx88/cx88-alsa.c
34031 +++ b/drivers/media/video/cx88/cx88-alsa.c
34032 @@ -766,7 +766,7 @@ static struct snd_kcontrol_new snd_cx88_alc_switch = {
34033 * Only boards with eeprom and byte 1 at eeprom=1 have it
34034 */
34035
34036 -static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitdata = {
34037 +static const struct pci_device_id const cx88_audio_pci_tbl[] __devinitconst = {
34038 {0x14f1,0x8801,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34039 {0x14f1,0x8811,PCI_ANY_ID,PCI_ANY_ID,0,0,0},
34040 {0, }
34041 diff --git a/drivers/media/video/omap/omap_vout.c b/drivers/media/video/omap/omap_vout.c
34042 index 88cf9d9..bbc4b2c 100644
34043 --- a/drivers/media/video/omap/omap_vout.c
34044 +++ b/drivers/media/video/omap/omap_vout.c
34045 @@ -64,7 +64,6 @@ enum omap_vout_channels {
34046 OMAP_VIDEO2,
34047 };
34048
34049 -static struct videobuf_queue_ops video_vbq_ops;
34050 /* Variables configurable through module params*/
34051 static u32 video1_numbuffers = 3;
34052 static u32 video2_numbuffers = 3;
34053 @@ -1000,6 +999,12 @@ static int omap_vout_open(struct file *file)
34054 {
34055 struct videobuf_queue *q;
34056 struct omap_vout_device *vout = NULL;
34057 + static struct videobuf_queue_ops video_vbq_ops = {
34058 + .buf_setup = omap_vout_buffer_setup,
34059 + .buf_prepare = omap_vout_buffer_prepare,
34060 + .buf_release = omap_vout_buffer_release,
34061 + .buf_queue = omap_vout_buffer_queue,
34062 + };
34063
34064 vout = video_drvdata(file);
34065 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
34066 @@ -1017,10 +1022,6 @@ static int omap_vout_open(struct file *file)
34067 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
34068
34069 q = &vout->vbq;
34070 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
34071 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
34072 - video_vbq_ops.buf_release = omap_vout_buffer_release;
34073 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
34074 spin_lock_init(&vout->vbq_lock);
34075
34076 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
34077 diff --git a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34078 index 036952f..80d356d 100644
34079 --- a/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34080 +++ b/drivers/media/video/pvrusb2/pvrusb2-hdw-internal.h
34081 @@ -196,7 +196,7 @@ struct pvr2_hdw {
34082
34083 /* I2C stuff */
34084 struct i2c_adapter i2c_adap;
34085 - struct i2c_algorithm i2c_algo;
34086 + i2c_algorithm_no_const i2c_algo;
34087 pvr2_i2c_func i2c_func[PVR2_I2C_FUNC_CNT];
34088 int i2c_cx25840_hack_state;
34089 int i2c_linked;
34090 diff --git a/drivers/media/video/timblogiw.c b/drivers/media/video/timblogiw.c
34091 index 02194c0..091733b 100644
34092 --- a/drivers/media/video/timblogiw.c
34093 +++ b/drivers/media/video/timblogiw.c
34094 @@ -745,7 +745,7 @@ static int timblogiw_mmap(struct file *file, struct vm_area_struct *vma)
34095
34096 /* Platform device functions */
34097
34098 -static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34099 +static __devinitconst v4l2_ioctl_ops_no_const timblogiw_ioctl_ops = {
34100 .vidioc_querycap = timblogiw_querycap,
34101 .vidioc_enum_fmt_vid_cap = timblogiw_enum_fmt,
34102 .vidioc_g_fmt_vid_cap = timblogiw_g_fmt,
34103 @@ -767,7 +767,7 @@ static __devinitconst struct v4l2_ioctl_ops timblogiw_ioctl_ops = {
34104 .vidioc_enum_framesizes = timblogiw_enum_framesizes,
34105 };
34106
34107 -static __devinitconst struct v4l2_file_operations timblogiw_fops = {
34108 +static __devinitconst v4l2_file_operations_no_const timblogiw_fops = {
34109 .owner = THIS_MODULE,
34110 .open = timblogiw_open,
34111 .release = timblogiw_close,
34112 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
34113 index d99db56..a16b959 100644
34114 --- a/drivers/message/fusion/mptbase.c
34115 +++ b/drivers/message/fusion/mptbase.c
34116 @@ -6751,8 +6751,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
34117 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
34118 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
34119
34120 +#ifdef CONFIG_GRKERNSEC_HIDESYM
34121 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
34122 +#else
34123 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
34124 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
34125 +#endif
34126 +
34127 /*
34128 * Rounding UP to nearest 4-kB boundary here...
34129 */
34130 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
34131 index 551262e..7551198 100644
34132 --- a/drivers/message/fusion/mptsas.c
34133 +++ b/drivers/message/fusion/mptsas.c
34134 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
34135 return 0;
34136 }
34137
34138 +static inline void
34139 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34140 +{
34141 + if (phy_info->port_details) {
34142 + phy_info->port_details->rphy = rphy;
34143 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34144 + ioc->name, rphy));
34145 + }
34146 +
34147 + if (rphy) {
34148 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34149 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34150 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34151 + ioc->name, rphy, rphy->dev.release));
34152 + }
34153 +}
34154 +
34155 /* no mutex */
34156 static void
34157 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
34158 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
34159 return NULL;
34160 }
34161
34162 -static inline void
34163 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
34164 -{
34165 - if (phy_info->port_details) {
34166 - phy_info->port_details->rphy = rphy;
34167 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
34168 - ioc->name, rphy));
34169 - }
34170 -
34171 - if (rphy) {
34172 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
34173 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
34174 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
34175 - ioc->name, rphy, rphy->dev.release));
34176 - }
34177 -}
34178 -
34179 static inline struct sas_port *
34180 mptsas_get_port(struct mptsas_phyinfo *phy_info)
34181 {
34182 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
34183 index 0c3ced7..1fe34ec 100644
34184 --- a/drivers/message/fusion/mptscsih.c
34185 +++ b/drivers/message/fusion/mptscsih.c
34186 @@ -1270,15 +1270,16 @@ mptscsih_info(struct Scsi_Host *SChost)
34187
34188 h = shost_priv(SChost);
34189
34190 - if (h) {
34191 - if (h->info_kbuf == NULL)
34192 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34193 - return h->info_kbuf;
34194 - h->info_kbuf[0] = '\0';
34195 + if (!h)
34196 + return NULL;
34197
34198 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34199 - h->info_kbuf[size-1] = '\0';
34200 - }
34201 + if (h->info_kbuf == NULL)
34202 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
34203 + return h->info_kbuf;
34204 + h->info_kbuf[0] = '\0';
34205 +
34206 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
34207 + h->info_kbuf[size-1] = '\0';
34208
34209 return h->info_kbuf;
34210 }
34211 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
34212 index 506c36f..b137580 100644
34213 --- a/drivers/message/i2o/i2o_proc.c
34214 +++ b/drivers/message/i2o/i2o_proc.c
34215 @@ -255,13 +255,6 @@ static char *scsi_devices[] = {
34216 "Array Controller Device"
34217 };
34218
34219 -static char *chtostr(u8 * chars, int n)
34220 -{
34221 - char tmp[256];
34222 - tmp[0] = 0;
34223 - return strncat(tmp, (char *)chars, n);
34224 -}
34225 -
34226 static int i2o_report_query_status(struct seq_file *seq, int block_status,
34227 char *group)
34228 {
34229 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
34230
34231 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
34232 seq_printf(seq, "%-#8x", ddm_table.module_id);
34233 - seq_printf(seq, "%-29s",
34234 - chtostr(ddm_table.module_name_version, 28));
34235 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
34236 seq_printf(seq, "%9d ", ddm_table.data_size);
34237 seq_printf(seq, "%8d", ddm_table.code_size);
34238
34239 @@ -927,8 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
34240
34241 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
34242 seq_printf(seq, "%-#8x", dst->module_id);
34243 - seq_printf(seq, "%-29s", chtostr(dst->module_name_version, 28));
34244 - seq_printf(seq, "%-9s", chtostr(dst->date, 8));
34245 + seq_printf(seq, "%-.28s", dst->module_name_version);
34246 + seq_printf(seq, "%-.8s", dst->date);
34247 seq_printf(seq, "%8d ", dst->module_size);
34248 seq_printf(seq, "%8d ", dst->mpb_size);
34249 seq_printf(seq, "0x%04x", dst->module_flags);
34250 @@ -1259,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
34251 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
34252 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
34253 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
34254 - seq_printf(seq, "Vendor info : %s\n",
34255 - chtostr((u8 *) (work32 + 2), 16));
34256 - seq_printf(seq, "Product info : %s\n",
34257 - chtostr((u8 *) (work32 + 6), 16));
34258 - seq_printf(seq, "Description : %s\n",
34259 - chtostr((u8 *) (work32 + 10), 16));
34260 - seq_printf(seq, "Product rev. : %s\n",
34261 - chtostr((u8 *) (work32 + 14), 8));
34262 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
34263 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
34264 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
34265 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
34266
34267 seq_printf(seq, "Serial number : ");
34268 print_serial_number(seq, (u8 *) (work32 + 16),
34269 @@ -1311,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
34270 }
34271
34272 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
34273 - seq_printf(seq, "Module name : %s\n",
34274 - chtostr(result.module_name, 24));
34275 - seq_printf(seq, "Module revision : %s\n",
34276 - chtostr(result.module_rev, 8));
34277 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
34278 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
34279
34280 seq_printf(seq, "Serial number : ");
34281 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
34282 @@ -1345,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
34283 return 0;
34284 }
34285
34286 - seq_printf(seq, "Device name : %s\n",
34287 - chtostr(result.device_name, 64));
34288 - seq_printf(seq, "Service name : %s\n",
34289 - chtostr(result.service_name, 64));
34290 - seq_printf(seq, "Physical name : %s\n",
34291 - chtostr(result.physical_location, 64));
34292 - seq_printf(seq, "Instance number : %s\n",
34293 - chtostr(result.instance_number, 4));
34294 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
34295 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
34296 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
34297 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
34298
34299 return 0;
34300 }
34301 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
34302 index a8c08f3..155fe3d 100644
34303 --- a/drivers/message/i2o/iop.c
34304 +++ b/drivers/message/i2o/iop.c
34305 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
34306
34307 spin_lock_irqsave(&c->context_list_lock, flags);
34308
34309 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
34310 - atomic_inc(&c->context_list_counter);
34311 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
34312 + atomic_inc_unchecked(&c->context_list_counter);
34313
34314 - entry->context = atomic_read(&c->context_list_counter);
34315 + entry->context = atomic_read_unchecked(&c->context_list_counter);
34316
34317 list_add(&entry->list, &c->context_list);
34318
34319 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
34320
34321 #if BITS_PER_LONG == 64
34322 spin_lock_init(&c->context_list_lock);
34323 - atomic_set(&c->context_list_counter, 0);
34324 + atomic_set_unchecked(&c->context_list_counter, 0);
34325 INIT_LIST_HEAD(&c->context_list);
34326 #endif
34327
34328 diff --git a/drivers/mfd/abx500-core.c b/drivers/mfd/abx500-core.c
34329 index 7ce65f4..e66e9bc 100644
34330 --- a/drivers/mfd/abx500-core.c
34331 +++ b/drivers/mfd/abx500-core.c
34332 @@ -15,7 +15,7 @@ static LIST_HEAD(abx500_list);
34333
34334 struct abx500_device_entry {
34335 struct list_head list;
34336 - struct abx500_ops ops;
34337 + abx500_ops_no_const ops;
34338 struct device *dev;
34339 };
34340
34341 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
34342 index 2ea9998..51dabee 100644
34343 --- a/drivers/mfd/janz-cmodio.c
34344 +++ b/drivers/mfd/janz-cmodio.c
34345 @@ -13,6 +13,7 @@
34346
34347 #include <linux/kernel.h>
34348 #include <linux/module.h>
34349 +#include <linux/slab.h>
34350 #include <linux/init.h>
34351 #include <linux/pci.h>
34352 #include <linux/interrupt.h>
34353 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
34354 index a981e2a..5ca0c8b 100644
34355 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
34356 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
34357 @@ -466,7 +466,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
34358 * the lid is closed. This leads to interrupts as soon as a little move
34359 * is done.
34360 */
34361 - atomic_inc(&lis3->count);
34362 + atomic_inc_unchecked(&lis3->count);
34363
34364 wake_up_interruptible(&lis3->misc_wait);
34365 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
34366 @@ -552,7 +552,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
34367 if (lis3->pm_dev)
34368 pm_runtime_get_sync(lis3->pm_dev);
34369
34370 - atomic_set(&lis3->count, 0);
34371 + atomic_set_unchecked(&lis3->count, 0);
34372 return 0;
34373 }
34374
34375 @@ -585,7 +585,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
34376 add_wait_queue(&lis3->misc_wait, &wait);
34377 while (true) {
34378 set_current_state(TASK_INTERRUPTIBLE);
34379 - data = atomic_xchg(&lis3->count, 0);
34380 + data = atomic_xchg_unchecked(&lis3->count, 0);
34381 if (data)
34382 break;
34383
34384 @@ -626,7 +626,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
34385 struct lis3lv02d, miscdev);
34386
34387 poll_wait(file, &lis3->misc_wait, wait);
34388 - if (atomic_read(&lis3->count))
34389 + if (atomic_read_unchecked(&lis3->count))
34390 return POLLIN | POLLRDNORM;
34391 return 0;
34392 }
34393 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
34394 index 2b1482a..5d33616 100644
34395 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
34396 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
34397 @@ -266,7 +266,7 @@ struct lis3lv02d {
34398 struct input_polled_dev *idev; /* input device */
34399 struct platform_device *pdev; /* platform device */
34400 struct regulator_bulk_data regulators[2];
34401 - atomic_t count; /* interrupt count after last read */
34402 + atomic_unchecked_t count; /* interrupt count after last read */
34403 union axis_conversion ac; /* hw -> logical axis */
34404 int mapped_btns[3];
34405
34406 diff --git a/drivers/misc/lkdtm.c b/drivers/misc/lkdtm.c
34407 index 28adefe..08aad69 100644
34408 --- a/drivers/misc/lkdtm.c
34409 +++ b/drivers/misc/lkdtm.c
34410 @@ -477,6 +477,8 @@ static ssize_t lkdtm_debugfs_read(struct file *f, char __user *user_buf,
34411 int i, n, out;
34412
34413 buf = (char *)__get_free_page(GFP_KERNEL);
34414 + if (buf == NULL)
34415 + return -ENOMEM;
34416
34417 n = snprintf(buf, PAGE_SIZE, "Available crash types:\n");
34418 for (i = 0; i < ARRAY_SIZE(cp_type); i++)
34419 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
34420 index 2f30bad..c4c13d0 100644
34421 --- a/drivers/misc/sgi-gru/gruhandles.c
34422 +++ b/drivers/misc/sgi-gru/gruhandles.c
34423 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
34424 unsigned long nsec;
34425
34426 nsec = CLKS2NSEC(clks);
34427 - atomic_long_inc(&mcs_op_statistics[op].count);
34428 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
34429 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
34430 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
34431 if (mcs_op_statistics[op].max < nsec)
34432 mcs_op_statistics[op].max = nsec;
34433 }
34434 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
34435 index 950dbe9..eeef0f8 100644
34436 --- a/drivers/misc/sgi-gru/gruprocfs.c
34437 +++ b/drivers/misc/sgi-gru/gruprocfs.c
34438 @@ -32,9 +32,9 @@
34439
34440 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
34441
34442 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
34443 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
34444 {
34445 - unsigned long val = atomic_long_read(v);
34446 + unsigned long val = atomic_long_read_unchecked(v);
34447
34448 seq_printf(s, "%16lu %s\n", val, id);
34449 }
34450 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
34451
34452 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
34453 for (op = 0; op < mcsop_last; op++) {
34454 - count = atomic_long_read(&mcs_op_statistics[op].count);
34455 - total = atomic_long_read(&mcs_op_statistics[op].total);
34456 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
34457 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
34458 max = mcs_op_statistics[op].max;
34459 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
34460 count ? total / count : 0, max);
34461 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
34462 index 5c3ce24..4915ccb 100644
34463 --- a/drivers/misc/sgi-gru/grutables.h
34464 +++ b/drivers/misc/sgi-gru/grutables.h
34465 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
34466 * GRU statistics.
34467 */
34468 struct gru_stats_s {
34469 - atomic_long_t vdata_alloc;
34470 - atomic_long_t vdata_free;
34471 - atomic_long_t gts_alloc;
34472 - atomic_long_t gts_free;
34473 - atomic_long_t gms_alloc;
34474 - atomic_long_t gms_free;
34475 - atomic_long_t gts_double_allocate;
34476 - atomic_long_t assign_context;
34477 - atomic_long_t assign_context_failed;
34478 - atomic_long_t free_context;
34479 - atomic_long_t load_user_context;
34480 - atomic_long_t load_kernel_context;
34481 - atomic_long_t lock_kernel_context;
34482 - atomic_long_t unlock_kernel_context;
34483 - atomic_long_t steal_user_context;
34484 - atomic_long_t steal_kernel_context;
34485 - atomic_long_t steal_context_failed;
34486 - atomic_long_t nopfn;
34487 - atomic_long_t asid_new;
34488 - atomic_long_t asid_next;
34489 - atomic_long_t asid_wrap;
34490 - atomic_long_t asid_reuse;
34491 - atomic_long_t intr;
34492 - atomic_long_t intr_cbr;
34493 - atomic_long_t intr_tfh;
34494 - atomic_long_t intr_spurious;
34495 - atomic_long_t intr_mm_lock_failed;
34496 - atomic_long_t call_os;
34497 - atomic_long_t call_os_wait_queue;
34498 - atomic_long_t user_flush_tlb;
34499 - atomic_long_t user_unload_context;
34500 - atomic_long_t user_exception;
34501 - atomic_long_t set_context_option;
34502 - atomic_long_t check_context_retarget_intr;
34503 - atomic_long_t check_context_unload;
34504 - atomic_long_t tlb_dropin;
34505 - atomic_long_t tlb_preload_page;
34506 - atomic_long_t tlb_dropin_fail_no_asid;
34507 - atomic_long_t tlb_dropin_fail_upm;
34508 - atomic_long_t tlb_dropin_fail_invalid;
34509 - atomic_long_t tlb_dropin_fail_range_active;
34510 - atomic_long_t tlb_dropin_fail_idle;
34511 - atomic_long_t tlb_dropin_fail_fmm;
34512 - atomic_long_t tlb_dropin_fail_no_exception;
34513 - atomic_long_t tfh_stale_on_fault;
34514 - atomic_long_t mmu_invalidate_range;
34515 - atomic_long_t mmu_invalidate_page;
34516 - atomic_long_t flush_tlb;
34517 - atomic_long_t flush_tlb_gru;
34518 - atomic_long_t flush_tlb_gru_tgh;
34519 - atomic_long_t flush_tlb_gru_zero_asid;
34520 + atomic_long_unchecked_t vdata_alloc;
34521 + atomic_long_unchecked_t vdata_free;
34522 + atomic_long_unchecked_t gts_alloc;
34523 + atomic_long_unchecked_t gts_free;
34524 + atomic_long_unchecked_t gms_alloc;
34525 + atomic_long_unchecked_t gms_free;
34526 + atomic_long_unchecked_t gts_double_allocate;
34527 + atomic_long_unchecked_t assign_context;
34528 + atomic_long_unchecked_t assign_context_failed;
34529 + atomic_long_unchecked_t free_context;
34530 + atomic_long_unchecked_t load_user_context;
34531 + atomic_long_unchecked_t load_kernel_context;
34532 + atomic_long_unchecked_t lock_kernel_context;
34533 + atomic_long_unchecked_t unlock_kernel_context;
34534 + atomic_long_unchecked_t steal_user_context;
34535 + atomic_long_unchecked_t steal_kernel_context;
34536 + atomic_long_unchecked_t steal_context_failed;
34537 + atomic_long_unchecked_t nopfn;
34538 + atomic_long_unchecked_t asid_new;
34539 + atomic_long_unchecked_t asid_next;
34540 + atomic_long_unchecked_t asid_wrap;
34541 + atomic_long_unchecked_t asid_reuse;
34542 + atomic_long_unchecked_t intr;
34543 + atomic_long_unchecked_t intr_cbr;
34544 + atomic_long_unchecked_t intr_tfh;
34545 + atomic_long_unchecked_t intr_spurious;
34546 + atomic_long_unchecked_t intr_mm_lock_failed;
34547 + atomic_long_unchecked_t call_os;
34548 + atomic_long_unchecked_t call_os_wait_queue;
34549 + atomic_long_unchecked_t user_flush_tlb;
34550 + atomic_long_unchecked_t user_unload_context;
34551 + atomic_long_unchecked_t user_exception;
34552 + atomic_long_unchecked_t set_context_option;
34553 + atomic_long_unchecked_t check_context_retarget_intr;
34554 + atomic_long_unchecked_t check_context_unload;
34555 + atomic_long_unchecked_t tlb_dropin;
34556 + atomic_long_unchecked_t tlb_preload_page;
34557 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
34558 + atomic_long_unchecked_t tlb_dropin_fail_upm;
34559 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
34560 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
34561 + atomic_long_unchecked_t tlb_dropin_fail_idle;
34562 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
34563 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
34564 + atomic_long_unchecked_t tfh_stale_on_fault;
34565 + atomic_long_unchecked_t mmu_invalidate_range;
34566 + atomic_long_unchecked_t mmu_invalidate_page;
34567 + atomic_long_unchecked_t flush_tlb;
34568 + atomic_long_unchecked_t flush_tlb_gru;
34569 + atomic_long_unchecked_t flush_tlb_gru_tgh;
34570 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
34571
34572 - atomic_long_t copy_gpa;
34573 - atomic_long_t read_gpa;
34574 + atomic_long_unchecked_t copy_gpa;
34575 + atomic_long_unchecked_t read_gpa;
34576
34577 - atomic_long_t mesq_receive;
34578 - atomic_long_t mesq_receive_none;
34579 - atomic_long_t mesq_send;
34580 - atomic_long_t mesq_send_failed;
34581 - atomic_long_t mesq_noop;
34582 - atomic_long_t mesq_send_unexpected_error;
34583 - atomic_long_t mesq_send_lb_overflow;
34584 - atomic_long_t mesq_send_qlimit_reached;
34585 - atomic_long_t mesq_send_amo_nacked;
34586 - atomic_long_t mesq_send_put_nacked;
34587 - atomic_long_t mesq_page_overflow;
34588 - atomic_long_t mesq_qf_locked;
34589 - atomic_long_t mesq_qf_noop_not_full;
34590 - atomic_long_t mesq_qf_switch_head_failed;
34591 - atomic_long_t mesq_qf_unexpected_error;
34592 - atomic_long_t mesq_noop_unexpected_error;
34593 - atomic_long_t mesq_noop_lb_overflow;
34594 - atomic_long_t mesq_noop_qlimit_reached;
34595 - atomic_long_t mesq_noop_amo_nacked;
34596 - atomic_long_t mesq_noop_put_nacked;
34597 - atomic_long_t mesq_noop_page_overflow;
34598 + atomic_long_unchecked_t mesq_receive;
34599 + atomic_long_unchecked_t mesq_receive_none;
34600 + atomic_long_unchecked_t mesq_send;
34601 + atomic_long_unchecked_t mesq_send_failed;
34602 + atomic_long_unchecked_t mesq_noop;
34603 + atomic_long_unchecked_t mesq_send_unexpected_error;
34604 + atomic_long_unchecked_t mesq_send_lb_overflow;
34605 + atomic_long_unchecked_t mesq_send_qlimit_reached;
34606 + atomic_long_unchecked_t mesq_send_amo_nacked;
34607 + atomic_long_unchecked_t mesq_send_put_nacked;
34608 + atomic_long_unchecked_t mesq_page_overflow;
34609 + atomic_long_unchecked_t mesq_qf_locked;
34610 + atomic_long_unchecked_t mesq_qf_noop_not_full;
34611 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
34612 + atomic_long_unchecked_t mesq_qf_unexpected_error;
34613 + atomic_long_unchecked_t mesq_noop_unexpected_error;
34614 + atomic_long_unchecked_t mesq_noop_lb_overflow;
34615 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
34616 + atomic_long_unchecked_t mesq_noop_amo_nacked;
34617 + atomic_long_unchecked_t mesq_noop_put_nacked;
34618 + atomic_long_unchecked_t mesq_noop_page_overflow;
34619
34620 };
34621
34622 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
34623 tghop_invalidate, mcsop_last};
34624
34625 struct mcs_op_statistic {
34626 - atomic_long_t count;
34627 - atomic_long_t total;
34628 + atomic_long_unchecked_t count;
34629 + atomic_long_unchecked_t total;
34630 unsigned long max;
34631 };
34632
34633 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
34634
34635 #define STAT(id) do { \
34636 if (gru_options & OPT_STATS) \
34637 - atomic_long_inc(&gru_stats.id); \
34638 + atomic_long_inc_unchecked(&gru_stats.id); \
34639 } while (0)
34640
34641 #ifdef CONFIG_SGI_GRU_DEBUG
34642 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
34643 index c862cd4..0d176fe 100644
34644 --- a/drivers/misc/sgi-xp/xp.h
34645 +++ b/drivers/misc/sgi-xp/xp.h
34646 @@ -288,7 +288,7 @@ struct xpc_interface {
34647 xpc_notify_func, void *);
34648 void (*received) (short, int, void *);
34649 enum xp_retval (*partid_to_nasids) (short, void *);
34650 -};
34651 +} __no_const;
34652
34653 extern struct xpc_interface xpc_interface;
34654
34655 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
34656 index b94d5f7..7f494c5 100644
34657 --- a/drivers/misc/sgi-xp/xpc.h
34658 +++ b/drivers/misc/sgi-xp/xpc.h
34659 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
34660 void (*received_payload) (struct xpc_channel *, void *);
34661 void (*notify_senders_of_disconnect) (struct xpc_channel *);
34662 };
34663 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
34664
34665 /* struct xpc_partition act_state values (for XPC HB) */
34666
34667 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
34668 /* found in xpc_main.c */
34669 extern struct device *xpc_part;
34670 extern struct device *xpc_chan;
34671 -extern struct xpc_arch_operations xpc_arch_ops;
34672 +extern xpc_arch_operations_no_const xpc_arch_ops;
34673 extern int xpc_disengage_timelimit;
34674 extern int xpc_disengage_timedout;
34675 extern int xpc_activate_IRQ_rcvd;
34676 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
34677 index 8d082b4..aa749ae 100644
34678 --- a/drivers/misc/sgi-xp/xpc_main.c
34679 +++ b/drivers/misc/sgi-xp/xpc_main.c
34680 @@ -162,7 +162,7 @@ static struct notifier_block xpc_die_notifier = {
34681 .notifier_call = xpc_system_die,
34682 };
34683
34684 -struct xpc_arch_operations xpc_arch_ops;
34685 +xpc_arch_operations_no_const xpc_arch_ops;
34686
34687 /*
34688 * Timer function to enforce the timelimit on the partition disengage.
34689 diff --git a/drivers/misc/ti-st/st_core.c b/drivers/misc/ti-st/st_core.c
34690 index 2b62232..acfaeeb 100644
34691 --- a/drivers/misc/ti-st/st_core.c
34692 +++ b/drivers/misc/ti-st/st_core.c
34693 @@ -349,6 +349,11 @@ void st_int_recv(void *disc_data,
34694 st_gdata->rx_skb = alloc_skb(
34695 st_gdata->list[type]->max_frame_size,
34696 GFP_ATOMIC);
34697 + if (st_gdata->rx_skb == NULL) {
34698 + pr_err("out of memory: dropping\n");
34699 + goto done;
34700 + }
34701 +
34702 skb_reserve(st_gdata->rx_skb,
34703 st_gdata->list[type]->reserve);
34704 /* next 2 required for BT only */
34705 diff --git a/drivers/mmc/host/sdhci-pci.c b/drivers/mmc/host/sdhci-pci.c
34706 index 504da71..9722d43 100644
34707 --- a/drivers/mmc/host/sdhci-pci.c
34708 +++ b/drivers/mmc/host/sdhci-pci.c
34709 @@ -653,7 +653,7 @@ static const struct sdhci_pci_fixes sdhci_via = {
34710 .probe = via_probe,
34711 };
34712
34713 -static const struct pci_device_id pci_ids[] __devinitdata = {
34714 +static const struct pci_device_id pci_ids[] __devinitconst = {
34715 {
34716 .vendor = PCI_VENDOR_ID_RICOH,
34717 .device = PCI_DEVICE_ID_RICOH_R5C822,
34718 diff --git a/drivers/mtd/devices/doc2000.c b/drivers/mtd/devices/doc2000.c
34719 index a4eb8b5..8c0628f 100644
34720 --- a/drivers/mtd/devices/doc2000.c
34721 +++ b/drivers/mtd/devices/doc2000.c
34722 @@ -753,7 +753,7 @@ static int doc_write(struct mtd_info *mtd, loff_t to, size_t len,
34723
34724 /* The ECC will not be calculated correctly if less than 512 is written */
34725 /* DBB-
34726 - if (len != 0x200 && eccbuf)
34727 + if (len != 0x200)
34728 printk(KERN_WARNING
34729 "ECC needs a full sector write (adr: %lx size %lx)\n",
34730 (long) to, (long) len);
34731 diff --git a/drivers/mtd/mtdchar.c b/drivers/mtd/mtdchar.c
34732 index f2f482b..a6e7451 100644
34733 --- a/drivers/mtd/mtdchar.c
34734 +++ b/drivers/mtd/mtdchar.c
34735 @@ -1123,6 +1123,33 @@ static unsigned long mtdchar_get_unmapped_area(struct file *file,
34736 }
34737 #endif
34738
34739 +static inline unsigned long get_vm_size(struct vm_area_struct *vma)
34740 +{
34741 + return vma->vm_end - vma->vm_start;
34742 +}
34743 +
34744 +static inline resource_size_t get_vm_offset(struct vm_area_struct *vma)
34745 +{
34746 + return (resource_size_t) vma->vm_pgoff << PAGE_SHIFT;
34747 +}
34748 +
34749 +/*
34750 + * Set a new vm offset.
34751 + *
34752 + * Verify that the incoming offset really works as a page offset,
34753 + * and that the offset and size fit in a resource_size_t.
34754 + */
34755 +static inline int set_vm_offset(struct vm_area_struct *vma, resource_size_t off)
34756 +{
34757 + pgoff_t pgoff = off >> PAGE_SHIFT;
34758 + if (off != (resource_size_t) pgoff << PAGE_SHIFT)
34759 + return -EINVAL;
34760 + if (off + get_vm_size(vma) - 1 < off)
34761 + return -EINVAL;
34762 + vma->vm_pgoff = pgoff;
34763 + return 0;
34764 +}
34765 +
34766 /*
34767 * set up a mapping for shared memory segments
34768 */
34769 @@ -1132,20 +1159,29 @@ static int mtdchar_mmap(struct file *file, struct vm_area_struct *vma)
34770 struct mtd_file_info *mfi = file->private_data;
34771 struct mtd_info *mtd = mfi->mtd;
34772 struct map_info *map = mtd->priv;
34773 - unsigned long start;
34774 - unsigned long off;
34775 - u32 len;
34776 + resource_size_t start, off;
34777 + unsigned long len, vma_len;
34778
34779 if (mtd->type == MTD_RAM || mtd->type == MTD_ROM) {
34780 - off = vma->vm_pgoff << PAGE_SHIFT;
34781 + off = get_vm_offset(vma);
34782 start = map->phys;
34783 len = PAGE_ALIGN((start & ~PAGE_MASK) + map->size);
34784 start &= PAGE_MASK;
34785 - if ((vma->vm_end - vma->vm_start + off) > len)
34786 + vma_len = get_vm_size(vma);
34787 +
34788 + /* Overflow in off+len? */
34789 + if (vma_len + off < off)
34790 + return -EINVAL;
34791 + /* Does it fit in the mapping? */
34792 + if (vma_len + off > len)
34793 return -EINVAL;
34794
34795 off += start;
34796 - vma->vm_pgoff = off >> PAGE_SHIFT;
34797 + /* Did that overflow? */
34798 + if (off < start)
34799 + return -EINVAL;
34800 + if (set_vm_offset(vma, off) < 0)
34801 + return -EINVAL;
34802 vma->vm_flags |= VM_IO | VM_RESERVED;
34803
34804 #ifdef pgprot_noncached
34805 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
34806 index 0650aaf..7718762 100644
34807 --- a/drivers/mtd/nand/denali.c
34808 +++ b/drivers/mtd/nand/denali.c
34809 @@ -26,6 +26,7 @@
34810 #include <linux/pci.h>
34811 #include <linux/mtd/mtd.h>
34812 #include <linux/module.h>
34813 +#include <linux/slab.h>
34814
34815 #include "denali.h"
34816
34817 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
34818 index 51b9d6a..52af9a7 100644
34819 --- a/drivers/mtd/nftlmount.c
34820 +++ b/drivers/mtd/nftlmount.c
34821 @@ -24,6 +24,7 @@
34822 #include <asm/errno.h>
34823 #include <linux/delay.h>
34824 #include <linux/slab.h>
34825 +#include <linux/sched.h>
34826 #include <linux/mtd/mtd.h>
34827 #include <linux/mtd/nand.h>
34828 #include <linux/mtd/nftl.h>
34829 diff --git a/drivers/net/ethernet/atheros/atlx/atl2.c b/drivers/net/ethernet/atheros/atlx/atl2.c
34830 index 6762dc4..9956862 100644
34831 --- a/drivers/net/ethernet/atheros/atlx/atl2.c
34832 +++ b/drivers/net/ethernet/atheros/atlx/atl2.c
34833 @@ -2859,7 +2859,7 @@ static void atl2_force_ps(struct atl2_hw *hw)
34834 */
34835
34836 #define ATL2_PARAM(X, desc) \
34837 - static const int __devinitdata X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34838 + static const int __devinitconst X[ATL2_MAX_NIC + 1] = ATL2_PARAM_INIT; \
34839 MODULE_PARM(X, "1-" __MODULE_STRING(ATL2_MAX_NIC) "i"); \
34840 MODULE_PARM_DESC(X, desc);
34841 #else
34842 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34843 index efd80bd..21fcff0 100644
34844 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34845 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
34846 @@ -487,7 +487,7 @@ struct bnx2x_rx_mode_obj {
34847
34848 int (*wait_comp)(struct bnx2x *bp,
34849 struct bnx2x_rx_mode_ramrod_params *p);
34850 -};
34851 +} __no_const;
34852
34853 /********************** Set multicast group ***********************************/
34854
34855 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
34856 index 93865f8..5448741 100644
34857 --- a/drivers/net/ethernet/broadcom/tg3.h
34858 +++ b/drivers/net/ethernet/broadcom/tg3.h
34859 @@ -140,6 +140,7 @@
34860 #define CHIPREV_ID_5750_A0 0x4000
34861 #define CHIPREV_ID_5750_A1 0x4001
34862 #define CHIPREV_ID_5750_A3 0x4003
34863 +#define CHIPREV_ID_5750_C1 0x4201
34864 #define CHIPREV_ID_5750_C2 0x4202
34865 #define CHIPREV_ID_5752_A0_HW 0x5000
34866 #define CHIPREV_ID_5752_A0 0x6000
34867 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34868 index c4e8643..0979484 100644
34869 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34870 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
34871 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
34872 */
34873 struct l2t_skb_cb {
34874 arp_failure_handler_func arp_failure_handler;
34875 -};
34876 +} __no_const;
34877
34878 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
34879
34880 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
34881 index d3cd489..0fd52dd 100644
34882 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
34883 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
34884 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34885 for (i=0; i<ETH_ALEN; i++) {
34886 tmp.addr[i] = dev->dev_addr[i];
34887 }
34888 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34889 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
34890 break;
34891
34892 case DE4X5_SET_HWADDR: /* Set the hardware address */
34893 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
34894 spin_lock_irqsave(&lp->lock, flags);
34895 memcpy(&statbuf, &lp->pktStats, ioc->len);
34896 spin_unlock_irqrestore(&lp->lock, flags);
34897 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
34898 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
34899 return -EFAULT;
34900 break;
34901 }
34902 diff --git a/drivers/net/ethernet/dec/tulip/eeprom.c b/drivers/net/ethernet/dec/tulip/eeprom.c
34903 index ed7d1dc..d426748 100644
34904 --- a/drivers/net/ethernet/dec/tulip/eeprom.c
34905 +++ b/drivers/net/ethernet/dec/tulip/eeprom.c
34906 @@ -79,7 +79,7 @@ static struct eeprom_fixup eeprom_fixups[] __devinitdata = {
34907 {NULL}};
34908
34909
34910 -static const char *block_name[] __devinitdata = {
34911 +static const char *block_name[] __devinitconst = {
34912 "21140 non-MII",
34913 "21140 MII PHY",
34914 "21142 Serial PHY",
34915 diff --git a/drivers/net/ethernet/dec/tulip/uli526x.c b/drivers/net/ethernet/dec/tulip/uli526x.c
34916 index 75d45f8..3d9c55b 100644
34917 --- a/drivers/net/ethernet/dec/tulip/uli526x.c
34918 +++ b/drivers/net/ethernet/dec/tulip/uli526x.c
34919 @@ -129,7 +129,7 @@ struct uli526x_board_info {
34920 struct uli_phy_ops {
34921 void (*write)(struct uli526x_board_info *, u8, u8, u16);
34922 u16 (*read)(struct uli526x_board_info *, u8, u8);
34923 - } phy;
34924 + } __no_const phy;
34925 struct net_device *next_dev; /* next device */
34926 struct pci_dev *pdev; /* PCI device */
34927 spinlock_t lock;
34928 diff --git a/drivers/net/ethernet/dec/tulip/winbond-840.c b/drivers/net/ethernet/dec/tulip/winbond-840.c
34929 index 4d1ffca..7c1ec4d 100644
34930 --- a/drivers/net/ethernet/dec/tulip/winbond-840.c
34931 +++ b/drivers/net/ethernet/dec/tulip/winbond-840.c
34932 @@ -236,7 +236,7 @@ struct pci_id_info {
34933 int drv_flags; /* Driver use, intended as capability flags. */
34934 };
34935
34936 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34937 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34938 { /* Sometime a Level-One switch card. */
34939 "Winbond W89c840", CanHaveMII | HasBrokenTx | FDXOnNoMII},
34940 { "Winbond W89c840", CanHaveMII | HasBrokenTx},
34941 diff --git a/drivers/net/ethernet/dlink/sundance.c b/drivers/net/ethernet/dlink/sundance.c
34942 index d7bb52a..3b83588 100644
34943 --- a/drivers/net/ethernet/dlink/sundance.c
34944 +++ b/drivers/net/ethernet/dlink/sundance.c
34945 @@ -218,7 +218,7 @@ enum {
34946 struct pci_id_info {
34947 const char *name;
34948 };
34949 -static const struct pci_id_info pci_id_tbl[] __devinitdata = {
34950 +static const struct pci_id_info pci_id_tbl[] __devinitconst = {
34951 {"D-Link DFE-550TX FAST Ethernet Adapter"},
34952 {"D-Link DFE-550FX 100Mbps Fiber-optics Adapter"},
34953 {"D-Link DFE-580TX 4 port Server Adapter"},
34954 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
34955 index bd5cf7e..c165651 100644
34956 --- a/drivers/net/ethernet/emulex/benet/be_main.c
34957 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
34958 @@ -403,7 +403,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
34959
34960 if (wrapped)
34961 newacc += 65536;
34962 - ACCESS_ONCE(*acc) = newacc;
34963 + ACCESS_ONCE_RW(*acc) = newacc;
34964 }
34965
34966 void be_parse_stats(struct be_adapter *adapter)
34967 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
34968 index 16b0704..d2c07d7 100644
34969 --- a/drivers/net/ethernet/faraday/ftgmac100.c
34970 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
34971 @@ -31,6 +31,8 @@
34972 #include <linux/netdevice.h>
34973 #include <linux/phy.h>
34974 #include <linux/platform_device.h>
34975 +#include <linux/interrupt.h>
34976 +#include <linux/irqreturn.h>
34977 #include <net/ip.h>
34978
34979 #include "ftgmac100.h"
34980 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
34981 index 829b109..4ae5f6a 100644
34982 --- a/drivers/net/ethernet/faraday/ftmac100.c
34983 +++ b/drivers/net/ethernet/faraday/ftmac100.c
34984 @@ -31,6 +31,8 @@
34985 #include <linux/module.h>
34986 #include <linux/netdevice.h>
34987 #include <linux/platform_device.h>
34988 +#include <linux/interrupt.h>
34989 +#include <linux/irqreturn.h>
34990
34991 #include "ftmac100.h"
34992
34993 diff --git a/drivers/net/ethernet/fealnx.c b/drivers/net/ethernet/fealnx.c
34994 index 9d71c9c..0e4a0ac 100644
34995 --- a/drivers/net/ethernet/fealnx.c
34996 +++ b/drivers/net/ethernet/fealnx.c
34997 @@ -150,7 +150,7 @@ struct chip_info {
34998 int flags;
34999 };
35000
35001 -static const struct chip_info skel_netdrv_tbl[] __devinitdata = {
35002 +static const struct chip_info skel_netdrv_tbl[] __devinitconst = {
35003 { "100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35004 { "100/10M Ethernet PCI Adapter", HAS_CHIP_XCVR },
35005 { "1000/100/10M Ethernet PCI Adapter", HAS_MII_XCVR },
35006 diff --git a/drivers/net/ethernet/intel/e1000e/e1000.h b/drivers/net/ethernet/intel/e1000e/e1000.h
35007 index fa47b85..246edeb 100644
35008 --- a/drivers/net/ethernet/intel/e1000e/e1000.h
35009 +++ b/drivers/net/ethernet/intel/e1000e/e1000.h
35010 @@ -181,7 +181,7 @@ struct e1000_info;
35011 #define E1000_TXDCTL_DMA_BURST_ENABLE \
35012 (E1000_TXDCTL_GRAN | /* set descriptor granularity */ \
35013 E1000_TXDCTL_COUNT_DESC | \
35014 - (5 << 16) | /* wthresh must be +1 more than desired */\
35015 + (1 << 16) | /* wthresh must be +1 more than desired */\
35016 (1 << 8) | /* hthresh */ \
35017 0x1f) /* pthresh */
35018
35019 diff --git a/drivers/net/ethernet/intel/e1000e/hw.h b/drivers/net/ethernet/intel/e1000e/hw.h
35020 index ed5b409..ec37828 100644
35021 --- a/drivers/net/ethernet/intel/e1000e/hw.h
35022 +++ b/drivers/net/ethernet/intel/e1000e/hw.h
35023 @@ -797,6 +797,7 @@ struct e1000_mac_operations {
35024 void (*rar_set)(struct e1000_hw *, u8 *, u32);
35025 s32 (*read_mac_addr)(struct e1000_hw *);
35026 };
35027 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35028
35029 /*
35030 * When to use various PHY register access functions:
35031 @@ -837,6 +838,7 @@ struct e1000_phy_operations {
35032 void (*power_up)(struct e1000_hw *);
35033 void (*power_down)(struct e1000_hw *);
35034 };
35035 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35036
35037 /* Function pointers for the NVM. */
35038 struct e1000_nvm_operations {
35039 @@ -849,9 +851,10 @@ struct e1000_nvm_operations {
35040 s32 (*validate)(struct e1000_hw *);
35041 s32 (*write)(struct e1000_hw *, u16, u16, u16 *);
35042 };
35043 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35044
35045 struct e1000_mac_info {
35046 - struct e1000_mac_operations ops;
35047 + e1000_mac_operations_no_const ops;
35048 u8 addr[ETH_ALEN];
35049 u8 perm_addr[ETH_ALEN];
35050
35051 @@ -892,7 +895,7 @@ struct e1000_mac_info {
35052 };
35053
35054 struct e1000_phy_info {
35055 - struct e1000_phy_operations ops;
35056 + e1000_phy_operations_no_const ops;
35057
35058 enum e1000_phy_type type;
35059
35060 @@ -926,7 +929,7 @@ struct e1000_phy_info {
35061 };
35062
35063 struct e1000_nvm_info {
35064 - struct e1000_nvm_operations ops;
35065 + e1000_nvm_operations_no_const ops;
35066
35067 enum e1000_nvm_type type;
35068 enum e1000_nvm_override override;
35069 diff --git a/drivers/net/ethernet/intel/igb/e1000_hw.h b/drivers/net/ethernet/intel/igb/e1000_hw.h
35070 index c2a51dc..c2bd262 100644
35071 --- a/drivers/net/ethernet/intel/igb/e1000_hw.h
35072 +++ b/drivers/net/ethernet/intel/igb/e1000_hw.h
35073 @@ -327,6 +327,7 @@ struct e1000_mac_operations {
35074 void (*release_swfw_sync)(struct e1000_hw *, u16);
35075
35076 };
35077 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35078
35079 struct e1000_phy_operations {
35080 s32 (*acquire)(struct e1000_hw *);
35081 @@ -343,6 +344,7 @@ struct e1000_phy_operations {
35082 s32 (*set_d3_lplu_state)(struct e1000_hw *, bool);
35083 s32 (*write_reg)(struct e1000_hw *, u32, u16);
35084 };
35085 +typedef struct e1000_phy_operations __no_const e1000_phy_operations_no_const;
35086
35087 struct e1000_nvm_operations {
35088 s32 (*acquire)(struct e1000_hw *);
35089 @@ -353,6 +355,7 @@ struct e1000_nvm_operations {
35090 s32 (*validate)(struct e1000_hw *);
35091 s32 (*valid_led_default)(struct e1000_hw *, u16 *);
35092 };
35093 +typedef struct e1000_nvm_operations __no_const e1000_nvm_operations_no_const;
35094
35095 struct e1000_info {
35096 s32 (*get_invariants)(struct e1000_hw *);
35097 @@ -364,7 +367,7 @@ struct e1000_info {
35098 extern const struct e1000_info e1000_82575_info;
35099
35100 struct e1000_mac_info {
35101 - struct e1000_mac_operations ops;
35102 + e1000_mac_operations_no_const ops;
35103
35104 u8 addr[6];
35105 u8 perm_addr[6];
35106 @@ -402,7 +405,7 @@ struct e1000_mac_info {
35107 };
35108
35109 struct e1000_phy_info {
35110 - struct e1000_phy_operations ops;
35111 + e1000_phy_operations_no_const ops;
35112
35113 enum e1000_phy_type type;
35114
35115 @@ -437,7 +440,7 @@ struct e1000_phy_info {
35116 };
35117
35118 struct e1000_nvm_info {
35119 - struct e1000_nvm_operations ops;
35120 + e1000_nvm_operations_no_const ops;
35121 enum e1000_nvm_type type;
35122 enum e1000_nvm_override override;
35123
35124 @@ -482,6 +485,7 @@ struct e1000_mbx_operations {
35125 s32 (*check_for_ack)(struct e1000_hw *, u16);
35126 s32 (*check_for_rst)(struct e1000_hw *, u16);
35127 };
35128 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35129
35130 struct e1000_mbx_stats {
35131 u32 msgs_tx;
35132 @@ -493,7 +497,7 @@ struct e1000_mbx_stats {
35133 };
35134
35135 struct e1000_mbx_info {
35136 - struct e1000_mbx_operations ops;
35137 + e1000_mbx_operations_no_const ops;
35138 struct e1000_mbx_stats stats;
35139 u32 timeout;
35140 u32 usec_delay;
35141 diff --git a/drivers/net/ethernet/intel/igbvf/vf.h b/drivers/net/ethernet/intel/igbvf/vf.h
35142 index 57db3c6..aa825fc 100644
35143 --- a/drivers/net/ethernet/intel/igbvf/vf.h
35144 +++ b/drivers/net/ethernet/intel/igbvf/vf.h
35145 @@ -189,9 +189,10 @@ struct e1000_mac_operations {
35146 s32 (*read_mac_addr)(struct e1000_hw *);
35147 s32 (*set_vfta)(struct e1000_hw *, u16, bool);
35148 };
35149 +typedef struct e1000_mac_operations __no_const e1000_mac_operations_no_const;
35150
35151 struct e1000_mac_info {
35152 - struct e1000_mac_operations ops;
35153 + e1000_mac_operations_no_const ops;
35154 u8 addr[6];
35155 u8 perm_addr[6];
35156
35157 @@ -213,6 +214,7 @@ struct e1000_mbx_operations {
35158 s32 (*check_for_ack)(struct e1000_hw *);
35159 s32 (*check_for_rst)(struct e1000_hw *);
35160 };
35161 +typedef struct e1000_mbx_operations __no_const e1000_mbx_operations_no_const;
35162
35163 struct e1000_mbx_stats {
35164 u32 msgs_tx;
35165 @@ -224,7 +226,7 @@ struct e1000_mbx_stats {
35166 };
35167
35168 struct e1000_mbx_info {
35169 - struct e1000_mbx_operations ops;
35170 + e1000_mbx_operations_no_const ops;
35171 struct e1000_mbx_stats stats;
35172 u32 timeout;
35173 u32 usec_delay;
35174 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35175 index dcebd12..c1fe8be 100644
35176 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35177 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
35178 @@ -805,7 +805,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
35179 /* store the new cycle speed */
35180 adapter->cycle_speed = cycle_speed;
35181
35182 - ACCESS_ONCE(adapter->base_incval) = incval;
35183 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
35184 smp_mb();
35185
35186 /* grab the ptp lock */
35187 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35188 index 204848d..d8aeaec 100644
35189 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35190 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_type.h
35191 @@ -2791,6 +2791,7 @@ struct ixgbe_eeprom_operations {
35192 s32 (*update_checksum)(struct ixgbe_hw *);
35193 u16 (*calc_checksum)(struct ixgbe_hw *);
35194 };
35195 +typedef struct ixgbe_eeprom_operations __no_const ixgbe_eeprom_operations_no_const;
35196
35197 struct ixgbe_mac_operations {
35198 s32 (*init_hw)(struct ixgbe_hw *);
35199 @@ -2856,6 +2857,7 @@ struct ixgbe_mac_operations {
35200 s32 (*get_thermal_sensor_data)(struct ixgbe_hw *);
35201 s32 (*init_thermal_sensor_thresh)(struct ixgbe_hw *hw);
35202 };
35203 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35204
35205 struct ixgbe_phy_operations {
35206 s32 (*identify)(struct ixgbe_hw *);
35207 @@ -2875,9 +2877,10 @@ struct ixgbe_phy_operations {
35208 s32 (*write_i2c_eeprom)(struct ixgbe_hw *, u8, u8);
35209 s32 (*check_overtemp)(struct ixgbe_hw *);
35210 };
35211 +typedef struct ixgbe_phy_operations __no_const ixgbe_phy_operations_no_const;
35212
35213 struct ixgbe_eeprom_info {
35214 - struct ixgbe_eeprom_operations ops;
35215 + ixgbe_eeprom_operations_no_const ops;
35216 enum ixgbe_eeprom_type type;
35217 u32 semaphore_delay;
35218 u16 word_size;
35219 @@ -2887,7 +2890,7 @@ struct ixgbe_eeprom_info {
35220
35221 #define IXGBE_FLAGS_DOUBLE_RESET_REQUIRED 0x01
35222 struct ixgbe_mac_info {
35223 - struct ixgbe_mac_operations ops;
35224 + ixgbe_mac_operations_no_const ops;
35225 enum ixgbe_mac_type type;
35226 u8 addr[ETH_ALEN];
35227 u8 perm_addr[ETH_ALEN];
35228 @@ -2916,7 +2919,7 @@ struct ixgbe_mac_info {
35229 };
35230
35231 struct ixgbe_phy_info {
35232 - struct ixgbe_phy_operations ops;
35233 + ixgbe_phy_operations_no_const ops;
35234 struct mdio_if_info mdio;
35235 enum ixgbe_phy_type type;
35236 u32 id;
35237 @@ -2944,6 +2947,7 @@ struct ixgbe_mbx_operations {
35238 s32 (*check_for_ack)(struct ixgbe_hw *, u16);
35239 s32 (*check_for_rst)(struct ixgbe_hw *, u16);
35240 };
35241 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35242
35243 struct ixgbe_mbx_stats {
35244 u32 msgs_tx;
35245 @@ -2955,7 +2959,7 @@ struct ixgbe_mbx_stats {
35246 };
35247
35248 struct ixgbe_mbx_info {
35249 - struct ixgbe_mbx_operations ops;
35250 + ixgbe_mbx_operations_no_const ops;
35251 struct ixgbe_mbx_stats stats;
35252 u32 timeout;
35253 u32 usec_delay;
35254 diff --git a/drivers/net/ethernet/intel/ixgbevf/vf.h b/drivers/net/ethernet/intel/ixgbevf/vf.h
35255 index 25c951d..cc7cf33 100644
35256 --- a/drivers/net/ethernet/intel/ixgbevf/vf.h
35257 +++ b/drivers/net/ethernet/intel/ixgbevf/vf.h
35258 @@ -70,6 +70,7 @@ struct ixgbe_mac_operations {
35259 s32 (*clear_vfta)(struct ixgbe_hw *);
35260 s32 (*set_vfta)(struct ixgbe_hw *, u32, u32, bool);
35261 };
35262 +typedef struct ixgbe_mac_operations __no_const ixgbe_mac_operations_no_const;
35263
35264 enum ixgbe_mac_type {
35265 ixgbe_mac_unknown = 0,
35266 @@ -79,7 +80,7 @@ enum ixgbe_mac_type {
35267 };
35268
35269 struct ixgbe_mac_info {
35270 - struct ixgbe_mac_operations ops;
35271 + ixgbe_mac_operations_no_const ops;
35272 u8 addr[6];
35273 u8 perm_addr[6];
35274
35275 @@ -103,6 +104,7 @@ struct ixgbe_mbx_operations {
35276 s32 (*check_for_ack)(struct ixgbe_hw *);
35277 s32 (*check_for_rst)(struct ixgbe_hw *);
35278 };
35279 +typedef struct ixgbe_mbx_operations __no_const ixgbe_mbx_operations_no_const;
35280
35281 struct ixgbe_mbx_stats {
35282 u32 msgs_tx;
35283 @@ -114,7 +116,7 @@ struct ixgbe_mbx_stats {
35284 };
35285
35286 struct ixgbe_mbx_info {
35287 - struct ixgbe_mbx_operations ops;
35288 + ixgbe_mbx_operations_no_const ops;
35289 struct ixgbe_mbx_stats stats;
35290 u32 timeout;
35291 u32 udelay;
35292 diff --git a/drivers/net/ethernet/mellanox/mlx4/main.c b/drivers/net/ethernet/mellanox/mlx4/main.c
35293 index a0313de..e83a572 100644
35294 --- a/drivers/net/ethernet/mellanox/mlx4/main.c
35295 +++ b/drivers/net/ethernet/mellanox/mlx4/main.c
35296 @@ -41,6 +41,7 @@
35297 #include <linux/slab.h>
35298 #include <linux/io-mapping.h>
35299 #include <linux/delay.h>
35300 +#include <linux/sched.h>
35301
35302 #include <linux/mlx4/device.h>
35303 #include <linux/mlx4/doorbell.h>
35304 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.h b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35305 index 5046a64..71ca936 100644
35306 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.h
35307 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.h
35308 @@ -514,7 +514,7 @@ struct vxge_hw_uld_cbs {
35309 void (*link_down)(struct __vxge_hw_device *devh);
35310 void (*crit_err)(struct __vxge_hw_device *devh,
35311 enum vxge_hw_event type, u64 ext_data);
35312 -};
35313 +} __no_const;
35314
35315 /*
35316 * struct __vxge_hw_blockpool_entry - Block private data structure
35317 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35318 index 4a518a3..936b334 100644
35319 --- a/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35320 +++ b/drivers/net/ethernet/neterion/vxge/vxge-traffic.h
35321 @@ -2088,7 +2088,7 @@ struct vxge_hw_mempool_cbs {
35322 struct vxge_hw_mempool_dma *dma_object,
35323 u32 index,
35324 u32 is_last);
35325 -};
35326 +} __no_const;
35327
35328 #define VXGE_HW_VIRTUAL_PATH_HANDLE(vpath) \
35329 ((struct __vxge_hw_vpath_handle *)(vpath)->vpath_handles.next)
35330 diff --git a/drivers/net/ethernet/octeon/octeon_mgmt.c b/drivers/net/ethernet/octeon/octeon_mgmt.c
35331 index cd827ff..389795e 100644
35332 --- a/drivers/net/ethernet/octeon/octeon_mgmt.c
35333 +++ b/drivers/net/ethernet/octeon/octeon_mgmt.c
35334 @@ -683,10 +683,8 @@ static int octeon_mgmt_init_phy(struct net_device *netdev)
35335 p->phydev = phy_connect(netdev, phy_id, octeon_mgmt_adjust_link, 0,
35336 PHY_INTERFACE_MODE_MII);
35337
35338 - if (IS_ERR(p->phydev)) {
35339 - p->phydev = NULL;
35340 + if (!p->phydev)
35341 return -1;
35342 - }
35343
35344 phy_start_aneg(p->phydev);
35345
35346 diff --git a/drivers/net/ethernet/pasemi/pasemi_mac.c b/drivers/net/ethernet/pasemi/pasemi_mac.c
35347 index e559dfa..6fa74d5 100644
35348 --- a/drivers/net/ethernet/pasemi/pasemi_mac.c
35349 +++ b/drivers/net/ethernet/pasemi/pasemi_mac.c
35350 @@ -1101,9 +1101,9 @@ static int pasemi_mac_phy_init(struct net_device *dev)
35351 phydev = of_phy_connect(dev, phy_dn, &pasemi_adjust_link, 0,
35352 PHY_INTERFACE_MODE_SGMII);
35353
35354 - if (IS_ERR(phydev)) {
35355 + if (!phydev) {
35356 printk(KERN_ERR "%s: Could not attach to phy\n", dev->name);
35357 - return PTR_ERR(phydev);
35358 + return -ENODEV;
35359 }
35360
35361 mac->phydev = phydev;
35362 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
35363 index eb81da4..1592b62 100644
35364 --- a/drivers/net/ethernet/realtek/r8169.c
35365 +++ b/drivers/net/ethernet/realtek/r8169.c
35366 @@ -723,22 +723,22 @@ struct rtl8169_private {
35367 struct mdio_ops {
35368 void (*write)(void __iomem *, int, int);
35369 int (*read)(void __iomem *, int);
35370 - } mdio_ops;
35371 + } __no_const mdio_ops;
35372
35373 struct pll_power_ops {
35374 void (*down)(struct rtl8169_private *);
35375 void (*up)(struct rtl8169_private *);
35376 - } pll_power_ops;
35377 + } __no_const pll_power_ops;
35378
35379 struct jumbo_ops {
35380 void (*enable)(struct rtl8169_private *);
35381 void (*disable)(struct rtl8169_private *);
35382 - } jumbo_ops;
35383 + } __no_const jumbo_ops;
35384
35385 struct csi_ops {
35386 void (*write)(void __iomem *, int, int);
35387 u32 (*read)(void __iomem *, int);
35388 - } csi_ops;
35389 + } __no_const csi_ops;
35390
35391 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
35392 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
35393 diff --git a/drivers/net/ethernet/sis/sis190.c b/drivers/net/ethernet/sis/sis190.c
35394 index 4613591..d816601 100644
35395 --- a/drivers/net/ethernet/sis/sis190.c
35396 +++ b/drivers/net/ethernet/sis/sis190.c
35397 @@ -1618,7 +1618,7 @@ static int __devinit sis190_get_mac_addr_from_eeprom(struct pci_dev *pdev,
35398 static int __devinit sis190_get_mac_addr_from_apc(struct pci_dev *pdev,
35399 struct net_device *dev)
35400 {
35401 - static const u16 __devinitdata ids[] = { 0x0965, 0x0966, 0x0968 };
35402 + static const u16 __devinitconst ids[] = { 0x0965, 0x0966, 0x0968 };
35403 struct sis190_private *tp = netdev_priv(dev);
35404 struct pci_dev *isa_bridge;
35405 u8 reg, tmp8;
35406 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35407 index c07cfe9..81cbf7e 100644
35408 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35409 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
35410 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
35411
35412 writel(value, ioaddr + MMC_CNTRL);
35413
35414 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35415 - MMC_CNTRL, value);
35416 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
35417 +// MMC_CNTRL, value);
35418 }
35419
35420 /* To mask all all interrupts.*/
35421 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
35422 index 2857ab0..9a1f9b0 100644
35423 --- a/drivers/net/hyperv/hyperv_net.h
35424 +++ b/drivers/net/hyperv/hyperv_net.h
35425 @@ -99,7 +99,7 @@ struct rndis_device {
35426
35427 enum rndis_device_state state;
35428 bool link_state;
35429 - atomic_t new_req_id;
35430 + atomic_unchecked_t new_req_id;
35431
35432 spinlock_t request_lock;
35433 struct list_head req_list;
35434 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
35435 index 981ebb1..b34959b 100644
35436 --- a/drivers/net/hyperv/rndis_filter.c
35437 +++ b/drivers/net/hyperv/rndis_filter.c
35438 @@ -97,7 +97,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
35439 * template
35440 */
35441 set = &rndis_msg->msg.set_req;
35442 - set->req_id = atomic_inc_return(&dev->new_req_id);
35443 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35444
35445 /* Add to the request list */
35446 spin_lock_irqsave(&dev->request_lock, flags);
35447 @@ -648,7 +648,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
35448
35449 /* Setup the rndis set */
35450 halt = &request->request_msg.msg.halt_req;
35451 - halt->req_id = atomic_inc_return(&dev->new_req_id);
35452 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
35453
35454 /* Ignore return since this msg is optional. */
35455 rndis_filter_send_request(dev, request);
35456 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
35457 index 5c05572..389610b 100644
35458 --- a/drivers/net/ppp/ppp_generic.c
35459 +++ b/drivers/net/ppp/ppp_generic.c
35460 @@ -986,7 +986,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35461 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
35462 struct ppp_stats stats;
35463 struct ppp_comp_stats cstats;
35464 - char *vers;
35465
35466 switch (cmd) {
35467 case SIOCGPPPSTATS:
35468 @@ -1008,8 +1007,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
35469 break;
35470
35471 case SIOCGPPPVER:
35472 - vers = PPP_VERSION;
35473 - if (copy_to_user(addr, vers, strlen(vers) + 1))
35474 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
35475 break;
35476 err = 0;
35477 break;
35478 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
35479 index c61ae35..7758801 100644
35480 --- a/drivers/net/team/team.c
35481 +++ b/drivers/net/team/team.c
35482 @@ -1410,8 +1410,8 @@ static int team_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
35483
35484 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
35485 &team_nl_family, 0, TEAM_CMD_NOOP);
35486 - if (IS_ERR(hdr)) {
35487 - err = PTR_ERR(hdr);
35488 + if (!hdr) {
35489 + err = -EMSGSIZE;
35490 goto err_msg_put;
35491 }
35492
35493 @@ -1493,8 +1493,8 @@ static int team_nl_fill_options_get(struct sk_buff *skb,
35494
35495 hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags,
35496 TEAM_CMD_OPTIONS_GET);
35497 - if (IS_ERR(hdr))
35498 - return PTR_ERR(hdr);
35499 + if (!hdr)
35500 + return -EMSGSIZE;
35501
35502 if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
35503 goto nla_put_failure;
35504 @@ -1739,8 +1739,8 @@ static int team_nl_fill_port_list_get(struct sk_buff *skb,
35505
35506 hdr = genlmsg_put(skb, pid, seq, &team_nl_family, flags,
35507 TEAM_CMD_PORT_LIST_GET);
35508 - if (IS_ERR(hdr))
35509 - return PTR_ERR(hdr);
35510 + if (!hdr)
35511 + return -EMSGSIZE;
35512
35513 if (nla_put_u32(skb, TEAM_ATTR_TEAM_IFINDEX, team->dev->ifindex))
35514 goto nla_put_failure;
35515 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
35516 index 5fb59ae..989715a 100644
35517 --- a/drivers/net/tun.c
35518 +++ b/drivers/net/tun.c
35519 @@ -1243,7 +1243,7 @@ static int set_offload(struct tun_struct *tun, unsigned long arg)
35520 }
35521
35522 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35523 - unsigned long arg, int ifreq_len)
35524 + unsigned long arg, size_t ifreq_len)
35525 {
35526 struct tun_file *tfile = file->private_data;
35527 struct tun_struct *tun;
35528 @@ -1254,6 +1254,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
35529 int vnet_hdr_sz;
35530 int ret;
35531
35532 + if (ifreq_len > sizeof ifr)
35533 + return -EFAULT;
35534 +
35535 if (cmd == TUNSETIFF || _IOC_TYPE(cmd) == 0x89) {
35536 if (copy_from_user(&ifr, argp, ifreq_len))
35537 return -EFAULT;
35538 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
35539 index 62f30b4..ff99dfd 100644
35540 --- a/drivers/net/usb/hso.c
35541 +++ b/drivers/net/usb/hso.c
35542 @@ -71,7 +71,7 @@
35543 #include <asm/byteorder.h>
35544 #include <linux/serial_core.h>
35545 #include <linux/serial.h>
35546 -
35547 +#include <asm/local.h>
35548
35549 #define MOD_AUTHOR "Option Wireless"
35550 #define MOD_DESCRIPTION "USB High Speed Option driver"
35551 @@ -1182,7 +1182,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
35552 struct urb *urb;
35553
35554 urb = serial->rx_urb[0];
35555 - if (serial->port.count > 0) {
35556 + if (atomic_read(&serial->port.count) > 0) {
35557 count = put_rxbuf_data(urb, serial);
35558 if (count == -1)
35559 return;
35560 @@ -1218,7 +1218,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
35561 DUMP1(urb->transfer_buffer, urb->actual_length);
35562
35563 /* Anyone listening? */
35564 - if (serial->port.count == 0)
35565 + if (atomic_read(&serial->port.count) == 0)
35566 return;
35567
35568 if (status == 0) {
35569 @@ -1300,8 +1300,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35570 tty_port_tty_set(&serial->port, tty);
35571
35572 /* check for port already opened, if not set the termios */
35573 - serial->port.count++;
35574 - if (serial->port.count == 1) {
35575 + if (atomic_inc_return(&serial->port.count) == 1) {
35576 serial->rx_state = RX_IDLE;
35577 /* Force default termio settings */
35578 _hso_serial_set_termios(tty, NULL);
35579 @@ -1313,7 +1312,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
35580 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
35581 if (result) {
35582 hso_stop_serial_device(serial->parent);
35583 - serial->port.count--;
35584 + atomic_dec(&serial->port.count);
35585 kref_put(&serial->parent->ref, hso_serial_ref_free);
35586 }
35587 } else {
35588 @@ -1350,10 +1349,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
35589
35590 /* reset the rts and dtr */
35591 /* do the actual close */
35592 - serial->port.count--;
35593 + atomic_dec(&serial->port.count);
35594
35595 - if (serial->port.count <= 0) {
35596 - serial->port.count = 0;
35597 + if (atomic_read(&serial->port.count) <= 0) {
35598 + atomic_set(&serial->port.count, 0);
35599 tty_port_tty_set(&serial->port, NULL);
35600 if (!usb_gone)
35601 hso_stop_serial_device(serial->parent);
35602 @@ -1429,7 +1428,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
35603
35604 /* the actual setup */
35605 spin_lock_irqsave(&serial->serial_lock, flags);
35606 - if (serial->port.count)
35607 + if (atomic_read(&serial->port.count))
35608 _hso_serial_set_termios(tty, old);
35609 else
35610 tty->termios = old;
35611 @@ -1888,7 +1887,7 @@ static void intr_callback(struct urb *urb)
35612 D1("Pending read interrupt on port %d\n", i);
35613 spin_lock(&serial->serial_lock);
35614 if (serial->rx_state == RX_IDLE &&
35615 - serial->port.count > 0) {
35616 + atomic_read(&serial->port.count) > 0) {
35617 /* Setup and send a ctrl req read on
35618 * port i */
35619 if (!serial->rx_urb_filled[0]) {
35620 @@ -3079,7 +3078,7 @@ static int hso_resume(struct usb_interface *iface)
35621 /* Start all serial ports */
35622 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
35623 if (serial_table[i] && (serial_table[i]->interface == iface)) {
35624 - if (dev2ser(serial_table[i])->port.count) {
35625 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
35626 result =
35627 hso_start_serial_device(serial_table[i], GFP_NOIO);
35628 hso_kick_transmit(dev2ser(serial_table[i]));
35629 diff --git a/drivers/net/wireless/ath/ath.h b/drivers/net/wireless/ath/ath.h
35630 index 420d69b..74f90a2 100644
35631 --- a/drivers/net/wireless/ath/ath.h
35632 +++ b/drivers/net/wireless/ath/ath.h
35633 @@ -119,6 +119,7 @@ struct ath_ops {
35634 void (*write_flush) (void *);
35635 u32 (*rmw)(void *, u32 reg_offset, u32 set, u32 clr);
35636 };
35637 +typedef struct ath_ops __no_const ath_ops_no_const;
35638
35639 struct ath_common;
35640 struct ath_bus_ops;
35641 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35642 index 8d78253..bebbb68 100644
35643 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35644 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
35645 @@ -184,8 +184,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35646 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
35647 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
35648
35649 - ACCESS_ONCE(ads->ds_link) = i->link;
35650 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
35651 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
35652 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
35653
35654 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
35655 ctl6 = SM(i->keytype, AR_EncrType);
35656 @@ -199,26 +199,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35657
35658 if ((i->is_first || i->is_last) &&
35659 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
35660 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
35661 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
35662 | set11nTries(i->rates, 1)
35663 | set11nTries(i->rates, 2)
35664 | set11nTries(i->rates, 3)
35665 | (i->dur_update ? AR_DurUpdateEna : 0)
35666 | SM(0, AR_BurstDur);
35667
35668 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
35669 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
35670 | set11nRate(i->rates, 1)
35671 | set11nRate(i->rates, 2)
35672 | set11nRate(i->rates, 3);
35673 } else {
35674 - ACCESS_ONCE(ads->ds_ctl2) = 0;
35675 - ACCESS_ONCE(ads->ds_ctl3) = 0;
35676 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
35677 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
35678 }
35679
35680 if (!i->is_first) {
35681 - ACCESS_ONCE(ads->ds_ctl0) = 0;
35682 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35683 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35684 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
35685 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35686 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35687 return;
35688 }
35689
35690 @@ -243,7 +243,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35691 break;
35692 }
35693
35694 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35695 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
35696 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35697 | SM(i->txpower, AR_XmitPower)
35698 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35699 @@ -253,19 +253,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35700 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
35701 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
35702
35703 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
35704 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
35705 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
35706 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
35707
35708 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
35709 return;
35710
35711 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35712 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
35713 | set11nPktDurRTSCTS(i->rates, 1);
35714
35715 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35716 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
35717 | set11nPktDurRTSCTS(i->rates, 3);
35718
35719 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35720 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
35721 | set11nRateFlags(i->rates, 1)
35722 | set11nRateFlags(i->rates, 2)
35723 | set11nRateFlags(i->rates, 3)
35724 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35725 index d9e0824..1a874e7 100644
35726 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35727 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
35728 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35729 (i->qcu << AR_TxQcuNum_S) | desc_len;
35730
35731 checksum += val;
35732 - ACCESS_ONCE(ads->info) = val;
35733 + ACCESS_ONCE_RW(ads->info) = val;
35734
35735 checksum += i->link;
35736 - ACCESS_ONCE(ads->link) = i->link;
35737 + ACCESS_ONCE_RW(ads->link) = i->link;
35738
35739 checksum += i->buf_addr[0];
35740 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
35741 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
35742 checksum += i->buf_addr[1];
35743 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
35744 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
35745 checksum += i->buf_addr[2];
35746 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
35747 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
35748 checksum += i->buf_addr[3];
35749 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
35750 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
35751
35752 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
35753 - ACCESS_ONCE(ads->ctl3) = val;
35754 + ACCESS_ONCE_RW(ads->ctl3) = val;
35755 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
35756 - ACCESS_ONCE(ads->ctl5) = val;
35757 + ACCESS_ONCE_RW(ads->ctl5) = val;
35758 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
35759 - ACCESS_ONCE(ads->ctl7) = val;
35760 + ACCESS_ONCE_RW(ads->ctl7) = val;
35761 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
35762 - ACCESS_ONCE(ads->ctl9) = val;
35763 + ACCESS_ONCE_RW(ads->ctl9) = val;
35764
35765 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
35766 - ACCESS_ONCE(ads->ctl10) = checksum;
35767 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
35768
35769 if (i->is_first || i->is_last) {
35770 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
35771 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
35772 | set11nTries(i->rates, 1)
35773 | set11nTries(i->rates, 2)
35774 | set11nTries(i->rates, 3)
35775 | (i->dur_update ? AR_DurUpdateEna : 0)
35776 | SM(0, AR_BurstDur);
35777
35778 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
35779 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
35780 | set11nRate(i->rates, 1)
35781 | set11nRate(i->rates, 2)
35782 | set11nRate(i->rates, 3);
35783 } else {
35784 - ACCESS_ONCE(ads->ctl13) = 0;
35785 - ACCESS_ONCE(ads->ctl14) = 0;
35786 + ACCESS_ONCE_RW(ads->ctl13) = 0;
35787 + ACCESS_ONCE_RW(ads->ctl14) = 0;
35788 }
35789
35790 ads->ctl20 = 0;
35791 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35792
35793 ctl17 = SM(i->keytype, AR_EncrType);
35794 if (!i->is_first) {
35795 - ACCESS_ONCE(ads->ctl11) = 0;
35796 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35797 - ACCESS_ONCE(ads->ctl15) = 0;
35798 - ACCESS_ONCE(ads->ctl16) = 0;
35799 - ACCESS_ONCE(ads->ctl17) = ctl17;
35800 - ACCESS_ONCE(ads->ctl18) = 0;
35801 - ACCESS_ONCE(ads->ctl19) = 0;
35802 + ACCESS_ONCE_RW(ads->ctl11) = 0;
35803 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
35804 + ACCESS_ONCE_RW(ads->ctl15) = 0;
35805 + ACCESS_ONCE_RW(ads->ctl16) = 0;
35806 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35807 + ACCESS_ONCE_RW(ads->ctl18) = 0;
35808 + ACCESS_ONCE_RW(ads->ctl19) = 0;
35809 return;
35810 }
35811
35812 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35813 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
35814 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
35815 | SM(i->txpower, AR_XmitPower)
35816 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
35817 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
35818 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
35819 ctl12 |= SM(val, AR_PAPRDChainMask);
35820
35821 - ACCESS_ONCE(ads->ctl12) = ctl12;
35822 - ACCESS_ONCE(ads->ctl17) = ctl17;
35823 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
35824 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
35825
35826 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35827 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
35828 | set11nPktDurRTSCTS(i->rates, 1);
35829
35830 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35831 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
35832 | set11nPktDurRTSCTS(i->rates, 3);
35833
35834 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
35835 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
35836 | set11nRateFlags(i->rates, 1)
35837 | set11nRateFlags(i->rates, 2)
35838 | set11nRateFlags(i->rates, 3)
35839 | SM(i->rtscts_rate, AR_RTSCTSRate);
35840
35841 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
35842 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
35843 }
35844
35845 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
35846 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
35847 index 02f5007..bd0bd8f 100644
35848 --- a/drivers/net/wireless/ath/ath9k/hw.h
35849 +++ b/drivers/net/wireless/ath/ath9k/hw.h
35850 @@ -610,7 +610,7 @@ struct ath_hw_private_ops {
35851
35852 /* ANI */
35853 void (*ani_cache_ini_regs)(struct ath_hw *ah);
35854 -};
35855 +} __no_const;
35856
35857 /**
35858 * struct ath_hw_ops - callbacks used by hardware code and driver code
35859 @@ -640,7 +640,7 @@ struct ath_hw_ops {
35860 void (*antdiv_comb_conf_set)(struct ath_hw *ah,
35861 struct ath_hw_antcomb_conf *antconf);
35862
35863 -};
35864 +} __no_const;
35865
35866 struct ath_nf_limits {
35867 s16 max;
35868 @@ -660,7 +660,7 @@ enum ath_cal_list {
35869 #define AH_FASTCC 0x4
35870
35871 struct ath_hw {
35872 - struct ath_ops reg_ops;
35873 + ath_ops_no_const reg_ops;
35874
35875 struct ieee80211_hw *hw;
35876 struct ath_common common;
35877 diff --git a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35878 index af00e2c..ab04d34 100644
35879 --- a/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35880 +++ b/drivers/net/wireless/brcm80211/brcmsmac/phy/phy_int.h
35881 @@ -545,7 +545,7 @@ struct phy_func_ptr {
35882 void (*carrsuppr)(struct brcms_phy *);
35883 s32 (*rxsigpwr)(struct brcms_phy *, s32);
35884 void (*detach)(struct brcms_phy *);
35885 -};
35886 +} __no_const;
35887
35888 struct brcms_phy {
35889 struct brcms_phy_pub pubpi_ro;
35890 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
35891 index faec404..a5277f1 100644
35892 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
35893 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
35894 @@ -3611,7 +3611,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
35895 */
35896 if (il3945_mod_params.disable_hw_scan) {
35897 D_INFO("Disabling hw_scan\n");
35898 - il3945_mac_ops.hw_scan = NULL;
35899 + pax_open_kernel();
35900 + *(void **)&il3945_mac_ops.hw_scan = NULL;
35901 + pax_close_kernel();
35902 }
35903
35904 D_INFO("*** LOAD DRIVER ***\n");
35905 diff --git a/drivers/net/wireless/iwlwifi/iwl-debugfs.c b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
35906 index 5000690..a67f98a 100644
35907 --- a/drivers/net/wireless/iwlwifi/iwl-debugfs.c
35908 +++ b/drivers/net/wireless/iwlwifi/iwl-debugfs.c
35909 @@ -207,7 +207,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
35910 {
35911 struct iwl_priv *priv = file->private_data;
35912 char buf[64];
35913 - int buf_size;
35914 + size_t buf_size;
35915 u32 offset, len;
35916
35917 memset(buf, 0, sizeof(buf));
35918 @@ -484,7 +484,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
35919 struct iwl_priv *priv = file->private_data;
35920
35921 char buf[8];
35922 - int buf_size;
35923 + size_t buf_size;
35924 u32 reset_flag;
35925
35926 memset(buf, 0, sizeof(buf));
35927 @@ -565,7 +565,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
35928 {
35929 struct iwl_priv *priv = file->private_data;
35930 char buf[8];
35931 - int buf_size;
35932 + size_t buf_size;
35933 int ht40;
35934
35935 memset(buf, 0, sizeof(buf));
35936 @@ -617,7 +617,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
35937 {
35938 struct iwl_priv *priv = file->private_data;
35939 char buf[8];
35940 - int buf_size;
35941 + size_t buf_size;
35942 int value;
35943
35944 memset(buf, 0, sizeof(buf));
35945 @@ -1882,7 +1882,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
35946 {
35947 struct iwl_priv *priv = file->private_data;
35948 char buf[8];
35949 - int buf_size;
35950 + size_t buf_size;
35951 int clear;
35952
35953 memset(buf, 0, sizeof(buf));
35954 @@ -1927,7 +1927,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
35955 {
35956 struct iwl_priv *priv = file->private_data;
35957 char buf[8];
35958 - int buf_size;
35959 + size_t buf_size;
35960 int trace;
35961
35962 memset(buf, 0, sizeof(buf));
35963 @@ -1998,7 +1998,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
35964 {
35965 struct iwl_priv *priv = file->private_data;
35966 char buf[8];
35967 - int buf_size;
35968 + size_t buf_size;
35969 int missed;
35970
35971 memset(buf, 0, sizeof(buf));
35972 @@ -2039,7 +2039,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
35973
35974 struct iwl_priv *priv = file->private_data;
35975 char buf[8];
35976 - int buf_size;
35977 + size_t buf_size;
35978 int plcp;
35979
35980 memset(buf, 0, sizeof(buf));
35981 @@ -2099,7 +2099,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
35982
35983 struct iwl_priv *priv = file->private_data;
35984 char buf[8];
35985 - int buf_size;
35986 + size_t buf_size;
35987 int flush;
35988
35989 memset(buf, 0, sizeof(buf));
35990 @@ -2189,7 +2189,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
35991
35992 struct iwl_priv *priv = file->private_data;
35993 char buf[8];
35994 - int buf_size;
35995 + size_t buf_size;
35996 int rts;
35997
35998 if (!priv->cfg->ht_params)
35999 @@ -2231,7 +2231,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
36000 {
36001 struct iwl_priv *priv = file->private_data;
36002 char buf[8];
36003 - int buf_size;
36004 + size_t buf_size;
36005
36006 memset(buf, 0, sizeof(buf));
36007 buf_size = min(count, sizeof(buf) - 1);
36008 @@ -2267,7 +2267,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
36009 struct iwl_priv *priv = file->private_data;
36010 u32 event_log_flag;
36011 char buf[8];
36012 - int buf_size;
36013 + size_t buf_size;
36014
36015 memset(buf, 0, sizeof(buf));
36016 buf_size = min(count, sizeof(buf) - 1);
36017 @@ -2317,7 +2317,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
36018 struct iwl_priv *priv = file->private_data;
36019 char buf[8];
36020 u32 calib_disabled;
36021 - int buf_size;
36022 + size_t buf_size;
36023
36024 memset(buf, 0, sizeof(buf));
36025 buf_size = min(count, sizeof(buf) - 1);
36026 diff --git a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c b/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
36027 index a1fb025..378e8a5 100644
36028 --- a/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
36029 +++ b/drivers/net/wireless/iwlwifi/iwl-trans-pcie.c
36030 @@ -1951,7 +1951,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
36031 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
36032
36033 char buf[8];
36034 - int buf_size;
36035 + size_t buf_size;
36036 u32 reset_flag;
36037
36038 memset(buf, 0, sizeof(buf));
36039 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
36040 {
36041 struct iwl_trans *trans = file->private_data;
36042 char buf[8];
36043 - int buf_size;
36044 + size_t buf_size;
36045 int csr;
36046
36047 memset(buf, 0, sizeof(buf));
36048 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
36049 index a0b7cfd..20b49f7 100644
36050 --- a/drivers/net/wireless/mac80211_hwsim.c
36051 +++ b/drivers/net/wireless/mac80211_hwsim.c
36052 @@ -1752,9 +1752,11 @@ static int __init init_mac80211_hwsim(void)
36053 return -EINVAL;
36054
36055 if (fake_hw_scan) {
36056 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36057 - mac80211_hwsim_ops.sw_scan_start = NULL;
36058 - mac80211_hwsim_ops.sw_scan_complete = NULL;
36059 + pax_open_kernel();
36060 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
36061 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
36062 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
36063 + pax_close_kernel();
36064 }
36065
36066 spin_lock_init(&hwsim_radio_lock);
36067 diff --git a/drivers/net/wireless/mwifiex/main.h b/drivers/net/wireless/mwifiex/main.h
36068 index bd3b0bf..f9db92a 100644
36069 --- a/drivers/net/wireless/mwifiex/main.h
36070 +++ b/drivers/net/wireless/mwifiex/main.h
36071 @@ -567,7 +567,7 @@ struct mwifiex_if_ops {
36072 int (*event_complete) (struct mwifiex_adapter *, struct sk_buff *);
36073 int (*data_complete) (struct mwifiex_adapter *, struct sk_buff *);
36074 int (*dnld_fw) (struct mwifiex_adapter *, struct mwifiex_fw_image *);
36075 -};
36076 +} __no_const;
36077
36078 struct mwifiex_adapter {
36079 u8 iface_type;
36080 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
36081 index dfcd02a..a42a59d 100644
36082 --- a/drivers/net/wireless/rndis_wlan.c
36083 +++ b/drivers/net/wireless/rndis_wlan.c
36084 @@ -1235,7 +1235,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
36085
36086 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
36087
36088 - if (rts_threshold < 0 || rts_threshold > 2347)
36089 + if (rts_threshold > 2347)
36090 rts_threshold = 2347;
36091
36092 tmp = cpu_to_le32(rts_threshold);
36093 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
36094 index 8f75402..eed109d 100644
36095 --- a/drivers/net/wireless/rt2x00/rt2x00.h
36096 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
36097 @@ -396,7 +396,7 @@ struct rt2x00_intf {
36098 * for hardware which doesn't support hardware
36099 * sequence counting.
36100 */
36101 - atomic_t seqno;
36102 + atomic_unchecked_t seqno;
36103 };
36104
36105 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
36106 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
36107 index 2fd8301..9767e8c 100644
36108 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
36109 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
36110 @@ -240,9 +240,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
36111 * sequence counter given by mac80211.
36112 */
36113 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
36114 - seqno = atomic_add_return(0x10, &intf->seqno);
36115 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
36116 else
36117 - seqno = atomic_read(&intf->seqno);
36118 + seqno = atomic_read_unchecked(&intf->seqno);
36119
36120 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
36121 hdr->seq_ctrl |= cpu_to_le16(seqno);
36122 diff --git a/drivers/net/wireless/ti/wl1251/wl1251.h b/drivers/net/wireless/ti/wl1251/wl1251.h
36123 index 9d8f581..0f6589e 100644
36124 --- a/drivers/net/wireless/ti/wl1251/wl1251.h
36125 +++ b/drivers/net/wireless/ti/wl1251/wl1251.h
36126 @@ -266,7 +266,7 @@ struct wl1251_if_operations {
36127 void (*reset)(struct wl1251 *wl);
36128 void (*enable_irq)(struct wl1251 *wl);
36129 void (*disable_irq)(struct wl1251 *wl);
36130 -};
36131 +} __no_const;
36132
36133 struct wl1251 {
36134 struct ieee80211_hw *hw;
36135 diff --git a/drivers/net/wireless/ti/wlcore/wlcore.h b/drivers/net/wireless/ti/wlcore/wlcore.h
36136 index 0b3f0b5..62f68bd 100644
36137 --- a/drivers/net/wireless/ti/wlcore/wlcore.h
36138 +++ b/drivers/net/wireless/ti/wlcore/wlcore.h
36139 @@ -61,7 +61,7 @@ struct wlcore_ops {
36140 struct wl12xx_vif *wlvif);
36141 s8 (*get_pg_ver)(struct wl1271 *wl);
36142 void (*get_mac)(struct wl1271 *wl);
36143 -};
36144 +} __no_const;
36145
36146 enum wlcore_partitions {
36147 PART_DOWN,
36148 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
36149 index f34b5b2..b5abb9f 100644
36150 --- a/drivers/oprofile/buffer_sync.c
36151 +++ b/drivers/oprofile/buffer_sync.c
36152 @@ -343,7 +343,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
36153 if (cookie == NO_COOKIE)
36154 offset = pc;
36155 if (cookie == INVALID_COOKIE) {
36156 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36157 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36158 offset = pc;
36159 }
36160 if (cookie != last_cookie) {
36161 @@ -387,14 +387,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
36162 /* add userspace sample */
36163
36164 if (!mm) {
36165 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
36166 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
36167 return 0;
36168 }
36169
36170 cookie = lookup_dcookie(mm, s->eip, &offset);
36171
36172 if (cookie == INVALID_COOKIE) {
36173 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
36174 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
36175 return 0;
36176 }
36177
36178 @@ -563,7 +563,7 @@ void sync_buffer(int cpu)
36179 /* ignore backtraces if failed to add a sample */
36180 if (state == sb_bt_start) {
36181 state = sb_bt_ignore;
36182 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
36183 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
36184 }
36185 }
36186 release_mm(mm);
36187 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
36188 index c0cc4e7..44d4e54 100644
36189 --- a/drivers/oprofile/event_buffer.c
36190 +++ b/drivers/oprofile/event_buffer.c
36191 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
36192 }
36193
36194 if (buffer_pos == buffer_size) {
36195 - atomic_inc(&oprofile_stats.event_lost_overflow);
36196 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
36197 return;
36198 }
36199
36200 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
36201 index ed2c3ec..deda85a 100644
36202 --- a/drivers/oprofile/oprof.c
36203 +++ b/drivers/oprofile/oprof.c
36204 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
36205 if (oprofile_ops.switch_events())
36206 return;
36207
36208 - atomic_inc(&oprofile_stats.multiplex_counter);
36209 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
36210 start_switch_worker();
36211 }
36212
36213 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
36214 index 917d28e..d62d981 100644
36215 --- a/drivers/oprofile/oprofile_stats.c
36216 +++ b/drivers/oprofile/oprofile_stats.c
36217 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
36218 cpu_buf->sample_invalid_eip = 0;
36219 }
36220
36221 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
36222 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
36223 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
36224 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
36225 - atomic_set(&oprofile_stats.multiplex_counter, 0);
36226 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
36227 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
36228 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
36229 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
36230 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
36231 }
36232
36233
36234 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
36235 index 38b6fc0..b5cbfce 100644
36236 --- a/drivers/oprofile/oprofile_stats.h
36237 +++ b/drivers/oprofile/oprofile_stats.h
36238 @@ -13,11 +13,11 @@
36239 #include <linux/atomic.h>
36240
36241 struct oprofile_stat_struct {
36242 - atomic_t sample_lost_no_mm;
36243 - atomic_t sample_lost_no_mapping;
36244 - atomic_t bt_lost_no_mapping;
36245 - atomic_t event_lost_overflow;
36246 - atomic_t multiplex_counter;
36247 + atomic_unchecked_t sample_lost_no_mm;
36248 + atomic_unchecked_t sample_lost_no_mapping;
36249 + atomic_unchecked_t bt_lost_no_mapping;
36250 + atomic_unchecked_t event_lost_overflow;
36251 + atomic_unchecked_t multiplex_counter;
36252 };
36253
36254 extern struct oprofile_stat_struct oprofile_stats;
36255 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
36256 index 849357c..b83c1e0 100644
36257 --- a/drivers/oprofile/oprofilefs.c
36258 +++ b/drivers/oprofile/oprofilefs.c
36259 @@ -185,7 +185,7 @@ static const struct file_operations atomic_ro_fops = {
36260
36261
36262 int oprofilefs_create_ro_atomic(struct super_block *sb, struct dentry *root,
36263 - char const *name, atomic_t *val)
36264 + char const *name, atomic_unchecked_t *val)
36265 {
36266 return __oprofilefs_create_file(sb, root, name,
36267 &atomic_ro_fops, 0444, val);
36268 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
36269 index 3f56bc0..707d642 100644
36270 --- a/drivers/parport/procfs.c
36271 +++ b/drivers/parport/procfs.c
36272 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
36273
36274 *ppos += len;
36275
36276 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
36277 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
36278 }
36279
36280 #ifdef CONFIG_PARPORT_1284
36281 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
36282
36283 *ppos += len;
36284
36285 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
36286 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
36287 }
36288 #endif /* IEEE1284.3 support. */
36289
36290 diff --git a/drivers/pci/hotplug/cpci_hotplug.h b/drivers/pci/hotplug/cpci_hotplug.h
36291 index 9fff878..ad0ad53 100644
36292 --- a/drivers/pci/hotplug/cpci_hotplug.h
36293 +++ b/drivers/pci/hotplug/cpci_hotplug.h
36294 @@ -59,7 +59,7 @@ struct cpci_hp_controller_ops {
36295 int (*hardware_test) (struct slot* slot, u32 value);
36296 u8 (*get_power) (struct slot* slot);
36297 int (*set_power) (struct slot* slot, int value);
36298 -};
36299 +} __no_const;
36300
36301 struct cpci_hp_controller {
36302 unsigned int irq;
36303 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
36304 index 76ba8a1..20ca857 100644
36305 --- a/drivers/pci/hotplug/cpqphp_nvram.c
36306 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
36307 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
36308
36309 void compaq_nvram_init (void __iomem *rom_start)
36310 {
36311 +
36312 +#ifndef CONFIG_PAX_KERNEXEC
36313 if (rom_start) {
36314 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
36315 }
36316 +#endif
36317 +
36318 dbg("int15 entry = %p\n", compaq_int15_entry_point);
36319
36320 /* initialize our int15 lock */
36321 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
36322 index b500840..d7159d3 100644
36323 --- a/drivers/pci/pcie/aspm.c
36324 +++ b/drivers/pci/pcie/aspm.c
36325 @@ -27,9 +27,9 @@
36326 #define MODULE_PARAM_PREFIX "pcie_aspm."
36327
36328 /* Note: those are not register definitions */
36329 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
36330 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
36331 -#define ASPM_STATE_L1 (4) /* L1 state */
36332 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
36333 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
36334 +#define ASPM_STATE_L1 (4U) /* L1 state */
36335 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
36336 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
36337
36338 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
36339 index 658ac97..05e1b90 100644
36340 --- a/drivers/pci/probe.c
36341 +++ b/drivers/pci/probe.c
36342 @@ -137,7 +137,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
36343 u16 orig_cmd;
36344 struct pci_bus_region region;
36345
36346 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
36347 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
36348
36349 if (!dev->mmio_always_on) {
36350 pci_read_config_word(dev, PCI_COMMAND, &orig_cmd);
36351 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
36352 index 27911b5..5b6db88 100644
36353 --- a/drivers/pci/proc.c
36354 +++ b/drivers/pci/proc.c
36355 @@ -476,7 +476,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
36356 static int __init pci_proc_init(void)
36357 {
36358 struct pci_dev *dev = NULL;
36359 +
36360 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
36361 +#ifdef CONFIG_GRKERNSEC_PROC_USER
36362 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
36363 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
36364 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
36365 +#endif
36366 +#else
36367 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
36368 +#endif
36369 proc_create("devices", 0, proc_bus_pci_dir,
36370 &proc_bus_pci_dev_operations);
36371 proc_initialized = 1;
36372 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
36373 index 8b5610d..a4c22bb 100644
36374 --- a/drivers/platform/x86/thinkpad_acpi.c
36375 +++ b/drivers/platform/x86/thinkpad_acpi.c
36376 @@ -2094,7 +2094,7 @@ static int hotkey_mask_get(void)
36377 return 0;
36378 }
36379
36380 -void static hotkey_mask_warn_incomplete_mask(void)
36381 +static void hotkey_mask_warn_incomplete_mask(void)
36382 {
36383 /* log only what the user can fix... */
36384 const u32 wantedmask = hotkey_driver_mask &
36385 @@ -2325,11 +2325,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
36386 }
36387 }
36388
36389 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36390 - struct tp_nvram_state *newn,
36391 - const u32 event_mask)
36392 -{
36393 -
36394 #define TPACPI_COMPARE_KEY(__scancode, __member) \
36395 do { \
36396 if ((event_mask & (1 << __scancode)) && \
36397 @@ -2343,36 +2338,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36398 tpacpi_hotkey_send_key(__scancode); \
36399 } while (0)
36400
36401 - void issue_volchange(const unsigned int oldvol,
36402 - const unsigned int newvol)
36403 - {
36404 - unsigned int i = oldvol;
36405 +static void issue_volchange(const unsigned int oldvol,
36406 + const unsigned int newvol,
36407 + const u32 event_mask)
36408 +{
36409 + unsigned int i = oldvol;
36410
36411 - while (i > newvol) {
36412 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36413 - i--;
36414 - }
36415 - while (i < newvol) {
36416 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36417 - i++;
36418 - }
36419 + while (i > newvol) {
36420 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
36421 + i--;
36422 }
36423 + while (i < newvol) {
36424 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36425 + i++;
36426 + }
36427 +}
36428
36429 - void issue_brightnesschange(const unsigned int oldbrt,
36430 - const unsigned int newbrt)
36431 - {
36432 - unsigned int i = oldbrt;
36433 +static void issue_brightnesschange(const unsigned int oldbrt,
36434 + const unsigned int newbrt,
36435 + const u32 event_mask)
36436 +{
36437 + unsigned int i = oldbrt;
36438
36439 - while (i > newbrt) {
36440 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36441 - i--;
36442 - }
36443 - while (i < newbrt) {
36444 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36445 - i++;
36446 - }
36447 + while (i > newbrt) {
36448 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
36449 + i--;
36450 + }
36451 + while (i < newbrt) {
36452 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36453 + i++;
36454 }
36455 +}
36456
36457 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36458 + struct tp_nvram_state *newn,
36459 + const u32 event_mask)
36460 +{
36461 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
36462 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
36463 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
36464 @@ -2406,7 +2407,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36465 oldn->volume_level != newn->volume_level) {
36466 /* recently muted, or repeated mute keypress, or
36467 * multiple presses ending in mute */
36468 - issue_volchange(oldn->volume_level, newn->volume_level);
36469 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36470 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
36471 }
36472 } else {
36473 @@ -2416,7 +2417,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36474 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
36475 }
36476 if (oldn->volume_level != newn->volume_level) {
36477 - issue_volchange(oldn->volume_level, newn->volume_level);
36478 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
36479 } else if (oldn->volume_toggle != newn->volume_toggle) {
36480 /* repeated vol up/down keypress at end of scale ? */
36481 if (newn->volume_level == 0)
36482 @@ -2429,7 +2430,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36483 /* handle brightness */
36484 if (oldn->brightness_level != newn->brightness_level) {
36485 issue_brightnesschange(oldn->brightness_level,
36486 - newn->brightness_level);
36487 + newn->brightness_level,
36488 + event_mask);
36489 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
36490 /* repeated key presses that didn't change state */
36491 if (newn->brightness_level == 0)
36492 @@ -2438,10 +2440,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
36493 && !tp_features.bright_unkfw)
36494 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
36495 }
36496 +}
36497
36498 #undef TPACPI_COMPARE_KEY
36499 #undef TPACPI_MAY_SEND_KEY
36500 -}
36501
36502 /*
36503 * Polling driver
36504 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
36505 index 769d265..a3a05ca 100644
36506 --- a/drivers/pnp/pnpbios/bioscalls.c
36507 +++ b/drivers/pnp/pnpbios/bioscalls.c
36508 @@ -58,7 +58,7 @@ do { \
36509 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
36510 } while(0)
36511
36512 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
36513 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
36514 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
36515
36516 /*
36517 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36518
36519 cpu = get_cpu();
36520 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
36521 +
36522 + pax_open_kernel();
36523 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
36524 + pax_close_kernel();
36525
36526 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
36527 spin_lock_irqsave(&pnp_bios_lock, flags);
36528 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
36529 :"memory");
36530 spin_unlock_irqrestore(&pnp_bios_lock, flags);
36531
36532 + pax_open_kernel();
36533 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
36534 + pax_close_kernel();
36535 +
36536 put_cpu();
36537
36538 /* If we get here and this is set then the PnP BIOS faulted on us. */
36539 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
36540 return status;
36541 }
36542
36543 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
36544 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
36545 {
36546 int i;
36547
36548 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36549 pnp_bios_callpoint.offset = header->fields.pm16offset;
36550 pnp_bios_callpoint.segment = PNP_CS16;
36551
36552 + pax_open_kernel();
36553 +
36554 for_each_possible_cpu(i) {
36555 struct desc_struct *gdt = get_cpu_gdt_table(i);
36556 if (!gdt)
36557 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
36558 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
36559 (unsigned long)__va(header->fields.pm16dseg));
36560 }
36561 +
36562 + pax_close_kernel();
36563 }
36564 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
36565 index b0ecacb..7c9da2e 100644
36566 --- a/drivers/pnp/resource.c
36567 +++ b/drivers/pnp/resource.c
36568 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
36569 return 1;
36570
36571 /* check if the resource is valid */
36572 - if (*irq < 0 || *irq > 15)
36573 + if (*irq > 15)
36574 return 0;
36575
36576 /* check if the resource is reserved */
36577 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
36578 return 1;
36579
36580 /* check if the resource is valid */
36581 - if (*dma < 0 || *dma == 4 || *dma > 7)
36582 + if (*dma == 4 || *dma > 7)
36583 return 0;
36584
36585 /* check if the resource is reserved */
36586 diff --git a/drivers/power/bq27x00_battery.c b/drivers/power/bq27x00_battery.c
36587 index f5d6d37..739f6a9 100644
36588 --- a/drivers/power/bq27x00_battery.c
36589 +++ b/drivers/power/bq27x00_battery.c
36590 @@ -72,7 +72,7 @@
36591 struct bq27x00_device_info;
36592 struct bq27x00_access_methods {
36593 int (*read)(struct bq27x00_device_info *di, u8 reg, bool single);
36594 -};
36595 +} __no_const;
36596
36597 enum bq27x00_chip { BQ27000, BQ27500 };
36598
36599 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
36600 index 8d53174..04c65de 100644
36601 --- a/drivers/regulator/max8660.c
36602 +++ b/drivers/regulator/max8660.c
36603 @@ -333,8 +333,10 @@ static int __devinit max8660_probe(struct i2c_client *client,
36604 max8660->shadow_regs[MAX8660_OVER1] = 5;
36605 } else {
36606 /* Otherwise devices can be toggled via software */
36607 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
36608 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
36609 + pax_open_kernel();
36610 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
36611 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
36612 + pax_close_kernel();
36613 }
36614
36615 /*
36616 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
36617 index 970a233..ee1f241 100644
36618 --- a/drivers/regulator/mc13892-regulator.c
36619 +++ b/drivers/regulator/mc13892-regulator.c
36620 @@ -566,10 +566,12 @@ static int __devinit mc13892_regulator_probe(struct platform_device *pdev)
36621 }
36622 mc13xxx_unlock(mc13892);
36623
36624 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36625 + pax_open_kernel();
36626 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
36627 = mc13892_vcam_set_mode;
36628 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36629 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
36630 = mc13892_vcam_get_mode;
36631 + pax_close_kernel();
36632
36633 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
36634 ARRAY_SIZE(mc13892_regulators));
36635 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
36636 index cace6d3..f623fda 100644
36637 --- a/drivers/rtc/rtc-dev.c
36638 +++ b/drivers/rtc/rtc-dev.c
36639 @@ -14,6 +14,7 @@
36640 #include <linux/module.h>
36641 #include <linux/rtc.h>
36642 #include <linux/sched.h>
36643 +#include <linux/grsecurity.h>
36644 #include "rtc-core.h"
36645
36646 static dev_t rtc_devt;
36647 @@ -345,6 +346,8 @@ static long rtc_dev_ioctl(struct file *file,
36648 if (copy_from_user(&tm, uarg, sizeof(tm)))
36649 return -EFAULT;
36650
36651 + gr_log_timechange();
36652 +
36653 return rtc_set_time(rtc, &tm);
36654
36655 case RTC_PIE_ON:
36656 diff --git a/drivers/scsi/aacraid/aacraid.h b/drivers/scsi/aacraid/aacraid.h
36657 index 3fcf627..f334910 100644
36658 --- a/drivers/scsi/aacraid/aacraid.h
36659 +++ b/drivers/scsi/aacraid/aacraid.h
36660 @@ -492,7 +492,7 @@ struct adapter_ops
36661 int (*adapter_scsi)(struct fib * fib, struct scsi_cmnd * cmd);
36662 /* Administrative operations */
36663 int (*adapter_comm)(struct aac_dev * dev, int comm);
36664 -};
36665 +} __no_const;
36666
36667 /*
36668 * Define which interrupt handler needs to be installed
36669 diff --git a/drivers/scsi/aacraid/linit.c b/drivers/scsi/aacraid/linit.c
36670 index 0d279c44..3d25a97 100644
36671 --- a/drivers/scsi/aacraid/linit.c
36672 +++ b/drivers/scsi/aacraid/linit.c
36673 @@ -93,7 +93,7 @@ static DECLARE_PCI_DEVICE_TABLE(aac_pci_tbl) = {
36674 #elif defined(__devinitconst)
36675 static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36676 #else
36677 -static const struct pci_device_id aac_pci_tbl[] __devinitdata = {
36678 +static const struct pci_device_id aac_pci_tbl[] __devinitconst = {
36679 #endif
36680 { 0x1028, 0x0001, 0x1028, 0x0001, 0, 0, 0 }, /* PERC 2/Si (Iguana/PERC2Si) */
36681 { 0x1028, 0x0002, 0x1028, 0x0002, 0, 0, 1 }, /* PERC 3/Di (Opal/PERC3Di) */
36682 diff --git a/drivers/scsi/aic94xx/aic94xx_init.c b/drivers/scsi/aic94xx/aic94xx_init.c
36683 index ff80552..1c4120c 100644
36684 --- a/drivers/scsi/aic94xx/aic94xx_init.c
36685 +++ b/drivers/scsi/aic94xx/aic94xx_init.c
36686 @@ -1012,7 +1012,7 @@ static struct sas_domain_function_template aic94xx_transport_functions = {
36687 .lldd_ata_set_dmamode = asd_set_dmamode,
36688 };
36689
36690 -static const struct pci_device_id aic94xx_pci_table[] __devinitdata = {
36691 +static const struct pci_device_id aic94xx_pci_table[] __devinitconst = {
36692 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x410),0, 0, 1},
36693 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x412),0, 0, 1},
36694 {PCI_DEVICE(PCI_VENDOR_ID_ADAPTEC2, 0x416),0, 0, 1},
36695 diff --git a/drivers/scsi/bfa/bfa.h b/drivers/scsi/bfa/bfa.h
36696 index 4ad7e36..d004679 100644
36697 --- a/drivers/scsi/bfa/bfa.h
36698 +++ b/drivers/scsi/bfa/bfa.h
36699 @@ -196,7 +196,7 @@ struct bfa_hwif_s {
36700 u32 *end);
36701 int cpe_vec_q0;
36702 int rme_vec_q0;
36703 -};
36704 +} __no_const;
36705 typedef void (*bfa_cb_iocfc_t) (void *cbarg, enum bfa_status status);
36706
36707 struct bfa_faa_cbfn_s {
36708 diff --git a/drivers/scsi/bfa/bfa_fcpim.c b/drivers/scsi/bfa/bfa_fcpim.c
36709 index f0f80e2..8ec946b 100644
36710 --- a/drivers/scsi/bfa/bfa_fcpim.c
36711 +++ b/drivers/scsi/bfa/bfa_fcpim.c
36712 @@ -3715,7 +3715,7 @@ bfa_fcp_attach(struct bfa_s *bfa, void *bfad, struct bfa_iocfc_cfg_s *cfg,
36713
36714 bfa_iotag_attach(fcp);
36715
36716 - fcp->itn_arr = (struct bfa_itn_s *) bfa_mem_kva_curp(fcp);
36717 + fcp->itn_arr = (bfa_itn_s_no_const *) bfa_mem_kva_curp(fcp);
36718 bfa_mem_kva_curp(fcp) = (u8 *)fcp->itn_arr +
36719 (fcp->num_itns * sizeof(struct bfa_itn_s));
36720 memset(fcp->itn_arr, 0,
36721 @@ -3773,7 +3773,7 @@ bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36722 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m))
36723 {
36724 struct bfa_fcp_mod_s *fcp = BFA_FCP_MOD(bfa);
36725 - struct bfa_itn_s *itn;
36726 + bfa_itn_s_no_const *itn;
36727
36728 itn = BFA_ITN_FROM_TAG(fcp, rport->rport_tag);
36729 itn->isr = isr;
36730 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
36731 index 36f26da..38a34a8 100644
36732 --- a/drivers/scsi/bfa/bfa_fcpim.h
36733 +++ b/drivers/scsi/bfa/bfa_fcpim.h
36734 @@ -37,6 +37,7 @@ struct bfa_iotag_s {
36735 struct bfa_itn_s {
36736 bfa_isr_func_t isr;
36737 };
36738 +typedef struct bfa_itn_s __no_const bfa_itn_s_no_const;
36739
36740 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
36741 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
36742 @@ -147,7 +148,7 @@ struct bfa_fcp_mod_s {
36743 struct list_head iotag_tio_free_q; /* free IO resources */
36744 struct list_head iotag_unused_q; /* unused IO resources*/
36745 struct bfa_iotag_s *iotag_arr;
36746 - struct bfa_itn_s *itn_arr;
36747 + bfa_itn_s_no_const *itn_arr;
36748 int num_ioim_reqs;
36749 int num_fwtio_reqs;
36750 int num_itns;
36751 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
36752 index 1a99d4b..e85d64b 100644
36753 --- a/drivers/scsi/bfa/bfa_ioc.h
36754 +++ b/drivers/scsi/bfa/bfa_ioc.h
36755 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
36756 bfa_ioc_disable_cbfn_t disable_cbfn;
36757 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
36758 bfa_ioc_reset_cbfn_t reset_cbfn;
36759 -};
36760 +} __no_const;
36761
36762 /*
36763 * IOC event notification mechanism.
36764 @@ -346,7 +346,7 @@ struct bfa_ioc_hwif_s {
36765 void (*ioc_sync_ack) (struct bfa_ioc_s *ioc);
36766 bfa_boolean_t (*ioc_sync_complete) (struct bfa_ioc_s *ioc);
36767 bfa_boolean_t (*ioc_lpu_read_stat) (struct bfa_ioc_s *ioc);
36768 -};
36769 +} __no_const;
36770
36771 /*
36772 * Queue element to wait for room in request queue. FIFO order is
36773 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
36774 index b48c24f..dac0fbc 100644
36775 --- a/drivers/scsi/hosts.c
36776 +++ b/drivers/scsi/hosts.c
36777 @@ -42,7 +42,7 @@
36778 #include "scsi_logging.h"
36779
36780
36781 -static atomic_t scsi_host_next_hn; /* host_no for next new host */
36782 +static atomic_unchecked_t scsi_host_next_hn; /* host_no for next new host */
36783
36784
36785 static void scsi_host_cls_release(struct device *dev)
36786 @@ -361,7 +361,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
36787 * subtract one because we increment first then return, but we need to
36788 * know what the next host number was before increment
36789 */
36790 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
36791 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
36792 shost->dma_channel = 0xff;
36793
36794 /* These three are default values which can be overridden */
36795 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
36796 index 2b4261c..e01516c 100644
36797 --- a/drivers/scsi/hpsa.c
36798 +++ b/drivers/scsi/hpsa.c
36799 @@ -536,7 +536,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
36800 unsigned long flags;
36801
36802 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36803 - return h->access.command_completed(h, q);
36804 + return h->access->command_completed(h, q);
36805
36806 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
36807 a = rq->head[rq->current_entry];
36808 @@ -3355,7 +3355,7 @@ static void start_io(struct ctlr_info *h)
36809 while (!list_empty(&h->reqQ)) {
36810 c = list_entry(h->reqQ.next, struct CommandList, list);
36811 /* can't do anything if fifo is full */
36812 - if ((h->access.fifo_full(h))) {
36813 + if ((h->access->fifo_full(h))) {
36814 dev_warn(&h->pdev->dev, "fifo full\n");
36815 break;
36816 }
36817 @@ -3377,7 +3377,7 @@ static void start_io(struct ctlr_info *h)
36818
36819 /* Tell the controller execute command */
36820 spin_unlock_irqrestore(&h->lock, flags);
36821 - h->access.submit_command(h, c);
36822 + h->access->submit_command(h, c);
36823 spin_lock_irqsave(&h->lock, flags);
36824 }
36825 spin_unlock_irqrestore(&h->lock, flags);
36826 @@ -3385,17 +3385,17 @@ static void start_io(struct ctlr_info *h)
36827
36828 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
36829 {
36830 - return h->access.command_completed(h, q);
36831 + return h->access->command_completed(h, q);
36832 }
36833
36834 static inline bool interrupt_pending(struct ctlr_info *h)
36835 {
36836 - return h->access.intr_pending(h);
36837 + return h->access->intr_pending(h);
36838 }
36839
36840 static inline long interrupt_not_for_us(struct ctlr_info *h)
36841 {
36842 - return (h->access.intr_pending(h) == 0) ||
36843 + return (h->access->intr_pending(h) == 0) ||
36844 (h->interrupts_enabled == 0);
36845 }
36846
36847 @@ -4299,7 +4299,7 @@ static int __devinit hpsa_pci_init(struct ctlr_info *h)
36848 if (prod_index < 0)
36849 return -ENODEV;
36850 h->product_name = products[prod_index].product_name;
36851 - h->access = *(products[prod_index].access);
36852 + h->access = products[prod_index].access;
36853
36854 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
36855 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
36856 @@ -4581,7 +4581,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
36857
36858 assert_spin_locked(&lockup_detector_lock);
36859 remove_ctlr_from_lockup_detector_list(h);
36860 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36861 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36862 spin_lock_irqsave(&h->lock, flags);
36863 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
36864 spin_unlock_irqrestore(&h->lock, flags);
36865 @@ -4759,7 +4759,7 @@ reinit_after_soft_reset:
36866 }
36867
36868 /* make sure the board interrupts are off */
36869 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36870 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36871
36872 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
36873 goto clean2;
36874 @@ -4793,7 +4793,7 @@ reinit_after_soft_reset:
36875 * fake ones to scoop up any residual completions.
36876 */
36877 spin_lock_irqsave(&h->lock, flags);
36878 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36879 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36880 spin_unlock_irqrestore(&h->lock, flags);
36881 free_irqs(h);
36882 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
36883 @@ -4812,9 +4812,9 @@ reinit_after_soft_reset:
36884 dev_info(&h->pdev->dev, "Board READY.\n");
36885 dev_info(&h->pdev->dev,
36886 "Waiting for stale completions to drain.\n");
36887 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36888 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36889 msleep(10000);
36890 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36891 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36892
36893 rc = controller_reset_failed(h->cfgtable);
36894 if (rc)
36895 @@ -4835,7 +4835,7 @@ reinit_after_soft_reset:
36896 }
36897
36898 /* Turn the interrupts on so we can service requests */
36899 - h->access.set_intr_mask(h, HPSA_INTR_ON);
36900 + h->access->set_intr_mask(h, HPSA_INTR_ON);
36901
36902 hpsa_hba_inquiry(h);
36903 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
36904 @@ -4887,7 +4887,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
36905 * To write all data in the battery backed cache to disks
36906 */
36907 hpsa_flush_cache(h);
36908 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
36909 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
36910 hpsa_free_irqs_and_disable_msix(h);
36911 }
36912
36913 @@ -5056,7 +5056,7 @@ static __devinit void hpsa_enter_performant_mode(struct ctlr_info *h,
36914 return;
36915 }
36916 /* Change the access methods to the performant access methods */
36917 - h->access = SA5_performant_access;
36918 + h->access = &SA5_performant_access;
36919 h->transMethod = CFGTBL_Trans_Performant;
36920 }
36921
36922 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
36923 index 9816479..c5d4e97 100644
36924 --- a/drivers/scsi/hpsa.h
36925 +++ b/drivers/scsi/hpsa.h
36926 @@ -79,7 +79,7 @@ struct ctlr_info {
36927 unsigned int msix_vector;
36928 unsigned int msi_vector;
36929 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
36930 - struct access_method access;
36931 + struct access_method *access;
36932
36933 /* queue and queue Info */
36934 struct list_head reqQ;
36935 diff --git a/drivers/scsi/ips.h b/drivers/scsi/ips.h
36936 index f2df059..a3a9930 100644
36937 --- a/drivers/scsi/ips.h
36938 +++ b/drivers/scsi/ips.h
36939 @@ -1027,7 +1027,7 @@ typedef struct {
36940 int (*intr)(struct ips_ha *);
36941 void (*enableint)(struct ips_ha *);
36942 uint32_t (*statupd)(struct ips_ha *);
36943 -} ips_hw_func_t;
36944 +} __no_const ips_hw_func_t;
36945
36946 typedef struct ips_ha {
36947 uint8_t ha_id[IPS_MAX_CHANNELS+1];
36948 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
36949 index aceffad..c35c08d 100644
36950 --- a/drivers/scsi/libfc/fc_exch.c
36951 +++ b/drivers/scsi/libfc/fc_exch.c
36952 @@ -105,12 +105,12 @@ struct fc_exch_mgr {
36953 * all together if not used XXX
36954 */
36955 struct {
36956 - atomic_t no_free_exch;
36957 - atomic_t no_free_exch_xid;
36958 - atomic_t xid_not_found;
36959 - atomic_t xid_busy;
36960 - atomic_t seq_not_found;
36961 - atomic_t non_bls_resp;
36962 + atomic_unchecked_t no_free_exch;
36963 + atomic_unchecked_t no_free_exch_xid;
36964 + atomic_unchecked_t xid_not_found;
36965 + atomic_unchecked_t xid_busy;
36966 + atomic_unchecked_t seq_not_found;
36967 + atomic_unchecked_t non_bls_resp;
36968 } stats;
36969 };
36970
36971 @@ -719,7 +719,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
36972 /* allocate memory for exchange */
36973 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
36974 if (!ep) {
36975 - atomic_inc(&mp->stats.no_free_exch);
36976 + atomic_inc_unchecked(&mp->stats.no_free_exch);
36977 goto out;
36978 }
36979 memset(ep, 0, sizeof(*ep));
36980 @@ -780,7 +780,7 @@ out:
36981 return ep;
36982 err:
36983 spin_unlock_bh(&pool->lock);
36984 - atomic_inc(&mp->stats.no_free_exch_xid);
36985 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
36986 mempool_free(ep, mp->ep_pool);
36987 return NULL;
36988 }
36989 @@ -923,7 +923,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36990 xid = ntohs(fh->fh_ox_id); /* we originated exch */
36991 ep = fc_exch_find(mp, xid);
36992 if (!ep) {
36993 - atomic_inc(&mp->stats.xid_not_found);
36994 + atomic_inc_unchecked(&mp->stats.xid_not_found);
36995 reject = FC_RJT_OX_ID;
36996 goto out;
36997 }
36998 @@ -953,7 +953,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
36999 ep = fc_exch_find(mp, xid);
37000 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
37001 if (ep) {
37002 - atomic_inc(&mp->stats.xid_busy);
37003 + atomic_inc_unchecked(&mp->stats.xid_busy);
37004 reject = FC_RJT_RX_ID;
37005 goto rel;
37006 }
37007 @@ -964,7 +964,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37008 }
37009 xid = ep->xid; /* get our XID */
37010 } else if (!ep) {
37011 - atomic_inc(&mp->stats.xid_not_found);
37012 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37013 reject = FC_RJT_RX_ID; /* XID not found */
37014 goto out;
37015 }
37016 @@ -981,7 +981,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
37017 } else {
37018 sp = &ep->seq;
37019 if (sp->id != fh->fh_seq_id) {
37020 - atomic_inc(&mp->stats.seq_not_found);
37021 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37022 if (f_ctl & FC_FC_END_SEQ) {
37023 /*
37024 * Update sequence_id based on incoming last
37025 @@ -1431,22 +1431,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37026
37027 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
37028 if (!ep) {
37029 - atomic_inc(&mp->stats.xid_not_found);
37030 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37031 goto out;
37032 }
37033 if (ep->esb_stat & ESB_ST_COMPLETE) {
37034 - atomic_inc(&mp->stats.xid_not_found);
37035 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37036 goto rel;
37037 }
37038 if (ep->rxid == FC_XID_UNKNOWN)
37039 ep->rxid = ntohs(fh->fh_rx_id);
37040 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
37041 - atomic_inc(&mp->stats.xid_not_found);
37042 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37043 goto rel;
37044 }
37045 if (ep->did != ntoh24(fh->fh_s_id) &&
37046 ep->did != FC_FID_FLOGI) {
37047 - atomic_inc(&mp->stats.xid_not_found);
37048 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37049 goto rel;
37050 }
37051 sof = fr_sof(fp);
37052 @@ -1455,7 +1455,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37053 sp->ssb_stat |= SSB_ST_RESP;
37054 sp->id = fh->fh_seq_id;
37055 } else if (sp->id != fh->fh_seq_id) {
37056 - atomic_inc(&mp->stats.seq_not_found);
37057 + atomic_inc_unchecked(&mp->stats.seq_not_found);
37058 goto rel;
37059 }
37060
37061 @@ -1519,9 +1519,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
37062 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
37063
37064 if (!sp)
37065 - atomic_inc(&mp->stats.xid_not_found);
37066 + atomic_inc_unchecked(&mp->stats.xid_not_found);
37067 else
37068 - atomic_inc(&mp->stats.non_bls_resp);
37069 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
37070
37071 fc_frame_free(fp);
37072 }
37073 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
37074 index d109cc3..09f4e7d 100644
37075 --- a/drivers/scsi/libsas/sas_ata.c
37076 +++ b/drivers/scsi/libsas/sas_ata.c
37077 @@ -529,7 +529,7 @@ static struct ata_port_operations sas_sata_ops = {
37078 .postreset = ata_std_postreset,
37079 .error_handler = ata_std_error_handler,
37080 .post_internal_cmd = sas_ata_post_internal,
37081 - .qc_defer = ata_std_qc_defer,
37082 + .qc_defer = ata_std_qc_defer,
37083 .qc_prep = ata_noop_qc_prep,
37084 .qc_issue = sas_ata_qc_issue,
37085 .qc_fill_rtf = sas_ata_qc_fill_rtf,
37086 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
37087 index e5da6da..c888d48 100644
37088 --- a/drivers/scsi/lpfc/lpfc.h
37089 +++ b/drivers/scsi/lpfc/lpfc.h
37090 @@ -416,7 +416,7 @@ struct lpfc_vport {
37091 struct dentry *debug_nodelist;
37092 struct dentry *vport_debugfs_root;
37093 struct lpfc_debugfs_trc *disc_trc;
37094 - atomic_t disc_trc_cnt;
37095 + atomic_unchecked_t disc_trc_cnt;
37096 #endif
37097 uint8_t stat_data_enabled;
37098 uint8_t stat_data_blocked;
37099 @@ -830,8 +830,8 @@ struct lpfc_hba {
37100 struct timer_list fabric_block_timer;
37101 unsigned long bit_flags;
37102 #define FABRIC_COMANDS_BLOCKED 0
37103 - atomic_t num_rsrc_err;
37104 - atomic_t num_cmd_success;
37105 + atomic_unchecked_t num_rsrc_err;
37106 + atomic_unchecked_t num_cmd_success;
37107 unsigned long last_rsrc_error_time;
37108 unsigned long last_ramp_down_time;
37109 unsigned long last_ramp_up_time;
37110 @@ -867,7 +867,7 @@ struct lpfc_hba {
37111
37112 struct dentry *debug_slow_ring_trc;
37113 struct lpfc_debugfs_trc *slow_ring_trc;
37114 - atomic_t slow_ring_trc_cnt;
37115 + atomic_unchecked_t slow_ring_trc_cnt;
37116 /* iDiag debugfs sub-directory */
37117 struct dentry *idiag_root;
37118 struct dentry *idiag_pci_cfg;
37119 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
37120 index 3217d63..c417981 100644
37121 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
37122 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
37123 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
37124
37125 #include <linux/debugfs.h>
37126
37127 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37128 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
37129 static unsigned long lpfc_debugfs_start_time = 0L;
37130
37131 /* iDiag */
37132 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
37133 lpfc_debugfs_enable = 0;
37134
37135 len = 0;
37136 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
37137 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
37138 (lpfc_debugfs_max_disc_trc - 1);
37139 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
37140 dtp = vport->disc_trc + i;
37141 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
37142 lpfc_debugfs_enable = 0;
37143
37144 len = 0;
37145 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
37146 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
37147 (lpfc_debugfs_max_slow_ring_trc - 1);
37148 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
37149 dtp = phba->slow_ring_trc + i;
37150 @@ -636,14 +636,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
37151 !vport || !vport->disc_trc)
37152 return;
37153
37154 - index = atomic_inc_return(&vport->disc_trc_cnt) &
37155 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
37156 (lpfc_debugfs_max_disc_trc - 1);
37157 dtp = vport->disc_trc + index;
37158 dtp->fmt = fmt;
37159 dtp->data1 = data1;
37160 dtp->data2 = data2;
37161 dtp->data3 = data3;
37162 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37163 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37164 dtp->jif = jiffies;
37165 #endif
37166 return;
37167 @@ -674,14 +674,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
37168 !phba || !phba->slow_ring_trc)
37169 return;
37170
37171 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
37172 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
37173 (lpfc_debugfs_max_slow_ring_trc - 1);
37174 dtp = phba->slow_ring_trc + index;
37175 dtp->fmt = fmt;
37176 dtp->data1 = data1;
37177 dtp->data2 = data2;
37178 dtp->data3 = data3;
37179 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
37180 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
37181 dtp->jif = jiffies;
37182 #endif
37183 return;
37184 @@ -4090,7 +4090,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37185 "slow_ring buffer\n");
37186 goto debug_failed;
37187 }
37188 - atomic_set(&phba->slow_ring_trc_cnt, 0);
37189 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
37190 memset(phba->slow_ring_trc, 0,
37191 (sizeof(struct lpfc_debugfs_trc) *
37192 lpfc_debugfs_max_slow_ring_trc));
37193 @@ -4136,7 +4136,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
37194 "buffer\n");
37195 goto debug_failed;
37196 }
37197 - atomic_set(&vport->disc_trc_cnt, 0);
37198 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
37199
37200 snprintf(name, sizeof(name), "discovery_trace");
37201 vport->debug_disc_trc =
37202 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
37203 index 411ed48..967f553 100644
37204 --- a/drivers/scsi/lpfc/lpfc_init.c
37205 +++ b/drivers/scsi/lpfc/lpfc_init.c
37206 @@ -10341,8 +10341,10 @@ lpfc_init(void)
37207 "misc_register returned with status %d", error);
37208
37209 if (lpfc_enable_npiv) {
37210 - lpfc_transport_functions.vport_create = lpfc_vport_create;
37211 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37212 + pax_open_kernel();
37213 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
37214 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
37215 + pax_close_kernel();
37216 }
37217 lpfc_transport_template =
37218 fc_attach_transport(&lpfc_transport_functions);
37219 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
37220 index 66e0906..1620281 100644
37221 --- a/drivers/scsi/lpfc/lpfc_scsi.c
37222 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
37223 @@ -311,7 +311,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
37224 uint32_t evt_posted;
37225
37226 spin_lock_irqsave(&phba->hbalock, flags);
37227 - atomic_inc(&phba->num_rsrc_err);
37228 + atomic_inc_unchecked(&phba->num_rsrc_err);
37229 phba->last_rsrc_error_time = jiffies;
37230
37231 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
37232 @@ -352,7 +352,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
37233 unsigned long flags;
37234 struct lpfc_hba *phba = vport->phba;
37235 uint32_t evt_posted;
37236 - atomic_inc(&phba->num_cmd_success);
37237 + atomic_inc_unchecked(&phba->num_cmd_success);
37238
37239 if (vport->cfg_lun_queue_depth <= queue_depth)
37240 return;
37241 @@ -396,8 +396,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37242 unsigned long num_rsrc_err, num_cmd_success;
37243 int i;
37244
37245 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
37246 - num_cmd_success = atomic_read(&phba->num_cmd_success);
37247 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
37248 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
37249
37250 /*
37251 * The error and success command counters are global per
37252 @@ -425,8 +425,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
37253 }
37254 }
37255 lpfc_destroy_vport_work_array(phba, vports);
37256 - atomic_set(&phba->num_rsrc_err, 0);
37257 - atomic_set(&phba->num_cmd_success, 0);
37258 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37259 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37260 }
37261
37262 /**
37263 @@ -460,8 +460,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
37264 }
37265 }
37266 lpfc_destroy_vport_work_array(phba, vports);
37267 - atomic_set(&phba->num_rsrc_err, 0);
37268 - atomic_set(&phba->num_cmd_success, 0);
37269 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
37270 + atomic_set_unchecked(&phba->num_cmd_success, 0);
37271 }
37272
37273 /**
37274 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
37275 index ea8a0b4..812a124 100644
37276 --- a/drivers/scsi/pmcraid.c
37277 +++ b/drivers/scsi/pmcraid.c
37278 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
37279 res->scsi_dev = scsi_dev;
37280 scsi_dev->hostdata = res;
37281 res->change_detected = 0;
37282 - atomic_set(&res->read_failures, 0);
37283 - atomic_set(&res->write_failures, 0);
37284 + atomic_set_unchecked(&res->read_failures, 0);
37285 + atomic_set_unchecked(&res->write_failures, 0);
37286 rc = 0;
37287 }
37288 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
37289 @@ -2676,9 +2676,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
37290
37291 /* If this was a SCSI read/write command keep count of errors */
37292 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
37293 - atomic_inc(&res->read_failures);
37294 + atomic_inc_unchecked(&res->read_failures);
37295 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
37296 - atomic_inc(&res->write_failures);
37297 + atomic_inc_unchecked(&res->write_failures);
37298
37299 if (!RES_IS_GSCSI(res->cfg_entry) &&
37300 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
37301 @@ -3534,7 +3534,7 @@ static int pmcraid_queuecommand_lck(
37302 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37303 * hrrq_id assigned here in queuecommand
37304 */
37305 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37306 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37307 pinstance->num_hrrq;
37308 cmd->cmd_done = pmcraid_io_done;
37309
37310 @@ -3859,7 +3859,7 @@ static long pmcraid_ioctl_passthrough(
37311 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
37312 * hrrq_id assigned here in queuecommand
37313 */
37314 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
37315 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
37316 pinstance->num_hrrq;
37317
37318 if (request_size) {
37319 @@ -4497,7 +4497,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
37320
37321 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
37322 /* add resources only after host is added into system */
37323 - if (!atomic_read(&pinstance->expose_resources))
37324 + if (!atomic_read_unchecked(&pinstance->expose_resources))
37325 return;
37326
37327 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
37328 @@ -5331,8 +5331,8 @@ static int __devinit pmcraid_init_instance(
37329 init_waitqueue_head(&pinstance->reset_wait_q);
37330
37331 atomic_set(&pinstance->outstanding_cmds, 0);
37332 - atomic_set(&pinstance->last_message_id, 0);
37333 - atomic_set(&pinstance->expose_resources, 0);
37334 + atomic_set_unchecked(&pinstance->last_message_id, 0);
37335 + atomic_set_unchecked(&pinstance->expose_resources, 0);
37336
37337 INIT_LIST_HEAD(&pinstance->free_res_q);
37338 INIT_LIST_HEAD(&pinstance->used_res_q);
37339 @@ -6047,7 +6047,7 @@ static int __devinit pmcraid_probe(
37340 /* Schedule worker thread to handle CCN and take care of adding and
37341 * removing devices to OS
37342 */
37343 - atomic_set(&pinstance->expose_resources, 1);
37344 + atomic_set_unchecked(&pinstance->expose_resources, 1);
37345 schedule_work(&pinstance->worker_q);
37346 return rc;
37347
37348 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
37349 index e1d150f..6c6df44 100644
37350 --- a/drivers/scsi/pmcraid.h
37351 +++ b/drivers/scsi/pmcraid.h
37352 @@ -748,7 +748,7 @@ struct pmcraid_instance {
37353 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
37354
37355 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
37356 - atomic_t last_message_id;
37357 + atomic_unchecked_t last_message_id;
37358
37359 /* configuration table */
37360 struct pmcraid_config_table *cfg_table;
37361 @@ -777,7 +777,7 @@ struct pmcraid_instance {
37362 atomic_t outstanding_cmds;
37363
37364 /* should add/delete resources to mid-layer now ?*/
37365 - atomic_t expose_resources;
37366 + atomic_unchecked_t expose_resources;
37367
37368
37369
37370 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
37371 struct pmcraid_config_table_entry_ext cfg_entry_ext;
37372 };
37373 struct scsi_device *scsi_dev; /* Link scsi_device structure */
37374 - atomic_t read_failures; /* count of failed READ commands */
37375 - atomic_t write_failures; /* count of failed WRITE commands */
37376 + atomic_unchecked_t read_failures; /* count of failed READ commands */
37377 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
37378
37379 /* To indicate add/delete/modify during CCN */
37380 u8 change_detected;
37381 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
37382 index 5ab9530..2dd80f7 100644
37383 --- a/drivers/scsi/qla2xxx/qla_attr.c
37384 +++ b/drivers/scsi/qla2xxx/qla_attr.c
37385 @@ -1855,7 +1855,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
37386 return 0;
37387 }
37388
37389 -struct fc_function_template qla2xxx_transport_functions = {
37390 +fc_function_template_no_const qla2xxx_transport_functions = {
37391
37392 .show_host_node_name = 1,
37393 .show_host_port_name = 1,
37394 @@ -1902,7 +1902,7 @@ struct fc_function_template qla2xxx_transport_functions = {
37395 .bsg_timeout = qla24xx_bsg_timeout,
37396 };
37397
37398 -struct fc_function_template qla2xxx_transport_vport_functions = {
37399 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
37400
37401 .show_host_node_name = 1,
37402 .show_host_port_name = 1,
37403 diff --git a/drivers/scsi/qla2xxx/qla_def.h b/drivers/scsi/qla2xxx/qla_def.h
37404 index 39007f5..7fafc64 100644
37405 --- a/drivers/scsi/qla2xxx/qla_def.h
37406 +++ b/drivers/scsi/qla2xxx/qla_def.h
37407 @@ -2284,7 +2284,7 @@ struct isp_operations {
37408 int (*start_scsi) (srb_t *);
37409 int (*abort_isp) (struct scsi_qla_host *);
37410 int (*iospace_config)(struct qla_hw_data*);
37411 -};
37412 +} __no_const;
37413
37414 /* MSI-X Support *************************************************************/
37415
37416 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
37417 index 9eacd2d..d79629c 100644
37418 --- a/drivers/scsi/qla2xxx/qla_gbl.h
37419 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
37420 @@ -484,8 +484,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
37421 struct device_attribute;
37422 extern struct device_attribute *qla2x00_host_attrs[];
37423 struct fc_function_template;
37424 -extern struct fc_function_template qla2xxx_transport_functions;
37425 -extern struct fc_function_template qla2xxx_transport_vport_functions;
37426 +extern fc_function_template_no_const qla2xxx_transport_functions;
37427 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
37428 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
37429 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
37430 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
37431 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
37432 index 96a5616..eeb185a 100644
37433 --- a/drivers/scsi/qla4xxx/ql4_def.h
37434 +++ b/drivers/scsi/qla4xxx/ql4_def.h
37435 @@ -268,7 +268,7 @@ struct ddb_entry {
37436 * (4000 only) */
37437 atomic_t relogin_timer; /* Max Time to wait for
37438 * relogin to complete */
37439 - atomic_t relogin_retry_count; /* Num of times relogin has been
37440 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
37441 * retried */
37442 uint32_t default_time2wait; /* Default Min time between
37443 * relogins (+aens) */
37444 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
37445 index cd15678..f7e6846 100644
37446 --- a/drivers/scsi/qla4xxx/ql4_os.c
37447 +++ b/drivers/scsi/qla4xxx/ql4_os.c
37448 @@ -2615,12 +2615,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
37449 */
37450 if (!iscsi_is_session_online(cls_sess)) {
37451 /* Reset retry relogin timer */
37452 - atomic_inc(&ddb_entry->relogin_retry_count);
37453 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
37454 DEBUG2(ql4_printk(KERN_INFO, ha,
37455 "%s: index[%d] relogin timed out-retrying"
37456 " relogin (%d), retry (%d)\n", __func__,
37457 ddb_entry->fw_ddb_index,
37458 - atomic_read(&ddb_entry->relogin_retry_count),
37459 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
37460 ddb_entry->default_time2wait + 4));
37461 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
37462 atomic_set(&ddb_entry->retry_relogin_timer,
37463 @@ -4517,7 +4517,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
37464
37465 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
37466 atomic_set(&ddb_entry->relogin_timer, 0);
37467 - atomic_set(&ddb_entry->relogin_retry_count, 0);
37468 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
37469 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
37470 ddb_entry->default_relogin_timeout =
37471 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
37472 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
37473 index bbbc9c9..ce22f77 100644
37474 --- a/drivers/scsi/scsi.c
37475 +++ b/drivers/scsi/scsi.c
37476 @@ -659,7 +659,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
37477 unsigned long timeout;
37478 int rtn = 0;
37479
37480 - atomic_inc(&cmd->device->iorequest_cnt);
37481 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37482
37483 /* check if the device is still usable */
37484 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
37485 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
37486 index dae3873..bb4bee6 100644
37487 --- a/drivers/scsi/scsi_lib.c
37488 +++ b/drivers/scsi/scsi_lib.c
37489 @@ -1425,7 +1425,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
37490 shost = sdev->host;
37491 scsi_init_cmd_errh(cmd);
37492 cmd->result = DID_NO_CONNECT << 16;
37493 - atomic_inc(&cmd->device->iorequest_cnt);
37494 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
37495
37496 /*
37497 * SCSI request completion path will do scsi_device_unbusy(),
37498 @@ -1451,9 +1451,9 @@ static void scsi_softirq_done(struct request *rq)
37499
37500 INIT_LIST_HEAD(&cmd->eh_entry);
37501
37502 - atomic_inc(&cmd->device->iodone_cnt);
37503 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
37504 if (cmd->result)
37505 - atomic_inc(&cmd->device->ioerr_cnt);
37506 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
37507
37508 disposition = scsi_decide_disposition(cmd);
37509 if (disposition != SUCCESS &&
37510 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
37511 index bb7c482..7551a95 100644
37512 --- a/drivers/scsi/scsi_sysfs.c
37513 +++ b/drivers/scsi/scsi_sysfs.c
37514 @@ -660,7 +660,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
37515 char *buf) \
37516 { \
37517 struct scsi_device *sdev = to_scsi_device(dev); \
37518 - unsigned long long count = atomic_read(&sdev->field); \
37519 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
37520 return snprintf(buf, 20, "0x%llx\n", count); \
37521 } \
37522 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
37523 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
37524 index 84a1fdf..693b0d6 100644
37525 --- a/drivers/scsi/scsi_tgt_lib.c
37526 +++ b/drivers/scsi/scsi_tgt_lib.c
37527 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
37528 int err;
37529
37530 dprintk("%lx %u\n", uaddr, len);
37531 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
37532 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
37533 if (err) {
37534 /*
37535 * TODO: need to fixup sg_tablesize, max_segment_size,
37536 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
37537 index 5797604..289a5b5 100644
37538 --- a/drivers/scsi/scsi_transport_fc.c
37539 +++ b/drivers/scsi/scsi_transport_fc.c
37540 @@ -498,7 +498,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
37541 * Netlink Infrastructure
37542 */
37543
37544 -static atomic_t fc_event_seq;
37545 +static atomic_unchecked_t fc_event_seq;
37546
37547 /**
37548 * fc_get_event_number - Obtain the next sequential FC event number
37549 @@ -511,7 +511,7 @@ static atomic_t fc_event_seq;
37550 u32
37551 fc_get_event_number(void)
37552 {
37553 - return atomic_add_return(1, &fc_event_seq);
37554 + return atomic_add_return_unchecked(1, &fc_event_seq);
37555 }
37556 EXPORT_SYMBOL(fc_get_event_number);
37557
37558 @@ -659,7 +659,7 @@ static __init int fc_transport_init(void)
37559 {
37560 int error;
37561
37562 - atomic_set(&fc_event_seq, 0);
37563 + atomic_set_unchecked(&fc_event_seq, 0);
37564
37565 error = transport_class_register(&fc_host_class);
37566 if (error)
37567 @@ -849,7 +849,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
37568 char *cp;
37569
37570 *val = simple_strtoul(buf, &cp, 0);
37571 - if ((*cp && (*cp != '\n')) || (*val < 0))
37572 + if (*cp && (*cp != '\n'))
37573 return -EINVAL;
37574 /*
37575 * Check for overflow; dev_loss_tmo is u32
37576 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
37577 index 1cf640e..78e9014 100644
37578 --- a/drivers/scsi/scsi_transport_iscsi.c
37579 +++ b/drivers/scsi/scsi_transport_iscsi.c
37580 @@ -79,7 +79,7 @@ struct iscsi_internal {
37581 struct transport_container session_cont;
37582 };
37583
37584 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
37585 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
37586 static struct workqueue_struct *iscsi_eh_timer_workq;
37587
37588 static DEFINE_IDA(iscsi_sess_ida);
37589 @@ -1064,7 +1064,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
37590 int err;
37591
37592 ihost = shost->shost_data;
37593 - session->sid = atomic_add_return(1, &iscsi_session_nr);
37594 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
37595
37596 if (target_id == ISCSI_MAX_TARGET) {
37597 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
37598 @@ -2940,7 +2940,7 @@ static __init int iscsi_transport_init(void)
37599 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
37600 ISCSI_TRANSPORT_VERSION);
37601
37602 - atomic_set(&iscsi_session_nr, 0);
37603 + atomic_set_unchecked(&iscsi_session_nr, 0);
37604
37605 err = class_register(&iscsi_transport_class);
37606 if (err)
37607 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
37608 index 21a045e..ec89e03 100644
37609 --- a/drivers/scsi/scsi_transport_srp.c
37610 +++ b/drivers/scsi/scsi_transport_srp.c
37611 @@ -33,7 +33,7 @@
37612 #include "scsi_transport_srp_internal.h"
37613
37614 struct srp_host_attrs {
37615 - atomic_t next_port_id;
37616 + atomic_unchecked_t next_port_id;
37617 };
37618 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
37619
37620 @@ -62,7 +62,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
37621 struct Scsi_Host *shost = dev_to_shost(dev);
37622 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
37623
37624 - atomic_set(&srp_host->next_port_id, 0);
37625 + atomic_set_unchecked(&srp_host->next_port_id, 0);
37626 return 0;
37627 }
37628
37629 @@ -211,7 +211,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
37630 memcpy(rport->port_id, ids->port_id, sizeof(rport->port_id));
37631 rport->roles = ids->roles;
37632
37633 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
37634 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
37635 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
37636
37637 transport_setup_device(&rport->dev);
37638 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
37639 index 9c5c5f2..8414557 100644
37640 --- a/drivers/scsi/sg.c
37641 +++ b/drivers/scsi/sg.c
37642 @@ -1101,7 +1101,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
37643 sdp->disk->disk_name,
37644 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
37645 NULL,
37646 - (char *)arg);
37647 + (char __user *)arg);
37648 case BLKTRACESTART:
37649 return blk_trace_startstop(sdp->device->request_queue, 1);
37650 case BLKTRACESTOP:
37651 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
37652 index 1041cb8..4a946fa 100644
37653 --- a/drivers/spi/spi.c
37654 +++ b/drivers/spi/spi.c
37655 @@ -1453,7 +1453,7 @@ int spi_bus_unlock(struct spi_master *master)
37656 EXPORT_SYMBOL_GPL(spi_bus_unlock);
37657
37658 /* portable code must never pass more than 32 bytes */
37659 -#define SPI_BUFSIZ max(32,SMP_CACHE_BYTES)
37660 +#define SPI_BUFSIZ max(32UL,SMP_CACHE_BYTES)
37661
37662 static u8 *buf;
37663
37664 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
37665 index 34afc16..ffe44dd 100644
37666 --- a/drivers/staging/octeon/ethernet-rx.c
37667 +++ b/drivers/staging/octeon/ethernet-rx.c
37668 @@ -421,11 +421,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37669 /* Increment RX stats for virtual ports */
37670 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
37671 #ifdef CONFIG_64BIT
37672 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
37673 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
37674 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
37675 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
37676 #else
37677 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
37678 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
37679 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
37680 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
37681 #endif
37682 }
37683 netif_receive_skb(skb);
37684 @@ -437,9 +437,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
37685 dev->name);
37686 */
37687 #ifdef CONFIG_64BIT
37688 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
37689 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37690 #else
37691 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
37692 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
37693 #endif
37694 dev_kfree_skb_irq(skb);
37695 }
37696 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
37697 index 18f7a79..cc3bc24 100644
37698 --- a/drivers/staging/octeon/ethernet.c
37699 +++ b/drivers/staging/octeon/ethernet.c
37700 @@ -259,11 +259,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
37701 * since the RX tasklet also increments it.
37702 */
37703 #ifdef CONFIG_64BIT
37704 - atomic64_add(rx_status.dropped_packets,
37705 - (atomic64_t *)&priv->stats.rx_dropped);
37706 + atomic64_add_unchecked(rx_status.dropped_packets,
37707 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
37708 #else
37709 - atomic_add(rx_status.dropped_packets,
37710 - (atomic_t *)&priv->stats.rx_dropped);
37711 + atomic_add_unchecked(rx_status.dropped_packets,
37712 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
37713 #endif
37714 }
37715
37716 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
37717 index dc23395..cf7e9b1 100644
37718 --- a/drivers/staging/rtl8712/rtl871x_io.h
37719 +++ b/drivers/staging/rtl8712/rtl871x_io.h
37720 @@ -108,7 +108,7 @@ struct _io_ops {
37721 u8 *pmem);
37722 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
37723 u8 *pmem);
37724 -};
37725 +} __no_const;
37726
37727 struct io_req {
37728 struct list_head list;
37729 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
37730 index c7b5e8b..783d6cb 100644
37731 --- a/drivers/staging/sbe-2t3e3/netdev.c
37732 +++ b/drivers/staging/sbe-2t3e3/netdev.c
37733 @@ -51,7 +51,7 @@ int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37734 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
37735
37736 if (rlen)
37737 - if (copy_to_user(data, &resp, rlen))
37738 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
37739 return -EFAULT;
37740
37741 return 0;
37742 diff --git a/drivers/staging/speakup/speakup_soft.c b/drivers/staging/speakup/speakup_soft.c
37743 index 42cdafe..2769103 100644
37744 --- a/drivers/staging/speakup/speakup_soft.c
37745 +++ b/drivers/staging/speakup/speakup_soft.c
37746 @@ -241,11 +241,11 @@ static ssize_t softsynth_read(struct file *fp, char *buf, size_t count,
37747 break;
37748 } else if (!initialized) {
37749 if (*init) {
37750 - ch = *init;
37751 init++;
37752 } else {
37753 initialized = 1;
37754 }
37755 + ch = *init;
37756 } else {
37757 ch = synth_buffer_getc();
37758 }
37759 diff --git a/drivers/staging/usbip/usbip_common.h b/drivers/staging/usbip/usbip_common.h
37760 index 5d89c0f..9261317 100644
37761 --- a/drivers/staging/usbip/usbip_common.h
37762 +++ b/drivers/staging/usbip/usbip_common.h
37763 @@ -289,7 +289,7 @@ struct usbip_device {
37764 void (*shutdown)(struct usbip_device *);
37765 void (*reset)(struct usbip_device *);
37766 void (*unusable)(struct usbip_device *);
37767 - } eh_ops;
37768 + } __no_const eh_ops;
37769 };
37770
37771 #define kthread_get_run(threadfn, data, namefmt, ...) \
37772 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
37773 index 88b3298..3783eee 100644
37774 --- a/drivers/staging/usbip/vhci.h
37775 +++ b/drivers/staging/usbip/vhci.h
37776 @@ -88,7 +88,7 @@ struct vhci_hcd {
37777 unsigned resuming:1;
37778 unsigned long re_timeout;
37779
37780 - atomic_t seqnum;
37781 + atomic_unchecked_t seqnum;
37782
37783 /*
37784 * NOTE:
37785 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
37786 index f708cba..2de6d72 100644
37787 --- a/drivers/staging/usbip/vhci_hcd.c
37788 +++ b/drivers/staging/usbip/vhci_hcd.c
37789 @@ -488,7 +488,7 @@ static void vhci_tx_urb(struct urb *urb)
37790 return;
37791 }
37792
37793 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
37794 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37795 if (priv->seqnum == 0xffff)
37796 dev_info(&urb->dev->dev, "seqnum max\n");
37797
37798 @@ -740,7 +740,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
37799 return -ENOMEM;
37800 }
37801
37802 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
37803 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
37804 if (unlink->seqnum == 0xffff)
37805 pr_info("seqnum max\n");
37806
37807 @@ -928,7 +928,7 @@ static int vhci_start(struct usb_hcd *hcd)
37808 vdev->rhport = rhport;
37809 }
37810
37811 - atomic_set(&vhci->seqnum, 0);
37812 + atomic_set_unchecked(&vhci->seqnum, 0);
37813 spin_lock_init(&vhci->lock);
37814
37815 hcd->power_budget = 0; /* no limit */
37816 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
37817 index f0eaf04..5a82e06 100644
37818 --- a/drivers/staging/usbip/vhci_rx.c
37819 +++ b/drivers/staging/usbip/vhci_rx.c
37820 @@ -77,7 +77,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
37821 if (!urb) {
37822 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
37823 pr_info("max seqnum %d\n",
37824 - atomic_read(&the_controller->seqnum));
37825 + atomic_read_unchecked(&the_controller->seqnum));
37826 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
37827 return;
37828 }
37829 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
37830 index 7735027..30eed13 100644
37831 --- a/drivers/staging/vt6655/hostap.c
37832 +++ b/drivers/staging/vt6655/hostap.c
37833 @@ -79,14 +79,13 @@ static int msglevel =MSG_LEVEL_INFO;
37834 *
37835 */
37836
37837 +static net_device_ops_no_const apdev_netdev_ops;
37838 +
37839 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37840 {
37841 PSDevice apdev_priv;
37842 struct net_device *dev = pDevice->dev;
37843 int ret;
37844 - const struct net_device_ops apdev_netdev_ops = {
37845 - .ndo_start_xmit = pDevice->tx_80211,
37846 - };
37847
37848 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37849
37850 @@ -98,6 +97,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37851 *apdev_priv = *pDevice;
37852 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37853
37854 + /* only half broken now */
37855 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37856 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37857
37858 pDevice->apdev->type = ARPHRD_IEEE80211;
37859 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
37860 index 51b5adf..098e320 100644
37861 --- a/drivers/staging/vt6656/hostap.c
37862 +++ b/drivers/staging/vt6656/hostap.c
37863 @@ -80,14 +80,13 @@ static int msglevel =MSG_LEVEL_INFO;
37864 *
37865 */
37866
37867 +static net_device_ops_no_const apdev_netdev_ops;
37868 +
37869 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37870 {
37871 PSDevice apdev_priv;
37872 struct net_device *dev = pDevice->dev;
37873 int ret;
37874 - const struct net_device_ops apdev_netdev_ops = {
37875 - .ndo_start_xmit = pDevice->tx_80211,
37876 - };
37877
37878 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
37879
37880 @@ -99,6 +98,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
37881 *apdev_priv = *pDevice;
37882 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
37883
37884 + /* only half broken now */
37885 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
37886 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
37887
37888 pDevice->apdev->type = ARPHRD_IEEE80211;
37889 diff --git a/drivers/staging/wlan-ng/hfa384x_usb.c b/drivers/staging/wlan-ng/hfa384x_usb.c
37890 index 7843dfd..3db105f 100644
37891 --- a/drivers/staging/wlan-ng/hfa384x_usb.c
37892 +++ b/drivers/staging/wlan-ng/hfa384x_usb.c
37893 @@ -204,7 +204,7 @@ static void unlocked_usbctlx_complete(hfa384x_t *hw, hfa384x_usbctlx_t *ctlx);
37894
37895 struct usbctlx_completor {
37896 int (*complete) (struct usbctlx_completor *);
37897 -};
37898 +} __no_const;
37899
37900 static int
37901 hfa384x_usbctlx_complete_sync(hfa384x_t *hw,
37902 diff --git a/drivers/staging/zcache/tmem.c b/drivers/staging/zcache/tmem.c
37903 index 1ca66ea..76f1343 100644
37904 --- a/drivers/staging/zcache/tmem.c
37905 +++ b/drivers/staging/zcache/tmem.c
37906 @@ -39,7 +39,7 @@
37907 * A tmem host implementation must use this function to register callbacks
37908 * for memory allocation.
37909 */
37910 -static struct tmem_hostops tmem_hostops;
37911 +static tmem_hostops_no_const tmem_hostops;
37912
37913 static void tmem_objnode_tree_init(void);
37914
37915 @@ -53,7 +53,7 @@ void tmem_register_hostops(struct tmem_hostops *m)
37916 * A tmem host implementation must use this function to register
37917 * callbacks for a page-accessible memory (PAM) implementation
37918 */
37919 -static struct tmem_pamops tmem_pamops;
37920 +static tmem_pamops_no_const tmem_pamops;
37921
37922 void tmem_register_pamops(struct tmem_pamops *m)
37923 {
37924 diff --git a/drivers/staging/zcache/tmem.h b/drivers/staging/zcache/tmem.h
37925 index 0d4aa82..f7832d4 100644
37926 --- a/drivers/staging/zcache/tmem.h
37927 +++ b/drivers/staging/zcache/tmem.h
37928 @@ -180,6 +180,7 @@ struct tmem_pamops {
37929 void (*new_obj)(struct tmem_obj *);
37930 int (*replace_in_obj)(void *, struct tmem_obj *);
37931 };
37932 +typedef struct tmem_pamops __no_const tmem_pamops_no_const;
37933 extern void tmem_register_pamops(struct tmem_pamops *m);
37934
37935 /* memory allocation methods provided by the host implementation */
37936 @@ -189,6 +190,7 @@ struct tmem_hostops {
37937 struct tmem_objnode *(*objnode_alloc)(struct tmem_pool *);
37938 void (*objnode_free)(struct tmem_objnode *, struct tmem_pool *);
37939 };
37940 +typedef struct tmem_hostops __no_const tmem_hostops_no_const;
37941 extern void tmem_register_hostops(struct tmem_hostops *m);
37942
37943 /* core tmem accessor functions */
37944 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
37945 index 0981707..fa256ac 100644
37946 --- a/drivers/target/target_core_transport.c
37947 +++ b/drivers/target/target_core_transport.c
37948 @@ -1233,7 +1233,7 @@ struct se_device *transport_add_device_to_core_hba(
37949 spin_lock_init(&dev->se_port_lock);
37950 spin_lock_init(&dev->se_tmr_lock);
37951 spin_lock_init(&dev->qf_cmd_lock);
37952 - atomic_set(&dev->dev_ordered_id, 0);
37953 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
37954
37955 se_dev_set_default_attribs(dev, dev_limits);
37956
37957 @@ -1402,7 +1402,7 @@ static int transport_check_alloc_task_attr(struct se_cmd *cmd)
37958 * Used to determine when ORDERED commands should go from
37959 * Dormant to Active status.
37960 */
37961 - cmd->se_ordered_id = atomic_inc_return(&cmd->se_dev->dev_ordered_id);
37962 + cmd->se_ordered_id = atomic_inc_return_unchecked(&cmd->se_dev->dev_ordered_id);
37963 smp_mb__after_atomic_inc();
37964 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
37965 cmd->se_ordered_id, cmd->sam_task_attr,
37966 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
37967 index e61cabd..7617d26 100644
37968 --- a/drivers/tty/cyclades.c
37969 +++ b/drivers/tty/cyclades.c
37970 @@ -1589,10 +1589,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
37971 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
37972 info->port.count);
37973 #endif
37974 - info->port.count++;
37975 + atomic_inc(&info->port.count);
37976 #ifdef CY_DEBUG_COUNT
37977 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
37978 - current->pid, info->port.count);
37979 + current->pid, atomic_read(&info->port.count));
37980 #endif
37981
37982 /*
37983 @@ -3987,7 +3987,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
37984 for (j = 0; j < cy_card[i].nports; j++) {
37985 info = &cy_card[i].ports[j];
37986
37987 - if (info->port.count) {
37988 + if (atomic_read(&info->port.count)) {
37989 /* XXX is the ldisc num worth this? */
37990 struct tty_struct *tty;
37991 struct tty_ldisc *ld;
37992 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
37993 index 2d691eb..be02ebd 100644
37994 --- a/drivers/tty/hvc/hvc_console.c
37995 +++ b/drivers/tty/hvc/hvc_console.c
37996 @@ -315,7 +315,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
37997
37998 spin_lock_irqsave(&hp->port.lock, flags);
37999 /* Check and then increment for fast path open. */
38000 - if (hp->port.count++ > 0) {
38001 + if (atomic_inc_return(&hp->port.count) > 1) {
38002 spin_unlock_irqrestore(&hp->port.lock, flags);
38003 hvc_kick();
38004 return 0;
38005 @@ -366,7 +366,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38006
38007 spin_lock_irqsave(&hp->port.lock, flags);
38008
38009 - if (--hp->port.count == 0) {
38010 + if (atomic_dec_return(&hp->port.count) == 0) {
38011 spin_unlock_irqrestore(&hp->port.lock, flags);
38012 /* We are done with the tty pointer now. */
38013 tty_port_tty_set(&hp->port, NULL);
38014 @@ -384,9 +384,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
38015 */
38016 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
38017 } else {
38018 - if (hp->port.count < 0)
38019 + if (atomic_read(&hp->port.count) < 0)
38020 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
38021 - hp->vtermno, hp->port.count);
38022 + hp->vtermno, atomic_read(&hp->port.count));
38023 spin_unlock_irqrestore(&hp->port.lock, flags);
38024 }
38025
38026 @@ -412,13 +412,13 @@ static void hvc_hangup(struct tty_struct *tty)
38027 * open->hangup case this can be called after the final close so prevent
38028 * that from happening for now.
38029 */
38030 - if (hp->port.count <= 0) {
38031 + if (atomic_read(&hp->port.count) <= 0) {
38032 spin_unlock_irqrestore(&hp->port.lock, flags);
38033 return;
38034 }
38035
38036 - temp_open_count = hp->port.count;
38037 - hp->port.count = 0;
38038 + temp_open_count = atomic_read(&hp->port.count);
38039 + atomic_set(&hp->port.count, 0);
38040 spin_unlock_irqrestore(&hp->port.lock, flags);
38041 tty_port_tty_set(&hp->port, NULL);
38042
38043 @@ -471,7 +471,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
38044 return -EPIPE;
38045
38046 /* FIXME what's this (unprotected) check for? */
38047 - if (hp->port.count <= 0)
38048 + if (atomic_read(&hp->port.count) <= 0)
38049 return -EIO;
38050
38051 spin_lock_irqsave(&hp->lock, flags);
38052 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
38053 index d56788c..12d8f85 100644
38054 --- a/drivers/tty/hvc/hvcs.c
38055 +++ b/drivers/tty/hvc/hvcs.c
38056 @@ -83,6 +83,7 @@
38057 #include <asm/hvcserver.h>
38058 #include <asm/uaccess.h>
38059 #include <asm/vio.h>
38060 +#include <asm/local.h>
38061
38062 /*
38063 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
38064 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
38065
38066 spin_lock_irqsave(&hvcsd->lock, flags);
38067
38068 - if (hvcsd->port.count > 0) {
38069 + if (atomic_read(&hvcsd->port.count) > 0) {
38070 spin_unlock_irqrestore(&hvcsd->lock, flags);
38071 printk(KERN_INFO "HVCS: vterm state unchanged. "
38072 "The hvcs device node is still in use.\n");
38073 @@ -1134,7 +1135,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
38074 if ((retval = hvcs_partner_connect(hvcsd)))
38075 goto error_release;
38076
38077 - hvcsd->port.count = 1;
38078 + atomic_set(&hvcsd->port.count, 1);
38079 hvcsd->port.tty = tty;
38080 tty->driver_data = hvcsd;
38081
38082 @@ -1168,7 +1169,7 @@ fast_open:
38083
38084 spin_lock_irqsave(&hvcsd->lock, flags);
38085 tty_port_get(&hvcsd->port);
38086 - hvcsd->port.count++;
38087 + atomic_inc(&hvcsd->port.count);
38088 hvcsd->todo_mask |= HVCS_SCHED_READ;
38089 spin_unlock_irqrestore(&hvcsd->lock, flags);
38090
38091 @@ -1212,7 +1213,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38092 hvcsd = tty->driver_data;
38093
38094 spin_lock_irqsave(&hvcsd->lock, flags);
38095 - if (--hvcsd->port.count == 0) {
38096 + if (atomic_dec_and_test(&hvcsd->port.count)) {
38097
38098 vio_disable_interrupts(hvcsd->vdev);
38099
38100 @@ -1238,10 +1239,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
38101 free_irq(irq, hvcsd);
38102 tty_port_put(&hvcsd->port);
38103 return;
38104 - } else if (hvcsd->port.count < 0) {
38105 + } else if (atomic_read(&hvcsd->port.count) < 0) {
38106 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
38107 " is missmanaged.\n",
38108 - hvcsd->vdev->unit_address, hvcsd->port.count);
38109 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
38110 }
38111
38112 spin_unlock_irqrestore(&hvcsd->lock, flags);
38113 @@ -1257,7 +1258,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38114
38115 spin_lock_irqsave(&hvcsd->lock, flags);
38116 /* Preserve this so that we know how many kref refs to put */
38117 - temp_open_count = hvcsd->port.count;
38118 + temp_open_count = atomic_read(&hvcsd->port.count);
38119
38120 /*
38121 * Don't kref put inside the spinlock because the destruction
38122 @@ -1272,7 +1273,7 @@ static void hvcs_hangup(struct tty_struct * tty)
38123 tty->driver_data = NULL;
38124 hvcsd->port.tty = NULL;
38125
38126 - hvcsd->port.count = 0;
38127 + atomic_set(&hvcsd->port.count, 0);
38128
38129 /* This will drop any buffered data on the floor which is OK in a hangup
38130 * scenario. */
38131 @@ -1343,7 +1344,7 @@ static int hvcs_write(struct tty_struct *tty,
38132 * the middle of a write operation? This is a crummy place to do this
38133 * but we want to keep it all in the spinlock.
38134 */
38135 - if (hvcsd->port.count <= 0) {
38136 + if (atomic_read(&hvcsd->port.count) <= 0) {
38137 spin_unlock_irqrestore(&hvcsd->lock, flags);
38138 return -ENODEV;
38139 }
38140 @@ -1417,7 +1418,7 @@ static int hvcs_write_room(struct tty_struct *tty)
38141 {
38142 struct hvcs_struct *hvcsd = tty->driver_data;
38143
38144 - if (!hvcsd || hvcsd->port.count <= 0)
38145 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
38146 return 0;
38147
38148 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
38149 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
38150 index f8b5fa0..4ba9f89 100644
38151 --- a/drivers/tty/ipwireless/tty.c
38152 +++ b/drivers/tty/ipwireless/tty.c
38153 @@ -29,6 +29,7 @@
38154 #include <linux/tty_driver.h>
38155 #include <linux/tty_flip.h>
38156 #include <linux/uaccess.h>
38157 +#include <asm/local.h>
38158
38159 #include "tty.h"
38160 #include "network.h"
38161 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38162 mutex_unlock(&tty->ipw_tty_mutex);
38163 return -ENODEV;
38164 }
38165 - if (tty->port.count == 0)
38166 + if (atomic_read(&tty->port.count) == 0)
38167 tty->tx_bytes_queued = 0;
38168
38169 - tty->port.count++;
38170 + atomic_inc(&tty->port.count);
38171
38172 tty->port.tty = linux_tty;
38173 linux_tty->driver_data = tty;
38174 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
38175
38176 static void do_ipw_close(struct ipw_tty *tty)
38177 {
38178 - tty->port.count--;
38179 -
38180 - if (tty->port.count == 0) {
38181 + if (atomic_dec_return(&tty->port.count) == 0) {
38182 struct tty_struct *linux_tty = tty->port.tty;
38183
38184 if (linux_tty != NULL) {
38185 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
38186 return;
38187
38188 mutex_lock(&tty->ipw_tty_mutex);
38189 - if (tty->port.count == 0) {
38190 + if (atomic_read(&tty->port.count) == 0) {
38191 mutex_unlock(&tty->ipw_tty_mutex);
38192 return;
38193 }
38194 @@ -170,7 +169,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
38195 return;
38196 }
38197
38198 - if (!tty->port.count) {
38199 + if (!atomic_read(&tty->port.count)) {
38200 mutex_unlock(&tty->ipw_tty_mutex);
38201 return;
38202 }
38203 @@ -212,7 +211,7 @@ static int ipw_write(struct tty_struct *linux_tty,
38204 return -ENODEV;
38205
38206 mutex_lock(&tty->ipw_tty_mutex);
38207 - if (!tty->port.count) {
38208 + if (!atomic_read(&tty->port.count)) {
38209 mutex_unlock(&tty->ipw_tty_mutex);
38210 return -EINVAL;
38211 }
38212 @@ -252,7 +251,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
38213 if (!tty)
38214 return -ENODEV;
38215
38216 - if (!tty->port.count)
38217 + if (!atomic_read(&tty->port.count))
38218 return -EINVAL;
38219
38220 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
38221 @@ -294,7 +293,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
38222 if (!tty)
38223 return 0;
38224
38225 - if (!tty->port.count)
38226 + if (!atomic_read(&tty->port.count))
38227 return 0;
38228
38229 return tty->tx_bytes_queued;
38230 @@ -375,7 +374,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
38231 if (!tty)
38232 return -ENODEV;
38233
38234 - if (!tty->port.count)
38235 + if (!atomic_read(&tty->port.count))
38236 return -EINVAL;
38237
38238 return get_control_lines(tty);
38239 @@ -391,7 +390,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
38240 if (!tty)
38241 return -ENODEV;
38242
38243 - if (!tty->port.count)
38244 + if (!atomic_read(&tty->port.count))
38245 return -EINVAL;
38246
38247 return set_control_lines(tty, set, clear);
38248 @@ -405,7 +404,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
38249 if (!tty)
38250 return -ENODEV;
38251
38252 - if (!tty->port.count)
38253 + if (!atomic_read(&tty->port.count))
38254 return -EINVAL;
38255
38256 /* FIXME: Exactly how is the tty object locked here .. */
38257 @@ -561,7 +560,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
38258 * are gone */
38259 mutex_lock(&ttyj->ipw_tty_mutex);
38260 }
38261 - while (ttyj->port.count)
38262 + while (atomic_read(&ttyj->port.count))
38263 do_ipw_close(ttyj);
38264 ipwireless_disassociate_network_ttys(network,
38265 ttyj->channel_idx);
38266 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
38267 index 324467d..504cc25 100644
38268 --- a/drivers/tty/moxa.c
38269 +++ b/drivers/tty/moxa.c
38270 @@ -1172,7 +1172,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
38271 }
38272
38273 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
38274 - ch->port.count++;
38275 + atomic_inc(&ch->port.count);
38276 tty->driver_data = ch;
38277 tty_port_tty_set(&ch->port, tty);
38278 mutex_lock(&ch->port.mutex);
38279 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
38280 index c43b683..4dab83e 100644
38281 --- a/drivers/tty/n_gsm.c
38282 +++ b/drivers/tty/n_gsm.c
38283 @@ -1629,7 +1629,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
38284 kref_init(&dlci->ref);
38285 mutex_init(&dlci->mutex);
38286 dlci->fifo = &dlci->_fifo;
38287 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
38288 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
38289 kfree(dlci);
38290 return NULL;
38291 }
38292 @@ -2895,7 +2895,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
38293 if (dlci == NULL)
38294 return -ENOMEM;
38295 port = &dlci->port;
38296 - port->count++;
38297 + atomic_inc(&port->count);
38298 tty->driver_data = dlci;
38299 dlci_get(dlci);
38300 dlci_get(dlci->gsm->dlci[0]);
38301 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
38302 index ee1c268..0e97caf 100644
38303 --- a/drivers/tty/n_tty.c
38304 +++ b/drivers/tty/n_tty.c
38305 @@ -2123,6 +2123,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
38306 {
38307 *ops = tty_ldisc_N_TTY;
38308 ops->owner = NULL;
38309 - ops->refcount = ops->flags = 0;
38310 + atomic_set(&ops->refcount, 0);
38311 + ops->flags = 0;
38312 }
38313 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
38314 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
38315 index 5505ffc..7affff9 100644
38316 --- a/drivers/tty/pty.c
38317 +++ b/drivers/tty/pty.c
38318 @@ -718,8 +718,10 @@ static void __init unix98_pty_init(void)
38319 panic("Couldn't register Unix98 pts driver");
38320
38321 /* Now create the /dev/ptmx special device */
38322 + pax_open_kernel();
38323 tty_default_fops(&ptmx_fops);
38324 - ptmx_fops.open = ptmx_open;
38325 + *(void **)&ptmx_fops.open = ptmx_open;
38326 + pax_close_kernel();
38327
38328 cdev_init(&ptmx_cdev, &ptmx_fops);
38329 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
38330 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
38331 index 777d5f9..56d67ca 100644
38332 --- a/drivers/tty/rocket.c
38333 +++ b/drivers/tty/rocket.c
38334 @@ -924,7 +924,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38335 tty->driver_data = info;
38336 tty_port_tty_set(port, tty);
38337
38338 - if (port->count++ == 0) {
38339 + if (atomic_inc_return(&port->count) == 1) {
38340 atomic_inc(&rp_num_ports_open);
38341
38342 #ifdef ROCKET_DEBUG_OPEN
38343 @@ -933,7 +933,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
38344 #endif
38345 }
38346 #ifdef ROCKET_DEBUG_OPEN
38347 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
38348 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
38349 #endif
38350
38351 /*
38352 @@ -1528,7 +1528,7 @@ static void rp_hangup(struct tty_struct *tty)
38353 spin_unlock_irqrestore(&info->port.lock, flags);
38354 return;
38355 }
38356 - if (info->port.count)
38357 + if (atomic_read(&info->port.count))
38358 atomic_dec(&rp_num_ports_open);
38359 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
38360 spin_unlock_irqrestore(&info->port.lock, flags);
38361 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
38362 index 2b42a01..32a2ed3 100644
38363 --- a/drivers/tty/serial/kgdboc.c
38364 +++ b/drivers/tty/serial/kgdboc.c
38365 @@ -24,8 +24,9 @@
38366 #define MAX_CONFIG_LEN 40
38367
38368 static struct kgdb_io kgdboc_io_ops;
38369 +static struct kgdb_io kgdboc_io_ops_console;
38370
38371 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
38372 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
38373 static int configured = -1;
38374
38375 static char config[MAX_CONFIG_LEN];
38376 @@ -148,6 +149,8 @@ static void cleanup_kgdboc(void)
38377 kgdboc_unregister_kbd();
38378 if (configured == 1)
38379 kgdb_unregister_io_module(&kgdboc_io_ops);
38380 + else if (configured == 2)
38381 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
38382 }
38383
38384 static int configure_kgdboc(void)
38385 @@ -157,13 +160,13 @@ static int configure_kgdboc(void)
38386 int err;
38387 char *cptr = config;
38388 struct console *cons;
38389 + int is_console = 0;
38390
38391 err = kgdboc_option_setup(config);
38392 if (err || !strlen(config) || isspace(config[0]))
38393 goto noconfig;
38394
38395 err = -ENODEV;
38396 - kgdboc_io_ops.is_console = 0;
38397 kgdb_tty_driver = NULL;
38398
38399 kgdboc_use_kms = 0;
38400 @@ -184,7 +187,7 @@ static int configure_kgdboc(void)
38401 int idx;
38402 if (cons->device && cons->device(cons, &idx) == p &&
38403 idx == tty_line) {
38404 - kgdboc_io_ops.is_console = 1;
38405 + is_console = 1;
38406 break;
38407 }
38408 cons = cons->next;
38409 @@ -194,12 +197,16 @@ static int configure_kgdboc(void)
38410 kgdb_tty_line = tty_line;
38411
38412 do_register:
38413 - err = kgdb_register_io_module(&kgdboc_io_ops);
38414 + if (is_console) {
38415 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
38416 + configured = 2;
38417 + } else {
38418 + err = kgdb_register_io_module(&kgdboc_io_ops);
38419 + configured = 1;
38420 + }
38421 if (err)
38422 goto noconfig;
38423
38424 - configured = 1;
38425 -
38426 return 0;
38427
38428 noconfig:
38429 @@ -213,7 +220,7 @@ noconfig:
38430 static int __init init_kgdboc(void)
38431 {
38432 /* Already configured? */
38433 - if (configured == 1)
38434 + if (configured >= 1)
38435 return 0;
38436
38437 return configure_kgdboc();
38438 @@ -262,7 +269,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
38439 if (config[len - 1] == '\n')
38440 config[len - 1] = '\0';
38441
38442 - if (configured == 1)
38443 + if (configured >= 1)
38444 cleanup_kgdboc();
38445
38446 /* Go and configure with the new params. */
38447 @@ -302,6 +309,15 @@ static struct kgdb_io kgdboc_io_ops = {
38448 .post_exception = kgdboc_post_exp_handler,
38449 };
38450
38451 +static struct kgdb_io kgdboc_io_ops_console = {
38452 + .name = "kgdboc",
38453 + .read_char = kgdboc_get_char,
38454 + .write_char = kgdboc_put_char,
38455 + .pre_exception = kgdboc_pre_exp_handler,
38456 + .post_exception = kgdboc_post_exp_handler,
38457 + .is_console = 1
38458 +};
38459 +
38460 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
38461 /* This is only available if kgdboc is a built in for early debugging */
38462 static int __init kgdboc_early_init(char *opt)
38463 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
38464 index 246b823..9e0db76 100644
38465 --- a/drivers/tty/serial/serial_core.c
38466 +++ b/drivers/tty/serial/serial_core.c
38467 @@ -1392,7 +1392,7 @@ static void uart_hangup(struct tty_struct *tty)
38468 uart_flush_buffer(tty);
38469 uart_shutdown(tty, state);
38470 spin_lock_irqsave(&port->lock, flags);
38471 - port->count = 0;
38472 + atomic_set(&port->count, 0);
38473 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
38474 spin_unlock_irqrestore(&port->lock, flags);
38475 tty_port_tty_set(port, NULL);
38476 @@ -1488,7 +1488,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38477 goto end;
38478 }
38479
38480 - port->count++;
38481 + atomic_inc(&port->count);
38482 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
38483 retval = -ENXIO;
38484 goto err_dec_count;
38485 @@ -1515,7 +1515,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38486 /*
38487 * Make sure the device is in D0 state.
38488 */
38489 - if (port->count == 1)
38490 + if (atomic_read(&port->count) == 1)
38491 uart_change_pm(state, 0);
38492
38493 /*
38494 @@ -1533,7 +1533,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
38495 end:
38496 return retval;
38497 err_dec_count:
38498 - port->count--;
38499 + atomic_inc(&port->count);
38500 mutex_unlock(&port->mutex);
38501 goto end;
38502 }
38503 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
38504 index 593d40a..bdc61f3 100644
38505 --- a/drivers/tty/synclink.c
38506 +++ b/drivers/tty/synclink.c
38507 @@ -3095,7 +3095,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38508
38509 if (debug_level >= DEBUG_LEVEL_INFO)
38510 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
38511 - __FILE__,__LINE__, info->device_name, info->port.count);
38512 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38513
38514 if (tty_port_close_start(&info->port, tty, filp) == 0)
38515 goto cleanup;
38516 @@ -3113,7 +3113,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
38517 cleanup:
38518 if (debug_level >= DEBUG_LEVEL_INFO)
38519 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
38520 - tty->driver->name, info->port.count);
38521 + tty->driver->name, atomic_read(&info->port.count));
38522
38523 } /* end of mgsl_close() */
38524
38525 @@ -3212,8 +3212,8 @@ static void mgsl_hangup(struct tty_struct *tty)
38526
38527 mgsl_flush_buffer(tty);
38528 shutdown(info);
38529 -
38530 - info->port.count = 0;
38531 +
38532 + atomic_set(&info->port.count, 0);
38533 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38534 info->port.tty = NULL;
38535
38536 @@ -3302,12 +3302,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38537
38538 if (debug_level >= DEBUG_LEVEL_INFO)
38539 printk("%s(%d):block_til_ready before block on %s count=%d\n",
38540 - __FILE__,__LINE__, tty->driver->name, port->count );
38541 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38542
38543 spin_lock_irqsave(&info->irq_spinlock, flags);
38544 if (!tty_hung_up_p(filp)) {
38545 extra_count = true;
38546 - port->count--;
38547 + atomic_dec(&port->count);
38548 }
38549 spin_unlock_irqrestore(&info->irq_spinlock, flags);
38550 port->blocked_open++;
38551 @@ -3336,7 +3336,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38552
38553 if (debug_level >= DEBUG_LEVEL_INFO)
38554 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
38555 - __FILE__,__LINE__, tty->driver->name, port->count );
38556 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38557
38558 tty_unlock();
38559 schedule();
38560 @@ -3348,12 +3348,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
38561
38562 /* FIXME: Racy on hangup during close wait */
38563 if (extra_count)
38564 - port->count++;
38565 + atomic_inc(&port->count);
38566 port->blocked_open--;
38567
38568 if (debug_level >= DEBUG_LEVEL_INFO)
38569 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
38570 - __FILE__,__LINE__, tty->driver->name, port->count );
38571 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38572
38573 if (!retval)
38574 port->flags |= ASYNC_NORMAL_ACTIVE;
38575 @@ -3398,7 +3398,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38576
38577 if (debug_level >= DEBUG_LEVEL_INFO)
38578 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
38579 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38580 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38581
38582 /* If port is closing, signal caller to try again */
38583 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38584 @@ -3417,10 +3417,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
38585 spin_unlock_irqrestore(&info->netlock, flags);
38586 goto cleanup;
38587 }
38588 - info->port.count++;
38589 + atomic_inc(&info->port.count);
38590 spin_unlock_irqrestore(&info->netlock, flags);
38591
38592 - if (info->port.count == 1) {
38593 + if (atomic_read(&info->port.count) == 1) {
38594 /* 1st open on this device, init hardware */
38595 retval = startup(info);
38596 if (retval < 0)
38597 @@ -3444,8 +3444,8 @@ cleanup:
38598 if (retval) {
38599 if (tty->count == 1)
38600 info->port.tty = NULL; /* tty layer will release tty struct */
38601 - if(info->port.count)
38602 - info->port.count--;
38603 + if (atomic_read(&info->port.count))
38604 + atomic_dec(&info->port.count);
38605 }
38606
38607 return retval;
38608 @@ -7653,7 +7653,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38609 unsigned short new_crctype;
38610
38611 /* return error if TTY interface open */
38612 - if (info->port.count)
38613 + if (atomic_read(&info->port.count))
38614 return -EBUSY;
38615
38616 switch (encoding)
38617 @@ -7748,7 +7748,7 @@ static int hdlcdev_open(struct net_device *dev)
38618
38619 /* arbitrate between network and tty opens */
38620 spin_lock_irqsave(&info->netlock, flags);
38621 - if (info->port.count != 0 || info->netcount != 0) {
38622 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38623 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38624 spin_unlock_irqrestore(&info->netlock, flags);
38625 return -EBUSY;
38626 @@ -7834,7 +7834,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38627 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38628
38629 /* return error if TTY interface open */
38630 - if (info->port.count)
38631 + if (atomic_read(&info->port.count))
38632 return -EBUSY;
38633
38634 if (cmd != SIOCWANDEV)
38635 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
38636 index aa1debf..9297a16 100644
38637 --- a/drivers/tty/synclink_gt.c
38638 +++ b/drivers/tty/synclink_gt.c
38639 @@ -671,7 +671,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38640 tty->driver_data = info;
38641 info->port.tty = tty;
38642
38643 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
38644 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
38645
38646 /* If port is closing, signal caller to try again */
38647 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38648 @@ -692,10 +692,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38649 mutex_unlock(&info->port.mutex);
38650 goto cleanup;
38651 }
38652 - info->port.count++;
38653 + atomic_inc(&info->port.count);
38654 spin_unlock_irqrestore(&info->netlock, flags);
38655
38656 - if (info->port.count == 1) {
38657 + if (atomic_read(&info->port.count) == 1) {
38658 /* 1st open on this device, init hardware */
38659 retval = startup(info);
38660 if (retval < 0) {
38661 @@ -716,8 +716,8 @@ cleanup:
38662 if (retval) {
38663 if (tty->count == 1)
38664 info->port.tty = NULL; /* tty layer will release tty struct */
38665 - if(info->port.count)
38666 - info->port.count--;
38667 + if(atomic_read(&info->port.count))
38668 + atomic_dec(&info->port.count);
38669 }
38670
38671 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
38672 @@ -730,7 +730,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38673
38674 if (sanity_check(info, tty->name, "close"))
38675 return;
38676 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
38677 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
38678
38679 if (tty_port_close_start(&info->port, tty, filp) == 0)
38680 goto cleanup;
38681 @@ -747,7 +747,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38682 tty_port_close_end(&info->port, tty);
38683 info->port.tty = NULL;
38684 cleanup:
38685 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
38686 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
38687 }
38688
38689 static void hangup(struct tty_struct *tty)
38690 @@ -765,7 +765,7 @@ static void hangup(struct tty_struct *tty)
38691 shutdown(info);
38692
38693 spin_lock_irqsave(&info->port.lock, flags);
38694 - info->port.count = 0;
38695 + atomic_set(&info->port.count, 0);
38696 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38697 info->port.tty = NULL;
38698 spin_unlock_irqrestore(&info->port.lock, flags);
38699 @@ -1450,7 +1450,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38700 unsigned short new_crctype;
38701
38702 /* return error if TTY interface open */
38703 - if (info->port.count)
38704 + if (atomic_read(&info->port.count))
38705 return -EBUSY;
38706
38707 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
38708 @@ -1545,7 +1545,7 @@ static int hdlcdev_open(struct net_device *dev)
38709
38710 /* arbitrate between network and tty opens */
38711 spin_lock_irqsave(&info->netlock, flags);
38712 - if (info->port.count != 0 || info->netcount != 0) {
38713 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38714 DBGINFO(("%s hdlc_open busy\n", dev->name));
38715 spin_unlock_irqrestore(&info->netlock, flags);
38716 return -EBUSY;
38717 @@ -1630,7 +1630,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38718 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
38719
38720 /* return error if TTY interface open */
38721 - if (info->port.count)
38722 + if (atomic_read(&info->port.count))
38723 return -EBUSY;
38724
38725 if (cmd != SIOCWANDEV)
38726 @@ -2419,7 +2419,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
38727 if (port == NULL)
38728 continue;
38729 spin_lock(&port->lock);
38730 - if ((port->port.count || port->netcount) &&
38731 + if ((atomic_read(&port->port.count) || port->netcount) &&
38732 port->pending_bh && !port->bh_running &&
38733 !port->bh_requested) {
38734 DBGISR(("%s bh queued\n", port->device_name));
38735 @@ -3308,7 +3308,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38736 spin_lock_irqsave(&info->lock, flags);
38737 if (!tty_hung_up_p(filp)) {
38738 extra_count = true;
38739 - port->count--;
38740 + atomic_dec(&port->count);
38741 }
38742 spin_unlock_irqrestore(&info->lock, flags);
38743 port->blocked_open++;
38744 @@ -3345,7 +3345,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38745 remove_wait_queue(&port->open_wait, &wait);
38746
38747 if (extra_count)
38748 - port->count++;
38749 + atomic_inc(&port->count);
38750 port->blocked_open--;
38751
38752 if (!retval)
38753 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
38754 index a3dddc1..8905ab2 100644
38755 --- a/drivers/tty/synclinkmp.c
38756 +++ b/drivers/tty/synclinkmp.c
38757 @@ -742,7 +742,7 @@ static int open(struct tty_struct *tty, struct file *filp)
38758
38759 if (debug_level >= DEBUG_LEVEL_INFO)
38760 printk("%s(%d):%s open(), old ref count = %d\n",
38761 - __FILE__,__LINE__,tty->driver->name, info->port.count);
38762 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
38763
38764 /* If port is closing, signal caller to try again */
38765 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
38766 @@ -761,10 +761,10 @@ static int open(struct tty_struct *tty, struct file *filp)
38767 spin_unlock_irqrestore(&info->netlock, flags);
38768 goto cleanup;
38769 }
38770 - info->port.count++;
38771 + atomic_inc(&info->port.count);
38772 spin_unlock_irqrestore(&info->netlock, flags);
38773
38774 - if (info->port.count == 1) {
38775 + if (atomic_read(&info->port.count) == 1) {
38776 /* 1st open on this device, init hardware */
38777 retval = startup(info);
38778 if (retval < 0)
38779 @@ -788,8 +788,8 @@ cleanup:
38780 if (retval) {
38781 if (tty->count == 1)
38782 info->port.tty = NULL; /* tty layer will release tty struct */
38783 - if(info->port.count)
38784 - info->port.count--;
38785 + if(atomic_read(&info->port.count))
38786 + atomic_dec(&info->port.count);
38787 }
38788
38789 return retval;
38790 @@ -807,7 +807,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38791
38792 if (debug_level >= DEBUG_LEVEL_INFO)
38793 printk("%s(%d):%s close() entry, count=%d\n",
38794 - __FILE__,__LINE__, info->device_name, info->port.count);
38795 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
38796
38797 if (tty_port_close_start(&info->port, tty, filp) == 0)
38798 goto cleanup;
38799 @@ -826,7 +826,7 @@ static void close(struct tty_struct *tty, struct file *filp)
38800 cleanup:
38801 if (debug_level >= DEBUG_LEVEL_INFO)
38802 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
38803 - tty->driver->name, info->port.count);
38804 + tty->driver->name, atomic_read(&info->port.count));
38805 }
38806
38807 /* Called by tty_hangup() when a hangup is signaled.
38808 @@ -849,7 +849,7 @@ static void hangup(struct tty_struct *tty)
38809 shutdown(info);
38810
38811 spin_lock_irqsave(&info->port.lock, flags);
38812 - info->port.count = 0;
38813 + atomic_set(&info->port.count, 0);
38814 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
38815 info->port.tty = NULL;
38816 spin_unlock_irqrestore(&info->port.lock, flags);
38817 @@ -1557,7 +1557,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
38818 unsigned short new_crctype;
38819
38820 /* return error if TTY interface open */
38821 - if (info->port.count)
38822 + if (atomic_read(&info->port.count))
38823 return -EBUSY;
38824
38825 switch (encoding)
38826 @@ -1652,7 +1652,7 @@ static int hdlcdev_open(struct net_device *dev)
38827
38828 /* arbitrate between network and tty opens */
38829 spin_lock_irqsave(&info->netlock, flags);
38830 - if (info->port.count != 0 || info->netcount != 0) {
38831 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
38832 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
38833 spin_unlock_irqrestore(&info->netlock, flags);
38834 return -EBUSY;
38835 @@ -1738,7 +1738,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
38836 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
38837
38838 /* return error if TTY interface open */
38839 - if (info->port.count)
38840 + if (atomic_read(&info->port.count))
38841 return -EBUSY;
38842
38843 if (cmd != SIOCWANDEV)
38844 @@ -2623,7 +2623,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
38845 * do not request bottom half processing if the
38846 * device is not open in a normal mode.
38847 */
38848 - if ( port && (port->port.count || port->netcount) &&
38849 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
38850 port->pending_bh && !port->bh_running &&
38851 !port->bh_requested ) {
38852 if ( debug_level >= DEBUG_LEVEL_ISR )
38853 @@ -3321,12 +3321,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38854
38855 if (debug_level >= DEBUG_LEVEL_INFO)
38856 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
38857 - __FILE__,__LINE__, tty->driver->name, port->count );
38858 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38859
38860 spin_lock_irqsave(&info->lock, flags);
38861 if (!tty_hung_up_p(filp)) {
38862 extra_count = true;
38863 - port->count--;
38864 + atomic_dec(&port->count);
38865 }
38866 spin_unlock_irqrestore(&info->lock, flags);
38867 port->blocked_open++;
38868 @@ -3355,7 +3355,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38869
38870 if (debug_level >= DEBUG_LEVEL_INFO)
38871 printk("%s(%d):%s block_til_ready() count=%d\n",
38872 - __FILE__,__LINE__, tty->driver->name, port->count );
38873 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38874
38875 tty_unlock();
38876 schedule();
38877 @@ -3366,12 +3366,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
38878 remove_wait_queue(&port->open_wait, &wait);
38879
38880 if (extra_count)
38881 - port->count++;
38882 + atomic_inc(&port->count);
38883 port->blocked_open--;
38884
38885 if (debug_level >= DEBUG_LEVEL_INFO)
38886 printk("%s(%d):%s block_til_ready() after, count=%d\n",
38887 - __FILE__,__LINE__, tty->driver->name, port->count );
38888 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
38889
38890 if (!retval)
38891 port->flags |= ASYNC_NORMAL_ACTIVE;
38892 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
38893 index 05728894..b9d44c6 100644
38894 --- a/drivers/tty/sysrq.c
38895 +++ b/drivers/tty/sysrq.c
38896 @@ -865,7 +865,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
38897 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
38898 size_t count, loff_t *ppos)
38899 {
38900 - if (count) {
38901 + if (count && capable(CAP_SYS_ADMIN)) {
38902 char c;
38903
38904 if (get_user(c, buf))
38905 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
38906 index b425c79..08a3f06 100644
38907 --- a/drivers/tty/tty_io.c
38908 +++ b/drivers/tty/tty_io.c
38909 @@ -3283,7 +3283,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
38910
38911 void tty_default_fops(struct file_operations *fops)
38912 {
38913 - *fops = tty_fops;
38914 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
38915 }
38916
38917 /*
38918 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
38919 index 9911eb6..5abe0e1 100644
38920 --- a/drivers/tty/tty_ldisc.c
38921 +++ b/drivers/tty/tty_ldisc.c
38922 @@ -56,7 +56,7 @@ static void put_ldisc(struct tty_ldisc *ld)
38923 if (atomic_dec_and_lock(&ld->users, &tty_ldisc_lock)) {
38924 struct tty_ldisc_ops *ldo = ld->ops;
38925
38926 - ldo->refcount--;
38927 + atomic_dec(&ldo->refcount);
38928 module_put(ldo->owner);
38929 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38930
38931 @@ -91,7 +91,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
38932 spin_lock_irqsave(&tty_ldisc_lock, flags);
38933 tty_ldiscs[disc] = new_ldisc;
38934 new_ldisc->num = disc;
38935 - new_ldisc->refcount = 0;
38936 + atomic_set(&new_ldisc->refcount, 0);
38937 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38938
38939 return ret;
38940 @@ -119,7 +119,7 @@ int tty_unregister_ldisc(int disc)
38941 return -EINVAL;
38942
38943 spin_lock_irqsave(&tty_ldisc_lock, flags);
38944 - if (tty_ldiscs[disc]->refcount)
38945 + if (atomic_read(&tty_ldiscs[disc]->refcount))
38946 ret = -EBUSY;
38947 else
38948 tty_ldiscs[disc] = NULL;
38949 @@ -140,7 +140,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
38950 if (ldops) {
38951 ret = ERR_PTR(-EAGAIN);
38952 if (try_module_get(ldops->owner)) {
38953 - ldops->refcount++;
38954 + atomic_inc(&ldops->refcount);
38955 ret = ldops;
38956 }
38957 }
38958 @@ -153,7 +153,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
38959 unsigned long flags;
38960
38961 spin_lock_irqsave(&tty_ldisc_lock, flags);
38962 - ldops->refcount--;
38963 + atomic_dec(&ldops->refcount);
38964 module_put(ldops->owner);
38965 spin_unlock_irqrestore(&tty_ldisc_lock, flags);
38966 }
38967 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
38968 index bf6e238..d401c04 100644
38969 --- a/drivers/tty/tty_port.c
38970 +++ b/drivers/tty/tty_port.c
38971 @@ -138,7 +138,7 @@ void tty_port_hangup(struct tty_port *port)
38972 unsigned long flags;
38973
38974 spin_lock_irqsave(&port->lock, flags);
38975 - port->count = 0;
38976 + atomic_set(&port->count, 0);
38977 port->flags &= ~ASYNC_NORMAL_ACTIVE;
38978 if (port->tty) {
38979 set_bit(TTY_IO_ERROR, &port->tty->flags);
38980 @@ -264,7 +264,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38981 /* The port lock protects the port counts */
38982 spin_lock_irqsave(&port->lock, flags);
38983 if (!tty_hung_up_p(filp))
38984 - port->count--;
38985 + atomic_dec(&port->count);
38986 port->blocked_open++;
38987 spin_unlock_irqrestore(&port->lock, flags);
38988
38989 @@ -306,7 +306,7 @@ int tty_port_block_til_ready(struct tty_port *port,
38990 we must not mess that up further */
38991 spin_lock_irqsave(&port->lock, flags);
38992 if (!tty_hung_up_p(filp))
38993 - port->count++;
38994 + atomic_inc(&port->count);
38995 port->blocked_open--;
38996 if (retval == 0)
38997 port->flags |= ASYNC_NORMAL_ACTIVE;
38998 @@ -326,19 +326,19 @@ int tty_port_close_start(struct tty_port *port,
38999 return 0;
39000 }
39001
39002 - if (tty->count == 1 && port->count != 1) {
39003 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
39004 printk(KERN_WARNING
39005 "tty_port_close_start: tty->count = 1 port count = %d.\n",
39006 - port->count);
39007 - port->count = 1;
39008 + atomic_read(&port->count));
39009 + atomic_set(&port->count, 1);
39010 }
39011 - if (--port->count < 0) {
39012 + if (atomic_dec_return(&port->count) < 0) {
39013 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
39014 - port->count);
39015 - port->count = 0;
39016 + atomic_read(&port->count));
39017 + atomic_set(&port->count, 0);
39018 }
39019
39020 - if (port->count) {
39021 + if (atomic_read(&port->count)) {
39022 spin_unlock_irqrestore(&port->lock, flags);
39023 if (port->ops->drop)
39024 port->ops->drop(port);
39025 @@ -418,7 +418,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
39026 {
39027 spin_lock_irq(&port->lock);
39028 if (!tty_hung_up_p(filp))
39029 - ++port->count;
39030 + atomic_inc(&port->count);
39031 spin_unlock_irq(&port->lock);
39032 tty_port_tty_set(port, tty);
39033
39034 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
39035 index 48cc6f2..85584dd 100644
39036 --- a/drivers/tty/vt/keyboard.c
39037 +++ b/drivers/tty/vt/keyboard.c
39038 @@ -659,6 +659,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
39039 kbd->kbdmode == VC_OFF) &&
39040 value != KVAL(K_SAK))
39041 return; /* SAK is allowed even in raw mode */
39042 +
39043 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
39044 + {
39045 + void *func = fn_handler[value];
39046 + if (func == fn_show_state || func == fn_show_ptregs ||
39047 + func == fn_show_mem)
39048 + return;
39049 + }
39050 +#endif
39051 +
39052 fn_handler[value](vc);
39053 }
39054
39055 @@ -1808,9 +1818,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39056 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
39057 return -EFAULT;
39058
39059 - if (!capable(CAP_SYS_TTY_CONFIG))
39060 - perm = 0;
39061 -
39062 switch (cmd) {
39063 case KDGKBENT:
39064 /* Ensure another thread doesn't free it under us */
39065 @@ -1825,6 +1832,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
39066 spin_unlock_irqrestore(&kbd_event_lock, flags);
39067 return put_user(val, &user_kbe->kb_value);
39068 case KDSKBENT:
39069 + if (!capable(CAP_SYS_TTY_CONFIG))
39070 + perm = 0;
39071 +
39072 if (!perm)
39073 return -EPERM;
39074 if (!i && v == K_NOSUCHMAP) {
39075 @@ -1915,9 +1925,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39076 int i, j, k;
39077 int ret;
39078
39079 - if (!capable(CAP_SYS_TTY_CONFIG))
39080 - perm = 0;
39081 -
39082 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
39083 if (!kbs) {
39084 ret = -ENOMEM;
39085 @@ -1951,6 +1958,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
39086 kfree(kbs);
39087 return ((p && *p) ? -EOVERFLOW : 0);
39088 case KDSKBSENT:
39089 + if (!capable(CAP_SYS_TTY_CONFIG))
39090 + perm = 0;
39091 +
39092 if (!perm) {
39093 ret = -EPERM;
39094 goto reterr;
39095 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
39096 index a783d53..cb30d94 100644
39097 --- a/drivers/uio/uio.c
39098 +++ b/drivers/uio/uio.c
39099 @@ -25,6 +25,7 @@
39100 #include <linux/kobject.h>
39101 #include <linux/cdev.h>
39102 #include <linux/uio_driver.h>
39103 +#include <asm/local.h>
39104
39105 #define UIO_MAX_DEVICES (1U << MINORBITS)
39106
39107 @@ -32,10 +33,10 @@ struct uio_device {
39108 struct module *owner;
39109 struct device *dev;
39110 int minor;
39111 - atomic_t event;
39112 + atomic_unchecked_t event;
39113 struct fasync_struct *async_queue;
39114 wait_queue_head_t wait;
39115 - int vma_count;
39116 + local_t vma_count;
39117 struct uio_info *info;
39118 struct kobject *map_dir;
39119 struct kobject *portio_dir;
39120 @@ -242,7 +243,7 @@ static ssize_t show_event(struct device *dev,
39121 struct device_attribute *attr, char *buf)
39122 {
39123 struct uio_device *idev = dev_get_drvdata(dev);
39124 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
39125 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
39126 }
39127
39128 static struct device_attribute uio_class_attributes[] = {
39129 @@ -408,7 +409,7 @@ void uio_event_notify(struct uio_info *info)
39130 {
39131 struct uio_device *idev = info->uio_dev;
39132
39133 - atomic_inc(&idev->event);
39134 + atomic_inc_unchecked(&idev->event);
39135 wake_up_interruptible(&idev->wait);
39136 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
39137 }
39138 @@ -461,7 +462,7 @@ static int uio_open(struct inode *inode, struct file *filep)
39139 }
39140
39141 listener->dev = idev;
39142 - listener->event_count = atomic_read(&idev->event);
39143 + listener->event_count = atomic_read_unchecked(&idev->event);
39144 filep->private_data = listener;
39145
39146 if (idev->info->open) {
39147 @@ -512,7 +513,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
39148 return -EIO;
39149
39150 poll_wait(filep, &idev->wait, wait);
39151 - if (listener->event_count != atomic_read(&idev->event))
39152 + if (listener->event_count != atomic_read_unchecked(&idev->event))
39153 return POLLIN | POLLRDNORM;
39154 return 0;
39155 }
39156 @@ -537,7 +538,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
39157 do {
39158 set_current_state(TASK_INTERRUPTIBLE);
39159
39160 - event_count = atomic_read(&idev->event);
39161 + event_count = atomic_read_unchecked(&idev->event);
39162 if (event_count != listener->event_count) {
39163 if (copy_to_user(buf, &event_count, count))
39164 retval = -EFAULT;
39165 @@ -606,13 +607,13 @@ static int uio_find_mem_index(struct vm_area_struct *vma)
39166 static void uio_vma_open(struct vm_area_struct *vma)
39167 {
39168 struct uio_device *idev = vma->vm_private_data;
39169 - idev->vma_count++;
39170 + local_inc(&idev->vma_count);
39171 }
39172
39173 static void uio_vma_close(struct vm_area_struct *vma)
39174 {
39175 struct uio_device *idev = vma->vm_private_data;
39176 - idev->vma_count--;
39177 + local_dec(&idev->vma_count);
39178 }
39179
39180 static int uio_vma_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
39181 @@ -821,7 +822,7 @@ int __uio_register_device(struct module *owner,
39182 idev->owner = owner;
39183 idev->info = info;
39184 init_waitqueue_head(&idev->wait);
39185 - atomic_set(&idev->event, 0);
39186 + atomic_set_unchecked(&idev->event, 0);
39187
39188 ret = uio_get_minor(idev);
39189 if (ret)
39190 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
39191 index b7eb86a..36d28af 100644
39192 --- a/drivers/usb/atm/cxacru.c
39193 +++ b/drivers/usb/atm/cxacru.c
39194 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
39195 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
39196 if (ret < 2)
39197 return -EINVAL;
39198 - if (index < 0 || index > 0x7f)
39199 + if (index > 0x7f)
39200 return -EINVAL;
39201 pos += tmp;
39202
39203 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
39204 index ee62b35..b663594 100644
39205 --- a/drivers/usb/atm/usbatm.c
39206 +++ b/drivers/usb/atm/usbatm.c
39207 @@ -333,7 +333,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39208 if (printk_ratelimit())
39209 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
39210 __func__, vpi, vci);
39211 - atomic_inc(&vcc->stats->rx_err);
39212 + atomic_inc_unchecked(&vcc->stats->rx_err);
39213 return;
39214 }
39215
39216 @@ -361,7 +361,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39217 if (length > ATM_MAX_AAL5_PDU) {
39218 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
39219 __func__, length, vcc);
39220 - atomic_inc(&vcc->stats->rx_err);
39221 + atomic_inc_unchecked(&vcc->stats->rx_err);
39222 goto out;
39223 }
39224
39225 @@ -370,14 +370,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39226 if (sarb->len < pdu_length) {
39227 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
39228 __func__, pdu_length, sarb->len, vcc);
39229 - atomic_inc(&vcc->stats->rx_err);
39230 + atomic_inc_unchecked(&vcc->stats->rx_err);
39231 goto out;
39232 }
39233
39234 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
39235 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
39236 __func__, vcc);
39237 - atomic_inc(&vcc->stats->rx_err);
39238 + atomic_inc_unchecked(&vcc->stats->rx_err);
39239 goto out;
39240 }
39241
39242 @@ -387,7 +387,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39243 if (printk_ratelimit())
39244 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
39245 __func__, length);
39246 - atomic_inc(&vcc->stats->rx_drop);
39247 + atomic_inc_unchecked(&vcc->stats->rx_drop);
39248 goto out;
39249 }
39250
39251 @@ -412,7 +412,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
39252
39253 vcc->push(vcc, skb);
39254
39255 - atomic_inc(&vcc->stats->rx);
39256 + atomic_inc_unchecked(&vcc->stats->rx);
39257 out:
39258 skb_trim(sarb, 0);
39259 }
39260 @@ -615,7 +615,7 @@ static void usbatm_tx_process(unsigned long data)
39261 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
39262
39263 usbatm_pop(vcc, skb);
39264 - atomic_inc(&vcc->stats->tx);
39265 + atomic_inc_unchecked(&vcc->stats->tx);
39266
39267 skb = skb_dequeue(&instance->sndqueue);
39268 }
39269 @@ -770,11 +770,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
39270 if (!left--)
39271 return sprintf(page,
39272 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
39273 - atomic_read(&atm_dev->stats.aal5.tx),
39274 - atomic_read(&atm_dev->stats.aal5.tx_err),
39275 - atomic_read(&atm_dev->stats.aal5.rx),
39276 - atomic_read(&atm_dev->stats.aal5.rx_err),
39277 - atomic_read(&atm_dev->stats.aal5.rx_drop));
39278 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
39279 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
39280 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
39281 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
39282 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
39283
39284 if (!left--) {
39285 if (instance->disconnected)
39286 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
39287 index 3440812..2a4ef1f 100644
39288 --- a/drivers/usb/core/devices.c
39289 +++ b/drivers/usb/core/devices.c
39290 @@ -126,7 +126,7 @@ static const char format_endpt[] =
39291 * time it gets called.
39292 */
39293 static struct device_connect_event {
39294 - atomic_t count;
39295 + atomic_unchecked_t count;
39296 wait_queue_head_t wait;
39297 } device_event = {
39298 .count = ATOMIC_INIT(1),
39299 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
39300
39301 void usbfs_conn_disc_event(void)
39302 {
39303 - atomic_add(2, &device_event.count);
39304 + atomic_add_unchecked(2, &device_event.count);
39305 wake_up(&device_event.wait);
39306 }
39307
39308 @@ -648,7 +648,7 @@ static unsigned int usb_device_poll(struct file *file,
39309
39310 poll_wait(file, &device_event.wait, wait);
39311
39312 - event_count = atomic_read(&device_event.count);
39313 + event_count = atomic_read_unchecked(&device_event.count);
39314 if (file->f_version != event_count) {
39315 file->f_version = event_count;
39316 return POLLIN | POLLRDNORM;
39317 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
39318 index 347bb05..63e1b73 100644
39319 --- a/drivers/usb/early/ehci-dbgp.c
39320 +++ b/drivers/usb/early/ehci-dbgp.c
39321 @@ -97,7 +97,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
39322
39323 #ifdef CONFIG_KGDB
39324 static struct kgdb_io kgdbdbgp_io_ops;
39325 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
39326 +static struct kgdb_io kgdbdbgp_io_ops_console;
39327 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
39328 #else
39329 #define dbgp_kgdb_mode (0)
39330 #endif
39331 @@ -1035,6 +1036,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
39332 .write_char = kgdbdbgp_write_char,
39333 };
39334
39335 +static struct kgdb_io kgdbdbgp_io_ops_console = {
39336 + .name = "kgdbdbgp",
39337 + .read_char = kgdbdbgp_read_char,
39338 + .write_char = kgdbdbgp_write_char,
39339 + .is_console = 1
39340 +};
39341 +
39342 static int kgdbdbgp_wait_time;
39343
39344 static int __init kgdbdbgp_parse_config(char *str)
39345 @@ -1050,8 +1058,10 @@ static int __init kgdbdbgp_parse_config(char *str)
39346 ptr++;
39347 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
39348 }
39349 - kgdb_register_io_module(&kgdbdbgp_io_ops);
39350 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
39351 + if (early_dbgp_console.index != -1)
39352 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
39353 + else
39354 + kgdb_register_io_module(&kgdbdbgp_io_ops);
39355
39356 return 0;
39357 }
39358 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
39359 index 5b3f5ff..6e00893 100644
39360 --- a/drivers/usb/gadget/u_serial.c
39361 +++ b/drivers/usb/gadget/u_serial.c
39362 @@ -731,9 +731,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39363 spin_lock_irq(&port->port_lock);
39364
39365 /* already open? Great. */
39366 - if (port->port.count) {
39367 + if (atomic_read(&port->port.count)) {
39368 status = 0;
39369 - port->port.count++;
39370 + atomic_inc(&port->port.count);
39371
39372 /* currently opening/closing? wait ... */
39373 } else if (port->openclose) {
39374 @@ -792,7 +792,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
39375 tty->driver_data = port;
39376 port->port.tty = tty;
39377
39378 - port->port.count = 1;
39379 + atomic_set(&port->port.count, 1);
39380 port->openclose = false;
39381
39382 /* if connected, start the I/O stream */
39383 @@ -834,11 +834,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39384
39385 spin_lock_irq(&port->port_lock);
39386
39387 - if (port->port.count != 1) {
39388 - if (port->port.count == 0)
39389 + if (atomic_read(&port->port.count) != 1) {
39390 + if (atomic_read(&port->port.count) == 0)
39391 WARN_ON(1);
39392 else
39393 - --port->port.count;
39394 + atomic_dec(&port->port.count);
39395 goto exit;
39396 }
39397
39398 @@ -848,7 +848,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
39399 * and sleep if necessary
39400 */
39401 port->openclose = true;
39402 - port->port.count = 0;
39403 + atomic_set(&port->port.count, 0);
39404
39405 gser = port->port_usb;
39406 if (gser && gser->disconnect)
39407 @@ -1152,7 +1152,7 @@ static int gs_closed(struct gs_port *port)
39408 int cond;
39409
39410 spin_lock_irq(&port->port_lock);
39411 - cond = (port->port.count == 0) && !port->openclose;
39412 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
39413 spin_unlock_irq(&port->port_lock);
39414 return cond;
39415 }
39416 @@ -1265,7 +1265,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
39417 /* if it's already open, start I/O ... and notify the serial
39418 * protocol about open/close status (connect/disconnect).
39419 */
39420 - if (port->port.count) {
39421 + if (atomic_read(&port->port.count)) {
39422 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
39423 gs_start_io(port);
39424 if (gser->connect)
39425 @@ -1312,7 +1312,7 @@ void gserial_disconnect(struct gserial *gser)
39426
39427 port->port_usb = NULL;
39428 gser->ioport = NULL;
39429 - if (port->port.count > 0 || port->openclose) {
39430 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
39431 wake_up_interruptible(&port->drain_wait);
39432 if (port->port.tty)
39433 tty_hangup(port->port.tty);
39434 @@ -1328,7 +1328,7 @@ void gserial_disconnect(struct gserial *gser)
39435
39436 /* finally, free any unused/unusable I/O buffers */
39437 spin_lock_irqsave(&port->port_lock, flags);
39438 - if (port->port.count == 0 && !port->openclose)
39439 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
39440 gs_buf_free(&port->port_write_buf);
39441 gs_free_requests(gser->out, &port->read_pool, NULL);
39442 gs_free_requests(gser->out, &port->read_queue, NULL);
39443 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
39444 index b9cca6d..75c75df 100644
39445 --- a/drivers/usb/serial/console.c
39446 +++ b/drivers/usb/serial/console.c
39447 @@ -127,7 +127,7 @@ static int usb_console_setup(struct console *co, char *options)
39448
39449 info->port = port;
39450
39451 - ++port->port.count;
39452 + atomic_inc(&port->port.count);
39453 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
39454 if (serial->type->set_termios) {
39455 /*
39456 @@ -177,7 +177,7 @@ static int usb_console_setup(struct console *co, char *options)
39457 }
39458 /* Now that any required fake tty operations are completed restore
39459 * the tty port count */
39460 - --port->port.count;
39461 + atomic_dec(&port->port.count);
39462 /* The console is special in terms of closing the device so
39463 * indicate this port is now acting as a system console. */
39464 port->port.console = 1;
39465 @@ -190,7 +190,7 @@ static int usb_console_setup(struct console *co, char *options)
39466 free_tty:
39467 kfree(tty);
39468 reset_open_count:
39469 - port->port.count = 0;
39470 + atomic_set(&port->port.count, 0);
39471 usb_autopm_put_interface(serial->interface);
39472 error_get_interface:
39473 usb_serial_put(serial);
39474 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
39475 index d6bea3e..60b250e 100644
39476 --- a/drivers/usb/wusbcore/wa-hc.h
39477 +++ b/drivers/usb/wusbcore/wa-hc.h
39478 @@ -192,7 +192,7 @@ struct wahc {
39479 struct list_head xfer_delayed_list;
39480 spinlock_t xfer_list_lock;
39481 struct work_struct xfer_work;
39482 - atomic_t xfer_id_count;
39483 + atomic_unchecked_t xfer_id_count;
39484 };
39485
39486
39487 @@ -246,7 +246,7 @@ static inline void wa_init(struct wahc *wa)
39488 INIT_LIST_HEAD(&wa->xfer_delayed_list);
39489 spin_lock_init(&wa->xfer_list_lock);
39490 INIT_WORK(&wa->xfer_work, wa_urb_enqueue_run);
39491 - atomic_set(&wa->xfer_id_count, 1);
39492 + atomic_set_unchecked(&wa->xfer_id_count, 1);
39493 }
39494
39495 /**
39496 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
39497 index 57c01ab..8a05959 100644
39498 --- a/drivers/usb/wusbcore/wa-xfer.c
39499 +++ b/drivers/usb/wusbcore/wa-xfer.c
39500 @@ -296,7 +296,7 @@ out:
39501 */
39502 static void wa_xfer_id_init(struct wa_xfer *xfer)
39503 {
39504 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
39505 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
39506 }
39507
39508 /*
39509 diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c
39510 index 112156f..eb81154 100644
39511 --- a/drivers/vhost/vhost.c
39512 +++ b/drivers/vhost/vhost.c
39513 @@ -635,7 +635,7 @@ static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m)
39514 return 0;
39515 }
39516
39517 -static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp)
39518 +static long vhost_set_vring(struct vhost_dev *d, unsigned int ioctl, void __user *argp)
39519 {
39520 struct file *eventfp, *filep = NULL,
39521 *pollstart = NULL, *pollstop = NULL;
39522 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
39523 index b0b2ac3..89a4399 100644
39524 --- a/drivers/video/aty/aty128fb.c
39525 +++ b/drivers/video/aty/aty128fb.c
39526 @@ -148,7 +148,7 @@ enum {
39527 };
39528
39529 /* Must match above enum */
39530 -static const char *r128_family[] __devinitdata = {
39531 +static const char *r128_family[] __devinitconst = {
39532 "AGP",
39533 "PCI",
39534 "PRO AGP",
39535 diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c
39536 index 88e9204..fdefa8f 100644
39537 --- a/drivers/video/console/fbcon.c
39538 +++ b/drivers/video/console/fbcon.c
39539 @@ -449,7 +449,7 @@ static int __init fb_console_setup(char *this_opt)
39540
39541 while ((options = strsep(&this_opt, ",")) != NULL) {
39542 if (!strncmp(options, "font:", 5))
39543 - strcpy(fontname, options + 5);
39544 + strlcpy(fontname, options + 5, sizeof(fontname));
39545
39546 if (!strncmp(options, "scrollback:", 11)) {
39547 options += 11;
39548 diff --git a/drivers/video/fbcmap.c b/drivers/video/fbcmap.c
39549 index 5c3960d..15cf8fc 100644
39550 --- a/drivers/video/fbcmap.c
39551 +++ b/drivers/video/fbcmap.c
39552 @@ -285,8 +285,7 @@ int fb_set_user_cmap(struct fb_cmap_user *cmap, struct fb_info *info)
39553 rc = -ENODEV;
39554 goto out;
39555 }
39556 - if (cmap->start < 0 || (!info->fbops->fb_setcolreg &&
39557 - !info->fbops->fb_setcmap)) {
39558 + if (!info->fbops->fb_setcolreg && !info->fbops->fb_setcmap) {
39559 rc = -EINVAL;
39560 goto out1;
39561 }
39562 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
39563 index 0dff12a..2ef47b3 100644
39564 --- a/drivers/video/fbmem.c
39565 +++ b/drivers/video/fbmem.c
39566 @@ -428,7 +428,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39567 image->dx += image->width + 8;
39568 }
39569 } else if (rotate == FB_ROTATE_UD) {
39570 - for (x = 0; x < num && image->dx >= 0; x++) {
39571 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
39572 info->fbops->fb_imageblit(info, image);
39573 image->dx -= image->width + 8;
39574 }
39575 @@ -440,7 +440,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
39576 image->dy += image->height + 8;
39577 }
39578 } else if (rotate == FB_ROTATE_CCW) {
39579 - for (x = 0; x < num && image->dy >= 0; x++) {
39580 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
39581 info->fbops->fb_imageblit(info, image);
39582 image->dy -= image->height + 8;
39583 }
39584 @@ -1166,7 +1166,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
39585 return -EFAULT;
39586 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
39587 return -EINVAL;
39588 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
39589 + if (con2fb.framebuffer >= FB_MAX)
39590 return -EINVAL;
39591 if (!registered_fb[con2fb.framebuffer])
39592 request_module("fb%d", con2fb.framebuffer);
39593 diff --git a/drivers/video/geode/gx1fb_core.c b/drivers/video/geode/gx1fb_core.c
39594 index 5a5d092..265c5ed 100644
39595 --- a/drivers/video/geode/gx1fb_core.c
39596 +++ b/drivers/video/geode/gx1fb_core.c
39597 @@ -29,7 +29,7 @@ static int crt_option = 1;
39598 static char panel_option[32] = "";
39599
39600 /* Modes relevant to the GX1 (taken from modedb.c) */
39601 -static const struct fb_videomode __devinitdata gx1_modedb[] = {
39602 +static const struct fb_videomode __devinitconst gx1_modedb[] = {
39603 /* 640x480-60 VESA */
39604 { NULL, 60, 640, 480, 39682, 48, 16, 33, 10, 96, 2,
39605 0, FB_VMODE_NONINTERLACED, FB_MODE_IS_VESA },
39606 diff --git a/drivers/video/gxt4500.c b/drivers/video/gxt4500.c
39607 index 0fad23f..0e9afa4 100644
39608 --- a/drivers/video/gxt4500.c
39609 +++ b/drivers/video/gxt4500.c
39610 @@ -156,7 +156,7 @@ struct gxt4500_par {
39611 static char *mode_option;
39612
39613 /* default mode: 1280x1024 @ 60 Hz, 8 bpp */
39614 -static const struct fb_videomode defaultmode __devinitdata = {
39615 +static const struct fb_videomode defaultmode __devinitconst = {
39616 .refresh = 60,
39617 .xres = 1280,
39618 .yres = 1024,
39619 @@ -581,7 +581,7 @@ static int gxt4500_blank(int blank, struct fb_info *info)
39620 return 0;
39621 }
39622
39623 -static const struct fb_fix_screeninfo gxt4500_fix __devinitdata = {
39624 +static const struct fb_fix_screeninfo gxt4500_fix __devinitconst = {
39625 .id = "IBM GXT4500P",
39626 .type = FB_TYPE_PACKED_PIXELS,
39627 .visual = FB_VISUAL_PSEUDOCOLOR,
39628 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
39629 index 7672d2e..b56437f 100644
39630 --- a/drivers/video/i810/i810_accel.c
39631 +++ b/drivers/video/i810/i810_accel.c
39632 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
39633 }
39634 }
39635 printk("ringbuffer lockup!!!\n");
39636 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
39637 i810_report_error(mmio);
39638 par->dev_flags |= LOCKUP;
39639 info->pixmap.scan_align = 1;
39640 diff --git a/drivers/video/i810/i810_main.c b/drivers/video/i810/i810_main.c
39641 index b83f361..2b05a91 100644
39642 --- a/drivers/video/i810/i810_main.c
39643 +++ b/drivers/video/i810/i810_main.c
39644 @@ -97,7 +97,7 @@ static int i810fb_blank (int blank_mode, struct fb_info *info);
39645 static void i810fb_release_resource (struct fb_info *info, struct i810fb_par *par);
39646
39647 /* PCI */
39648 -static const char *i810_pci_list[] __devinitdata = {
39649 +static const char *i810_pci_list[] __devinitconst = {
39650 "Intel(R) 810 Framebuffer Device" ,
39651 "Intel(R) 810-DC100 Framebuffer Device" ,
39652 "Intel(R) 810E Framebuffer Device" ,
39653 diff --git a/drivers/video/jz4740_fb.c b/drivers/video/jz4740_fb.c
39654 index de36693..3c63fc2 100644
39655 --- a/drivers/video/jz4740_fb.c
39656 +++ b/drivers/video/jz4740_fb.c
39657 @@ -136,7 +136,7 @@ struct jzfb {
39658 uint32_t pseudo_palette[16];
39659 };
39660
39661 -static const struct fb_fix_screeninfo jzfb_fix __devinitdata = {
39662 +static const struct fb_fix_screeninfo jzfb_fix __devinitconst = {
39663 .id = "JZ4740 FB",
39664 .type = FB_TYPE_PACKED_PIXELS,
39665 .visual = FB_VISUAL_TRUECOLOR,
39666 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
39667 index 3c14e43..eafa544 100644
39668 --- a/drivers/video/logo/logo_linux_clut224.ppm
39669 +++ b/drivers/video/logo/logo_linux_clut224.ppm
39670 @@ -1,1604 +1,1123 @@
39671 P3
39672 -# Standard 224-color Linux logo
39673 80 80
39674 255
39675 - 0 0 0 0 0 0 0 0 0 0 0 0
39676 - 0 0 0 0 0 0 0 0 0 0 0 0
39677 - 0 0 0 0 0 0 0 0 0 0 0 0
39678 - 0 0 0 0 0 0 0 0 0 0 0 0
39679 - 0 0 0 0 0 0 0 0 0 0 0 0
39680 - 0 0 0 0 0 0 0 0 0 0 0 0
39681 - 0 0 0 0 0 0 0 0 0 0 0 0
39682 - 0 0 0 0 0 0 0 0 0 0 0 0
39683 - 0 0 0 0 0 0 0 0 0 0 0 0
39684 - 6 6 6 6 6 6 10 10 10 10 10 10
39685 - 10 10 10 6 6 6 6 6 6 6 6 6
39686 - 0 0 0 0 0 0 0 0 0 0 0 0
39687 - 0 0 0 0 0 0 0 0 0 0 0 0
39688 - 0 0 0 0 0 0 0 0 0 0 0 0
39689 - 0 0 0 0 0 0 0 0 0 0 0 0
39690 - 0 0 0 0 0 0 0 0 0 0 0 0
39691 - 0 0 0 0 0 0 0 0 0 0 0 0
39692 - 0 0 0 0 0 0 0 0 0 0 0 0
39693 - 0 0 0 0 0 0 0 0 0 0 0 0
39694 - 0 0 0 0 0 0 0 0 0 0 0 0
39695 - 0 0 0 0 0 0 0 0 0 0 0 0
39696 - 0 0 0 0 0 0 0 0 0 0 0 0
39697 - 0 0 0 0 0 0 0 0 0 0 0 0
39698 - 0 0 0 0 0 0 0 0 0 0 0 0
39699 - 0 0 0 0 0 0 0 0 0 0 0 0
39700 - 0 0 0 0 0 0 0 0 0 0 0 0
39701 - 0 0 0 0 0 0 0 0 0 0 0 0
39702 - 0 0 0 0 0 0 0 0 0 0 0 0
39703 - 0 0 0 6 6 6 10 10 10 14 14 14
39704 - 22 22 22 26 26 26 30 30 30 34 34 34
39705 - 30 30 30 30 30 30 26 26 26 18 18 18
39706 - 14 14 14 10 10 10 6 6 6 0 0 0
39707 - 0 0 0 0 0 0 0 0 0 0 0 0
39708 - 0 0 0 0 0 0 0 0 0 0 0 0
39709 - 0 0 0 0 0 0 0 0 0 0 0 0
39710 - 0 0 0 0 0 0 0 0 0 0 0 0
39711 - 0 0 0 0 0 0 0 0 0 0 0 0
39712 - 0 0 0 0 0 0 0 0 0 0 0 0
39713 - 0 0 0 0 0 0 0 0 0 0 0 0
39714 - 0 0 0 0 0 0 0 0 0 0 0 0
39715 - 0 0 0 0 0 0 0 0 0 0 0 0
39716 - 0 0 0 0 0 1 0 0 1 0 0 0
39717 - 0 0 0 0 0 0 0 0 0 0 0 0
39718 - 0 0 0 0 0 0 0 0 0 0 0 0
39719 - 0 0 0 0 0 0 0 0 0 0 0 0
39720 - 0 0 0 0 0 0 0 0 0 0 0 0
39721 - 0 0 0 0 0 0 0 0 0 0 0 0
39722 - 0 0 0 0 0 0 0 0 0 0 0 0
39723 - 6 6 6 14 14 14 26 26 26 42 42 42
39724 - 54 54 54 66 66 66 78 78 78 78 78 78
39725 - 78 78 78 74 74 74 66 66 66 54 54 54
39726 - 42 42 42 26 26 26 18 18 18 10 10 10
39727 - 6 6 6 0 0 0 0 0 0 0 0 0
39728 - 0 0 0 0 0 0 0 0 0 0 0 0
39729 - 0 0 0 0 0 0 0 0 0 0 0 0
39730 - 0 0 0 0 0 0 0 0 0 0 0 0
39731 - 0 0 0 0 0 0 0 0 0 0 0 0
39732 - 0 0 0 0 0 0 0 0 0 0 0 0
39733 - 0 0 0 0 0 0 0 0 0 0 0 0
39734 - 0 0 0 0 0 0 0 0 0 0 0 0
39735 - 0 0 0 0 0 0 0 0 0 0 0 0
39736 - 0 0 1 0 0 0 0 0 0 0 0 0
39737 - 0 0 0 0 0 0 0 0 0 0 0 0
39738 - 0 0 0 0 0 0 0 0 0 0 0 0
39739 - 0 0 0 0 0 0 0 0 0 0 0 0
39740 - 0 0 0 0 0 0 0 0 0 0 0 0
39741 - 0 0 0 0 0 0 0 0 0 0 0 0
39742 - 0 0 0 0 0 0 0 0 0 10 10 10
39743 - 22 22 22 42 42 42 66 66 66 86 86 86
39744 - 66 66 66 38 38 38 38 38 38 22 22 22
39745 - 26 26 26 34 34 34 54 54 54 66 66 66
39746 - 86 86 86 70 70 70 46 46 46 26 26 26
39747 - 14 14 14 6 6 6 0 0 0 0 0 0
39748 - 0 0 0 0 0 0 0 0 0 0 0 0
39749 - 0 0 0 0 0 0 0 0 0 0 0 0
39750 - 0 0 0 0 0 0 0 0 0 0 0 0
39751 - 0 0 0 0 0 0 0 0 0 0 0 0
39752 - 0 0 0 0 0 0 0 0 0 0 0 0
39753 - 0 0 0 0 0 0 0 0 0 0 0 0
39754 - 0 0 0 0 0 0 0 0 0 0 0 0
39755 - 0 0 0 0 0 0 0 0 0 0 0 0
39756 - 0 0 1 0 0 1 0 0 1 0 0 0
39757 - 0 0 0 0 0 0 0 0 0 0 0 0
39758 - 0 0 0 0 0 0 0 0 0 0 0 0
39759 - 0 0 0 0 0 0 0 0 0 0 0 0
39760 - 0 0 0 0 0 0 0 0 0 0 0 0
39761 - 0 0 0 0 0 0 0 0 0 0 0 0
39762 - 0 0 0 0 0 0 10 10 10 26 26 26
39763 - 50 50 50 82 82 82 58 58 58 6 6 6
39764 - 2 2 6 2 2 6 2 2 6 2 2 6
39765 - 2 2 6 2 2 6 2 2 6 2 2 6
39766 - 6 6 6 54 54 54 86 86 86 66 66 66
39767 - 38 38 38 18 18 18 6 6 6 0 0 0
39768 - 0 0 0 0 0 0 0 0 0 0 0 0
39769 - 0 0 0 0 0 0 0 0 0 0 0 0
39770 - 0 0 0 0 0 0 0 0 0 0 0 0
39771 - 0 0 0 0 0 0 0 0 0 0 0 0
39772 - 0 0 0 0 0 0 0 0 0 0 0 0
39773 - 0 0 0 0 0 0 0 0 0 0 0 0
39774 - 0 0 0 0 0 0 0 0 0 0 0 0
39775 - 0 0 0 0 0 0 0 0 0 0 0 0
39776 - 0 0 0 0 0 0 0 0 0 0 0 0
39777 - 0 0 0 0 0 0 0 0 0 0 0 0
39778 - 0 0 0 0 0 0 0 0 0 0 0 0
39779 - 0 0 0 0 0 0 0 0 0 0 0 0
39780 - 0 0 0 0 0 0 0 0 0 0 0 0
39781 - 0 0 0 0 0 0 0 0 0 0 0 0
39782 - 0 0 0 6 6 6 22 22 22 50 50 50
39783 - 78 78 78 34 34 34 2 2 6 2 2 6
39784 - 2 2 6 2 2 6 2 2 6 2 2 6
39785 - 2 2 6 2 2 6 2 2 6 2 2 6
39786 - 2 2 6 2 2 6 6 6 6 70 70 70
39787 - 78 78 78 46 46 46 22 22 22 6 6 6
39788 - 0 0 0 0 0 0 0 0 0 0 0 0
39789 - 0 0 0 0 0 0 0 0 0 0 0 0
39790 - 0 0 0 0 0 0 0 0 0 0 0 0
39791 - 0 0 0 0 0 0 0 0 0 0 0 0
39792 - 0 0 0 0 0 0 0 0 0 0 0 0
39793 - 0 0 0 0 0 0 0 0 0 0 0 0
39794 - 0 0 0 0 0 0 0 0 0 0 0 0
39795 - 0 0 0 0 0 0 0 0 0 0 0 0
39796 - 0 0 1 0 0 1 0 0 1 0 0 0
39797 - 0 0 0 0 0 0 0 0 0 0 0 0
39798 - 0 0 0 0 0 0 0 0 0 0 0 0
39799 - 0 0 0 0 0 0 0 0 0 0 0 0
39800 - 0 0 0 0 0 0 0 0 0 0 0 0
39801 - 0 0 0 0 0 0 0 0 0 0 0 0
39802 - 6 6 6 18 18 18 42 42 42 82 82 82
39803 - 26 26 26 2 2 6 2 2 6 2 2 6
39804 - 2 2 6 2 2 6 2 2 6 2 2 6
39805 - 2 2 6 2 2 6 2 2 6 14 14 14
39806 - 46 46 46 34 34 34 6 6 6 2 2 6
39807 - 42 42 42 78 78 78 42 42 42 18 18 18
39808 - 6 6 6 0 0 0 0 0 0 0 0 0
39809 - 0 0 0 0 0 0 0 0 0 0 0 0
39810 - 0 0 0 0 0 0 0 0 0 0 0 0
39811 - 0 0 0 0 0 0 0 0 0 0 0 0
39812 - 0 0 0 0 0 0 0 0 0 0 0 0
39813 - 0 0 0 0 0 0 0 0 0 0 0 0
39814 - 0 0 0 0 0 0 0 0 0 0 0 0
39815 - 0 0 0 0 0 0 0 0 0 0 0 0
39816 - 0 0 1 0 0 0 0 0 1 0 0 0
39817 - 0 0 0 0 0 0 0 0 0 0 0 0
39818 - 0 0 0 0 0 0 0 0 0 0 0 0
39819 - 0 0 0 0 0 0 0 0 0 0 0 0
39820 - 0 0 0 0 0 0 0 0 0 0 0 0
39821 - 0 0 0 0 0 0 0 0 0 0 0 0
39822 - 10 10 10 30 30 30 66 66 66 58 58 58
39823 - 2 2 6 2 2 6 2 2 6 2 2 6
39824 - 2 2 6 2 2 6 2 2 6 2 2 6
39825 - 2 2 6 2 2 6 2 2 6 26 26 26
39826 - 86 86 86 101 101 101 46 46 46 10 10 10
39827 - 2 2 6 58 58 58 70 70 70 34 34 34
39828 - 10 10 10 0 0 0 0 0 0 0 0 0
39829 - 0 0 0 0 0 0 0 0 0 0 0 0
39830 - 0 0 0 0 0 0 0 0 0 0 0 0
39831 - 0 0 0 0 0 0 0 0 0 0 0 0
39832 - 0 0 0 0 0 0 0 0 0 0 0 0
39833 - 0 0 0 0 0 0 0 0 0 0 0 0
39834 - 0 0 0 0 0 0 0 0 0 0 0 0
39835 - 0 0 0 0 0 0 0 0 0 0 0 0
39836 - 0 0 1 0 0 1 0 0 1 0 0 0
39837 - 0 0 0 0 0 0 0 0 0 0 0 0
39838 - 0 0 0 0 0 0 0 0 0 0 0 0
39839 - 0 0 0 0 0 0 0 0 0 0 0 0
39840 - 0 0 0 0 0 0 0 0 0 0 0 0
39841 - 0 0 0 0 0 0 0 0 0 0 0 0
39842 - 14 14 14 42 42 42 86 86 86 10 10 10
39843 - 2 2 6 2 2 6 2 2 6 2 2 6
39844 - 2 2 6 2 2 6 2 2 6 2 2 6
39845 - 2 2 6 2 2 6 2 2 6 30 30 30
39846 - 94 94 94 94 94 94 58 58 58 26 26 26
39847 - 2 2 6 6 6 6 78 78 78 54 54 54
39848 - 22 22 22 6 6 6 0 0 0 0 0 0
39849 - 0 0 0 0 0 0 0 0 0 0 0 0
39850 - 0 0 0 0 0 0 0 0 0 0 0 0
39851 - 0 0 0 0 0 0 0 0 0 0 0 0
39852 - 0 0 0 0 0 0 0 0 0 0 0 0
39853 - 0 0 0 0 0 0 0 0 0 0 0 0
39854 - 0 0 0 0 0 0 0 0 0 0 0 0
39855 - 0 0 0 0 0 0 0 0 0 0 0 0
39856 - 0 0 0 0 0 0 0 0 0 0 0 0
39857 - 0 0 0 0 0 0 0 0 0 0 0 0
39858 - 0 0 0 0 0 0 0 0 0 0 0 0
39859 - 0 0 0 0 0 0 0 0 0 0 0 0
39860 - 0 0 0 0 0 0 0 0 0 0 0 0
39861 - 0 0 0 0 0 0 0 0 0 6 6 6
39862 - 22 22 22 62 62 62 62 62 62 2 2 6
39863 - 2 2 6 2 2 6 2 2 6 2 2 6
39864 - 2 2 6 2 2 6 2 2 6 2 2 6
39865 - 2 2 6 2 2 6 2 2 6 26 26 26
39866 - 54 54 54 38 38 38 18 18 18 10 10 10
39867 - 2 2 6 2 2 6 34 34 34 82 82 82
39868 - 38 38 38 14 14 14 0 0 0 0 0 0
39869 - 0 0 0 0 0 0 0 0 0 0 0 0
39870 - 0 0 0 0 0 0 0 0 0 0 0 0
39871 - 0 0 0 0 0 0 0 0 0 0 0 0
39872 - 0 0 0 0 0 0 0 0 0 0 0 0
39873 - 0 0 0 0 0 0 0 0 0 0 0 0
39874 - 0 0 0 0 0 0 0 0 0 0 0 0
39875 - 0 0 0 0 0 0 0 0 0 0 0 0
39876 - 0 0 0 0 0 1 0 0 1 0 0 0
39877 - 0 0 0 0 0 0 0 0 0 0 0 0
39878 - 0 0 0 0 0 0 0 0 0 0 0 0
39879 - 0 0 0 0 0 0 0 0 0 0 0 0
39880 - 0 0 0 0 0 0 0 0 0 0 0 0
39881 - 0 0 0 0 0 0 0 0 0 6 6 6
39882 - 30 30 30 78 78 78 30 30 30 2 2 6
39883 - 2 2 6 2 2 6 2 2 6 2 2 6
39884 - 2 2 6 2 2 6 2 2 6 2 2 6
39885 - 2 2 6 2 2 6 2 2 6 10 10 10
39886 - 10 10 10 2 2 6 2 2 6 2 2 6
39887 - 2 2 6 2 2 6 2 2 6 78 78 78
39888 - 50 50 50 18 18 18 6 6 6 0 0 0
39889 - 0 0 0 0 0 0 0 0 0 0 0 0
39890 - 0 0 0 0 0 0 0 0 0 0 0 0
39891 - 0 0 0 0 0 0 0 0 0 0 0 0
39892 - 0 0 0 0 0 0 0 0 0 0 0 0
39893 - 0 0 0 0 0 0 0 0 0 0 0 0
39894 - 0 0 0 0 0 0 0 0 0 0 0 0
39895 - 0 0 0 0 0 0 0 0 0 0 0 0
39896 - 0 0 1 0 0 0 0 0 0 0 0 0
39897 - 0 0 0 0 0 0 0 0 0 0 0 0
39898 - 0 0 0 0 0 0 0 0 0 0 0 0
39899 - 0 0 0 0 0 0 0 0 0 0 0 0
39900 - 0 0 0 0 0 0 0 0 0 0 0 0
39901 - 0 0 0 0 0 0 0 0 0 10 10 10
39902 - 38 38 38 86 86 86 14 14 14 2 2 6
39903 - 2 2 6 2 2 6 2 2 6 2 2 6
39904 - 2 2 6 2 2 6 2 2 6 2 2 6
39905 - 2 2 6 2 2 6 2 2 6 2 2 6
39906 - 2 2 6 2 2 6 2 2 6 2 2 6
39907 - 2 2 6 2 2 6 2 2 6 54 54 54
39908 - 66 66 66 26 26 26 6 6 6 0 0 0
39909 - 0 0 0 0 0 0 0 0 0 0 0 0
39910 - 0 0 0 0 0 0 0 0 0 0 0 0
39911 - 0 0 0 0 0 0 0 0 0 0 0 0
39912 - 0 0 0 0 0 0 0 0 0 0 0 0
39913 - 0 0 0 0 0 0 0 0 0 0 0 0
39914 - 0 0 0 0 0 0 0 0 0 0 0 0
39915 - 0 0 0 0 0 0 0 0 0 0 0 0
39916 - 0 0 0 0 0 1 0 0 1 0 0 0
39917 - 0 0 0 0 0 0 0 0 0 0 0 0
39918 - 0 0 0 0 0 0 0 0 0 0 0 0
39919 - 0 0 0 0 0 0 0 0 0 0 0 0
39920 - 0 0 0 0 0 0 0 0 0 0 0 0
39921 - 0 0 0 0 0 0 0 0 0 14 14 14
39922 - 42 42 42 82 82 82 2 2 6 2 2 6
39923 - 2 2 6 6 6 6 10 10 10 2 2 6
39924 - 2 2 6 2 2 6 2 2 6 2 2 6
39925 - 2 2 6 2 2 6 2 2 6 6 6 6
39926 - 14 14 14 10 10 10 2 2 6 2 2 6
39927 - 2 2 6 2 2 6 2 2 6 18 18 18
39928 - 82 82 82 34 34 34 10 10 10 0 0 0
39929 - 0 0 0 0 0 0 0 0 0 0 0 0
39930 - 0 0 0 0 0 0 0 0 0 0 0 0
39931 - 0 0 0 0 0 0 0 0 0 0 0 0
39932 - 0 0 0 0 0 0 0 0 0 0 0 0
39933 - 0 0 0 0 0 0 0 0 0 0 0 0
39934 - 0 0 0 0 0 0 0 0 0 0 0 0
39935 - 0 0 0 0 0 0 0 0 0 0 0 0
39936 - 0 0 1 0 0 0 0 0 0 0 0 0
39937 - 0 0 0 0 0 0 0 0 0 0 0 0
39938 - 0 0 0 0 0 0 0 0 0 0 0 0
39939 - 0 0 0 0 0 0 0 0 0 0 0 0
39940 - 0 0 0 0 0 0 0 0 0 0 0 0
39941 - 0 0 0 0 0 0 0 0 0 14 14 14
39942 - 46 46 46 86 86 86 2 2 6 2 2 6
39943 - 6 6 6 6 6 6 22 22 22 34 34 34
39944 - 6 6 6 2 2 6 2 2 6 2 2 6
39945 - 2 2 6 2 2 6 18 18 18 34 34 34
39946 - 10 10 10 50 50 50 22 22 22 2 2 6
39947 - 2 2 6 2 2 6 2 2 6 10 10 10
39948 - 86 86 86 42 42 42 14 14 14 0 0 0
39949 - 0 0 0 0 0 0 0 0 0 0 0 0
39950 - 0 0 0 0 0 0 0 0 0 0 0 0
39951 - 0 0 0 0 0 0 0 0 0 0 0 0
39952 - 0 0 0 0 0 0 0 0 0 0 0 0
39953 - 0 0 0 0 0 0 0 0 0 0 0 0
39954 - 0 0 0 0 0 0 0 0 0 0 0 0
39955 - 0 0 0 0 0 0 0 0 0 0 0 0
39956 - 0 0 1 0 0 1 0 0 1 0 0 0
39957 - 0 0 0 0 0 0 0 0 0 0 0 0
39958 - 0 0 0 0 0 0 0 0 0 0 0 0
39959 - 0 0 0 0 0 0 0 0 0 0 0 0
39960 - 0 0 0 0 0 0 0 0 0 0 0 0
39961 - 0 0 0 0 0 0 0 0 0 14 14 14
39962 - 46 46 46 86 86 86 2 2 6 2 2 6
39963 - 38 38 38 116 116 116 94 94 94 22 22 22
39964 - 22 22 22 2 2 6 2 2 6 2 2 6
39965 - 14 14 14 86 86 86 138 138 138 162 162 162
39966 -154 154 154 38 38 38 26 26 26 6 6 6
39967 - 2 2 6 2 2 6 2 2 6 2 2 6
39968 - 86 86 86 46 46 46 14 14 14 0 0 0
39969 - 0 0 0 0 0 0 0 0 0 0 0 0
39970 - 0 0 0 0 0 0 0 0 0 0 0 0
39971 - 0 0 0 0 0 0 0 0 0 0 0 0
39972 - 0 0 0 0 0 0 0 0 0 0 0 0
39973 - 0 0 0 0 0 0 0 0 0 0 0 0
39974 - 0 0 0 0 0 0 0 0 0 0 0 0
39975 - 0 0 0 0 0 0 0 0 0 0 0 0
39976 - 0 0 0 0 0 0 0 0 0 0 0 0
39977 - 0 0 0 0 0 0 0 0 0 0 0 0
39978 - 0 0 0 0 0 0 0 0 0 0 0 0
39979 - 0 0 0 0 0 0 0 0 0 0 0 0
39980 - 0 0 0 0 0 0 0 0 0 0 0 0
39981 - 0 0 0 0 0 0 0 0 0 14 14 14
39982 - 46 46 46 86 86 86 2 2 6 14 14 14
39983 -134 134 134 198 198 198 195 195 195 116 116 116
39984 - 10 10 10 2 2 6 2 2 6 6 6 6
39985 -101 98 89 187 187 187 210 210 210 218 218 218
39986 -214 214 214 134 134 134 14 14 14 6 6 6
39987 - 2 2 6 2 2 6 2 2 6 2 2 6
39988 - 86 86 86 50 50 50 18 18 18 6 6 6
39989 - 0 0 0 0 0 0 0 0 0 0 0 0
39990 - 0 0 0 0 0 0 0 0 0 0 0 0
39991 - 0 0 0 0 0 0 0 0 0 0 0 0
39992 - 0 0 0 0 0 0 0 0 0 0 0 0
39993 - 0 0 0 0 0 0 0 0 0 0 0 0
39994 - 0 0 0 0 0 0 0 0 0 0 0 0
39995 - 0 0 0 0 0 0 0 0 1 0 0 0
39996 - 0 0 1 0 0 1 0 0 1 0 0 0
39997 - 0 0 0 0 0 0 0 0 0 0 0 0
39998 - 0 0 0 0 0 0 0 0 0 0 0 0
39999 - 0 0 0 0 0 0 0 0 0 0 0 0
40000 - 0 0 0 0 0 0 0 0 0 0 0 0
40001 - 0 0 0 0 0 0 0 0 0 14 14 14
40002 - 46 46 46 86 86 86 2 2 6 54 54 54
40003 -218 218 218 195 195 195 226 226 226 246 246 246
40004 - 58 58 58 2 2 6 2 2 6 30 30 30
40005 -210 210 210 253 253 253 174 174 174 123 123 123
40006 -221 221 221 234 234 234 74 74 74 2 2 6
40007 - 2 2 6 2 2 6 2 2 6 2 2 6
40008 - 70 70 70 58 58 58 22 22 22 6 6 6
40009 - 0 0 0 0 0 0 0 0 0 0 0 0
40010 - 0 0 0 0 0 0 0 0 0 0 0 0
40011 - 0 0 0 0 0 0 0 0 0 0 0 0
40012 - 0 0 0 0 0 0 0 0 0 0 0 0
40013 - 0 0 0 0 0 0 0 0 0 0 0 0
40014 - 0 0 0 0 0 0 0 0 0 0 0 0
40015 - 0 0 0 0 0 0 0 0 0 0 0 0
40016 - 0 0 0 0 0 0 0 0 0 0 0 0
40017 - 0 0 0 0 0 0 0 0 0 0 0 0
40018 - 0 0 0 0 0 0 0 0 0 0 0 0
40019 - 0 0 0 0 0 0 0 0 0 0 0 0
40020 - 0 0 0 0 0 0 0 0 0 0 0 0
40021 - 0 0 0 0 0 0 0 0 0 14 14 14
40022 - 46 46 46 82 82 82 2 2 6 106 106 106
40023 -170 170 170 26 26 26 86 86 86 226 226 226
40024 -123 123 123 10 10 10 14 14 14 46 46 46
40025 -231 231 231 190 190 190 6 6 6 70 70 70
40026 - 90 90 90 238 238 238 158 158 158 2 2 6
40027 - 2 2 6 2 2 6 2 2 6 2 2 6
40028 - 70 70 70 58 58 58 22 22 22 6 6 6
40029 - 0 0 0 0 0 0 0 0 0 0 0 0
40030 - 0 0 0 0 0 0 0 0 0 0 0 0
40031 - 0 0 0 0 0 0 0 0 0 0 0 0
40032 - 0 0 0 0 0 0 0 0 0 0 0 0
40033 - 0 0 0 0 0 0 0 0 0 0 0 0
40034 - 0 0 0 0 0 0 0 0 0 0 0 0
40035 - 0 0 0 0 0 0 0 0 1 0 0 0
40036 - 0 0 1 0 0 1 0 0 1 0 0 0
40037 - 0 0 0 0 0 0 0 0 0 0 0 0
40038 - 0 0 0 0 0 0 0 0 0 0 0 0
40039 - 0 0 0 0 0 0 0 0 0 0 0 0
40040 - 0 0 0 0 0 0 0 0 0 0 0 0
40041 - 0 0 0 0 0 0 0 0 0 14 14 14
40042 - 42 42 42 86 86 86 6 6 6 116 116 116
40043 -106 106 106 6 6 6 70 70 70 149 149 149
40044 -128 128 128 18 18 18 38 38 38 54 54 54
40045 -221 221 221 106 106 106 2 2 6 14 14 14
40046 - 46 46 46 190 190 190 198 198 198 2 2 6
40047 - 2 2 6 2 2 6 2 2 6 2 2 6
40048 - 74 74 74 62 62 62 22 22 22 6 6 6
40049 - 0 0 0 0 0 0 0 0 0 0 0 0
40050 - 0 0 0 0 0 0 0 0 0 0 0 0
40051 - 0 0 0 0 0 0 0 0 0 0 0 0
40052 - 0 0 0 0 0 0 0 0 0 0 0 0
40053 - 0 0 0 0 0 0 0 0 0 0 0 0
40054 - 0 0 0 0 0 0 0 0 0 0 0 0
40055 - 0 0 0 0 0 0 0 0 1 0 0 0
40056 - 0 0 1 0 0 0 0 0 1 0 0 0
40057 - 0 0 0 0 0 0 0 0 0 0 0 0
40058 - 0 0 0 0 0 0 0 0 0 0 0 0
40059 - 0 0 0 0 0 0 0 0 0 0 0 0
40060 - 0 0 0 0 0 0 0 0 0 0 0 0
40061 - 0 0 0 0 0 0 0 0 0 14 14 14
40062 - 42 42 42 94 94 94 14 14 14 101 101 101
40063 -128 128 128 2 2 6 18 18 18 116 116 116
40064 -118 98 46 121 92 8 121 92 8 98 78 10
40065 -162 162 162 106 106 106 2 2 6 2 2 6
40066 - 2 2 6 195 195 195 195 195 195 6 6 6
40067 - 2 2 6 2 2 6 2 2 6 2 2 6
40068 - 74 74 74 62 62 62 22 22 22 6 6 6
40069 - 0 0 0 0 0 0 0 0 0 0 0 0
40070 - 0 0 0 0 0 0 0 0 0 0 0 0
40071 - 0 0 0 0 0 0 0 0 0 0 0 0
40072 - 0 0 0 0 0 0 0 0 0 0 0 0
40073 - 0 0 0 0 0 0 0 0 0 0 0 0
40074 - 0 0 0 0 0 0 0 0 0 0 0 0
40075 - 0 0 0 0 0 0 0 0 1 0 0 1
40076 - 0 0 1 0 0 0 0 0 1 0 0 0
40077 - 0 0 0 0 0 0 0 0 0 0 0 0
40078 - 0 0 0 0 0 0 0 0 0 0 0 0
40079 - 0 0 0 0 0 0 0 0 0 0 0 0
40080 - 0 0 0 0 0 0 0 0 0 0 0 0
40081 - 0 0 0 0 0 0 0 0 0 10 10 10
40082 - 38 38 38 90 90 90 14 14 14 58 58 58
40083 -210 210 210 26 26 26 54 38 6 154 114 10
40084 -226 170 11 236 186 11 225 175 15 184 144 12
40085 -215 174 15 175 146 61 37 26 9 2 2 6
40086 - 70 70 70 246 246 246 138 138 138 2 2 6
40087 - 2 2 6 2 2 6 2 2 6 2 2 6
40088 - 70 70 70 66 66 66 26 26 26 6 6 6
40089 - 0 0 0 0 0 0 0 0 0 0 0 0
40090 - 0 0 0 0 0 0 0 0 0 0 0 0
40091 - 0 0 0 0 0 0 0 0 0 0 0 0
40092 - 0 0 0 0 0 0 0 0 0 0 0 0
40093 - 0 0 0 0 0 0 0 0 0 0 0 0
40094 - 0 0 0 0 0 0 0 0 0 0 0 0
40095 - 0 0 0 0 0 0 0 0 0 0 0 0
40096 - 0 0 0 0 0 0 0 0 0 0 0 0
40097 - 0 0 0 0 0 0 0 0 0 0 0 0
40098 - 0 0 0 0 0 0 0 0 0 0 0 0
40099 - 0 0 0 0 0 0 0 0 0 0 0 0
40100 - 0 0 0 0 0 0 0 0 0 0 0 0
40101 - 0 0 0 0 0 0 0 0 0 10 10 10
40102 - 38 38 38 86 86 86 14 14 14 10 10 10
40103 -195 195 195 188 164 115 192 133 9 225 175 15
40104 -239 182 13 234 190 10 232 195 16 232 200 30
40105 -245 207 45 241 208 19 232 195 16 184 144 12
40106 -218 194 134 211 206 186 42 42 42 2 2 6
40107 - 2 2 6 2 2 6 2 2 6 2 2 6
40108 - 50 50 50 74 74 74 30 30 30 6 6 6
40109 - 0 0 0 0 0 0 0 0 0 0 0 0
40110 - 0 0 0 0 0 0 0 0 0 0 0 0
40111 - 0 0 0 0 0 0 0 0 0 0 0 0
40112 - 0 0 0 0 0 0 0 0 0 0 0 0
40113 - 0 0 0 0 0 0 0 0 0 0 0 0
40114 - 0 0 0 0 0 0 0 0 0 0 0 0
40115 - 0 0 0 0 0 0 0 0 0 0 0 0
40116 - 0 0 0 0 0 0 0 0 0 0 0 0
40117 - 0 0 0 0 0 0 0 0 0 0 0 0
40118 - 0 0 0 0 0 0 0 0 0 0 0 0
40119 - 0 0 0 0 0 0 0 0 0 0 0 0
40120 - 0 0 0 0 0 0 0 0 0 0 0 0
40121 - 0 0 0 0 0 0 0 0 0 10 10 10
40122 - 34 34 34 86 86 86 14 14 14 2 2 6
40123 -121 87 25 192 133 9 219 162 10 239 182 13
40124 -236 186 11 232 195 16 241 208 19 244 214 54
40125 -246 218 60 246 218 38 246 215 20 241 208 19
40126 -241 208 19 226 184 13 121 87 25 2 2 6
40127 - 2 2 6 2 2 6 2 2 6 2 2 6
40128 - 50 50 50 82 82 82 34 34 34 10 10 10
40129 - 0 0 0 0 0 0 0 0 0 0 0 0
40130 - 0 0 0 0 0 0 0 0 0 0 0 0
40131 - 0 0 0 0 0 0 0 0 0 0 0 0
40132 - 0 0 0 0 0 0 0 0 0 0 0 0
40133 - 0 0 0 0 0 0 0 0 0 0 0 0
40134 - 0 0 0 0 0 0 0 0 0 0 0 0
40135 - 0 0 0 0 0 0 0 0 0 0 0 0
40136 - 0 0 0 0 0 0 0 0 0 0 0 0
40137 - 0 0 0 0 0 0 0 0 0 0 0 0
40138 - 0 0 0 0 0 0 0 0 0 0 0 0
40139 - 0 0 0 0 0 0 0 0 0 0 0 0
40140 - 0 0 0 0 0 0 0 0 0 0 0 0
40141 - 0 0 0 0 0 0 0 0 0 10 10 10
40142 - 34 34 34 82 82 82 30 30 30 61 42 6
40143 -180 123 7 206 145 10 230 174 11 239 182 13
40144 -234 190 10 238 202 15 241 208 19 246 218 74
40145 -246 218 38 246 215 20 246 215 20 246 215 20
40146 -226 184 13 215 174 15 184 144 12 6 6 6
40147 - 2 2 6 2 2 6 2 2 6 2 2 6
40148 - 26 26 26 94 94 94 42 42 42 14 14 14
40149 - 0 0 0 0 0 0 0 0 0 0 0 0
40150 - 0 0 0 0 0 0 0 0 0 0 0 0
40151 - 0 0 0 0 0 0 0 0 0 0 0 0
40152 - 0 0 0 0 0 0 0 0 0 0 0 0
40153 - 0 0 0 0 0 0 0 0 0 0 0 0
40154 - 0 0 0 0 0 0 0 0 0 0 0 0
40155 - 0 0 0 0 0 0 0 0 0 0 0 0
40156 - 0 0 0 0 0 0 0 0 0 0 0 0
40157 - 0 0 0 0 0 0 0 0 0 0 0 0
40158 - 0 0 0 0 0 0 0 0 0 0 0 0
40159 - 0 0 0 0 0 0 0 0 0 0 0 0
40160 - 0 0 0 0 0 0 0 0 0 0 0 0
40161 - 0 0 0 0 0 0 0 0 0 10 10 10
40162 - 30 30 30 78 78 78 50 50 50 104 69 6
40163 -192 133 9 216 158 10 236 178 12 236 186 11
40164 -232 195 16 241 208 19 244 214 54 245 215 43
40165 -246 215 20 246 215 20 241 208 19 198 155 10
40166 -200 144 11 216 158 10 156 118 10 2 2 6
40167 - 2 2 6 2 2 6 2 2 6 2 2 6
40168 - 6 6 6 90 90 90 54 54 54 18 18 18
40169 - 6 6 6 0 0 0 0 0 0 0 0 0
40170 - 0 0 0 0 0 0 0 0 0 0 0 0
40171 - 0 0 0 0 0 0 0 0 0 0 0 0
40172 - 0 0 0 0 0 0 0 0 0 0 0 0
40173 - 0 0 0 0 0 0 0 0 0 0 0 0
40174 - 0 0 0 0 0 0 0 0 0 0 0 0
40175 - 0 0 0 0 0 0 0 0 0 0 0 0
40176 - 0 0 0 0 0 0 0 0 0 0 0 0
40177 - 0 0 0 0 0 0 0 0 0 0 0 0
40178 - 0 0 0 0 0 0 0 0 0 0 0 0
40179 - 0 0 0 0 0 0 0 0 0 0 0 0
40180 - 0 0 0 0 0 0 0 0 0 0 0 0
40181 - 0 0 0 0 0 0 0 0 0 10 10 10
40182 - 30 30 30 78 78 78 46 46 46 22 22 22
40183 -137 92 6 210 162 10 239 182 13 238 190 10
40184 -238 202 15 241 208 19 246 215 20 246 215 20
40185 -241 208 19 203 166 17 185 133 11 210 150 10
40186 -216 158 10 210 150 10 102 78 10 2 2 6
40187 - 6 6 6 54 54 54 14 14 14 2 2 6
40188 - 2 2 6 62 62 62 74 74 74 30 30 30
40189 - 10 10 10 0 0 0 0 0 0 0 0 0
40190 - 0 0 0 0 0 0 0 0 0 0 0 0
40191 - 0 0 0 0 0 0 0 0 0 0 0 0
40192 - 0 0 0 0 0 0 0 0 0 0 0 0
40193 - 0 0 0 0 0 0 0 0 0 0 0 0
40194 - 0 0 0 0 0 0 0 0 0 0 0 0
40195 - 0 0 0 0 0 0 0 0 0 0 0 0
40196 - 0 0 0 0 0 0 0 0 0 0 0 0
40197 - 0 0 0 0 0 0 0 0 0 0 0 0
40198 - 0 0 0 0 0 0 0 0 0 0 0 0
40199 - 0 0 0 0 0 0 0 0 0 0 0 0
40200 - 0 0 0 0 0 0 0 0 0 0 0 0
40201 - 0 0 0 0 0 0 0 0 0 10 10 10
40202 - 34 34 34 78 78 78 50 50 50 6 6 6
40203 - 94 70 30 139 102 15 190 146 13 226 184 13
40204 -232 200 30 232 195 16 215 174 15 190 146 13
40205 -168 122 10 192 133 9 210 150 10 213 154 11
40206 -202 150 34 182 157 106 101 98 89 2 2 6
40207 - 2 2 6 78 78 78 116 116 116 58 58 58
40208 - 2 2 6 22 22 22 90 90 90 46 46 46
40209 - 18 18 18 6 6 6 0 0 0 0 0 0
40210 - 0 0 0 0 0 0 0 0 0 0 0 0
40211 - 0 0 0 0 0 0 0 0 0 0 0 0
40212 - 0 0 0 0 0 0 0 0 0 0 0 0
40213 - 0 0 0 0 0 0 0 0 0 0 0 0
40214 - 0 0 0 0 0 0 0 0 0 0 0 0
40215 - 0 0 0 0 0 0 0 0 0 0 0 0
40216 - 0 0 0 0 0 0 0 0 0 0 0 0
40217 - 0 0 0 0 0 0 0 0 0 0 0 0
40218 - 0 0 0 0 0 0 0 0 0 0 0 0
40219 - 0 0 0 0 0 0 0 0 0 0 0 0
40220 - 0 0 0 0 0 0 0 0 0 0 0 0
40221 - 0 0 0 0 0 0 0 0 0 10 10 10
40222 - 38 38 38 86 86 86 50 50 50 6 6 6
40223 -128 128 128 174 154 114 156 107 11 168 122 10
40224 -198 155 10 184 144 12 197 138 11 200 144 11
40225 -206 145 10 206 145 10 197 138 11 188 164 115
40226 -195 195 195 198 198 198 174 174 174 14 14 14
40227 - 2 2 6 22 22 22 116 116 116 116 116 116
40228 - 22 22 22 2 2 6 74 74 74 70 70 70
40229 - 30 30 30 10 10 10 0 0 0 0 0 0
40230 - 0 0 0 0 0 0 0 0 0 0 0 0
40231 - 0 0 0 0 0 0 0 0 0 0 0 0
40232 - 0 0 0 0 0 0 0 0 0 0 0 0
40233 - 0 0 0 0 0 0 0 0 0 0 0 0
40234 - 0 0 0 0 0 0 0 0 0 0 0 0
40235 - 0 0 0 0 0 0 0 0 0 0 0 0
40236 - 0 0 0 0 0 0 0 0 0 0 0 0
40237 - 0 0 0 0 0 0 0 0 0 0 0 0
40238 - 0 0 0 0 0 0 0 0 0 0 0 0
40239 - 0 0 0 0 0 0 0 0 0 0 0 0
40240 - 0 0 0 0 0 0 0 0 0 0 0 0
40241 - 0 0 0 0 0 0 6 6 6 18 18 18
40242 - 50 50 50 101 101 101 26 26 26 10 10 10
40243 -138 138 138 190 190 190 174 154 114 156 107 11
40244 -197 138 11 200 144 11 197 138 11 192 133 9
40245 -180 123 7 190 142 34 190 178 144 187 187 187
40246 -202 202 202 221 221 221 214 214 214 66 66 66
40247 - 2 2 6 2 2 6 50 50 50 62 62 62
40248 - 6 6 6 2 2 6 10 10 10 90 90 90
40249 - 50 50 50 18 18 18 6 6 6 0 0 0
40250 - 0 0 0 0 0 0 0 0 0 0 0 0
40251 - 0 0 0 0 0 0 0 0 0 0 0 0
40252 - 0 0 0 0 0 0 0 0 0 0 0 0
40253 - 0 0 0 0 0 0 0 0 0 0 0 0
40254 - 0 0 0 0 0 0 0 0 0 0 0 0
40255 - 0 0 0 0 0 0 0 0 0 0 0 0
40256 - 0 0 0 0 0 0 0 0 0 0 0 0
40257 - 0 0 0 0 0 0 0 0 0 0 0 0
40258 - 0 0 0 0 0 0 0 0 0 0 0 0
40259 - 0 0 0 0 0 0 0 0 0 0 0 0
40260 - 0 0 0 0 0 0 0 0 0 0 0 0
40261 - 0 0 0 0 0 0 10 10 10 34 34 34
40262 - 74 74 74 74 74 74 2 2 6 6 6 6
40263 -144 144 144 198 198 198 190 190 190 178 166 146
40264 -154 121 60 156 107 11 156 107 11 168 124 44
40265 -174 154 114 187 187 187 190 190 190 210 210 210
40266 -246 246 246 253 253 253 253 253 253 182 182 182
40267 - 6 6 6 2 2 6 2 2 6 2 2 6
40268 - 2 2 6 2 2 6 2 2 6 62 62 62
40269 - 74 74 74 34 34 34 14 14 14 0 0 0
40270 - 0 0 0 0 0 0 0 0 0 0 0 0
40271 - 0 0 0 0 0 0 0 0 0 0 0 0
40272 - 0 0 0 0 0 0 0 0 0 0 0 0
40273 - 0 0 0 0 0 0 0 0 0 0 0 0
40274 - 0 0 0 0 0 0 0 0 0 0 0 0
40275 - 0 0 0 0 0 0 0 0 0 0 0 0
40276 - 0 0 0 0 0 0 0 0 0 0 0 0
40277 - 0 0 0 0 0 0 0 0 0 0 0 0
40278 - 0 0 0 0 0 0 0 0 0 0 0 0
40279 - 0 0 0 0 0 0 0 0 0 0 0 0
40280 - 0 0 0 0 0 0 0 0 0 0 0 0
40281 - 0 0 0 10 10 10 22 22 22 54 54 54
40282 - 94 94 94 18 18 18 2 2 6 46 46 46
40283 -234 234 234 221 221 221 190 190 190 190 190 190
40284 -190 190 190 187 187 187 187 187 187 190 190 190
40285 -190 190 190 195 195 195 214 214 214 242 242 242
40286 -253 253 253 253 253 253 253 253 253 253 253 253
40287 - 82 82 82 2 2 6 2 2 6 2 2 6
40288 - 2 2 6 2 2 6 2 2 6 14 14 14
40289 - 86 86 86 54 54 54 22 22 22 6 6 6
40290 - 0 0 0 0 0 0 0 0 0 0 0 0
40291 - 0 0 0 0 0 0 0 0 0 0 0 0
40292 - 0 0 0 0 0 0 0 0 0 0 0 0
40293 - 0 0 0 0 0 0 0 0 0 0 0 0
40294 - 0 0 0 0 0 0 0 0 0 0 0 0
40295 - 0 0 0 0 0 0 0 0 0 0 0 0
40296 - 0 0 0 0 0 0 0 0 0 0 0 0
40297 - 0 0 0 0 0 0 0 0 0 0 0 0
40298 - 0 0 0 0 0 0 0 0 0 0 0 0
40299 - 0 0 0 0 0 0 0 0 0 0 0 0
40300 - 0 0 0 0 0 0 0 0 0 0 0 0
40301 - 6 6 6 18 18 18 46 46 46 90 90 90
40302 - 46 46 46 18 18 18 6 6 6 182 182 182
40303 -253 253 253 246 246 246 206 206 206 190 190 190
40304 -190 190 190 190 190 190 190 190 190 190 190 190
40305 -206 206 206 231 231 231 250 250 250 253 253 253
40306 -253 253 253 253 253 253 253 253 253 253 253 253
40307 -202 202 202 14 14 14 2 2 6 2 2 6
40308 - 2 2 6 2 2 6 2 2 6 2 2 6
40309 - 42 42 42 86 86 86 42 42 42 18 18 18
40310 - 6 6 6 0 0 0 0 0 0 0 0 0
40311 - 0 0 0 0 0 0 0 0 0 0 0 0
40312 - 0 0 0 0 0 0 0 0 0 0 0 0
40313 - 0 0 0 0 0 0 0 0 0 0 0 0
40314 - 0 0 0 0 0 0 0 0 0 0 0 0
40315 - 0 0 0 0 0 0 0 0 0 0 0 0
40316 - 0 0 0 0 0 0 0 0 0 0 0 0
40317 - 0 0 0 0 0 0 0 0 0 0 0 0
40318 - 0 0 0 0 0 0 0 0 0 0 0 0
40319 - 0 0 0 0 0 0 0 0 0 0 0 0
40320 - 0 0 0 0 0 0 0 0 0 6 6 6
40321 - 14 14 14 38 38 38 74 74 74 66 66 66
40322 - 2 2 6 6 6 6 90 90 90 250 250 250
40323 -253 253 253 253 253 253 238 238 238 198 198 198
40324 -190 190 190 190 190 190 195 195 195 221 221 221
40325 -246 246 246 253 253 253 253 253 253 253 253 253
40326 -253 253 253 253 253 253 253 253 253 253 253 253
40327 -253 253 253 82 82 82 2 2 6 2 2 6
40328 - 2 2 6 2 2 6 2 2 6 2 2 6
40329 - 2 2 6 78 78 78 70 70 70 34 34 34
40330 - 14 14 14 6 6 6 0 0 0 0 0 0
40331 - 0 0 0 0 0 0 0 0 0 0 0 0
40332 - 0 0 0 0 0 0 0 0 0 0 0 0
40333 - 0 0 0 0 0 0 0 0 0 0 0 0
40334 - 0 0 0 0 0 0 0 0 0 0 0 0
40335 - 0 0 0 0 0 0 0 0 0 0 0 0
40336 - 0 0 0 0 0 0 0 0 0 0 0 0
40337 - 0 0 0 0 0 0 0 0 0 0 0 0
40338 - 0 0 0 0 0 0 0 0 0 0 0 0
40339 - 0 0 0 0 0 0 0 0 0 0 0 0
40340 - 0 0 0 0 0 0 0 0 0 14 14 14
40341 - 34 34 34 66 66 66 78 78 78 6 6 6
40342 - 2 2 6 18 18 18 218 218 218 253 253 253
40343 -253 253 253 253 253 253 253 253 253 246 246 246
40344 -226 226 226 231 231 231 246 246 246 253 253 253
40345 -253 253 253 253 253 253 253 253 253 253 253 253
40346 -253 253 253 253 253 253 253 253 253 253 253 253
40347 -253 253 253 178 178 178 2 2 6 2 2 6
40348 - 2 2 6 2 2 6 2 2 6 2 2 6
40349 - 2 2 6 18 18 18 90 90 90 62 62 62
40350 - 30 30 30 10 10 10 0 0 0 0 0 0
40351 - 0 0 0 0 0 0 0 0 0 0 0 0
40352 - 0 0 0 0 0 0 0 0 0 0 0 0
40353 - 0 0 0 0 0 0 0 0 0 0 0 0
40354 - 0 0 0 0 0 0 0 0 0 0 0 0
40355 - 0 0 0 0 0 0 0 0 0 0 0 0
40356 - 0 0 0 0 0 0 0 0 0 0 0 0
40357 - 0 0 0 0 0 0 0 0 0 0 0 0
40358 - 0 0 0 0 0 0 0 0 0 0 0 0
40359 - 0 0 0 0 0 0 0 0 0 0 0 0
40360 - 0 0 0 0 0 0 10 10 10 26 26 26
40361 - 58 58 58 90 90 90 18 18 18 2 2 6
40362 - 2 2 6 110 110 110 253 253 253 253 253 253
40363 -253 253 253 253 253 253 253 253 253 253 253 253
40364 -250 250 250 253 253 253 253 253 253 253 253 253
40365 -253 253 253 253 253 253 253 253 253 253 253 253
40366 -253 253 253 253 253 253 253 253 253 253 253 253
40367 -253 253 253 231 231 231 18 18 18 2 2 6
40368 - 2 2 6 2 2 6 2 2 6 2 2 6
40369 - 2 2 6 2 2 6 18 18 18 94 94 94
40370 - 54 54 54 26 26 26 10 10 10 0 0 0
40371 - 0 0 0 0 0 0 0 0 0 0 0 0
40372 - 0 0 0 0 0 0 0 0 0 0 0 0
40373 - 0 0 0 0 0 0 0 0 0 0 0 0
40374 - 0 0 0 0 0 0 0 0 0 0 0 0
40375 - 0 0 0 0 0 0 0 0 0 0 0 0
40376 - 0 0 0 0 0 0 0 0 0 0 0 0
40377 - 0 0 0 0 0 0 0 0 0 0 0 0
40378 - 0 0 0 0 0 0 0 0 0 0 0 0
40379 - 0 0 0 0 0 0 0 0 0 0 0 0
40380 - 0 0 0 6 6 6 22 22 22 50 50 50
40381 - 90 90 90 26 26 26 2 2 6 2 2 6
40382 - 14 14 14 195 195 195 250 250 250 253 253 253
40383 -253 253 253 253 253 253 253 253 253 253 253 253
40384 -253 253 253 253 253 253 253 253 253 253 253 253
40385 -253 253 253 253 253 253 253 253 253 253 253 253
40386 -253 253 253 253 253 253 253 253 253 253 253 253
40387 -250 250 250 242 242 242 54 54 54 2 2 6
40388 - 2 2 6 2 2 6 2 2 6 2 2 6
40389 - 2 2 6 2 2 6 2 2 6 38 38 38
40390 - 86 86 86 50 50 50 22 22 22 6 6 6
40391 - 0 0 0 0 0 0 0 0 0 0 0 0
40392 - 0 0 0 0 0 0 0 0 0 0 0 0
40393 - 0 0 0 0 0 0 0 0 0 0 0 0
40394 - 0 0 0 0 0 0 0 0 0 0 0 0
40395 - 0 0 0 0 0 0 0 0 0 0 0 0
40396 - 0 0 0 0 0 0 0 0 0 0 0 0
40397 - 0 0 0 0 0 0 0 0 0 0 0 0
40398 - 0 0 0 0 0 0 0 0 0 0 0 0
40399 - 0 0 0 0 0 0 0 0 0 0 0 0
40400 - 6 6 6 14 14 14 38 38 38 82 82 82
40401 - 34 34 34 2 2 6 2 2 6 2 2 6
40402 - 42 42 42 195 195 195 246 246 246 253 253 253
40403 -253 253 253 253 253 253 253 253 253 250 250 250
40404 -242 242 242 242 242 242 250 250 250 253 253 253
40405 -253 253 253 253 253 253 253 253 253 253 253 253
40406 -253 253 253 250 250 250 246 246 246 238 238 238
40407 -226 226 226 231 231 231 101 101 101 6 6 6
40408 - 2 2 6 2 2 6 2 2 6 2 2 6
40409 - 2 2 6 2 2 6 2 2 6 2 2 6
40410 - 38 38 38 82 82 82 42 42 42 14 14 14
40411 - 6 6 6 0 0 0 0 0 0 0 0 0
40412 - 0 0 0 0 0 0 0 0 0 0 0 0
40413 - 0 0 0 0 0 0 0 0 0 0 0 0
40414 - 0 0 0 0 0 0 0 0 0 0 0 0
40415 - 0 0 0 0 0 0 0 0 0 0 0 0
40416 - 0 0 0 0 0 0 0 0 0 0 0 0
40417 - 0 0 0 0 0 0 0 0 0 0 0 0
40418 - 0 0 0 0 0 0 0 0 0 0 0 0
40419 - 0 0 0 0 0 0 0 0 0 0 0 0
40420 - 10 10 10 26 26 26 62 62 62 66 66 66
40421 - 2 2 6 2 2 6 2 2 6 6 6 6
40422 - 70 70 70 170 170 170 206 206 206 234 234 234
40423 -246 246 246 250 250 250 250 250 250 238 238 238
40424 -226 226 226 231 231 231 238 238 238 250 250 250
40425 -250 250 250 250 250 250 246 246 246 231 231 231
40426 -214 214 214 206 206 206 202 202 202 202 202 202
40427 -198 198 198 202 202 202 182 182 182 18 18 18
40428 - 2 2 6 2 2 6 2 2 6 2 2 6
40429 - 2 2 6 2 2 6 2 2 6 2 2 6
40430 - 2 2 6 62 62 62 66 66 66 30 30 30
40431 - 10 10 10 0 0 0 0 0 0 0 0 0
40432 - 0 0 0 0 0 0 0 0 0 0 0 0
40433 - 0 0 0 0 0 0 0 0 0 0 0 0
40434 - 0 0 0 0 0 0 0 0 0 0 0 0
40435 - 0 0 0 0 0 0 0 0 0 0 0 0
40436 - 0 0 0 0 0 0 0 0 0 0 0 0
40437 - 0 0 0 0 0 0 0 0 0 0 0 0
40438 - 0 0 0 0 0 0 0 0 0 0 0 0
40439 - 0 0 0 0 0 0 0 0 0 0 0 0
40440 - 14 14 14 42 42 42 82 82 82 18 18 18
40441 - 2 2 6 2 2 6 2 2 6 10 10 10
40442 - 94 94 94 182 182 182 218 218 218 242 242 242
40443 -250 250 250 253 253 253 253 253 253 250 250 250
40444 -234 234 234 253 253 253 253 253 253 253 253 253
40445 -253 253 253 253 253 253 253 253 253 246 246 246
40446 -238 238 238 226 226 226 210 210 210 202 202 202
40447 -195 195 195 195 195 195 210 210 210 158 158 158
40448 - 6 6 6 14 14 14 50 50 50 14 14 14
40449 - 2 2 6 2 2 6 2 2 6 2 2 6
40450 - 2 2 6 6 6 6 86 86 86 46 46 46
40451 - 18 18 18 6 6 6 0 0 0 0 0 0
40452 - 0 0 0 0 0 0 0 0 0 0 0 0
40453 - 0 0 0 0 0 0 0 0 0 0 0 0
40454 - 0 0 0 0 0 0 0 0 0 0 0 0
40455 - 0 0 0 0 0 0 0 0 0 0 0 0
40456 - 0 0 0 0 0 0 0 0 0 0 0 0
40457 - 0 0 0 0 0 0 0 0 0 0 0 0
40458 - 0 0 0 0 0 0 0 0 0 0 0 0
40459 - 0 0 0 0 0 0 0 0 0 6 6 6
40460 - 22 22 22 54 54 54 70 70 70 2 2 6
40461 - 2 2 6 10 10 10 2 2 6 22 22 22
40462 -166 166 166 231 231 231 250 250 250 253 253 253
40463 -253 253 253 253 253 253 253 253 253 250 250 250
40464 -242 242 242 253 253 253 253 253 253 253 253 253
40465 -253 253 253 253 253 253 253 253 253 253 253 253
40466 -253 253 253 253 253 253 253 253 253 246 246 246
40467 -231 231 231 206 206 206 198 198 198 226 226 226
40468 - 94 94 94 2 2 6 6 6 6 38 38 38
40469 - 30 30 30 2 2 6 2 2 6 2 2 6
40470 - 2 2 6 2 2 6 62 62 62 66 66 66
40471 - 26 26 26 10 10 10 0 0 0 0 0 0
40472 - 0 0 0 0 0 0 0 0 0 0 0 0
40473 - 0 0 0 0 0 0 0 0 0 0 0 0
40474 - 0 0 0 0 0 0 0 0 0 0 0 0
40475 - 0 0 0 0 0 0 0 0 0 0 0 0
40476 - 0 0 0 0 0 0 0 0 0 0 0 0
40477 - 0 0 0 0 0 0 0 0 0 0 0 0
40478 - 0 0 0 0 0 0 0 0 0 0 0 0
40479 - 0 0 0 0 0 0 0 0 0 10 10 10
40480 - 30 30 30 74 74 74 50 50 50 2 2 6
40481 - 26 26 26 26 26 26 2 2 6 106 106 106
40482 -238 238 238 253 253 253 253 253 253 253 253 253
40483 -253 253 253 253 253 253 253 253 253 253 253 253
40484 -253 253 253 253 253 253 253 253 253 253 253 253
40485 -253 253 253 253 253 253 253 253 253 253 253 253
40486 -253 253 253 253 253 253 253 253 253 253 253 253
40487 -253 253 253 246 246 246 218 218 218 202 202 202
40488 -210 210 210 14 14 14 2 2 6 2 2 6
40489 - 30 30 30 22 22 22 2 2 6 2 2 6
40490 - 2 2 6 2 2 6 18 18 18 86 86 86
40491 - 42 42 42 14 14 14 0 0 0 0 0 0
40492 - 0 0 0 0 0 0 0 0 0 0 0 0
40493 - 0 0 0 0 0 0 0 0 0 0 0 0
40494 - 0 0 0 0 0 0 0 0 0 0 0 0
40495 - 0 0 0 0 0 0 0 0 0 0 0 0
40496 - 0 0 0 0 0 0 0 0 0 0 0 0
40497 - 0 0 0 0 0 0 0 0 0 0 0 0
40498 - 0 0 0 0 0 0 0 0 0 0 0 0
40499 - 0 0 0 0 0 0 0 0 0 14 14 14
40500 - 42 42 42 90 90 90 22 22 22 2 2 6
40501 - 42 42 42 2 2 6 18 18 18 218 218 218
40502 -253 253 253 253 253 253 253 253 253 253 253 253
40503 -253 253 253 253 253 253 253 253 253 253 253 253
40504 -253 253 253 253 253 253 253 253 253 253 253 253
40505 -253 253 253 253 253 253 253 253 253 253 253 253
40506 -253 253 253 253 253 253 253 253 253 253 253 253
40507 -253 253 253 253 253 253 250 250 250 221 221 221
40508 -218 218 218 101 101 101 2 2 6 14 14 14
40509 - 18 18 18 38 38 38 10 10 10 2 2 6
40510 - 2 2 6 2 2 6 2 2 6 78 78 78
40511 - 58 58 58 22 22 22 6 6 6 0 0 0
40512 - 0 0 0 0 0 0 0 0 0 0 0 0
40513 - 0 0 0 0 0 0 0 0 0 0 0 0
40514 - 0 0 0 0 0 0 0 0 0 0 0 0
40515 - 0 0 0 0 0 0 0 0 0 0 0 0
40516 - 0 0 0 0 0 0 0 0 0 0 0 0
40517 - 0 0 0 0 0 0 0 0 0 0 0 0
40518 - 0 0 0 0 0 0 0 0 0 0 0 0
40519 - 0 0 0 0 0 0 6 6 6 18 18 18
40520 - 54 54 54 82 82 82 2 2 6 26 26 26
40521 - 22 22 22 2 2 6 123 123 123 253 253 253
40522 -253 253 253 253 253 253 253 253 253 253 253 253
40523 -253 253 253 253 253 253 253 253 253 253 253 253
40524 -253 253 253 253 253 253 253 253 253 253 253 253
40525 -253 253 253 253 253 253 253 253 253 253 253 253
40526 -253 253 253 253 253 253 253 253 253 253 253 253
40527 -253 253 253 253 253 253 253 253 253 250 250 250
40528 -238 238 238 198 198 198 6 6 6 38 38 38
40529 - 58 58 58 26 26 26 38 38 38 2 2 6
40530 - 2 2 6 2 2 6 2 2 6 46 46 46
40531 - 78 78 78 30 30 30 10 10 10 0 0 0
40532 - 0 0 0 0 0 0 0 0 0 0 0 0
40533 - 0 0 0 0 0 0 0 0 0 0 0 0
40534 - 0 0 0 0 0 0 0 0 0 0 0 0
40535 - 0 0 0 0 0 0 0 0 0 0 0 0
40536 - 0 0 0 0 0 0 0 0 0 0 0 0
40537 - 0 0 0 0 0 0 0 0 0 0 0 0
40538 - 0 0 0 0 0 0 0 0 0 0 0 0
40539 - 0 0 0 0 0 0 10 10 10 30 30 30
40540 - 74 74 74 58 58 58 2 2 6 42 42 42
40541 - 2 2 6 22 22 22 231 231 231 253 253 253
40542 -253 253 253 253 253 253 253 253 253 253 253 253
40543 -253 253 253 253 253 253 253 253 253 250 250 250
40544 -253 253 253 253 253 253 253 253 253 253 253 253
40545 -253 253 253 253 253 253 253 253 253 253 253 253
40546 -253 253 253 253 253 253 253 253 253 253 253 253
40547 -253 253 253 253 253 253 253 253 253 253 253 253
40548 -253 253 253 246 246 246 46 46 46 38 38 38
40549 - 42 42 42 14 14 14 38 38 38 14 14 14
40550 - 2 2 6 2 2 6 2 2 6 6 6 6
40551 - 86 86 86 46 46 46 14 14 14 0 0 0
40552 - 0 0 0 0 0 0 0 0 0 0 0 0
40553 - 0 0 0 0 0 0 0 0 0 0 0 0
40554 - 0 0 0 0 0 0 0 0 0 0 0 0
40555 - 0 0 0 0 0 0 0 0 0 0 0 0
40556 - 0 0 0 0 0 0 0 0 0 0 0 0
40557 - 0 0 0 0 0 0 0 0 0 0 0 0
40558 - 0 0 0 0 0 0 0 0 0 0 0 0
40559 - 0 0 0 6 6 6 14 14 14 42 42 42
40560 - 90 90 90 18 18 18 18 18 18 26 26 26
40561 - 2 2 6 116 116 116 253 253 253 253 253 253
40562 -253 253 253 253 253 253 253 253 253 253 253 253
40563 -253 253 253 253 253 253 250 250 250 238 238 238
40564 -253 253 253 253 253 253 253 253 253 253 253 253
40565 -253 253 253 253 253 253 253 253 253 253 253 253
40566 -253 253 253 253 253 253 253 253 253 253 253 253
40567 -253 253 253 253 253 253 253 253 253 253 253 253
40568 -253 253 253 253 253 253 94 94 94 6 6 6
40569 - 2 2 6 2 2 6 10 10 10 34 34 34
40570 - 2 2 6 2 2 6 2 2 6 2 2 6
40571 - 74 74 74 58 58 58 22 22 22 6 6 6
40572 - 0 0 0 0 0 0 0 0 0 0 0 0
40573 - 0 0 0 0 0 0 0 0 0 0 0 0
40574 - 0 0 0 0 0 0 0 0 0 0 0 0
40575 - 0 0 0 0 0 0 0 0 0 0 0 0
40576 - 0 0 0 0 0 0 0 0 0 0 0 0
40577 - 0 0 0 0 0 0 0 0 0 0 0 0
40578 - 0 0 0 0 0 0 0 0 0 0 0 0
40579 - 0 0 0 10 10 10 26 26 26 66 66 66
40580 - 82 82 82 2 2 6 38 38 38 6 6 6
40581 - 14 14 14 210 210 210 253 253 253 253 253 253
40582 -253 253 253 253 253 253 253 253 253 253 253 253
40583 -253 253 253 253 253 253 246 246 246 242 242 242
40584 -253 253 253 253 253 253 253 253 253 253 253 253
40585 -253 253 253 253 253 253 253 253 253 253 253 253
40586 -253 253 253 253 253 253 253 253 253 253 253 253
40587 -253 253 253 253 253 253 253 253 253 253 253 253
40588 -253 253 253 253 253 253 144 144 144 2 2 6
40589 - 2 2 6 2 2 6 2 2 6 46 46 46
40590 - 2 2 6 2 2 6 2 2 6 2 2 6
40591 - 42 42 42 74 74 74 30 30 30 10 10 10
40592 - 0 0 0 0 0 0 0 0 0 0 0 0
40593 - 0 0 0 0 0 0 0 0 0 0 0 0
40594 - 0 0 0 0 0 0 0 0 0 0 0 0
40595 - 0 0 0 0 0 0 0 0 0 0 0 0
40596 - 0 0 0 0 0 0 0 0 0 0 0 0
40597 - 0 0 0 0 0 0 0 0 0 0 0 0
40598 - 0 0 0 0 0 0 0 0 0 0 0 0
40599 - 6 6 6 14 14 14 42 42 42 90 90 90
40600 - 26 26 26 6 6 6 42 42 42 2 2 6
40601 - 74 74 74 250 250 250 253 253 253 253 253 253
40602 -253 253 253 253 253 253 253 253 253 253 253 253
40603 -253 253 253 253 253 253 242 242 242 242 242 242
40604 -253 253 253 253 253 253 253 253 253 253 253 253
40605 -253 253 253 253 253 253 253 253 253 253 253 253
40606 -253 253 253 253 253 253 253 253 253 253 253 253
40607 -253 253 253 253 253 253 253 253 253 253 253 253
40608 -253 253 253 253 253 253 182 182 182 2 2 6
40609 - 2 2 6 2 2 6 2 2 6 46 46 46
40610 - 2 2 6 2 2 6 2 2 6 2 2 6
40611 - 10 10 10 86 86 86 38 38 38 10 10 10
40612 - 0 0 0 0 0 0 0 0 0 0 0 0
40613 - 0 0 0 0 0 0 0 0 0 0 0 0
40614 - 0 0 0 0 0 0 0 0 0 0 0 0
40615 - 0 0 0 0 0 0 0 0 0 0 0 0
40616 - 0 0 0 0 0 0 0 0 0 0 0 0
40617 - 0 0 0 0 0 0 0 0 0 0 0 0
40618 - 0 0 0 0 0 0 0 0 0 0 0 0
40619 - 10 10 10 26 26 26 66 66 66 82 82 82
40620 - 2 2 6 22 22 22 18 18 18 2 2 6
40621 -149 149 149 253 253 253 253 253 253 253 253 253
40622 -253 253 253 253 253 253 253 253 253 253 253 253
40623 -253 253 253 253 253 253 234 234 234 242 242 242
40624 -253 253 253 253 253 253 253 253 253 253 253 253
40625 -253 253 253 253 253 253 253 253 253 253 253 253
40626 -253 253 253 253 253 253 253 253 253 253 253 253
40627 -253 253 253 253 253 253 253 253 253 253 253 253
40628 -253 253 253 253 253 253 206 206 206 2 2 6
40629 - 2 2 6 2 2 6 2 2 6 38 38 38
40630 - 2 2 6 2 2 6 2 2 6 2 2 6
40631 - 6 6 6 86 86 86 46 46 46 14 14 14
40632 - 0 0 0 0 0 0 0 0 0 0 0 0
40633 - 0 0 0 0 0 0 0 0 0 0 0 0
40634 - 0 0 0 0 0 0 0 0 0 0 0 0
40635 - 0 0 0 0 0 0 0 0 0 0 0 0
40636 - 0 0 0 0 0 0 0 0 0 0 0 0
40637 - 0 0 0 0 0 0 0 0 0 0 0 0
40638 - 0 0 0 0 0 0 0 0 0 6 6 6
40639 - 18 18 18 46 46 46 86 86 86 18 18 18
40640 - 2 2 6 34 34 34 10 10 10 6 6 6
40641 -210 210 210 253 253 253 253 253 253 253 253 253
40642 -253 253 253 253 253 253 253 253 253 253 253 253
40643 -253 253 253 253 253 253 234 234 234 242 242 242
40644 -253 253 253 253 253 253 253 253 253 253 253 253
40645 -253 253 253 253 253 253 253 253 253 253 253 253
40646 -253 253 253 253 253 253 253 253 253 253 253 253
40647 -253 253 253 253 253 253 253 253 253 253 253 253
40648 -253 253 253 253 253 253 221 221 221 6 6 6
40649 - 2 2 6 2 2 6 6 6 6 30 30 30
40650 - 2 2 6 2 2 6 2 2 6 2 2 6
40651 - 2 2 6 82 82 82 54 54 54 18 18 18
40652 - 6 6 6 0 0 0 0 0 0 0 0 0
40653 - 0 0 0 0 0 0 0 0 0 0 0 0
40654 - 0 0 0 0 0 0 0 0 0 0 0 0
40655 - 0 0 0 0 0 0 0 0 0 0 0 0
40656 - 0 0 0 0 0 0 0 0 0 0 0 0
40657 - 0 0 0 0 0 0 0 0 0 0 0 0
40658 - 0 0 0 0 0 0 0 0 0 10 10 10
40659 - 26 26 26 66 66 66 62 62 62 2 2 6
40660 - 2 2 6 38 38 38 10 10 10 26 26 26
40661 -238 238 238 253 253 253 253 253 253 253 253 253
40662 -253 253 253 253 253 253 253 253 253 253 253 253
40663 -253 253 253 253 253 253 231 231 231 238 238 238
40664 -253 253 253 253 253 253 253 253 253 253 253 253
40665 -253 253 253 253 253 253 253 253 253 253 253 253
40666 -253 253 253 253 253 253 253 253 253 253 253 253
40667 -253 253 253 253 253 253 253 253 253 253 253 253
40668 -253 253 253 253 253 253 231 231 231 6 6 6
40669 - 2 2 6 2 2 6 10 10 10 30 30 30
40670 - 2 2 6 2 2 6 2 2 6 2 2 6
40671 - 2 2 6 66 66 66 58 58 58 22 22 22
40672 - 6 6 6 0 0 0 0 0 0 0 0 0
40673 - 0 0 0 0 0 0 0 0 0 0 0 0
40674 - 0 0 0 0 0 0 0 0 0 0 0 0
40675 - 0 0 0 0 0 0 0 0 0 0 0 0
40676 - 0 0 0 0 0 0 0 0 0 0 0 0
40677 - 0 0 0 0 0 0 0 0 0 0 0 0
40678 - 0 0 0 0 0 0 0 0 0 10 10 10
40679 - 38 38 38 78 78 78 6 6 6 2 2 6
40680 - 2 2 6 46 46 46 14 14 14 42 42 42
40681 -246 246 246 253 253 253 253 253 253 253 253 253
40682 -253 253 253 253 253 253 253 253 253 253 253 253
40683 -253 253 253 253 253 253 231 231 231 242 242 242
40684 -253 253 253 253 253 253 253 253 253 253 253 253
40685 -253 253 253 253 253 253 253 253 253 253 253 253
40686 -253 253 253 253 253 253 253 253 253 253 253 253
40687 -253 253 253 253 253 253 253 253 253 253 253 253
40688 -253 253 253 253 253 253 234 234 234 10 10 10
40689 - 2 2 6 2 2 6 22 22 22 14 14 14
40690 - 2 2 6 2 2 6 2 2 6 2 2 6
40691 - 2 2 6 66 66 66 62 62 62 22 22 22
40692 - 6 6 6 0 0 0 0 0 0 0 0 0
40693 - 0 0 0 0 0 0 0 0 0 0 0 0
40694 - 0 0 0 0 0 0 0 0 0 0 0 0
40695 - 0 0 0 0 0 0 0 0 0 0 0 0
40696 - 0 0 0 0 0 0 0 0 0 0 0 0
40697 - 0 0 0 0 0 0 0 0 0 0 0 0
40698 - 0 0 0 0 0 0 6 6 6 18 18 18
40699 - 50 50 50 74 74 74 2 2 6 2 2 6
40700 - 14 14 14 70 70 70 34 34 34 62 62 62
40701 -250 250 250 253 253 253 253 253 253 253 253 253
40702 -253 253 253 253 253 253 253 253 253 253 253 253
40703 -253 253 253 253 253 253 231 231 231 246 246 246
40704 -253 253 253 253 253 253 253 253 253 253 253 253
40705 -253 253 253 253 253 253 253 253 253 253 253 253
40706 -253 253 253 253 253 253 253 253 253 253 253 253
40707 -253 253 253 253 253 253 253 253 253 253 253 253
40708 -253 253 253 253 253 253 234 234 234 14 14 14
40709 - 2 2 6 2 2 6 30 30 30 2 2 6
40710 - 2 2 6 2 2 6 2 2 6 2 2 6
40711 - 2 2 6 66 66 66 62 62 62 22 22 22
40712 - 6 6 6 0 0 0 0 0 0 0 0 0
40713 - 0 0 0 0 0 0 0 0 0 0 0 0
40714 - 0 0 0 0 0 0 0 0 0 0 0 0
40715 - 0 0 0 0 0 0 0 0 0 0 0 0
40716 - 0 0 0 0 0 0 0 0 0 0 0 0
40717 - 0 0 0 0 0 0 0 0 0 0 0 0
40718 - 0 0 0 0 0 0 6 6 6 18 18 18
40719 - 54 54 54 62 62 62 2 2 6 2 2 6
40720 - 2 2 6 30 30 30 46 46 46 70 70 70
40721 -250 250 250 253 253 253 253 253 253 253 253 253
40722 -253 253 253 253 253 253 253 253 253 253 253 253
40723 -253 253 253 253 253 253 231 231 231 246 246 246
40724 -253 253 253 253 253 253 253 253 253 253 253 253
40725 -253 253 253 253 253 253 253 253 253 253 253 253
40726 -253 253 253 253 253 253 253 253 253 253 253 253
40727 -253 253 253 253 253 253 253 253 253 253 253 253
40728 -253 253 253 253 253 253 226 226 226 10 10 10
40729 - 2 2 6 6 6 6 30 30 30 2 2 6
40730 - 2 2 6 2 2 6 2 2 6 2 2 6
40731 - 2 2 6 66 66 66 58 58 58 22 22 22
40732 - 6 6 6 0 0 0 0 0 0 0 0 0
40733 - 0 0 0 0 0 0 0 0 0 0 0 0
40734 - 0 0 0 0 0 0 0 0 0 0 0 0
40735 - 0 0 0 0 0 0 0 0 0 0 0 0
40736 - 0 0 0 0 0 0 0 0 0 0 0 0
40737 - 0 0 0 0 0 0 0 0 0 0 0 0
40738 - 0 0 0 0 0 0 6 6 6 22 22 22
40739 - 58 58 58 62 62 62 2 2 6 2 2 6
40740 - 2 2 6 2 2 6 30 30 30 78 78 78
40741 -250 250 250 253 253 253 253 253 253 253 253 253
40742 -253 253 253 253 253 253 253 253 253 253 253 253
40743 -253 253 253 253 253 253 231 231 231 246 246 246
40744 -253 253 253 253 253 253 253 253 253 253 253 253
40745 -253 253 253 253 253 253 253 253 253 253 253 253
40746 -253 253 253 253 253 253 253 253 253 253 253 253
40747 -253 253 253 253 253 253 253 253 253 253 253 253
40748 -253 253 253 253 253 253 206 206 206 2 2 6
40749 - 22 22 22 34 34 34 18 14 6 22 22 22
40750 - 26 26 26 18 18 18 6 6 6 2 2 6
40751 - 2 2 6 82 82 82 54 54 54 18 18 18
40752 - 6 6 6 0 0 0 0 0 0 0 0 0
40753 - 0 0 0 0 0 0 0 0 0 0 0 0
40754 - 0 0 0 0 0 0 0 0 0 0 0 0
40755 - 0 0 0 0 0 0 0 0 0 0 0 0
40756 - 0 0 0 0 0 0 0 0 0 0 0 0
40757 - 0 0 0 0 0 0 0 0 0 0 0 0
40758 - 0 0 0 0 0 0 6 6 6 26 26 26
40759 - 62 62 62 106 106 106 74 54 14 185 133 11
40760 -210 162 10 121 92 8 6 6 6 62 62 62
40761 -238 238 238 253 253 253 253 253 253 253 253 253
40762 -253 253 253 253 253 253 253 253 253 253 253 253
40763 -253 253 253 253 253 253 231 231 231 246 246 246
40764 -253 253 253 253 253 253 253 253 253 253 253 253
40765 -253 253 253 253 253 253 253 253 253 253 253 253
40766 -253 253 253 253 253 253 253 253 253 253 253 253
40767 -253 253 253 253 253 253 253 253 253 253 253 253
40768 -253 253 253 253 253 253 158 158 158 18 18 18
40769 - 14 14 14 2 2 6 2 2 6 2 2 6
40770 - 6 6 6 18 18 18 66 66 66 38 38 38
40771 - 6 6 6 94 94 94 50 50 50 18 18 18
40772 - 6 6 6 0 0 0 0 0 0 0 0 0
40773 - 0 0 0 0 0 0 0 0 0 0 0 0
40774 - 0 0 0 0 0 0 0 0 0 0 0 0
40775 - 0 0 0 0 0 0 0 0 0 0 0 0
40776 - 0 0 0 0 0 0 0 0 0 0 0 0
40777 - 0 0 0 0 0 0 0 0 0 6 6 6
40778 - 10 10 10 10 10 10 18 18 18 38 38 38
40779 - 78 78 78 142 134 106 216 158 10 242 186 14
40780 -246 190 14 246 190 14 156 118 10 10 10 10
40781 - 90 90 90 238 238 238 253 253 253 253 253 253
40782 -253 253 253 253 253 253 253 253 253 253 253 253
40783 -253 253 253 253 253 253 231 231 231 250 250 250
40784 -253 253 253 253 253 253 253 253 253 253 253 253
40785 -253 253 253 253 253 253 253 253 253 253 253 253
40786 -253 253 253 253 253 253 253 253 253 253 253 253
40787 -253 253 253 253 253 253 253 253 253 246 230 190
40788 -238 204 91 238 204 91 181 142 44 37 26 9
40789 - 2 2 6 2 2 6 2 2 6 2 2 6
40790 - 2 2 6 2 2 6 38 38 38 46 46 46
40791 - 26 26 26 106 106 106 54 54 54 18 18 18
40792 - 6 6 6 0 0 0 0 0 0 0 0 0
40793 - 0 0 0 0 0 0 0 0 0 0 0 0
40794 - 0 0 0 0 0 0 0 0 0 0 0 0
40795 - 0 0 0 0 0 0 0 0 0 0 0 0
40796 - 0 0 0 0 0 0 0 0 0 0 0 0
40797 - 0 0 0 6 6 6 14 14 14 22 22 22
40798 - 30 30 30 38 38 38 50 50 50 70 70 70
40799 -106 106 106 190 142 34 226 170 11 242 186 14
40800 -246 190 14 246 190 14 246 190 14 154 114 10
40801 - 6 6 6 74 74 74 226 226 226 253 253 253
40802 -253 253 253 253 253 253 253 253 253 253 253 253
40803 -253 253 253 253 253 253 231 231 231 250 250 250
40804 -253 253 253 253 253 253 253 253 253 253 253 253
40805 -253 253 253 253 253 253 253 253 253 253 253 253
40806 -253 253 253 253 253 253 253 253 253 253 253 253
40807 -253 253 253 253 253 253 253 253 253 228 184 62
40808 -241 196 14 241 208 19 232 195 16 38 30 10
40809 - 2 2 6 2 2 6 2 2 6 2 2 6
40810 - 2 2 6 6 6 6 30 30 30 26 26 26
40811 -203 166 17 154 142 90 66 66 66 26 26 26
40812 - 6 6 6 0 0 0 0 0 0 0 0 0
40813 - 0 0 0 0 0 0 0 0 0 0 0 0
40814 - 0 0 0 0 0 0 0 0 0 0 0 0
40815 - 0 0 0 0 0 0 0 0 0 0 0 0
40816 - 0 0 0 0 0 0 0 0 0 0 0 0
40817 - 6 6 6 18 18 18 38 38 38 58 58 58
40818 - 78 78 78 86 86 86 101 101 101 123 123 123
40819 -175 146 61 210 150 10 234 174 13 246 186 14
40820 -246 190 14 246 190 14 246 190 14 238 190 10
40821 -102 78 10 2 2 6 46 46 46 198 198 198
40822 -253 253 253 253 253 253 253 253 253 253 253 253
40823 -253 253 253 253 253 253 234 234 234 242 242 242
40824 -253 253 253 253 253 253 253 253 253 253 253 253
40825 -253 253 253 253 253 253 253 253 253 253 253 253
40826 -253 253 253 253 253 253 253 253 253 253 253 253
40827 -253 253 253 253 253 253 253 253 253 224 178 62
40828 -242 186 14 241 196 14 210 166 10 22 18 6
40829 - 2 2 6 2 2 6 2 2 6 2 2 6
40830 - 2 2 6 2 2 6 6 6 6 121 92 8
40831 -238 202 15 232 195 16 82 82 82 34 34 34
40832 - 10 10 10 0 0 0 0 0 0 0 0 0
40833 - 0 0 0 0 0 0 0 0 0 0 0 0
40834 - 0 0 0 0 0 0 0 0 0 0 0 0
40835 - 0 0 0 0 0 0 0 0 0 0 0 0
40836 - 0 0 0 0 0 0 0 0 0 0 0 0
40837 - 14 14 14 38 38 38 70 70 70 154 122 46
40838 -190 142 34 200 144 11 197 138 11 197 138 11
40839 -213 154 11 226 170 11 242 186 14 246 190 14
40840 -246 190 14 246 190 14 246 190 14 246 190 14
40841 -225 175 15 46 32 6 2 2 6 22 22 22
40842 -158 158 158 250 250 250 253 253 253 253 253 253
40843 -253 253 253 253 253 253 253 253 253 253 253 253
40844 -253 253 253 253 253 253 253 253 253 253 253 253
40845 -253 253 253 253 253 253 253 253 253 253 253 253
40846 -253 253 253 253 253 253 253 253 253 253 253 253
40847 -253 253 253 250 250 250 242 242 242 224 178 62
40848 -239 182 13 236 186 11 213 154 11 46 32 6
40849 - 2 2 6 2 2 6 2 2 6 2 2 6
40850 - 2 2 6 2 2 6 61 42 6 225 175 15
40851 -238 190 10 236 186 11 112 100 78 42 42 42
40852 - 14 14 14 0 0 0 0 0 0 0 0 0
40853 - 0 0 0 0 0 0 0 0 0 0 0 0
40854 - 0 0 0 0 0 0 0 0 0 0 0 0
40855 - 0 0 0 0 0 0 0 0 0 0 0 0
40856 - 0 0 0 0 0 0 0 0 0 6 6 6
40857 - 22 22 22 54 54 54 154 122 46 213 154 11
40858 -226 170 11 230 174 11 226 170 11 226 170 11
40859 -236 178 12 242 186 14 246 190 14 246 190 14
40860 -246 190 14 246 190 14 246 190 14 246 190 14
40861 -241 196 14 184 144 12 10 10 10 2 2 6
40862 - 6 6 6 116 116 116 242 242 242 253 253 253
40863 -253 253 253 253 253 253 253 253 253 253 253 253
40864 -253 253 253 253 253 253 253 253 253 253 253 253
40865 -253 253 253 253 253 253 253 253 253 253 253 253
40866 -253 253 253 253 253 253 253 253 253 253 253 253
40867 -253 253 253 231 231 231 198 198 198 214 170 54
40868 -236 178 12 236 178 12 210 150 10 137 92 6
40869 - 18 14 6 2 2 6 2 2 6 2 2 6
40870 - 6 6 6 70 47 6 200 144 11 236 178 12
40871 -239 182 13 239 182 13 124 112 88 58 58 58
40872 - 22 22 22 6 6 6 0 0 0 0 0 0
40873 - 0 0 0 0 0 0 0 0 0 0 0 0
40874 - 0 0 0 0 0 0 0 0 0 0 0 0
40875 - 0 0 0 0 0 0 0 0 0 0 0 0
40876 - 0 0 0 0 0 0 0 0 0 10 10 10
40877 - 30 30 30 70 70 70 180 133 36 226 170 11
40878 -239 182 13 242 186 14 242 186 14 246 186 14
40879 -246 190 14 246 190 14 246 190 14 246 190 14
40880 -246 190 14 246 190 14 246 190 14 246 190 14
40881 -246 190 14 232 195 16 98 70 6 2 2 6
40882 - 2 2 6 2 2 6 66 66 66 221 221 221
40883 -253 253 253 253 253 253 253 253 253 253 253 253
40884 -253 253 253 253 253 253 253 253 253 253 253 253
40885 -253 253 253 253 253 253 253 253 253 253 253 253
40886 -253 253 253 253 253 253 253 253 253 253 253 253
40887 -253 253 253 206 206 206 198 198 198 214 166 58
40888 -230 174 11 230 174 11 216 158 10 192 133 9
40889 -163 110 8 116 81 8 102 78 10 116 81 8
40890 -167 114 7 197 138 11 226 170 11 239 182 13
40891 -242 186 14 242 186 14 162 146 94 78 78 78
40892 - 34 34 34 14 14 14 6 6 6 0 0 0
40893 - 0 0 0 0 0 0 0 0 0 0 0 0
40894 - 0 0 0 0 0 0 0 0 0 0 0 0
40895 - 0 0 0 0 0 0 0 0 0 0 0 0
40896 - 0 0 0 0 0 0 0 0 0 6 6 6
40897 - 30 30 30 78 78 78 190 142 34 226 170 11
40898 -239 182 13 246 190 14 246 190 14 246 190 14
40899 -246 190 14 246 190 14 246 190 14 246 190 14
40900 -246 190 14 246 190 14 246 190 14 246 190 14
40901 -246 190 14 241 196 14 203 166 17 22 18 6
40902 - 2 2 6 2 2 6 2 2 6 38 38 38
40903 -218 218 218 253 253 253 253 253 253 253 253 253
40904 -253 253 253 253 253 253 253 253 253 253 253 253
40905 -253 253 253 253 253 253 253 253 253 253 253 253
40906 -253 253 253 253 253 253 253 253 253 253 253 253
40907 -250 250 250 206 206 206 198 198 198 202 162 69
40908 -226 170 11 236 178 12 224 166 10 210 150 10
40909 -200 144 11 197 138 11 192 133 9 197 138 11
40910 -210 150 10 226 170 11 242 186 14 246 190 14
40911 -246 190 14 246 186 14 225 175 15 124 112 88
40912 - 62 62 62 30 30 30 14 14 14 6 6 6
40913 - 0 0 0 0 0 0 0 0 0 0 0 0
40914 - 0 0 0 0 0 0 0 0 0 0 0 0
40915 - 0 0 0 0 0 0 0 0 0 0 0 0
40916 - 0 0 0 0 0 0 0 0 0 10 10 10
40917 - 30 30 30 78 78 78 174 135 50 224 166 10
40918 -239 182 13 246 190 14 246 190 14 246 190 14
40919 -246 190 14 246 190 14 246 190 14 246 190 14
40920 -246 190 14 246 190 14 246 190 14 246 190 14
40921 -246 190 14 246 190 14 241 196 14 139 102 15
40922 - 2 2 6 2 2 6 2 2 6 2 2 6
40923 - 78 78 78 250 250 250 253 253 253 253 253 253
40924 -253 253 253 253 253 253 253 253 253 253 253 253
40925 -253 253 253 253 253 253 253 253 253 253 253 253
40926 -253 253 253 253 253 253 253 253 253 253 253 253
40927 -250 250 250 214 214 214 198 198 198 190 150 46
40928 -219 162 10 236 178 12 234 174 13 224 166 10
40929 -216 158 10 213 154 11 213 154 11 216 158 10
40930 -226 170 11 239 182 13 246 190 14 246 190 14
40931 -246 190 14 246 190 14 242 186 14 206 162 42
40932 -101 101 101 58 58 58 30 30 30 14 14 14
40933 - 6 6 6 0 0 0 0 0 0 0 0 0
40934 - 0 0 0 0 0 0 0 0 0 0 0 0
40935 - 0 0 0 0 0 0 0 0 0 0 0 0
40936 - 0 0 0 0 0 0 0 0 0 10 10 10
40937 - 30 30 30 74 74 74 174 135 50 216 158 10
40938 -236 178 12 246 190 14 246 190 14 246 190 14
40939 -246 190 14 246 190 14 246 190 14 246 190 14
40940 -246 190 14 246 190 14 246 190 14 246 190 14
40941 -246 190 14 246 190 14 241 196 14 226 184 13
40942 - 61 42 6 2 2 6 2 2 6 2 2 6
40943 - 22 22 22 238 238 238 253 253 253 253 253 253
40944 -253 253 253 253 253 253 253 253 253 253 253 253
40945 -253 253 253 253 253 253 253 253 253 253 253 253
40946 -253 253 253 253 253 253 253 253 253 253 253 253
40947 -253 253 253 226 226 226 187 187 187 180 133 36
40948 -216 158 10 236 178 12 239 182 13 236 178 12
40949 -230 174 11 226 170 11 226 170 11 230 174 11
40950 -236 178 12 242 186 14 246 190 14 246 190 14
40951 -246 190 14 246 190 14 246 186 14 239 182 13
40952 -206 162 42 106 106 106 66 66 66 34 34 34
40953 - 14 14 14 6 6 6 0 0 0 0 0 0
40954 - 0 0 0 0 0 0 0 0 0 0 0 0
40955 - 0 0 0 0 0 0 0 0 0 0 0 0
40956 - 0 0 0 0 0 0 0 0 0 6 6 6
40957 - 26 26 26 70 70 70 163 133 67 213 154 11
40958 -236 178 12 246 190 14 246 190 14 246 190 14
40959 -246 190 14 246 190 14 246 190 14 246 190 14
40960 -246 190 14 246 190 14 246 190 14 246 190 14
40961 -246 190 14 246 190 14 246 190 14 241 196 14
40962 -190 146 13 18 14 6 2 2 6 2 2 6
40963 - 46 46 46 246 246 246 253 253 253 253 253 253
40964 -253 253 253 253 253 253 253 253 253 253 253 253
40965 -253 253 253 253 253 253 253 253 253 253 253 253
40966 -253 253 253 253 253 253 253 253 253 253 253 253
40967 -253 253 253 221 221 221 86 86 86 156 107 11
40968 -216 158 10 236 178 12 242 186 14 246 186 14
40969 -242 186 14 239 182 13 239 182 13 242 186 14
40970 -242 186 14 246 186 14 246 190 14 246 190 14
40971 -246 190 14 246 190 14 246 190 14 246 190 14
40972 -242 186 14 225 175 15 142 122 72 66 66 66
40973 - 30 30 30 10 10 10 0 0 0 0 0 0
40974 - 0 0 0 0 0 0 0 0 0 0 0 0
40975 - 0 0 0 0 0 0 0 0 0 0 0 0
40976 - 0 0 0 0 0 0 0 0 0 6 6 6
40977 - 26 26 26 70 70 70 163 133 67 210 150 10
40978 -236 178 12 246 190 14 246 190 14 246 190 14
40979 -246 190 14 246 190 14 246 190 14 246 190 14
40980 -246 190 14 246 190 14 246 190 14 246 190 14
40981 -246 190 14 246 190 14 246 190 14 246 190 14
40982 -232 195 16 121 92 8 34 34 34 106 106 106
40983 -221 221 221 253 253 253 253 253 253 253 253 253
40984 -253 253 253 253 253 253 253 253 253 253 253 253
40985 -253 253 253 253 253 253 253 253 253 253 253 253
40986 -253 253 253 253 253 253 253 253 253 253 253 253
40987 -242 242 242 82 82 82 18 14 6 163 110 8
40988 -216 158 10 236 178 12 242 186 14 246 190 14
40989 -246 190 14 246 190 14 246 190 14 246 190 14
40990 -246 190 14 246 190 14 246 190 14 246 190 14
40991 -246 190 14 246 190 14 246 190 14 246 190 14
40992 -246 190 14 246 190 14 242 186 14 163 133 67
40993 - 46 46 46 18 18 18 6 6 6 0 0 0
40994 - 0 0 0 0 0 0 0 0 0 0 0 0
40995 - 0 0 0 0 0 0 0 0 0 0 0 0
40996 - 0 0 0 0 0 0 0 0 0 10 10 10
40997 - 30 30 30 78 78 78 163 133 67 210 150 10
40998 -236 178 12 246 186 14 246 190 14 246 190 14
40999 -246 190 14 246 190 14 246 190 14 246 190 14
41000 -246 190 14 246 190 14 246 190 14 246 190 14
41001 -246 190 14 246 190 14 246 190 14 246 190 14
41002 -241 196 14 215 174 15 190 178 144 253 253 253
41003 -253 253 253 253 253 253 253 253 253 253 253 253
41004 -253 253 253 253 253 253 253 253 253 253 253 253
41005 -253 253 253 253 253 253 253 253 253 253 253 253
41006 -253 253 253 253 253 253 253 253 253 218 218 218
41007 - 58 58 58 2 2 6 22 18 6 167 114 7
41008 -216 158 10 236 178 12 246 186 14 246 190 14
41009 -246 190 14 246 190 14 246 190 14 246 190 14
41010 -246 190 14 246 190 14 246 190 14 246 190 14
41011 -246 190 14 246 190 14 246 190 14 246 190 14
41012 -246 190 14 246 186 14 242 186 14 190 150 46
41013 - 54 54 54 22 22 22 6 6 6 0 0 0
41014 - 0 0 0 0 0 0 0 0 0 0 0 0
41015 - 0 0 0 0 0 0 0 0 0 0 0 0
41016 - 0 0 0 0 0 0 0 0 0 14 14 14
41017 - 38 38 38 86 86 86 180 133 36 213 154 11
41018 -236 178 12 246 186 14 246 190 14 246 190 14
41019 -246 190 14 246 190 14 246 190 14 246 190 14
41020 -246 190 14 246 190 14 246 190 14 246 190 14
41021 -246 190 14 246 190 14 246 190 14 246 190 14
41022 -246 190 14 232 195 16 190 146 13 214 214 214
41023 -253 253 253 253 253 253 253 253 253 253 253 253
41024 -253 253 253 253 253 253 253 253 253 253 253 253
41025 -253 253 253 253 253 253 253 253 253 253 253 253
41026 -253 253 253 250 250 250 170 170 170 26 26 26
41027 - 2 2 6 2 2 6 37 26 9 163 110 8
41028 -219 162 10 239 182 13 246 186 14 246 190 14
41029 -246 190 14 246 190 14 246 190 14 246 190 14
41030 -246 190 14 246 190 14 246 190 14 246 190 14
41031 -246 190 14 246 190 14 246 190 14 246 190 14
41032 -246 186 14 236 178 12 224 166 10 142 122 72
41033 - 46 46 46 18 18 18 6 6 6 0 0 0
41034 - 0 0 0 0 0 0 0 0 0 0 0 0
41035 - 0 0 0 0 0 0 0 0 0 0 0 0
41036 - 0 0 0 0 0 0 6 6 6 18 18 18
41037 - 50 50 50 109 106 95 192 133 9 224 166 10
41038 -242 186 14 246 190 14 246 190 14 246 190 14
41039 -246 190 14 246 190 14 246 190 14 246 190 14
41040 -246 190 14 246 190 14 246 190 14 246 190 14
41041 -246 190 14 246 190 14 246 190 14 246 190 14
41042 -242 186 14 226 184 13 210 162 10 142 110 46
41043 -226 226 226 253 253 253 253 253 253 253 253 253
41044 -253 253 253 253 253 253 253 253 253 253 253 253
41045 -253 253 253 253 253 253 253 253 253 253 253 253
41046 -198 198 198 66 66 66 2 2 6 2 2 6
41047 - 2 2 6 2 2 6 50 34 6 156 107 11
41048 -219 162 10 239 182 13 246 186 14 246 190 14
41049 -246 190 14 246 190 14 246 190 14 246 190 14
41050 -246 190 14 246 190 14 246 190 14 246 190 14
41051 -246 190 14 246 190 14 246 190 14 242 186 14
41052 -234 174 13 213 154 11 154 122 46 66 66 66
41053 - 30 30 30 10 10 10 0 0 0 0 0 0
41054 - 0 0 0 0 0 0 0 0 0 0 0 0
41055 - 0 0 0 0 0 0 0 0 0 0 0 0
41056 - 0 0 0 0 0 0 6 6 6 22 22 22
41057 - 58 58 58 154 121 60 206 145 10 234 174 13
41058 -242 186 14 246 186 14 246 190 14 246 190 14
41059 -246 190 14 246 190 14 246 190 14 246 190 14
41060 -246 190 14 246 190 14 246 190 14 246 190 14
41061 -246 190 14 246 190 14 246 190 14 246 190 14
41062 -246 186 14 236 178 12 210 162 10 163 110 8
41063 - 61 42 6 138 138 138 218 218 218 250 250 250
41064 -253 253 253 253 253 253 253 253 253 250 250 250
41065 -242 242 242 210 210 210 144 144 144 66 66 66
41066 - 6 6 6 2 2 6 2 2 6 2 2 6
41067 - 2 2 6 2 2 6 61 42 6 163 110 8
41068 -216 158 10 236 178 12 246 190 14 246 190 14
41069 -246 190 14 246 190 14 246 190 14 246 190 14
41070 -246 190 14 246 190 14 246 190 14 246 190 14
41071 -246 190 14 239 182 13 230 174 11 216 158 10
41072 -190 142 34 124 112 88 70 70 70 38 38 38
41073 - 18 18 18 6 6 6 0 0 0 0 0 0
41074 - 0 0 0 0 0 0 0 0 0 0 0 0
41075 - 0 0 0 0 0 0 0 0 0 0 0 0
41076 - 0 0 0 0 0 0 6 6 6 22 22 22
41077 - 62 62 62 168 124 44 206 145 10 224 166 10
41078 -236 178 12 239 182 13 242 186 14 242 186 14
41079 -246 186 14 246 190 14 246 190 14 246 190 14
41080 -246 190 14 246 190 14 246 190 14 246 190 14
41081 -246 190 14 246 190 14 246 190 14 246 190 14
41082 -246 190 14 236 178 12 216 158 10 175 118 6
41083 - 80 54 7 2 2 6 6 6 6 30 30 30
41084 - 54 54 54 62 62 62 50 50 50 38 38 38
41085 - 14 14 14 2 2 6 2 2 6 2 2 6
41086 - 2 2 6 2 2 6 2 2 6 2 2 6
41087 - 2 2 6 6 6 6 80 54 7 167 114 7
41088 -213 154 11 236 178 12 246 190 14 246 190 14
41089 -246 190 14 246 190 14 246 190 14 246 190 14
41090 -246 190 14 242 186 14 239 182 13 239 182 13
41091 -230 174 11 210 150 10 174 135 50 124 112 88
41092 - 82 82 82 54 54 54 34 34 34 18 18 18
41093 - 6 6 6 0 0 0 0 0 0 0 0 0
41094 - 0 0 0 0 0 0 0 0 0 0 0 0
41095 - 0 0 0 0 0 0 0 0 0 0 0 0
41096 - 0 0 0 0 0 0 6 6 6 18 18 18
41097 - 50 50 50 158 118 36 192 133 9 200 144 11
41098 -216 158 10 219 162 10 224 166 10 226 170 11
41099 -230 174 11 236 178 12 239 182 13 239 182 13
41100 -242 186 14 246 186 14 246 190 14 246 190 14
41101 -246 190 14 246 190 14 246 190 14 246 190 14
41102 -246 186 14 230 174 11 210 150 10 163 110 8
41103 -104 69 6 10 10 10 2 2 6 2 2 6
41104 - 2 2 6 2 2 6 2 2 6 2 2 6
41105 - 2 2 6 2 2 6 2 2 6 2 2 6
41106 - 2 2 6 2 2 6 2 2 6 2 2 6
41107 - 2 2 6 6 6 6 91 60 6 167 114 7
41108 -206 145 10 230 174 11 242 186 14 246 190 14
41109 -246 190 14 246 190 14 246 186 14 242 186 14
41110 -239 182 13 230 174 11 224 166 10 213 154 11
41111 -180 133 36 124 112 88 86 86 86 58 58 58
41112 - 38 38 38 22 22 22 10 10 10 6 6 6
41113 - 0 0 0 0 0 0 0 0 0 0 0 0
41114 - 0 0 0 0 0 0 0 0 0 0 0 0
41115 - 0 0 0 0 0 0 0 0 0 0 0 0
41116 - 0 0 0 0 0 0 0 0 0 14 14 14
41117 - 34 34 34 70 70 70 138 110 50 158 118 36
41118 -167 114 7 180 123 7 192 133 9 197 138 11
41119 -200 144 11 206 145 10 213 154 11 219 162 10
41120 -224 166 10 230 174 11 239 182 13 242 186 14
41121 -246 186 14 246 186 14 246 186 14 246 186 14
41122 -239 182 13 216 158 10 185 133 11 152 99 6
41123 -104 69 6 18 14 6 2 2 6 2 2 6
41124 - 2 2 6 2 2 6 2 2 6 2 2 6
41125 - 2 2 6 2 2 6 2 2 6 2 2 6
41126 - 2 2 6 2 2 6 2 2 6 2 2 6
41127 - 2 2 6 6 6 6 80 54 7 152 99 6
41128 -192 133 9 219 162 10 236 178 12 239 182 13
41129 -246 186 14 242 186 14 239 182 13 236 178 12
41130 -224 166 10 206 145 10 192 133 9 154 121 60
41131 - 94 94 94 62 62 62 42 42 42 22 22 22
41132 - 14 14 14 6 6 6 0 0 0 0 0 0
41133 - 0 0 0 0 0 0 0 0 0 0 0 0
41134 - 0 0 0 0 0 0 0 0 0 0 0 0
41135 - 0 0 0 0 0 0 0 0 0 0 0 0
41136 - 0 0 0 0 0 0 0 0 0 6 6 6
41137 - 18 18 18 34 34 34 58 58 58 78 78 78
41138 -101 98 89 124 112 88 142 110 46 156 107 11
41139 -163 110 8 167 114 7 175 118 6 180 123 7
41140 -185 133 11 197 138 11 210 150 10 219 162 10
41141 -226 170 11 236 178 12 236 178 12 234 174 13
41142 -219 162 10 197 138 11 163 110 8 130 83 6
41143 - 91 60 6 10 10 10 2 2 6 2 2 6
41144 - 18 18 18 38 38 38 38 38 38 38 38 38
41145 - 38 38 38 38 38 38 38 38 38 38 38 38
41146 - 38 38 38 38 38 38 26 26 26 2 2 6
41147 - 2 2 6 6 6 6 70 47 6 137 92 6
41148 -175 118 6 200 144 11 219 162 10 230 174 11
41149 -234 174 13 230 174 11 219 162 10 210 150 10
41150 -192 133 9 163 110 8 124 112 88 82 82 82
41151 - 50 50 50 30 30 30 14 14 14 6 6 6
41152 - 0 0 0 0 0 0 0 0 0 0 0 0
41153 - 0 0 0 0 0 0 0 0 0 0 0 0
41154 - 0 0 0 0 0 0 0 0 0 0 0 0
41155 - 0 0 0 0 0 0 0 0 0 0 0 0
41156 - 0 0 0 0 0 0 0 0 0 0 0 0
41157 - 6 6 6 14 14 14 22 22 22 34 34 34
41158 - 42 42 42 58 58 58 74 74 74 86 86 86
41159 -101 98 89 122 102 70 130 98 46 121 87 25
41160 -137 92 6 152 99 6 163 110 8 180 123 7
41161 -185 133 11 197 138 11 206 145 10 200 144 11
41162 -180 123 7 156 107 11 130 83 6 104 69 6
41163 - 50 34 6 54 54 54 110 110 110 101 98 89
41164 - 86 86 86 82 82 82 78 78 78 78 78 78
41165 - 78 78 78 78 78 78 78 78 78 78 78 78
41166 - 78 78 78 82 82 82 86 86 86 94 94 94
41167 -106 106 106 101 101 101 86 66 34 124 80 6
41168 -156 107 11 180 123 7 192 133 9 200 144 11
41169 -206 145 10 200 144 11 192 133 9 175 118 6
41170 -139 102 15 109 106 95 70 70 70 42 42 42
41171 - 22 22 22 10 10 10 0 0 0 0 0 0
41172 - 0 0 0 0 0 0 0 0 0 0 0 0
41173 - 0 0 0 0 0 0 0 0 0 0 0 0
41174 - 0 0 0 0 0 0 0 0 0 0 0 0
41175 - 0 0 0 0 0 0 0 0 0 0 0 0
41176 - 0 0 0 0 0 0 0 0 0 0 0 0
41177 - 0 0 0 0 0 0 6 6 6 10 10 10
41178 - 14 14 14 22 22 22 30 30 30 38 38 38
41179 - 50 50 50 62 62 62 74 74 74 90 90 90
41180 -101 98 89 112 100 78 121 87 25 124 80 6
41181 -137 92 6 152 99 6 152 99 6 152 99 6
41182 -138 86 6 124 80 6 98 70 6 86 66 30
41183 -101 98 89 82 82 82 58 58 58 46 46 46
41184 - 38 38 38 34 34 34 34 34 34 34 34 34
41185 - 34 34 34 34 34 34 34 34 34 34 34 34
41186 - 34 34 34 34 34 34 38 38 38 42 42 42
41187 - 54 54 54 82 82 82 94 86 76 91 60 6
41188 -134 86 6 156 107 11 167 114 7 175 118 6
41189 -175 118 6 167 114 7 152 99 6 121 87 25
41190 -101 98 89 62 62 62 34 34 34 18 18 18
41191 - 6 6 6 0 0 0 0 0 0 0 0 0
41192 - 0 0 0 0 0 0 0 0 0 0 0 0
41193 - 0 0 0 0 0 0 0 0 0 0 0 0
41194 - 0 0 0 0 0 0 0 0 0 0 0 0
41195 - 0 0 0 0 0 0 0 0 0 0 0 0
41196 - 0 0 0 0 0 0 0 0 0 0 0 0
41197 - 0 0 0 0 0 0 0 0 0 0 0 0
41198 - 0 0 0 6 6 6 6 6 6 10 10 10
41199 - 18 18 18 22 22 22 30 30 30 42 42 42
41200 - 50 50 50 66 66 66 86 86 86 101 98 89
41201 -106 86 58 98 70 6 104 69 6 104 69 6
41202 -104 69 6 91 60 6 82 62 34 90 90 90
41203 - 62 62 62 38 38 38 22 22 22 14 14 14
41204 - 10 10 10 10 10 10 10 10 10 10 10 10
41205 - 10 10 10 10 10 10 6 6 6 10 10 10
41206 - 10 10 10 10 10 10 10 10 10 14 14 14
41207 - 22 22 22 42 42 42 70 70 70 89 81 66
41208 - 80 54 7 104 69 6 124 80 6 137 92 6
41209 -134 86 6 116 81 8 100 82 52 86 86 86
41210 - 58 58 58 30 30 30 14 14 14 6 6 6
41211 - 0 0 0 0 0 0 0 0 0 0 0 0
41212 - 0 0 0 0 0 0 0 0 0 0 0 0
41213 - 0 0 0 0 0 0 0 0 0 0 0 0
41214 - 0 0 0 0 0 0 0 0 0 0 0 0
41215 - 0 0 0 0 0 0 0 0 0 0 0 0
41216 - 0 0 0 0 0 0 0 0 0 0 0 0
41217 - 0 0 0 0 0 0 0 0 0 0 0 0
41218 - 0 0 0 0 0 0 0 0 0 0 0 0
41219 - 0 0 0 6 6 6 10 10 10 14 14 14
41220 - 18 18 18 26 26 26 38 38 38 54 54 54
41221 - 70 70 70 86 86 86 94 86 76 89 81 66
41222 - 89 81 66 86 86 86 74 74 74 50 50 50
41223 - 30 30 30 14 14 14 6 6 6 0 0 0
41224 - 0 0 0 0 0 0 0 0 0 0 0 0
41225 - 0 0 0 0 0 0 0 0 0 0 0 0
41226 - 0 0 0 0 0 0 0 0 0 0 0 0
41227 - 6 6 6 18 18 18 34 34 34 58 58 58
41228 - 82 82 82 89 81 66 89 81 66 89 81 66
41229 - 94 86 66 94 86 76 74 74 74 50 50 50
41230 - 26 26 26 14 14 14 6 6 6 0 0 0
41231 - 0 0 0 0 0 0 0 0 0 0 0 0
41232 - 0 0 0 0 0 0 0 0 0 0 0 0
41233 - 0 0 0 0 0 0 0 0 0 0 0 0
41234 - 0 0 0 0 0 0 0 0 0 0 0 0
41235 - 0 0 0 0 0 0 0 0 0 0 0 0
41236 - 0 0 0 0 0 0 0 0 0 0 0 0
41237 - 0 0 0 0 0 0 0 0 0 0 0 0
41238 - 0 0 0 0 0 0 0 0 0 0 0 0
41239 - 0 0 0 0 0 0 0 0 0 0 0 0
41240 - 6 6 6 6 6 6 14 14 14 18 18 18
41241 - 30 30 30 38 38 38 46 46 46 54 54 54
41242 - 50 50 50 42 42 42 30 30 30 18 18 18
41243 - 10 10 10 0 0 0 0 0 0 0 0 0
41244 - 0 0 0 0 0 0 0 0 0 0 0 0
41245 - 0 0 0 0 0 0 0 0 0 0 0 0
41246 - 0 0 0 0 0 0 0 0 0 0 0 0
41247 - 0 0 0 6 6 6 14 14 14 26 26 26
41248 - 38 38 38 50 50 50 58 58 58 58 58 58
41249 - 54 54 54 42 42 42 30 30 30 18 18 18
41250 - 10 10 10 0 0 0 0 0 0 0 0 0
41251 - 0 0 0 0 0 0 0 0 0 0 0 0
41252 - 0 0 0 0 0 0 0 0 0 0 0 0
41253 - 0 0 0 0 0 0 0 0 0 0 0 0
41254 - 0 0 0 0 0 0 0 0 0 0 0 0
41255 - 0 0 0 0 0 0 0 0 0 0 0 0
41256 - 0 0 0 0 0 0 0 0 0 0 0 0
41257 - 0 0 0 0 0 0 0 0 0 0 0 0
41258 - 0 0 0 0 0 0 0 0 0 0 0 0
41259 - 0 0 0 0 0 0 0 0 0 0 0 0
41260 - 0 0 0 0 0 0 0 0 0 6 6 6
41261 - 6 6 6 10 10 10 14 14 14 18 18 18
41262 - 18 18 18 14 14 14 10 10 10 6 6 6
41263 - 0 0 0 0 0 0 0 0 0 0 0 0
41264 - 0 0 0 0 0 0 0 0 0 0 0 0
41265 - 0 0 0 0 0 0 0 0 0 0 0 0
41266 - 0 0 0 0 0 0 0 0 0 0 0 0
41267 - 0 0 0 0 0 0 0 0 0 6 6 6
41268 - 14 14 14 18 18 18 22 22 22 22 22 22
41269 - 18 18 18 14 14 14 10 10 10 6 6 6
41270 - 0 0 0 0 0 0 0 0 0 0 0 0
41271 - 0 0 0 0 0 0 0 0 0 0 0 0
41272 - 0 0 0 0 0 0 0 0 0 0 0 0
41273 - 0 0 0 0 0 0 0 0 0 0 0 0
41274 - 0 0 0 0 0 0 0 0 0 0 0 0
41275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41282 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41288 +4 4 4 4 4 4
41289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41302 +4 4 4 4 4 4
41303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41316 +4 4 4 4 4 4
41317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41330 +4 4 4 4 4 4
41331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41344 +4 4 4 4 4 4
41345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41358 +4 4 4 4 4 4
41359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41363 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
41364 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
41365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41368 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
41369 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41370 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
41371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41372 +4 4 4 4 4 4
41373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41377 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
41378 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
41379 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41382 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
41383 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
41384 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
41385 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41386 +4 4 4 4 4 4
41387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41391 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
41392 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
41393 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41394 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41395 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41396 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
41397 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
41398 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
41399 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
41400 +4 4 4 4 4 4
41401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41404 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
41405 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
41406 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
41407 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
41408 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41409 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41410 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
41411 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
41412 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
41413 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
41414 +4 4 4 4 4 4
41415 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41416 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41418 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
41419 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
41420 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
41421 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
41422 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
41423 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
41424 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
41425 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
41426 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
41427 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
41428 +4 4 4 4 4 4
41429 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41430 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41431 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
41432 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
41433 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
41434 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
41435 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
41436 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
41437 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
41438 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
41439 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
41440 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
41441 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
41442 +4 4 4 4 4 4
41443 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41444 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41445 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
41446 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
41447 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
41448 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
41449 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
41450 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
41451 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
41452 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
41453 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
41454 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
41455 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
41456 +4 4 4 4 4 4
41457 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41458 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41459 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
41460 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
41461 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
41462 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
41463 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
41464 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
41465 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
41466 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
41467 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
41468 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
41469 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
41470 +4 4 4 4 4 4
41471 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41472 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41473 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
41474 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
41475 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
41476 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
41477 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
41478 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
41479 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
41480 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
41481 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
41482 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
41483 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
41484 +4 4 4 4 4 4
41485 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41486 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41487 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
41488 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
41489 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
41490 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
41491 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
41492 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
41493 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
41494 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
41495 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
41496 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
41497 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
41498 +4 4 4 4 4 4
41499 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41500 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
41501 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
41502 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
41503 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
41504 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
41505 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
41506 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
41507 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
41508 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
41509 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
41510 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
41511 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
41512 +4 4 4 4 4 4
41513 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41514 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
41515 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
41516 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
41517 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
41518 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
41519 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
41520 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
41521 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
41522 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
41523 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
41524 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
41525 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
41526 +0 0 0 4 4 4
41527 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
41528 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
41529 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
41530 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
41531 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
41532 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
41533 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
41534 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
41535 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
41536 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
41537 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
41538 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
41539 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
41540 +2 0 0 0 0 0
41541 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
41542 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
41543 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
41544 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
41545 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
41546 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
41547 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
41548 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
41549 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
41550 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
41551 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
41552 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
41553 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
41554 +37 38 37 0 0 0
41555 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41556 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
41557 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
41558 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
41559 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
41560 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
41561 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
41562 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
41563 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
41564 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
41565 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
41566 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
41567 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
41568 +85 115 134 4 0 0
41569 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
41570 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
41571 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
41572 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
41573 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
41574 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
41575 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
41576 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
41577 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
41578 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
41579 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
41580 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
41581 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
41582 +60 73 81 4 0 0
41583 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
41584 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
41585 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
41586 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
41587 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
41588 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
41589 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
41590 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
41591 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
41592 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
41593 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
41594 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
41595 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
41596 +16 19 21 4 0 0
41597 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
41598 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
41599 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
41600 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
41601 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
41602 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
41603 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
41604 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
41605 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
41606 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
41607 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
41608 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
41609 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
41610 +4 0 0 4 3 3
41611 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
41612 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
41613 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
41614 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
41615 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
41616 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
41617 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
41618 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
41619 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
41620 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
41621 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
41622 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
41623 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
41624 +3 2 2 4 4 4
41625 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
41626 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
41627 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
41628 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
41629 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
41630 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
41631 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
41632 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
41633 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
41634 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
41635 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
41636 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
41637 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
41638 +4 4 4 4 4 4
41639 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
41640 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
41641 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
41642 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
41643 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
41644 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
41645 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
41646 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
41647 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
41648 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
41649 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
41650 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
41651 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
41652 +4 4 4 4 4 4
41653 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
41654 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
41655 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
41656 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
41657 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
41658 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41659 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
41660 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
41661 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
41662 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
41663 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
41664 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
41665 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
41666 +5 5 5 5 5 5
41667 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
41668 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
41669 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
41670 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
41671 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
41672 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41673 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
41674 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
41675 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
41676 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
41677 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
41678 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
41679 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
41680 +5 5 5 4 4 4
41681 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
41682 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
41683 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
41684 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
41685 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41686 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
41687 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
41688 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
41689 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
41690 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
41691 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
41692 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
41693 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41694 +4 4 4 4 4 4
41695 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
41696 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
41697 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
41698 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
41699 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
41700 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41701 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41702 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
41703 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
41704 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
41705 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
41706 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
41707 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41708 +4 4 4 4 4 4
41709 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
41710 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
41711 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
41712 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
41713 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41714 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
41715 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
41716 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
41717 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
41718 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
41719 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
41720 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41721 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41722 +4 4 4 4 4 4
41723 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
41724 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
41725 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
41726 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
41727 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41728 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41729 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
41730 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
41731 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
41732 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
41733 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
41734 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41735 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41736 +4 4 4 4 4 4
41737 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
41738 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
41739 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
41740 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
41741 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41742 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
41743 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
41744 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
41745 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
41746 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
41747 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41748 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41749 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41750 +4 4 4 4 4 4
41751 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
41752 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
41753 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
41754 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
41755 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
41756 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
41757 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
41758 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
41759 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
41760 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
41761 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
41762 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41763 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41764 +4 4 4 4 4 4
41765 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
41766 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
41767 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
41768 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
41769 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
41770 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
41771 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
41772 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
41773 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
41774 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
41775 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
41776 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41777 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41778 +4 4 4 4 4 4
41779 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
41780 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
41781 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
41782 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41783 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
41784 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
41785 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
41786 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
41787 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
41788 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
41789 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41790 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41791 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41792 +4 4 4 4 4 4
41793 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
41794 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
41795 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
41796 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41797 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41798 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
41799 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
41800 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
41801 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
41802 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
41803 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41804 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41805 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41806 +4 4 4 4 4 4
41807 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
41808 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
41809 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41810 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
41811 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41812 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
41813 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
41814 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
41815 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
41816 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
41817 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41818 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41819 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41820 +4 4 4 4 4 4
41821 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
41822 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
41823 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41824 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
41825 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41826 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
41827 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
41828 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
41829 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41830 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41831 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41832 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41833 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41834 +4 4 4 4 4 4
41835 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41836 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
41837 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
41838 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
41839 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
41840 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
41841 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
41842 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
41843 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41844 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41845 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41846 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41847 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41848 +4 4 4 4 4 4
41849 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
41850 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
41851 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
41852 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
41853 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41854 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
41855 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
41856 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
41857 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41858 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41859 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41860 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41861 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41862 +4 4 4 4 4 4
41863 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
41864 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
41865 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41866 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
41867 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
41868 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
41869 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
41870 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
41871 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41872 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41873 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41874 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41875 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41876 +4 4 4 4 4 4
41877 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
41878 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
41879 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41880 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
41881 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
41882 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
41883 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
41884 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
41885 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
41886 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41887 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41888 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41889 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41890 +4 4 4 4 4 4
41891 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41892 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
41893 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
41894 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
41895 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
41896 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
41897 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
41898 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
41899 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41900 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41901 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41902 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41903 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41904 +4 4 4 4 4 4
41905 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
41906 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
41907 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41908 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
41909 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
41910 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
41911 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
41912 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
41913 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
41914 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41915 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41916 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41917 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41918 +4 4 4 4 4 4
41919 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
41920 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
41921 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
41922 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
41923 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
41924 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
41925 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
41926 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
41927 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41928 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41929 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41930 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41931 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41932 +4 4 4 4 4 4
41933 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41934 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
41935 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
41936 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
41937 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
41938 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
41939 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
41940 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
41941 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41942 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41943 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41944 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41945 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41946 +4 4 4 4 4 4
41947 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41948 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
41949 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
41950 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
41951 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
41952 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
41953 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41954 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
41955 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
41956 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41957 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41958 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41959 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41960 +4 4 4 4 4 4
41961 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41962 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
41963 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
41964 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
41965 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
41966 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
41967 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
41968 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
41969 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
41970 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41971 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41972 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41973 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41974 +4 4 4 4 4 4
41975 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
41976 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
41977 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
41978 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
41979 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
41980 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
41981 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
41982 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
41983 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
41984 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41985 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
41986 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41987 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
41988 +4 4 4 4 4 4
41989 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
41990 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
41991 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
41992 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
41993 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
41994 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
41995 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
41996 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
41997 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
41998 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
41999 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42000 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42001 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42002 +4 4 4 4 4 4
42003 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
42004 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
42005 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
42006 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
42007 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
42008 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
42009 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
42010 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
42011 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
42012 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42013 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42014 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42015 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42016 +4 4 4 4 4 4
42017 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
42018 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
42019 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
42020 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
42021 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
42022 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
42023 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
42024 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
42025 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
42026 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
42027 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42028 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42029 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42030 +4 4 4 4 4 4
42031 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
42032 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
42033 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
42034 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
42035 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
42036 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
42037 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
42038 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
42039 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
42040 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
42041 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42042 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42043 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42044 +4 4 4 4 4 4
42045 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
42046 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42047 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
42048 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
42049 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
42050 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
42051 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
42052 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
42053 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
42054 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
42055 +0 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42056 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42057 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42058 +4 4 4 4 4 4
42059 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
42060 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
42061 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
42062 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
42063 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
42064 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
42065 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42066 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
42067 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
42068 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
42069 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42070 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42071 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42072 +4 4 4 4 4 4
42073 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
42074 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
42075 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
42076 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
42077 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
42078 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
42079 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
42080 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
42081 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
42082 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
42083 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42084 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42085 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42086 +4 4 4 4 4 4
42087 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
42088 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
42089 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42090 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
42091 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
42092 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
42093 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
42094 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
42095 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
42096 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
42097 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42098 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42099 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42100 +4 4 4 4 4 4
42101 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42102 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
42103 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
42104 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
42105 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
42106 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
42107 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
42108 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
42109 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
42110 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42111 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42112 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42113 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42114 +4 4 4 4 4 4
42115 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
42116 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
42117 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
42118 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
42119 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
42120 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
42121 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
42122 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
42123 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
42124 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
42125 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42126 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42127 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42128 +4 4 4 4 4 4
42129 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
42130 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
42131 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
42132 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
42133 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
42134 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
42135 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
42136 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
42137 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
42138 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42139 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42140 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42141 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42142 +4 4 4 4 4 4
42143 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
42144 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42145 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
42146 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
42147 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
42148 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
42149 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
42150 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
42151 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
42152 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42153 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42154 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42155 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42156 +4 4 4 4 4 4
42157 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
42158 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
42159 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
42160 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
42161 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
42162 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
42163 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
42164 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
42165 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
42166 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42167 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42168 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42169 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42170 +4 4 4 4 4 4
42171 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42172 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
42173 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
42174 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
42175 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
42176 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
42177 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
42178 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
42179 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42180 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42181 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42182 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42183 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42184 +4 4 4 4 4 4
42185 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
42186 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
42187 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42188 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
42189 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
42190 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
42191 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
42192 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
42193 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42194 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42195 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42196 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42197 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42198 +4 4 4 4 4 4
42199 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42200 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
42201 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
42202 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
42203 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
42204 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
42205 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
42206 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
42207 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42208 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42209 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42210 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42211 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42212 +4 4 4 4 4 4
42213 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42214 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
42215 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42216 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
42217 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
42218 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
42219 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
42220 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
42221 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42223 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42224 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42225 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42226 +4 4 4 4 4 4
42227 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42228 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
42229 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
42230 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
42231 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
42232 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
42233 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
42234 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
42235 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42237 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42238 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42239 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42240 +4 4 4 4 4 4
42241 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42242 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
42243 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
42244 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42245 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
42246 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
42247 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
42248 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42249 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42251 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42252 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42253 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42254 +4 4 4 4 4 4
42255 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42256 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42257 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42258 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
42259 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
42260 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
42261 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
42262 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
42263 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42266 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42267 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42268 +4 4 4 4 4 4
42269 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42270 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42271 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42272 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42273 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
42274 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
42275 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
42276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42277 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42281 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42282 +4 4 4 4 4 4
42283 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42286 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
42287 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
42288 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
42289 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
42290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42296 +4 4 4 4 4 4
42297 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42300 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
42301 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
42302 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
42303 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
42304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42310 +4 4 4 4 4 4
42311 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42314 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
42315 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
42316 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
42317 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
42318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42324 +4 4 4 4 4 4
42325 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
42329 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
42330 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
42331 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
42332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42338 +4 4 4 4 4 4
42339 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42343 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
42344 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
42345 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
42346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42352 +4 4 4 4 4 4
42353 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42357 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
42358 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
42359 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42366 +4 4 4 4 4 4
42367 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42371 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
42372 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
42373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42377 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42378 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42379 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42380 +4 4 4 4 4 4
42381 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42385 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
42386 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
42387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42391 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42392 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42393 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
42394 +4 4 4 4 4 4
42395 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
42396 index 8af6414..658c030 100644
42397 --- a/drivers/video/udlfb.c
42398 +++ b/drivers/video/udlfb.c
42399 @@ -620,11 +620,11 @@ int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
42400 dlfb_urb_completion(urb);
42401
42402 error:
42403 - atomic_add(bytes_sent, &dev->bytes_sent);
42404 - atomic_add(bytes_identical, &dev->bytes_identical);
42405 - atomic_add(width*height*2, &dev->bytes_rendered);
42406 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42407 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42408 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
42409 end_cycles = get_cycles();
42410 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42411 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42412 >> 10)), /* Kcycles */
42413 &dev->cpu_kcycles_used);
42414
42415 @@ -745,11 +745,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
42416 dlfb_urb_completion(urb);
42417
42418 error:
42419 - atomic_add(bytes_sent, &dev->bytes_sent);
42420 - atomic_add(bytes_identical, &dev->bytes_identical);
42421 - atomic_add(bytes_rendered, &dev->bytes_rendered);
42422 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
42423 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
42424 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
42425 end_cycles = get_cycles();
42426 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
42427 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
42428 >> 10)), /* Kcycles */
42429 &dev->cpu_kcycles_used);
42430 }
42431 @@ -1373,7 +1373,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
42432 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42433 struct dlfb_data *dev = fb_info->par;
42434 return snprintf(buf, PAGE_SIZE, "%u\n",
42435 - atomic_read(&dev->bytes_rendered));
42436 + atomic_read_unchecked(&dev->bytes_rendered));
42437 }
42438
42439 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42440 @@ -1381,7 +1381,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
42441 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42442 struct dlfb_data *dev = fb_info->par;
42443 return snprintf(buf, PAGE_SIZE, "%u\n",
42444 - atomic_read(&dev->bytes_identical));
42445 + atomic_read_unchecked(&dev->bytes_identical));
42446 }
42447
42448 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42449 @@ -1389,7 +1389,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
42450 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42451 struct dlfb_data *dev = fb_info->par;
42452 return snprintf(buf, PAGE_SIZE, "%u\n",
42453 - atomic_read(&dev->bytes_sent));
42454 + atomic_read_unchecked(&dev->bytes_sent));
42455 }
42456
42457 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42458 @@ -1397,7 +1397,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
42459 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42460 struct dlfb_data *dev = fb_info->par;
42461 return snprintf(buf, PAGE_SIZE, "%u\n",
42462 - atomic_read(&dev->cpu_kcycles_used));
42463 + atomic_read_unchecked(&dev->cpu_kcycles_used));
42464 }
42465
42466 static ssize_t edid_show(
42467 @@ -1457,10 +1457,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
42468 struct fb_info *fb_info = dev_get_drvdata(fbdev);
42469 struct dlfb_data *dev = fb_info->par;
42470
42471 - atomic_set(&dev->bytes_rendered, 0);
42472 - atomic_set(&dev->bytes_identical, 0);
42473 - atomic_set(&dev->bytes_sent, 0);
42474 - atomic_set(&dev->cpu_kcycles_used, 0);
42475 + atomic_set_unchecked(&dev->bytes_rendered, 0);
42476 + atomic_set_unchecked(&dev->bytes_identical, 0);
42477 + atomic_set_unchecked(&dev->bytes_sent, 0);
42478 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
42479
42480 return count;
42481 }
42482 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
42483 index b0e2a42..e2df3ad 100644
42484 --- a/drivers/video/uvesafb.c
42485 +++ b/drivers/video/uvesafb.c
42486 @@ -19,6 +19,7 @@
42487 #include <linux/io.h>
42488 #include <linux/mutex.h>
42489 #include <linux/slab.h>
42490 +#include <linux/moduleloader.h>
42491 #include <video/edid.h>
42492 #include <video/uvesafb.h>
42493 #ifdef CONFIG_X86
42494 @@ -569,10 +570,32 @@ static int __devinit uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
42495 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
42496 par->pmi_setpal = par->ypan = 0;
42497 } else {
42498 +
42499 +#ifdef CONFIG_PAX_KERNEXEC
42500 +#ifdef CONFIG_MODULES
42501 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
42502 +#endif
42503 + if (!par->pmi_code) {
42504 + par->pmi_setpal = par->ypan = 0;
42505 + return 0;
42506 + }
42507 +#endif
42508 +
42509 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
42510 + task->t.regs.edi);
42511 +
42512 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42513 + pax_open_kernel();
42514 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
42515 + pax_close_kernel();
42516 +
42517 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
42518 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
42519 +#else
42520 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
42521 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
42522 +#endif
42523 +
42524 printk(KERN_INFO "uvesafb: protected mode interface info at "
42525 "%04x:%04x\n",
42526 (u16)task->t.regs.es, (u16)task->t.regs.edi);
42527 @@ -816,13 +839,14 @@ static int __devinit uvesafb_vbe_init(struct fb_info *info)
42528 par->ypan = ypan;
42529
42530 if (par->pmi_setpal || par->ypan) {
42531 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
42532 if (__supported_pte_mask & _PAGE_NX) {
42533 par->pmi_setpal = par->ypan = 0;
42534 printk(KERN_WARNING "uvesafb: NX protection is actively."
42535 "We have better not to use the PMI.\n");
42536 - } else {
42537 + } else
42538 +#endif
42539 uvesafb_vbe_getpmi(task, par);
42540 - }
42541 }
42542 #else
42543 /* The protected mode interface is not available on non-x86. */
42544 @@ -1836,6 +1860,11 @@ out:
42545 if (par->vbe_modes)
42546 kfree(par->vbe_modes);
42547
42548 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42549 + if (par->pmi_code)
42550 + module_free_exec(NULL, par->pmi_code);
42551 +#endif
42552 +
42553 framebuffer_release(info);
42554 return err;
42555 }
42556 @@ -1862,6 +1891,12 @@ static int uvesafb_remove(struct platform_device *dev)
42557 kfree(par->vbe_state_orig);
42558 if (par->vbe_state_saved)
42559 kfree(par->vbe_state_saved);
42560 +
42561 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42562 + if (par->pmi_code)
42563 + module_free_exec(NULL, par->pmi_code);
42564 +#endif
42565 +
42566 }
42567
42568 framebuffer_release(info);
42569 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
42570 index 501b340..86bd4cf 100644
42571 --- a/drivers/video/vesafb.c
42572 +++ b/drivers/video/vesafb.c
42573 @@ -9,6 +9,7 @@
42574 */
42575
42576 #include <linux/module.h>
42577 +#include <linux/moduleloader.h>
42578 #include <linux/kernel.h>
42579 #include <linux/errno.h>
42580 #include <linux/string.h>
42581 @@ -52,8 +53,8 @@ static int vram_remap __initdata; /* Set amount of memory to be used */
42582 static int vram_total __initdata; /* Set total amount of memory */
42583 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
42584 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
42585 -static void (*pmi_start)(void) __read_mostly;
42586 -static void (*pmi_pal) (void) __read_mostly;
42587 +static void (*pmi_start)(void) __read_only;
42588 +static void (*pmi_pal) (void) __read_only;
42589 static int depth __read_mostly;
42590 static int vga_compat __read_mostly;
42591 /* --------------------------------------------------------------------- */
42592 @@ -233,6 +234,7 @@ static int __init vesafb_probe(struct platform_device *dev)
42593 unsigned int size_vmode;
42594 unsigned int size_remap;
42595 unsigned int size_total;
42596 + void *pmi_code = NULL;
42597
42598 if (screen_info.orig_video_isVGA != VIDEO_TYPE_VLFB)
42599 return -ENODEV;
42600 @@ -275,10 +277,6 @@ static int __init vesafb_probe(struct platform_device *dev)
42601 size_remap = size_total;
42602 vesafb_fix.smem_len = size_remap;
42603
42604 -#ifndef __i386__
42605 - screen_info.vesapm_seg = 0;
42606 -#endif
42607 -
42608 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
42609 printk(KERN_WARNING
42610 "vesafb: cannot reserve video memory at 0x%lx\n",
42611 @@ -307,9 +305,21 @@ static int __init vesafb_probe(struct platform_device *dev)
42612 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
42613 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
42614
42615 +#ifdef __i386__
42616 +
42617 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42618 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
42619 + if (!pmi_code)
42620 +#elif !defined(CONFIG_PAX_KERNEXEC)
42621 + if (0)
42622 +#endif
42623 +
42624 +#endif
42625 + screen_info.vesapm_seg = 0;
42626 +
42627 if (screen_info.vesapm_seg) {
42628 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
42629 - screen_info.vesapm_seg,screen_info.vesapm_off);
42630 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
42631 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
42632 }
42633
42634 if (screen_info.vesapm_seg < 0xc000)
42635 @@ -317,9 +327,25 @@ static int __init vesafb_probe(struct platform_device *dev)
42636
42637 if (ypan || pmi_setpal) {
42638 unsigned short *pmi_base;
42639 +
42640 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
42641 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
42642 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
42643 +
42644 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42645 + pax_open_kernel();
42646 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
42647 +#else
42648 + pmi_code = pmi_base;
42649 +#endif
42650 +
42651 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
42652 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
42653 +
42654 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42655 + pmi_start = ktva_ktla(pmi_start);
42656 + pmi_pal = ktva_ktla(pmi_pal);
42657 + pax_close_kernel();
42658 +#endif
42659 +
42660 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
42661 if (pmi_base[3]) {
42662 printk(KERN_INFO "vesafb: pmi: ports = ");
42663 @@ -488,6 +514,11 @@ static int __init vesafb_probe(struct platform_device *dev)
42664 info->node, info->fix.id);
42665 return 0;
42666 err:
42667 +
42668 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
42669 + module_free_exec(NULL, pmi_code);
42670 +#endif
42671 +
42672 if (info->screen_base)
42673 iounmap(info->screen_base);
42674 framebuffer_release(info);
42675 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
42676 index 88714ae..16c2e11 100644
42677 --- a/drivers/video/via/via_clock.h
42678 +++ b/drivers/video/via/via_clock.h
42679 @@ -56,7 +56,7 @@ struct via_clock {
42680
42681 void (*set_engine_pll_state)(u8 state);
42682 void (*set_engine_pll)(struct via_pll_config config);
42683 -};
42684 +} __no_const;
42685
42686
42687 static inline u32 get_pll_internal_frequency(u32 ref_freq,
42688 diff --git a/drivers/xen/xen-pciback/conf_space.h b/drivers/xen/xen-pciback/conf_space.h
42689 index e56c934..fc22f4b 100644
42690 --- a/drivers/xen/xen-pciback/conf_space.h
42691 +++ b/drivers/xen/xen-pciback/conf_space.h
42692 @@ -44,15 +44,15 @@ struct config_field {
42693 struct {
42694 conf_dword_write write;
42695 conf_dword_read read;
42696 - } dw;
42697 + } __no_const dw;
42698 struct {
42699 conf_word_write write;
42700 conf_word_read read;
42701 - } w;
42702 + } __no_const w;
42703 struct {
42704 conf_byte_write write;
42705 conf_byte_read read;
42706 - } b;
42707 + } __no_const b;
42708 } u;
42709 struct list_head list;
42710 };
42711 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
42712 index 57ccb75..f6d05f8 100644
42713 --- a/fs/9p/vfs_inode.c
42714 +++ b/fs/9p/vfs_inode.c
42715 @@ -1303,7 +1303,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
42716 void
42717 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42718 {
42719 - char *s = nd_get_link(nd);
42720 + const char *s = nd_get_link(nd);
42721
42722 p9_debug(P9_DEBUG_VFS, " %s %s\n",
42723 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
42724 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
42725 index 0225742..1cd4732 100644
42726 --- a/fs/Kconfig.binfmt
42727 +++ b/fs/Kconfig.binfmt
42728 @@ -89,7 +89,7 @@ config HAVE_AOUT
42729
42730 config BINFMT_AOUT
42731 tristate "Kernel support for a.out and ECOFF binaries"
42732 - depends on HAVE_AOUT
42733 + depends on HAVE_AOUT && BROKEN
42734 ---help---
42735 A.out (Assembler.OUTput) is a set of formats for libraries and
42736 executables used in the earliest versions of UNIX. Linux used
42737 diff --git a/fs/aio.c b/fs/aio.c
42738 index 55c4c76..11aee6f 100644
42739 --- a/fs/aio.c
42740 +++ b/fs/aio.c
42741 @@ -118,7 +118,7 @@ static int aio_setup_ring(struct kioctx *ctx)
42742 size += sizeof(struct io_event) * nr_events;
42743 nr_pages = (size + PAGE_SIZE-1) >> PAGE_SHIFT;
42744
42745 - if (nr_pages < 0)
42746 + if (nr_pages <= 0)
42747 return -EINVAL;
42748
42749 nr_events = (PAGE_SIZE * nr_pages - sizeof(struct aio_ring)) / sizeof(struct io_event);
42750 @@ -1440,18 +1440,19 @@ static ssize_t aio_fsync(struct kiocb *iocb)
42751 static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42752 {
42753 ssize_t ret;
42754 + struct iovec iovstack;
42755
42756 #ifdef CONFIG_COMPAT
42757 if (compat)
42758 ret = compat_rw_copy_check_uvector(type,
42759 (struct compat_iovec __user *)kiocb->ki_buf,
42760 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42761 + kiocb->ki_nbytes, 1, &iovstack,
42762 &kiocb->ki_iovec);
42763 else
42764 #endif
42765 ret = rw_copy_check_uvector(type,
42766 (struct iovec __user *)kiocb->ki_buf,
42767 - kiocb->ki_nbytes, 1, &kiocb->ki_inline_vec,
42768 + kiocb->ki_nbytes, 1, &iovstack,
42769 &kiocb->ki_iovec);
42770 if (ret < 0)
42771 goto out;
42772 @@ -1460,6 +1461,10 @@ static ssize_t aio_setup_vectored_rw(int type, struct kiocb *kiocb, bool compat)
42773 if (ret < 0)
42774 goto out;
42775
42776 + if (kiocb->ki_iovec == &iovstack) {
42777 + kiocb->ki_inline_vec = iovstack;
42778 + kiocb->ki_iovec = &kiocb->ki_inline_vec;
42779 + }
42780 kiocb->ki_nr_segs = kiocb->ki_nbytes;
42781 kiocb->ki_cur_seg = 0;
42782 /* ki_nbytes/left now reflect bytes instead of segs */
42783 diff --git a/fs/attr.c b/fs/attr.c
42784 index 0da9095..1386693 100644
42785 --- a/fs/attr.c
42786 +++ b/fs/attr.c
42787 @@ -99,6 +99,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
42788 unsigned long limit;
42789
42790 limit = rlimit(RLIMIT_FSIZE);
42791 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
42792 if (limit != RLIM_INFINITY && offset > limit)
42793 goto out_sig;
42794 if (offset > inode->i_sb->s_maxbytes)
42795 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
42796 index da8876d..4456166 100644
42797 --- a/fs/autofs4/waitq.c
42798 +++ b/fs/autofs4/waitq.c
42799 @@ -61,7 +61,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
42800 {
42801 unsigned long sigpipe, flags;
42802 mm_segment_t fs;
42803 - const char *data = (const char *)addr;
42804 + const char __user *data = (const char __force_user *)addr;
42805 ssize_t wr = 0;
42806
42807 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
42808 @@ -348,6 +348,10 @@ static int validate_request(struct autofs_wait_queue **wait,
42809 return 1;
42810 }
42811
42812 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42813 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
42814 +#endif
42815 +
42816 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42817 enum autofs_notify notify)
42818 {
42819 @@ -381,7 +385,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
42820
42821 /* If this is a direct mount request create a dummy name */
42822 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
42823 +#ifdef CONFIG_GRKERNSEC_HIDESYM
42824 + /* this name does get written to userland via autofs4_write() */
42825 + qstr.len = sprintf(name, "%08lx", atomic_inc_return_unchecked(&autofs_dummy_name_id));
42826 +#else
42827 qstr.len = sprintf(name, "%p", dentry);
42828 +#endif
42829 else {
42830 qstr.len = autofs4_getpath(sbi, dentry, &name);
42831 if (!qstr.len) {
42832 diff --git a/fs/befs/linuxvfs.c b/fs/befs/linuxvfs.c
42833 index e18da23..affc30e 100644
42834 --- a/fs/befs/linuxvfs.c
42835 +++ b/fs/befs/linuxvfs.c
42836 @@ -502,7 +502,7 @@ static void befs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
42837 {
42838 befs_inode_info *befs_ino = BEFS_I(dentry->d_inode);
42839 if (befs_ino->i_flags & BEFS_LONG_SYMLINK) {
42840 - char *link = nd_get_link(nd);
42841 + const char *link = nd_get_link(nd);
42842 if (!IS_ERR(link))
42843 kfree(link);
42844 }
42845 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
42846 index d146e18..12d1bd1 100644
42847 --- a/fs/binfmt_aout.c
42848 +++ b/fs/binfmt_aout.c
42849 @@ -16,6 +16,7 @@
42850 #include <linux/string.h>
42851 #include <linux/fs.h>
42852 #include <linux/file.h>
42853 +#include <linux/security.h>
42854 #include <linux/stat.h>
42855 #include <linux/fcntl.h>
42856 #include <linux/ptrace.h>
42857 @@ -83,6 +84,8 @@ static int aout_core_dump(struct coredump_params *cprm)
42858 #endif
42859 # define START_STACK(u) ((void __user *)u.start_stack)
42860
42861 + memset(&dump, 0, sizeof(dump));
42862 +
42863 fs = get_fs();
42864 set_fs(KERNEL_DS);
42865 has_dumped = 1;
42866 @@ -94,10 +97,12 @@ static int aout_core_dump(struct coredump_params *cprm)
42867
42868 /* If the size of the dump file exceeds the rlimit, then see what would happen
42869 if we wrote the stack, but not the data area. */
42870 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
42871 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
42872 dump.u_dsize = 0;
42873
42874 /* Make sure we have enough room to write the stack and data areas. */
42875 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
42876 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
42877 dump.u_ssize = 0;
42878
42879 @@ -231,6 +236,8 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42880 rlim = rlimit(RLIMIT_DATA);
42881 if (rlim >= RLIM_INFINITY)
42882 rlim = ~0;
42883 +
42884 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
42885 if (ex.a_data + ex.a_bss > rlim)
42886 return -ENOMEM;
42887
42888 @@ -265,6 +272,27 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42889
42890 install_exec_creds(bprm);
42891
42892 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
42893 + current->mm->pax_flags = 0UL;
42894 +#endif
42895 +
42896 +#ifdef CONFIG_PAX_PAGEEXEC
42897 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
42898 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
42899 +
42900 +#ifdef CONFIG_PAX_EMUTRAMP
42901 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
42902 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
42903 +#endif
42904 +
42905 +#ifdef CONFIG_PAX_MPROTECT
42906 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
42907 + current->mm->pax_flags |= MF_PAX_MPROTECT;
42908 +#endif
42909 +
42910 + }
42911 +#endif
42912 +
42913 if (N_MAGIC(ex) == OMAGIC) {
42914 unsigned long text_addr, map_size;
42915 loff_t pos;
42916 @@ -330,7 +358,7 @@ static int load_aout_binary(struct linux_binprm * bprm, struct pt_regs * regs)
42917 }
42918
42919 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
42920 - PROT_READ | PROT_WRITE | PROT_EXEC,
42921 + PROT_READ | PROT_WRITE,
42922 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
42923 fd_offset + ex.a_text);
42924 if (error != N_DATADDR(ex)) {
42925 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
42926 index 1b52956..725eca7 100644
42927 --- a/fs/binfmt_elf.c
42928 +++ b/fs/binfmt_elf.c
42929 @@ -32,6 +32,7 @@
42930 #include <linux/elf.h>
42931 #include <linux/utsname.h>
42932 #include <linux/coredump.h>
42933 +#include <linux/xattr.h>
42934 #include <asm/uaccess.h>
42935 #include <asm/param.h>
42936 #include <asm/page.h>
42937 @@ -52,6 +53,10 @@ static int elf_core_dump(struct coredump_params *cprm);
42938 #define elf_core_dump NULL
42939 #endif
42940
42941 +#ifdef CONFIG_PAX_MPROTECT
42942 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
42943 +#endif
42944 +
42945 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
42946 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
42947 #else
42948 @@ -71,6 +76,11 @@ static struct linux_binfmt elf_format = {
42949 .load_binary = load_elf_binary,
42950 .load_shlib = load_elf_library,
42951 .core_dump = elf_core_dump,
42952 +
42953 +#ifdef CONFIG_PAX_MPROTECT
42954 + .handle_mprotect= elf_handle_mprotect,
42955 +#endif
42956 +
42957 .min_coredump = ELF_EXEC_PAGESIZE,
42958 };
42959
42960 @@ -78,6 +88,8 @@ static struct linux_binfmt elf_format = {
42961
42962 static int set_brk(unsigned long start, unsigned long end)
42963 {
42964 + unsigned long e = end;
42965 +
42966 start = ELF_PAGEALIGN(start);
42967 end = ELF_PAGEALIGN(end);
42968 if (end > start) {
42969 @@ -86,7 +98,7 @@ static int set_brk(unsigned long start, unsigned long end)
42970 if (BAD_ADDR(addr))
42971 return addr;
42972 }
42973 - current->mm->start_brk = current->mm->brk = end;
42974 + current->mm->start_brk = current->mm->brk = e;
42975 return 0;
42976 }
42977
42978 @@ -147,12 +159,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42979 elf_addr_t __user *u_rand_bytes;
42980 const char *k_platform = ELF_PLATFORM;
42981 const char *k_base_platform = ELF_BASE_PLATFORM;
42982 - unsigned char k_rand_bytes[16];
42983 + u32 k_rand_bytes[4];
42984 int items;
42985 elf_addr_t *elf_info;
42986 int ei_index = 0;
42987 const struct cred *cred = current_cred();
42988 struct vm_area_struct *vma;
42989 + unsigned long saved_auxv[AT_VECTOR_SIZE];
42990
42991 /*
42992 * In some cases (e.g. Hyper-Threading), we want to avoid L1
42993 @@ -194,8 +207,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
42994 * Generate 16 random bytes for userspace PRNG seeding.
42995 */
42996 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
42997 - u_rand_bytes = (elf_addr_t __user *)
42998 - STACK_ALLOC(p, sizeof(k_rand_bytes));
42999 + srandom32(k_rand_bytes[0] ^ random32());
43000 + srandom32(k_rand_bytes[1] ^ random32());
43001 + srandom32(k_rand_bytes[2] ^ random32());
43002 + srandom32(k_rand_bytes[3] ^ random32());
43003 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
43004 + u_rand_bytes = (elf_addr_t __user *) p;
43005 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
43006 return -EFAULT;
43007
43008 @@ -307,9 +324,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
43009 return -EFAULT;
43010 current->mm->env_end = p;
43011
43012 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
43013 +
43014 /* Put the elf_info on the stack in the right place. */
43015 sp = (elf_addr_t __user *)envp + 1;
43016 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
43017 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
43018 return -EFAULT;
43019 return 0;
43020 }
43021 @@ -378,10 +397,10 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43022 {
43023 struct elf_phdr *elf_phdata;
43024 struct elf_phdr *eppnt;
43025 - unsigned long load_addr = 0;
43026 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
43027 int load_addr_set = 0;
43028 unsigned long last_bss = 0, elf_bss = 0;
43029 - unsigned long error = ~0UL;
43030 + unsigned long error = -EINVAL;
43031 unsigned long total_size;
43032 int retval, i, size;
43033
43034 @@ -427,6 +446,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43035 goto out_close;
43036 }
43037
43038 +#ifdef CONFIG_PAX_SEGMEXEC
43039 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
43040 + pax_task_size = SEGMEXEC_TASK_SIZE;
43041 +#endif
43042 +
43043 eppnt = elf_phdata;
43044 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
43045 if (eppnt->p_type == PT_LOAD) {
43046 @@ -470,8 +494,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
43047 k = load_addr + eppnt->p_vaddr;
43048 if (BAD_ADDR(k) ||
43049 eppnt->p_filesz > eppnt->p_memsz ||
43050 - eppnt->p_memsz > TASK_SIZE ||
43051 - TASK_SIZE - eppnt->p_memsz < k) {
43052 + eppnt->p_memsz > pax_task_size ||
43053 + pax_task_size - eppnt->p_memsz < k) {
43054 error = -ENOMEM;
43055 goto out_close;
43056 }
43057 @@ -523,6 +547,311 @@ out:
43058 return error;
43059 }
43060
43061 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43062 +#ifdef CONFIG_PAX_SOFTMODE
43063 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
43064 +{
43065 + unsigned long pax_flags = 0UL;
43066 +
43067 +#ifdef CONFIG_PAX_PAGEEXEC
43068 + if (elf_phdata->p_flags & PF_PAGEEXEC)
43069 + pax_flags |= MF_PAX_PAGEEXEC;
43070 +#endif
43071 +
43072 +#ifdef CONFIG_PAX_SEGMEXEC
43073 + if (elf_phdata->p_flags & PF_SEGMEXEC)
43074 + pax_flags |= MF_PAX_SEGMEXEC;
43075 +#endif
43076 +
43077 +#ifdef CONFIG_PAX_EMUTRAMP
43078 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
43079 + pax_flags |= MF_PAX_EMUTRAMP;
43080 +#endif
43081 +
43082 +#ifdef CONFIG_PAX_MPROTECT
43083 + if (elf_phdata->p_flags & PF_MPROTECT)
43084 + pax_flags |= MF_PAX_MPROTECT;
43085 +#endif
43086 +
43087 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43088 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
43089 + pax_flags |= MF_PAX_RANDMMAP;
43090 +#endif
43091 +
43092 + return pax_flags;
43093 +}
43094 +#endif
43095 +
43096 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
43097 +{
43098 + unsigned long pax_flags = 0UL;
43099 +
43100 +#ifdef CONFIG_PAX_PAGEEXEC
43101 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
43102 + pax_flags |= MF_PAX_PAGEEXEC;
43103 +#endif
43104 +
43105 +#ifdef CONFIG_PAX_SEGMEXEC
43106 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
43107 + pax_flags |= MF_PAX_SEGMEXEC;
43108 +#endif
43109 +
43110 +#ifdef CONFIG_PAX_EMUTRAMP
43111 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
43112 + pax_flags |= MF_PAX_EMUTRAMP;
43113 +#endif
43114 +
43115 +#ifdef CONFIG_PAX_MPROTECT
43116 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
43117 + pax_flags |= MF_PAX_MPROTECT;
43118 +#endif
43119 +
43120 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43121 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
43122 + pax_flags |= MF_PAX_RANDMMAP;
43123 +#endif
43124 +
43125 + return pax_flags;
43126 +}
43127 +#endif
43128 +
43129 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43130 +#ifdef CONFIG_PAX_SOFTMODE
43131 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
43132 +{
43133 + unsigned long pax_flags = 0UL;
43134 +
43135 +#ifdef CONFIG_PAX_PAGEEXEC
43136 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
43137 + pax_flags |= MF_PAX_PAGEEXEC;
43138 +#endif
43139 +
43140 +#ifdef CONFIG_PAX_SEGMEXEC
43141 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
43142 + pax_flags |= MF_PAX_SEGMEXEC;
43143 +#endif
43144 +
43145 +#ifdef CONFIG_PAX_EMUTRAMP
43146 + if (pax_flags_softmode & MF_PAX_EMUTRAMP)
43147 + pax_flags |= MF_PAX_EMUTRAMP;
43148 +#endif
43149 +
43150 +#ifdef CONFIG_PAX_MPROTECT
43151 + if (pax_flags_softmode & MF_PAX_MPROTECT)
43152 + pax_flags |= MF_PAX_MPROTECT;
43153 +#endif
43154 +
43155 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43156 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
43157 + pax_flags |= MF_PAX_RANDMMAP;
43158 +#endif
43159 +
43160 + return pax_flags;
43161 +}
43162 +#endif
43163 +
43164 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
43165 +{
43166 + unsigned long pax_flags = 0UL;
43167 +
43168 +#ifdef CONFIG_PAX_PAGEEXEC
43169 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
43170 + pax_flags |= MF_PAX_PAGEEXEC;
43171 +#endif
43172 +
43173 +#ifdef CONFIG_PAX_SEGMEXEC
43174 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
43175 + pax_flags |= MF_PAX_SEGMEXEC;
43176 +#endif
43177 +
43178 +#ifdef CONFIG_PAX_EMUTRAMP
43179 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
43180 + pax_flags |= MF_PAX_EMUTRAMP;
43181 +#endif
43182 +
43183 +#ifdef CONFIG_PAX_MPROTECT
43184 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
43185 + pax_flags |= MF_PAX_MPROTECT;
43186 +#endif
43187 +
43188 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
43189 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
43190 + pax_flags |= MF_PAX_RANDMMAP;
43191 +#endif
43192 +
43193 + return pax_flags;
43194 +}
43195 +#endif
43196 +
43197 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43198 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
43199 +{
43200 + unsigned long pax_flags = 0UL;
43201 +
43202 +#ifdef CONFIG_PAX_EI_PAX
43203 +
43204 +#ifdef CONFIG_PAX_PAGEEXEC
43205 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
43206 + pax_flags |= MF_PAX_PAGEEXEC;
43207 +#endif
43208 +
43209 +#ifdef CONFIG_PAX_SEGMEXEC
43210 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
43211 + pax_flags |= MF_PAX_SEGMEXEC;
43212 +#endif
43213 +
43214 +#ifdef CONFIG_PAX_EMUTRAMP
43215 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
43216 + pax_flags |= MF_PAX_EMUTRAMP;
43217 +#endif
43218 +
43219 +#ifdef CONFIG_PAX_MPROTECT
43220 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
43221 + pax_flags |= MF_PAX_MPROTECT;
43222 +#endif
43223 +
43224 +#ifdef CONFIG_PAX_ASLR
43225 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
43226 + pax_flags |= MF_PAX_RANDMMAP;
43227 +#endif
43228 +
43229 +#else
43230 +
43231 +#ifdef CONFIG_PAX_PAGEEXEC
43232 + pax_flags |= MF_PAX_PAGEEXEC;
43233 +#endif
43234 +
43235 +#ifdef CONFIG_PAX_SEGMEXEC
43236 + pax_flags |= MF_PAX_SEGMEXEC;
43237 +#endif
43238 +
43239 +#ifdef CONFIG_PAX_MPROTECT
43240 + pax_flags |= MF_PAX_MPROTECT;
43241 +#endif
43242 +
43243 +#ifdef CONFIG_PAX_RANDMMAP
43244 + if (randomize_va_space)
43245 + pax_flags |= MF_PAX_RANDMMAP;
43246 +#endif
43247 +
43248 +#endif
43249 +
43250 + return pax_flags;
43251 +}
43252 +
43253 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
43254 +{
43255 +
43256 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
43257 + unsigned long i;
43258 +
43259 + for (i = 0UL; i < elf_ex->e_phnum; i++)
43260 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
43261 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
43262 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
43263 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
43264 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
43265 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
43266 + return ~0UL;
43267 +
43268 +#ifdef CONFIG_PAX_SOFTMODE
43269 + if (pax_softmode)
43270 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
43271 + else
43272 +#endif
43273 +
43274 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
43275 + break;
43276 + }
43277 +#endif
43278 +
43279 + return ~0UL;
43280 +}
43281 +
43282 +static unsigned long pax_parse_xattr_pax(struct file * const file)
43283 +{
43284 +
43285 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
43286 + ssize_t xattr_size, i;
43287 + unsigned char xattr_value[5];
43288 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
43289 +
43290 + xattr_size = vfs_getxattr(file->f_path.dentry, XATTR_NAME_PAX_FLAGS, xattr_value, sizeof xattr_value);
43291 + if (xattr_size <= 0)
43292 + return ~0UL;
43293 +
43294 + for (i = 0; i < xattr_size; i++)
43295 + switch (xattr_value[i]) {
43296 + default:
43297 + return ~0UL;
43298 +
43299 +#define parse_flag(option1, option2, flag) \
43300 + case option1: \
43301 + pax_flags_hardmode |= MF_PAX_##flag; \
43302 + break; \
43303 + case option2: \
43304 + pax_flags_softmode |= MF_PAX_##flag; \
43305 + break;
43306 +
43307 + parse_flag('p', 'P', PAGEEXEC);
43308 + parse_flag('e', 'E', EMUTRAMP);
43309 + parse_flag('m', 'M', MPROTECT);
43310 + parse_flag('r', 'R', RANDMMAP);
43311 + parse_flag('s', 'S', SEGMEXEC);
43312 +
43313 +#undef parse_flag
43314 + }
43315 +
43316 + if (pax_flags_hardmode & pax_flags_softmode)
43317 + return ~0UL;
43318 +
43319 +#ifdef CONFIG_PAX_SOFTMODE
43320 + if (pax_softmode)
43321 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
43322 + else
43323 +#endif
43324 +
43325 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
43326 +#else
43327 + return ~0UL;
43328 +#endif
43329 +
43330 +}
43331 +
43332 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
43333 +{
43334 + unsigned long pax_flags, pt_pax_flags, xattr_pax_flags;
43335 +
43336 + pax_flags = pax_parse_ei_pax(elf_ex);
43337 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
43338 + xattr_pax_flags = pax_parse_xattr_pax(file);
43339 +
43340 + if (pt_pax_flags == ~0UL)
43341 + pt_pax_flags = xattr_pax_flags;
43342 + else if (xattr_pax_flags == ~0UL)
43343 + xattr_pax_flags = pt_pax_flags;
43344 + if (pt_pax_flags != xattr_pax_flags)
43345 + return -EINVAL;
43346 + if (pt_pax_flags != ~0UL)
43347 + pax_flags = pt_pax_flags;
43348 +
43349 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
43350 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43351 + if ((__supported_pte_mask & _PAGE_NX))
43352 + pax_flags &= ~MF_PAX_SEGMEXEC;
43353 + else
43354 + pax_flags &= ~MF_PAX_PAGEEXEC;
43355 + }
43356 +#endif
43357 +
43358 + if (0 > pax_check_flags(&pax_flags))
43359 + return -EINVAL;
43360 +
43361 + current->mm->pax_flags = pax_flags;
43362 + return 0;
43363 +}
43364 +#endif
43365 +
43366 /*
43367 * These are the functions used to load ELF style executables and shared
43368 * libraries. There is no binary dependent code anywhere else.
43369 @@ -539,6 +868,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
43370 {
43371 unsigned int random_variable = 0;
43372
43373 +#ifdef CONFIG_PAX_RANDUSTACK
43374 + if (randomize_va_space)
43375 + return stack_top - current->mm->delta_stack;
43376 +#endif
43377 +
43378 if ((current->flags & PF_RANDOMIZE) &&
43379 !(current->personality & ADDR_NO_RANDOMIZE)) {
43380 random_variable = get_random_int() & STACK_RND_MASK;
43381 @@ -557,7 +891,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43382 unsigned long load_addr = 0, load_bias = 0;
43383 int load_addr_set = 0;
43384 char * elf_interpreter = NULL;
43385 - unsigned long error;
43386 + unsigned long error = 0;
43387 struct elf_phdr *elf_ppnt, *elf_phdata;
43388 unsigned long elf_bss, elf_brk;
43389 int retval, i;
43390 @@ -567,11 +901,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43391 unsigned long start_code, end_code, start_data, end_data;
43392 unsigned long reloc_func_desc __maybe_unused = 0;
43393 int executable_stack = EXSTACK_DEFAULT;
43394 - unsigned long def_flags = 0;
43395 struct {
43396 struct elfhdr elf_ex;
43397 struct elfhdr interp_elf_ex;
43398 } *loc;
43399 + unsigned long pax_task_size = TASK_SIZE;
43400
43401 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
43402 if (!loc) {
43403 @@ -707,11 +1041,81 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43404 goto out_free_dentry;
43405
43406 /* OK, This is the point of no return */
43407 - current->mm->def_flags = def_flags;
43408 +
43409 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43410 + current->mm->pax_flags = 0UL;
43411 +#endif
43412 +
43413 +#ifdef CONFIG_PAX_DLRESOLVE
43414 + current->mm->call_dl_resolve = 0UL;
43415 +#endif
43416 +
43417 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
43418 + current->mm->call_syscall = 0UL;
43419 +#endif
43420 +
43421 +#ifdef CONFIG_PAX_ASLR
43422 + current->mm->delta_mmap = 0UL;
43423 + current->mm->delta_stack = 0UL;
43424 +#endif
43425 +
43426 + current->mm->def_flags = 0;
43427 +
43428 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
43429 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
43430 + send_sig(SIGKILL, current, 0);
43431 + goto out_free_dentry;
43432 + }
43433 +#endif
43434 +
43435 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
43436 + pax_set_initial_flags(bprm);
43437 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
43438 + if (pax_set_initial_flags_func)
43439 + (pax_set_initial_flags_func)(bprm);
43440 +#endif
43441 +
43442 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
43443 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
43444 + current->mm->context.user_cs_limit = PAGE_SIZE;
43445 + current->mm->def_flags |= VM_PAGEEXEC;
43446 + }
43447 +#endif
43448 +
43449 +#ifdef CONFIG_PAX_SEGMEXEC
43450 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
43451 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
43452 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
43453 + pax_task_size = SEGMEXEC_TASK_SIZE;
43454 + current->mm->def_flags |= VM_NOHUGEPAGE;
43455 + }
43456 +#endif
43457 +
43458 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
43459 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43460 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
43461 + put_cpu();
43462 + }
43463 +#endif
43464
43465 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
43466 may depend on the personality. */
43467 SET_PERSONALITY(loc->elf_ex);
43468 +
43469 +#ifdef CONFIG_PAX_ASLR
43470 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43471 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
43472 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
43473 + }
43474 +#endif
43475 +
43476 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
43477 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
43478 + executable_stack = EXSTACK_DISABLE_X;
43479 + current->personality &= ~READ_IMPLIES_EXEC;
43480 + } else
43481 +#endif
43482 +
43483 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
43484 current->personality |= READ_IMPLIES_EXEC;
43485
43486 @@ -802,6 +1206,20 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43487 #else
43488 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
43489 #endif
43490 +
43491 +#ifdef CONFIG_PAX_RANDMMAP
43492 + /* PaX: randomize base address at the default exe base if requested */
43493 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
43494 +#ifdef CONFIG_SPARC64
43495 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
43496 +#else
43497 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
43498 +#endif
43499 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
43500 + elf_flags |= MAP_FIXED;
43501 + }
43502 +#endif
43503 +
43504 }
43505
43506 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
43507 @@ -834,9 +1252,9 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43508 * allowed task size. Note that p_filesz must always be
43509 * <= p_memsz so it is only necessary to check p_memsz.
43510 */
43511 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43512 - elf_ppnt->p_memsz > TASK_SIZE ||
43513 - TASK_SIZE - elf_ppnt->p_memsz < k) {
43514 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
43515 + elf_ppnt->p_memsz > pax_task_size ||
43516 + pax_task_size - elf_ppnt->p_memsz < k) {
43517 /* set_brk can never work. Avoid overflows. */
43518 send_sig(SIGKILL, current, 0);
43519 retval = -EINVAL;
43520 @@ -875,11 +1293,41 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs)
43521 goto out_free_dentry;
43522 }
43523 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
43524 - send_sig(SIGSEGV, current, 0);
43525 - retval = -EFAULT; /* Nobody gets to see this, but.. */
43526 - goto out_free_dentry;
43527 + /*
43528 + * This bss-zeroing can fail if the ELF
43529 + * file specifies odd protections. So
43530 + * we don't check the return value
43531 + */
43532 }
43533
43534 +#ifdef CONFIG_PAX_RANDMMAP
43535 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
43536 + unsigned long start, size;
43537 +
43538 + start = ELF_PAGEALIGN(elf_brk);
43539 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
43540 + down_read(&current->mm->mmap_sem);
43541 + retval = -ENOMEM;
43542 + if (!find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
43543 + unsigned long prot = PROT_NONE;
43544 +
43545 + up_read(&current->mm->mmap_sem);
43546 + current->mm->brk_gap = PAGE_ALIGN(size) >> PAGE_SHIFT;
43547 +// if (current->personality & ADDR_NO_RANDOMIZE)
43548 +// prot = PROT_READ;
43549 + start = vm_mmap(NULL, start, size, prot, MAP_ANONYMOUS | MAP_FIXED | MAP_PRIVATE, 0);
43550 + retval = IS_ERR_VALUE(start) ? start : 0;
43551 + } else
43552 + up_read(&current->mm->mmap_sem);
43553 + if (retval == 0)
43554 + retval = set_brk(start + size, start + size + PAGE_SIZE);
43555 + if (retval < 0) {
43556 + send_sig(SIGKILL, current, 0);
43557 + goto out_free_dentry;
43558 + }
43559 + }
43560 +#endif
43561 +
43562 if (elf_interpreter) {
43563 unsigned long uninitialized_var(interp_map_addr);
43564
43565 @@ -1107,7 +1555,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
43566 * Decide what to dump of a segment, part, all or none.
43567 */
43568 static unsigned long vma_dump_size(struct vm_area_struct *vma,
43569 - unsigned long mm_flags)
43570 + unsigned long mm_flags, long signr)
43571 {
43572 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
43573
43574 @@ -1144,7 +1592,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
43575 if (vma->vm_file == NULL)
43576 return 0;
43577
43578 - if (FILTER(MAPPED_PRIVATE))
43579 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
43580 goto whole;
43581
43582 /*
43583 @@ -1366,9 +1814,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
43584 {
43585 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
43586 int i = 0;
43587 - do
43588 + do {
43589 i += 2;
43590 - while (auxv[i - 2] != AT_NULL);
43591 + } while (auxv[i - 2] != AT_NULL);
43592 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
43593 }
43594
43595 @@ -1890,14 +2338,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
43596 }
43597
43598 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
43599 - unsigned long mm_flags)
43600 + struct coredump_params *cprm)
43601 {
43602 struct vm_area_struct *vma;
43603 size_t size = 0;
43604
43605 for (vma = first_vma(current, gate_vma); vma != NULL;
43606 vma = next_vma(vma, gate_vma))
43607 - size += vma_dump_size(vma, mm_flags);
43608 + size += vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43609 return size;
43610 }
43611
43612 @@ -1991,7 +2439,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43613
43614 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
43615
43616 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
43617 + offset += elf_core_vma_data_size(gate_vma, cprm);
43618 offset += elf_core_extra_data_size();
43619 e_shoff = offset;
43620
43621 @@ -2005,10 +2453,12 @@ static int elf_core_dump(struct coredump_params *cprm)
43622 offset = dataoff;
43623
43624 size += sizeof(*elf);
43625 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43626 if (size > cprm->limit || !dump_write(cprm->file, elf, sizeof(*elf)))
43627 goto end_coredump;
43628
43629 size += sizeof(*phdr4note);
43630 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43631 if (size > cprm->limit
43632 || !dump_write(cprm->file, phdr4note, sizeof(*phdr4note)))
43633 goto end_coredump;
43634 @@ -2022,7 +2472,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43635 phdr.p_offset = offset;
43636 phdr.p_vaddr = vma->vm_start;
43637 phdr.p_paddr = 0;
43638 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
43639 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43640 phdr.p_memsz = vma->vm_end - vma->vm_start;
43641 offset += phdr.p_filesz;
43642 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
43643 @@ -2033,6 +2483,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43644 phdr.p_align = ELF_EXEC_PAGESIZE;
43645
43646 size += sizeof(phdr);
43647 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43648 if (size > cprm->limit
43649 || !dump_write(cprm->file, &phdr, sizeof(phdr)))
43650 goto end_coredump;
43651 @@ -2057,7 +2508,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43652 unsigned long addr;
43653 unsigned long end;
43654
43655 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
43656 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->signr);
43657
43658 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
43659 struct page *page;
43660 @@ -2066,6 +2517,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43661 page = get_dump_page(addr);
43662 if (page) {
43663 void *kaddr = kmap(page);
43664 + gr_learn_resource(current, RLIMIT_CORE, size + PAGE_SIZE, 1);
43665 stop = ((size += PAGE_SIZE) > cprm->limit) ||
43666 !dump_write(cprm->file, kaddr,
43667 PAGE_SIZE);
43668 @@ -2083,6 +2535,7 @@ static int elf_core_dump(struct coredump_params *cprm)
43669
43670 if (e_phnum == PN_XNUM) {
43671 size += sizeof(*shdr4extnum);
43672 + gr_learn_resource(current, RLIMIT_CORE, size, 1);
43673 if (size > cprm->limit
43674 || !dump_write(cprm->file, shdr4extnum,
43675 sizeof(*shdr4extnum)))
43676 @@ -2103,6 +2556,97 @@ out:
43677
43678 #endif /* CONFIG_ELF_CORE */
43679
43680 +#ifdef CONFIG_PAX_MPROTECT
43681 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
43682 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
43683 + * we'll remove VM_MAYWRITE for good on RELRO segments.
43684 + *
43685 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
43686 + * basis because we want to allow the common case and not the special ones.
43687 + */
43688 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
43689 +{
43690 + struct elfhdr elf_h;
43691 + struct elf_phdr elf_p;
43692 + unsigned long i;
43693 + unsigned long oldflags;
43694 + bool is_textrel_rw, is_textrel_rx, is_relro;
43695 +
43696 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT))
43697 + return;
43698 +
43699 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
43700 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
43701 +
43702 +#ifdef CONFIG_PAX_ELFRELOCS
43703 + /* possible TEXTREL */
43704 + is_textrel_rw = vma->vm_file && !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
43705 + 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);
43706 +#else
43707 + is_textrel_rw = false;
43708 + is_textrel_rx = false;
43709 +#endif
43710 +
43711 + /* possible RELRO */
43712 + is_relro = vma->vm_file && vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
43713 +
43714 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
43715 + return;
43716 +
43717 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
43718 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
43719 +
43720 +#ifdef CONFIG_PAX_ETEXECRELOCS
43721 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43722 +#else
43723 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
43724 +#endif
43725 +
43726 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
43727 + !elf_check_arch(&elf_h) ||
43728 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
43729 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
43730 + return;
43731 +
43732 + for (i = 0UL; i < elf_h.e_phnum; i++) {
43733 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
43734 + return;
43735 + switch (elf_p.p_type) {
43736 + case PT_DYNAMIC:
43737 + if (!is_textrel_rw && !is_textrel_rx)
43738 + continue;
43739 + i = 0UL;
43740 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
43741 + elf_dyn dyn;
43742 +
43743 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
43744 + return;
43745 + if (dyn.d_tag == DT_NULL)
43746 + return;
43747 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
43748 + gr_log_textrel(vma);
43749 + if (is_textrel_rw)
43750 + vma->vm_flags |= VM_MAYWRITE;
43751 + else
43752 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
43753 + vma->vm_flags &= ~VM_MAYWRITE;
43754 + return;
43755 + }
43756 + i++;
43757 + }
43758 + return;
43759 +
43760 + case PT_GNU_RELRO:
43761 + if (!is_relro)
43762 + continue;
43763 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
43764 + vma->vm_flags &= ~VM_MAYWRITE;
43765 + return;
43766 + }
43767 + }
43768 +}
43769 +#endif
43770 +
43771 static int __init init_elf_binfmt(void)
43772 {
43773 register_binfmt(&elf_format);
43774 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
43775 index 178cb70..8972997 100644
43776 --- a/fs/binfmt_flat.c
43777 +++ b/fs/binfmt_flat.c
43778 @@ -562,7 +562,9 @@ static int load_flat_file(struct linux_binprm * bprm,
43779 realdatastart = (unsigned long) -ENOMEM;
43780 printk("Unable to allocate RAM for process data, errno %d\n",
43781 (int)-realdatastart);
43782 + down_write(&current->mm->mmap_sem);
43783 vm_munmap(textpos, text_len);
43784 + up_write(&current->mm->mmap_sem);
43785 ret = realdatastart;
43786 goto err;
43787 }
43788 @@ -586,8 +588,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43789 }
43790 if (IS_ERR_VALUE(result)) {
43791 printk("Unable to read data+bss, errno %d\n", (int)-result);
43792 + down_write(&current->mm->mmap_sem);
43793 vm_munmap(textpos, text_len);
43794 vm_munmap(realdatastart, len);
43795 + up_write(&current->mm->mmap_sem);
43796 ret = result;
43797 goto err;
43798 }
43799 @@ -654,8 +658,10 @@ static int load_flat_file(struct linux_binprm * bprm,
43800 }
43801 if (IS_ERR_VALUE(result)) {
43802 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
43803 + down_write(&current->mm->mmap_sem);
43804 vm_munmap(textpos, text_len + data_len + extra +
43805 MAX_SHARED_LIBS * sizeof(unsigned long));
43806 + up_write(&current->mm->mmap_sem);
43807 ret = result;
43808 goto err;
43809 }
43810 diff --git a/fs/bio.c b/fs/bio.c
43811 index 73922ab..16642dd 100644
43812 --- a/fs/bio.c
43813 +++ b/fs/bio.c
43814 @@ -841,7 +841,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
43815 /*
43816 * Overflow, abort
43817 */
43818 - if (end < start)
43819 + if (end < start || end - start > INT_MAX - nr_pages)
43820 return ERR_PTR(-EINVAL);
43821
43822 nr_pages += end - start;
43823 @@ -975,7 +975,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
43824 /*
43825 * Overflow, abort
43826 */
43827 - if (end < start)
43828 + if (end < start || end - start > INT_MAX - nr_pages)
43829 return ERR_PTR(-EINVAL);
43830
43831 nr_pages += end - start;
43832 @@ -1237,7 +1237,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
43833 const int read = bio_data_dir(bio) == READ;
43834 struct bio_map_data *bmd = bio->bi_private;
43835 int i;
43836 - char *p = bmd->sgvecs[0].iov_base;
43837 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
43838
43839 __bio_for_each_segment(bvec, bio, i, 0) {
43840 char *addr = page_address(bvec->bv_page);
43841 diff --git a/fs/block_dev.c b/fs/block_dev.c
43842 index c2bbe1f..9dfbc23 100644
43843 --- a/fs/block_dev.c
43844 +++ b/fs/block_dev.c
43845 @@ -704,7 +704,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
43846 else if (bdev->bd_contains == bdev)
43847 return true; /* is a whole device which isn't held */
43848
43849 - else if (whole->bd_holder == bd_may_claim)
43850 + else if (whole->bd_holder == (void *)bd_may_claim)
43851 return true; /* is a partition of a device that is being partitioned */
43852 else if (whole->bd_holder != NULL)
43853 return false; /* is a partition of a held device */
43854 diff --git a/fs/btrfs/check-integrity.c b/fs/btrfs/check-integrity.c
43855 index da6e936..1598dd0 100644
43856 --- a/fs/btrfs/check-integrity.c
43857 +++ b/fs/btrfs/check-integrity.c
43858 @@ -155,7 +155,7 @@ struct btrfsic_block {
43859 union {
43860 bio_end_io_t *bio;
43861 bh_end_io_t *bh;
43862 - } orig_bio_bh_end_io;
43863 + } __no_const orig_bio_bh_end_io;
43864 int submit_bio_bh_rw;
43865 u64 flush_gen; /* only valid if !never_written */
43866 };
43867 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
43868 index 8206b39..06d5654 100644
43869 --- a/fs/btrfs/ctree.c
43870 +++ b/fs/btrfs/ctree.c
43871 @@ -973,9 +973,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
43872 free_extent_buffer(buf);
43873 add_root_to_dirty_list(root);
43874 } else {
43875 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
43876 - parent_start = parent->start;
43877 - else
43878 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
43879 + if (parent)
43880 + parent_start = parent->start;
43881 + else
43882 + parent_start = 0;
43883 + } else
43884 parent_start = 0;
43885
43886 WARN_ON(trans->transid != btrfs_header_generation(parent));
43887 diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c
43888 index a7d1921..a32dba2 100644
43889 --- a/fs/btrfs/inode.c
43890 +++ b/fs/btrfs/inode.c
43891 @@ -7111,7 +7111,7 @@ fail:
43892 return -ENOMEM;
43893 }
43894
43895 -static int btrfs_getattr(struct vfsmount *mnt,
43896 +int btrfs_getattr(struct vfsmount *mnt,
43897 struct dentry *dentry, struct kstat *stat)
43898 {
43899 struct inode *inode = dentry->d_inode;
43900 @@ -7125,6 +7125,14 @@ static int btrfs_getattr(struct vfsmount *mnt,
43901 return 0;
43902 }
43903
43904 +EXPORT_SYMBOL(btrfs_getattr);
43905 +
43906 +dev_t get_btrfs_dev_from_inode(struct inode *inode)
43907 +{
43908 + return BTRFS_I(inode)->root->anon_dev;
43909 +}
43910 +EXPORT_SYMBOL(get_btrfs_dev_from_inode);
43911 +
43912 /*
43913 * If a file is moved, it will inherit the cow and compression flags of the new
43914 * directory.
43915 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
43916 index 0e92e57..8b560de 100644
43917 --- a/fs/btrfs/ioctl.c
43918 +++ b/fs/btrfs/ioctl.c
43919 @@ -2902,9 +2902,12 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43920 for (i = 0; i < num_types; i++) {
43921 struct btrfs_space_info *tmp;
43922
43923 + /* Don't copy in more than we allocated */
43924 if (!slot_count)
43925 break;
43926
43927 + slot_count--;
43928 +
43929 info = NULL;
43930 rcu_read_lock();
43931 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
43932 @@ -2926,10 +2929,7 @@ long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
43933 memcpy(dest, &space, sizeof(space));
43934 dest++;
43935 space_args.total_spaces++;
43936 - slot_count--;
43937 }
43938 - if (!slot_count)
43939 - break;
43940 }
43941 up_read(&info->groups_sem);
43942 }
43943 diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c
43944 index 646ee21..f020f87 100644
43945 --- a/fs/btrfs/relocation.c
43946 +++ b/fs/btrfs/relocation.c
43947 @@ -1268,7 +1268,7 @@ static int __update_reloc_root(struct btrfs_root *root, int del)
43948 }
43949 spin_unlock(&rc->reloc_root_tree.lock);
43950
43951 - BUG_ON((struct btrfs_root *)node->data != root);
43952 + BUG_ON(!node || (struct btrfs_root *)node->data != root);
43953
43954 if (!del) {
43955 spin_lock(&rc->reloc_root_tree.lock);
43956 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
43957 index 622f469..e8d2d55 100644
43958 --- a/fs/cachefiles/bind.c
43959 +++ b/fs/cachefiles/bind.c
43960 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
43961 args);
43962
43963 /* start by checking things over */
43964 - ASSERT(cache->fstop_percent >= 0 &&
43965 - cache->fstop_percent < cache->fcull_percent &&
43966 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
43967 cache->fcull_percent < cache->frun_percent &&
43968 cache->frun_percent < 100);
43969
43970 - ASSERT(cache->bstop_percent >= 0 &&
43971 - cache->bstop_percent < cache->bcull_percent &&
43972 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
43973 cache->bcull_percent < cache->brun_percent &&
43974 cache->brun_percent < 100);
43975
43976 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
43977 index 0a1467b..6a53245 100644
43978 --- a/fs/cachefiles/daemon.c
43979 +++ b/fs/cachefiles/daemon.c
43980 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
43981 if (n > buflen)
43982 return -EMSGSIZE;
43983
43984 - if (copy_to_user(_buffer, buffer, n) != 0)
43985 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
43986 return -EFAULT;
43987
43988 return n;
43989 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
43990 if (test_bit(CACHEFILES_DEAD, &cache->flags))
43991 return -EIO;
43992
43993 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
43994 + if (datalen > PAGE_SIZE - 1)
43995 return -EOPNOTSUPP;
43996
43997 /* drag the command string into the kernel so we can parse it */
43998 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
43999 if (args[0] != '%' || args[1] != '\0')
44000 return -EINVAL;
44001
44002 - if (fstop < 0 || fstop >= cache->fcull_percent)
44003 + if (fstop >= cache->fcull_percent)
44004 return cachefiles_daemon_range_error(cache, args);
44005
44006 cache->fstop_percent = fstop;
44007 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
44008 if (args[0] != '%' || args[1] != '\0')
44009 return -EINVAL;
44010
44011 - if (bstop < 0 || bstop >= cache->bcull_percent)
44012 + if (bstop >= cache->bcull_percent)
44013 return cachefiles_daemon_range_error(cache, args);
44014
44015 cache->bstop_percent = bstop;
44016 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
44017 index bd6bc1b..b627b53 100644
44018 --- a/fs/cachefiles/internal.h
44019 +++ b/fs/cachefiles/internal.h
44020 @@ -57,7 +57,7 @@ struct cachefiles_cache {
44021 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
44022 struct rb_root active_nodes; /* active nodes (can't be culled) */
44023 rwlock_t active_lock; /* lock for active_nodes */
44024 - atomic_t gravecounter; /* graveyard uniquifier */
44025 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
44026 unsigned frun_percent; /* when to stop culling (% files) */
44027 unsigned fcull_percent; /* when to start culling (% files) */
44028 unsigned fstop_percent; /* when to stop allocating (% files) */
44029 @@ -169,19 +169,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
44030 * proc.c
44031 */
44032 #ifdef CONFIG_CACHEFILES_HISTOGRAM
44033 -extern atomic_t cachefiles_lookup_histogram[HZ];
44034 -extern atomic_t cachefiles_mkdir_histogram[HZ];
44035 -extern atomic_t cachefiles_create_histogram[HZ];
44036 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44037 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44038 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
44039
44040 extern int __init cachefiles_proc_init(void);
44041 extern void cachefiles_proc_cleanup(void);
44042 static inline
44043 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
44044 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
44045 {
44046 unsigned long jif = jiffies - start_jif;
44047 if (jif >= HZ)
44048 jif = HZ - 1;
44049 - atomic_inc(&histogram[jif]);
44050 + atomic_inc_unchecked(&histogram[jif]);
44051 }
44052
44053 #else
44054 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
44055 index 7f0771d..87d4f36 100644
44056 --- a/fs/cachefiles/namei.c
44057 +++ b/fs/cachefiles/namei.c
44058 @@ -318,7 +318,7 @@ try_again:
44059 /* first step is to make up a grave dentry in the graveyard */
44060 sprintf(nbuffer, "%08x%08x",
44061 (uint32_t) get_seconds(),
44062 - (uint32_t) atomic_inc_return(&cache->gravecounter));
44063 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
44064
44065 /* do the multiway lock magic */
44066 trap = lock_rename(cache->graveyard, dir);
44067 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
44068 index eccd339..4c1d995 100644
44069 --- a/fs/cachefiles/proc.c
44070 +++ b/fs/cachefiles/proc.c
44071 @@ -14,9 +14,9 @@
44072 #include <linux/seq_file.h>
44073 #include "internal.h"
44074
44075 -atomic_t cachefiles_lookup_histogram[HZ];
44076 -atomic_t cachefiles_mkdir_histogram[HZ];
44077 -atomic_t cachefiles_create_histogram[HZ];
44078 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
44079 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
44080 +atomic_unchecked_t cachefiles_create_histogram[HZ];
44081
44082 /*
44083 * display the latency histogram
44084 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
44085 return 0;
44086 default:
44087 index = (unsigned long) v - 3;
44088 - x = atomic_read(&cachefiles_lookup_histogram[index]);
44089 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
44090 - z = atomic_read(&cachefiles_create_histogram[index]);
44091 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
44092 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
44093 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
44094 if (x == 0 && y == 0 && z == 0)
44095 return 0;
44096
44097 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
44098 index 0e3c092..818480e 100644
44099 --- a/fs/cachefiles/rdwr.c
44100 +++ b/fs/cachefiles/rdwr.c
44101 @@ -945,7 +945,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
44102 old_fs = get_fs();
44103 set_fs(KERNEL_DS);
44104 ret = file->f_op->write(
44105 - file, (const void __user *) data, len, &pos);
44106 + file, (const void __force_user *) data, len, &pos);
44107 set_fs(old_fs);
44108 kunmap(page);
44109 if (ret != len)
44110 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
44111 index 3e8094b..cb3ff3d 100644
44112 --- a/fs/ceph/dir.c
44113 +++ b/fs/ceph/dir.c
44114 @@ -244,7 +244,7 @@ static int ceph_readdir(struct file *filp, void *dirent, filldir_t filldir)
44115 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
44116 struct ceph_mds_client *mdsc = fsc->mdsc;
44117 unsigned frag = fpos_frag(filp->f_pos);
44118 - int off = fpos_off(filp->f_pos);
44119 + unsigned int off = fpos_off(filp->f_pos);
44120 int err;
44121 u32 ftype;
44122 struct ceph_mds_reply_info_parsed *rinfo;
44123 @@ -598,7 +598,7 @@ static struct dentry *ceph_lookup(struct inode *dir, struct dentry *dentry,
44124 if (nd &&
44125 (nd->flags & LOOKUP_OPEN) &&
44126 !(nd->intent.open.flags & O_CREAT)) {
44127 - int mode = nd->intent.open.create_mode & ~current->fs->umask;
44128 + int mode = nd->intent.open.create_mode & ~current_umask();
44129 return ceph_lookup_open(dir, dentry, nd, mode, 1);
44130 }
44131
44132 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
44133 index e814052..28dcdf7 100644
44134 --- a/fs/cifs/cifs_debug.c
44135 +++ b/fs/cifs/cifs_debug.c
44136 @@ -267,8 +267,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44137
44138 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
44139 #ifdef CONFIG_CIFS_STATS2
44140 - atomic_set(&totBufAllocCount, 0);
44141 - atomic_set(&totSmBufAllocCount, 0);
44142 + atomic_set_unchecked(&totBufAllocCount, 0);
44143 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44144 #endif /* CONFIG_CIFS_STATS2 */
44145 spin_lock(&cifs_tcp_ses_lock);
44146 list_for_each(tmp1, &cifs_tcp_ses_list) {
44147 @@ -281,25 +281,25 @@ static ssize_t cifs_stats_proc_write(struct file *file,
44148 tcon = list_entry(tmp3,
44149 struct cifs_tcon,
44150 tcon_list);
44151 - atomic_set(&tcon->num_smbs_sent, 0);
44152 - atomic_set(&tcon->num_writes, 0);
44153 - atomic_set(&tcon->num_reads, 0);
44154 - atomic_set(&tcon->num_oplock_brks, 0);
44155 - atomic_set(&tcon->num_opens, 0);
44156 - atomic_set(&tcon->num_posixopens, 0);
44157 - atomic_set(&tcon->num_posixmkdirs, 0);
44158 - atomic_set(&tcon->num_closes, 0);
44159 - atomic_set(&tcon->num_deletes, 0);
44160 - atomic_set(&tcon->num_mkdirs, 0);
44161 - atomic_set(&tcon->num_rmdirs, 0);
44162 - atomic_set(&tcon->num_renames, 0);
44163 - atomic_set(&tcon->num_t2renames, 0);
44164 - atomic_set(&tcon->num_ffirst, 0);
44165 - atomic_set(&tcon->num_fnext, 0);
44166 - atomic_set(&tcon->num_fclose, 0);
44167 - atomic_set(&tcon->num_hardlinks, 0);
44168 - atomic_set(&tcon->num_symlinks, 0);
44169 - atomic_set(&tcon->num_locks, 0);
44170 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
44171 + atomic_set_unchecked(&tcon->num_writes, 0);
44172 + atomic_set_unchecked(&tcon->num_reads, 0);
44173 + atomic_set_unchecked(&tcon->num_oplock_brks, 0);
44174 + atomic_set_unchecked(&tcon->num_opens, 0);
44175 + atomic_set_unchecked(&tcon->num_posixopens, 0);
44176 + atomic_set_unchecked(&tcon->num_posixmkdirs, 0);
44177 + atomic_set_unchecked(&tcon->num_closes, 0);
44178 + atomic_set_unchecked(&tcon->num_deletes, 0);
44179 + atomic_set_unchecked(&tcon->num_mkdirs, 0);
44180 + atomic_set_unchecked(&tcon->num_rmdirs, 0);
44181 + atomic_set_unchecked(&tcon->num_renames, 0);
44182 + atomic_set_unchecked(&tcon->num_t2renames, 0);
44183 + atomic_set_unchecked(&tcon->num_ffirst, 0);
44184 + atomic_set_unchecked(&tcon->num_fnext, 0);
44185 + atomic_set_unchecked(&tcon->num_fclose, 0);
44186 + atomic_set_unchecked(&tcon->num_hardlinks, 0);
44187 + atomic_set_unchecked(&tcon->num_symlinks, 0);
44188 + atomic_set_unchecked(&tcon->num_locks, 0);
44189 }
44190 }
44191 }
44192 @@ -329,8 +329,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44193 smBufAllocCount.counter, cifs_min_small);
44194 #ifdef CONFIG_CIFS_STATS2
44195 seq_printf(m, "Total Large %d Small %d Allocations\n",
44196 - atomic_read(&totBufAllocCount),
44197 - atomic_read(&totSmBufAllocCount));
44198 + atomic_read_unchecked(&totBufAllocCount),
44199 + atomic_read_unchecked(&totSmBufAllocCount));
44200 #endif /* CONFIG_CIFS_STATS2 */
44201
44202 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
44203 @@ -359,41 +359,41 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
44204 if (tcon->need_reconnect)
44205 seq_puts(m, "\tDISCONNECTED ");
44206 seq_printf(m, "\nSMBs: %d Oplock Breaks: %d",
44207 - atomic_read(&tcon->num_smbs_sent),
44208 - atomic_read(&tcon->num_oplock_brks));
44209 + atomic_read_unchecked(&tcon->num_smbs_sent),
44210 + atomic_read_unchecked(&tcon->num_oplock_brks));
44211 seq_printf(m, "\nReads: %d Bytes: %lld",
44212 - atomic_read(&tcon->num_reads),
44213 + atomic_read_unchecked(&tcon->num_reads),
44214 (long long)(tcon->bytes_read));
44215 seq_printf(m, "\nWrites: %d Bytes: %lld",
44216 - atomic_read(&tcon->num_writes),
44217 + atomic_read_unchecked(&tcon->num_writes),
44218 (long long)(tcon->bytes_written));
44219 seq_printf(m, "\nFlushes: %d",
44220 - atomic_read(&tcon->num_flushes));
44221 + atomic_read_unchecked(&tcon->num_flushes));
44222 seq_printf(m, "\nLocks: %d HardLinks: %d "
44223 "Symlinks: %d",
44224 - atomic_read(&tcon->num_locks),
44225 - atomic_read(&tcon->num_hardlinks),
44226 - atomic_read(&tcon->num_symlinks));
44227 + atomic_read_unchecked(&tcon->num_locks),
44228 + atomic_read_unchecked(&tcon->num_hardlinks),
44229 + atomic_read_unchecked(&tcon->num_symlinks));
44230 seq_printf(m, "\nOpens: %d Closes: %d "
44231 "Deletes: %d",
44232 - atomic_read(&tcon->num_opens),
44233 - atomic_read(&tcon->num_closes),
44234 - atomic_read(&tcon->num_deletes));
44235 + atomic_read_unchecked(&tcon->num_opens),
44236 + atomic_read_unchecked(&tcon->num_closes),
44237 + atomic_read_unchecked(&tcon->num_deletes));
44238 seq_printf(m, "\nPosix Opens: %d "
44239 "Posix Mkdirs: %d",
44240 - atomic_read(&tcon->num_posixopens),
44241 - atomic_read(&tcon->num_posixmkdirs));
44242 + atomic_read_unchecked(&tcon->num_posixopens),
44243 + atomic_read_unchecked(&tcon->num_posixmkdirs));
44244 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
44245 - atomic_read(&tcon->num_mkdirs),
44246 - atomic_read(&tcon->num_rmdirs));
44247 + atomic_read_unchecked(&tcon->num_mkdirs),
44248 + atomic_read_unchecked(&tcon->num_rmdirs));
44249 seq_printf(m, "\nRenames: %d T2 Renames %d",
44250 - atomic_read(&tcon->num_renames),
44251 - atomic_read(&tcon->num_t2renames));
44252 + atomic_read_unchecked(&tcon->num_renames),
44253 + atomic_read_unchecked(&tcon->num_t2renames));
44254 seq_printf(m, "\nFindFirst: %d FNext %d "
44255 "FClose %d",
44256 - atomic_read(&tcon->num_ffirst),
44257 - atomic_read(&tcon->num_fnext),
44258 - atomic_read(&tcon->num_fclose));
44259 + atomic_read_unchecked(&tcon->num_ffirst),
44260 + atomic_read_unchecked(&tcon->num_fnext),
44261 + atomic_read_unchecked(&tcon->num_fclose));
44262 }
44263 }
44264 }
44265 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
44266 index 8b6e344..303a662 100644
44267 --- a/fs/cifs/cifsfs.c
44268 +++ b/fs/cifs/cifsfs.c
44269 @@ -994,7 +994,7 @@ cifs_init_request_bufs(void)
44270 cifs_req_cachep = kmem_cache_create("cifs_request",
44271 CIFSMaxBufSize +
44272 MAX_CIFS_HDR_SIZE, 0,
44273 - SLAB_HWCACHE_ALIGN, NULL);
44274 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
44275 if (cifs_req_cachep == NULL)
44276 return -ENOMEM;
44277
44278 @@ -1021,7 +1021,7 @@ cifs_init_request_bufs(void)
44279 efficient to alloc 1 per page off the slab compared to 17K (5page)
44280 alloc of large cifs buffers even when page debugging is on */
44281 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
44282 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
44283 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
44284 NULL);
44285 if (cifs_sm_req_cachep == NULL) {
44286 mempool_destroy(cifs_req_poolp);
44287 @@ -1106,8 +1106,8 @@ init_cifs(void)
44288 atomic_set(&bufAllocCount, 0);
44289 atomic_set(&smBufAllocCount, 0);
44290 #ifdef CONFIG_CIFS_STATS2
44291 - atomic_set(&totBufAllocCount, 0);
44292 - atomic_set(&totSmBufAllocCount, 0);
44293 + atomic_set_unchecked(&totBufAllocCount, 0);
44294 + atomic_set_unchecked(&totSmBufAllocCount, 0);
44295 #endif /* CONFIG_CIFS_STATS2 */
44296
44297 atomic_set(&midCount, 0);
44298 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
44299 index d86ba9f..e80049d 100644
44300 --- a/fs/cifs/cifsglob.h
44301 +++ b/fs/cifs/cifsglob.h
44302 @@ -491,28 +491,28 @@ struct cifs_tcon {
44303 __u16 Flags; /* optional support bits */
44304 enum statusEnum tidStatus;
44305 #ifdef CONFIG_CIFS_STATS
44306 - atomic_t num_smbs_sent;
44307 - atomic_t num_writes;
44308 - atomic_t num_reads;
44309 - atomic_t num_flushes;
44310 - atomic_t num_oplock_brks;
44311 - atomic_t num_opens;
44312 - atomic_t num_closes;
44313 - atomic_t num_deletes;
44314 - atomic_t num_mkdirs;
44315 - atomic_t num_posixopens;
44316 - atomic_t num_posixmkdirs;
44317 - atomic_t num_rmdirs;
44318 - atomic_t num_renames;
44319 - atomic_t num_t2renames;
44320 - atomic_t num_ffirst;
44321 - atomic_t num_fnext;
44322 - atomic_t num_fclose;
44323 - atomic_t num_hardlinks;
44324 - atomic_t num_symlinks;
44325 - atomic_t num_locks;
44326 - atomic_t num_acl_get;
44327 - atomic_t num_acl_set;
44328 + atomic_unchecked_t num_smbs_sent;
44329 + atomic_unchecked_t num_writes;
44330 + atomic_unchecked_t num_reads;
44331 + atomic_unchecked_t num_flushes;
44332 + atomic_unchecked_t num_oplock_brks;
44333 + atomic_unchecked_t num_opens;
44334 + atomic_unchecked_t num_closes;
44335 + atomic_unchecked_t num_deletes;
44336 + atomic_unchecked_t num_mkdirs;
44337 + atomic_unchecked_t num_posixopens;
44338 + atomic_unchecked_t num_posixmkdirs;
44339 + atomic_unchecked_t num_rmdirs;
44340 + atomic_unchecked_t num_renames;
44341 + atomic_unchecked_t num_t2renames;
44342 + atomic_unchecked_t num_ffirst;
44343 + atomic_unchecked_t num_fnext;
44344 + atomic_unchecked_t num_fclose;
44345 + atomic_unchecked_t num_hardlinks;
44346 + atomic_unchecked_t num_symlinks;
44347 + atomic_unchecked_t num_locks;
44348 + atomic_unchecked_t num_acl_get;
44349 + atomic_unchecked_t num_acl_set;
44350 #ifdef CONFIG_CIFS_STATS2
44351 unsigned long long time_writes;
44352 unsigned long long time_reads;
44353 @@ -735,7 +735,7 @@ convert_delimiter(char *path, char delim)
44354 }
44355
44356 #ifdef CONFIG_CIFS_STATS
44357 -#define cifs_stats_inc atomic_inc
44358 +#define cifs_stats_inc atomic_inc_unchecked
44359
44360 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
44361 unsigned int bytes)
44362 @@ -1093,8 +1093,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
44363 /* Various Debug counters */
44364 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
44365 #ifdef CONFIG_CIFS_STATS2
44366 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
44367 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
44368 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
44369 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
44370 #endif
44371 GLOBAL_EXTERN atomic_t smBufAllocCount;
44372 GLOBAL_EXTERN atomic_t midCount;
44373 diff --git a/fs/cifs/link.c b/fs/cifs/link.c
44374 index 6b0e064..94e6c3c 100644
44375 --- a/fs/cifs/link.c
44376 +++ b/fs/cifs/link.c
44377 @@ -600,7 +600,7 @@ symlink_exit:
44378
44379 void cifs_put_link(struct dentry *direntry, struct nameidata *nd, void *cookie)
44380 {
44381 - char *p = nd_get_link(nd);
44382 + const char *p = nd_get_link(nd);
44383 if (!IS_ERR(p))
44384 kfree(p);
44385 }
44386 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
44387 index 557506a..2fd3816 100644
44388 --- a/fs/cifs/misc.c
44389 +++ b/fs/cifs/misc.c
44390 @@ -156,7 +156,7 @@ cifs_buf_get(void)
44391 memset(ret_buf, 0, sizeof(struct smb_hdr) + 3);
44392 atomic_inc(&bufAllocCount);
44393 #ifdef CONFIG_CIFS_STATS2
44394 - atomic_inc(&totBufAllocCount);
44395 + atomic_inc_unchecked(&totBufAllocCount);
44396 #endif /* CONFIG_CIFS_STATS2 */
44397 }
44398
44399 @@ -191,7 +191,7 @@ cifs_small_buf_get(void)
44400 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
44401 atomic_inc(&smBufAllocCount);
44402 #ifdef CONFIG_CIFS_STATS2
44403 - atomic_inc(&totSmBufAllocCount);
44404 + atomic_inc_unchecked(&totSmBufAllocCount);
44405 #endif /* CONFIG_CIFS_STATS2 */
44406
44407 }
44408 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
44409 index 6901578..d402eb5 100644
44410 --- a/fs/coda/cache.c
44411 +++ b/fs/coda/cache.c
44412 @@ -24,7 +24,7 @@
44413 #include "coda_linux.h"
44414 #include "coda_cache.h"
44415
44416 -static atomic_t permission_epoch = ATOMIC_INIT(0);
44417 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
44418
44419 /* replace or extend an acl cache hit */
44420 void coda_cache_enter(struct inode *inode, int mask)
44421 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
44422 struct coda_inode_info *cii = ITOC(inode);
44423
44424 spin_lock(&cii->c_lock);
44425 - cii->c_cached_epoch = atomic_read(&permission_epoch);
44426 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
44427 if (cii->c_uid != current_fsuid()) {
44428 cii->c_uid = current_fsuid();
44429 cii->c_cached_perm = mask;
44430 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
44431 {
44432 struct coda_inode_info *cii = ITOC(inode);
44433 spin_lock(&cii->c_lock);
44434 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
44435 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
44436 spin_unlock(&cii->c_lock);
44437 }
44438
44439 /* remove all acl caches */
44440 void coda_cache_clear_all(struct super_block *sb)
44441 {
44442 - atomic_inc(&permission_epoch);
44443 + atomic_inc_unchecked(&permission_epoch);
44444 }
44445
44446
44447 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
44448 spin_lock(&cii->c_lock);
44449 hit = (mask & cii->c_cached_perm) == mask &&
44450 cii->c_uid == current_fsuid() &&
44451 - cii->c_cached_epoch == atomic_read(&permission_epoch);
44452 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
44453 spin_unlock(&cii->c_lock);
44454
44455 return hit;
44456 diff --git a/fs/compat.c b/fs/compat.c
44457 index 1bdb350..9f28287 100644
44458 --- a/fs/compat.c
44459 +++ b/fs/compat.c
44460 @@ -490,7 +490,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
44461
44462 set_fs(KERNEL_DS);
44463 /* The __user pointer cast is valid because of the set_fs() */
44464 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
44465 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
44466 set_fs(oldfs);
44467 /* truncating is ok because it's a user address */
44468 if (!ret)
44469 @@ -548,7 +548,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
44470 goto out;
44471
44472 ret = -EINVAL;
44473 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
44474 + if (nr_segs > UIO_MAXIOV)
44475 goto out;
44476 if (nr_segs > fast_segs) {
44477 ret = -ENOMEM;
44478 @@ -831,6 +831,7 @@ struct compat_old_linux_dirent {
44479
44480 struct compat_readdir_callback {
44481 struct compat_old_linux_dirent __user *dirent;
44482 + struct file * file;
44483 int result;
44484 };
44485
44486 @@ -848,6 +849,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
44487 buf->result = -EOVERFLOW;
44488 return -EOVERFLOW;
44489 }
44490 +
44491 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44492 + return 0;
44493 +
44494 buf->result++;
44495 dirent = buf->dirent;
44496 if (!access_ok(VERIFY_WRITE, dirent,
44497 @@ -880,6 +885,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
44498
44499 buf.result = 0;
44500 buf.dirent = dirent;
44501 + buf.file = file;
44502
44503 error = vfs_readdir(file, compat_fillonedir, &buf);
44504 if (buf.result)
44505 @@ -899,6 +905,7 @@ struct compat_linux_dirent {
44506 struct compat_getdents_callback {
44507 struct compat_linux_dirent __user *current_dir;
44508 struct compat_linux_dirent __user *previous;
44509 + struct file * file;
44510 int count;
44511 int error;
44512 };
44513 @@ -920,6 +927,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
44514 buf->error = -EOVERFLOW;
44515 return -EOVERFLOW;
44516 }
44517 +
44518 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44519 + return 0;
44520 +
44521 dirent = buf->previous;
44522 if (dirent) {
44523 if (__put_user(offset, &dirent->d_off))
44524 @@ -966,6 +977,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44525 buf.previous = NULL;
44526 buf.count = count;
44527 buf.error = 0;
44528 + buf.file = file;
44529
44530 error = vfs_readdir(file, compat_filldir, &buf);
44531 if (error >= 0)
44532 @@ -986,6 +998,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
44533 struct compat_getdents_callback64 {
44534 struct linux_dirent64 __user *current_dir;
44535 struct linux_dirent64 __user *previous;
44536 + struct file * file;
44537 int count;
44538 int error;
44539 };
44540 @@ -1002,6 +1015,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
44541 buf->error = -EINVAL; /* only used if we fail.. */
44542 if (reclen > buf->count)
44543 return -EINVAL;
44544 +
44545 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
44546 + return 0;
44547 +
44548 dirent = buf->previous;
44549
44550 if (dirent) {
44551 @@ -1052,13 +1069,14 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
44552 buf.previous = NULL;
44553 buf.count = count;
44554 buf.error = 0;
44555 + buf.file = file;
44556
44557 error = vfs_readdir(file, compat_filldir64, &buf);
44558 if (error >= 0)
44559 error = buf.error;
44560 lastdirent = buf.previous;
44561 if (lastdirent) {
44562 - typeof(lastdirent->d_off) d_off = file->f_pos;
44563 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
44564 if (__put_user_unaligned(d_off, &lastdirent->d_off))
44565 error = -EFAULT;
44566 else
44567 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
44568 index 112e45a..b59845b 100644
44569 --- a/fs/compat_binfmt_elf.c
44570 +++ b/fs/compat_binfmt_elf.c
44571 @@ -30,11 +30,13 @@
44572 #undef elf_phdr
44573 #undef elf_shdr
44574 #undef elf_note
44575 +#undef elf_dyn
44576 #undef elf_addr_t
44577 #define elfhdr elf32_hdr
44578 #define elf_phdr elf32_phdr
44579 #define elf_shdr elf32_shdr
44580 #define elf_note elf32_note
44581 +#define elf_dyn Elf32_Dyn
44582 #define elf_addr_t Elf32_Addr
44583
44584 /*
44585 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
44586 index debdfe0..75d31d4 100644
44587 --- a/fs/compat_ioctl.c
44588 +++ b/fs/compat_ioctl.c
44589 @@ -210,6 +210,8 @@ static int do_video_set_spu_palette(unsigned int fd, unsigned int cmd,
44590
44591 err = get_user(palp, &up->palette);
44592 err |= get_user(length, &up->length);
44593 + if (err)
44594 + return -EFAULT;
44595
44596 up_native = compat_alloc_user_space(sizeof(struct video_spu_palette));
44597 err = put_user(compat_ptr(palp), &up_native->palette);
44598 @@ -621,7 +623,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
44599 return -EFAULT;
44600 if (__get_user(udata, &ss32->iomem_base))
44601 return -EFAULT;
44602 - ss.iomem_base = compat_ptr(udata);
44603 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
44604 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
44605 __get_user(ss.port_high, &ss32->port_high))
44606 return -EFAULT;
44607 @@ -796,7 +798,7 @@ static int compat_ioctl_preallocate(struct file *file,
44608 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
44609 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
44610 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
44611 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44612 + copy_in_user(p->l_pad, &p32->l_pad, 4*sizeof(u32)))
44613 return -EFAULT;
44614
44615 return ioctl_preallocate(file, p);
44616 @@ -1610,8 +1612,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
44617 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
44618 {
44619 unsigned int a, b;
44620 - a = *(unsigned int *)p;
44621 - b = *(unsigned int *)q;
44622 + a = *(const unsigned int *)p;
44623 + b = *(const unsigned int *)q;
44624 if (a > b)
44625 return 1;
44626 if (a < b)
44627 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
44628 index 7e6c52d..94bc756 100644
44629 --- a/fs/configfs/dir.c
44630 +++ b/fs/configfs/dir.c
44631 @@ -1564,7 +1564,8 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44632 }
44633 for (p=q->next; p!= &parent_sd->s_children; p=p->next) {
44634 struct configfs_dirent *next;
44635 - const char * name;
44636 + const unsigned char * name;
44637 + char d_name[sizeof(next->s_dentry->d_iname)];
44638 int len;
44639 struct inode *inode = NULL;
44640
44641 @@ -1574,7 +1575,12 @@ static int configfs_readdir(struct file * filp, void * dirent, filldir_t filldir
44642 continue;
44643
44644 name = configfs_get_name(next);
44645 - len = strlen(name);
44646 + if (next->s_dentry && name == next->s_dentry->d_iname) {
44647 + len = next->s_dentry->d_name.len;
44648 + memcpy(d_name, name, len);
44649 + name = d_name;
44650 + } else
44651 + len = strlen(name);
44652
44653 /*
44654 * We'll have a dentry and an inode for
44655 diff --git a/fs/dcache.c b/fs/dcache.c
44656 index 4123b92..5381f16 100644
44657 --- a/fs/dcache.c
44658 +++ b/fs/dcache.c
44659 @@ -1132,6 +1132,8 @@ positive:
44660 return 1;
44661
44662 rename_retry:
44663 + if (locked)
44664 + goto again;
44665 locked = 1;
44666 write_seqlock(&rename_lock);
44667 goto again;
44668 @@ -1234,6 +1236,8 @@ out:
44669 rename_retry:
44670 if (found)
44671 return found;
44672 + if (locked)
44673 + goto again;
44674 locked = 1;
44675 write_seqlock(&rename_lock);
44676 goto again;
44677 @@ -3031,6 +3035,8 @@ resume:
44678 return;
44679
44680 rename_retry:
44681 + if (locked)
44682 + goto again;
44683 locked = 1;
44684 write_seqlock(&rename_lock);
44685 goto again;
44686 @@ -3154,7 +3160,7 @@ void __init vfs_caches_init(unsigned long mempages)
44687 mempages -= reserve;
44688
44689 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
44690 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
44691 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY, NULL);
44692
44693 dcache_init();
44694 inode_init();
44695 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
44696 index b80bc84..0d46d1a 100644
44697 --- a/fs/debugfs/inode.c
44698 +++ b/fs/debugfs/inode.c
44699 @@ -408,7 +408,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
44700 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
44701 {
44702 return debugfs_create_file(name,
44703 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
44704 + S_IFDIR | S_IRWXU,
44705 +#else
44706 S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
44707 +#endif
44708 parent, NULL, NULL);
44709 }
44710 EXPORT_SYMBOL_GPL(debugfs_create_dir);
44711 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
44712 index 02e2fec..5c47fa2 100644
44713 --- a/fs/ecryptfs/inode.c
44714 +++ b/fs/ecryptfs/inode.c
44715 @@ -676,7 +676,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
44716 old_fs = get_fs();
44717 set_fs(get_ds());
44718 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
44719 - (char __user *)lower_buf,
44720 + (char __force_user *)lower_buf,
44721 PATH_MAX);
44722 set_fs(old_fs);
44723 if (rc < 0)
44724 @@ -708,7 +708,7 @@ out:
44725 static void
44726 ecryptfs_put_link(struct dentry *dentry, struct nameidata *nd, void *ptr)
44727 {
44728 - char *buf = nd_get_link(nd);
44729 + const char *buf = nd_get_link(nd);
44730 if (!IS_ERR(buf)) {
44731 /* Free the char* */
44732 kfree(buf);
44733 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
44734 index c0038f6..47ab347 100644
44735 --- a/fs/ecryptfs/miscdev.c
44736 +++ b/fs/ecryptfs/miscdev.c
44737 @@ -355,7 +355,7 @@ check_list:
44738 goto out_unlock_msg_ctx;
44739 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
44740 if (msg_ctx->msg) {
44741 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
44742 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
44743 goto out_unlock_msg_ctx;
44744 i += packet_length_size;
44745 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
44746 diff --git a/fs/ecryptfs/read_write.c b/fs/ecryptfs/read_write.c
44747 index b2a34a1..162fa69 100644
44748 --- a/fs/ecryptfs/read_write.c
44749 +++ b/fs/ecryptfs/read_write.c
44750 @@ -48,7 +48,7 @@ int ecryptfs_write_lower(struct inode *ecryptfs_inode, char *data,
44751 return -EIO;
44752 fs_save = get_fs();
44753 set_fs(get_ds());
44754 - rc = vfs_write(lower_file, data, size, &offset);
44755 + rc = vfs_write(lower_file, (const char __force_user *)data, size, &offset);
44756 set_fs(fs_save);
44757 mark_inode_dirty_sync(ecryptfs_inode);
44758 return rc;
44759 @@ -244,7 +244,7 @@ int ecryptfs_read_lower(char *data, loff_t offset, size_t size,
44760 return -EIO;
44761 fs_save = get_fs();
44762 set_fs(get_ds());
44763 - rc = vfs_read(lower_file, data, size, &offset);
44764 + rc = vfs_read(lower_file, (char __force_user *)data, size, &offset);
44765 set_fs(fs_save);
44766 return rc;
44767 }
44768 diff --git a/fs/eventpoll.c b/fs/eventpoll.c
44769 index 1c8b556..eedec84 100644
44770 --- a/fs/eventpoll.c
44771 +++ b/fs/eventpoll.c
44772 @@ -1654,8 +1654,8 @@ SYSCALL_DEFINE1(epoll_create1, int, flags)
44773 error = PTR_ERR(file);
44774 goto out_free_fd;
44775 }
44776 - fd_install(fd, file);
44777 ep->file = file;
44778 + fd_install(fd, file);
44779 return fd;
44780
44781 out_free_fd:
44782 diff --git a/fs/exec.c b/fs/exec.c
44783 index e95aeed..a943469 100644
44784 --- a/fs/exec.c
44785 +++ b/fs/exec.c
44786 @@ -55,6 +55,15 @@
44787 #include <linux/pipe_fs_i.h>
44788 #include <linux/oom.h>
44789 #include <linux/compat.h>
44790 +#include <linux/random.h>
44791 +#include <linux/seq_file.h>
44792 +
44793 +#ifdef CONFIG_PAX_REFCOUNT
44794 +#include <linux/kallsyms.h>
44795 +#include <linux/kdebug.h>
44796 +#endif
44797 +
44798 +#include <trace/events/fs.h>
44799
44800 #include <asm/uaccess.h>
44801 #include <asm/mmu_context.h>
44802 @@ -66,6 +75,18 @@
44803
44804 #include <trace/events/sched.h>
44805
44806 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
44807 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
44808 +{
44809 + WARN_ONCE(1, "PAX: PAX_HAVE_ACL_FLAGS was enabled without providing the pax_set_initial_flags callback, this is probably not what you wanted.\n");
44810 +}
44811 +#endif
44812 +
44813 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
44814 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
44815 +EXPORT_SYMBOL(pax_set_initial_flags_func);
44816 +#endif
44817 +
44818 int core_uses_pid;
44819 char core_pattern[CORENAME_MAX_SIZE] = "core";
44820 unsigned int core_pipe_limit;
44821 @@ -75,7 +96,7 @@ struct core_name {
44822 char *corename;
44823 int used, size;
44824 };
44825 -static atomic_t call_count = ATOMIC_INIT(1);
44826 +static atomic_unchecked_t call_count = ATOMIC_INIT(1);
44827
44828 /* The maximal length of core_pattern is also specified in sysctl.c */
44829
44830 @@ -191,18 +212,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44831 int write)
44832 {
44833 struct page *page;
44834 - int ret;
44835
44836 -#ifdef CONFIG_STACK_GROWSUP
44837 - if (write) {
44838 - ret = expand_downwards(bprm->vma, pos);
44839 - if (ret < 0)
44840 - return NULL;
44841 - }
44842 -#endif
44843 - ret = get_user_pages(current, bprm->mm, pos,
44844 - 1, write, 1, &page, NULL);
44845 - if (ret <= 0)
44846 + if (0 > expand_downwards(bprm->vma, pos))
44847 + return NULL;
44848 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
44849 return NULL;
44850
44851 if (write) {
44852 @@ -218,6 +231,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
44853 if (size <= ARG_MAX)
44854 return page;
44855
44856 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
44857 + // only allow 512KB for argv+env on suid/sgid binaries
44858 + // to prevent easy ASLR exhaustion
44859 + if (((bprm->cred->euid != current_euid()) ||
44860 + (bprm->cred->egid != current_egid())) &&
44861 + (size > (512 * 1024))) {
44862 + put_page(page);
44863 + return NULL;
44864 + }
44865 +#endif
44866 +
44867 /*
44868 * Limit to 1/4-th the stack size for the argv+env strings.
44869 * This ensures that:
44870 @@ -277,6 +301,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44871 vma->vm_end = STACK_TOP_MAX;
44872 vma->vm_start = vma->vm_end - PAGE_SIZE;
44873 vma->vm_flags = VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
44874 +
44875 +#ifdef CONFIG_PAX_SEGMEXEC
44876 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
44877 +#endif
44878 +
44879 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
44880 INIT_LIST_HEAD(&vma->anon_vma_chain);
44881
44882 @@ -287,6 +316,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
44883 mm->stack_vm = mm->total_vm = 1;
44884 up_write(&mm->mmap_sem);
44885 bprm->p = vma->vm_end - sizeof(void *);
44886 +
44887 +#ifdef CONFIG_PAX_RANDUSTACK
44888 + if (randomize_va_space)
44889 + bprm->p ^= random32() & ~PAGE_MASK;
44890 +#endif
44891 +
44892 return 0;
44893 err:
44894 up_write(&mm->mmap_sem);
44895 @@ -395,19 +430,7 @@ err:
44896 return err;
44897 }
44898
44899 -struct user_arg_ptr {
44900 -#ifdef CONFIG_COMPAT
44901 - bool is_compat;
44902 -#endif
44903 - union {
44904 - const char __user *const __user *native;
44905 -#ifdef CONFIG_COMPAT
44906 - compat_uptr_t __user *compat;
44907 -#endif
44908 - } ptr;
44909 -};
44910 -
44911 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44912 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44913 {
44914 const char __user *native;
44915
44916 @@ -416,14 +439,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
44917 compat_uptr_t compat;
44918
44919 if (get_user(compat, argv.ptr.compat + nr))
44920 - return ERR_PTR(-EFAULT);
44921 + return (const char __force_user *)ERR_PTR(-EFAULT);
44922
44923 return compat_ptr(compat);
44924 }
44925 #endif
44926
44927 if (get_user(native, argv.ptr.native + nr))
44928 - return ERR_PTR(-EFAULT);
44929 + return (const char __force_user *)ERR_PTR(-EFAULT);
44930
44931 return native;
44932 }
44933 @@ -442,7 +465,7 @@ static int count(struct user_arg_ptr argv, int max)
44934 if (!p)
44935 break;
44936
44937 - if (IS_ERR(p))
44938 + if (IS_ERR((const char __force_kernel *)p))
44939 return -EFAULT;
44940
44941 if (i++ >= max)
44942 @@ -476,7 +499,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
44943
44944 ret = -EFAULT;
44945 str = get_user_arg_ptr(argv, argc);
44946 - if (IS_ERR(str))
44947 + if (IS_ERR((const char __force_kernel *)str))
44948 goto out;
44949
44950 len = strnlen_user(str, MAX_ARG_STRLEN);
44951 @@ -558,7 +581,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
44952 int r;
44953 mm_segment_t oldfs = get_fs();
44954 struct user_arg_ptr argv = {
44955 - .ptr.native = (const char __user *const __user *)__argv,
44956 + .ptr.native = (const char __force_user *const __force_user *)__argv,
44957 };
44958
44959 set_fs(KERNEL_DS);
44960 @@ -593,7 +616,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44961 unsigned long new_end = old_end - shift;
44962 struct mmu_gather tlb;
44963
44964 - BUG_ON(new_start > new_end);
44965 + if (new_start >= new_end || new_start < mmap_min_addr)
44966 + return -ENOMEM;
44967
44968 /*
44969 * ensure there are no vmas between where we want to go
44970 @@ -602,6 +626,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
44971 if (vma != find_vma(mm, new_start))
44972 return -EFAULT;
44973
44974 +#ifdef CONFIG_PAX_SEGMEXEC
44975 + BUG_ON(pax_find_mirror_vma(vma));
44976 +#endif
44977 +
44978 /*
44979 * cover the whole range: [new_start, old_end)
44980 */
44981 @@ -682,10 +710,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
44982 stack_top = arch_align_stack(stack_top);
44983 stack_top = PAGE_ALIGN(stack_top);
44984
44985 - if (unlikely(stack_top < mmap_min_addr) ||
44986 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
44987 - return -ENOMEM;
44988 -
44989 stack_shift = vma->vm_end - stack_top;
44990
44991 bprm->p -= stack_shift;
44992 @@ -697,8 +721,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
44993 bprm->exec -= stack_shift;
44994
44995 down_write(&mm->mmap_sem);
44996 +
44997 + /* Move stack pages down in memory. */
44998 + if (stack_shift) {
44999 + ret = shift_arg_pages(vma, stack_shift);
45000 + if (ret)
45001 + goto out_unlock;
45002 + }
45003 +
45004 vm_flags = VM_STACK_FLAGS;
45005
45006 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45007 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
45008 + vm_flags &= ~VM_EXEC;
45009 +
45010 +#ifdef CONFIG_PAX_MPROTECT
45011 + if (mm->pax_flags & MF_PAX_MPROTECT)
45012 + vm_flags &= ~VM_MAYEXEC;
45013 +#endif
45014 +
45015 + }
45016 +#endif
45017 +
45018 /*
45019 * Adjust stack execute permissions; explicitly enable for
45020 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
45021 @@ -717,13 +761,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
45022 goto out_unlock;
45023 BUG_ON(prev != vma);
45024
45025 - /* Move stack pages down in memory. */
45026 - if (stack_shift) {
45027 - ret = shift_arg_pages(vma, stack_shift);
45028 - if (ret)
45029 - goto out_unlock;
45030 - }
45031 -
45032 /* mprotect_fixup is overkill to remove the temporary stack flags */
45033 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
45034
45035 @@ -781,6 +818,8 @@ struct file *open_exec(const char *name)
45036
45037 fsnotify_open(file);
45038
45039 + trace_open_exec(name);
45040 +
45041 err = deny_write_access(file);
45042 if (err)
45043 goto exit;
45044 @@ -804,7 +843,7 @@ int kernel_read(struct file *file, loff_t offset,
45045 old_fs = get_fs();
45046 set_fs(get_ds());
45047 /* The cast to a user pointer is valid due to the set_fs() */
45048 - result = vfs_read(file, (void __user *)addr, count, &pos);
45049 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
45050 set_fs(old_fs);
45051 return result;
45052 }
45053 @@ -1257,7 +1296,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
45054 }
45055 rcu_read_unlock();
45056
45057 - if (p->fs->users > n_fs) {
45058 + if (atomic_read(&p->fs->users) > n_fs) {
45059 bprm->unsafe |= LSM_UNSAFE_SHARE;
45060 } else {
45061 res = -EAGAIN;
45062 @@ -1460,6 +1499,28 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
45063
45064 EXPORT_SYMBOL(search_binary_handler);
45065
45066 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45067 +static DEFINE_PER_CPU(u64, exec_counter);
45068 +static int __init init_exec_counters(void)
45069 +{
45070 + unsigned int cpu;
45071 +
45072 + for_each_possible_cpu(cpu) {
45073 + per_cpu(exec_counter, cpu) = (u64)cpu;
45074 + }
45075 +
45076 + return 0;
45077 +}
45078 +early_initcall(init_exec_counters);
45079 +static inline void increment_exec_counter(void)
45080 +{
45081 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
45082 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
45083 +}
45084 +#else
45085 +static inline void increment_exec_counter(void) {}
45086 +#endif
45087 +
45088 /*
45089 * sys_execve() executes a new program.
45090 */
45091 @@ -1468,6 +1529,11 @@ static int do_execve_common(const char *filename,
45092 struct user_arg_ptr envp,
45093 struct pt_regs *regs)
45094 {
45095 +#ifdef CONFIG_GRKERNSEC
45096 + struct file *old_exec_file;
45097 + struct acl_subject_label *old_acl;
45098 + struct rlimit old_rlim[RLIM_NLIMITS];
45099 +#endif
45100 struct linux_binprm *bprm;
45101 struct file *file;
45102 struct files_struct *displaced;
45103 @@ -1475,6 +1541,8 @@ static int do_execve_common(const char *filename,
45104 int retval;
45105 const struct cred *cred = current_cred();
45106
45107 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current->cred->user->processes), 1);
45108 +
45109 /*
45110 * We move the actual failure in case of RLIMIT_NPROC excess from
45111 * set*uid() to execve() because too many poorly written programs
45112 @@ -1515,12 +1583,27 @@ static int do_execve_common(const char *filename,
45113 if (IS_ERR(file))
45114 goto out_unmark;
45115
45116 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
45117 + retval = -EPERM;
45118 + goto out_file;
45119 + }
45120 +
45121 sched_exec();
45122
45123 bprm->file = file;
45124 bprm->filename = filename;
45125 bprm->interp = filename;
45126
45127 + if (gr_process_user_ban()) {
45128 + retval = -EPERM;
45129 + goto out_file;
45130 + }
45131 +
45132 + if (!gr_acl_handle_execve(file->f_dentry, file->f_vfsmnt)) {
45133 + retval = -EACCES;
45134 + goto out_file;
45135 + }
45136 +
45137 retval = bprm_mm_init(bprm);
45138 if (retval)
45139 goto out_file;
45140 @@ -1537,24 +1620,65 @@ static int do_execve_common(const char *filename,
45141 if (retval < 0)
45142 goto out;
45143
45144 +#ifdef CONFIG_GRKERNSEC
45145 + old_acl = current->acl;
45146 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
45147 + old_exec_file = current->exec_file;
45148 + get_file(file);
45149 + current->exec_file = file;
45150 +#endif
45151 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
45152 + /* limit suid stack to 8MB
45153 + we saved the old limits above and will restore them if this exec fails
45154 + */
45155 + if (((bprm->cred->euid != current_euid()) || (bprm->cred->egid != current_egid())) &&
45156 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
45157 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
45158 +#endif
45159 +
45160 + if (!gr_tpe_allow(file)) {
45161 + retval = -EACCES;
45162 + goto out_fail;
45163 + }
45164 +
45165 + if (gr_check_crash_exec(file)) {
45166 + retval = -EACCES;
45167 + goto out_fail;
45168 + }
45169 +
45170 + retval = gr_set_proc_label(file->f_dentry, file->f_vfsmnt,
45171 + bprm->unsafe);
45172 + if (retval < 0)
45173 + goto out_fail;
45174 +
45175 retval = copy_strings_kernel(1, &bprm->filename, bprm);
45176 if (retval < 0)
45177 - goto out;
45178 + goto out_fail;
45179
45180 bprm->exec = bprm->p;
45181 retval = copy_strings(bprm->envc, envp, bprm);
45182 if (retval < 0)
45183 - goto out;
45184 + goto out_fail;
45185
45186 retval = copy_strings(bprm->argc, argv, bprm);
45187 if (retval < 0)
45188 - goto out;
45189 + goto out_fail;
45190 +
45191 + gr_log_chroot_exec(file->f_dentry, file->f_vfsmnt);
45192 +
45193 + gr_handle_exec_args(bprm, argv);
45194
45195 retval = search_binary_handler(bprm,regs);
45196 if (retval < 0)
45197 - goto out;
45198 + goto out_fail;
45199 +#ifdef CONFIG_GRKERNSEC
45200 + if (old_exec_file)
45201 + fput(old_exec_file);
45202 +#endif
45203
45204 /* execve succeeded */
45205 +
45206 + increment_exec_counter();
45207 current->fs->in_exec = 0;
45208 current->in_execve = 0;
45209 acct_update_integrals(current);
45210 @@ -1563,6 +1687,14 @@ static int do_execve_common(const char *filename,
45211 put_files_struct(displaced);
45212 return retval;
45213
45214 +out_fail:
45215 +#ifdef CONFIG_GRKERNSEC
45216 + current->acl = old_acl;
45217 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
45218 + fput(current->exec_file);
45219 + current->exec_file = old_exec_file;
45220 +#endif
45221 +
45222 out:
45223 if (bprm->mm) {
45224 acct_arg_size(bprm, 0);
45225 @@ -1636,7 +1768,7 @@ static int expand_corename(struct core_name *cn)
45226 {
45227 char *old_corename = cn->corename;
45228
45229 - cn->size = CORENAME_MAX_SIZE * atomic_inc_return(&call_count);
45230 + cn->size = CORENAME_MAX_SIZE * atomic_inc_return_unchecked(&call_count);
45231 cn->corename = krealloc(old_corename, cn->size, GFP_KERNEL);
45232
45233 if (!cn->corename) {
45234 @@ -1733,7 +1865,7 @@ static int format_corename(struct core_name *cn, long signr)
45235 int pid_in_pattern = 0;
45236 int err = 0;
45237
45238 - cn->size = CORENAME_MAX_SIZE * atomic_read(&call_count);
45239 + cn->size = CORENAME_MAX_SIZE * atomic_read_unchecked(&call_count);
45240 cn->corename = kmalloc(cn->size, GFP_KERNEL);
45241 cn->used = 0;
45242
45243 @@ -1830,6 +1962,250 @@ out:
45244 return ispipe;
45245 }
45246
45247 +int pax_check_flags(unsigned long *flags)
45248 +{
45249 + int retval = 0;
45250 +
45251 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
45252 + if (*flags & MF_PAX_SEGMEXEC)
45253 + {
45254 + *flags &= ~MF_PAX_SEGMEXEC;
45255 + retval = -EINVAL;
45256 + }
45257 +#endif
45258 +
45259 + if ((*flags & MF_PAX_PAGEEXEC)
45260 +
45261 +#ifdef CONFIG_PAX_PAGEEXEC
45262 + && (*flags & MF_PAX_SEGMEXEC)
45263 +#endif
45264 +
45265 + )
45266 + {
45267 + *flags &= ~MF_PAX_PAGEEXEC;
45268 + retval = -EINVAL;
45269 + }
45270 +
45271 + if ((*flags & MF_PAX_MPROTECT)
45272 +
45273 +#ifdef CONFIG_PAX_MPROTECT
45274 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45275 +#endif
45276 +
45277 + )
45278 + {
45279 + *flags &= ~MF_PAX_MPROTECT;
45280 + retval = -EINVAL;
45281 + }
45282 +
45283 + if ((*flags & MF_PAX_EMUTRAMP)
45284 +
45285 +#ifdef CONFIG_PAX_EMUTRAMP
45286 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
45287 +#endif
45288 +
45289 + )
45290 + {
45291 + *flags &= ~MF_PAX_EMUTRAMP;
45292 + retval = -EINVAL;
45293 + }
45294 +
45295 + return retval;
45296 +}
45297 +
45298 +EXPORT_SYMBOL(pax_check_flags);
45299 +
45300 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
45301 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
45302 +{
45303 + struct task_struct *tsk = current;
45304 + struct mm_struct *mm = current->mm;
45305 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
45306 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
45307 + char *path_exec = NULL;
45308 + char *path_fault = NULL;
45309 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
45310 +
45311 + if (buffer_exec && buffer_fault) {
45312 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
45313 +
45314 + down_read(&mm->mmap_sem);
45315 + vma = mm->mmap;
45316 + while (vma && (!vma_exec || !vma_fault)) {
45317 + if ((vma->vm_flags & VM_EXECUTABLE) && vma->vm_file)
45318 + vma_exec = vma;
45319 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
45320 + vma_fault = vma;
45321 + vma = vma->vm_next;
45322 + }
45323 + if (vma_exec) {
45324 + path_exec = d_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
45325 + if (IS_ERR(path_exec))
45326 + path_exec = "<path too long>";
45327 + else {
45328 + path_exec = mangle_path(buffer_exec, path_exec, "\t\n\\");
45329 + if (path_exec) {
45330 + *path_exec = 0;
45331 + path_exec = buffer_exec;
45332 + } else
45333 + path_exec = "<path too long>";
45334 + }
45335 + }
45336 + if (vma_fault) {
45337 + start = vma_fault->vm_start;
45338 + end = vma_fault->vm_end;
45339 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
45340 + if (vma_fault->vm_file) {
45341 + path_fault = d_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
45342 + if (IS_ERR(path_fault))
45343 + path_fault = "<path too long>";
45344 + else {
45345 + path_fault = mangle_path(buffer_fault, path_fault, "\t\n\\");
45346 + if (path_fault) {
45347 + *path_fault = 0;
45348 + path_fault = buffer_fault;
45349 + } else
45350 + path_fault = "<path too long>";
45351 + }
45352 + } else
45353 + path_fault = "<anonymous mapping>";
45354 + }
45355 + up_read(&mm->mmap_sem);
45356 + }
45357 + if (tsk->signal->curr_ip)
45358 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
45359 + else
45360 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
45361 + printk(KERN_ERR "PAX: terminating task: %s(%s):%d, uid/euid: %u/%u, "
45362 + "PC: %p, SP: %p\n", path_exec, tsk->comm, task_pid_nr(tsk),
45363 + task_uid(tsk), task_euid(tsk), pc, sp);
45364 + free_page((unsigned long)buffer_exec);
45365 + free_page((unsigned long)buffer_fault);
45366 + pax_report_insns(regs, pc, sp);
45367 + do_coredump(SIGKILL, SIGKILL, regs);
45368 +}
45369 +#endif
45370 +
45371 +#ifdef CONFIG_PAX_REFCOUNT
45372 +void pax_report_refcount_overflow(struct pt_regs *regs)
45373 +{
45374 + if (current->signal->curr_ip)
45375 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45376 + &current->signal->curr_ip, current->comm, task_pid_nr(current), current_uid(), current_euid());
45377 + else
45378 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
45379 + current->comm, task_pid_nr(current), current_uid(), current_euid());
45380 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
45381 + show_regs(regs);
45382 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
45383 +}
45384 +#endif
45385 +
45386 +#ifdef CONFIG_PAX_USERCOPY
45387 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
45388 +static noinline int check_stack_object(const void *obj, unsigned long len)
45389 +{
45390 + const void * const stack = task_stack_page(current);
45391 + const void * const stackend = stack + THREAD_SIZE;
45392 +
45393 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45394 + const void *frame = NULL;
45395 + const void *oldframe;
45396 +#endif
45397 +
45398 + if (obj + len < obj)
45399 + return -1;
45400 +
45401 + if (obj + len <= stack || stackend <= obj)
45402 + return 0;
45403 +
45404 + if (obj < stack || stackend < obj + len)
45405 + return -1;
45406 +
45407 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
45408 + oldframe = __builtin_frame_address(1);
45409 + if (oldframe)
45410 + frame = __builtin_frame_address(2);
45411 + /*
45412 + low ----------------------------------------------> high
45413 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
45414 + ^----------------^
45415 + allow copies only within here
45416 + */
45417 + while (stack <= frame && frame < stackend) {
45418 + /* if obj + len extends past the last frame, this
45419 + check won't pass and the next frame will be 0,
45420 + causing us to bail out and correctly report
45421 + the copy as invalid
45422 + */
45423 + if (obj + len <= frame)
45424 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
45425 + oldframe = frame;
45426 + frame = *(const void * const *)frame;
45427 + }
45428 + return -1;
45429 +#else
45430 + return 1;
45431 +#endif
45432 +}
45433 +
45434 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to, const char *type)
45435 +{
45436 + if (current->signal->curr_ip)
45437 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45438 + &current->signal->curr_ip, to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45439 + else
45440 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
45441 + to ? "leak" : "overwrite", to ? "from" : "to", ptr, type ? : "unknown", len);
45442 + dump_stack();
45443 + gr_handle_kernel_exploit();
45444 + do_group_exit(SIGKILL);
45445 +}
45446 +#endif
45447 +
45448 +void check_object_size(const void *ptr, unsigned long n, bool to)
45449 +{
45450 +
45451 +#ifdef CONFIG_PAX_USERCOPY
45452 + const char *type;
45453 +
45454 + if (!n)
45455 + return;
45456 +
45457 + type = check_heap_object(ptr, n, to);
45458 + if (!type) {
45459 + if (check_stack_object(ptr, n) != -1)
45460 + return;
45461 + type = "<process stack>";
45462 + }
45463 +
45464 + pax_report_usercopy(ptr, n, to, type);
45465 +#endif
45466 +
45467 +}
45468 +EXPORT_SYMBOL(check_object_size);
45469 +
45470 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
45471 +void pax_track_stack(void)
45472 +{
45473 + unsigned long sp = (unsigned long)&sp;
45474 + if (sp < current_thread_info()->lowest_stack &&
45475 + sp > (unsigned long)task_stack_page(current))
45476 + current_thread_info()->lowest_stack = sp;
45477 +}
45478 +EXPORT_SYMBOL(pax_track_stack);
45479 +#endif
45480 +
45481 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
45482 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
45483 +{
45484 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
45485 + dump_stack();
45486 + do_group_exit(SIGKILL);
45487 +}
45488 +EXPORT_SYMBOL(report_size_overflow);
45489 +#endif
45490 +
45491 static int zap_process(struct task_struct *start, int exit_code)
45492 {
45493 struct task_struct *t;
45494 @@ -2002,17 +2378,17 @@ static void coredump_finish(struct mm_struct *mm)
45495 void set_dumpable(struct mm_struct *mm, int value)
45496 {
45497 switch (value) {
45498 - case 0:
45499 + case SUID_DUMPABLE_DISABLED:
45500 clear_bit(MMF_DUMPABLE, &mm->flags);
45501 smp_wmb();
45502 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
45503 break;
45504 - case 1:
45505 + case SUID_DUMPABLE_ENABLED:
45506 set_bit(MMF_DUMPABLE, &mm->flags);
45507 smp_wmb();
45508 clear_bit(MMF_DUMP_SECURELY, &mm->flags);
45509 break;
45510 - case 2:
45511 + case SUID_DUMPABLE_SAFE:
45512 set_bit(MMF_DUMP_SECURELY, &mm->flags);
45513 smp_wmb();
45514 set_bit(MMF_DUMPABLE, &mm->flags);
45515 @@ -2025,7 +2401,7 @@ static int __get_dumpable(unsigned long mm_flags)
45516 int ret;
45517
45518 ret = mm_flags & MMF_DUMPABLE_MASK;
45519 - return (ret >= 2) ? 2 : ret;
45520 + return (ret > SUID_DUMPABLE_ENABLED) ? SUID_DUMPABLE_SAFE : ret;
45521 }
45522
45523 int get_dumpable(struct mm_struct *mm)
45524 @@ -2040,17 +2416,17 @@ static void wait_for_dump_helpers(struct file *file)
45525 pipe = file->f_path.dentry->d_inode->i_pipe;
45526
45527 pipe_lock(pipe);
45528 - pipe->readers++;
45529 - pipe->writers--;
45530 + atomic_inc(&pipe->readers);
45531 + atomic_dec(&pipe->writers);
45532
45533 - while ((pipe->readers > 1) && (!signal_pending(current))) {
45534 + while ((atomic_read(&pipe->readers) > 1) && (!signal_pending(current))) {
45535 wake_up_interruptible_sync(&pipe->wait);
45536 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
45537 pipe_wait(pipe);
45538 }
45539
45540 - pipe->readers--;
45541 - pipe->writers++;
45542 + atomic_dec(&pipe->readers);
45543 + atomic_inc(&pipe->writers);
45544 pipe_unlock(pipe);
45545
45546 }
45547 @@ -2111,7 +2487,8 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45548 int retval = 0;
45549 int flag = 0;
45550 int ispipe;
45551 - static atomic_t core_dump_count = ATOMIC_INIT(0);
45552 + bool need_nonrelative = false;
45553 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
45554 struct coredump_params cprm = {
45555 .signr = signr,
45556 .regs = regs,
45557 @@ -2126,6 +2503,9 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45558
45559 audit_core_dumps(signr);
45560
45561 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
45562 + gr_handle_brute_attach(current, cprm.mm_flags);
45563 +
45564 binfmt = mm->binfmt;
45565 if (!binfmt || !binfmt->core_dump)
45566 goto fail;
45567 @@ -2136,14 +2516,16 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45568 if (!cred)
45569 goto fail;
45570 /*
45571 - * We cannot trust fsuid as being the "true" uid of the
45572 - * process nor do we know its entire history. We only know it
45573 - * was tainted so we dump it as root in mode 2.
45574 + * We cannot trust fsuid as being the "true" uid of the process
45575 + * nor do we know its entire history. We only know it was tainted
45576 + * so we dump it as root in mode 2, and only into a controlled
45577 + * environment (pipe handler or fully qualified path).
45578 */
45579 - if (__get_dumpable(cprm.mm_flags) == 2) {
45580 + if (__get_dumpable(cprm.mm_flags) == SUID_DUMPABLE_SAFE) {
45581 /* Setuid core dump mode */
45582 flag = O_EXCL; /* Stop rewrite attacks */
45583 cred->fsuid = GLOBAL_ROOT_UID; /* Dump root private */
45584 + need_nonrelative = true;
45585 }
45586
45587 retval = coredump_wait(exit_code, &core_state);
45588 @@ -2193,7 +2575,7 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45589 }
45590 cprm.limit = RLIM_INFINITY;
45591
45592 - dump_count = atomic_inc_return(&core_dump_count);
45593 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
45594 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
45595 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
45596 task_tgid_vnr(current), current->comm);
45597 @@ -2220,9 +2602,19 @@ void do_coredump(long signr, int exit_code, struct pt_regs *regs)
45598 } else {
45599 struct inode *inode;
45600
45601 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
45602 +
45603 if (cprm.limit < binfmt->min_coredump)
45604 goto fail_unlock;
45605
45606 + if (need_nonrelative && cn.corename[0] != '/') {
45607 + printk(KERN_WARNING "Pid %d(%s) can only dump core "\
45608 + "to fully qualified path!\n",
45609 + task_tgid_vnr(current), current->comm);
45610 + printk(KERN_WARNING "Skipping core dump\n");
45611 + goto fail_unlock;
45612 + }
45613 +
45614 cprm.file = filp_open(cn.corename,
45615 O_CREAT | 2 | O_NOFOLLOW | O_LARGEFILE | flag,
45616 0600);
45617 @@ -2263,7 +2655,7 @@ close_fail:
45618 filp_close(cprm.file, NULL);
45619 fail_dropcount:
45620 if (ispipe)
45621 - atomic_dec(&core_dump_count);
45622 + atomic_dec_unchecked(&core_dump_count);
45623 fail_unlock:
45624 kfree(cn.corename);
45625 fail_corename:
45626 @@ -2282,7 +2674,7 @@ fail:
45627 */
45628 int dump_write(struct file *file, const void *addr, int nr)
45629 {
45630 - return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, addr, nr, &file->f_pos) == nr;
45631 + return access_ok(VERIFY_READ, addr, nr) && file->f_op->write(file, (const char __force_user *)addr, nr, &file->f_pos) == nr;
45632 }
45633 EXPORT_SYMBOL(dump_write);
45634
45635 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
45636 index 1c36139..cf6b350 100644
45637 --- a/fs/ext2/balloc.c
45638 +++ b/fs/ext2/balloc.c
45639 @@ -1190,10 +1190,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
45640
45641 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45642 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45643 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45644 + if (free_blocks < root_blocks + 1 &&
45645 !uid_eq(sbi->s_resuid, current_fsuid()) &&
45646 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45647 - !in_group_p (sbi->s_resgid))) {
45648 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45649 return 0;
45650 }
45651 return 1;
45652 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
45653 index 25cd608..9ed5294 100644
45654 --- a/fs/ext3/balloc.c
45655 +++ b/fs/ext3/balloc.c
45656 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
45657
45658 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
45659 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
45660 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
45661 + if (free_blocks < root_blocks + 1 &&
45662 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
45663 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
45664 - !in_group_p (sbi->s_resgid))) {
45665 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
45666 return 0;
45667 }
45668 return 1;
45669 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
45670 index 1b50890..e56c5ad 100644
45671 --- a/fs/ext4/balloc.c
45672 +++ b/fs/ext4/balloc.c
45673 @@ -500,8 +500,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
45674 /* Hm, nope. Are (enough) root reserved clusters available? */
45675 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
45676 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
45677 - capable(CAP_SYS_RESOURCE) ||
45678 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
45679 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
45680 + capable_nolog(CAP_SYS_RESOURCE)) {
45681
45682 if (free_clusters >= (nclusters + dirty_clusters))
45683 return 1;
45684 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
45685 index 01434f2..bd995b4 100644
45686 --- a/fs/ext4/ext4.h
45687 +++ b/fs/ext4/ext4.h
45688 @@ -1246,19 +1246,19 @@ struct ext4_sb_info {
45689 unsigned long s_mb_last_start;
45690
45691 /* stats for buddy allocator */
45692 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
45693 - atomic_t s_bal_success; /* we found long enough chunks */
45694 - atomic_t s_bal_allocated; /* in blocks */
45695 - atomic_t s_bal_ex_scanned; /* total extents scanned */
45696 - atomic_t s_bal_goals; /* goal hits */
45697 - atomic_t s_bal_breaks; /* too long searches */
45698 - atomic_t s_bal_2orders; /* 2^order hits */
45699 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
45700 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
45701 + atomic_unchecked_t s_bal_allocated; /* in blocks */
45702 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
45703 + atomic_unchecked_t s_bal_goals; /* goal hits */
45704 + atomic_unchecked_t s_bal_breaks; /* too long searches */
45705 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
45706 spinlock_t s_bal_lock;
45707 unsigned long s_mb_buddies_generated;
45708 unsigned long long s_mb_generation_time;
45709 - atomic_t s_mb_lost_chunks;
45710 - atomic_t s_mb_preallocated;
45711 - atomic_t s_mb_discarded;
45712 + atomic_unchecked_t s_mb_lost_chunks;
45713 + atomic_unchecked_t s_mb_preallocated;
45714 + atomic_unchecked_t s_mb_discarded;
45715 atomic_t s_lock_busy;
45716
45717 /* locality groups */
45718 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
45719 index 1cd6994..5799d45 100644
45720 --- a/fs/ext4/mballoc.c
45721 +++ b/fs/ext4/mballoc.c
45722 @@ -1747,7 +1747,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
45723 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
45724
45725 if (EXT4_SB(sb)->s_mb_stats)
45726 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
45727 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
45728
45729 break;
45730 }
45731 @@ -2041,7 +2041,7 @@ repeat:
45732 ac->ac_status = AC_STATUS_CONTINUE;
45733 ac->ac_flags |= EXT4_MB_HINT_FIRST;
45734 cr = 3;
45735 - atomic_inc(&sbi->s_mb_lost_chunks);
45736 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
45737 goto repeat;
45738 }
45739 }
45740 @@ -2545,25 +2545,25 @@ int ext4_mb_release(struct super_block *sb)
45741 if (sbi->s_mb_stats) {
45742 ext4_msg(sb, KERN_INFO,
45743 "mballoc: %u blocks %u reqs (%u success)",
45744 - atomic_read(&sbi->s_bal_allocated),
45745 - atomic_read(&sbi->s_bal_reqs),
45746 - atomic_read(&sbi->s_bal_success));
45747 + atomic_read_unchecked(&sbi->s_bal_allocated),
45748 + atomic_read_unchecked(&sbi->s_bal_reqs),
45749 + atomic_read_unchecked(&sbi->s_bal_success));
45750 ext4_msg(sb, KERN_INFO,
45751 "mballoc: %u extents scanned, %u goal hits, "
45752 "%u 2^N hits, %u breaks, %u lost",
45753 - atomic_read(&sbi->s_bal_ex_scanned),
45754 - atomic_read(&sbi->s_bal_goals),
45755 - atomic_read(&sbi->s_bal_2orders),
45756 - atomic_read(&sbi->s_bal_breaks),
45757 - atomic_read(&sbi->s_mb_lost_chunks));
45758 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
45759 + atomic_read_unchecked(&sbi->s_bal_goals),
45760 + atomic_read_unchecked(&sbi->s_bal_2orders),
45761 + atomic_read_unchecked(&sbi->s_bal_breaks),
45762 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
45763 ext4_msg(sb, KERN_INFO,
45764 "mballoc: %lu generated and it took %Lu",
45765 sbi->s_mb_buddies_generated,
45766 sbi->s_mb_generation_time);
45767 ext4_msg(sb, KERN_INFO,
45768 "mballoc: %u preallocated, %u discarded",
45769 - atomic_read(&sbi->s_mb_preallocated),
45770 - atomic_read(&sbi->s_mb_discarded));
45771 + atomic_read_unchecked(&sbi->s_mb_preallocated),
45772 + atomic_read_unchecked(&sbi->s_mb_discarded));
45773 }
45774
45775 free_percpu(sbi->s_locality_groups);
45776 @@ -3047,16 +3047,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
45777 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
45778
45779 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
45780 - atomic_inc(&sbi->s_bal_reqs);
45781 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45782 + atomic_inc_unchecked(&sbi->s_bal_reqs);
45783 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
45784 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
45785 - atomic_inc(&sbi->s_bal_success);
45786 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
45787 + atomic_inc_unchecked(&sbi->s_bal_success);
45788 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
45789 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
45790 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
45791 - atomic_inc(&sbi->s_bal_goals);
45792 + atomic_inc_unchecked(&sbi->s_bal_goals);
45793 if (ac->ac_found > sbi->s_mb_max_to_scan)
45794 - atomic_inc(&sbi->s_bal_breaks);
45795 + atomic_inc_unchecked(&sbi->s_bal_breaks);
45796 }
45797
45798 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
45799 @@ -3456,7 +3456,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
45800 trace_ext4_mb_new_inode_pa(ac, pa);
45801
45802 ext4_mb_use_inode_pa(ac, pa);
45803 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
45804 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
45805
45806 ei = EXT4_I(ac->ac_inode);
45807 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45808 @@ -3516,7 +3516,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
45809 trace_ext4_mb_new_group_pa(ac, pa);
45810
45811 ext4_mb_use_group_pa(ac, pa);
45812 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45813 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
45814
45815 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
45816 lg = ac->ac_lg;
45817 @@ -3605,7 +3605,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
45818 * from the bitmap and continue.
45819 */
45820 }
45821 - atomic_add(free, &sbi->s_mb_discarded);
45822 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
45823
45824 return err;
45825 }
45826 @@ -3623,7 +3623,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
45827 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
45828 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
45829 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
45830 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45831 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
45832 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
45833
45834 return 0;
45835 diff --git a/fs/fcntl.c b/fs/fcntl.c
45836 index 81b70e6..d9ae6cf 100644
45837 --- a/fs/fcntl.c
45838 +++ b/fs/fcntl.c
45839 @@ -224,6 +224,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
45840 if (err)
45841 return err;
45842
45843 + if (gr_handle_chroot_fowner(pid, type))
45844 + return -ENOENT;
45845 + if (gr_check_protected_task_fowner(pid, type))
45846 + return -EACCES;
45847 +
45848 f_modown(filp, pid, type, force);
45849 return 0;
45850 }
45851 @@ -266,7 +271,7 @@ pid_t f_getown(struct file *filp)
45852
45853 static int f_setown_ex(struct file *filp, unsigned long arg)
45854 {
45855 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45856 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45857 struct f_owner_ex owner;
45858 struct pid *pid;
45859 int type;
45860 @@ -306,7 +311,7 @@ static int f_setown_ex(struct file *filp, unsigned long arg)
45861
45862 static int f_getown_ex(struct file *filp, unsigned long arg)
45863 {
45864 - struct f_owner_ex * __user owner_p = (void * __user)arg;
45865 + struct f_owner_ex __user *owner_p = (void __user *)arg;
45866 struct f_owner_ex owner;
45867 int ret = 0;
45868
45869 @@ -348,6 +353,7 @@ static long do_fcntl(int fd, unsigned int cmd, unsigned long arg,
45870 switch (cmd) {
45871 case F_DUPFD:
45872 case F_DUPFD_CLOEXEC:
45873 + gr_learn_resource(current, RLIMIT_NOFILE, arg, 0);
45874 if (arg >= rlimit(RLIMIT_NOFILE))
45875 break;
45876 err = alloc_fd(arg, cmd == F_DUPFD_CLOEXEC ? O_CLOEXEC : 0);
45877 diff --git a/fs/fifo.c b/fs/fifo.c
45878 index cf6f434..3d7942c 100644
45879 --- a/fs/fifo.c
45880 +++ b/fs/fifo.c
45881 @@ -59,10 +59,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
45882 */
45883 filp->f_op = &read_pipefifo_fops;
45884 pipe->r_counter++;
45885 - if (pipe->readers++ == 0)
45886 + if (atomic_inc_return(&pipe->readers) == 1)
45887 wake_up_partner(inode);
45888
45889 - if (!pipe->writers) {
45890 + if (!atomic_read(&pipe->writers)) {
45891 if ((filp->f_flags & O_NONBLOCK)) {
45892 /* suppress POLLHUP until we have
45893 * seen a writer */
45894 @@ -81,15 +81,15 @@ static int fifo_open(struct inode *inode, struct file *filp)
45895 * errno=ENXIO when there is no process reading the FIFO.
45896 */
45897 ret = -ENXIO;
45898 - if ((filp->f_flags & O_NONBLOCK) && !pipe->readers)
45899 + if ((filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
45900 goto err;
45901
45902 filp->f_op = &write_pipefifo_fops;
45903 pipe->w_counter++;
45904 - if (!pipe->writers++)
45905 + if (atomic_inc_return(&pipe->writers) == 1)
45906 wake_up_partner(inode);
45907
45908 - if (!pipe->readers) {
45909 + if (!atomic_read(&pipe->readers)) {
45910 if (wait_for_partner(inode, &pipe->r_counter))
45911 goto err_wr;
45912 }
45913 @@ -104,11 +104,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
45914 */
45915 filp->f_op = &rdwr_pipefifo_fops;
45916
45917 - pipe->readers++;
45918 - pipe->writers++;
45919 + atomic_inc(&pipe->readers);
45920 + atomic_inc(&pipe->writers);
45921 pipe->r_counter++;
45922 pipe->w_counter++;
45923 - if (pipe->readers == 1 || pipe->writers == 1)
45924 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
45925 wake_up_partner(inode);
45926 break;
45927
45928 @@ -122,19 +122,19 @@ static int fifo_open(struct inode *inode, struct file *filp)
45929 return 0;
45930
45931 err_rd:
45932 - if (!--pipe->readers)
45933 + if (atomic_dec_and_test(&pipe->readers))
45934 wake_up_interruptible(&pipe->wait);
45935 ret = -ERESTARTSYS;
45936 goto err;
45937
45938 err_wr:
45939 - if (!--pipe->writers)
45940 + if (atomic_dec_and_test(&pipe->writers))
45941 wake_up_interruptible(&pipe->wait);
45942 ret = -ERESTARTSYS;
45943 goto err;
45944
45945 err:
45946 - if (!pipe->readers && !pipe->writers)
45947 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers))
45948 free_pipe_info(inode);
45949
45950 err_nocleanup:
45951 diff --git a/fs/file.c b/fs/file.c
45952 index ba3f605..fade102 100644
45953 --- a/fs/file.c
45954 +++ b/fs/file.c
45955 @@ -15,6 +15,7 @@
45956 #include <linux/slab.h>
45957 #include <linux/vmalloc.h>
45958 #include <linux/file.h>
45959 +#include <linux/security.h>
45960 #include <linux/fdtable.h>
45961 #include <linux/bitops.h>
45962 #include <linux/interrupt.h>
45963 @@ -255,6 +256,7 @@ int expand_files(struct files_struct *files, int nr)
45964 * N.B. For clone tasks sharing a files structure, this test
45965 * will limit the total number of files that can be opened.
45966 */
45967 + gr_learn_resource(current, RLIMIT_NOFILE, nr, 0);
45968 if (nr >= rlimit(RLIMIT_NOFILE))
45969 return -EMFILE;
45970
45971 diff --git a/fs/filesystems.c b/fs/filesystems.c
45972 index 96f2428..f5eeb8e 100644
45973 --- a/fs/filesystems.c
45974 +++ b/fs/filesystems.c
45975 @@ -273,7 +273,12 @@ struct file_system_type *get_fs_type(const char *name)
45976 int len = dot ? dot - name : strlen(name);
45977
45978 fs = __get_fs_type(name, len);
45979 +
45980 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
45981 + if (!fs && (___request_module(true, "grsec_modharden_fs", "%.*s", len, name) == 0))
45982 +#else
45983 if (!fs && (request_module("%.*s", len, name) == 0))
45984 +#endif
45985 fs = __get_fs_type(name, len);
45986
45987 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
45988 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
45989 index e159e68..e7d2a6f 100644
45990 --- a/fs/fs_struct.c
45991 +++ b/fs/fs_struct.c
45992 @@ -4,6 +4,7 @@
45993 #include <linux/path.h>
45994 #include <linux/slab.h>
45995 #include <linux/fs_struct.h>
45996 +#include <linux/grsecurity.h>
45997 #include "internal.h"
45998
45999 static inline void path_get_longterm(struct path *path)
46000 @@ -31,6 +32,7 @@ void set_fs_root(struct fs_struct *fs, struct path *path)
46001 write_seqcount_begin(&fs->seq);
46002 old_root = fs->root;
46003 fs->root = *path;
46004 + gr_set_chroot_entries(current, path);
46005 write_seqcount_end(&fs->seq);
46006 spin_unlock(&fs->lock);
46007 if (old_root.dentry)
46008 @@ -65,6 +67,17 @@ static inline int replace_path(struct path *p, const struct path *old, const str
46009 return 1;
46010 }
46011
46012 +static inline int replace_root_path(struct task_struct *task, struct path *p, const struct path *old, struct path *new)
46013 +{
46014 + if (likely(p->dentry != old->dentry || p->mnt != old->mnt))
46015 + return 0;
46016 + *p = *new;
46017 +
46018 + gr_set_chroot_entries(task, new);
46019 +
46020 + return 1;
46021 +}
46022 +
46023 void chroot_fs_refs(struct path *old_root, struct path *new_root)
46024 {
46025 struct task_struct *g, *p;
46026 @@ -79,7 +92,7 @@ void chroot_fs_refs(struct path *old_root, struct path *new_root)
46027 int hits = 0;
46028 spin_lock(&fs->lock);
46029 write_seqcount_begin(&fs->seq);
46030 - hits += replace_path(&fs->root, old_root, new_root);
46031 + hits += replace_root_path(p, &fs->root, old_root, new_root);
46032 hits += replace_path(&fs->pwd, old_root, new_root);
46033 write_seqcount_end(&fs->seq);
46034 while (hits--) {
46035 @@ -111,7 +124,8 @@ void exit_fs(struct task_struct *tsk)
46036 task_lock(tsk);
46037 spin_lock(&fs->lock);
46038 tsk->fs = NULL;
46039 - kill = !--fs->users;
46040 + gr_clear_chroot_entries(tsk);
46041 + kill = !atomic_dec_return(&fs->users);
46042 spin_unlock(&fs->lock);
46043 task_unlock(tsk);
46044 if (kill)
46045 @@ -124,7 +138,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46046 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
46047 /* We don't need to lock fs - think why ;-) */
46048 if (fs) {
46049 - fs->users = 1;
46050 + atomic_set(&fs->users, 1);
46051 fs->in_exec = 0;
46052 spin_lock_init(&fs->lock);
46053 seqcount_init(&fs->seq);
46054 @@ -133,6 +147,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
46055 spin_lock(&old->lock);
46056 fs->root = old->root;
46057 path_get_longterm(&fs->root);
46058 + /* instead of calling gr_set_chroot_entries here,
46059 + we call it from every caller of this function
46060 + */
46061 fs->pwd = old->pwd;
46062 path_get_longterm(&fs->pwd);
46063 spin_unlock(&old->lock);
46064 @@ -151,8 +168,9 @@ int unshare_fs_struct(void)
46065
46066 task_lock(current);
46067 spin_lock(&fs->lock);
46068 - kill = !--fs->users;
46069 + kill = !atomic_dec_return(&fs->users);
46070 current->fs = new_fs;
46071 + gr_set_chroot_entries(current, &new_fs->root);
46072 spin_unlock(&fs->lock);
46073 task_unlock(current);
46074
46075 @@ -165,13 +183,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
46076
46077 int current_umask(void)
46078 {
46079 - return current->fs->umask;
46080 + return current->fs->umask | gr_acl_umask();
46081 }
46082 EXPORT_SYMBOL(current_umask);
46083
46084 /* to be mentioned only in INIT_TASK */
46085 struct fs_struct init_fs = {
46086 - .users = 1,
46087 + .users = ATOMIC_INIT(1),
46088 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
46089 .seq = SEQCNT_ZERO,
46090 .umask = 0022,
46091 @@ -187,12 +205,13 @@ void daemonize_fs_struct(void)
46092 task_lock(current);
46093
46094 spin_lock(&init_fs.lock);
46095 - init_fs.users++;
46096 + atomic_inc(&init_fs.users);
46097 spin_unlock(&init_fs.lock);
46098
46099 spin_lock(&fs->lock);
46100 current->fs = &init_fs;
46101 - kill = !--fs->users;
46102 + gr_set_chroot_entries(current, &current->fs->root);
46103 + kill = !atomic_dec_return(&fs->users);
46104 spin_unlock(&fs->lock);
46105
46106 task_unlock(current);
46107 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
46108 index 9905350..02eaec4 100644
46109 --- a/fs/fscache/cookie.c
46110 +++ b/fs/fscache/cookie.c
46111 @@ -68,11 +68,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
46112 parent ? (char *) parent->def->name : "<no-parent>",
46113 def->name, netfs_data);
46114
46115 - fscache_stat(&fscache_n_acquires);
46116 + fscache_stat_unchecked(&fscache_n_acquires);
46117
46118 /* if there's no parent cookie, then we don't create one here either */
46119 if (!parent) {
46120 - fscache_stat(&fscache_n_acquires_null);
46121 + fscache_stat_unchecked(&fscache_n_acquires_null);
46122 _leave(" [no parent]");
46123 return NULL;
46124 }
46125 @@ -87,7 +87,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
46126 /* allocate and initialise a cookie */
46127 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
46128 if (!cookie) {
46129 - fscache_stat(&fscache_n_acquires_oom);
46130 + fscache_stat_unchecked(&fscache_n_acquires_oom);
46131 _leave(" [ENOMEM]");
46132 return NULL;
46133 }
46134 @@ -109,13 +109,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46135
46136 switch (cookie->def->type) {
46137 case FSCACHE_COOKIE_TYPE_INDEX:
46138 - fscache_stat(&fscache_n_cookie_index);
46139 + fscache_stat_unchecked(&fscache_n_cookie_index);
46140 break;
46141 case FSCACHE_COOKIE_TYPE_DATAFILE:
46142 - fscache_stat(&fscache_n_cookie_data);
46143 + fscache_stat_unchecked(&fscache_n_cookie_data);
46144 break;
46145 default:
46146 - fscache_stat(&fscache_n_cookie_special);
46147 + fscache_stat_unchecked(&fscache_n_cookie_special);
46148 break;
46149 }
46150
46151 @@ -126,13 +126,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
46152 if (fscache_acquire_non_index_cookie(cookie) < 0) {
46153 atomic_dec(&parent->n_children);
46154 __fscache_cookie_put(cookie);
46155 - fscache_stat(&fscache_n_acquires_nobufs);
46156 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
46157 _leave(" = NULL");
46158 return NULL;
46159 }
46160 }
46161
46162 - fscache_stat(&fscache_n_acquires_ok);
46163 + fscache_stat_unchecked(&fscache_n_acquires_ok);
46164 _leave(" = %p", cookie);
46165 return cookie;
46166 }
46167 @@ -168,7 +168,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
46168 cache = fscache_select_cache_for_object(cookie->parent);
46169 if (!cache) {
46170 up_read(&fscache_addremove_sem);
46171 - fscache_stat(&fscache_n_acquires_no_cache);
46172 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
46173 _leave(" = -ENOMEDIUM [no cache]");
46174 return -ENOMEDIUM;
46175 }
46176 @@ -256,12 +256,12 @@ static int fscache_alloc_object(struct fscache_cache *cache,
46177 object = cache->ops->alloc_object(cache, cookie);
46178 fscache_stat_d(&fscache_n_cop_alloc_object);
46179 if (IS_ERR(object)) {
46180 - fscache_stat(&fscache_n_object_no_alloc);
46181 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
46182 ret = PTR_ERR(object);
46183 goto error;
46184 }
46185
46186 - fscache_stat(&fscache_n_object_alloc);
46187 + fscache_stat_unchecked(&fscache_n_object_alloc);
46188
46189 object->debug_id = atomic_inc_return(&fscache_object_debug_id);
46190
46191 @@ -377,10 +377,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
46192 struct fscache_object *object;
46193 struct hlist_node *_p;
46194
46195 - fscache_stat(&fscache_n_updates);
46196 + fscache_stat_unchecked(&fscache_n_updates);
46197
46198 if (!cookie) {
46199 - fscache_stat(&fscache_n_updates_null);
46200 + fscache_stat_unchecked(&fscache_n_updates_null);
46201 _leave(" [no cookie]");
46202 return;
46203 }
46204 @@ -414,12 +414,12 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46205 struct fscache_object *object;
46206 unsigned long event;
46207
46208 - fscache_stat(&fscache_n_relinquishes);
46209 + fscache_stat_unchecked(&fscache_n_relinquishes);
46210 if (retire)
46211 - fscache_stat(&fscache_n_relinquishes_retire);
46212 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
46213
46214 if (!cookie) {
46215 - fscache_stat(&fscache_n_relinquishes_null);
46216 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
46217 _leave(" [no cookie]");
46218 return;
46219 }
46220 @@ -435,7 +435,7 @@ void __fscache_relinquish_cookie(struct fscache_cookie *cookie, int retire)
46221
46222 /* wait for the cookie to finish being instantiated (or to fail) */
46223 if (test_bit(FSCACHE_COOKIE_CREATING, &cookie->flags)) {
46224 - fscache_stat(&fscache_n_relinquishes_waitcrt);
46225 + fscache_stat_unchecked(&fscache_n_relinquishes_waitcrt);
46226 wait_on_bit(&cookie->flags, FSCACHE_COOKIE_CREATING,
46227 fscache_wait_bit, TASK_UNINTERRUPTIBLE);
46228 }
46229 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
46230 index f6aad48..88dcf26 100644
46231 --- a/fs/fscache/internal.h
46232 +++ b/fs/fscache/internal.h
46233 @@ -144,94 +144,94 @@ extern void fscache_proc_cleanup(void);
46234 extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
46235 extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
46236
46237 -extern atomic_t fscache_n_op_pend;
46238 -extern atomic_t fscache_n_op_run;
46239 -extern atomic_t fscache_n_op_enqueue;
46240 -extern atomic_t fscache_n_op_deferred_release;
46241 -extern atomic_t fscache_n_op_release;
46242 -extern atomic_t fscache_n_op_gc;
46243 -extern atomic_t fscache_n_op_cancelled;
46244 -extern atomic_t fscache_n_op_rejected;
46245 +extern atomic_unchecked_t fscache_n_op_pend;
46246 +extern atomic_unchecked_t fscache_n_op_run;
46247 +extern atomic_unchecked_t fscache_n_op_enqueue;
46248 +extern atomic_unchecked_t fscache_n_op_deferred_release;
46249 +extern atomic_unchecked_t fscache_n_op_release;
46250 +extern atomic_unchecked_t fscache_n_op_gc;
46251 +extern atomic_unchecked_t fscache_n_op_cancelled;
46252 +extern atomic_unchecked_t fscache_n_op_rejected;
46253
46254 -extern atomic_t fscache_n_attr_changed;
46255 -extern atomic_t fscache_n_attr_changed_ok;
46256 -extern atomic_t fscache_n_attr_changed_nobufs;
46257 -extern atomic_t fscache_n_attr_changed_nomem;
46258 -extern atomic_t fscache_n_attr_changed_calls;
46259 +extern atomic_unchecked_t fscache_n_attr_changed;
46260 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
46261 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
46262 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
46263 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
46264
46265 -extern atomic_t fscache_n_allocs;
46266 -extern atomic_t fscache_n_allocs_ok;
46267 -extern atomic_t fscache_n_allocs_wait;
46268 -extern atomic_t fscache_n_allocs_nobufs;
46269 -extern atomic_t fscache_n_allocs_intr;
46270 -extern atomic_t fscache_n_allocs_object_dead;
46271 -extern atomic_t fscache_n_alloc_ops;
46272 -extern atomic_t fscache_n_alloc_op_waits;
46273 +extern atomic_unchecked_t fscache_n_allocs;
46274 +extern atomic_unchecked_t fscache_n_allocs_ok;
46275 +extern atomic_unchecked_t fscache_n_allocs_wait;
46276 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
46277 +extern atomic_unchecked_t fscache_n_allocs_intr;
46278 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
46279 +extern atomic_unchecked_t fscache_n_alloc_ops;
46280 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
46281
46282 -extern atomic_t fscache_n_retrievals;
46283 -extern atomic_t fscache_n_retrievals_ok;
46284 -extern atomic_t fscache_n_retrievals_wait;
46285 -extern atomic_t fscache_n_retrievals_nodata;
46286 -extern atomic_t fscache_n_retrievals_nobufs;
46287 -extern atomic_t fscache_n_retrievals_intr;
46288 -extern atomic_t fscache_n_retrievals_nomem;
46289 -extern atomic_t fscache_n_retrievals_object_dead;
46290 -extern atomic_t fscache_n_retrieval_ops;
46291 -extern atomic_t fscache_n_retrieval_op_waits;
46292 +extern atomic_unchecked_t fscache_n_retrievals;
46293 +extern atomic_unchecked_t fscache_n_retrievals_ok;
46294 +extern atomic_unchecked_t fscache_n_retrievals_wait;
46295 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
46296 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
46297 +extern atomic_unchecked_t fscache_n_retrievals_intr;
46298 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
46299 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
46300 +extern atomic_unchecked_t fscache_n_retrieval_ops;
46301 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
46302
46303 -extern atomic_t fscache_n_stores;
46304 -extern atomic_t fscache_n_stores_ok;
46305 -extern atomic_t fscache_n_stores_again;
46306 -extern atomic_t fscache_n_stores_nobufs;
46307 -extern atomic_t fscache_n_stores_oom;
46308 -extern atomic_t fscache_n_store_ops;
46309 -extern atomic_t fscache_n_store_calls;
46310 -extern atomic_t fscache_n_store_pages;
46311 -extern atomic_t fscache_n_store_radix_deletes;
46312 -extern atomic_t fscache_n_store_pages_over_limit;
46313 +extern atomic_unchecked_t fscache_n_stores;
46314 +extern atomic_unchecked_t fscache_n_stores_ok;
46315 +extern atomic_unchecked_t fscache_n_stores_again;
46316 +extern atomic_unchecked_t fscache_n_stores_nobufs;
46317 +extern atomic_unchecked_t fscache_n_stores_oom;
46318 +extern atomic_unchecked_t fscache_n_store_ops;
46319 +extern atomic_unchecked_t fscache_n_store_calls;
46320 +extern atomic_unchecked_t fscache_n_store_pages;
46321 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
46322 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
46323
46324 -extern atomic_t fscache_n_store_vmscan_not_storing;
46325 -extern atomic_t fscache_n_store_vmscan_gone;
46326 -extern atomic_t fscache_n_store_vmscan_busy;
46327 -extern atomic_t fscache_n_store_vmscan_cancelled;
46328 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
46329 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
46330 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
46331 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
46332
46333 -extern atomic_t fscache_n_marks;
46334 -extern atomic_t fscache_n_uncaches;
46335 +extern atomic_unchecked_t fscache_n_marks;
46336 +extern atomic_unchecked_t fscache_n_uncaches;
46337
46338 -extern atomic_t fscache_n_acquires;
46339 -extern atomic_t fscache_n_acquires_null;
46340 -extern atomic_t fscache_n_acquires_no_cache;
46341 -extern atomic_t fscache_n_acquires_ok;
46342 -extern atomic_t fscache_n_acquires_nobufs;
46343 -extern atomic_t fscache_n_acquires_oom;
46344 +extern atomic_unchecked_t fscache_n_acquires;
46345 +extern atomic_unchecked_t fscache_n_acquires_null;
46346 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
46347 +extern atomic_unchecked_t fscache_n_acquires_ok;
46348 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
46349 +extern atomic_unchecked_t fscache_n_acquires_oom;
46350
46351 -extern atomic_t fscache_n_updates;
46352 -extern atomic_t fscache_n_updates_null;
46353 -extern atomic_t fscache_n_updates_run;
46354 +extern atomic_unchecked_t fscache_n_updates;
46355 +extern atomic_unchecked_t fscache_n_updates_null;
46356 +extern atomic_unchecked_t fscache_n_updates_run;
46357
46358 -extern atomic_t fscache_n_relinquishes;
46359 -extern atomic_t fscache_n_relinquishes_null;
46360 -extern atomic_t fscache_n_relinquishes_waitcrt;
46361 -extern atomic_t fscache_n_relinquishes_retire;
46362 +extern atomic_unchecked_t fscache_n_relinquishes;
46363 +extern atomic_unchecked_t fscache_n_relinquishes_null;
46364 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
46365 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
46366
46367 -extern atomic_t fscache_n_cookie_index;
46368 -extern atomic_t fscache_n_cookie_data;
46369 -extern atomic_t fscache_n_cookie_special;
46370 +extern atomic_unchecked_t fscache_n_cookie_index;
46371 +extern atomic_unchecked_t fscache_n_cookie_data;
46372 +extern atomic_unchecked_t fscache_n_cookie_special;
46373
46374 -extern atomic_t fscache_n_object_alloc;
46375 -extern atomic_t fscache_n_object_no_alloc;
46376 -extern atomic_t fscache_n_object_lookups;
46377 -extern atomic_t fscache_n_object_lookups_negative;
46378 -extern atomic_t fscache_n_object_lookups_positive;
46379 -extern atomic_t fscache_n_object_lookups_timed_out;
46380 -extern atomic_t fscache_n_object_created;
46381 -extern atomic_t fscache_n_object_avail;
46382 -extern atomic_t fscache_n_object_dead;
46383 +extern atomic_unchecked_t fscache_n_object_alloc;
46384 +extern atomic_unchecked_t fscache_n_object_no_alloc;
46385 +extern atomic_unchecked_t fscache_n_object_lookups;
46386 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
46387 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
46388 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
46389 +extern atomic_unchecked_t fscache_n_object_created;
46390 +extern atomic_unchecked_t fscache_n_object_avail;
46391 +extern atomic_unchecked_t fscache_n_object_dead;
46392
46393 -extern atomic_t fscache_n_checkaux_none;
46394 -extern atomic_t fscache_n_checkaux_okay;
46395 -extern atomic_t fscache_n_checkaux_update;
46396 -extern atomic_t fscache_n_checkaux_obsolete;
46397 +extern atomic_unchecked_t fscache_n_checkaux_none;
46398 +extern atomic_unchecked_t fscache_n_checkaux_okay;
46399 +extern atomic_unchecked_t fscache_n_checkaux_update;
46400 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
46401
46402 extern atomic_t fscache_n_cop_alloc_object;
46403 extern atomic_t fscache_n_cop_lookup_object;
46404 @@ -255,6 +255,11 @@ static inline void fscache_stat(atomic_t *stat)
46405 atomic_inc(stat);
46406 }
46407
46408 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
46409 +{
46410 + atomic_inc_unchecked(stat);
46411 +}
46412 +
46413 static inline void fscache_stat_d(atomic_t *stat)
46414 {
46415 atomic_dec(stat);
46416 @@ -267,6 +272,7 @@ extern const struct file_operations fscache_stats_fops;
46417
46418 #define __fscache_stat(stat) (NULL)
46419 #define fscache_stat(stat) do {} while (0)
46420 +#define fscache_stat_unchecked(stat) do {} while (0)
46421 #define fscache_stat_d(stat) do {} while (0)
46422 #endif
46423
46424 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
46425 index b6b897c..0ffff9c 100644
46426 --- a/fs/fscache/object.c
46427 +++ b/fs/fscache/object.c
46428 @@ -128,7 +128,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46429 /* update the object metadata on disk */
46430 case FSCACHE_OBJECT_UPDATING:
46431 clear_bit(FSCACHE_OBJECT_EV_UPDATE, &object->events);
46432 - fscache_stat(&fscache_n_updates_run);
46433 + fscache_stat_unchecked(&fscache_n_updates_run);
46434 fscache_stat(&fscache_n_cop_update_object);
46435 object->cache->ops->update_object(object);
46436 fscache_stat_d(&fscache_n_cop_update_object);
46437 @@ -217,7 +217,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46438 spin_lock(&object->lock);
46439 object->state = FSCACHE_OBJECT_DEAD;
46440 spin_unlock(&object->lock);
46441 - fscache_stat(&fscache_n_object_dead);
46442 + fscache_stat_unchecked(&fscache_n_object_dead);
46443 goto terminal_transit;
46444
46445 /* handle the parent cache of this object being withdrawn from
46446 @@ -232,7 +232,7 @@ static void fscache_object_state_machine(struct fscache_object *object)
46447 spin_lock(&object->lock);
46448 object->state = FSCACHE_OBJECT_DEAD;
46449 spin_unlock(&object->lock);
46450 - fscache_stat(&fscache_n_object_dead);
46451 + fscache_stat_unchecked(&fscache_n_object_dead);
46452 goto terminal_transit;
46453
46454 /* complain about the object being woken up once it is
46455 @@ -461,7 +461,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46456 parent->cookie->def->name, cookie->def->name,
46457 object->cache->tag->name);
46458
46459 - fscache_stat(&fscache_n_object_lookups);
46460 + fscache_stat_unchecked(&fscache_n_object_lookups);
46461 fscache_stat(&fscache_n_cop_lookup_object);
46462 ret = object->cache->ops->lookup_object(object);
46463 fscache_stat_d(&fscache_n_cop_lookup_object);
46464 @@ -472,7 +472,7 @@ static void fscache_lookup_object(struct fscache_object *object)
46465 if (ret == -ETIMEDOUT) {
46466 /* probably stuck behind another object, so move this one to
46467 * the back of the queue */
46468 - fscache_stat(&fscache_n_object_lookups_timed_out);
46469 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
46470 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46471 }
46472
46473 @@ -495,7 +495,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
46474
46475 spin_lock(&object->lock);
46476 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46477 - fscache_stat(&fscache_n_object_lookups_negative);
46478 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
46479
46480 /* transit here to allow write requests to begin stacking up
46481 * and read requests to begin returning ENODATA */
46482 @@ -541,7 +541,7 @@ void fscache_obtained_object(struct fscache_object *object)
46483 * result, in which case there may be data available */
46484 spin_lock(&object->lock);
46485 if (object->state == FSCACHE_OBJECT_LOOKING_UP) {
46486 - fscache_stat(&fscache_n_object_lookups_positive);
46487 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
46488
46489 clear_bit(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
46490
46491 @@ -555,7 +555,7 @@ void fscache_obtained_object(struct fscache_object *object)
46492 set_bit(FSCACHE_OBJECT_EV_REQUEUE, &object->events);
46493 } else {
46494 ASSERTCMP(object->state, ==, FSCACHE_OBJECT_CREATING);
46495 - fscache_stat(&fscache_n_object_created);
46496 + fscache_stat_unchecked(&fscache_n_object_created);
46497
46498 object->state = FSCACHE_OBJECT_AVAILABLE;
46499 spin_unlock(&object->lock);
46500 @@ -602,7 +602,7 @@ static void fscache_object_available(struct fscache_object *object)
46501 fscache_enqueue_dependents(object);
46502
46503 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
46504 - fscache_stat(&fscache_n_object_avail);
46505 + fscache_stat_unchecked(&fscache_n_object_avail);
46506
46507 _leave("");
46508 }
46509 @@ -861,7 +861,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46510 enum fscache_checkaux result;
46511
46512 if (!object->cookie->def->check_aux) {
46513 - fscache_stat(&fscache_n_checkaux_none);
46514 + fscache_stat_unchecked(&fscache_n_checkaux_none);
46515 return FSCACHE_CHECKAUX_OKAY;
46516 }
46517
46518 @@ -870,17 +870,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
46519 switch (result) {
46520 /* entry okay as is */
46521 case FSCACHE_CHECKAUX_OKAY:
46522 - fscache_stat(&fscache_n_checkaux_okay);
46523 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
46524 break;
46525
46526 /* entry requires update */
46527 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
46528 - fscache_stat(&fscache_n_checkaux_update);
46529 + fscache_stat_unchecked(&fscache_n_checkaux_update);
46530 break;
46531
46532 /* entry requires deletion */
46533 case FSCACHE_CHECKAUX_OBSOLETE:
46534 - fscache_stat(&fscache_n_checkaux_obsolete);
46535 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
46536 break;
46537
46538 default:
46539 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
46540 index 30afdfa..2256596 100644
46541 --- a/fs/fscache/operation.c
46542 +++ b/fs/fscache/operation.c
46543 @@ -17,7 +17,7 @@
46544 #include <linux/slab.h>
46545 #include "internal.h"
46546
46547 -atomic_t fscache_op_debug_id;
46548 +atomic_unchecked_t fscache_op_debug_id;
46549 EXPORT_SYMBOL(fscache_op_debug_id);
46550
46551 /**
46552 @@ -38,7 +38,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
46553 ASSERTCMP(op->object->state, >=, FSCACHE_OBJECT_AVAILABLE);
46554 ASSERTCMP(atomic_read(&op->usage), >, 0);
46555
46556 - fscache_stat(&fscache_n_op_enqueue);
46557 + fscache_stat_unchecked(&fscache_n_op_enqueue);
46558 switch (op->flags & FSCACHE_OP_TYPE) {
46559 case FSCACHE_OP_ASYNC:
46560 _debug("queue async");
46561 @@ -69,7 +69,7 @@ static void fscache_run_op(struct fscache_object *object,
46562 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
46563 if (op->processor)
46564 fscache_enqueue_operation(op);
46565 - fscache_stat(&fscache_n_op_run);
46566 + fscache_stat_unchecked(&fscache_n_op_run);
46567 }
46568
46569 /*
46570 @@ -98,11 +98,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46571 if (object->n_ops > 1) {
46572 atomic_inc(&op->usage);
46573 list_add_tail(&op->pend_link, &object->pending_ops);
46574 - fscache_stat(&fscache_n_op_pend);
46575 + fscache_stat_unchecked(&fscache_n_op_pend);
46576 } else if (!list_empty(&object->pending_ops)) {
46577 atomic_inc(&op->usage);
46578 list_add_tail(&op->pend_link, &object->pending_ops);
46579 - fscache_stat(&fscache_n_op_pend);
46580 + fscache_stat_unchecked(&fscache_n_op_pend);
46581 fscache_start_operations(object);
46582 } else {
46583 ASSERTCMP(object->n_in_progress, ==, 0);
46584 @@ -118,7 +118,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
46585 object->n_exclusive++; /* reads and writes must wait */
46586 atomic_inc(&op->usage);
46587 list_add_tail(&op->pend_link, &object->pending_ops);
46588 - fscache_stat(&fscache_n_op_pend);
46589 + fscache_stat_unchecked(&fscache_n_op_pend);
46590 ret = 0;
46591 } else {
46592 /* not allowed to submit ops in any other state */
46593 @@ -203,11 +203,11 @@ int fscache_submit_op(struct fscache_object *object,
46594 if (object->n_exclusive > 0) {
46595 atomic_inc(&op->usage);
46596 list_add_tail(&op->pend_link, &object->pending_ops);
46597 - fscache_stat(&fscache_n_op_pend);
46598 + fscache_stat_unchecked(&fscache_n_op_pend);
46599 } else if (!list_empty(&object->pending_ops)) {
46600 atomic_inc(&op->usage);
46601 list_add_tail(&op->pend_link, &object->pending_ops);
46602 - fscache_stat(&fscache_n_op_pend);
46603 + fscache_stat_unchecked(&fscache_n_op_pend);
46604 fscache_start_operations(object);
46605 } else {
46606 ASSERTCMP(object->n_exclusive, ==, 0);
46607 @@ -219,12 +219,12 @@ int fscache_submit_op(struct fscache_object *object,
46608 object->n_ops++;
46609 atomic_inc(&op->usage);
46610 list_add_tail(&op->pend_link, &object->pending_ops);
46611 - fscache_stat(&fscache_n_op_pend);
46612 + fscache_stat_unchecked(&fscache_n_op_pend);
46613 ret = 0;
46614 } else if (object->state == FSCACHE_OBJECT_DYING ||
46615 object->state == FSCACHE_OBJECT_LC_DYING ||
46616 object->state == FSCACHE_OBJECT_WITHDRAWING) {
46617 - fscache_stat(&fscache_n_op_rejected);
46618 + fscache_stat_unchecked(&fscache_n_op_rejected);
46619 ret = -ENOBUFS;
46620 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
46621 fscache_report_unexpected_submission(object, op, ostate);
46622 @@ -294,7 +294,7 @@ int fscache_cancel_op(struct fscache_operation *op)
46623
46624 ret = -EBUSY;
46625 if (!list_empty(&op->pend_link)) {
46626 - fscache_stat(&fscache_n_op_cancelled);
46627 + fscache_stat_unchecked(&fscache_n_op_cancelled);
46628 list_del_init(&op->pend_link);
46629 object->n_ops--;
46630 if (test_bit(FSCACHE_OP_EXCLUSIVE, &op->flags))
46631 @@ -331,7 +331,7 @@ void fscache_put_operation(struct fscache_operation *op)
46632 if (test_and_set_bit(FSCACHE_OP_DEAD, &op->flags))
46633 BUG();
46634
46635 - fscache_stat(&fscache_n_op_release);
46636 + fscache_stat_unchecked(&fscache_n_op_release);
46637
46638 if (op->release) {
46639 op->release(op);
46640 @@ -348,7 +348,7 @@ void fscache_put_operation(struct fscache_operation *op)
46641 * lock, and defer it otherwise */
46642 if (!spin_trylock(&object->lock)) {
46643 _debug("defer put");
46644 - fscache_stat(&fscache_n_op_deferred_release);
46645 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
46646
46647 cache = object->cache;
46648 spin_lock(&cache->op_gc_list_lock);
46649 @@ -410,7 +410,7 @@ void fscache_operation_gc(struct work_struct *work)
46650
46651 _debug("GC DEFERRED REL OBJ%x OP%x",
46652 object->debug_id, op->debug_id);
46653 - fscache_stat(&fscache_n_op_gc);
46654 + fscache_stat_unchecked(&fscache_n_op_gc);
46655
46656 ASSERTCMP(atomic_read(&op->usage), ==, 0);
46657
46658 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
46659 index 3f7a59b..cf196cc 100644
46660 --- a/fs/fscache/page.c
46661 +++ b/fs/fscache/page.c
46662 @@ -60,7 +60,7 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46663 val = radix_tree_lookup(&cookie->stores, page->index);
46664 if (!val) {
46665 rcu_read_unlock();
46666 - fscache_stat(&fscache_n_store_vmscan_not_storing);
46667 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
46668 __fscache_uncache_page(cookie, page);
46669 return true;
46670 }
46671 @@ -90,11 +90,11 @@ bool __fscache_maybe_release_page(struct fscache_cookie *cookie,
46672 spin_unlock(&cookie->stores_lock);
46673
46674 if (xpage) {
46675 - fscache_stat(&fscache_n_store_vmscan_cancelled);
46676 - fscache_stat(&fscache_n_store_radix_deletes);
46677 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
46678 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46679 ASSERTCMP(xpage, ==, page);
46680 } else {
46681 - fscache_stat(&fscache_n_store_vmscan_gone);
46682 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
46683 }
46684
46685 wake_up_bit(&cookie->flags, 0);
46686 @@ -107,7 +107,7 @@ page_busy:
46687 /* we might want to wait here, but that could deadlock the allocator as
46688 * the work threads writing to the cache may all end up sleeping
46689 * on memory allocation */
46690 - fscache_stat(&fscache_n_store_vmscan_busy);
46691 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
46692 return false;
46693 }
46694 EXPORT_SYMBOL(__fscache_maybe_release_page);
46695 @@ -131,7 +131,7 @@ static void fscache_end_page_write(struct fscache_object *object,
46696 FSCACHE_COOKIE_STORING_TAG);
46697 if (!radix_tree_tag_get(&cookie->stores, page->index,
46698 FSCACHE_COOKIE_PENDING_TAG)) {
46699 - fscache_stat(&fscache_n_store_radix_deletes);
46700 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
46701 xpage = radix_tree_delete(&cookie->stores, page->index);
46702 }
46703 spin_unlock(&cookie->stores_lock);
46704 @@ -152,7 +152,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
46705
46706 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
46707
46708 - fscache_stat(&fscache_n_attr_changed_calls);
46709 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
46710
46711 if (fscache_object_is_active(object)) {
46712 fscache_stat(&fscache_n_cop_attr_changed);
46713 @@ -177,11 +177,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46714
46715 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46716
46717 - fscache_stat(&fscache_n_attr_changed);
46718 + fscache_stat_unchecked(&fscache_n_attr_changed);
46719
46720 op = kzalloc(sizeof(*op), GFP_KERNEL);
46721 if (!op) {
46722 - fscache_stat(&fscache_n_attr_changed_nomem);
46723 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
46724 _leave(" = -ENOMEM");
46725 return -ENOMEM;
46726 }
46727 @@ -199,7 +199,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46728 if (fscache_submit_exclusive_op(object, op) < 0)
46729 goto nobufs;
46730 spin_unlock(&cookie->lock);
46731 - fscache_stat(&fscache_n_attr_changed_ok);
46732 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
46733 fscache_put_operation(op);
46734 _leave(" = 0");
46735 return 0;
46736 @@ -207,7 +207,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
46737 nobufs:
46738 spin_unlock(&cookie->lock);
46739 kfree(op);
46740 - fscache_stat(&fscache_n_attr_changed_nobufs);
46741 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
46742 _leave(" = %d", -ENOBUFS);
46743 return -ENOBUFS;
46744 }
46745 @@ -243,7 +243,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
46746 /* allocate a retrieval operation and attempt to submit it */
46747 op = kzalloc(sizeof(*op), GFP_NOIO);
46748 if (!op) {
46749 - fscache_stat(&fscache_n_retrievals_nomem);
46750 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46751 return NULL;
46752 }
46753
46754 @@ -271,13 +271,13 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46755 return 0;
46756 }
46757
46758 - fscache_stat(&fscache_n_retrievals_wait);
46759 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
46760
46761 jif = jiffies;
46762 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
46763 fscache_wait_bit_interruptible,
46764 TASK_INTERRUPTIBLE) != 0) {
46765 - fscache_stat(&fscache_n_retrievals_intr);
46766 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46767 _leave(" = -ERESTARTSYS");
46768 return -ERESTARTSYS;
46769 }
46770 @@ -295,8 +295,8 @@ static int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
46771 */
46772 static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46773 struct fscache_retrieval *op,
46774 - atomic_t *stat_op_waits,
46775 - atomic_t *stat_object_dead)
46776 + atomic_unchecked_t *stat_op_waits,
46777 + atomic_unchecked_t *stat_object_dead)
46778 {
46779 int ret;
46780
46781 @@ -304,7 +304,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46782 goto check_if_dead;
46783
46784 _debug(">>> WT");
46785 - fscache_stat(stat_op_waits);
46786 + fscache_stat_unchecked(stat_op_waits);
46787 if (wait_on_bit(&op->op.flags, FSCACHE_OP_WAITING,
46788 fscache_wait_bit_interruptible,
46789 TASK_INTERRUPTIBLE) < 0) {
46790 @@ -321,7 +321,7 @@ static int fscache_wait_for_retrieval_activation(struct fscache_object *object,
46791
46792 check_if_dead:
46793 if (unlikely(fscache_object_is_dead(object))) {
46794 - fscache_stat(stat_object_dead);
46795 + fscache_stat_unchecked(stat_object_dead);
46796 return -ENOBUFS;
46797 }
46798 return 0;
46799 @@ -348,7 +348,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46800
46801 _enter("%p,%p,,,", cookie, page);
46802
46803 - fscache_stat(&fscache_n_retrievals);
46804 + fscache_stat_unchecked(&fscache_n_retrievals);
46805
46806 if (hlist_empty(&cookie->backing_objects))
46807 goto nobufs;
46808 @@ -381,7 +381,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46809 goto nobufs_unlock;
46810 spin_unlock(&cookie->lock);
46811
46812 - fscache_stat(&fscache_n_retrieval_ops);
46813 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46814
46815 /* pin the netfs read context in case we need to do the actual netfs
46816 * read because we've encountered a cache read failure */
46817 @@ -411,15 +411,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
46818
46819 error:
46820 if (ret == -ENOMEM)
46821 - fscache_stat(&fscache_n_retrievals_nomem);
46822 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46823 else if (ret == -ERESTARTSYS)
46824 - fscache_stat(&fscache_n_retrievals_intr);
46825 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46826 else if (ret == -ENODATA)
46827 - fscache_stat(&fscache_n_retrievals_nodata);
46828 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46829 else if (ret < 0)
46830 - fscache_stat(&fscache_n_retrievals_nobufs);
46831 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46832 else
46833 - fscache_stat(&fscache_n_retrievals_ok);
46834 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46835
46836 fscache_put_retrieval(op);
46837 _leave(" = %d", ret);
46838 @@ -429,7 +429,7 @@ nobufs_unlock:
46839 spin_unlock(&cookie->lock);
46840 kfree(op);
46841 nobufs:
46842 - fscache_stat(&fscache_n_retrievals_nobufs);
46843 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46844 _leave(" = -ENOBUFS");
46845 return -ENOBUFS;
46846 }
46847 @@ -467,7 +467,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46848
46849 _enter("%p,,%d,,,", cookie, *nr_pages);
46850
46851 - fscache_stat(&fscache_n_retrievals);
46852 + fscache_stat_unchecked(&fscache_n_retrievals);
46853
46854 if (hlist_empty(&cookie->backing_objects))
46855 goto nobufs;
46856 @@ -497,7 +497,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46857 goto nobufs_unlock;
46858 spin_unlock(&cookie->lock);
46859
46860 - fscache_stat(&fscache_n_retrieval_ops);
46861 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
46862
46863 /* pin the netfs read context in case we need to do the actual netfs
46864 * read because we've encountered a cache read failure */
46865 @@ -527,15 +527,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
46866
46867 error:
46868 if (ret == -ENOMEM)
46869 - fscache_stat(&fscache_n_retrievals_nomem);
46870 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
46871 else if (ret == -ERESTARTSYS)
46872 - fscache_stat(&fscache_n_retrievals_intr);
46873 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
46874 else if (ret == -ENODATA)
46875 - fscache_stat(&fscache_n_retrievals_nodata);
46876 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
46877 else if (ret < 0)
46878 - fscache_stat(&fscache_n_retrievals_nobufs);
46879 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46880 else
46881 - fscache_stat(&fscache_n_retrievals_ok);
46882 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
46883
46884 fscache_put_retrieval(op);
46885 _leave(" = %d", ret);
46886 @@ -545,7 +545,7 @@ nobufs_unlock:
46887 spin_unlock(&cookie->lock);
46888 kfree(op);
46889 nobufs:
46890 - fscache_stat(&fscache_n_retrievals_nobufs);
46891 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
46892 _leave(" = -ENOBUFS");
46893 return -ENOBUFS;
46894 }
46895 @@ -569,7 +569,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46896
46897 _enter("%p,%p,,,", cookie, page);
46898
46899 - fscache_stat(&fscache_n_allocs);
46900 + fscache_stat_unchecked(&fscache_n_allocs);
46901
46902 if (hlist_empty(&cookie->backing_objects))
46903 goto nobufs;
46904 @@ -595,7 +595,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46905 goto nobufs_unlock;
46906 spin_unlock(&cookie->lock);
46907
46908 - fscache_stat(&fscache_n_alloc_ops);
46909 + fscache_stat_unchecked(&fscache_n_alloc_ops);
46910
46911 ret = fscache_wait_for_retrieval_activation(
46912 object, op,
46913 @@ -611,11 +611,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
46914
46915 error:
46916 if (ret == -ERESTARTSYS)
46917 - fscache_stat(&fscache_n_allocs_intr);
46918 + fscache_stat_unchecked(&fscache_n_allocs_intr);
46919 else if (ret < 0)
46920 - fscache_stat(&fscache_n_allocs_nobufs);
46921 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46922 else
46923 - fscache_stat(&fscache_n_allocs_ok);
46924 + fscache_stat_unchecked(&fscache_n_allocs_ok);
46925
46926 fscache_put_retrieval(op);
46927 _leave(" = %d", ret);
46928 @@ -625,7 +625,7 @@ nobufs_unlock:
46929 spin_unlock(&cookie->lock);
46930 kfree(op);
46931 nobufs:
46932 - fscache_stat(&fscache_n_allocs_nobufs);
46933 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
46934 _leave(" = -ENOBUFS");
46935 return -ENOBUFS;
46936 }
46937 @@ -666,7 +666,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46938
46939 spin_lock(&cookie->stores_lock);
46940
46941 - fscache_stat(&fscache_n_store_calls);
46942 + fscache_stat_unchecked(&fscache_n_store_calls);
46943
46944 /* find a page to store */
46945 page = NULL;
46946 @@ -677,7 +677,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46947 page = results[0];
46948 _debug("gang %d [%lx]", n, page->index);
46949 if (page->index > op->store_limit) {
46950 - fscache_stat(&fscache_n_store_pages_over_limit);
46951 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
46952 goto superseded;
46953 }
46954
46955 @@ -689,7 +689,7 @@ static void fscache_write_op(struct fscache_operation *_op)
46956 spin_unlock(&cookie->stores_lock);
46957 spin_unlock(&object->lock);
46958
46959 - fscache_stat(&fscache_n_store_pages);
46960 + fscache_stat_unchecked(&fscache_n_store_pages);
46961 fscache_stat(&fscache_n_cop_write_page);
46962 ret = object->cache->ops->write_page(op, page);
46963 fscache_stat_d(&fscache_n_cop_write_page);
46964 @@ -757,7 +757,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46965 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
46966 ASSERT(PageFsCache(page));
46967
46968 - fscache_stat(&fscache_n_stores);
46969 + fscache_stat_unchecked(&fscache_n_stores);
46970
46971 op = kzalloc(sizeof(*op), GFP_NOIO);
46972 if (!op)
46973 @@ -808,7 +808,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46974 spin_unlock(&cookie->stores_lock);
46975 spin_unlock(&object->lock);
46976
46977 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
46978 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
46979 op->store_limit = object->store_limit;
46980
46981 if (fscache_submit_op(object, &op->op) < 0)
46982 @@ -816,8 +816,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46983
46984 spin_unlock(&cookie->lock);
46985 radix_tree_preload_end();
46986 - fscache_stat(&fscache_n_store_ops);
46987 - fscache_stat(&fscache_n_stores_ok);
46988 + fscache_stat_unchecked(&fscache_n_store_ops);
46989 + fscache_stat_unchecked(&fscache_n_stores_ok);
46990
46991 /* the work queue now carries its own ref on the object */
46992 fscache_put_operation(&op->op);
46993 @@ -825,14 +825,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
46994 return 0;
46995
46996 already_queued:
46997 - fscache_stat(&fscache_n_stores_again);
46998 + fscache_stat_unchecked(&fscache_n_stores_again);
46999 already_pending:
47000 spin_unlock(&cookie->stores_lock);
47001 spin_unlock(&object->lock);
47002 spin_unlock(&cookie->lock);
47003 radix_tree_preload_end();
47004 kfree(op);
47005 - fscache_stat(&fscache_n_stores_ok);
47006 + fscache_stat_unchecked(&fscache_n_stores_ok);
47007 _leave(" = 0");
47008 return 0;
47009
47010 @@ -851,14 +851,14 @@ nobufs:
47011 spin_unlock(&cookie->lock);
47012 radix_tree_preload_end();
47013 kfree(op);
47014 - fscache_stat(&fscache_n_stores_nobufs);
47015 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
47016 _leave(" = -ENOBUFS");
47017 return -ENOBUFS;
47018
47019 nomem_free:
47020 kfree(op);
47021 nomem:
47022 - fscache_stat(&fscache_n_stores_oom);
47023 + fscache_stat_unchecked(&fscache_n_stores_oom);
47024 _leave(" = -ENOMEM");
47025 return -ENOMEM;
47026 }
47027 @@ -876,7 +876,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
47028 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
47029 ASSERTCMP(page, !=, NULL);
47030
47031 - fscache_stat(&fscache_n_uncaches);
47032 + fscache_stat_unchecked(&fscache_n_uncaches);
47033
47034 /* cache withdrawal may beat us to it */
47035 if (!PageFsCache(page))
47036 @@ -929,7 +929,7 @@ void fscache_mark_pages_cached(struct fscache_retrieval *op,
47037 unsigned long loop;
47038
47039 #ifdef CONFIG_FSCACHE_STATS
47040 - atomic_add(pagevec->nr, &fscache_n_marks);
47041 + atomic_add_unchecked(pagevec->nr, &fscache_n_marks);
47042 #endif
47043
47044 for (loop = 0; loop < pagevec->nr; loop++) {
47045 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
47046 index 4765190..2a067f2 100644
47047 --- a/fs/fscache/stats.c
47048 +++ b/fs/fscache/stats.c
47049 @@ -18,95 +18,95 @@
47050 /*
47051 * operation counters
47052 */
47053 -atomic_t fscache_n_op_pend;
47054 -atomic_t fscache_n_op_run;
47055 -atomic_t fscache_n_op_enqueue;
47056 -atomic_t fscache_n_op_requeue;
47057 -atomic_t fscache_n_op_deferred_release;
47058 -atomic_t fscache_n_op_release;
47059 -atomic_t fscache_n_op_gc;
47060 -atomic_t fscache_n_op_cancelled;
47061 -atomic_t fscache_n_op_rejected;
47062 +atomic_unchecked_t fscache_n_op_pend;
47063 +atomic_unchecked_t fscache_n_op_run;
47064 +atomic_unchecked_t fscache_n_op_enqueue;
47065 +atomic_unchecked_t fscache_n_op_requeue;
47066 +atomic_unchecked_t fscache_n_op_deferred_release;
47067 +atomic_unchecked_t fscache_n_op_release;
47068 +atomic_unchecked_t fscache_n_op_gc;
47069 +atomic_unchecked_t fscache_n_op_cancelled;
47070 +atomic_unchecked_t fscache_n_op_rejected;
47071
47072 -atomic_t fscache_n_attr_changed;
47073 -atomic_t fscache_n_attr_changed_ok;
47074 -atomic_t fscache_n_attr_changed_nobufs;
47075 -atomic_t fscache_n_attr_changed_nomem;
47076 -atomic_t fscache_n_attr_changed_calls;
47077 +atomic_unchecked_t fscache_n_attr_changed;
47078 +atomic_unchecked_t fscache_n_attr_changed_ok;
47079 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
47080 +atomic_unchecked_t fscache_n_attr_changed_nomem;
47081 +atomic_unchecked_t fscache_n_attr_changed_calls;
47082
47083 -atomic_t fscache_n_allocs;
47084 -atomic_t fscache_n_allocs_ok;
47085 -atomic_t fscache_n_allocs_wait;
47086 -atomic_t fscache_n_allocs_nobufs;
47087 -atomic_t fscache_n_allocs_intr;
47088 -atomic_t fscache_n_allocs_object_dead;
47089 -atomic_t fscache_n_alloc_ops;
47090 -atomic_t fscache_n_alloc_op_waits;
47091 +atomic_unchecked_t fscache_n_allocs;
47092 +atomic_unchecked_t fscache_n_allocs_ok;
47093 +atomic_unchecked_t fscache_n_allocs_wait;
47094 +atomic_unchecked_t fscache_n_allocs_nobufs;
47095 +atomic_unchecked_t fscache_n_allocs_intr;
47096 +atomic_unchecked_t fscache_n_allocs_object_dead;
47097 +atomic_unchecked_t fscache_n_alloc_ops;
47098 +atomic_unchecked_t fscache_n_alloc_op_waits;
47099
47100 -atomic_t fscache_n_retrievals;
47101 -atomic_t fscache_n_retrievals_ok;
47102 -atomic_t fscache_n_retrievals_wait;
47103 -atomic_t fscache_n_retrievals_nodata;
47104 -atomic_t fscache_n_retrievals_nobufs;
47105 -atomic_t fscache_n_retrievals_intr;
47106 -atomic_t fscache_n_retrievals_nomem;
47107 -atomic_t fscache_n_retrievals_object_dead;
47108 -atomic_t fscache_n_retrieval_ops;
47109 -atomic_t fscache_n_retrieval_op_waits;
47110 +atomic_unchecked_t fscache_n_retrievals;
47111 +atomic_unchecked_t fscache_n_retrievals_ok;
47112 +atomic_unchecked_t fscache_n_retrievals_wait;
47113 +atomic_unchecked_t fscache_n_retrievals_nodata;
47114 +atomic_unchecked_t fscache_n_retrievals_nobufs;
47115 +atomic_unchecked_t fscache_n_retrievals_intr;
47116 +atomic_unchecked_t fscache_n_retrievals_nomem;
47117 +atomic_unchecked_t fscache_n_retrievals_object_dead;
47118 +atomic_unchecked_t fscache_n_retrieval_ops;
47119 +atomic_unchecked_t fscache_n_retrieval_op_waits;
47120
47121 -atomic_t fscache_n_stores;
47122 -atomic_t fscache_n_stores_ok;
47123 -atomic_t fscache_n_stores_again;
47124 -atomic_t fscache_n_stores_nobufs;
47125 -atomic_t fscache_n_stores_oom;
47126 -atomic_t fscache_n_store_ops;
47127 -atomic_t fscache_n_store_calls;
47128 -atomic_t fscache_n_store_pages;
47129 -atomic_t fscache_n_store_radix_deletes;
47130 -atomic_t fscache_n_store_pages_over_limit;
47131 +atomic_unchecked_t fscache_n_stores;
47132 +atomic_unchecked_t fscache_n_stores_ok;
47133 +atomic_unchecked_t fscache_n_stores_again;
47134 +atomic_unchecked_t fscache_n_stores_nobufs;
47135 +atomic_unchecked_t fscache_n_stores_oom;
47136 +atomic_unchecked_t fscache_n_store_ops;
47137 +atomic_unchecked_t fscache_n_store_calls;
47138 +atomic_unchecked_t fscache_n_store_pages;
47139 +atomic_unchecked_t fscache_n_store_radix_deletes;
47140 +atomic_unchecked_t fscache_n_store_pages_over_limit;
47141
47142 -atomic_t fscache_n_store_vmscan_not_storing;
47143 -atomic_t fscache_n_store_vmscan_gone;
47144 -atomic_t fscache_n_store_vmscan_busy;
47145 -atomic_t fscache_n_store_vmscan_cancelled;
47146 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
47147 +atomic_unchecked_t fscache_n_store_vmscan_gone;
47148 +atomic_unchecked_t fscache_n_store_vmscan_busy;
47149 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
47150
47151 -atomic_t fscache_n_marks;
47152 -atomic_t fscache_n_uncaches;
47153 +atomic_unchecked_t fscache_n_marks;
47154 +atomic_unchecked_t fscache_n_uncaches;
47155
47156 -atomic_t fscache_n_acquires;
47157 -atomic_t fscache_n_acquires_null;
47158 -atomic_t fscache_n_acquires_no_cache;
47159 -atomic_t fscache_n_acquires_ok;
47160 -atomic_t fscache_n_acquires_nobufs;
47161 -atomic_t fscache_n_acquires_oom;
47162 +atomic_unchecked_t fscache_n_acquires;
47163 +atomic_unchecked_t fscache_n_acquires_null;
47164 +atomic_unchecked_t fscache_n_acquires_no_cache;
47165 +atomic_unchecked_t fscache_n_acquires_ok;
47166 +atomic_unchecked_t fscache_n_acquires_nobufs;
47167 +atomic_unchecked_t fscache_n_acquires_oom;
47168
47169 -atomic_t fscache_n_updates;
47170 -atomic_t fscache_n_updates_null;
47171 -atomic_t fscache_n_updates_run;
47172 +atomic_unchecked_t fscache_n_updates;
47173 +atomic_unchecked_t fscache_n_updates_null;
47174 +atomic_unchecked_t fscache_n_updates_run;
47175
47176 -atomic_t fscache_n_relinquishes;
47177 -atomic_t fscache_n_relinquishes_null;
47178 -atomic_t fscache_n_relinquishes_waitcrt;
47179 -atomic_t fscache_n_relinquishes_retire;
47180 +atomic_unchecked_t fscache_n_relinquishes;
47181 +atomic_unchecked_t fscache_n_relinquishes_null;
47182 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
47183 +atomic_unchecked_t fscache_n_relinquishes_retire;
47184
47185 -atomic_t fscache_n_cookie_index;
47186 -atomic_t fscache_n_cookie_data;
47187 -atomic_t fscache_n_cookie_special;
47188 +atomic_unchecked_t fscache_n_cookie_index;
47189 +atomic_unchecked_t fscache_n_cookie_data;
47190 +atomic_unchecked_t fscache_n_cookie_special;
47191
47192 -atomic_t fscache_n_object_alloc;
47193 -atomic_t fscache_n_object_no_alloc;
47194 -atomic_t fscache_n_object_lookups;
47195 -atomic_t fscache_n_object_lookups_negative;
47196 -atomic_t fscache_n_object_lookups_positive;
47197 -atomic_t fscache_n_object_lookups_timed_out;
47198 -atomic_t fscache_n_object_created;
47199 -atomic_t fscache_n_object_avail;
47200 -atomic_t fscache_n_object_dead;
47201 +atomic_unchecked_t fscache_n_object_alloc;
47202 +atomic_unchecked_t fscache_n_object_no_alloc;
47203 +atomic_unchecked_t fscache_n_object_lookups;
47204 +atomic_unchecked_t fscache_n_object_lookups_negative;
47205 +atomic_unchecked_t fscache_n_object_lookups_positive;
47206 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
47207 +atomic_unchecked_t fscache_n_object_created;
47208 +atomic_unchecked_t fscache_n_object_avail;
47209 +atomic_unchecked_t fscache_n_object_dead;
47210
47211 -atomic_t fscache_n_checkaux_none;
47212 -atomic_t fscache_n_checkaux_okay;
47213 -atomic_t fscache_n_checkaux_update;
47214 -atomic_t fscache_n_checkaux_obsolete;
47215 +atomic_unchecked_t fscache_n_checkaux_none;
47216 +atomic_unchecked_t fscache_n_checkaux_okay;
47217 +atomic_unchecked_t fscache_n_checkaux_update;
47218 +atomic_unchecked_t fscache_n_checkaux_obsolete;
47219
47220 atomic_t fscache_n_cop_alloc_object;
47221 atomic_t fscache_n_cop_lookup_object;
47222 @@ -133,113 +133,113 @@ static int fscache_stats_show(struct seq_file *m, void *v)
47223 seq_puts(m, "FS-Cache statistics\n");
47224
47225 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
47226 - atomic_read(&fscache_n_cookie_index),
47227 - atomic_read(&fscache_n_cookie_data),
47228 - atomic_read(&fscache_n_cookie_special));
47229 + atomic_read_unchecked(&fscache_n_cookie_index),
47230 + atomic_read_unchecked(&fscache_n_cookie_data),
47231 + atomic_read_unchecked(&fscache_n_cookie_special));
47232
47233 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
47234 - atomic_read(&fscache_n_object_alloc),
47235 - atomic_read(&fscache_n_object_no_alloc),
47236 - atomic_read(&fscache_n_object_avail),
47237 - atomic_read(&fscache_n_object_dead));
47238 + atomic_read_unchecked(&fscache_n_object_alloc),
47239 + atomic_read_unchecked(&fscache_n_object_no_alloc),
47240 + atomic_read_unchecked(&fscache_n_object_avail),
47241 + atomic_read_unchecked(&fscache_n_object_dead));
47242 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
47243 - atomic_read(&fscache_n_checkaux_none),
47244 - atomic_read(&fscache_n_checkaux_okay),
47245 - atomic_read(&fscache_n_checkaux_update),
47246 - atomic_read(&fscache_n_checkaux_obsolete));
47247 + atomic_read_unchecked(&fscache_n_checkaux_none),
47248 + atomic_read_unchecked(&fscache_n_checkaux_okay),
47249 + atomic_read_unchecked(&fscache_n_checkaux_update),
47250 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
47251
47252 seq_printf(m, "Pages : mrk=%u unc=%u\n",
47253 - atomic_read(&fscache_n_marks),
47254 - atomic_read(&fscache_n_uncaches));
47255 + atomic_read_unchecked(&fscache_n_marks),
47256 + atomic_read_unchecked(&fscache_n_uncaches));
47257
47258 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
47259 " oom=%u\n",
47260 - atomic_read(&fscache_n_acquires),
47261 - atomic_read(&fscache_n_acquires_null),
47262 - atomic_read(&fscache_n_acquires_no_cache),
47263 - atomic_read(&fscache_n_acquires_ok),
47264 - atomic_read(&fscache_n_acquires_nobufs),
47265 - atomic_read(&fscache_n_acquires_oom));
47266 + atomic_read_unchecked(&fscache_n_acquires),
47267 + atomic_read_unchecked(&fscache_n_acquires_null),
47268 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
47269 + atomic_read_unchecked(&fscache_n_acquires_ok),
47270 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
47271 + atomic_read_unchecked(&fscache_n_acquires_oom));
47272
47273 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
47274 - atomic_read(&fscache_n_object_lookups),
47275 - atomic_read(&fscache_n_object_lookups_negative),
47276 - atomic_read(&fscache_n_object_lookups_positive),
47277 - atomic_read(&fscache_n_object_created),
47278 - atomic_read(&fscache_n_object_lookups_timed_out));
47279 + atomic_read_unchecked(&fscache_n_object_lookups),
47280 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
47281 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
47282 + atomic_read_unchecked(&fscache_n_object_created),
47283 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
47284
47285 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
47286 - atomic_read(&fscache_n_updates),
47287 - atomic_read(&fscache_n_updates_null),
47288 - atomic_read(&fscache_n_updates_run));
47289 + atomic_read_unchecked(&fscache_n_updates),
47290 + atomic_read_unchecked(&fscache_n_updates_null),
47291 + atomic_read_unchecked(&fscache_n_updates_run));
47292
47293 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
47294 - atomic_read(&fscache_n_relinquishes),
47295 - atomic_read(&fscache_n_relinquishes_null),
47296 - atomic_read(&fscache_n_relinquishes_waitcrt),
47297 - atomic_read(&fscache_n_relinquishes_retire));
47298 + atomic_read_unchecked(&fscache_n_relinquishes),
47299 + atomic_read_unchecked(&fscache_n_relinquishes_null),
47300 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
47301 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
47302
47303 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
47304 - atomic_read(&fscache_n_attr_changed),
47305 - atomic_read(&fscache_n_attr_changed_ok),
47306 - atomic_read(&fscache_n_attr_changed_nobufs),
47307 - atomic_read(&fscache_n_attr_changed_nomem),
47308 - atomic_read(&fscache_n_attr_changed_calls));
47309 + atomic_read_unchecked(&fscache_n_attr_changed),
47310 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
47311 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
47312 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
47313 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
47314
47315 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
47316 - atomic_read(&fscache_n_allocs),
47317 - atomic_read(&fscache_n_allocs_ok),
47318 - atomic_read(&fscache_n_allocs_wait),
47319 - atomic_read(&fscache_n_allocs_nobufs),
47320 - atomic_read(&fscache_n_allocs_intr));
47321 + atomic_read_unchecked(&fscache_n_allocs),
47322 + atomic_read_unchecked(&fscache_n_allocs_ok),
47323 + atomic_read_unchecked(&fscache_n_allocs_wait),
47324 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
47325 + atomic_read_unchecked(&fscache_n_allocs_intr));
47326 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
47327 - atomic_read(&fscache_n_alloc_ops),
47328 - atomic_read(&fscache_n_alloc_op_waits),
47329 - atomic_read(&fscache_n_allocs_object_dead));
47330 + atomic_read_unchecked(&fscache_n_alloc_ops),
47331 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
47332 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
47333
47334 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
47335 " int=%u oom=%u\n",
47336 - atomic_read(&fscache_n_retrievals),
47337 - atomic_read(&fscache_n_retrievals_ok),
47338 - atomic_read(&fscache_n_retrievals_wait),
47339 - atomic_read(&fscache_n_retrievals_nodata),
47340 - atomic_read(&fscache_n_retrievals_nobufs),
47341 - atomic_read(&fscache_n_retrievals_intr),
47342 - atomic_read(&fscache_n_retrievals_nomem));
47343 + atomic_read_unchecked(&fscache_n_retrievals),
47344 + atomic_read_unchecked(&fscache_n_retrievals_ok),
47345 + atomic_read_unchecked(&fscache_n_retrievals_wait),
47346 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
47347 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
47348 + atomic_read_unchecked(&fscache_n_retrievals_intr),
47349 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
47350 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
47351 - atomic_read(&fscache_n_retrieval_ops),
47352 - atomic_read(&fscache_n_retrieval_op_waits),
47353 - atomic_read(&fscache_n_retrievals_object_dead));
47354 + atomic_read_unchecked(&fscache_n_retrieval_ops),
47355 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
47356 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
47357
47358 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
47359 - atomic_read(&fscache_n_stores),
47360 - atomic_read(&fscache_n_stores_ok),
47361 - atomic_read(&fscache_n_stores_again),
47362 - atomic_read(&fscache_n_stores_nobufs),
47363 - atomic_read(&fscache_n_stores_oom));
47364 + atomic_read_unchecked(&fscache_n_stores),
47365 + atomic_read_unchecked(&fscache_n_stores_ok),
47366 + atomic_read_unchecked(&fscache_n_stores_again),
47367 + atomic_read_unchecked(&fscache_n_stores_nobufs),
47368 + atomic_read_unchecked(&fscache_n_stores_oom));
47369 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
47370 - atomic_read(&fscache_n_store_ops),
47371 - atomic_read(&fscache_n_store_calls),
47372 - atomic_read(&fscache_n_store_pages),
47373 - atomic_read(&fscache_n_store_radix_deletes),
47374 - atomic_read(&fscache_n_store_pages_over_limit));
47375 + atomic_read_unchecked(&fscache_n_store_ops),
47376 + atomic_read_unchecked(&fscache_n_store_calls),
47377 + atomic_read_unchecked(&fscache_n_store_pages),
47378 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
47379 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
47380
47381 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u\n",
47382 - atomic_read(&fscache_n_store_vmscan_not_storing),
47383 - atomic_read(&fscache_n_store_vmscan_gone),
47384 - atomic_read(&fscache_n_store_vmscan_busy),
47385 - atomic_read(&fscache_n_store_vmscan_cancelled));
47386 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
47387 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
47388 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
47389 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled));
47390
47391 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
47392 - atomic_read(&fscache_n_op_pend),
47393 - atomic_read(&fscache_n_op_run),
47394 - atomic_read(&fscache_n_op_enqueue),
47395 - atomic_read(&fscache_n_op_cancelled),
47396 - atomic_read(&fscache_n_op_rejected));
47397 + atomic_read_unchecked(&fscache_n_op_pend),
47398 + atomic_read_unchecked(&fscache_n_op_run),
47399 + atomic_read_unchecked(&fscache_n_op_enqueue),
47400 + atomic_read_unchecked(&fscache_n_op_cancelled),
47401 + atomic_read_unchecked(&fscache_n_op_rejected));
47402 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
47403 - atomic_read(&fscache_n_op_deferred_release),
47404 - atomic_read(&fscache_n_op_release),
47405 - atomic_read(&fscache_n_op_gc));
47406 + atomic_read_unchecked(&fscache_n_op_deferred_release),
47407 + atomic_read_unchecked(&fscache_n_op_release),
47408 + atomic_read_unchecked(&fscache_n_op_gc));
47409
47410 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
47411 atomic_read(&fscache_n_cop_alloc_object),
47412 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
47413 index 3426521..3b75162 100644
47414 --- a/fs/fuse/cuse.c
47415 +++ b/fs/fuse/cuse.c
47416 @@ -587,10 +587,12 @@ static int __init cuse_init(void)
47417 INIT_LIST_HEAD(&cuse_conntbl[i]);
47418
47419 /* inherit and extend fuse_dev_operations */
47420 - cuse_channel_fops = fuse_dev_operations;
47421 - cuse_channel_fops.owner = THIS_MODULE;
47422 - cuse_channel_fops.open = cuse_channel_open;
47423 - cuse_channel_fops.release = cuse_channel_release;
47424 + pax_open_kernel();
47425 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
47426 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
47427 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
47428 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
47429 + pax_close_kernel();
47430
47431 cuse_class = class_create(THIS_MODULE, "cuse");
47432 if (IS_ERR(cuse_class))
47433 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
47434 index f4246cf..b4aed1d 100644
47435 --- a/fs/fuse/dev.c
47436 +++ b/fs/fuse/dev.c
47437 @@ -1242,7 +1242,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
47438 ret = 0;
47439 pipe_lock(pipe);
47440
47441 - if (!pipe->readers) {
47442 + if (!atomic_read(&pipe->readers)) {
47443 send_sig(SIGPIPE, current, 0);
47444 if (!ret)
47445 ret = -EPIPE;
47446 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
47447 index 334e0b1..fc571e8 100644
47448 --- a/fs/fuse/dir.c
47449 +++ b/fs/fuse/dir.c
47450 @@ -1189,7 +1189,7 @@ static char *read_link(struct dentry *dentry)
47451 return link;
47452 }
47453
47454 -static void free_link(char *link)
47455 +static void free_link(const char *link)
47456 {
47457 if (!IS_ERR(link))
47458 free_page((unsigned long) link);
47459 diff --git a/fs/gfs2/inode.c b/fs/gfs2/inode.c
47460 index a9ba244..d9df391 100644
47461 --- a/fs/gfs2/inode.c
47462 +++ b/fs/gfs2/inode.c
47463 @@ -1496,7 +1496,7 @@ out:
47464
47465 static void gfs2_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
47466 {
47467 - char *s = nd_get_link(nd);
47468 + const char *s = nd_get_link(nd);
47469 if (!IS_ERR(s))
47470 kfree(s);
47471 }
47472 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
47473 index cc9281b..58996fb 100644
47474 --- a/fs/hugetlbfs/inode.c
47475 +++ b/fs/hugetlbfs/inode.c
47476 @@ -920,7 +920,7 @@ static struct file_system_type hugetlbfs_fs_type = {
47477 .kill_sb = kill_litter_super,
47478 };
47479
47480 -static struct vfsmount *hugetlbfs_vfsmount;
47481 +struct vfsmount *hugetlbfs_vfsmount;
47482
47483 static int can_do_hugetlb_shm(void)
47484 {
47485 diff --git a/fs/inode.c b/fs/inode.c
47486 index c99163b..a11ad40 100644
47487 --- a/fs/inode.c
47488 +++ b/fs/inode.c
47489 @@ -867,8 +867,8 @@ unsigned int get_next_ino(void)
47490
47491 #ifdef CONFIG_SMP
47492 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
47493 - static atomic_t shared_last_ino;
47494 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
47495 + static atomic_unchecked_t shared_last_ino;
47496 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
47497
47498 res = next - LAST_INO_BATCH;
47499 }
47500 diff --git a/fs/isofs/export.c b/fs/isofs/export.c
47501 index aa4356d..1d38044 100644
47502 --- a/fs/isofs/export.c
47503 +++ b/fs/isofs/export.c
47504 @@ -134,6 +134,7 @@ isofs_export_encode_fh(struct inode *inode,
47505 len = 3;
47506 fh32[0] = ei->i_iget5_block;
47507 fh16[2] = (__u16)ei->i_iget5_offset; /* fh16 [sic] */
47508 + fh16[3] = 0; /* avoid leaking uninitialized data */
47509 fh32[2] = inode->i_generation;
47510 if (parent) {
47511 struct iso_inode_info *eparent;
47512 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
47513 index 4a6cf28..d3a29d3 100644
47514 --- a/fs/jffs2/erase.c
47515 +++ b/fs/jffs2/erase.c
47516 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
47517 struct jffs2_unknown_node marker = {
47518 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
47519 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47520 - .totlen = cpu_to_je32(c->cleanmarker_size)
47521 + .totlen = cpu_to_je32(c->cleanmarker_size),
47522 + .hdr_crc = cpu_to_je32(0)
47523 };
47524
47525 jffs2_prealloc_raw_node_refs(c, jeb, 1);
47526 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
47527 index 6f4529d..bf12806 100644
47528 --- a/fs/jffs2/wbuf.c
47529 +++ b/fs/jffs2/wbuf.c
47530 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
47531 {
47532 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
47533 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
47534 - .totlen = constant_cpu_to_je32(8)
47535 + .totlen = constant_cpu_to_je32(8),
47536 + .hdr_crc = constant_cpu_to_je32(0)
47537 };
47538
47539 /*
47540 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
47541 index 4a82950..bcaa0cb 100644
47542 --- a/fs/jfs/super.c
47543 +++ b/fs/jfs/super.c
47544 @@ -801,7 +801,7 @@ static int __init init_jfs_fs(void)
47545
47546 jfs_inode_cachep =
47547 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
47548 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
47549 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
47550 init_once);
47551 if (jfs_inode_cachep == NULL)
47552 return -ENOMEM;
47553 diff --git a/fs/libfs.c b/fs/libfs.c
47554 index f86ec27..4734776 100644
47555 --- a/fs/libfs.c
47556 +++ b/fs/libfs.c
47557 @@ -165,6 +165,9 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47558
47559 for (p=q->next; p != &dentry->d_subdirs; p=p->next) {
47560 struct dentry *next;
47561 + char d_name[sizeof(next->d_iname)];
47562 + const unsigned char *name;
47563 +
47564 next = list_entry(p, struct dentry, d_u.d_child);
47565 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
47566 if (!simple_positive(next)) {
47567 @@ -174,7 +177,12 @@ int dcache_readdir(struct file * filp, void * dirent, filldir_t filldir)
47568
47569 spin_unlock(&next->d_lock);
47570 spin_unlock(&dentry->d_lock);
47571 - if (filldir(dirent, next->d_name.name,
47572 + name = next->d_name.name;
47573 + if (name == next->d_iname) {
47574 + memcpy(d_name, name, next->d_name.len);
47575 + name = d_name;
47576 + }
47577 + if (filldir(dirent, name,
47578 next->d_name.len, filp->f_pos,
47579 next->d_inode->i_ino,
47580 dt_type(next->d_inode)) < 0)
47581 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
47582 index 8392cb8..80d6193 100644
47583 --- a/fs/lockd/clntproc.c
47584 +++ b/fs/lockd/clntproc.c
47585 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
47586 /*
47587 * Cookie counter for NLM requests
47588 */
47589 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
47590 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
47591
47592 void nlmclnt_next_cookie(struct nlm_cookie *c)
47593 {
47594 - u32 cookie = atomic_inc_return(&nlm_cookie);
47595 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
47596
47597 memcpy(c->data, &cookie, 4);
47598 c->len=4;
47599 diff --git a/fs/locks.c b/fs/locks.c
47600 index 82c3533..34e929c 100644
47601 --- a/fs/locks.c
47602 +++ b/fs/locks.c
47603 @@ -2076,16 +2076,16 @@ void locks_remove_flock(struct file *filp)
47604 return;
47605
47606 if (filp->f_op && filp->f_op->flock) {
47607 - struct file_lock fl = {
47608 + struct file_lock flock = {
47609 .fl_pid = current->tgid,
47610 .fl_file = filp,
47611 .fl_flags = FL_FLOCK,
47612 .fl_type = F_UNLCK,
47613 .fl_end = OFFSET_MAX,
47614 };
47615 - filp->f_op->flock(filp, F_SETLKW, &fl);
47616 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
47617 - fl.fl_ops->fl_release_private(&fl);
47618 + filp->f_op->flock(filp, F_SETLKW, &flock);
47619 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
47620 + flock.fl_ops->fl_release_private(&flock);
47621 }
47622
47623 lock_flocks();
47624 diff --git a/fs/namei.c b/fs/namei.c
47625 index 7d69419..c7a09f0 100644
47626 --- a/fs/namei.c
47627 +++ b/fs/namei.c
47628 @@ -265,16 +265,32 @@ int generic_permission(struct inode *inode, int mask)
47629 if (ret != -EACCES)
47630 return ret;
47631
47632 +#ifdef CONFIG_GRKERNSEC
47633 + /* we'll block if we have to log due to a denied capability use */
47634 + if (mask & MAY_NOT_BLOCK)
47635 + return -ECHILD;
47636 +#endif
47637 +
47638 if (S_ISDIR(inode->i_mode)) {
47639 /* DACs are overridable for directories */
47640 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
47641 - return 0;
47642 if (!(mask & MAY_WRITE))
47643 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47644 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47645 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47646 return 0;
47647 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
47648 + return 0;
47649 return -EACCES;
47650 }
47651 /*
47652 + * Searching includes executable on directories, else just read.
47653 + */
47654 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47655 + if (mask == MAY_READ)
47656 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
47657 + inode_capable(inode, CAP_DAC_READ_SEARCH))
47658 + return 0;
47659 +
47660 + /*
47661 * Read/write DACs are always overridable.
47662 * Executable DACs are overridable when there is
47663 * at least one exec bit set.
47664 @@ -283,14 +299,6 @@ int generic_permission(struct inode *inode, int mask)
47665 if (inode_capable(inode, CAP_DAC_OVERRIDE))
47666 return 0;
47667
47668 - /*
47669 - * Searching includes executable on directories, else just read.
47670 - */
47671 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
47672 - if (mask == MAY_READ)
47673 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
47674 - return 0;
47675 -
47676 return -EACCES;
47677 }
47678
47679 @@ -639,11 +647,19 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
47680 return error;
47681 }
47682
47683 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
47684 + dentry->d_inode, dentry, nd->path.mnt)) {
47685 + error = -EACCES;
47686 + *p = ERR_PTR(error); /* no ->put_link(), please */
47687 + path_put(&nd->path);
47688 + return error;
47689 + }
47690 +
47691 nd->last_type = LAST_BIND;
47692 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
47693 error = PTR_ERR(*p);
47694 if (!IS_ERR(*p)) {
47695 - char *s = nd_get_link(nd);
47696 + const char *s = nd_get_link(nd);
47697 error = 0;
47698 if (s)
47699 error = __vfs_follow_link(nd, s);
47700 @@ -1386,6 +1402,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
47701 if (!res)
47702 res = walk_component(nd, path, &nd->last,
47703 nd->last_type, LOOKUP_FOLLOW);
47704 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
47705 + res = -EACCES;
47706 put_link(nd, &link, cookie);
47707 } while (res > 0);
47708
47709 @@ -1779,6 +1797,8 @@ static int path_lookupat(int dfd, const char *name,
47710 err = follow_link(&link, nd, &cookie);
47711 if (!err)
47712 err = lookup_last(nd, &path);
47713 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
47714 + err = -EACCES;
47715 put_link(nd, &link, cookie);
47716 }
47717 }
47718 @@ -1786,6 +1806,21 @@ static int path_lookupat(int dfd, const char *name,
47719 if (!err)
47720 err = complete_walk(nd);
47721
47722 + if (!(nd->flags & LOOKUP_PARENT)) {
47723 +#ifdef CONFIG_GRKERNSEC
47724 + if (flags & LOOKUP_RCU) {
47725 + if (!err)
47726 + path_put(&nd->path);
47727 + err = -ECHILD;
47728 + } else
47729 +#endif
47730 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47731 + if (!err)
47732 + path_put(&nd->path);
47733 + err = -ENOENT;
47734 + }
47735 + }
47736 +
47737 if (!err && nd->flags & LOOKUP_DIRECTORY) {
47738 if (!nd->inode->i_op->lookup) {
47739 path_put(&nd->path);
47740 @@ -1813,6 +1848,15 @@ static int do_path_lookup(int dfd, const char *name,
47741 retval = path_lookupat(dfd, name, flags | LOOKUP_REVAL, nd);
47742
47743 if (likely(!retval)) {
47744 + if (*name != '/' && nd->path.dentry && nd->inode) {
47745 +#ifdef CONFIG_GRKERNSEC
47746 + if (flags & LOOKUP_RCU)
47747 + return -ECHILD;
47748 +#endif
47749 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt))
47750 + return -ENOENT;
47751 + }
47752 +
47753 if (unlikely(!audit_dummy_context())) {
47754 if (nd->path.dentry && nd->inode)
47755 audit_inode(name, nd->path.dentry);
47756 @@ -2155,6 +2199,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
47757 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
47758 return -EPERM;
47759
47760 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
47761 + return -EPERM;
47762 + if (gr_handle_rawio(inode))
47763 + return -EPERM;
47764 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
47765 + return -EACCES;
47766 +
47767 return 0;
47768 }
47769
47770 @@ -2190,7 +2241,7 @@ static inline int open_to_namei_flags(int flag)
47771 /*
47772 * Handle the last step of open()
47773 */
47774 -static struct file *do_last(struct nameidata *nd, struct path *path,
47775 +static struct file *do_last(struct nameidata *nd, struct path *path, struct path *link,
47776 const struct open_flags *op, const char *pathname)
47777 {
47778 struct dentry *dir = nd->path.dentry;
47779 @@ -2220,16 +2271,44 @@ static struct file *do_last(struct nameidata *nd, struct path *path,
47780 error = complete_walk(nd);
47781 if (error)
47782 return ERR_PTR(error);
47783 +#ifdef CONFIG_GRKERNSEC
47784 + if (nd->flags & LOOKUP_RCU) {
47785 + error = -ECHILD;
47786 + goto exit;
47787 + }
47788 +#endif
47789 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47790 + error = -ENOENT;
47791 + goto exit;
47792 + }
47793 audit_inode(pathname, nd->path.dentry);
47794 if (open_flag & O_CREAT) {
47795 error = -EISDIR;
47796 goto exit;
47797 }
47798 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47799 + error = -EACCES;
47800 + goto exit;
47801 + }
47802 goto ok;
47803 case LAST_BIND:
47804 error = complete_walk(nd);
47805 if (error)
47806 return ERR_PTR(error);
47807 +#ifdef CONFIG_GRKERNSEC
47808 + if (nd->flags & LOOKUP_RCU) {
47809 + error = -ECHILD;
47810 + goto exit;
47811 + }
47812 +#endif
47813 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
47814 + error = -ENOENT;
47815 + goto exit;
47816 + }
47817 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47818 + error = -EACCES;
47819 + goto exit;
47820 + }
47821 audit_inode(pathname, dir);
47822 goto ok;
47823 }
47824 @@ -2285,6 +2364,17 @@ retry_lookup:
47825 /* Negative dentry, just create the file */
47826 if (!dentry->d_inode) {
47827 umode_t mode = op->mode;
47828 +
47829 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
47830 + error = -EACCES;
47831 + goto exit_mutex_unlock;
47832 + }
47833 +
47834 + if (!gr_acl_handle_creat(path->dentry, nd->path.dentry, path->mnt, open_flag, acc_mode, mode)) {
47835 + error = -EACCES;
47836 + goto exit_mutex_unlock;
47837 + }
47838 +
47839 if (!IS_POSIXACL(dir->d_inode))
47840 mode &= ~current_umask();
47841 /*
47842 @@ -2308,6 +2398,8 @@ retry_lookup:
47843 error = vfs_create(dir->d_inode, dentry, mode, nd);
47844 if (error)
47845 goto exit_mutex_unlock;
47846 + else
47847 + gr_handle_create(path->dentry, path->mnt);
47848 mutex_unlock(&dir->d_inode->i_mutex);
47849 dput(nd->path.dentry);
47850 nd->path.dentry = dentry;
47851 @@ -2317,6 +2409,23 @@ retry_lookup:
47852 /*
47853 * It already exists.
47854 */
47855 +
47856 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt)) {
47857 + error = -ENOENT;
47858 + goto exit_mutex_unlock;
47859 + }
47860 + if (link && gr_handle_symlink_owner(link, dentry->d_inode)) {
47861 + error = -EACCES;
47862 + goto exit_mutex_unlock;
47863 + }
47864 +
47865 + /* only check if O_CREAT is specified, all other checks need to go
47866 + into may_open */
47867 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
47868 + error = -EACCES;
47869 + goto exit_mutex_unlock;
47870 + }
47871 +
47872 mutex_unlock(&dir->d_inode->i_mutex);
47873 audit_inode(pathname, path->dentry);
47874
47875 @@ -2349,6 +2458,11 @@ finish_lookup:
47876 }
47877 }
47878 BUG_ON(inode != path->dentry->d_inode);
47879 + /* if we're resolving a symlink to another symlink */
47880 + if (link && gr_handle_symlink_owner(link, inode)) {
47881 + error = -EACCES;
47882 + goto exit;
47883 + }
47884 return NULL;
47885 }
47886
47887 @@ -2358,7 +2472,6 @@ finish_lookup:
47888 save_parent.dentry = nd->path.dentry;
47889 save_parent.mnt = mntget(path->mnt);
47890 nd->path.dentry = path->dentry;
47891 -
47892 }
47893 nd->inode = inode;
47894 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
47895 @@ -2367,6 +2480,21 @@ finish_lookup:
47896 path_put(&save_parent);
47897 return ERR_PTR(error);
47898 }
47899 +#ifdef CONFIG_GRKERNSEC
47900 + if (nd->flags & LOOKUP_RCU) {
47901 + error = -ECHILD;
47902 + goto exit;
47903 + }
47904 +#endif
47905 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
47906 + error = -ENOENT;
47907 + goto exit;
47908 + }
47909 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
47910 + error = -EACCES;
47911 + goto exit;
47912 + }
47913 +
47914 error = -EISDIR;
47915 if ((open_flag & O_CREAT) && S_ISDIR(nd->inode->i_mode))
47916 goto exit;
47917 @@ -2461,7 +2589,7 @@ static struct file *path_openat(int dfd, const char *pathname,
47918 if (unlikely(error))
47919 goto out_filp;
47920
47921 - filp = do_last(nd, &path, op, pathname);
47922 + filp = do_last(nd, &path, NULL, op, pathname);
47923 while (unlikely(!filp)) { /* trailing symlink */
47924 struct path link = path;
47925 void *cookie;
47926 @@ -2476,8 +2604,9 @@ static struct file *path_openat(int dfd, const char *pathname,
47927 error = follow_link(&link, nd, &cookie);
47928 if (unlikely(error))
47929 filp = ERR_PTR(error);
47930 - else
47931 - filp = do_last(nd, &path, op, pathname);
47932 + else {
47933 + filp = do_last(nd, &path, &link, op, pathname);
47934 + }
47935 put_link(nd, &link, cookie);
47936 }
47937 out:
47938 @@ -2577,6 +2706,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname, struct path *path
47939 *path = nd.path;
47940 return dentry;
47941 eexist:
47942 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt)) {
47943 + dput(dentry);
47944 + dentry = ERR_PTR(-ENOENT);
47945 + goto fail;
47946 + }
47947 dput(dentry);
47948 dentry = ERR_PTR(-EEXIST);
47949 fail:
47950 @@ -2599,6 +2733,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname, struct pat
47951 }
47952 EXPORT_SYMBOL(user_path_create);
47953
47954 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, char **to, int is_dir)
47955 +{
47956 + char *tmp = getname(pathname);
47957 + struct dentry *res;
47958 + if (IS_ERR(tmp))
47959 + return ERR_CAST(tmp);
47960 + res = kern_path_create(dfd, tmp, path, is_dir);
47961 + if (IS_ERR(res))
47962 + putname(tmp);
47963 + else
47964 + *to = tmp;
47965 + return res;
47966 +}
47967 +
47968 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
47969 {
47970 int error = may_create(dir, dentry);
47971 @@ -2665,6 +2813,17 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47972 error = mnt_want_write(path.mnt);
47973 if (error)
47974 goto out_dput;
47975 +
47976 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
47977 + error = -EPERM;
47978 + goto out_drop_write;
47979 + }
47980 +
47981 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
47982 + error = -EACCES;
47983 + goto out_drop_write;
47984 + }
47985 +
47986 error = security_path_mknod(&path, dentry, mode, dev);
47987 if (error)
47988 goto out_drop_write;
47989 @@ -2682,6 +2841,9 @@ SYSCALL_DEFINE4(mknodat, int, dfd, const char __user *, filename, umode_t, mode,
47990 }
47991 out_drop_write:
47992 mnt_drop_write(path.mnt);
47993 +
47994 + if (!error)
47995 + gr_handle_create(dentry, path.mnt);
47996 out_dput:
47997 dput(dentry);
47998 mutex_unlock(&path.dentry->d_inode->i_mutex);
47999 @@ -2735,12 +2897,21 @@ SYSCALL_DEFINE3(mkdirat, int, dfd, const char __user *, pathname, umode_t, mode)
48000 error = mnt_want_write(path.mnt);
48001 if (error)
48002 goto out_dput;
48003 +
48004 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
48005 + error = -EACCES;
48006 + goto out_drop_write;
48007 + }
48008 +
48009 error = security_path_mkdir(&path, dentry, mode);
48010 if (error)
48011 goto out_drop_write;
48012 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
48013 out_drop_write:
48014 mnt_drop_write(path.mnt);
48015 +
48016 + if (!error)
48017 + gr_handle_create(dentry, path.mnt);
48018 out_dput:
48019 dput(dentry);
48020 mutex_unlock(&path.dentry->d_inode->i_mutex);
48021 @@ -2820,6 +2991,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48022 char * name;
48023 struct dentry *dentry;
48024 struct nameidata nd;
48025 + ino_t saved_ino = 0;
48026 + dev_t saved_dev = 0;
48027
48028 error = user_path_parent(dfd, pathname, &nd, &name);
48029 if (error)
48030 @@ -2848,6 +3021,15 @@ static long do_rmdir(int dfd, const char __user *pathname)
48031 error = -ENOENT;
48032 goto exit3;
48033 }
48034 +
48035 + saved_ino = dentry->d_inode->i_ino;
48036 + saved_dev = gr_get_dev_from_dentry(dentry);
48037 +
48038 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
48039 + error = -EACCES;
48040 + goto exit3;
48041 + }
48042 +
48043 error = mnt_want_write(nd.path.mnt);
48044 if (error)
48045 goto exit3;
48046 @@ -2855,6 +3037,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
48047 if (error)
48048 goto exit4;
48049 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
48050 + if (!error && (saved_dev || saved_ino))
48051 + gr_handle_delete(saved_ino, saved_dev);
48052 exit4:
48053 mnt_drop_write(nd.path.mnt);
48054 exit3:
48055 @@ -2917,6 +3101,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48056 struct dentry *dentry;
48057 struct nameidata nd;
48058 struct inode *inode = NULL;
48059 + ino_t saved_ino = 0;
48060 + dev_t saved_dev = 0;
48061
48062 error = user_path_parent(dfd, pathname, &nd, &name);
48063 if (error)
48064 @@ -2939,6 +3125,16 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48065 if (!inode)
48066 goto slashes;
48067 ihold(inode);
48068 +
48069 + if (inode->i_nlink <= 1) {
48070 + saved_ino = inode->i_ino;
48071 + saved_dev = gr_get_dev_from_dentry(dentry);
48072 + }
48073 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
48074 + error = -EACCES;
48075 + goto exit2;
48076 + }
48077 +
48078 error = mnt_want_write(nd.path.mnt);
48079 if (error)
48080 goto exit2;
48081 @@ -2946,6 +3142,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
48082 if (error)
48083 goto exit3;
48084 error = vfs_unlink(nd.path.dentry->d_inode, dentry);
48085 + if (!error && (saved_ino || saved_dev))
48086 + gr_handle_delete(saved_ino, saved_dev);
48087 exit3:
48088 mnt_drop_write(nd.path.mnt);
48089 exit2:
48090 @@ -3021,10 +3219,18 @@ SYSCALL_DEFINE3(symlinkat, const char __user *, oldname,
48091 error = mnt_want_write(path.mnt);
48092 if (error)
48093 goto out_dput;
48094 +
48095 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
48096 + error = -EACCES;
48097 + goto out_drop_write;
48098 + }
48099 +
48100 error = security_path_symlink(&path, dentry, from);
48101 if (error)
48102 goto out_drop_write;
48103 error = vfs_symlink(path.dentry->d_inode, dentry, from);
48104 + if (!error)
48105 + gr_handle_create(dentry, path.mnt);
48106 out_drop_write:
48107 mnt_drop_write(path.mnt);
48108 out_dput:
48109 @@ -3099,6 +3305,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48110 {
48111 struct dentry *new_dentry;
48112 struct path old_path, new_path;
48113 + char *to = NULL;
48114 int how = 0;
48115 int error;
48116
48117 @@ -3122,7 +3329,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48118 if (error)
48119 return error;
48120
48121 - new_dentry = user_path_create(newdfd, newname, &new_path, 0);
48122 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to, 0);
48123 error = PTR_ERR(new_dentry);
48124 if (IS_ERR(new_dentry))
48125 goto out;
48126 @@ -3133,13 +3340,30 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
48127 error = mnt_want_write(new_path.mnt);
48128 if (error)
48129 goto out_dput;
48130 +
48131 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
48132 + old_path.dentry->d_inode,
48133 + old_path.dentry->d_inode->i_mode, to)) {
48134 + error = -EACCES;
48135 + goto out_drop_write;
48136 + }
48137 +
48138 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
48139 + old_path.dentry, old_path.mnt, to)) {
48140 + error = -EACCES;
48141 + goto out_drop_write;
48142 + }
48143 +
48144 error = security_path_link(old_path.dentry, &new_path, new_dentry);
48145 if (error)
48146 goto out_drop_write;
48147 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry);
48148 + if (!error)
48149 + gr_handle_create(new_dentry, new_path.mnt);
48150 out_drop_write:
48151 mnt_drop_write(new_path.mnt);
48152 out_dput:
48153 + putname(to);
48154 dput(new_dentry);
48155 mutex_unlock(&new_path.dentry->d_inode->i_mutex);
48156 path_put(&new_path);
48157 @@ -3373,6 +3597,12 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48158 if (new_dentry == trap)
48159 goto exit5;
48160
48161 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
48162 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
48163 + to);
48164 + if (error)
48165 + goto exit5;
48166 +
48167 error = mnt_want_write(oldnd.path.mnt);
48168 if (error)
48169 goto exit5;
48170 @@ -3382,6 +3612,9 @@ SYSCALL_DEFINE4(renameat, int, olddfd, const char __user *, oldname,
48171 goto exit6;
48172 error = vfs_rename(old_dir->d_inode, old_dentry,
48173 new_dir->d_inode, new_dentry);
48174 + if (!error)
48175 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
48176 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
48177 exit6:
48178 mnt_drop_write(oldnd.path.mnt);
48179 exit5:
48180 @@ -3407,6 +3640,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
48181
48182 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
48183 {
48184 + char tmpbuf[64];
48185 + const char *newlink;
48186 int len;
48187
48188 len = PTR_ERR(link);
48189 @@ -3416,7 +3651,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
48190 len = strlen(link);
48191 if (len > (unsigned) buflen)
48192 len = buflen;
48193 - if (copy_to_user(buffer, link, len))
48194 +
48195 + if (len < sizeof(tmpbuf)) {
48196 + memcpy(tmpbuf, link, len);
48197 + newlink = tmpbuf;
48198 + } else
48199 + newlink = link;
48200 +
48201 + if (copy_to_user(buffer, newlink, len))
48202 len = -EFAULT;
48203 out:
48204 return len;
48205 diff --git a/fs/namespace.c b/fs/namespace.c
48206 index 1e4a5fe..a5ce747 100644
48207 --- a/fs/namespace.c
48208 +++ b/fs/namespace.c
48209 @@ -1157,6 +1157,9 @@ static int do_umount(struct mount *mnt, int flags)
48210 if (!(sb->s_flags & MS_RDONLY))
48211 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
48212 up_write(&sb->s_umount);
48213 +
48214 + gr_log_remount(mnt->mnt_devname, retval);
48215 +
48216 return retval;
48217 }
48218
48219 @@ -1176,6 +1179,9 @@ static int do_umount(struct mount *mnt, int flags)
48220 br_write_unlock(&vfsmount_lock);
48221 up_write(&namespace_sem);
48222 release_mounts(&umount_list);
48223 +
48224 + gr_log_unmount(mnt->mnt_devname, retval);
48225 +
48226 return retval;
48227 }
48228
48229 @@ -2177,6 +2183,16 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48230 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
48231 MS_STRICTATIME);
48232
48233 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
48234 + retval = -EPERM;
48235 + goto dput_out;
48236 + }
48237 +
48238 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
48239 + retval = -EPERM;
48240 + goto dput_out;
48241 + }
48242 +
48243 if (flags & MS_REMOUNT)
48244 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
48245 data_page);
48246 @@ -2191,6 +2207,9 @@ long do_mount(char *dev_name, char *dir_name, char *type_page,
48247 dev_name, data_page);
48248 dput_out:
48249 path_put(&path);
48250 +
48251 + gr_log_mount(dev_name, dir_name, retval);
48252 +
48253 return retval;
48254 }
48255
48256 @@ -2472,6 +2491,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
48257 if (error)
48258 goto out2;
48259
48260 + if (gr_handle_chroot_pivot()) {
48261 + error = -EPERM;
48262 + goto out2;
48263 + }
48264 +
48265 get_fs_root(current->fs, &root);
48266 error = lock_mount(&old);
48267 if (error)
48268 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
48269 index 30bd45a..2ad67a5 100644
48270 --- a/fs/nfs/inode.c
48271 +++ b/fs/nfs/inode.c
48272 @@ -1008,16 +1008,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
48273 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
48274 }
48275
48276 -static atomic_long_t nfs_attr_generation_counter;
48277 +static atomic_long_unchecked_t nfs_attr_generation_counter;
48278
48279 static unsigned long nfs_read_attr_generation_counter(void)
48280 {
48281 - return atomic_long_read(&nfs_attr_generation_counter);
48282 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
48283 }
48284
48285 unsigned long nfs_inc_attr_generation_counter(void)
48286 {
48287 - return atomic_long_inc_return(&nfs_attr_generation_counter);
48288 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
48289 }
48290
48291 void nfs_fattr_init(struct nfs_fattr *fattr)
48292 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
48293 index c8bd9c3..4f83416 100644
48294 --- a/fs/nfsd/vfs.c
48295 +++ b/fs/nfsd/vfs.c
48296 @@ -933,7 +933,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48297 } else {
48298 oldfs = get_fs();
48299 set_fs(KERNEL_DS);
48300 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
48301 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
48302 set_fs(oldfs);
48303 }
48304
48305 @@ -1037,7 +1037,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
48306
48307 /* Write the data. */
48308 oldfs = get_fs(); set_fs(KERNEL_DS);
48309 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &offset);
48310 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &offset);
48311 set_fs(oldfs);
48312 if (host_err < 0)
48313 goto out_nfserr;
48314 @@ -1573,7 +1573,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
48315 */
48316
48317 oldfs = get_fs(); set_fs(KERNEL_DS);
48318 - host_err = inode->i_op->readlink(path.dentry, buf, *lenp);
48319 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
48320 set_fs(oldfs);
48321
48322 if (host_err < 0)
48323 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
48324 index 3568c8a..e0240d8 100644
48325 --- a/fs/notify/fanotify/fanotify_user.c
48326 +++ b/fs/notify/fanotify/fanotify_user.c
48327 @@ -278,7 +278,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
48328 goto out_close_fd;
48329
48330 ret = -EFAULT;
48331 - if (copy_to_user(buf, &fanotify_event_metadata,
48332 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
48333 + copy_to_user(buf, &fanotify_event_metadata,
48334 fanotify_event_metadata.event_len))
48335 goto out_kill_access_response;
48336
48337 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
48338 index c887b13..0fdf472 100644
48339 --- a/fs/notify/notification.c
48340 +++ b/fs/notify/notification.c
48341 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
48342 * get set to 0 so it will never get 'freed'
48343 */
48344 static struct fsnotify_event *q_overflow_event;
48345 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48346 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48347
48348 /**
48349 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
48350 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
48351 */
48352 u32 fsnotify_get_cookie(void)
48353 {
48354 - return atomic_inc_return(&fsnotify_sync_cookie);
48355 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
48356 }
48357 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
48358
48359 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
48360 index 99e3610..02c1068 100644
48361 --- a/fs/ntfs/dir.c
48362 +++ b/fs/ntfs/dir.c
48363 @@ -1329,7 +1329,7 @@ find_next_index_buffer:
48364 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
48365 ~(s64)(ndir->itype.index.block_size - 1)));
48366 /* Bounds checks. */
48367 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48368 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
48369 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
48370 "inode 0x%lx or driver bug.", vdir->i_ino);
48371 goto err_out;
48372 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
48373 index 7389d2d..dfd5dbe 100644
48374 --- a/fs/ntfs/file.c
48375 +++ b/fs/ntfs/file.c
48376 @@ -2231,6 +2231,6 @@ const struct inode_operations ntfs_file_inode_ops = {
48377 #endif /* NTFS_RW */
48378 };
48379
48380 -const struct file_operations ntfs_empty_file_ops = {};
48381 +const struct file_operations ntfs_empty_file_ops __read_only;
48382
48383 -const struct inode_operations ntfs_empty_inode_ops = {};
48384 +const struct inode_operations ntfs_empty_inode_ops __read_only;
48385 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
48386 index 210c352..a174f83 100644
48387 --- a/fs/ocfs2/localalloc.c
48388 +++ b/fs/ocfs2/localalloc.c
48389 @@ -1283,7 +1283,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
48390 goto bail;
48391 }
48392
48393 - atomic_inc(&osb->alloc_stats.moves);
48394 + atomic_inc_unchecked(&osb->alloc_stats.moves);
48395
48396 bail:
48397 if (handle)
48398 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
48399 index d355e6e..578d905 100644
48400 --- a/fs/ocfs2/ocfs2.h
48401 +++ b/fs/ocfs2/ocfs2.h
48402 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
48403
48404 struct ocfs2_alloc_stats
48405 {
48406 - atomic_t moves;
48407 - atomic_t local_data;
48408 - atomic_t bitmap_data;
48409 - atomic_t bg_allocs;
48410 - atomic_t bg_extends;
48411 + atomic_unchecked_t moves;
48412 + atomic_unchecked_t local_data;
48413 + atomic_unchecked_t bitmap_data;
48414 + atomic_unchecked_t bg_allocs;
48415 + atomic_unchecked_t bg_extends;
48416 };
48417
48418 enum ocfs2_local_alloc_state
48419 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
48420 index f169da4..9112253 100644
48421 --- a/fs/ocfs2/suballoc.c
48422 +++ b/fs/ocfs2/suballoc.c
48423 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
48424 mlog_errno(status);
48425 goto bail;
48426 }
48427 - atomic_inc(&osb->alloc_stats.bg_extends);
48428 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
48429
48430 /* You should never ask for this much metadata */
48431 BUG_ON(bits_wanted >
48432 @@ -2008,7 +2008,7 @@ int ocfs2_claim_metadata(handle_t *handle,
48433 mlog_errno(status);
48434 goto bail;
48435 }
48436 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48437 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48438
48439 *suballoc_loc = res.sr_bg_blkno;
48440 *suballoc_bit_start = res.sr_bit_offset;
48441 @@ -2172,7 +2172,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
48442 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
48443 res->sr_bits);
48444
48445 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48446 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48447
48448 BUG_ON(res->sr_bits != 1);
48449
48450 @@ -2214,7 +2214,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
48451 mlog_errno(status);
48452 goto bail;
48453 }
48454 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48455 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
48456
48457 BUG_ON(res.sr_bits != 1);
48458
48459 @@ -2318,7 +2318,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48460 cluster_start,
48461 num_clusters);
48462 if (!status)
48463 - atomic_inc(&osb->alloc_stats.local_data);
48464 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
48465 } else {
48466 if (min_clusters > (osb->bitmap_cpg - 1)) {
48467 /* The only paths asking for contiguousness
48468 @@ -2344,7 +2344,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
48469 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
48470 res.sr_bg_blkno,
48471 res.sr_bit_offset);
48472 - atomic_inc(&osb->alloc_stats.bitmap_data);
48473 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
48474 *num_clusters = res.sr_bits;
48475 }
48476 }
48477 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
48478 index 68f4541..89cfe6a 100644
48479 --- a/fs/ocfs2/super.c
48480 +++ b/fs/ocfs2/super.c
48481 @@ -301,11 +301,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
48482 "%10s => GlobalAllocs: %d LocalAllocs: %d "
48483 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
48484 "Stats",
48485 - atomic_read(&osb->alloc_stats.bitmap_data),
48486 - atomic_read(&osb->alloc_stats.local_data),
48487 - atomic_read(&osb->alloc_stats.bg_allocs),
48488 - atomic_read(&osb->alloc_stats.moves),
48489 - atomic_read(&osb->alloc_stats.bg_extends));
48490 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
48491 + atomic_read_unchecked(&osb->alloc_stats.local_data),
48492 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
48493 + atomic_read_unchecked(&osb->alloc_stats.moves),
48494 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
48495
48496 out += snprintf(buf + out, len - out,
48497 "%10s => State: %u Descriptor: %llu Size: %u bits "
48498 @@ -2116,11 +2116,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
48499 spin_lock_init(&osb->osb_xattr_lock);
48500 ocfs2_init_steal_slots(osb);
48501
48502 - atomic_set(&osb->alloc_stats.moves, 0);
48503 - atomic_set(&osb->alloc_stats.local_data, 0);
48504 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
48505 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
48506 - atomic_set(&osb->alloc_stats.bg_extends, 0);
48507 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
48508 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
48509 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
48510 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
48511 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
48512
48513 /* Copy the blockcheck stats from the superblock probe */
48514 osb->osb_ecc_stats = *stats;
48515 diff --git a/fs/open.c b/fs/open.c
48516 index 5d9c71b..adb5b19 100644
48517 --- a/fs/open.c
48518 +++ b/fs/open.c
48519 @@ -31,6 +31,8 @@
48520 #include <linux/ima.h>
48521 #include <linux/dnotify.h>
48522
48523 +#define CREATE_TRACE_POINTS
48524 +#include <trace/events/fs.h>
48525 #include "internal.h"
48526
48527 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
48528 @@ -112,6 +114,10 @@ static long do_sys_truncate(const char __user *pathname, loff_t length)
48529 error = locks_verify_truncate(inode, NULL, length);
48530 if (!error)
48531 error = security_path_truncate(&path);
48532 +
48533 + if (!error && !gr_acl_handle_truncate(path.dentry, path.mnt))
48534 + error = -EACCES;
48535 +
48536 if (!error)
48537 error = do_truncate(path.dentry, length, 0, NULL);
48538
48539 @@ -359,6 +365,9 @@ SYSCALL_DEFINE3(faccessat, int, dfd, const char __user *, filename, int, mode)
48540 if (__mnt_is_readonly(path.mnt))
48541 res = -EROFS;
48542
48543 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
48544 + res = -EACCES;
48545 +
48546 out_path_release:
48547 path_put(&path);
48548 out:
48549 @@ -385,6 +394,8 @@ SYSCALL_DEFINE1(chdir, const char __user *, filename)
48550 if (error)
48551 goto dput_and_out;
48552
48553 + gr_log_chdir(path.dentry, path.mnt);
48554 +
48555 set_fs_pwd(current->fs, &path);
48556
48557 dput_and_out:
48558 @@ -411,6 +422,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
48559 goto out_putf;
48560
48561 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
48562 +
48563 + if (!error && !gr_chroot_fchdir(file->f_path.dentry, file->f_path.mnt))
48564 + error = -EPERM;
48565 +
48566 + if (!error)
48567 + gr_log_chdir(file->f_path.dentry, file->f_path.mnt);
48568 +
48569 if (!error)
48570 set_fs_pwd(current->fs, &file->f_path);
48571 out_putf:
48572 @@ -439,7 +457,13 @@ SYSCALL_DEFINE1(chroot, const char __user *, filename)
48573 if (error)
48574 goto dput_and_out;
48575
48576 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
48577 + goto dput_and_out;
48578 +
48579 set_fs_root(current->fs, &path);
48580 +
48581 + gr_handle_chroot_chdir(&path);
48582 +
48583 error = 0;
48584 dput_and_out:
48585 path_put(&path);
48586 @@ -457,6 +481,16 @@ static int chmod_common(struct path *path, umode_t mode)
48587 if (error)
48588 return error;
48589 mutex_lock(&inode->i_mutex);
48590 +
48591 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
48592 + error = -EACCES;
48593 + goto out_unlock;
48594 + }
48595 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
48596 + error = -EACCES;
48597 + goto out_unlock;
48598 + }
48599 +
48600 error = security_path_chmod(path, mode);
48601 if (error)
48602 goto out_unlock;
48603 @@ -512,6 +546,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
48604 uid = make_kuid(current_user_ns(), user);
48605 gid = make_kgid(current_user_ns(), group);
48606
48607 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
48608 + return -EACCES;
48609 +
48610 newattrs.ia_valid = ATTR_CTIME;
48611 if (user != (uid_t) -1) {
48612 if (!uid_valid(uid))
48613 @@ -1036,6 +1073,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
48614 } else {
48615 fsnotify_open(f);
48616 fd_install(fd, f);
48617 + trace_do_sys_open(tmp, flags, mode);
48618 }
48619 }
48620 putname(tmp);
48621 diff --git a/fs/pipe.c b/fs/pipe.c
48622 index 49c1065..13b9e12 100644
48623 --- a/fs/pipe.c
48624 +++ b/fs/pipe.c
48625 @@ -438,9 +438,9 @@ redo:
48626 }
48627 if (bufs) /* More to do? */
48628 continue;
48629 - if (!pipe->writers)
48630 + if (!atomic_read(&pipe->writers))
48631 break;
48632 - if (!pipe->waiting_writers) {
48633 + if (!atomic_read(&pipe->waiting_writers)) {
48634 /* syscall merging: Usually we must not sleep
48635 * if O_NONBLOCK is set, or if we got some data.
48636 * But if a writer sleeps in kernel space, then
48637 @@ -504,7 +504,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
48638 mutex_lock(&inode->i_mutex);
48639 pipe = inode->i_pipe;
48640
48641 - if (!pipe->readers) {
48642 + if (!atomic_read(&pipe->readers)) {
48643 send_sig(SIGPIPE, current, 0);
48644 ret = -EPIPE;
48645 goto out;
48646 @@ -553,7 +553,7 @@ redo1:
48647 for (;;) {
48648 int bufs;
48649
48650 - if (!pipe->readers) {
48651 + if (!atomic_read(&pipe->readers)) {
48652 send_sig(SIGPIPE, current, 0);
48653 if (!ret)
48654 ret = -EPIPE;
48655 @@ -644,9 +644,9 @@ redo2:
48656 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
48657 do_wakeup = 0;
48658 }
48659 - pipe->waiting_writers++;
48660 + atomic_inc(&pipe->waiting_writers);
48661 pipe_wait(pipe);
48662 - pipe->waiting_writers--;
48663 + atomic_dec(&pipe->waiting_writers);
48664 }
48665 out:
48666 mutex_unlock(&inode->i_mutex);
48667 @@ -716,7 +716,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48668 mask = 0;
48669 if (filp->f_mode & FMODE_READ) {
48670 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
48671 - if (!pipe->writers && filp->f_version != pipe->w_counter)
48672 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
48673 mask |= POLLHUP;
48674 }
48675
48676 @@ -726,7 +726,7 @@ pipe_poll(struct file *filp, poll_table *wait)
48677 * Most Unices do not set POLLERR for FIFOs but on Linux they
48678 * behave exactly like pipes for poll().
48679 */
48680 - if (!pipe->readers)
48681 + if (!atomic_read(&pipe->readers))
48682 mask |= POLLERR;
48683 }
48684
48685 @@ -740,10 +740,10 @@ pipe_release(struct inode *inode, int decr, int decw)
48686
48687 mutex_lock(&inode->i_mutex);
48688 pipe = inode->i_pipe;
48689 - pipe->readers -= decr;
48690 - pipe->writers -= decw;
48691 + atomic_sub(decr, &pipe->readers);
48692 + atomic_sub(decw, &pipe->writers);
48693
48694 - if (!pipe->readers && !pipe->writers) {
48695 + if (!atomic_read(&pipe->readers) && !atomic_read(&pipe->writers)) {
48696 free_pipe_info(inode);
48697 } else {
48698 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
48699 @@ -833,7 +833,7 @@ pipe_read_open(struct inode *inode, struct file *filp)
48700
48701 if (inode->i_pipe) {
48702 ret = 0;
48703 - inode->i_pipe->readers++;
48704 + atomic_inc(&inode->i_pipe->readers);
48705 }
48706
48707 mutex_unlock(&inode->i_mutex);
48708 @@ -850,7 +850,7 @@ pipe_write_open(struct inode *inode, struct file *filp)
48709
48710 if (inode->i_pipe) {
48711 ret = 0;
48712 - inode->i_pipe->writers++;
48713 + atomic_inc(&inode->i_pipe->writers);
48714 }
48715
48716 mutex_unlock(&inode->i_mutex);
48717 @@ -868,9 +868,9 @@ pipe_rdwr_open(struct inode *inode, struct file *filp)
48718 if (inode->i_pipe) {
48719 ret = 0;
48720 if (filp->f_mode & FMODE_READ)
48721 - inode->i_pipe->readers++;
48722 + atomic_inc(&inode->i_pipe->readers);
48723 if (filp->f_mode & FMODE_WRITE)
48724 - inode->i_pipe->writers++;
48725 + atomic_inc(&inode->i_pipe->writers);
48726 }
48727
48728 mutex_unlock(&inode->i_mutex);
48729 @@ -962,7 +962,7 @@ void free_pipe_info(struct inode *inode)
48730 inode->i_pipe = NULL;
48731 }
48732
48733 -static struct vfsmount *pipe_mnt __read_mostly;
48734 +struct vfsmount *pipe_mnt __read_mostly;
48735
48736 /*
48737 * pipefs_dname() is called from d_path().
48738 @@ -992,7 +992,8 @@ static struct inode * get_pipe_inode(void)
48739 goto fail_iput;
48740 inode->i_pipe = pipe;
48741
48742 - pipe->readers = pipe->writers = 1;
48743 + atomic_set(&pipe->readers, 1);
48744 + atomic_set(&pipe->writers, 1);
48745 inode->i_fop = &rdwr_pipefifo_fops;
48746
48747 /*
48748 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
48749 index 15af622..0e9f4467 100644
48750 --- a/fs/proc/Kconfig
48751 +++ b/fs/proc/Kconfig
48752 @@ -30,12 +30,12 @@ config PROC_FS
48753
48754 config PROC_KCORE
48755 bool "/proc/kcore support" if !ARM
48756 - depends on PROC_FS && MMU
48757 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
48758
48759 config PROC_VMCORE
48760 bool "/proc/vmcore support"
48761 - depends on PROC_FS && CRASH_DUMP
48762 - default y
48763 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
48764 + default n
48765 help
48766 Exports the dump image of crashed kernel in ELF format.
48767
48768 @@ -59,8 +59,8 @@ config PROC_SYSCTL
48769 limited in memory.
48770
48771 config PROC_PAGE_MONITOR
48772 - default y
48773 - depends on PROC_FS && MMU
48774 + default n
48775 + depends on PROC_FS && MMU && !GRKERNSEC
48776 bool "Enable /proc page monitoring" if EXPERT
48777 help
48778 Various /proc files exist to monitor process memory utilization:
48779 diff --git a/fs/proc/array.c b/fs/proc/array.c
48780 index c1c207c..01ce725 100644
48781 --- a/fs/proc/array.c
48782 +++ b/fs/proc/array.c
48783 @@ -60,6 +60,7 @@
48784 #include <linux/tty.h>
48785 #include <linux/string.h>
48786 #include <linux/mman.h>
48787 +#include <linux/grsecurity.h>
48788 #include <linux/proc_fs.h>
48789 #include <linux/ioport.h>
48790 #include <linux/uaccess.h>
48791 @@ -346,6 +347,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
48792 seq_putc(m, '\n');
48793 }
48794
48795 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48796 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
48797 +{
48798 + if (p->mm)
48799 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
48800 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
48801 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
48802 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
48803 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
48804 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
48805 + else
48806 + seq_printf(m, "PaX:\t-----\n");
48807 +}
48808 +#endif
48809 +
48810 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48811 struct pid *pid, struct task_struct *task)
48812 {
48813 @@ -363,9 +379,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
48814 task_cpus_allowed(m, task);
48815 cpuset_task_status_allowed(m, task);
48816 task_context_switch_counts(m, task);
48817 +
48818 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
48819 + task_pax(m, task);
48820 +#endif
48821 +
48822 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
48823 + task_grsec_rbac(m, task);
48824 +#endif
48825 +
48826 return 0;
48827 }
48828
48829 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48830 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48831 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48832 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48833 +#endif
48834 +
48835 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48836 struct pid *pid, struct task_struct *task, int whole)
48837 {
48838 @@ -387,6 +418,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48839 char tcomm[sizeof(task->comm)];
48840 unsigned long flags;
48841
48842 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48843 + if (current->exec_id != m->exec_id) {
48844 + gr_log_badprocpid("stat");
48845 + return 0;
48846 + }
48847 +#endif
48848 +
48849 state = *get_task_state(task);
48850 vsize = eip = esp = 0;
48851 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
48852 @@ -458,6 +496,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48853 gtime = task->gtime;
48854 }
48855
48856 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48857 + if (PAX_RAND_FLAGS(mm)) {
48858 + eip = 0;
48859 + esp = 0;
48860 + wchan = 0;
48861 + }
48862 +#endif
48863 +#ifdef CONFIG_GRKERNSEC_HIDESYM
48864 + wchan = 0;
48865 + eip =0;
48866 + esp =0;
48867 +#endif
48868 +
48869 /* scale priority and nice values from timeslices to -20..20 */
48870 /* to make it look like a "normal" Unix priority/nice value */
48871 priority = task_prio(task);
48872 @@ -494,9 +545,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48873 seq_put_decimal_ull(m, ' ', vsize);
48874 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
48875 seq_put_decimal_ull(m, ' ', rsslim);
48876 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48877 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
48878 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
48879 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
48880 +#else
48881 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
48882 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
48883 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
48884 +#endif
48885 seq_put_decimal_ull(m, ' ', esp);
48886 seq_put_decimal_ull(m, ' ', eip);
48887 /* The signal information here is obsolete.
48888 @@ -518,7 +575,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
48889 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
48890 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
48891
48892 - if (mm && permitted) {
48893 + if (mm && permitted
48894 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48895 + && !PAX_RAND_FLAGS(mm)
48896 +#endif
48897 + ) {
48898 seq_put_decimal_ull(m, ' ', mm->start_data);
48899 seq_put_decimal_ull(m, ' ', mm->end_data);
48900 seq_put_decimal_ull(m, ' ', mm->start_brk);
48901 @@ -556,8 +617,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48902 struct pid *pid, struct task_struct *task)
48903 {
48904 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
48905 - struct mm_struct *mm = get_task_mm(task);
48906 + struct mm_struct *mm;
48907
48908 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48909 + if (current->exec_id != m->exec_id) {
48910 + gr_log_badprocpid("statm");
48911 + return 0;
48912 + }
48913 +#endif
48914 + mm = get_task_mm(task);
48915 if (mm) {
48916 size = task_statm(mm, &shared, &text, &data, &resident);
48917 mmput(mm);
48918 @@ -580,6 +648,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
48919 return 0;
48920 }
48921
48922 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
48923 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
48924 +{
48925 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
48926 +}
48927 +#endif
48928 +
48929 #ifdef CONFIG_CHECKPOINT_RESTORE
48930 static struct pid *
48931 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
48932 diff --git a/fs/proc/base.c b/fs/proc/base.c
48933 index 437195f..e1b6a2d 100644
48934 --- a/fs/proc/base.c
48935 +++ b/fs/proc/base.c
48936 @@ -110,6 +110,14 @@ struct pid_entry {
48937 union proc_op op;
48938 };
48939
48940 +struct getdents_callback {
48941 + struct linux_dirent __user * current_dir;
48942 + struct linux_dirent __user * previous;
48943 + struct file * file;
48944 + int count;
48945 + int error;
48946 +};
48947 +
48948 #define NOD(NAME, MODE, IOP, FOP, OP) { \
48949 .name = (NAME), \
48950 .len = sizeof(NAME) - 1, \
48951 @@ -209,6 +217,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
48952 if (!mm->arg_end)
48953 goto out_mm; /* Shh! No looking before we're done */
48954
48955 + if (gr_acl_handle_procpidmem(task))
48956 + goto out_mm;
48957 +
48958 len = mm->arg_end - mm->arg_start;
48959
48960 if (len > PAGE_SIZE)
48961 @@ -236,12 +247,28 @@ out:
48962 return res;
48963 }
48964
48965 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48966 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
48967 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
48968 + _mm->pax_flags & MF_PAX_SEGMEXEC))
48969 +#endif
48970 +
48971 static int proc_pid_auxv(struct task_struct *task, char *buffer)
48972 {
48973 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
48974 int res = PTR_ERR(mm);
48975 if (mm && !IS_ERR(mm)) {
48976 unsigned int nwords = 0;
48977 +
48978 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
48979 + /* allow if we're currently ptracing this task */
48980 + if (PAX_RAND_FLAGS(mm) &&
48981 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
48982 + mmput(mm);
48983 + return 0;
48984 + }
48985 +#endif
48986 +
48987 do {
48988 nwords += 2;
48989 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
48990 @@ -255,7 +282,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
48991 }
48992
48993
48994 -#ifdef CONFIG_KALLSYMS
48995 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
48996 /*
48997 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
48998 * Returns the resolved symbol. If that fails, simply return the address.
48999 @@ -294,7 +321,7 @@ static void unlock_trace(struct task_struct *task)
49000 mutex_unlock(&task->signal->cred_guard_mutex);
49001 }
49002
49003 -#ifdef CONFIG_STACKTRACE
49004 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49005
49006 #define MAX_STACK_TRACE_DEPTH 64
49007
49008 @@ -486,7 +513,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
49009 return count;
49010 }
49011
49012 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49013 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49014 static int proc_pid_syscall(struct task_struct *task, char *buffer)
49015 {
49016 long nr;
49017 @@ -515,7 +542,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
49018 /************************************************************************/
49019
49020 /* permission checks */
49021 -static int proc_fd_access_allowed(struct inode *inode)
49022 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
49023 {
49024 struct task_struct *task;
49025 int allowed = 0;
49026 @@ -525,7 +552,10 @@ static int proc_fd_access_allowed(struct inode *inode)
49027 */
49028 task = get_proc_task(inode);
49029 if (task) {
49030 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49031 + if (log)
49032 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
49033 + else
49034 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
49035 put_task_struct(task);
49036 }
49037 return allowed;
49038 @@ -563,10 +593,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
49039 struct task_struct *task,
49040 int hide_pid_min)
49041 {
49042 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49043 + return false;
49044 +
49045 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49046 + rcu_read_lock();
49047 + {
49048 + const struct cred *tmpcred = current_cred();
49049 + const struct cred *cred = __task_cred(task);
49050 +
49051 + if (!tmpcred->uid || (tmpcred->uid == cred->uid)
49052 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49053 + || in_group_p(grsec_proc_gid)
49054 +#endif
49055 + ) {
49056 + rcu_read_unlock();
49057 + return true;
49058 + }
49059 + }
49060 + rcu_read_unlock();
49061 +
49062 + if (!pid->hide_pid)
49063 + return false;
49064 +#endif
49065 +
49066 if (pid->hide_pid < hide_pid_min)
49067 return true;
49068 if (in_group_p(pid->pid_gid))
49069 return true;
49070 +
49071 return ptrace_may_access(task, PTRACE_MODE_READ);
49072 }
49073
49074 @@ -584,7 +639,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
49075 put_task_struct(task);
49076
49077 if (!has_perms) {
49078 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49079 + {
49080 +#else
49081 if (pid->hide_pid == 2) {
49082 +#endif
49083 /*
49084 * Let's make getdents(), stat(), and open()
49085 * consistent with each other. If a process
49086 @@ -682,6 +741,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49087 if (!task)
49088 return -ESRCH;
49089
49090 + if (gr_acl_handle_procpidmem(task)) {
49091 + put_task_struct(task);
49092 + return -EPERM;
49093 + }
49094 +
49095 mm = mm_access(task, mode);
49096 put_task_struct(task);
49097
49098 @@ -695,16 +759,24 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
49099 mmput(mm);
49100 }
49101
49102 - /* OK to pass negative loff_t, we can catch out-of-range */
49103 - file->f_mode |= FMODE_UNSIGNED_OFFSET;
49104 file->private_data = mm;
49105
49106 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49107 + file->f_version = current->exec_id;
49108 +#endif
49109 +
49110 return 0;
49111 }
49112
49113 static int mem_open(struct inode *inode, struct file *file)
49114 {
49115 - return __mem_open(inode, file, PTRACE_MODE_ATTACH);
49116 + int ret;
49117 + ret = __mem_open(inode, file, PTRACE_MODE_ATTACH);
49118 +
49119 + /* OK to pass negative loff_t, we can catch out-of-range */
49120 + file->f_mode |= FMODE_UNSIGNED_OFFSET;
49121 +
49122 + return ret;
49123 }
49124
49125 static ssize_t mem_rw(struct file *file, char __user *buf,
49126 @@ -715,6 +787,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
49127 ssize_t copied;
49128 char *page;
49129
49130 +#ifdef CONFIG_GRKERNSEC
49131 + if (write)
49132 + return -EPERM;
49133 +#endif
49134 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49135 + if (file->f_version != current->exec_id) {
49136 + gr_log_badprocpid("mem");
49137 + return 0;
49138 + }
49139 +#endif
49140 +
49141 if (!mm)
49142 return 0;
49143
49144 @@ -819,6 +902,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49145 if (!mm)
49146 return 0;
49147
49148 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49149 + if (file->f_version != current->exec_id) {
49150 + gr_log_badprocpid("environ");
49151 + return 0;
49152 + }
49153 +#endif
49154 +
49155 page = (char *)__get_free_page(GFP_TEMPORARY);
49156 if (!page)
49157 return -ENOMEM;
49158 @@ -827,15 +917,17 @@ static ssize_t environ_read(struct file *file, char __user *buf,
49159 if (!atomic_inc_not_zero(&mm->mm_users))
49160 goto free;
49161 while (count > 0) {
49162 - int this_len, retval, max_len;
49163 + size_t this_len, max_len;
49164 + int retval;
49165 +
49166 + if (src >= (mm->env_end - mm->env_start))
49167 + break;
49168
49169 this_len = mm->env_end - (mm->env_start + src);
49170
49171 - if (this_len <= 0)
49172 - break;
49173
49174 - max_len = (count > PAGE_SIZE) ? PAGE_SIZE : count;
49175 - this_len = (this_len > max_len) ? max_len : this_len;
49176 + max_len = min_t(size_t, PAGE_SIZE, count);
49177 + this_len = min(max_len, this_len);
49178
49179 retval = access_remote_vm(mm, (mm->env_start + src),
49180 page, this_len, 0);
49181 @@ -1433,7 +1525,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
49182 path_put(&nd->path);
49183
49184 /* Are we allowed to snoop on the tasks file descriptors? */
49185 - if (!proc_fd_access_allowed(inode))
49186 + if (!proc_fd_access_allowed(inode, 0))
49187 goto out;
49188
49189 error = PROC_I(inode)->op.proc_get_link(dentry, &nd->path);
49190 @@ -1472,8 +1564,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
49191 struct path path;
49192
49193 /* Are we allowed to snoop on the tasks file descriptors? */
49194 - if (!proc_fd_access_allowed(inode))
49195 - goto out;
49196 + /* logging this is needed for learning on chromium to work properly,
49197 + but we don't want to flood the logs from 'ps' which does a readlink
49198 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
49199 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
49200 + */
49201 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
49202 + if (!proc_fd_access_allowed(inode,0))
49203 + goto out;
49204 + } else {
49205 + if (!proc_fd_access_allowed(inode,1))
49206 + goto out;
49207 + }
49208
49209 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
49210 if (error)
49211 @@ -1538,7 +1640,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
49212 rcu_read_lock();
49213 cred = __task_cred(task);
49214 inode->i_uid = cred->euid;
49215 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49216 + inode->i_gid = grsec_proc_gid;
49217 +#else
49218 inode->i_gid = cred->egid;
49219 +#endif
49220 rcu_read_unlock();
49221 }
49222 security_task_to_inode(task, inode);
49223 @@ -1574,10 +1680,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
49224 return -ENOENT;
49225 }
49226 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49227 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49228 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49229 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49230 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49231 +#endif
49232 task_dumpable(task)) {
49233 cred = __task_cred(task);
49234 stat->uid = cred->euid;
49235 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49236 + stat->gid = grsec_proc_gid;
49237 +#else
49238 stat->gid = cred->egid;
49239 +#endif
49240 }
49241 }
49242 rcu_read_unlock();
49243 @@ -1615,11 +1730,20 @@ int pid_revalidate(struct dentry *dentry, struct nameidata *nd)
49244
49245 if (task) {
49246 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
49247 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49248 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
49249 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49250 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
49251 +#endif
49252 task_dumpable(task)) {
49253 rcu_read_lock();
49254 cred = __task_cred(task);
49255 inode->i_uid = cred->euid;
49256 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49257 + inode->i_gid = grsec_proc_gid;
49258 +#else
49259 inode->i_gid = cred->egid;
49260 +#endif
49261 rcu_read_unlock();
49262 } else {
49263 inode->i_uid = GLOBAL_ROOT_UID;
49264 @@ -1737,7 +1861,8 @@ static int proc_fd_info(struct inode *inode, struct path *path, char *info)
49265 int fd = proc_fd(inode);
49266
49267 if (task) {
49268 - files = get_files_struct(task);
49269 + if (!gr_acl_handle_procpidmem(task))
49270 + files = get_files_struct(task);
49271 put_task_struct(task);
49272 }
49273 if (files) {
49274 @@ -2336,11 +2461,21 @@ static const struct file_operations proc_map_files_operations = {
49275 */
49276 static int proc_fd_permission(struct inode *inode, int mask)
49277 {
49278 + struct task_struct *task;
49279 int rv = generic_permission(inode, mask);
49280 - if (rv == 0)
49281 - return 0;
49282 +
49283 if (task_pid(current) == proc_pid(inode))
49284 rv = 0;
49285 +
49286 + task = get_proc_task(inode);
49287 + if (task == NULL)
49288 + return rv;
49289 +
49290 + if (gr_acl_handle_procpidmem(task))
49291 + rv = -EACCES;
49292 +
49293 + put_task_struct(task);
49294 +
49295 return rv;
49296 }
49297
49298 @@ -2450,6 +2585,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
49299 if (!task)
49300 goto out_no_task;
49301
49302 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49303 + goto out;
49304 +
49305 /*
49306 * Yes, it does not scale. And it should not. Don't add
49307 * new entries into /proc/<tgid>/ without very good reasons.
49308 @@ -2494,6 +2632,9 @@ static int proc_pident_readdir(struct file *filp,
49309 if (!task)
49310 goto out_no_task;
49311
49312 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49313 + goto out;
49314 +
49315 ret = 0;
49316 i = filp->f_pos;
49317 switch (i) {
49318 @@ -2764,7 +2905,7 @@ static void *proc_self_follow_link(struct dentry *dentry, struct nameidata *nd)
49319 static void proc_self_put_link(struct dentry *dentry, struct nameidata *nd,
49320 void *cookie)
49321 {
49322 - char *s = nd_get_link(nd);
49323 + const char *s = nd_get_link(nd);
49324 if (!IS_ERR(s))
49325 __putname(s);
49326 }
49327 @@ -3033,7 +3174,7 @@ static const struct pid_entry tgid_base_stuff[] = {
49328 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
49329 #endif
49330 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49331 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49332 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49333 INF("syscall", S_IRUGO, proc_pid_syscall),
49334 #endif
49335 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49336 @@ -3058,10 +3199,10 @@ static const struct pid_entry tgid_base_stuff[] = {
49337 #ifdef CONFIG_SECURITY
49338 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49339 #endif
49340 -#ifdef CONFIG_KALLSYMS
49341 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49342 INF("wchan", S_IRUGO, proc_pid_wchan),
49343 #endif
49344 -#ifdef CONFIG_STACKTRACE
49345 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49346 ONE("stack", S_IRUGO, proc_pid_stack),
49347 #endif
49348 #ifdef CONFIG_SCHEDSTATS
49349 @@ -3095,6 +3236,9 @@ static const struct pid_entry tgid_base_stuff[] = {
49350 #ifdef CONFIG_HARDWALL
49351 INF("hardwall", S_IRUGO, proc_pid_hardwall),
49352 #endif
49353 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49354 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
49355 +#endif
49356 #ifdef CONFIG_USER_NS
49357 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
49358 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
49359 @@ -3225,7 +3369,14 @@ static struct dentry *proc_pid_instantiate(struct inode *dir,
49360 if (!inode)
49361 goto out;
49362
49363 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49364 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
49365 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49366 + inode->i_gid = grsec_proc_gid;
49367 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
49368 +#else
49369 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
49370 +#endif
49371 inode->i_op = &proc_tgid_base_inode_operations;
49372 inode->i_fop = &proc_tgid_base_operations;
49373 inode->i_flags|=S_IMMUTABLE;
49374 @@ -3267,7 +3418,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, struct
49375 if (!task)
49376 goto out;
49377
49378 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
49379 + goto out_put_task;
49380 +
49381 result = proc_pid_instantiate(dir, dentry, task, NULL);
49382 +out_put_task:
49383 put_task_struct(task);
49384 out:
49385 return result;
49386 @@ -3330,6 +3485,8 @@ static int proc_pid_fill_cache(struct file *filp, void *dirent, filldir_t filldi
49387 static int fake_filldir(void *buf, const char *name, int namelen,
49388 loff_t offset, u64 ino, unsigned d_type)
49389 {
49390 + struct getdents_callback * __buf = (struct getdents_callback *) buf;
49391 + __buf->error = -EINVAL;
49392 return 0;
49393 }
49394
49395 @@ -3396,7 +3553,7 @@ static const struct pid_entry tid_base_stuff[] = {
49396 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
49397 #endif
49398 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
49399 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
49400 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
49401 INF("syscall", S_IRUGO, proc_pid_syscall),
49402 #endif
49403 INF("cmdline", S_IRUGO, proc_pid_cmdline),
49404 @@ -3423,10 +3580,10 @@ static const struct pid_entry tid_base_stuff[] = {
49405 #ifdef CONFIG_SECURITY
49406 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
49407 #endif
49408 -#ifdef CONFIG_KALLSYMS
49409 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49410 INF("wchan", S_IRUGO, proc_pid_wchan),
49411 #endif
49412 -#ifdef CONFIG_STACKTRACE
49413 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
49414 ONE("stack", S_IRUGO, proc_pid_stack),
49415 #endif
49416 #ifdef CONFIG_SCHEDSTATS
49417 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
49418 index 82676e3..5f8518a 100644
49419 --- a/fs/proc/cmdline.c
49420 +++ b/fs/proc/cmdline.c
49421 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
49422
49423 static int __init proc_cmdline_init(void)
49424 {
49425 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49426 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
49427 +#else
49428 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
49429 +#endif
49430 return 0;
49431 }
49432 module_init(proc_cmdline_init);
49433 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
49434 index b143471..bb105e5 100644
49435 --- a/fs/proc/devices.c
49436 +++ b/fs/proc/devices.c
49437 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
49438
49439 static int __init proc_devices_init(void)
49440 {
49441 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49442 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
49443 +#else
49444 proc_create("devices", 0, NULL, &proc_devinfo_operations);
49445 +#endif
49446 return 0;
49447 }
49448 module_init(proc_devices_init);
49449 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
49450 index 7ac817b..c5c9eb0 100644
49451 --- a/fs/proc/inode.c
49452 +++ b/fs/proc/inode.c
49453 @@ -21,11 +21,17 @@
49454 #include <linux/seq_file.h>
49455 #include <linux/slab.h>
49456 #include <linux/mount.h>
49457 +#include <linux/grsecurity.h>
49458
49459 #include <asm/uaccess.h>
49460
49461 #include "internal.h"
49462
49463 +#ifdef CONFIG_PROC_SYSCTL
49464 +extern const struct inode_operations proc_sys_inode_operations;
49465 +extern const struct inode_operations proc_sys_dir_operations;
49466 +#endif
49467 +
49468 static void proc_evict_inode(struct inode *inode)
49469 {
49470 struct proc_dir_entry *de;
49471 @@ -51,6 +57,13 @@ static void proc_evict_inode(struct inode *inode)
49472 ns_ops = PROC_I(inode)->ns_ops;
49473 if (ns_ops && ns_ops->put)
49474 ns_ops->put(PROC_I(inode)->ns);
49475 +
49476 +#ifdef CONFIG_PROC_SYSCTL
49477 + if (inode->i_op == &proc_sys_inode_operations ||
49478 + inode->i_op == &proc_sys_dir_operations)
49479 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
49480 +#endif
49481 +
49482 }
49483
49484 static struct kmem_cache * proc_inode_cachep;
49485 @@ -456,7 +469,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
49486 if (de->mode) {
49487 inode->i_mode = de->mode;
49488 inode->i_uid = de->uid;
49489 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
49490 + inode->i_gid = grsec_proc_gid;
49491 +#else
49492 inode->i_gid = de->gid;
49493 +#endif
49494 }
49495 if (de->size)
49496 inode->i_size = de->size;
49497 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
49498 index eca4aca..19166b2 100644
49499 --- a/fs/proc/internal.h
49500 +++ b/fs/proc/internal.h
49501 @@ -52,6 +52,9 @@ extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
49502 struct pid *pid, struct task_struct *task);
49503 extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
49504 struct pid *pid, struct task_struct *task);
49505 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
49506 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
49507 +#endif
49508 extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
49509
49510 extern const struct file_operations proc_tid_children_operations;
49511 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
49512 index 86c67ee..cdca321 100644
49513 --- a/fs/proc/kcore.c
49514 +++ b/fs/proc/kcore.c
49515 @@ -480,9 +480,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49516 * the addresses in the elf_phdr on our list.
49517 */
49518 start = kc_offset_to_vaddr(*fpos - elf_buflen);
49519 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
49520 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
49521 + if (tsz > buflen)
49522 tsz = buflen;
49523 -
49524 +
49525 while (buflen) {
49526 struct kcore_list *m;
49527
49528 @@ -511,20 +512,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49529 kfree(elf_buf);
49530 } else {
49531 if (kern_addr_valid(start)) {
49532 - unsigned long n;
49533 + char *elf_buf;
49534 + mm_segment_t oldfs;
49535
49536 - n = copy_to_user(buffer, (char *)start, tsz);
49537 - /*
49538 - * We cannot distinguish between fault on source
49539 - * and fault on destination. When this happens
49540 - * we clear too and hope it will trigger the
49541 - * EFAULT again.
49542 - */
49543 - if (n) {
49544 - if (clear_user(buffer + tsz - n,
49545 - n))
49546 + elf_buf = kmalloc(tsz, GFP_KERNEL);
49547 + if (!elf_buf)
49548 + return -ENOMEM;
49549 + oldfs = get_fs();
49550 + set_fs(KERNEL_DS);
49551 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
49552 + set_fs(oldfs);
49553 + if (copy_to_user(buffer, elf_buf, tsz)) {
49554 + kfree(elf_buf);
49555 return -EFAULT;
49556 + }
49557 }
49558 + set_fs(oldfs);
49559 + kfree(elf_buf);
49560 } else {
49561 if (clear_user(buffer, tsz))
49562 return -EFAULT;
49563 @@ -544,6 +548,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
49564
49565 static int open_kcore(struct inode *inode, struct file *filp)
49566 {
49567 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
49568 + return -EPERM;
49569 +#endif
49570 if (!capable(CAP_SYS_RAWIO))
49571 return -EPERM;
49572 if (kcore_need_update)
49573 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
49574 index 80e4645..53e5fcf 100644
49575 --- a/fs/proc/meminfo.c
49576 +++ b/fs/proc/meminfo.c
49577 @@ -158,7 +158,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
49578 vmi.used >> 10,
49579 vmi.largest_chunk >> 10
49580 #ifdef CONFIG_MEMORY_FAILURE
49581 - ,atomic_long_read(&mce_bad_pages) << (PAGE_SHIFT - 10)
49582 + ,atomic_long_read_unchecked(&mce_bad_pages) << (PAGE_SHIFT - 10)
49583 #endif
49584 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
49585 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
49586 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
49587 index b1822dd..df622cb 100644
49588 --- a/fs/proc/nommu.c
49589 +++ b/fs/proc/nommu.c
49590 @@ -66,7 +66,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
49591 if (len < 1)
49592 len = 1;
49593 seq_printf(m, "%*c", len, ' ');
49594 - seq_path(m, &file->f_path, "");
49595 + seq_path(m, &file->f_path, "\n\\");
49596 }
49597
49598 seq_putc(m, '\n');
49599 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
49600 index 06e1cc1..aa6fbbf 100644
49601 --- a/fs/proc/proc_net.c
49602 +++ b/fs/proc/proc_net.c
49603 @@ -105,6 +105,17 @@ static struct net *get_proc_task_net(struct inode *dir)
49604 struct task_struct *task;
49605 struct nsproxy *ns;
49606 struct net *net = NULL;
49607 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49608 + const struct cred *cred = current_cred();
49609 +#endif
49610 +
49611 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49612 + if (cred->fsuid)
49613 + return net;
49614 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49615 + if (cred->fsuid && !in_group_p(grsec_proc_gid))
49616 + return net;
49617 +#endif
49618
49619 rcu_read_lock();
49620 task = pid_task(proc_pid(dir), PIDTYPE_PID);
49621 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
49622 index 5d00eb8..75e1775 100644
49623 --- a/fs/proc/proc_sysctl.c
49624 +++ b/fs/proc/proc_sysctl.c
49625 @@ -12,11 +12,15 @@
49626 #include <linux/module.h>
49627 #include "internal.h"
49628
49629 +extern int gr_handle_chroot_sysctl(const int op);
49630 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
49631 + const int op);
49632 +
49633 static const struct dentry_operations proc_sys_dentry_operations;
49634 static const struct file_operations proc_sys_file_operations;
49635 -static const struct inode_operations proc_sys_inode_operations;
49636 +const struct inode_operations proc_sys_inode_operations;
49637 static const struct file_operations proc_sys_dir_file_operations;
49638 -static const struct inode_operations proc_sys_dir_operations;
49639 +const struct inode_operations proc_sys_dir_operations;
49640
49641 void proc_sys_poll_notify(struct ctl_table_poll *poll)
49642 {
49643 @@ -467,8 +471,14 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
49644
49645 err = NULL;
49646 d_set_d_op(dentry, &proc_sys_dentry_operations);
49647 +
49648 + gr_handle_proc_create(dentry, inode);
49649 +
49650 d_add(dentry, inode);
49651
49652 + if (!gr_acl_handle_hidden_file(dentry, nd->path.mnt))
49653 + err = ERR_PTR(-ENOENT);
49654 +
49655 out:
49656 if (h)
49657 sysctl_head_finish(h);
49658 @@ -482,18 +492,20 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49659 struct inode *inode = filp->f_path.dentry->d_inode;
49660 struct ctl_table_header *head = grab_header(inode);
49661 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
49662 + int op = write ? MAY_WRITE : MAY_READ;
49663 ssize_t error;
49664 size_t res;
49665
49666 if (IS_ERR(head))
49667 return PTR_ERR(head);
49668
49669 +
49670 /*
49671 * At this point we know that the sysctl was not unregistered
49672 * and won't be until we finish.
49673 */
49674 error = -EPERM;
49675 - if (sysctl_perm(head->root, table, write ? MAY_WRITE : MAY_READ))
49676 + if (sysctl_perm(head->root, table, op))
49677 goto out;
49678
49679 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
49680 @@ -501,6 +513,22 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
49681 if (!table->proc_handler)
49682 goto out;
49683
49684 +#ifdef CONFIG_GRKERNSEC
49685 + error = -EPERM;
49686 + if (gr_handle_chroot_sysctl(op))
49687 + goto out;
49688 + dget(filp->f_path.dentry);
49689 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
49690 + dput(filp->f_path.dentry);
49691 + goto out;
49692 + }
49693 + dput(filp->f_path.dentry);
49694 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
49695 + goto out;
49696 + if (write && !capable(CAP_SYS_ADMIN))
49697 + goto out;
49698 +#endif
49699 +
49700 /* careful: calling conventions are nasty here */
49701 res = count;
49702 error = table->proc_handler(table, write, buf, &res, ppos);
49703 @@ -598,6 +626,9 @@ static int proc_sys_fill_cache(struct file *filp, void *dirent,
49704 return -ENOMEM;
49705 } else {
49706 d_set_d_op(child, &proc_sys_dentry_operations);
49707 +
49708 + gr_handle_proc_create(child, inode);
49709 +
49710 d_add(child, inode);
49711 }
49712 } else {
49713 @@ -641,6 +672,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
49714 if ((*pos)++ < file->f_pos)
49715 return 0;
49716
49717 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
49718 + return 0;
49719 +
49720 if (unlikely(S_ISLNK(table->mode)))
49721 res = proc_sys_link_fill_cache(file, dirent, filldir, head, table);
49722 else
49723 @@ -758,6 +792,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
49724 if (IS_ERR(head))
49725 return PTR_ERR(head);
49726
49727 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
49728 + return -ENOENT;
49729 +
49730 generic_fillattr(inode, stat);
49731 if (table)
49732 stat->mode = (stat->mode & S_IFMT) | table->mode;
49733 @@ -780,13 +817,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
49734 .llseek = generic_file_llseek,
49735 };
49736
49737 -static const struct inode_operations proc_sys_inode_operations = {
49738 +const struct inode_operations proc_sys_inode_operations = {
49739 .permission = proc_sys_permission,
49740 .setattr = proc_sys_setattr,
49741 .getattr = proc_sys_getattr,
49742 };
49743
49744 -static const struct inode_operations proc_sys_dir_operations = {
49745 +const struct inode_operations proc_sys_dir_operations = {
49746 .lookup = proc_sys_lookup,
49747 .permission = proc_sys_permission,
49748 .setattr = proc_sys_setattr,
49749 diff --git a/fs/proc/root.c b/fs/proc/root.c
49750 index 7c30fce..b3d3aa2 100644
49751 --- a/fs/proc/root.c
49752 +++ b/fs/proc/root.c
49753 @@ -188,7 +188,15 @@ void __init proc_root_init(void)
49754 #ifdef CONFIG_PROC_DEVICETREE
49755 proc_device_tree_init();
49756 #endif
49757 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
49758 +#ifdef CONFIG_GRKERNSEC_PROC_USER
49759 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
49760 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
49761 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
49762 +#endif
49763 +#else
49764 proc_mkdir("bus", NULL);
49765 +#endif
49766 proc_sys_init();
49767 }
49768
49769 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
49770 index 4540b8f..1b9772f 100644
49771 --- a/fs/proc/task_mmu.c
49772 +++ b/fs/proc/task_mmu.c
49773 @@ -11,12 +11,19 @@
49774 #include <linux/rmap.h>
49775 #include <linux/swap.h>
49776 #include <linux/swapops.h>
49777 +#include <linux/grsecurity.h>
49778
49779 #include <asm/elf.h>
49780 #include <asm/uaccess.h>
49781 #include <asm/tlbflush.h>
49782 #include "internal.h"
49783
49784 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49785 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
49786 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
49787 + _mm->pax_flags & MF_PAX_SEGMEXEC))
49788 +#endif
49789 +
49790 void task_mem(struct seq_file *m, struct mm_struct *mm)
49791 {
49792 unsigned long data, text, lib, swap;
49793 @@ -52,8 +59,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49794 "VmExe:\t%8lu kB\n"
49795 "VmLib:\t%8lu kB\n"
49796 "VmPTE:\t%8lu kB\n"
49797 - "VmSwap:\t%8lu kB\n",
49798 - hiwater_vm << (PAGE_SHIFT-10),
49799 + "VmSwap:\t%8lu kB\n"
49800 +
49801 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49802 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
49803 +#endif
49804 +
49805 + ,hiwater_vm << (PAGE_SHIFT-10),
49806 (total_vm - mm->reserved_vm) << (PAGE_SHIFT-10),
49807 mm->locked_vm << (PAGE_SHIFT-10),
49808 mm->pinned_vm << (PAGE_SHIFT-10),
49809 @@ -62,7 +74,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49810 data << (PAGE_SHIFT-10),
49811 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
49812 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10,
49813 - swap << (PAGE_SHIFT-10));
49814 + swap << (PAGE_SHIFT-10)
49815 +
49816 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
49817 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49818 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
49819 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
49820 +#else
49821 + , mm->context.user_cs_base
49822 + , mm->context.user_cs_limit
49823 +#endif
49824 +#endif
49825 +
49826 + );
49827 }
49828
49829 unsigned long task_vsize(struct mm_struct *mm)
49830 @@ -231,13 +255,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49831 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
49832 }
49833
49834 - /* We don't show the stack guard page in /proc/maps */
49835 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49836 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
49837 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
49838 +#else
49839 start = vma->vm_start;
49840 - if (stack_guard_page_start(vma, start))
49841 - start += PAGE_SIZE;
49842 end = vma->vm_end;
49843 - if (stack_guard_page_end(vma, end))
49844 - end -= PAGE_SIZE;
49845 +#endif
49846
49847 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n",
49848 start,
49849 @@ -246,7 +270,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49850 flags & VM_WRITE ? 'w' : '-',
49851 flags & VM_EXEC ? 'x' : '-',
49852 flags & VM_MAYSHARE ? 's' : 'p',
49853 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49854 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
49855 +#else
49856 pgoff,
49857 +#endif
49858 MAJOR(dev), MINOR(dev), ino, &len);
49859
49860 /*
49861 @@ -255,7 +283,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49862 */
49863 if (file) {
49864 pad_len_spaces(m, len);
49865 - seq_path(m, &file->f_path, "\n");
49866 + seq_path(m, &file->f_path, "\n\\");
49867 goto done;
49868 }
49869
49870 @@ -281,8 +309,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
49871 * Thread stack in /proc/PID/task/TID/maps or
49872 * the main process stack.
49873 */
49874 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
49875 - vma->vm_end >= mm->start_stack)) {
49876 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
49877 + (vma->vm_start <= mm->start_stack &&
49878 + vma->vm_end >= mm->start_stack)) {
49879 name = "[stack]";
49880 } else {
49881 /* Thread stack in /proc/PID/maps */
49882 @@ -306,6 +335,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
49883 struct proc_maps_private *priv = m->private;
49884 struct task_struct *task = priv->task;
49885
49886 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49887 + if (current->exec_id != m->exec_id) {
49888 + gr_log_badprocpid("maps");
49889 + return 0;
49890 + }
49891 +#endif
49892 +
49893 show_map_vma(m, vma, is_pid);
49894
49895 if (m->count < m->size) /* vma is copied successfully */
49896 @@ -492,12 +528,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49897 .private = &mss,
49898 };
49899
49900 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49901 + if (current->exec_id != m->exec_id) {
49902 + gr_log_badprocpid("smaps");
49903 + return 0;
49904 + }
49905 +#endif
49906 memset(&mss, 0, sizeof mss);
49907 - mss.vma = vma;
49908 - /* mmap_sem is held in m_start */
49909 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49910 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49911 -
49912 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49913 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
49914 +#endif
49915 + mss.vma = vma;
49916 + /* mmap_sem is held in m_start */
49917 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
49918 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
49919 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49920 + }
49921 +#endif
49922 show_map_vma(m, vma, is_pid);
49923
49924 seq_printf(m,
49925 @@ -515,7 +562,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
49926 "KernelPageSize: %8lu kB\n"
49927 "MMUPageSize: %8lu kB\n"
49928 "Locked: %8lu kB\n",
49929 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49930 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
49931 +#else
49932 (vma->vm_end - vma->vm_start) >> 10,
49933 +#endif
49934 mss.resident >> 10,
49935 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
49936 mss.shared_clean >> 10,
49937 @@ -1164,6 +1215,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49938 int n;
49939 char buffer[50];
49940
49941 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49942 + if (current->exec_id != m->exec_id) {
49943 + gr_log_badprocpid("numa_maps");
49944 + return 0;
49945 + }
49946 +#endif
49947 +
49948 if (!mm)
49949 return 0;
49950
49951 @@ -1181,11 +1239,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
49952 mpol_to_str(buffer, sizeof(buffer), pol, 0);
49953 mpol_cond_put(pol);
49954
49955 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
49956 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
49957 +#else
49958 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
49959 +#endif
49960
49961 if (file) {
49962 seq_printf(m, " file=");
49963 - seq_path(m, &file->f_path, "\n\t= ");
49964 + seq_path(m, &file->f_path, "\n\t\\= ");
49965 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
49966 seq_printf(m, " heap");
49967 } else {
49968 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
49969 index 1ccfa53..0848f95 100644
49970 --- a/fs/proc/task_nommu.c
49971 +++ b/fs/proc/task_nommu.c
49972 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
49973 else
49974 bytes += kobjsize(mm);
49975
49976 - if (current->fs && current->fs->users > 1)
49977 + if (current->fs && atomic_read(&current->fs->users) > 1)
49978 sbytes += kobjsize(current->fs);
49979 else
49980 bytes += kobjsize(current->fs);
49981 @@ -168,7 +168,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
49982
49983 if (file) {
49984 pad_len_spaces(m, len);
49985 - seq_path(m, &file->f_path, "");
49986 + seq_path(m, &file->f_path, "\n\\");
49987 } else if (mm) {
49988 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
49989
49990 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
49991 index d67908b..d13f6a6 100644
49992 --- a/fs/quota/netlink.c
49993 +++ b/fs/quota/netlink.c
49994 @@ -33,7 +33,7 @@ static struct genl_family quota_genl_family = {
49995 void quota_send_warning(short type, unsigned int id, dev_t dev,
49996 const char warntype)
49997 {
49998 - static atomic_t seq;
49999 + static atomic_unchecked_t seq;
50000 struct sk_buff *skb;
50001 void *msg_head;
50002 int ret;
50003 @@ -49,7 +49,7 @@ void quota_send_warning(short type, unsigned int id, dev_t dev,
50004 "VFS: Not enough memory to send quota warning.\n");
50005 return;
50006 }
50007 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
50008 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
50009 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
50010 if (!msg_head) {
50011 printk(KERN_ERR
50012 diff --git a/fs/readdir.c b/fs/readdir.c
50013 index 39e3370..20d446d 100644
50014 --- a/fs/readdir.c
50015 +++ b/fs/readdir.c
50016 @@ -17,6 +17,7 @@
50017 #include <linux/security.h>
50018 #include <linux/syscalls.h>
50019 #include <linux/unistd.h>
50020 +#include <linux/namei.h>
50021
50022 #include <asm/uaccess.h>
50023
50024 @@ -67,6 +68,7 @@ struct old_linux_dirent {
50025
50026 struct readdir_callback {
50027 struct old_linux_dirent __user * dirent;
50028 + struct file * file;
50029 int result;
50030 };
50031
50032 @@ -84,6 +86,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
50033 buf->result = -EOVERFLOW;
50034 return -EOVERFLOW;
50035 }
50036 +
50037 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50038 + return 0;
50039 +
50040 buf->result++;
50041 dirent = buf->dirent;
50042 if (!access_ok(VERIFY_WRITE, dirent,
50043 @@ -116,6 +122,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
50044
50045 buf.result = 0;
50046 buf.dirent = dirent;
50047 + buf.file = file;
50048
50049 error = vfs_readdir(file, fillonedir, &buf);
50050 if (buf.result)
50051 @@ -141,6 +148,7 @@ struct linux_dirent {
50052 struct getdents_callback {
50053 struct linux_dirent __user * current_dir;
50054 struct linux_dirent __user * previous;
50055 + struct file * file;
50056 int count;
50057 int error;
50058 };
50059 @@ -162,6 +170,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
50060 buf->error = -EOVERFLOW;
50061 return -EOVERFLOW;
50062 }
50063 +
50064 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50065 + return 0;
50066 +
50067 dirent = buf->previous;
50068 if (dirent) {
50069 if (__put_user(offset, &dirent->d_off))
50070 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50071 buf.previous = NULL;
50072 buf.count = count;
50073 buf.error = 0;
50074 + buf.file = file;
50075
50076 error = vfs_readdir(file, filldir, &buf);
50077 if (error >= 0)
50078 @@ -226,6 +239,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
50079 struct getdents_callback64 {
50080 struct linux_dirent64 __user * current_dir;
50081 struct linux_dirent64 __user * previous;
50082 + struct file *file;
50083 int count;
50084 int error;
50085 };
50086 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
50087 buf->error = -EINVAL; /* only used if we fail.. */
50088 if (reclen > buf->count)
50089 return -EINVAL;
50090 +
50091 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
50092 + return 0;
50093 +
50094 dirent = buf->previous;
50095 if (dirent) {
50096 if (__put_user(offset, &dirent->d_off))
50097 @@ -287,6 +305,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50098
50099 buf.current_dir = dirent;
50100 buf.previous = NULL;
50101 + buf.file = file;
50102 buf.count = count;
50103 buf.error = 0;
50104
50105 @@ -295,7 +314,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
50106 error = buf.error;
50107 lastdirent = buf.previous;
50108 if (lastdirent) {
50109 - typeof(lastdirent->d_off) d_off = file->f_pos;
50110 + typeof(((struct linux_dirent64 *)0)->d_off) d_off = file->f_pos;
50111 if (__put_user(d_off, &lastdirent->d_off))
50112 error = -EFAULT;
50113 else
50114 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
50115 index 2b7882b..1c5ef48 100644
50116 --- a/fs/reiserfs/do_balan.c
50117 +++ b/fs/reiserfs/do_balan.c
50118 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
50119 return;
50120 }
50121
50122 - atomic_inc(&(fs_generation(tb->tb_sb)));
50123 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
50124 do_balance_starts(tb);
50125
50126 /* balance leaf returns 0 except if combining L R and S into
50127 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
50128 index 2c1ade6..8c59d8d 100644
50129 --- a/fs/reiserfs/procfs.c
50130 +++ b/fs/reiserfs/procfs.c
50131 @@ -112,7 +112,7 @@ static int show_super(struct seq_file *m, struct super_block *sb)
50132 "SMALL_TAILS " : "NO_TAILS ",
50133 replay_only(sb) ? "REPLAY_ONLY " : "",
50134 convert_reiserfs(sb) ? "CONV " : "",
50135 - atomic_read(&r->s_generation_counter),
50136 + atomic_read_unchecked(&r->s_generation_counter),
50137 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
50138 SF(s_do_balance), SF(s_unneeded_left_neighbor),
50139 SF(s_good_search_by_key_reada), SF(s_bmaps),
50140 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
50141 index 33215f5..c5d427a 100644
50142 --- a/fs/reiserfs/reiserfs.h
50143 +++ b/fs/reiserfs/reiserfs.h
50144 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
50145 /* Comment? -Hans */
50146 wait_queue_head_t s_wait;
50147 /* To be obsoleted soon by per buffer seals.. -Hans */
50148 - atomic_t s_generation_counter; // increased by one every time the
50149 + atomic_unchecked_t s_generation_counter; // increased by one every time the
50150 // tree gets re-balanced
50151 unsigned long s_properties; /* File system properties. Currently holds
50152 on-disk FS format */
50153 @@ -1978,7 +1978,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
50154 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
50155
50156 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
50157 -#define get_generation(s) atomic_read (&fs_generation(s))
50158 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
50159 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
50160 #define __fs_changed(gen,s) (gen != get_generation (s))
50161 #define fs_changed(gen,s) \
50162 diff --git a/fs/select.c b/fs/select.c
50163 index db14c78..3aae1bd 100644
50164 --- a/fs/select.c
50165 +++ b/fs/select.c
50166 @@ -20,6 +20,7 @@
50167 #include <linux/export.h>
50168 #include <linux/slab.h>
50169 #include <linux/poll.h>
50170 +#include <linux/security.h>
50171 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
50172 #include <linux/file.h>
50173 #include <linux/fdtable.h>
50174 @@ -831,6 +832,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
50175 struct poll_list *walk = head;
50176 unsigned long todo = nfds;
50177
50178 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
50179 if (nfds > rlimit(RLIMIT_NOFILE))
50180 return -EINVAL;
50181
50182 diff --git a/fs/seq_file.c b/fs/seq_file.c
50183 index 0cbd049..64e705c 100644
50184 --- a/fs/seq_file.c
50185 +++ b/fs/seq_file.c
50186 @@ -9,6 +9,7 @@
50187 #include <linux/export.h>
50188 #include <linux/seq_file.h>
50189 #include <linux/slab.h>
50190 +#include <linux/sched.h>
50191
50192 #include <asm/uaccess.h>
50193 #include <asm/page.h>
50194 @@ -56,6 +57,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
50195 memset(p, 0, sizeof(*p));
50196 mutex_init(&p->lock);
50197 p->op = op;
50198 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
50199 + p->exec_id = current->exec_id;
50200 +#endif
50201
50202 /*
50203 * Wrappers around seq_open(e.g. swaps_open) need to be
50204 @@ -92,7 +96,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50205 return 0;
50206 }
50207 if (!m->buf) {
50208 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50209 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50210 if (!m->buf)
50211 return -ENOMEM;
50212 }
50213 @@ -132,7 +136,7 @@ static int traverse(struct seq_file *m, loff_t offset)
50214 Eoverflow:
50215 m->op->stop(m, p);
50216 kfree(m->buf);
50217 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50218 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50219 return !m->buf ? -ENOMEM : -EAGAIN;
50220 }
50221
50222 @@ -187,7 +191,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50223
50224 /* grab buffer if we didn't have one */
50225 if (!m->buf) {
50226 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
50227 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
50228 if (!m->buf)
50229 goto Enomem;
50230 }
50231 @@ -228,7 +232,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
50232 goto Fill;
50233 m->op->stop(m, p);
50234 kfree(m->buf);
50235 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
50236 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
50237 if (!m->buf)
50238 goto Enomem;
50239 m->count = 0;
50240 @@ -567,7 +571,7 @@ static void single_stop(struct seq_file *p, void *v)
50241 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
50242 void *data)
50243 {
50244 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
50245 + seq_operations_no_const *op = kmalloc(sizeof(*op), GFP_KERNEL);
50246 int res = -ENOMEM;
50247
50248 if (op) {
50249 diff --git a/fs/splice.c b/fs/splice.c
50250 index 7bf08fa..eb35c2f 100644
50251 --- a/fs/splice.c
50252 +++ b/fs/splice.c
50253 @@ -194,7 +194,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50254 pipe_lock(pipe);
50255
50256 for (;;) {
50257 - if (!pipe->readers) {
50258 + if (!atomic_read(&pipe->readers)) {
50259 send_sig(SIGPIPE, current, 0);
50260 if (!ret)
50261 ret = -EPIPE;
50262 @@ -248,9 +248,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
50263 do_wakeup = 0;
50264 }
50265
50266 - pipe->waiting_writers++;
50267 + atomic_inc(&pipe->waiting_writers);
50268 pipe_wait(pipe);
50269 - pipe->waiting_writers--;
50270 + atomic_dec(&pipe->waiting_writers);
50271 }
50272
50273 pipe_unlock(pipe);
50274 @@ -563,7 +563,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
50275 old_fs = get_fs();
50276 set_fs(get_ds());
50277 /* The cast to a user pointer is valid due to the set_fs() */
50278 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
50279 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
50280 set_fs(old_fs);
50281
50282 return res;
50283 @@ -578,7 +578,7 @@ static ssize_t kernel_write(struct file *file, const char *buf, size_t count,
50284 old_fs = get_fs();
50285 set_fs(get_ds());
50286 /* The cast to a user pointer is valid due to the set_fs() */
50287 - res = vfs_write(file, (const char __user *)buf, count, &pos);
50288 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
50289 set_fs(old_fs);
50290
50291 return res;
50292 @@ -630,7 +630,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
50293 goto err;
50294
50295 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
50296 - vec[i].iov_base = (void __user *) page_address(page);
50297 + vec[i].iov_base = (void __force_user *) page_address(page);
50298 vec[i].iov_len = this_len;
50299 spd.pages[i] = page;
50300 spd.nr_pages++;
50301 @@ -849,10 +849,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
50302 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
50303 {
50304 while (!pipe->nrbufs) {
50305 - if (!pipe->writers)
50306 + if (!atomic_read(&pipe->writers))
50307 return 0;
50308
50309 - if (!pipe->waiting_writers && sd->num_spliced)
50310 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
50311 return 0;
50312
50313 if (sd->flags & SPLICE_F_NONBLOCK)
50314 @@ -1187,7 +1187,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
50315 * out of the pipe right after the splice_to_pipe(). So set
50316 * PIPE_READERS appropriately.
50317 */
50318 - pipe->readers = 1;
50319 + atomic_set(&pipe->readers, 1);
50320
50321 current->splice_pipe = pipe;
50322 }
50323 @@ -1740,9 +1740,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50324 ret = -ERESTARTSYS;
50325 break;
50326 }
50327 - if (!pipe->writers)
50328 + if (!atomic_read(&pipe->writers))
50329 break;
50330 - if (!pipe->waiting_writers) {
50331 + if (!atomic_read(&pipe->waiting_writers)) {
50332 if (flags & SPLICE_F_NONBLOCK) {
50333 ret = -EAGAIN;
50334 break;
50335 @@ -1774,7 +1774,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50336 pipe_lock(pipe);
50337
50338 while (pipe->nrbufs >= pipe->buffers) {
50339 - if (!pipe->readers) {
50340 + if (!atomic_read(&pipe->readers)) {
50341 send_sig(SIGPIPE, current, 0);
50342 ret = -EPIPE;
50343 break;
50344 @@ -1787,9 +1787,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
50345 ret = -ERESTARTSYS;
50346 break;
50347 }
50348 - pipe->waiting_writers++;
50349 + atomic_inc(&pipe->waiting_writers);
50350 pipe_wait(pipe);
50351 - pipe->waiting_writers--;
50352 + atomic_dec(&pipe->waiting_writers);
50353 }
50354
50355 pipe_unlock(pipe);
50356 @@ -1825,14 +1825,14 @@ retry:
50357 pipe_double_lock(ipipe, opipe);
50358
50359 do {
50360 - if (!opipe->readers) {
50361 + if (!atomic_read(&opipe->readers)) {
50362 send_sig(SIGPIPE, current, 0);
50363 if (!ret)
50364 ret = -EPIPE;
50365 break;
50366 }
50367
50368 - if (!ipipe->nrbufs && !ipipe->writers)
50369 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
50370 break;
50371
50372 /*
50373 @@ -1929,7 +1929,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50374 pipe_double_lock(ipipe, opipe);
50375
50376 do {
50377 - if (!opipe->readers) {
50378 + if (!atomic_read(&opipe->readers)) {
50379 send_sig(SIGPIPE, current, 0);
50380 if (!ret)
50381 ret = -EPIPE;
50382 @@ -1974,7 +1974,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
50383 * return EAGAIN if we have the potential of some data in the
50384 * future, otherwise just return 0
50385 */
50386 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
50387 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
50388 ret = -EAGAIN;
50389
50390 pipe_unlock(ipipe);
50391 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
50392 index e6bb9b2..d8e3951 100644
50393 --- a/fs/sysfs/dir.c
50394 +++ b/fs/sysfs/dir.c
50395 @@ -678,6 +678,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
50396 struct sysfs_dirent *sd;
50397 int rc;
50398
50399 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
50400 + const char *parent_name = parent_sd->s_name;
50401 +
50402 + mode = S_IFDIR | S_IRWXU;
50403 +
50404 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
50405 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
50406 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse"))) ||
50407 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
50408 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
50409 +#endif
50410 +
50411 /* allocate */
50412 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
50413 if (!sd)
50414 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
50415 index 00012e3..8392349 100644
50416 --- a/fs/sysfs/file.c
50417 +++ b/fs/sysfs/file.c
50418 @@ -37,7 +37,7 @@ static DEFINE_SPINLOCK(sysfs_open_dirent_lock);
50419
50420 struct sysfs_open_dirent {
50421 atomic_t refcnt;
50422 - atomic_t event;
50423 + atomic_unchecked_t event;
50424 wait_queue_head_t poll;
50425 struct list_head buffers; /* goes through sysfs_buffer.list */
50426 };
50427 @@ -81,7 +81,7 @@ static int fill_read_buffer(struct dentry * dentry, struct sysfs_buffer * buffer
50428 if (!sysfs_get_active(attr_sd))
50429 return -ENODEV;
50430
50431 - buffer->event = atomic_read(&attr_sd->s_attr.open->event);
50432 + buffer->event = atomic_read_unchecked(&attr_sd->s_attr.open->event);
50433 count = ops->show(kobj, attr_sd->s_attr.attr, buffer->page);
50434
50435 sysfs_put_active(attr_sd);
50436 @@ -287,7 +287,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
50437 return -ENOMEM;
50438
50439 atomic_set(&new_od->refcnt, 0);
50440 - atomic_set(&new_od->event, 1);
50441 + atomic_set_unchecked(&new_od->event, 1);
50442 init_waitqueue_head(&new_od->poll);
50443 INIT_LIST_HEAD(&new_od->buffers);
50444 goto retry;
50445 @@ -432,7 +432,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
50446
50447 sysfs_put_active(attr_sd);
50448
50449 - if (buffer->event != atomic_read(&od->event))
50450 + if (buffer->event != atomic_read_unchecked(&od->event))
50451 goto trigger;
50452
50453 return DEFAULT_POLLMASK;
50454 @@ -451,7 +451,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
50455
50456 od = sd->s_attr.open;
50457 if (od) {
50458 - atomic_inc(&od->event);
50459 + atomic_inc_unchecked(&od->event);
50460 wake_up_interruptible(&od->poll);
50461 }
50462
50463 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
50464 index a7ac78f..02158e1 100644
50465 --- a/fs/sysfs/symlink.c
50466 +++ b/fs/sysfs/symlink.c
50467 @@ -286,7 +286,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
50468
50469 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
50470 {
50471 - char *page = nd_get_link(nd);
50472 + const char *page = nd_get_link(nd);
50473 if (!IS_ERR(page))
50474 free_page((unsigned long)page);
50475 }
50476 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
50477 index c175b4d..8f36a16 100644
50478 --- a/fs/udf/misc.c
50479 +++ b/fs/udf/misc.c
50480 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
50481
50482 u8 udf_tag_checksum(const struct tag *t)
50483 {
50484 - u8 *data = (u8 *)t;
50485 + const u8 *data = (const u8 *)t;
50486 u8 checksum = 0;
50487 int i;
50488 for (i = 0; i < sizeof(struct tag); ++i)
50489 diff --git a/fs/udf/namei.c b/fs/udf/namei.c
50490 index 1802417..c31deb3 100644
50491 --- a/fs/udf/namei.c
50492 +++ b/fs/udf/namei.c
50493 @@ -1279,6 +1279,7 @@ static int udf_encode_fh(struct inode *inode, __u32 *fh, int *lenp,
50494 *lenp = 3;
50495 fid->udf.block = location.logicalBlockNum;
50496 fid->udf.partref = location.partitionReferenceNum;
50497 + fid->udf.parent_partref = 0;
50498 fid->udf.generation = inode->i_generation;
50499
50500 if (parent) {
50501 diff --git a/fs/utimes.c b/fs/utimes.c
50502 index fa4dbe4..e12d1b9 100644
50503 --- a/fs/utimes.c
50504 +++ b/fs/utimes.c
50505 @@ -1,6 +1,7 @@
50506 #include <linux/compiler.h>
50507 #include <linux/file.h>
50508 #include <linux/fs.h>
50509 +#include <linux/security.h>
50510 #include <linux/linkage.h>
50511 #include <linux/mount.h>
50512 #include <linux/namei.h>
50513 @@ -101,6 +102,12 @@ static int utimes_common(struct path *path, struct timespec *times)
50514 goto mnt_drop_write_and_out;
50515 }
50516 }
50517 +
50518 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
50519 + error = -EACCES;
50520 + goto mnt_drop_write_and_out;
50521 + }
50522 +
50523 mutex_lock(&inode->i_mutex);
50524 error = notify_change(path->dentry, &newattrs);
50525 mutex_unlock(&inode->i_mutex);
50526 diff --git a/fs/xattr.c b/fs/xattr.c
50527 index 1d7ac37..23cb9ec 100644
50528 --- a/fs/xattr.c
50529 +++ b/fs/xattr.c
50530 @@ -316,7 +316,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
50531 * Extended attribute SET operations
50532 */
50533 static long
50534 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
50535 +setxattr(struct path *path, const char __user *name, const void __user *value,
50536 size_t size, int flags)
50537 {
50538 int error;
50539 @@ -349,7 +349,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
50540 }
50541 }
50542
50543 - error = vfs_setxattr(d, kname, kvalue, size, flags);
50544 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
50545 + error = -EACCES;
50546 + goto out;
50547 + }
50548 +
50549 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
50550 out:
50551 if (vvalue)
50552 vfree(vvalue);
50553 @@ -370,7 +375,7 @@ SYSCALL_DEFINE5(setxattr, const char __user *, pathname,
50554 return error;
50555 error = mnt_want_write(path.mnt);
50556 if (!error) {
50557 - error = setxattr(path.dentry, name, value, size, flags);
50558 + error = setxattr(&path, name, value, size, flags);
50559 mnt_drop_write(path.mnt);
50560 }
50561 path_put(&path);
50562 @@ -389,7 +394,7 @@ SYSCALL_DEFINE5(lsetxattr, const char __user *, pathname,
50563 return error;
50564 error = mnt_want_write(path.mnt);
50565 if (!error) {
50566 - error = setxattr(path.dentry, name, value, size, flags);
50567 + error = setxattr(&path, name, value, size, flags);
50568 mnt_drop_write(path.mnt);
50569 }
50570 path_put(&path);
50571 @@ -401,17 +406,15 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
50572 {
50573 int fput_needed;
50574 struct file *f;
50575 - struct dentry *dentry;
50576 int error = -EBADF;
50577
50578 f = fget_light(fd, &fput_needed);
50579 if (!f)
50580 return error;
50581 - dentry = f->f_path.dentry;
50582 - audit_inode(NULL, dentry);
50583 + audit_inode(NULL, f->f_path.dentry);
50584 error = mnt_want_write_file(f);
50585 if (!error) {
50586 - error = setxattr(dentry, name, value, size, flags);
50587 + error = setxattr(&f->f_path, name, value, size, flags);
50588 mnt_drop_write_file(f);
50589 }
50590 fput_light(f, fput_needed);
50591 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
50592 index 69d06b0..c0996e5 100644
50593 --- a/fs/xattr_acl.c
50594 +++ b/fs/xattr_acl.c
50595 @@ -17,8 +17,8 @@
50596 struct posix_acl *
50597 posix_acl_from_xattr(const void *value, size_t size)
50598 {
50599 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
50600 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
50601 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
50602 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
50603 int count;
50604 struct posix_acl *acl;
50605 struct posix_acl_entry *acl_e;
50606 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
50607 index 58b815e..595ddee 100644
50608 --- a/fs/xfs/xfs_bmap.c
50609 +++ b/fs/xfs/xfs_bmap.c
50610 @@ -189,7 +189,7 @@ xfs_bmap_validate_ret(
50611 int nmap,
50612 int ret_nmap);
50613 #else
50614 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
50615 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do {} while (0)
50616 #endif /* DEBUG */
50617
50618 STATIC int
50619 diff --git a/fs/xfs/xfs_dir2_sf.c b/fs/xfs/xfs_dir2_sf.c
50620 index 19bf0c5..9f26b02 100644
50621 --- a/fs/xfs/xfs_dir2_sf.c
50622 +++ b/fs/xfs/xfs_dir2_sf.c
50623 @@ -851,7 +851,15 @@ xfs_dir2_sf_getdents(
50624 }
50625
50626 ino = xfs_dir2_sfe_get_ino(sfp, sfep);
50627 - if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50628 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
50629 + char name[sfep->namelen];
50630 + memcpy(name, sfep->name, sfep->namelen);
50631 + if (filldir(dirent, name, sfep->namelen,
50632 + off & 0x7fffffff, ino, DT_UNKNOWN)) {
50633 + *offset = off & 0x7fffffff;
50634 + return 0;
50635 + }
50636 + } else if (filldir(dirent, (char *)sfep->name, sfep->namelen,
50637 off & 0x7fffffff, ino, DT_UNKNOWN)) {
50638 *offset = off & 0x7fffffff;
50639 return 0;
50640 diff --git a/fs/xfs/xfs_discard.c b/fs/xfs/xfs_discard.c
50641 index f9c3fe3..69cf4fc 100644
50642 --- a/fs/xfs/xfs_discard.c
50643 +++ b/fs/xfs/xfs_discard.c
50644 @@ -179,12 +179,14 @@ xfs_ioc_trim(
50645 * used by the fstrim application. In the end it really doesn't
50646 * matter as trimming blocks is an advisory interface.
50647 */
50648 + if (range.start >= XFS_FSB_TO_B(mp, mp->m_sb.sb_dblocks) ||
50649 + range.minlen > XFS_FSB_TO_B(mp, XFS_ALLOC_AG_MAX_USABLE(mp)))
50650 + return -XFS_ERROR(EINVAL);
50651 +
50652 start = BTOBB(range.start);
50653 end = start + BTOBBT(range.len) - 1;
50654 minlen = BTOBB(max_t(u64, granularity, range.minlen));
50655
50656 - if (XFS_BB_TO_FSB(mp, start) >= mp->m_sb.sb_dblocks)
50657 - return -XFS_ERROR(EINVAL);
50658 if (end > XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks) - 1)
50659 end = XFS_FSB_TO_BB(mp, mp->m_sb.sb_dblocks)- 1;
50660
50661 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
50662 index 3a05a41..320bec6 100644
50663 --- a/fs/xfs/xfs_ioctl.c
50664 +++ b/fs/xfs/xfs_ioctl.c
50665 @@ -126,7 +126,7 @@ xfs_find_handle(
50666 }
50667
50668 error = -EFAULT;
50669 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
50670 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
50671 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
50672 goto out_put;
50673
50674 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
50675 index 1a25fd8..e935581 100644
50676 --- a/fs/xfs/xfs_iops.c
50677 +++ b/fs/xfs/xfs_iops.c
50678 @@ -394,7 +394,7 @@ xfs_vn_put_link(
50679 struct nameidata *nd,
50680 void *p)
50681 {
50682 - char *s = nd_get_link(nd);
50683 + const char *s = nd_get_link(nd);
50684
50685 if (!IS_ERR(s))
50686 kfree(s);
50687 diff --git a/fs/xfs/xfs_rtalloc.c b/fs/xfs/xfs_rtalloc.c
50688 index 92d4331..ca28a4b 100644
50689 --- a/fs/xfs/xfs_rtalloc.c
50690 +++ b/fs/xfs/xfs_rtalloc.c
50691 @@ -857,7 +857,7 @@ xfs_rtbuf_get(
50692 xfs_buf_t *bp; /* block buffer, result */
50693 xfs_inode_t *ip; /* bitmap or summary inode */
50694 xfs_bmbt_irec_t map;
50695 - int nmap;
50696 + int nmap = 1;
50697 int error; /* error value */
50698
50699 ip = issum ? mp->m_rsumip : mp->m_rbmip;
50700 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
50701 new file mode 100644
50702 index 0000000..d38b430
50703 --- /dev/null
50704 +++ b/grsecurity/Kconfig
50705 @@ -0,0 +1,947 @@
50706 +#
50707 +# grecurity configuration
50708 +#
50709 +menu "Memory Protections"
50710 +depends on GRKERNSEC
50711 +
50712 +config GRKERNSEC_KMEM
50713 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
50714 + default y if GRKERNSEC_CONFIG_AUTO
50715 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
50716 + help
50717 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
50718 + be written to or read from to modify or leak the contents of the running
50719 + kernel. /dev/port will also not be allowed to be opened. If you have module
50720 + support disabled, enabling this will close up four ways that are
50721 + currently used to insert malicious code into the running kernel.
50722 + Even with all these features enabled, we still highly recommend that
50723 + you use the RBAC system, as it is still possible for an attacker to
50724 + modify the running kernel through privileged I/O granted by ioperm/iopl.
50725 + If you are not using XFree86, you may be able to stop this additional
50726 + case by enabling the 'Disable privileged I/O' option. Though nothing
50727 + legitimately writes to /dev/kmem, XFree86 does need to write to /dev/mem,
50728 + but only to video memory, which is the only writing we allow in this
50729 + case. If /dev/kmem or /dev/mem are mmaped without PROT_WRITE, they will
50730 + not be allowed to mprotect it with PROT_WRITE later.
50731 + It is highly recommended that you say Y here if you meet all the
50732 + conditions above.
50733 +
50734 +config GRKERNSEC_VM86
50735 + bool "Restrict VM86 mode"
50736 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50737 + depends on X86_32
50738 +
50739 + help
50740 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
50741 + make use of a special execution mode on 32bit x86 processors called
50742 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
50743 + video cards and will still work with this option enabled. The purpose
50744 + of the option is to prevent exploitation of emulation errors in
50745 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
50746 + Nearly all users should be able to enable this option.
50747 +
50748 +config GRKERNSEC_IO
50749 + bool "Disable privileged I/O"
50750 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
50751 + depends on X86
50752 + select RTC_CLASS
50753 + select RTC_INTF_DEV
50754 + select RTC_DRV_CMOS
50755 +
50756 + help
50757 + If you say Y here, all ioperm and iopl calls will return an error.
50758 + Ioperm and iopl can be used to modify the running kernel.
50759 + Unfortunately, some programs need this access to operate properly,
50760 + the most notable of which are XFree86 and hwclock. hwclock can be
50761 + remedied by having RTC support in the kernel, so real-time
50762 + clock support is enabled if this option is enabled, to ensure
50763 + that hwclock operates correctly. XFree86 still will not
50764 + operate correctly with this option enabled, so DO NOT CHOOSE Y
50765 + IF YOU USE XFree86. If you use XFree86 and you still want to
50766 + protect your kernel against modification, use the RBAC system.
50767 +
50768 +config GRKERNSEC_PROC_MEMMAP
50769 + bool "Harden ASLR against information leaks and entropy reduction"
50770 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
50771 + depends on PAX_NOEXEC || PAX_ASLR
50772 + help
50773 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
50774 + give no information about the addresses of its mappings if
50775 + PaX features that rely on random addresses are enabled on the task.
50776 + In addition to sanitizing this information and disabling other
50777 + dangerous sources of information, this option causes reads of sensitive
50778 + /proc/<pid> entries where the file descriptor was opened in a different
50779 + task than the one performing the read. Such attempts are logged.
50780 + This option also limits argv/env strings for suid/sgid binaries
50781 + to 512KB to prevent a complete exhaustion of the stack entropy provided
50782 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
50783 + binaries to prevent alternative mmap layouts from being abused.
50784 +
50785 + If you use PaX it is essential that you say Y here as it closes up
50786 + several holes that make full ASLR useless locally.
50787 +
50788 +config GRKERNSEC_BRUTE
50789 + bool "Deter exploit bruteforcing"
50790 + default y if GRKERNSEC_CONFIG_AUTO
50791 + help
50792 + If you say Y here, attempts to bruteforce exploits against forking
50793 + daemons such as apache or sshd, as well as against suid/sgid binaries
50794 + will be deterred. When a child of a forking daemon is killed by PaX
50795 + or crashes due to an illegal instruction or other suspicious signal,
50796 + the parent process will be delayed 30 seconds upon every subsequent
50797 + fork until the administrator is able to assess the situation and
50798 + restart the daemon.
50799 + In the suid/sgid case, the attempt is logged, the user has all their
50800 + processes terminated, and they are prevented from executing any further
50801 + processes for 15 minutes.
50802 + It is recommended that you also enable signal logging in the auditing
50803 + section so that logs are generated when a process triggers a suspicious
50804 + signal.
50805 + If the sysctl option is enabled, a sysctl option with name
50806 + "deter_bruteforce" is created.
50807 +
50808 +
50809 +config GRKERNSEC_MODHARDEN
50810 + bool "Harden module auto-loading"
50811 + default y if GRKERNSEC_CONFIG_AUTO
50812 + depends on MODULES
50813 + help
50814 + If you say Y here, module auto-loading in response to use of some
50815 + feature implemented by an unloaded module will be restricted to
50816 + root users. Enabling this option helps defend against attacks
50817 + by unprivileged users who abuse the auto-loading behavior to
50818 + cause a vulnerable module to load that is then exploited.
50819 +
50820 + If this option prevents a legitimate use of auto-loading for a
50821 + non-root user, the administrator can execute modprobe manually
50822 + with the exact name of the module mentioned in the alert log.
50823 + Alternatively, the administrator can add the module to the list
50824 + of modules loaded at boot by modifying init scripts.
50825 +
50826 + Modification of init scripts will most likely be needed on
50827 + Ubuntu servers with encrypted home directory support enabled,
50828 + as the first non-root user logging in will cause the ecb(aes),
50829 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
50830 +
50831 +config GRKERNSEC_HIDESYM
50832 + bool "Hide kernel symbols"
50833 + default y if GRKERNSEC_CONFIG_AUTO
50834 + select PAX_USERCOPY_SLABS
50835 + help
50836 + If you say Y here, getting information on loaded modules, and
50837 + displaying all kernel symbols through a syscall will be restricted
50838 + to users with CAP_SYS_MODULE. For software compatibility reasons,
50839 + /proc/kallsyms will be restricted to the root user. The RBAC
50840 + system can hide that entry even from root.
50841 +
50842 + This option also prevents leaking of kernel addresses through
50843 + several /proc entries.
50844 +
50845 + Note that this option is only effective provided the following
50846 + conditions are met:
50847 + 1) The kernel using grsecurity is not precompiled by some distribution
50848 + 2) You have also enabled GRKERNSEC_DMESG
50849 + 3) You are using the RBAC system and hiding other files such as your
50850 + kernel image and System.map. Alternatively, enabling this option
50851 + causes the permissions on /boot, /lib/modules, and the kernel
50852 + source directory to change at compile time to prevent
50853 + reading by non-root users.
50854 + If the above conditions are met, this option will aid in providing a
50855 + useful protection against local kernel exploitation of overflows
50856 + and arbitrary read/write vulnerabilities.
50857 +
50858 +config GRKERNSEC_KERN_LOCKOUT
50859 + bool "Active kernel exploit response"
50860 + default y if GRKERNSEC_CONFIG_AUTO
50861 + depends on X86 || ARM || PPC || SPARC
50862 + help
50863 + If you say Y here, when a PaX alert is triggered due to suspicious
50864 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
50865 + or an OOPS occurs due to bad memory accesses, instead of just
50866 + terminating the offending process (and potentially allowing
50867 + a subsequent exploit from the same user), we will take one of two
50868 + actions:
50869 + If the user was root, we will panic the system
50870 + If the user was non-root, we will log the attempt, terminate
50871 + all processes owned by the user, then prevent them from creating
50872 + any new processes until the system is restarted
50873 + This deters repeated kernel exploitation/bruteforcing attempts
50874 + and is useful for later forensics.
50875 +
50876 +endmenu
50877 +menu "Role Based Access Control Options"
50878 +depends on GRKERNSEC
50879 +
50880 +config GRKERNSEC_RBAC_DEBUG
50881 + bool
50882 +
50883 +config GRKERNSEC_NO_RBAC
50884 + bool "Disable RBAC system"
50885 + help
50886 + If you say Y here, the /dev/grsec device will be removed from the kernel,
50887 + preventing the RBAC system from being enabled. You should only say Y
50888 + here if you have no intention of using the RBAC system, so as to prevent
50889 + an attacker with root access from misusing the RBAC system to hide files
50890 + and processes when loadable module support and /dev/[k]mem have been
50891 + locked down.
50892 +
50893 +config GRKERNSEC_ACL_HIDEKERN
50894 + bool "Hide kernel processes"
50895 + help
50896 + If you say Y here, all kernel threads will be hidden to all
50897 + processes but those whose subject has the "view hidden processes"
50898 + flag.
50899 +
50900 +config GRKERNSEC_ACL_MAXTRIES
50901 + int "Maximum tries before password lockout"
50902 + default 3
50903 + help
50904 + This option enforces the maximum number of times a user can attempt
50905 + to authorize themselves with the grsecurity RBAC system before being
50906 + denied the ability to attempt authorization again for a specified time.
50907 + The lower the number, the harder it will be to brute-force a password.
50908 +
50909 +config GRKERNSEC_ACL_TIMEOUT
50910 + int "Time to wait after max password tries, in seconds"
50911 + default 30
50912 + help
50913 + This option specifies the time the user must wait after attempting to
50914 + authorize to the RBAC system with the maximum number of invalid
50915 + passwords. The higher the number, the harder it will be to brute-force
50916 + a password.
50917 +
50918 +endmenu
50919 +menu "Filesystem Protections"
50920 +depends on GRKERNSEC
50921 +
50922 +config GRKERNSEC_PROC
50923 + bool "Proc restrictions"
50924 + default y if GRKERNSEC_CONFIG_AUTO
50925 + help
50926 + If you say Y here, the permissions of the /proc filesystem
50927 + will be altered to enhance system security and privacy. You MUST
50928 + choose either a user only restriction or a user and group restriction.
50929 + Depending upon the option you choose, you can either restrict users to
50930 + see only the processes they themselves run, or choose a group that can
50931 + view all processes and files normally restricted to root if you choose
50932 + the "restrict to user only" option. NOTE: If you're running identd or
50933 + ntpd as a non-root user, you will have to run it as the group you
50934 + specify here.
50935 +
50936 +config GRKERNSEC_PROC_USER
50937 + bool "Restrict /proc to user only"
50938 + depends on GRKERNSEC_PROC
50939 + help
50940 + If you say Y here, non-root users will only be able to view their own
50941 + processes, and restricts them from viewing network-related information,
50942 + and viewing kernel symbol and module information.
50943 +
50944 +config GRKERNSEC_PROC_USERGROUP
50945 + bool "Allow special group"
50946 + default y if GRKERNSEC_CONFIG_AUTO
50947 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
50948 + help
50949 + If you say Y here, you will be able to select a group that will be
50950 + able to view all processes and network-related information. If you've
50951 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
50952 + remain hidden. This option is useful if you want to run identd as
50953 + a non-root user. The group you select may also be chosen at boot time
50954 + via "grsec_proc_gid=" on the kernel commandline.
50955 +
50956 +config GRKERNSEC_PROC_GID
50957 + int "GID for special group"
50958 + depends on GRKERNSEC_PROC_USERGROUP
50959 + default 1001
50960 +
50961 +config GRKERNSEC_PROC_ADD
50962 + bool "Additional restrictions"
50963 + default y if GRKERNSEC_CONFIG_AUTO
50964 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
50965 + help
50966 + If you say Y here, additional restrictions will be placed on
50967 + /proc that keep normal users from viewing device information and
50968 + slabinfo information that could be useful for exploits.
50969 +
50970 +config GRKERNSEC_LINK
50971 + bool "Linking restrictions"
50972 + default y if GRKERNSEC_CONFIG_AUTO
50973 + help
50974 + If you say Y here, /tmp race exploits will be prevented, since users
50975 + will no longer be able to follow symlinks owned by other users in
50976 + world-writable +t directories (e.g. /tmp), unless the owner of the
50977 + symlink is the owner of the directory. users will also not be
50978 + able to hardlink to files they do not own. If the sysctl option is
50979 + enabled, a sysctl option with name "linking_restrictions" is created.
50980 +
50981 +config GRKERNSEC_SYMLINKOWN
50982 + bool "Kernel-enforced SymlinksIfOwnerMatch"
50983 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
50984 + help
50985 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
50986 + that prevents it from being used as a security feature. As Apache
50987 + verifies the symlink by performing a stat() against the target of
50988 + the symlink before it is followed, an attacker can setup a symlink
50989 + to point to a same-owned file, then replace the symlink with one
50990 + that targets another user's file just after Apache "validates" the
50991 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
50992 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
50993 + will be in place for the group you specify. If the sysctl option
50994 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
50995 + created.
50996 +
50997 +config GRKERNSEC_SYMLINKOWN_GID
50998 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
50999 + depends on GRKERNSEC_SYMLINKOWN
51000 + default 1006
51001 + help
51002 + Setting this GID determines what group kernel-enforced
51003 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
51004 + is enabled, a sysctl option with name "symlinkown_gid" is created.
51005 +
51006 +config GRKERNSEC_FIFO
51007 + bool "FIFO restrictions"
51008 + default y if GRKERNSEC_CONFIG_AUTO
51009 + help
51010 + If you say Y here, users will not be able to write to FIFOs they don't
51011 + own in world-writable +t directories (e.g. /tmp), unless the owner of
51012 + the FIFO is the same owner of the directory it's held in. If the sysctl
51013 + option is enabled, a sysctl option with name "fifo_restrictions" is
51014 + created.
51015 +
51016 +config GRKERNSEC_SYSFS_RESTRICT
51017 + bool "Sysfs/debugfs restriction"
51018 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
51019 + depends on SYSFS
51020 + help
51021 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
51022 + any filesystem normally mounted under it (e.g. debugfs) will be
51023 + mostly accessible only by root. These filesystems generally provide access
51024 + to hardware and debug information that isn't appropriate for unprivileged
51025 + users of the system. Sysfs and debugfs have also become a large source
51026 + of new vulnerabilities, ranging from infoleaks to local compromise.
51027 + There has been very little oversight with an eye toward security involved
51028 + in adding new exporters of information to these filesystems, so their
51029 + use is discouraged.
51030 + For reasons of compatibility, a few directories have been whitelisted
51031 + for access by non-root users:
51032 + /sys/fs/selinux
51033 + /sys/fs/fuse
51034 + /sys/devices/system/cpu
51035 +
51036 +config GRKERNSEC_ROFS
51037 + bool "Runtime read-only mount protection"
51038 + help
51039 + If you say Y here, a sysctl option with name "romount_protect" will
51040 + be created. By setting this option to 1 at runtime, filesystems
51041 + will be protected in the following ways:
51042 + * No new writable mounts will be allowed
51043 + * Existing read-only mounts won't be able to be remounted read/write
51044 + * Write operations will be denied on all block devices
51045 + This option acts independently of grsec_lock: once it is set to 1,
51046 + it cannot be turned off. Therefore, please be mindful of the resulting
51047 + behavior if this option is enabled in an init script on a read-only
51048 + filesystem. This feature is mainly intended for secure embedded systems.
51049 +
51050 +config GRKERNSEC_CHROOT
51051 + bool "Chroot jail restrictions"
51052 + default y if GRKERNSEC_CONFIG_AUTO
51053 + help
51054 + If you say Y here, you will be able to choose several options that will
51055 + make breaking out of a chrooted jail much more difficult. If you
51056 + encounter no software incompatibilities with the following options, it
51057 + is recommended that you enable each one.
51058 +
51059 +config GRKERNSEC_CHROOT_MOUNT
51060 + bool "Deny mounts"
51061 + default y if GRKERNSEC_CONFIG_AUTO
51062 + depends on GRKERNSEC_CHROOT
51063 + help
51064 + If you say Y here, processes inside a chroot will not be able to
51065 + mount or remount filesystems. If the sysctl option is enabled, a
51066 + sysctl option with name "chroot_deny_mount" is created.
51067 +
51068 +config GRKERNSEC_CHROOT_DOUBLE
51069 + bool "Deny double-chroots"
51070 + default y if GRKERNSEC_CONFIG_AUTO
51071 + depends on GRKERNSEC_CHROOT
51072 + help
51073 + If you say Y here, processes inside a chroot will not be able to chroot
51074 + again outside the chroot. This is a widely used method of breaking
51075 + out of a chroot jail and should not be allowed. If the sysctl
51076 + option is enabled, a sysctl option with name
51077 + "chroot_deny_chroot" is created.
51078 +
51079 +config GRKERNSEC_CHROOT_PIVOT
51080 + bool "Deny pivot_root in chroot"
51081 + default y if GRKERNSEC_CONFIG_AUTO
51082 + depends on GRKERNSEC_CHROOT
51083 + help
51084 + If you say Y here, processes inside a chroot will not be able to use
51085 + a function called pivot_root() that was introduced in Linux 2.3.41. It
51086 + works similar to chroot in that it changes the root filesystem. This
51087 + function could be misused in a chrooted process to attempt to break out
51088 + of the chroot, and therefore should not be allowed. If the sysctl
51089 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
51090 + created.
51091 +
51092 +config GRKERNSEC_CHROOT_CHDIR
51093 + bool "Enforce chdir(\"/\") on all chroots"
51094 + default y if GRKERNSEC_CONFIG_AUTO
51095 + depends on GRKERNSEC_CHROOT
51096 + help
51097 + If you say Y here, the current working directory of all newly-chrooted
51098 + applications will be set to the the root directory of the chroot.
51099 + The man page on chroot(2) states:
51100 + Note that this call does not change the current working
51101 + directory, so that `.' can be outside the tree rooted at
51102 + `/'. In particular, the super-user can escape from a
51103 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
51104 +
51105 + It is recommended that you say Y here, since it's not known to break
51106 + any software. If the sysctl option is enabled, a sysctl option with
51107 + name "chroot_enforce_chdir" is created.
51108 +
51109 +config GRKERNSEC_CHROOT_CHMOD
51110 + bool "Deny (f)chmod +s"
51111 + default y if GRKERNSEC_CONFIG_AUTO
51112 + depends on GRKERNSEC_CHROOT
51113 + help
51114 + If you say Y here, processes inside a chroot will not be able to chmod
51115 + or fchmod files to make them have suid or sgid bits. This protects
51116 + against another published method of breaking a chroot. If the sysctl
51117 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
51118 + created.
51119 +
51120 +config GRKERNSEC_CHROOT_FCHDIR
51121 + bool "Deny fchdir out of chroot"
51122 + default y if GRKERNSEC_CONFIG_AUTO
51123 + depends on GRKERNSEC_CHROOT
51124 + help
51125 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
51126 + to a file descriptor of the chrooting process that points to a directory
51127 + outside the filesystem will be stopped. If the sysctl option
51128 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
51129 +
51130 +config GRKERNSEC_CHROOT_MKNOD
51131 + bool "Deny mknod"
51132 + default y if GRKERNSEC_CONFIG_AUTO
51133 + depends on GRKERNSEC_CHROOT
51134 + help
51135 + If you say Y here, processes inside a chroot will not be allowed to
51136 + mknod. The problem with using mknod inside a chroot is that it
51137 + would allow an attacker to create a device entry that is the same
51138 + as one on the physical root of your system, which could range from
51139 + anything from the console device to a device for your harddrive (which
51140 + they could then use to wipe the drive or steal data). It is recommended
51141 + that you say Y here, unless you run into software incompatibilities.
51142 + If the sysctl option is enabled, a sysctl option with name
51143 + "chroot_deny_mknod" is created.
51144 +
51145 +config GRKERNSEC_CHROOT_SHMAT
51146 + bool "Deny shmat() out of chroot"
51147 + default y if GRKERNSEC_CONFIG_AUTO
51148 + depends on GRKERNSEC_CHROOT
51149 + help
51150 + If you say Y here, processes inside a chroot will not be able to attach
51151 + to shared memory segments that were created outside of the chroot jail.
51152 + It is recommended that you say Y here. If the sysctl option is enabled,
51153 + a sysctl option with name "chroot_deny_shmat" is created.
51154 +
51155 +config GRKERNSEC_CHROOT_UNIX
51156 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
51157 + default y if GRKERNSEC_CONFIG_AUTO
51158 + depends on GRKERNSEC_CHROOT
51159 + help
51160 + If you say Y here, processes inside a chroot will not be able to
51161 + connect to abstract (meaning not belonging to a filesystem) Unix
51162 + domain sockets that were bound outside of a chroot. It is recommended
51163 + that you say Y here. If the sysctl option is enabled, a sysctl option
51164 + with name "chroot_deny_unix" is created.
51165 +
51166 +config GRKERNSEC_CHROOT_FINDTASK
51167 + bool "Protect outside processes"
51168 + default y if GRKERNSEC_CONFIG_AUTO
51169 + depends on GRKERNSEC_CHROOT
51170 + help
51171 + If you say Y here, processes inside a chroot will not be able to
51172 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
51173 + getsid, or view any process outside of the chroot. If the sysctl
51174 + option is enabled, a sysctl option with name "chroot_findtask" is
51175 + created.
51176 +
51177 +config GRKERNSEC_CHROOT_NICE
51178 + bool "Restrict priority changes"
51179 + default y if GRKERNSEC_CONFIG_AUTO
51180 + depends on GRKERNSEC_CHROOT
51181 + help
51182 + If you say Y here, processes inside a chroot will not be able to raise
51183 + the priority of processes in the chroot, or alter the priority of
51184 + processes outside the chroot. This provides more security than simply
51185 + removing CAP_SYS_NICE from the process' capability set. If the
51186 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
51187 + is created.
51188 +
51189 +config GRKERNSEC_CHROOT_SYSCTL
51190 + bool "Deny sysctl writes"
51191 + default y if GRKERNSEC_CONFIG_AUTO
51192 + depends on GRKERNSEC_CHROOT
51193 + help
51194 + If you say Y here, an attacker in a chroot will not be able to
51195 + write to sysctl entries, either by sysctl(2) or through a /proc
51196 + interface. It is strongly recommended that you say Y here. If the
51197 + sysctl option is enabled, a sysctl option with name
51198 + "chroot_deny_sysctl" is created.
51199 +
51200 +config GRKERNSEC_CHROOT_CAPS
51201 + bool "Capability restrictions"
51202 + default y if GRKERNSEC_CONFIG_AUTO
51203 + depends on GRKERNSEC_CHROOT
51204 + help
51205 + If you say Y here, the capabilities on all processes within a
51206 + chroot jail will be lowered to stop module insertion, raw i/o,
51207 + system and net admin tasks, rebooting the system, modifying immutable
51208 + files, modifying IPC owned by another, and changing the system time.
51209 + This is left an option because it can break some apps. Disable this
51210 + if your chrooted apps are having problems performing those kinds of
51211 + tasks. If the sysctl option is enabled, a sysctl option with
51212 + name "chroot_caps" is created.
51213 +
51214 +endmenu
51215 +menu "Kernel Auditing"
51216 +depends on GRKERNSEC
51217 +
51218 +config GRKERNSEC_AUDIT_GROUP
51219 + bool "Single group for auditing"
51220 + help
51221 + If you say Y here, the exec, chdir, and (un)mount logging features
51222 + will only operate on a group you specify. This option is recommended
51223 + if you only want to watch certain users instead of having a large
51224 + amount of logs from the entire system. If the sysctl option is enabled,
51225 + a sysctl option with name "audit_group" is created.
51226 +
51227 +config GRKERNSEC_AUDIT_GID
51228 + int "GID for auditing"
51229 + depends on GRKERNSEC_AUDIT_GROUP
51230 + default 1007
51231 +
51232 +config GRKERNSEC_EXECLOG
51233 + bool "Exec logging"
51234 + help
51235 + If you say Y here, all execve() calls will be logged (since the
51236 + other exec*() calls are frontends to execve(), all execution
51237 + will be logged). Useful for shell-servers that like to keep track
51238 + of their users. If the sysctl option is enabled, a sysctl option with
51239 + name "exec_logging" is created.
51240 + WARNING: This option when enabled will produce a LOT of logs, especially
51241 + on an active system.
51242 +
51243 +config GRKERNSEC_RESLOG
51244 + bool "Resource logging"
51245 + default y if GRKERNSEC_CONFIG_AUTO
51246 + help
51247 + If you say Y here, all attempts to overstep resource limits will
51248 + be logged with the resource name, the requested size, and the current
51249 + limit. It is highly recommended that you say Y here. If the sysctl
51250 + option is enabled, a sysctl option with name "resource_logging" is
51251 + created. If the RBAC system is enabled, the sysctl value is ignored.
51252 +
51253 +config GRKERNSEC_CHROOT_EXECLOG
51254 + bool "Log execs within chroot"
51255 + help
51256 + If you say Y here, all executions inside a chroot jail will be logged
51257 + to syslog. This can cause a large amount of logs if certain
51258 + applications (eg. djb's daemontools) are installed on the system, and
51259 + is therefore left as an option. If the sysctl option is enabled, a
51260 + sysctl option with name "chroot_execlog" is created.
51261 +
51262 +config GRKERNSEC_AUDIT_PTRACE
51263 + bool "Ptrace logging"
51264 + help
51265 + If you say Y here, all attempts to attach to a process via ptrace
51266 + will be logged. If the sysctl option is enabled, a sysctl option
51267 + with name "audit_ptrace" is created.
51268 +
51269 +config GRKERNSEC_AUDIT_CHDIR
51270 + bool "Chdir logging"
51271 + help
51272 + If you say Y here, all chdir() calls will be logged. If the sysctl
51273 + option is enabled, a sysctl option with name "audit_chdir" is created.
51274 +
51275 +config GRKERNSEC_AUDIT_MOUNT
51276 + bool "(Un)Mount logging"
51277 + help
51278 + If you say Y here, all mounts and unmounts will be logged. If the
51279 + sysctl option is enabled, a sysctl option with name "audit_mount" is
51280 + created.
51281 +
51282 +config GRKERNSEC_SIGNAL
51283 + bool "Signal logging"
51284 + default y if GRKERNSEC_CONFIG_AUTO
51285 + help
51286 + If you say Y here, certain important signals will be logged, such as
51287 + SIGSEGV, which will as a result inform you of when a error in a program
51288 + occurred, which in some cases could mean a possible exploit attempt.
51289 + If the sysctl option is enabled, a sysctl option with name
51290 + "signal_logging" is created.
51291 +
51292 +config GRKERNSEC_FORKFAIL
51293 + bool "Fork failure logging"
51294 + help
51295 + If you say Y here, all failed fork() attempts will be logged.
51296 + This could suggest a fork bomb, or someone attempting to overstep
51297 + their process limit. If the sysctl option is enabled, a sysctl option
51298 + with name "forkfail_logging" is created.
51299 +
51300 +config GRKERNSEC_TIME
51301 + bool "Time change logging"
51302 + default y if GRKERNSEC_CONFIG_AUTO
51303 + help
51304 + If you say Y here, any changes of the system clock will be logged.
51305 + If the sysctl option is enabled, a sysctl option with name
51306 + "timechange_logging" is created.
51307 +
51308 +config GRKERNSEC_PROC_IPADDR
51309 + bool "/proc/<pid>/ipaddr support"
51310 + default y if GRKERNSEC_CONFIG_AUTO
51311 + help
51312 + If you say Y here, a new entry will be added to each /proc/<pid>
51313 + directory that contains the IP address of the person using the task.
51314 + The IP is carried across local TCP and AF_UNIX stream sockets.
51315 + This information can be useful for IDS/IPSes to perform remote response
51316 + to a local attack. The entry is readable by only the owner of the
51317 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
51318 + the RBAC system), and thus does not create privacy concerns.
51319 +
51320 +config GRKERNSEC_RWXMAP_LOG
51321 + bool 'Denied RWX mmap/mprotect logging'
51322 + default y if GRKERNSEC_CONFIG_AUTO
51323 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
51324 + help
51325 + If you say Y here, calls to mmap() and mprotect() with explicit
51326 + usage of PROT_WRITE and PROT_EXEC together will be logged when
51327 + denied by the PAX_MPROTECT feature. If the sysctl option is
51328 + enabled, a sysctl option with name "rwxmap_logging" is created.
51329 +
51330 +config GRKERNSEC_AUDIT_TEXTREL
51331 + bool 'ELF text relocations logging (READ HELP)'
51332 + depends on PAX_MPROTECT
51333 + help
51334 + If you say Y here, text relocations will be logged with the filename
51335 + of the offending library or binary. The purpose of the feature is
51336 + to help Linux distribution developers get rid of libraries and
51337 + binaries that need text relocations which hinder the future progress
51338 + of PaX. Only Linux distribution developers should say Y here, and
51339 + never on a production machine, as this option creates an information
51340 + leak that could aid an attacker in defeating the randomization of
51341 + a single memory region. If the sysctl option is enabled, a sysctl
51342 + option with name "audit_textrel" is created.
51343 +
51344 +endmenu
51345 +
51346 +menu "Executable Protections"
51347 +depends on GRKERNSEC
51348 +
51349 +config GRKERNSEC_DMESG
51350 + bool "Dmesg(8) restriction"
51351 + default y if GRKERNSEC_CONFIG_AUTO
51352 + help
51353 + If you say Y here, non-root users will not be able to use dmesg(8)
51354 + to view up to the last 4kb of messages in the kernel's log buffer.
51355 + The kernel's log buffer often contains kernel addresses and other
51356 + identifying information useful to an attacker in fingerprinting a
51357 + system for a targeted exploit.
51358 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
51359 + created.
51360 +
51361 +config GRKERNSEC_HARDEN_PTRACE
51362 + bool "Deter ptrace-based process snooping"
51363 + default y if GRKERNSEC_CONFIG_AUTO
51364 + help
51365 + If you say Y here, TTY sniffers and other malicious monitoring
51366 + programs implemented through ptrace will be defeated. If you
51367 + have been using the RBAC system, this option has already been
51368 + enabled for several years for all users, with the ability to make
51369 + fine-grained exceptions.
51370 +
51371 + This option only affects the ability of non-root users to ptrace
51372 + processes that are not a descendent of the ptracing process.
51373 + This means that strace ./binary and gdb ./binary will still work,
51374 + but attaching to arbitrary processes will not. If the sysctl
51375 + option is enabled, a sysctl option with name "harden_ptrace" is
51376 + created.
51377 +
51378 +config GRKERNSEC_PTRACE_READEXEC
51379 + bool "Require read access to ptrace sensitive binaries"
51380 + default y if GRKERNSEC_CONFIG_AUTO
51381 + help
51382 + If you say Y here, unprivileged users will not be able to ptrace unreadable
51383 + binaries. This option is useful in environments that
51384 + remove the read bits (e.g. file mode 4711) from suid binaries to
51385 + prevent infoleaking of their contents. This option adds
51386 + consistency to the use of that file mode, as the binary could normally
51387 + be read out when run without privileges while ptracing.
51388 +
51389 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
51390 + is created.
51391 +
51392 +config GRKERNSEC_SETXID
51393 + bool "Enforce consistent multithreaded privileges"
51394 + default y if GRKERNSEC_CONFIG_AUTO
51395 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
51396 + help
51397 + If you say Y here, a change from a root uid to a non-root uid
51398 + in a multithreaded application will cause the resulting uids,
51399 + gids, supplementary groups, and capabilities in that thread
51400 + to be propagated to the other threads of the process. In most
51401 + cases this is unnecessary, as glibc will emulate this behavior
51402 + on behalf of the application. Other libcs do not act in the
51403 + same way, allowing the other threads of the process to continue
51404 + running with root privileges. If the sysctl option is enabled,
51405 + a sysctl option with name "consistent_setxid" is created.
51406 +
51407 +config GRKERNSEC_TPE
51408 + bool "Trusted Path Execution (TPE)"
51409 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
51410 + help
51411 + If you say Y here, you will be able to choose a gid to add to the
51412 + supplementary groups of users you want to mark as "untrusted."
51413 + These users will not be able to execute any files that are not in
51414 + root-owned directories writable only by root. If the sysctl option
51415 + is enabled, a sysctl option with name "tpe" is created.
51416 +
51417 +config GRKERNSEC_TPE_ALL
51418 + bool "Partially restrict all non-root users"
51419 + depends on GRKERNSEC_TPE
51420 + help
51421 + If you say Y here, all non-root users will be covered under
51422 + a weaker TPE restriction. This is separate from, and in addition to,
51423 + the main TPE options that you have selected elsewhere. Thus, if a
51424 + "trusted" GID is chosen, this restriction applies to even that GID.
51425 + Under this restriction, all non-root users will only be allowed to
51426 + execute files in directories they own that are not group or
51427 + world-writable, or in directories owned by root and writable only by
51428 + root. If the sysctl option is enabled, a sysctl option with name
51429 + "tpe_restrict_all" is created.
51430 +
51431 +config GRKERNSEC_TPE_INVERT
51432 + bool "Invert GID option"
51433 + depends on GRKERNSEC_TPE
51434 + help
51435 + If you say Y here, the group you specify in the TPE configuration will
51436 + decide what group TPE restrictions will be *disabled* for. This
51437 + option is useful if you want TPE restrictions to be applied to most
51438 + users on the system. If the sysctl option is enabled, a sysctl option
51439 + with name "tpe_invert" is created. Unlike other sysctl options, this
51440 + entry will default to on for backward-compatibility.
51441 +
51442 +config GRKERNSEC_TPE_GID
51443 + int
51444 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
51445 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
51446 +
51447 +config GRKERNSEC_TPE_UNTRUSTED_GID
51448 + int "GID for TPE-untrusted users"
51449 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
51450 + default 1005
51451 + help
51452 + Setting this GID determines what group TPE restrictions will be
51453 + *enabled* for. If the sysctl option is enabled, a sysctl option
51454 + with name "tpe_gid" is created.
51455 +
51456 +config GRKERNSEC_TPE_TRUSTED_GID
51457 + int "GID for TPE-trusted users"
51458 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
51459 + default 1005
51460 + help
51461 + Setting this GID determines what group TPE restrictions will be
51462 + *disabled* for. If the sysctl option is enabled, a sysctl option
51463 + with name "tpe_gid" is created.
51464 +
51465 +endmenu
51466 +menu "Network Protections"
51467 +depends on GRKERNSEC
51468 +
51469 +config GRKERNSEC_RANDNET
51470 + bool "Larger entropy pools"
51471 + default y if GRKERNSEC_CONFIG_AUTO
51472 + help
51473 + If you say Y here, the entropy pools used for many features of Linux
51474 + and grsecurity will be doubled in size. Since several grsecurity
51475 + features use additional randomness, it is recommended that you say Y
51476 + here. Saying Y here has a similar effect as modifying
51477 + /proc/sys/kernel/random/poolsize.
51478 +
51479 +config GRKERNSEC_BLACKHOLE
51480 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
51481 + default y if GRKERNSEC_CONFIG_AUTO
51482 + depends on NET
51483 + help
51484 + If you say Y here, neither TCP resets nor ICMP
51485 + destination-unreachable packets will be sent in response to packets
51486 + sent to ports for which no associated listening process exists.
51487 + This feature supports both IPV4 and IPV6 and exempts the
51488 + loopback interface from blackholing. Enabling this feature
51489 + makes a host more resilient to DoS attacks and reduces network
51490 + visibility against scanners.
51491 +
51492 + The blackhole feature as-implemented is equivalent to the FreeBSD
51493 + blackhole feature, as it prevents RST responses to all packets, not
51494 + just SYNs. Under most application behavior this causes no
51495 + problems, but applications (like haproxy) may not close certain
51496 + connections in a way that cleanly terminates them on the remote
51497 + end, leaving the remote host in LAST_ACK state. Because of this
51498 + side-effect and to prevent intentional LAST_ACK DoSes, this
51499 + feature also adds automatic mitigation against such attacks.
51500 + The mitigation drastically reduces the amount of time a socket
51501 + can spend in LAST_ACK state. If you're using haproxy and not
51502 + all servers it connects to have this option enabled, consider
51503 + disabling this feature on the haproxy host.
51504 +
51505 + If the sysctl option is enabled, two sysctl options with names
51506 + "ip_blackhole" and "lastack_retries" will be created.
51507 + While "ip_blackhole" takes the standard zero/non-zero on/off
51508 + toggle, "lastack_retries" uses the same kinds of values as
51509 + "tcp_retries1" and "tcp_retries2". The default value of 4
51510 + prevents a socket from lasting more than 45 seconds in LAST_ACK
51511 + state.
51512 +
51513 +config GRKERNSEC_SOCKET
51514 + bool "Socket restrictions"
51515 + depends on NET
51516 + help
51517 + If you say Y here, you will be able to choose from several options.
51518 + If you assign a GID on your system and add it to the supplementary
51519 + groups of users you want to restrict socket access to, this patch
51520 + will perform up to three things, based on the option(s) you choose.
51521 +
51522 +config GRKERNSEC_SOCKET_ALL
51523 + bool "Deny any sockets to group"
51524 + depends on GRKERNSEC_SOCKET
51525 + help
51526 + If you say Y here, you will be able to choose a GID of whose users will
51527 + be unable to connect to other hosts from your machine or run server
51528 + applications from your machine. If the sysctl option is enabled, a
51529 + sysctl option with name "socket_all" is created.
51530 +
51531 +config GRKERNSEC_SOCKET_ALL_GID
51532 + int "GID to deny all sockets for"
51533 + depends on GRKERNSEC_SOCKET_ALL
51534 + default 1004
51535 + help
51536 + Here you can choose the GID to disable socket access for. Remember to
51537 + add the users you want socket access disabled for to the GID
51538 + specified here. If the sysctl option is enabled, a sysctl option
51539 + with name "socket_all_gid" is created.
51540 +
51541 +config GRKERNSEC_SOCKET_CLIENT
51542 + bool "Deny client sockets to group"
51543 + depends on GRKERNSEC_SOCKET
51544 + help
51545 + If you say Y here, you will be able to choose a GID of whose users will
51546 + be unable to connect to other hosts from your machine, but will be
51547 + able to run servers. If this option is enabled, all users in the group
51548 + you specify will have to use passive mode when initiating ftp transfers
51549 + from the shell on your machine. If the sysctl option is enabled, a
51550 + sysctl option with name "socket_client" is created.
51551 +
51552 +config GRKERNSEC_SOCKET_CLIENT_GID
51553 + int "GID to deny client sockets for"
51554 + depends on GRKERNSEC_SOCKET_CLIENT
51555 + default 1003
51556 + help
51557 + Here you can choose the GID to disable client socket access for.
51558 + Remember to add the users you want client socket access disabled for to
51559 + the GID specified here. If the sysctl option is enabled, a sysctl
51560 + option with name "socket_client_gid" is created.
51561 +
51562 +config GRKERNSEC_SOCKET_SERVER
51563 + bool "Deny server sockets to group"
51564 + depends on GRKERNSEC_SOCKET
51565 + help
51566 + If you say Y here, you will be able to choose a GID of whose users will
51567 + be unable to run server applications from your machine. If the sysctl
51568 + option is enabled, a sysctl option with name "socket_server" is created.
51569 +
51570 +config GRKERNSEC_SOCKET_SERVER_GID
51571 + int "GID to deny server sockets for"
51572 + depends on GRKERNSEC_SOCKET_SERVER
51573 + default 1002
51574 + help
51575 + Here you can choose the GID to disable server socket access for.
51576 + Remember to add the users you want server socket access disabled for to
51577 + the GID specified here. If the sysctl option is enabled, a sysctl
51578 + option with name "socket_server_gid" is created.
51579 +
51580 +endmenu
51581 +menu "Sysctl Support"
51582 +depends on GRKERNSEC && SYSCTL
51583 +
51584 +config GRKERNSEC_SYSCTL
51585 + bool "Sysctl support"
51586 + default y if GRKERNSEC_CONFIG_AUTO
51587 + help
51588 + If you say Y here, you will be able to change the options that
51589 + grsecurity runs with at bootup, without having to recompile your
51590 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
51591 + to enable (1) or disable (0) various features. All the sysctl entries
51592 + are mutable until the "grsec_lock" entry is set to a non-zero value.
51593 + All features enabled in the kernel configuration are disabled at boot
51594 + if you do not say Y to the "Turn on features by default" option.
51595 + All options should be set at startup, and the grsec_lock entry should
51596 + be set to a non-zero value after all the options are set.
51597 + *THIS IS EXTREMELY IMPORTANT*
51598 +
51599 +config GRKERNSEC_SYSCTL_DISTRO
51600 + bool "Extra sysctl support for distro makers (READ HELP)"
51601 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
51602 + help
51603 + If you say Y here, additional sysctl options will be created
51604 + for features that affect processes running as root. Therefore,
51605 + it is critical when using this option that the grsec_lock entry be
51606 + enabled after boot. Only distros with prebuilt kernel packages
51607 + with this option enabled that can ensure grsec_lock is enabled
51608 + after boot should use this option.
51609 + *Failure to set grsec_lock after boot makes all grsec features
51610 + this option covers useless*
51611 +
51612 + Currently this option creates the following sysctl entries:
51613 + "Disable Privileged I/O": "disable_priv_io"
51614 +
51615 +config GRKERNSEC_SYSCTL_ON
51616 + bool "Turn on features by default"
51617 + default y if GRKERNSEC_CONFIG_AUTO
51618 + depends on GRKERNSEC_SYSCTL
51619 + help
51620 + If you say Y here, instead of having all features enabled in the
51621 + kernel configuration disabled at boot time, the features will be
51622 + enabled at boot time. It is recommended you say Y here unless
51623 + there is some reason you would want all sysctl-tunable features to
51624 + be disabled by default. As mentioned elsewhere, it is important
51625 + to enable the grsec_lock entry once you have finished modifying
51626 + the sysctl entries.
51627 +
51628 +endmenu
51629 +menu "Logging Options"
51630 +depends on GRKERNSEC
51631 +
51632 +config GRKERNSEC_FLOODTIME
51633 + int "Seconds in between log messages (minimum)"
51634 + default 10
51635 + help
51636 + This option allows you to enforce the number of seconds between
51637 + grsecurity log messages. The default should be suitable for most
51638 + people, however, if you choose to change it, choose a value small enough
51639 + to allow informative logs to be produced, but large enough to
51640 + prevent flooding.
51641 +
51642 +config GRKERNSEC_FLOODBURST
51643 + int "Number of messages in a burst (maximum)"
51644 + default 6
51645 + help
51646 + This option allows you to choose the maximum number of messages allowed
51647 + within the flood time interval you chose in a separate option. The
51648 + default should be suitable for most people, however if you find that
51649 + many of your logs are being interpreted as flooding, you may want to
51650 + raise this value.
51651 +
51652 +endmenu
51653 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
51654 new file mode 100644
51655 index 0000000..1b9afa9
51656 --- /dev/null
51657 +++ b/grsecurity/Makefile
51658 @@ -0,0 +1,38 @@
51659 +# grsecurity's ACL system was originally written in 2001 by Michael Dalton
51660 +# during 2001-2009 it has been completely redesigned by Brad Spengler
51661 +# into an RBAC system
51662 +#
51663 +# All code in this directory and various hooks inserted throughout the kernel
51664 +# are copyright Brad Spengler - Open Source Security, Inc., and released
51665 +# under the GPL v2 or higher
51666 +
51667 +KBUILD_CFLAGS += -Werror
51668 +
51669 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
51670 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
51671 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o
51672 +
51673 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
51674 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
51675 + gracl_learn.o grsec_log.o
51676 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
51677 +
51678 +ifdef CONFIG_NET
51679 +obj-y += grsec_sock.o
51680 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
51681 +endif
51682 +
51683 +ifndef CONFIG_GRKERNSEC
51684 +obj-y += grsec_disabled.o
51685 +endif
51686 +
51687 +ifdef CONFIG_GRKERNSEC_HIDESYM
51688 +extra-y := grsec_hidesym.o
51689 +$(obj)/grsec_hidesym.o:
51690 + @-chmod -f 500 /boot
51691 + @-chmod -f 500 /lib/modules
51692 + @-chmod -f 500 /lib64/modules
51693 + @-chmod -f 500 /lib32/modules
51694 + @-chmod -f 700 .
51695 + @echo ' grsec: protected kernel image paths'
51696 +endif
51697 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
51698 new file mode 100644
51699 index 0000000..07cd799
51700 --- /dev/null
51701 +++ b/grsecurity/gracl.c
51702 @@ -0,0 +1,4017 @@
51703 +#include <linux/kernel.h>
51704 +#include <linux/module.h>
51705 +#include <linux/sched.h>
51706 +#include <linux/mm.h>
51707 +#include <linux/file.h>
51708 +#include <linux/fs.h>
51709 +#include <linux/namei.h>
51710 +#include <linux/mount.h>
51711 +#include <linux/tty.h>
51712 +#include <linux/proc_fs.h>
51713 +#include <linux/lglock.h>
51714 +#include <linux/slab.h>
51715 +#include <linux/vmalloc.h>
51716 +#include <linux/types.h>
51717 +#include <linux/sysctl.h>
51718 +#include <linux/netdevice.h>
51719 +#include <linux/ptrace.h>
51720 +#include <linux/gracl.h>
51721 +#include <linux/gralloc.h>
51722 +#include <linux/security.h>
51723 +#include <linux/grinternal.h>
51724 +#include <linux/pid_namespace.h>
51725 +#include <linux/stop_machine.h>
51726 +#include <linux/fdtable.h>
51727 +#include <linux/percpu.h>
51728 +#include <linux/lglock.h>
51729 +#include "../fs/mount.h"
51730 +
51731 +#include <asm/uaccess.h>
51732 +#include <asm/errno.h>
51733 +#include <asm/mman.h>
51734 +
51735 +extern struct lglock vfsmount_lock;
51736 +
51737 +static struct acl_role_db acl_role_set;
51738 +static struct name_db name_set;
51739 +static struct inodev_db inodev_set;
51740 +
51741 +/* for keeping track of userspace pointers used for subjects, so we
51742 + can share references in the kernel as well
51743 +*/
51744 +
51745 +static struct path real_root;
51746 +
51747 +static struct acl_subj_map_db subj_map_set;
51748 +
51749 +static struct acl_role_label *default_role;
51750 +
51751 +static struct acl_role_label *role_list;
51752 +
51753 +static u16 acl_sp_role_value;
51754 +
51755 +extern char *gr_shared_page[4];
51756 +static DEFINE_MUTEX(gr_dev_mutex);
51757 +DEFINE_RWLOCK(gr_inode_lock);
51758 +
51759 +struct gr_arg *gr_usermode;
51760 +
51761 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
51762 +
51763 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
51764 +extern void gr_clear_learn_entries(void);
51765 +
51766 +#ifdef CONFIG_GRKERNSEC_RESLOG
51767 +extern void gr_log_resource(const struct task_struct *task,
51768 + const int res, const unsigned long wanted, const int gt);
51769 +#endif
51770 +
51771 +unsigned char *gr_system_salt;
51772 +unsigned char *gr_system_sum;
51773 +
51774 +static struct sprole_pw **acl_special_roles = NULL;
51775 +static __u16 num_sprole_pws = 0;
51776 +
51777 +static struct acl_role_label *kernel_role = NULL;
51778 +
51779 +static unsigned int gr_auth_attempts = 0;
51780 +static unsigned long gr_auth_expires = 0UL;
51781 +
51782 +#ifdef CONFIG_NET
51783 +extern struct vfsmount *sock_mnt;
51784 +#endif
51785 +
51786 +extern struct vfsmount *pipe_mnt;
51787 +extern struct vfsmount *shm_mnt;
51788 +#ifdef CONFIG_HUGETLBFS
51789 +extern struct vfsmount *hugetlbfs_vfsmount;
51790 +#endif
51791 +
51792 +static struct acl_object_label *fakefs_obj_rw;
51793 +static struct acl_object_label *fakefs_obj_rwx;
51794 +
51795 +extern int gr_init_uidset(void);
51796 +extern void gr_free_uidset(void);
51797 +extern void gr_remove_uid(uid_t uid);
51798 +extern int gr_find_uid(uid_t uid);
51799 +
51800 +__inline__ int
51801 +gr_acl_is_enabled(void)
51802 +{
51803 + return (gr_status & GR_READY);
51804 +}
51805 +
51806 +#ifdef CONFIG_BTRFS_FS
51807 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
51808 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
51809 +#endif
51810 +
51811 +static inline dev_t __get_dev(const struct dentry *dentry)
51812 +{
51813 +#ifdef CONFIG_BTRFS_FS
51814 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
51815 + return get_btrfs_dev_from_inode(dentry->d_inode);
51816 + else
51817 +#endif
51818 + return dentry->d_inode->i_sb->s_dev;
51819 +}
51820 +
51821 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
51822 +{
51823 + return __get_dev(dentry);
51824 +}
51825 +
51826 +static char gr_task_roletype_to_char(struct task_struct *task)
51827 +{
51828 + switch (task->role->roletype &
51829 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
51830 + GR_ROLE_SPECIAL)) {
51831 + case GR_ROLE_DEFAULT:
51832 + return 'D';
51833 + case GR_ROLE_USER:
51834 + return 'U';
51835 + case GR_ROLE_GROUP:
51836 + return 'G';
51837 + case GR_ROLE_SPECIAL:
51838 + return 'S';
51839 + }
51840 +
51841 + return 'X';
51842 +}
51843 +
51844 +char gr_roletype_to_char(void)
51845 +{
51846 + return gr_task_roletype_to_char(current);
51847 +}
51848 +
51849 +__inline__ int
51850 +gr_acl_tpe_check(void)
51851 +{
51852 + if (unlikely(!(gr_status & GR_READY)))
51853 + return 0;
51854 + if (current->role->roletype & GR_ROLE_TPE)
51855 + return 1;
51856 + else
51857 + return 0;
51858 +}
51859 +
51860 +int
51861 +gr_handle_rawio(const struct inode *inode)
51862 +{
51863 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
51864 + if (inode && S_ISBLK(inode->i_mode) &&
51865 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
51866 + !capable(CAP_SYS_RAWIO))
51867 + return 1;
51868 +#endif
51869 + return 0;
51870 +}
51871 +
51872 +static int
51873 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
51874 +{
51875 + if (likely(lena != lenb))
51876 + return 0;
51877 +
51878 + return !memcmp(a, b, lena);
51879 +}
51880 +
51881 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
51882 +{
51883 + *buflen -= namelen;
51884 + if (*buflen < 0)
51885 + return -ENAMETOOLONG;
51886 + *buffer -= namelen;
51887 + memcpy(*buffer, str, namelen);
51888 + return 0;
51889 +}
51890 +
51891 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
51892 +{
51893 + return prepend(buffer, buflen, name->name, name->len);
51894 +}
51895 +
51896 +static int prepend_path(const struct path *path, struct path *root,
51897 + char **buffer, int *buflen)
51898 +{
51899 + struct dentry *dentry = path->dentry;
51900 + struct vfsmount *vfsmnt = path->mnt;
51901 + struct mount *mnt = real_mount(vfsmnt);
51902 + bool slash = false;
51903 + int error = 0;
51904 +
51905 + while (dentry != root->dentry || vfsmnt != root->mnt) {
51906 + struct dentry * parent;
51907 +
51908 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
51909 + /* Global root? */
51910 + if (!mnt_has_parent(mnt)) {
51911 + goto out;
51912 + }
51913 + dentry = mnt->mnt_mountpoint;
51914 + mnt = mnt->mnt_parent;
51915 + vfsmnt = &mnt->mnt;
51916 + continue;
51917 + }
51918 + parent = dentry->d_parent;
51919 + prefetch(parent);
51920 + spin_lock(&dentry->d_lock);
51921 + error = prepend_name(buffer, buflen, &dentry->d_name);
51922 + spin_unlock(&dentry->d_lock);
51923 + if (!error)
51924 + error = prepend(buffer, buflen, "/", 1);
51925 + if (error)
51926 + break;
51927 +
51928 + slash = true;
51929 + dentry = parent;
51930 + }
51931 +
51932 +out:
51933 + if (!error && !slash)
51934 + error = prepend(buffer, buflen, "/", 1);
51935 +
51936 + return error;
51937 +}
51938 +
51939 +/* this must be called with vfsmount_lock and rename_lock held */
51940 +
51941 +static char *__our_d_path(const struct path *path, struct path *root,
51942 + char *buf, int buflen)
51943 +{
51944 + char *res = buf + buflen;
51945 + int error;
51946 +
51947 + prepend(&res, &buflen, "\0", 1);
51948 + error = prepend_path(path, root, &res, &buflen);
51949 + if (error)
51950 + return ERR_PTR(error);
51951 +
51952 + return res;
51953 +}
51954 +
51955 +static char *
51956 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
51957 +{
51958 + char *retval;
51959 +
51960 + retval = __our_d_path(path, root, buf, buflen);
51961 + if (unlikely(IS_ERR(retval)))
51962 + retval = strcpy(buf, "<path too long>");
51963 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
51964 + retval[1] = '\0';
51965 +
51966 + return retval;
51967 +}
51968 +
51969 +static char *
51970 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51971 + char *buf, int buflen)
51972 +{
51973 + struct path path;
51974 + char *res;
51975 +
51976 + path.dentry = (struct dentry *)dentry;
51977 + path.mnt = (struct vfsmount *)vfsmnt;
51978 +
51979 + /* we can use real_root.dentry, real_root.mnt, because this is only called
51980 + by the RBAC system */
51981 + res = gen_full_path(&path, &real_root, buf, buflen);
51982 +
51983 + return res;
51984 +}
51985 +
51986 +static char *
51987 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
51988 + char *buf, int buflen)
51989 +{
51990 + char *res;
51991 + struct path path;
51992 + struct path root;
51993 + struct task_struct *reaper = init_pid_ns.child_reaper;
51994 +
51995 + path.dentry = (struct dentry *)dentry;
51996 + path.mnt = (struct vfsmount *)vfsmnt;
51997 +
51998 + /* we can't use real_root.dentry, real_root.mnt, because they belong only to the RBAC system */
51999 + get_fs_root(reaper->fs, &root);
52000 +
52001 + write_seqlock(&rename_lock);
52002 + br_read_lock(&vfsmount_lock);
52003 + res = gen_full_path(&path, &root, buf, buflen);
52004 + br_read_unlock(&vfsmount_lock);
52005 + write_sequnlock(&rename_lock);
52006 +
52007 + path_put(&root);
52008 + return res;
52009 +}
52010 +
52011 +static char *
52012 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52013 +{
52014 + char *ret;
52015 + write_seqlock(&rename_lock);
52016 + br_read_lock(&vfsmount_lock);
52017 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52018 + PAGE_SIZE);
52019 + br_read_unlock(&vfsmount_lock);
52020 + write_sequnlock(&rename_lock);
52021 + return ret;
52022 +}
52023 +
52024 +static char *
52025 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
52026 +{
52027 + char *ret;
52028 + char *buf;
52029 + int buflen;
52030 +
52031 + write_seqlock(&rename_lock);
52032 + br_read_lock(&vfsmount_lock);
52033 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
52034 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
52035 + buflen = (int)(ret - buf);
52036 + if (buflen >= 5)
52037 + prepend(&ret, &buflen, "/proc", 5);
52038 + else
52039 + ret = strcpy(buf, "<path too long>");
52040 + br_read_unlock(&vfsmount_lock);
52041 + write_sequnlock(&rename_lock);
52042 + return ret;
52043 +}
52044 +
52045 +char *
52046 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
52047 +{
52048 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
52049 + PAGE_SIZE);
52050 +}
52051 +
52052 +char *
52053 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
52054 +{
52055 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
52056 + PAGE_SIZE);
52057 +}
52058 +
52059 +char *
52060 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
52061 +{
52062 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
52063 + PAGE_SIZE);
52064 +}
52065 +
52066 +char *
52067 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
52068 +{
52069 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
52070 + PAGE_SIZE);
52071 +}
52072 +
52073 +char *
52074 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
52075 +{
52076 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
52077 + PAGE_SIZE);
52078 +}
52079 +
52080 +__inline__ __u32
52081 +to_gr_audit(const __u32 reqmode)
52082 +{
52083 + /* masks off auditable permission flags, then shifts them to create
52084 + auditing flags, and adds the special case of append auditing if
52085 + we're requesting write */
52086 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
52087 +}
52088 +
52089 +struct acl_subject_label *
52090 +lookup_subject_map(const struct acl_subject_label *userp)
52091 +{
52092 + unsigned int index = shash(userp, subj_map_set.s_size);
52093 + struct subject_map *match;
52094 +
52095 + match = subj_map_set.s_hash[index];
52096 +
52097 + while (match && match->user != userp)
52098 + match = match->next;
52099 +
52100 + if (match != NULL)
52101 + return match->kernel;
52102 + else
52103 + return NULL;
52104 +}
52105 +
52106 +static void
52107 +insert_subj_map_entry(struct subject_map *subjmap)
52108 +{
52109 + unsigned int index = shash(subjmap->user, subj_map_set.s_size);
52110 + struct subject_map **curr;
52111 +
52112 + subjmap->prev = NULL;
52113 +
52114 + curr = &subj_map_set.s_hash[index];
52115 + if (*curr != NULL)
52116 + (*curr)->prev = subjmap;
52117 +
52118 + subjmap->next = *curr;
52119 + *curr = subjmap;
52120 +
52121 + return;
52122 +}
52123 +
52124 +static struct acl_role_label *
52125 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
52126 + const gid_t gid)
52127 +{
52128 + unsigned int index = rhash(uid, GR_ROLE_USER, acl_role_set.r_size);
52129 + struct acl_role_label *match;
52130 + struct role_allowed_ip *ipp;
52131 + unsigned int x;
52132 + u32 curr_ip = task->signal->curr_ip;
52133 +
52134 + task->signal->saved_ip = curr_ip;
52135 +
52136 + match = acl_role_set.r_hash[index];
52137 +
52138 + while (match) {
52139 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
52140 + for (x = 0; x < match->domain_child_num; x++) {
52141 + if (match->domain_children[x] == uid)
52142 + goto found;
52143 + }
52144 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
52145 + break;
52146 + match = match->next;
52147 + }
52148 +found:
52149 + if (match == NULL) {
52150 + try_group:
52151 + index = rhash(gid, GR_ROLE_GROUP, acl_role_set.r_size);
52152 + match = acl_role_set.r_hash[index];
52153 +
52154 + while (match) {
52155 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
52156 + for (x = 0; x < match->domain_child_num; x++) {
52157 + if (match->domain_children[x] == gid)
52158 + goto found2;
52159 + }
52160 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
52161 + break;
52162 + match = match->next;
52163 + }
52164 +found2:
52165 + if (match == NULL)
52166 + match = default_role;
52167 + if (match->allowed_ips == NULL)
52168 + return match;
52169 + else {
52170 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52171 + if (likely
52172 + ((ntohl(curr_ip) & ipp->netmask) ==
52173 + (ntohl(ipp->addr) & ipp->netmask)))
52174 + return match;
52175 + }
52176 + match = default_role;
52177 + }
52178 + } else if (match->allowed_ips == NULL) {
52179 + return match;
52180 + } else {
52181 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
52182 + if (likely
52183 + ((ntohl(curr_ip) & ipp->netmask) ==
52184 + (ntohl(ipp->addr) & ipp->netmask)))
52185 + return match;
52186 + }
52187 + goto try_group;
52188 + }
52189 +
52190 + return match;
52191 +}
52192 +
52193 +struct acl_subject_label *
52194 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
52195 + const struct acl_role_label *role)
52196 +{
52197 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52198 + struct acl_subject_label *match;
52199 +
52200 + match = role->subj_hash[index];
52201 +
52202 + while (match && (match->inode != ino || match->device != dev ||
52203 + (match->mode & GR_DELETED))) {
52204 + match = match->next;
52205 + }
52206 +
52207 + if (match && !(match->mode & GR_DELETED))
52208 + return match;
52209 + else
52210 + return NULL;
52211 +}
52212 +
52213 +struct acl_subject_label *
52214 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
52215 + const struct acl_role_label *role)
52216 +{
52217 + unsigned int index = fhash(ino, dev, role->subj_hash_size);
52218 + struct acl_subject_label *match;
52219 +
52220 + match = role->subj_hash[index];
52221 +
52222 + while (match && (match->inode != ino || match->device != dev ||
52223 + !(match->mode & GR_DELETED))) {
52224 + match = match->next;
52225 + }
52226 +
52227 + if (match && (match->mode & GR_DELETED))
52228 + return match;
52229 + else
52230 + return NULL;
52231 +}
52232 +
52233 +static struct acl_object_label *
52234 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
52235 + const struct acl_subject_label *subj)
52236 +{
52237 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52238 + struct acl_object_label *match;
52239 +
52240 + match = subj->obj_hash[index];
52241 +
52242 + while (match && (match->inode != ino || match->device != dev ||
52243 + (match->mode & GR_DELETED))) {
52244 + match = match->next;
52245 + }
52246 +
52247 + if (match && !(match->mode & GR_DELETED))
52248 + return match;
52249 + else
52250 + return NULL;
52251 +}
52252 +
52253 +static struct acl_object_label *
52254 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
52255 + const struct acl_subject_label *subj)
52256 +{
52257 + unsigned int index = fhash(ino, dev, subj->obj_hash_size);
52258 + struct acl_object_label *match;
52259 +
52260 + match = subj->obj_hash[index];
52261 +
52262 + while (match && (match->inode != ino || match->device != dev ||
52263 + !(match->mode & GR_DELETED))) {
52264 + match = match->next;
52265 + }
52266 +
52267 + if (match && (match->mode & GR_DELETED))
52268 + return match;
52269 +
52270 + match = subj->obj_hash[index];
52271 +
52272 + while (match && (match->inode != ino || match->device != dev ||
52273 + (match->mode & GR_DELETED))) {
52274 + match = match->next;
52275 + }
52276 +
52277 + if (match && !(match->mode & GR_DELETED))
52278 + return match;
52279 + else
52280 + return NULL;
52281 +}
52282 +
52283 +static struct name_entry *
52284 +lookup_name_entry(const char *name)
52285 +{
52286 + unsigned int len = strlen(name);
52287 + unsigned int key = full_name_hash(name, len);
52288 + unsigned int index = key % name_set.n_size;
52289 + struct name_entry *match;
52290 +
52291 + match = name_set.n_hash[index];
52292 +
52293 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
52294 + match = match->next;
52295 +
52296 + return match;
52297 +}
52298 +
52299 +static struct name_entry *
52300 +lookup_name_entry_create(const char *name)
52301 +{
52302 + unsigned int len = strlen(name);
52303 + unsigned int key = full_name_hash(name, len);
52304 + unsigned int index = key % name_set.n_size;
52305 + struct name_entry *match;
52306 +
52307 + match = name_set.n_hash[index];
52308 +
52309 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52310 + !match->deleted))
52311 + match = match->next;
52312 +
52313 + if (match && match->deleted)
52314 + return match;
52315 +
52316 + match = name_set.n_hash[index];
52317 +
52318 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
52319 + match->deleted))
52320 + match = match->next;
52321 +
52322 + if (match && !match->deleted)
52323 + return match;
52324 + else
52325 + return NULL;
52326 +}
52327 +
52328 +static struct inodev_entry *
52329 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
52330 +{
52331 + unsigned int index = fhash(ino, dev, inodev_set.i_size);
52332 + struct inodev_entry *match;
52333 +
52334 + match = inodev_set.i_hash[index];
52335 +
52336 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
52337 + match = match->next;
52338 +
52339 + return match;
52340 +}
52341 +
52342 +static void
52343 +insert_inodev_entry(struct inodev_entry *entry)
52344 +{
52345 + unsigned int index = fhash(entry->nentry->inode, entry->nentry->device,
52346 + inodev_set.i_size);
52347 + struct inodev_entry **curr;
52348 +
52349 + entry->prev = NULL;
52350 +
52351 + curr = &inodev_set.i_hash[index];
52352 + if (*curr != NULL)
52353 + (*curr)->prev = entry;
52354 +
52355 + entry->next = *curr;
52356 + *curr = entry;
52357 +
52358 + return;
52359 +}
52360 +
52361 +static void
52362 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
52363 +{
52364 + unsigned int index =
52365 + rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), acl_role_set.r_size);
52366 + struct acl_role_label **curr;
52367 + struct acl_role_label *tmp, *tmp2;
52368 +
52369 + curr = &acl_role_set.r_hash[index];
52370 +
52371 + /* simple case, slot is empty, just set it to our role */
52372 + if (*curr == NULL) {
52373 + *curr = role;
52374 + } else {
52375 + /* example:
52376 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
52377 + 2 -> 3
52378 + */
52379 + /* first check to see if we can already be reached via this slot */
52380 + tmp = *curr;
52381 + while (tmp && tmp != role)
52382 + tmp = tmp->next;
52383 + if (tmp == role) {
52384 + /* we don't need to add ourselves to this slot's chain */
52385 + return;
52386 + }
52387 + /* we need to add ourselves to this chain, two cases */
52388 + if (role->next == NULL) {
52389 + /* simple case, append the current chain to our role */
52390 + role->next = *curr;
52391 + *curr = role;
52392 + } else {
52393 + /* 1 -> 2 -> 3 -> 4
52394 + 2 -> 3 -> 4
52395 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
52396 + */
52397 + /* trickier case: walk our role's chain until we find
52398 + the role for the start of the current slot's chain */
52399 + tmp = role;
52400 + tmp2 = *curr;
52401 + while (tmp->next && tmp->next != tmp2)
52402 + tmp = tmp->next;
52403 + if (tmp->next == tmp2) {
52404 + /* from example above, we found 3, so just
52405 + replace this slot's chain with ours */
52406 + *curr = role;
52407 + } else {
52408 + /* we didn't find a subset of our role's chain
52409 + in the current slot's chain, so append their
52410 + chain to ours, and set us as the first role in
52411 + the slot's chain
52412 +
52413 + we could fold this case with the case above,
52414 + but making it explicit for clarity
52415 + */
52416 + tmp->next = tmp2;
52417 + *curr = role;
52418 + }
52419 + }
52420 + }
52421 +
52422 + return;
52423 +}
52424 +
52425 +static void
52426 +insert_acl_role_label(struct acl_role_label *role)
52427 +{
52428 + int i;
52429 +
52430 + if (role_list == NULL) {
52431 + role_list = role;
52432 + role->prev = NULL;
52433 + } else {
52434 + role->prev = role_list;
52435 + role_list = role;
52436 + }
52437 +
52438 + /* used for hash chains */
52439 + role->next = NULL;
52440 +
52441 + if (role->roletype & GR_ROLE_DOMAIN) {
52442 + for (i = 0; i < role->domain_child_num; i++)
52443 + __insert_acl_role_label(role, role->domain_children[i]);
52444 + } else
52445 + __insert_acl_role_label(role, role->uidgid);
52446 +}
52447 +
52448 +static int
52449 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
52450 +{
52451 + struct name_entry **curr, *nentry;
52452 + struct inodev_entry *ientry;
52453 + unsigned int len = strlen(name);
52454 + unsigned int key = full_name_hash(name, len);
52455 + unsigned int index = key % name_set.n_size;
52456 +
52457 + curr = &name_set.n_hash[index];
52458 +
52459 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
52460 + curr = &((*curr)->next);
52461 +
52462 + if (*curr != NULL)
52463 + return 1;
52464 +
52465 + nentry = acl_alloc(sizeof (struct name_entry));
52466 + if (nentry == NULL)
52467 + return 0;
52468 + ientry = acl_alloc(sizeof (struct inodev_entry));
52469 + if (ientry == NULL)
52470 + return 0;
52471 + ientry->nentry = nentry;
52472 +
52473 + nentry->key = key;
52474 + nentry->name = name;
52475 + nentry->inode = inode;
52476 + nentry->device = device;
52477 + nentry->len = len;
52478 + nentry->deleted = deleted;
52479 +
52480 + nentry->prev = NULL;
52481 + curr = &name_set.n_hash[index];
52482 + if (*curr != NULL)
52483 + (*curr)->prev = nentry;
52484 + nentry->next = *curr;
52485 + *curr = nentry;
52486 +
52487 + /* insert us into the table searchable by inode/dev */
52488 + insert_inodev_entry(ientry);
52489 +
52490 + return 1;
52491 +}
52492 +
52493 +static void
52494 +insert_acl_obj_label(struct acl_object_label *obj,
52495 + struct acl_subject_label *subj)
52496 +{
52497 + unsigned int index =
52498 + fhash(obj->inode, obj->device, subj->obj_hash_size);
52499 + struct acl_object_label **curr;
52500 +
52501 +
52502 + obj->prev = NULL;
52503 +
52504 + curr = &subj->obj_hash[index];
52505 + if (*curr != NULL)
52506 + (*curr)->prev = obj;
52507 +
52508 + obj->next = *curr;
52509 + *curr = obj;
52510 +
52511 + return;
52512 +}
52513 +
52514 +static void
52515 +insert_acl_subj_label(struct acl_subject_label *obj,
52516 + struct acl_role_label *role)
52517 +{
52518 + unsigned int index = fhash(obj->inode, obj->device, role->subj_hash_size);
52519 + struct acl_subject_label **curr;
52520 +
52521 + obj->prev = NULL;
52522 +
52523 + curr = &role->subj_hash[index];
52524 + if (*curr != NULL)
52525 + (*curr)->prev = obj;
52526 +
52527 + obj->next = *curr;
52528 + *curr = obj;
52529 +
52530 + return;
52531 +}
52532 +
52533 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
52534 +
52535 +static void *
52536 +create_table(__u32 * len, int elementsize)
52537 +{
52538 + unsigned int table_sizes[] = {
52539 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
52540 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
52541 + 4194301, 8388593, 16777213, 33554393, 67108859
52542 + };
52543 + void *newtable = NULL;
52544 + unsigned int pwr = 0;
52545 +
52546 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
52547 + table_sizes[pwr] <= *len)
52548 + pwr++;
52549 +
52550 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
52551 + return newtable;
52552 +
52553 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
52554 + newtable =
52555 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
52556 + else
52557 + newtable = vmalloc(table_sizes[pwr] * elementsize);
52558 +
52559 + *len = table_sizes[pwr];
52560 +
52561 + return newtable;
52562 +}
52563 +
52564 +static int
52565 +init_variables(const struct gr_arg *arg)
52566 +{
52567 + struct task_struct *reaper = init_pid_ns.child_reaper;
52568 + unsigned int stacksize;
52569 +
52570 + subj_map_set.s_size = arg->role_db.num_subjects;
52571 + acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
52572 + name_set.n_size = arg->role_db.num_objects;
52573 + inodev_set.i_size = arg->role_db.num_objects;
52574 +
52575 + if (!subj_map_set.s_size || !acl_role_set.r_size ||
52576 + !name_set.n_size || !inodev_set.i_size)
52577 + return 1;
52578 +
52579 + if (!gr_init_uidset())
52580 + return 1;
52581 +
52582 + /* set up the stack that holds allocation info */
52583 +
52584 + stacksize = arg->role_db.num_pointers + 5;
52585 +
52586 + if (!acl_alloc_stack_init(stacksize))
52587 + return 1;
52588 +
52589 + /* grab reference for the real root dentry and vfsmount */
52590 + get_fs_root(reaper->fs, &real_root);
52591 +
52592 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
52593 + printk(KERN_ALERT "Obtained real root device=%d, inode=%lu\n", __get_dev(real_root.dentry), real_root.dentry->d_inode->i_ino);
52594 +#endif
52595 +
52596 + fakefs_obj_rw = acl_alloc(sizeof(struct acl_object_label));
52597 + if (fakefs_obj_rw == NULL)
52598 + return 1;
52599 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
52600 +
52601 + fakefs_obj_rwx = acl_alloc(sizeof(struct acl_object_label));
52602 + if (fakefs_obj_rwx == NULL)
52603 + return 1;
52604 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
52605 +
52606 + subj_map_set.s_hash =
52607 + (struct subject_map **) create_table(&subj_map_set.s_size, sizeof(void *));
52608 + acl_role_set.r_hash =
52609 + (struct acl_role_label **) create_table(&acl_role_set.r_size, sizeof(void *));
52610 + name_set.n_hash = (struct name_entry **) create_table(&name_set.n_size, sizeof(void *));
52611 + inodev_set.i_hash =
52612 + (struct inodev_entry **) create_table(&inodev_set.i_size, sizeof(void *));
52613 +
52614 + if (!subj_map_set.s_hash || !acl_role_set.r_hash ||
52615 + !name_set.n_hash || !inodev_set.i_hash)
52616 + return 1;
52617 +
52618 + memset(subj_map_set.s_hash, 0,
52619 + sizeof(struct subject_map *) * subj_map_set.s_size);
52620 + memset(acl_role_set.r_hash, 0,
52621 + sizeof (struct acl_role_label *) * acl_role_set.r_size);
52622 + memset(name_set.n_hash, 0,
52623 + sizeof (struct name_entry *) * name_set.n_size);
52624 + memset(inodev_set.i_hash, 0,
52625 + sizeof (struct inodev_entry *) * inodev_set.i_size);
52626 +
52627 + return 0;
52628 +}
52629 +
52630 +/* free information not needed after startup
52631 + currently contains user->kernel pointer mappings for subjects
52632 +*/
52633 +
52634 +static void
52635 +free_init_variables(void)
52636 +{
52637 + __u32 i;
52638 +
52639 + if (subj_map_set.s_hash) {
52640 + for (i = 0; i < subj_map_set.s_size; i++) {
52641 + if (subj_map_set.s_hash[i]) {
52642 + kfree(subj_map_set.s_hash[i]);
52643 + subj_map_set.s_hash[i] = NULL;
52644 + }
52645 + }
52646 +
52647 + if ((subj_map_set.s_size * sizeof (struct subject_map *)) <=
52648 + PAGE_SIZE)
52649 + kfree(subj_map_set.s_hash);
52650 + else
52651 + vfree(subj_map_set.s_hash);
52652 + }
52653 +
52654 + return;
52655 +}
52656 +
52657 +static void
52658 +free_variables(void)
52659 +{
52660 + struct acl_subject_label *s;
52661 + struct acl_role_label *r;
52662 + struct task_struct *task, *task2;
52663 + unsigned int x;
52664 +
52665 + gr_clear_learn_entries();
52666 +
52667 + read_lock(&tasklist_lock);
52668 + do_each_thread(task2, task) {
52669 + task->acl_sp_role = 0;
52670 + task->acl_role_id = 0;
52671 + task->acl = NULL;
52672 + task->role = NULL;
52673 + } while_each_thread(task2, task);
52674 + read_unlock(&tasklist_lock);
52675 +
52676 + /* release the reference to the real root dentry and vfsmount */
52677 + path_put(&real_root);
52678 + memset(&real_root, 0, sizeof(real_root));
52679 +
52680 + /* free all object hash tables */
52681 +
52682 + FOR_EACH_ROLE_START(r)
52683 + if (r->subj_hash == NULL)
52684 + goto next_role;
52685 + FOR_EACH_SUBJECT_START(r, s, x)
52686 + if (s->obj_hash == NULL)
52687 + break;
52688 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52689 + kfree(s->obj_hash);
52690 + else
52691 + vfree(s->obj_hash);
52692 + FOR_EACH_SUBJECT_END(s, x)
52693 + FOR_EACH_NESTED_SUBJECT_START(r, s)
52694 + if (s->obj_hash == NULL)
52695 + break;
52696 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
52697 + kfree(s->obj_hash);
52698 + else
52699 + vfree(s->obj_hash);
52700 + FOR_EACH_NESTED_SUBJECT_END(s)
52701 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
52702 + kfree(r->subj_hash);
52703 + else
52704 + vfree(r->subj_hash);
52705 + r->subj_hash = NULL;
52706 +next_role:
52707 + FOR_EACH_ROLE_END(r)
52708 +
52709 + acl_free_all();
52710 +
52711 + if (acl_role_set.r_hash) {
52712 + if ((acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
52713 + PAGE_SIZE)
52714 + kfree(acl_role_set.r_hash);
52715 + else
52716 + vfree(acl_role_set.r_hash);
52717 + }
52718 + if (name_set.n_hash) {
52719 + if ((name_set.n_size * sizeof (struct name_entry *)) <=
52720 + PAGE_SIZE)
52721 + kfree(name_set.n_hash);
52722 + else
52723 + vfree(name_set.n_hash);
52724 + }
52725 +
52726 + if (inodev_set.i_hash) {
52727 + if ((inodev_set.i_size * sizeof (struct inodev_entry *)) <=
52728 + PAGE_SIZE)
52729 + kfree(inodev_set.i_hash);
52730 + else
52731 + vfree(inodev_set.i_hash);
52732 + }
52733 +
52734 + gr_free_uidset();
52735 +
52736 + memset(&name_set, 0, sizeof (struct name_db));
52737 + memset(&inodev_set, 0, sizeof (struct inodev_db));
52738 + memset(&acl_role_set, 0, sizeof (struct acl_role_db));
52739 + memset(&subj_map_set, 0, sizeof (struct acl_subj_map_db));
52740 +
52741 + default_role = NULL;
52742 + kernel_role = NULL;
52743 + role_list = NULL;
52744 +
52745 + return;
52746 +}
52747 +
52748 +static __u32
52749 +count_user_objs(struct acl_object_label *userp)
52750 +{
52751 + struct acl_object_label o_tmp;
52752 + __u32 num = 0;
52753 +
52754 + while (userp) {
52755 + if (copy_from_user(&o_tmp, userp,
52756 + sizeof (struct acl_object_label)))
52757 + break;
52758 +
52759 + userp = o_tmp.prev;
52760 + num++;
52761 + }
52762 +
52763 + return num;
52764 +}
52765 +
52766 +static struct acl_subject_label *
52767 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role);
52768 +
52769 +static int
52770 +copy_user_glob(struct acl_object_label *obj)
52771 +{
52772 + struct acl_object_label *g_tmp, **guser;
52773 + unsigned int len;
52774 + char *tmp;
52775 +
52776 + if (obj->globbed == NULL)
52777 + return 0;
52778 +
52779 + guser = &obj->globbed;
52780 + while (*guser) {
52781 + g_tmp = (struct acl_object_label *)
52782 + acl_alloc(sizeof (struct acl_object_label));
52783 + if (g_tmp == NULL)
52784 + return -ENOMEM;
52785 +
52786 + if (copy_from_user(g_tmp, *guser,
52787 + sizeof (struct acl_object_label)))
52788 + return -EFAULT;
52789 +
52790 + len = strnlen_user(g_tmp->filename, PATH_MAX);
52791 +
52792 + if (!len || len >= PATH_MAX)
52793 + return -EINVAL;
52794 +
52795 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52796 + return -ENOMEM;
52797 +
52798 + if (copy_from_user(tmp, g_tmp->filename, len))
52799 + return -EFAULT;
52800 + tmp[len-1] = '\0';
52801 + g_tmp->filename = tmp;
52802 +
52803 + *guser = g_tmp;
52804 + guser = &(g_tmp->next);
52805 + }
52806 +
52807 + return 0;
52808 +}
52809 +
52810 +static int
52811 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
52812 + struct acl_role_label *role)
52813 +{
52814 + struct acl_object_label *o_tmp;
52815 + unsigned int len;
52816 + int ret;
52817 + char *tmp;
52818 +
52819 + while (userp) {
52820 + if ((o_tmp = (struct acl_object_label *)
52821 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
52822 + return -ENOMEM;
52823 +
52824 + if (copy_from_user(o_tmp, userp,
52825 + sizeof (struct acl_object_label)))
52826 + return -EFAULT;
52827 +
52828 + userp = o_tmp->prev;
52829 +
52830 + len = strnlen_user(o_tmp->filename, PATH_MAX);
52831 +
52832 + if (!len || len >= PATH_MAX)
52833 + return -EINVAL;
52834 +
52835 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52836 + return -ENOMEM;
52837 +
52838 + if (copy_from_user(tmp, o_tmp->filename, len))
52839 + return -EFAULT;
52840 + tmp[len-1] = '\0';
52841 + o_tmp->filename = tmp;
52842 +
52843 + insert_acl_obj_label(o_tmp, subj);
52844 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
52845 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
52846 + return -ENOMEM;
52847 +
52848 + ret = copy_user_glob(o_tmp);
52849 + if (ret)
52850 + return ret;
52851 +
52852 + if (o_tmp->nested) {
52853 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role);
52854 + if (IS_ERR(o_tmp->nested))
52855 + return PTR_ERR(o_tmp->nested);
52856 +
52857 + /* insert into nested subject list */
52858 + o_tmp->nested->next = role->hash->first;
52859 + role->hash->first = o_tmp->nested;
52860 + }
52861 + }
52862 +
52863 + return 0;
52864 +}
52865 +
52866 +static __u32
52867 +count_user_subjs(struct acl_subject_label *userp)
52868 +{
52869 + struct acl_subject_label s_tmp;
52870 + __u32 num = 0;
52871 +
52872 + while (userp) {
52873 + if (copy_from_user(&s_tmp, userp,
52874 + sizeof (struct acl_subject_label)))
52875 + break;
52876 +
52877 + userp = s_tmp.prev;
52878 + /* do not count nested subjects against this count, since
52879 + they are not included in the hash table, but are
52880 + attached to objects. We have already counted
52881 + the subjects in userspace for the allocation
52882 + stack
52883 + */
52884 + if (!(s_tmp.mode & GR_NESTED))
52885 + num++;
52886 + }
52887 +
52888 + return num;
52889 +}
52890 +
52891 +static int
52892 +copy_user_allowedips(struct acl_role_label *rolep)
52893 +{
52894 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
52895 +
52896 + ruserip = rolep->allowed_ips;
52897 +
52898 + while (ruserip) {
52899 + rlast = rtmp;
52900 +
52901 + if ((rtmp = (struct role_allowed_ip *)
52902 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
52903 + return -ENOMEM;
52904 +
52905 + if (copy_from_user(rtmp, ruserip,
52906 + sizeof (struct role_allowed_ip)))
52907 + return -EFAULT;
52908 +
52909 + ruserip = rtmp->prev;
52910 +
52911 + if (!rlast) {
52912 + rtmp->prev = NULL;
52913 + rolep->allowed_ips = rtmp;
52914 + } else {
52915 + rlast->next = rtmp;
52916 + rtmp->prev = rlast;
52917 + }
52918 +
52919 + if (!ruserip)
52920 + rtmp->next = NULL;
52921 + }
52922 +
52923 + return 0;
52924 +}
52925 +
52926 +static int
52927 +copy_user_transitions(struct acl_role_label *rolep)
52928 +{
52929 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
52930 +
52931 + unsigned int len;
52932 + char *tmp;
52933 +
52934 + rusertp = rolep->transitions;
52935 +
52936 + while (rusertp) {
52937 + rlast = rtmp;
52938 +
52939 + if ((rtmp = (struct role_transition *)
52940 + acl_alloc(sizeof (struct role_transition))) == NULL)
52941 + return -ENOMEM;
52942 +
52943 + if (copy_from_user(rtmp, rusertp,
52944 + sizeof (struct role_transition)))
52945 + return -EFAULT;
52946 +
52947 + rusertp = rtmp->prev;
52948 +
52949 + len = strnlen_user(rtmp->rolename, GR_SPROLE_LEN);
52950 +
52951 + if (!len || len >= GR_SPROLE_LEN)
52952 + return -EINVAL;
52953 +
52954 + if ((tmp = (char *) acl_alloc(len)) == NULL)
52955 + return -ENOMEM;
52956 +
52957 + if (copy_from_user(tmp, rtmp->rolename, len))
52958 + return -EFAULT;
52959 + tmp[len-1] = '\0';
52960 + rtmp->rolename = tmp;
52961 +
52962 + if (!rlast) {
52963 + rtmp->prev = NULL;
52964 + rolep->transitions = rtmp;
52965 + } else {
52966 + rlast->next = rtmp;
52967 + rtmp->prev = rlast;
52968 + }
52969 +
52970 + if (!rusertp)
52971 + rtmp->next = NULL;
52972 + }
52973 +
52974 + return 0;
52975 +}
52976 +
52977 +static struct acl_subject_label *
52978 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role)
52979 +{
52980 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
52981 + unsigned int len;
52982 + char *tmp;
52983 + __u32 num_objs;
52984 + struct acl_ip_label **i_tmp, *i_utmp2;
52985 + struct gr_hash_struct ghash;
52986 + struct subject_map *subjmap;
52987 + unsigned int i_num;
52988 + int err;
52989 +
52990 + s_tmp = lookup_subject_map(userp);
52991 +
52992 + /* we've already copied this subject into the kernel, just return
52993 + the reference to it, and don't copy it over again
52994 + */
52995 + if (s_tmp)
52996 + return(s_tmp);
52997 +
52998 + if ((s_tmp = (struct acl_subject_label *)
52999 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
53000 + return ERR_PTR(-ENOMEM);
53001 +
53002 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
53003 + if (subjmap == NULL)
53004 + return ERR_PTR(-ENOMEM);
53005 +
53006 + subjmap->user = userp;
53007 + subjmap->kernel = s_tmp;
53008 + insert_subj_map_entry(subjmap);
53009 +
53010 + if (copy_from_user(s_tmp, userp,
53011 + sizeof (struct acl_subject_label)))
53012 + return ERR_PTR(-EFAULT);
53013 +
53014 + len = strnlen_user(s_tmp->filename, PATH_MAX);
53015 +
53016 + if (!len || len >= PATH_MAX)
53017 + return ERR_PTR(-EINVAL);
53018 +
53019 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53020 + return ERR_PTR(-ENOMEM);
53021 +
53022 + if (copy_from_user(tmp, s_tmp->filename, len))
53023 + return ERR_PTR(-EFAULT);
53024 + tmp[len-1] = '\0';
53025 + s_tmp->filename = tmp;
53026 +
53027 + if (!strcmp(s_tmp->filename, "/"))
53028 + role->root_label = s_tmp;
53029 +
53030 + if (copy_from_user(&ghash, s_tmp->hash, sizeof(struct gr_hash_struct)))
53031 + return ERR_PTR(-EFAULT);
53032 +
53033 + /* copy user and group transition tables */
53034 +
53035 + if (s_tmp->user_trans_num) {
53036 + uid_t *uidlist;
53037 +
53038 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
53039 + if (uidlist == NULL)
53040 + return ERR_PTR(-ENOMEM);
53041 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
53042 + return ERR_PTR(-EFAULT);
53043 +
53044 + s_tmp->user_transitions = uidlist;
53045 + }
53046 +
53047 + if (s_tmp->group_trans_num) {
53048 + gid_t *gidlist;
53049 +
53050 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
53051 + if (gidlist == NULL)
53052 + return ERR_PTR(-ENOMEM);
53053 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
53054 + return ERR_PTR(-EFAULT);
53055 +
53056 + s_tmp->group_transitions = gidlist;
53057 + }
53058 +
53059 + /* set up object hash table */
53060 + num_objs = count_user_objs(ghash.first);
53061 +
53062 + s_tmp->obj_hash_size = num_objs;
53063 + s_tmp->obj_hash =
53064 + (struct acl_object_label **)
53065 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
53066 +
53067 + if (!s_tmp->obj_hash)
53068 + return ERR_PTR(-ENOMEM);
53069 +
53070 + memset(s_tmp->obj_hash, 0,
53071 + s_tmp->obj_hash_size *
53072 + sizeof (struct acl_object_label *));
53073 +
53074 + /* add in objects */
53075 + err = copy_user_objs(ghash.first, s_tmp, role);
53076 +
53077 + if (err)
53078 + return ERR_PTR(err);
53079 +
53080 + /* set pointer for parent subject */
53081 + if (s_tmp->parent_subject) {
53082 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role);
53083 +
53084 + if (IS_ERR(s_tmp2))
53085 + return s_tmp2;
53086 +
53087 + s_tmp->parent_subject = s_tmp2;
53088 + }
53089 +
53090 + /* add in ip acls */
53091 +
53092 + if (!s_tmp->ip_num) {
53093 + s_tmp->ips = NULL;
53094 + goto insert;
53095 + }
53096 +
53097 + i_tmp =
53098 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
53099 + sizeof (struct acl_ip_label *));
53100 +
53101 + if (!i_tmp)
53102 + return ERR_PTR(-ENOMEM);
53103 +
53104 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
53105 + *(i_tmp + i_num) =
53106 + (struct acl_ip_label *)
53107 + acl_alloc(sizeof (struct acl_ip_label));
53108 + if (!*(i_tmp + i_num))
53109 + return ERR_PTR(-ENOMEM);
53110 +
53111 + if (copy_from_user
53112 + (&i_utmp2, s_tmp->ips + i_num,
53113 + sizeof (struct acl_ip_label *)))
53114 + return ERR_PTR(-EFAULT);
53115 +
53116 + if (copy_from_user
53117 + (*(i_tmp + i_num), i_utmp2,
53118 + sizeof (struct acl_ip_label)))
53119 + return ERR_PTR(-EFAULT);
53120 +
53121 + if ((*(i_tmp + i_num))->iface == NULL)
53122 + continue;
53123 +
53124 + len = strnlen_user((*(i_tmp + i_num))->iface, IFNAMSIZ);
53125 + if (!len || len >= IFNAMSIZ)
53126 + return ERR_PTR(-EINVAL);
53127 + tmp = acl_alloc(len);
53128 + if (tmp == NULL)
53129 + return ERR_PTR(-ENOMEM);
53130 + if (copy_from_user(tmp, (*(i_tmp + i_num))->iface, len))
53131 + return ERR_PTR(-EFAULT);
53132 + (*(i_tmp + i_num))->iface = tmp;
53133 + }
53134 +
53135 + s_tmp->ips = i_tmp;
53136 +
53137 +insert:
53138 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
53139 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
53140 + return ERR_PTR(-ENOMEM);
53141 +
53142 + return s_tmp;
53143 +}
53144 +
53145 +static int
53146 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
53147 +{
53148 + struct acl_subject_label s_pre;
53149 + struct acl_subject_label * ret;
53150 + int err;
53151 +
53152 + while (userp) {
53153 + if (copy_from_user(&s_pre, userp,
53154 + sizeof (struct acl_subject_label)))
53155 + return -EFAULT;
53156 +
53157 + /* do not add nested subjects here, add
53158 + while parsing objects
53159 + */
53160 +
53161 + if (s_pre.mode & GR_NESTED) {
53162 + userp = s_pre.prev;
53163 + continue;
53164 + }
53165 +
53166 + ret = do_copy_user_subj(userp, role);
53167 +
53168 + err = PTR_ERR(ret);
53169 + if (IS_ERR(ret))
53170 + return err;
53171 +
53172 + insert_acl_subj_label(ret, role);
53173 +
53174 + userp = s_pre.prev;
53175 + }
53176 +
53177 + return 0;
53178 +}
53179 +
53180 +static int
53181 +copy_user_acl(struct gr_arg *arg)
53182 +{
53183 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
53184 + struct sprole_pw *sptmp;
53185 + struct gr_hash_struct *ghash;
53186 + uid_t *domainlist;
53187 + unsigned int r_num;
53188 + unsigned int len;
53189 + char *tmp;
53190 + int err = 0;
53191 + __u16 i;
53192 + __u32 num_subjs;
53193 +
53194 + /* we need a default and kernel role */
53195 + if (arg->role_db.num_roles < 2)
53196 + return -EINVAL;
53197 +
53198 + /* copy special role authentication info from userspace */
53199 +
53200 + num_sprole_pws = arg->num_sprole_pws;
53201 + acl_special_roles = (struct sprole_pw **) acl_alloc_num(num_sprole_pws, sizeof(struct sprole_pw *));
53202 +
53203 + if (!acl_special_roles && num_sprole_pws)
53204 + return -ENOMEM;
53205 +
53206 + for (i = 0; i < num_sprole_pws; i++) {
53207 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
53208 + if (!sptmp)
53209 + return -ENOMEM;
53210 + if (copy_from_user(sptmp, arg->sprole_pws + i,
53211 + sizeof (struct sprole_pw)))
53212 + return -EFAULT;
53213 +
53214 + len = strnlen_user(sptmp->rolename, GR_SPROLE_LEN);
53215 +
53216 + if (!len || len >= GR_SPROLE_LEN)
53217 + return -EINVAL;
53218 +
53219 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53220 + return -ENOMEM;
53221 +
53222 + if (copy_from_user(tmp, sptmp->rolename, len))
53223 + return -EFAULT;
53224 +
53225 + tmp[len-1] = '\0';
53226 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
53227 + printk(KERN_ALERT "Copying special role %s\n", tmp);
53228 +#endif
53229 + sptmp->rolename = tmp;
53230 + acl_special_roles[i] = sptmp;
53231 + }
53232 +
53233 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
53234 +
53235 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
53236 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
53237 +
53238 + if (!r_tmp)
53239 + return -ENOMEM;
53240 +
53241 + if (copy_from_user(&r_utmp2, r_utmp + r_num,
53242 + sizeof (struct acl_role_label *)))
53243 + return -EFAULT;
53244 +
53245 + if (copy_from_user(r_tmp, r_utmp2,
53246 + sizeof (struct acl_role_label)))
53247 + return -EFAULT;
53248 +
53249 + len = strnlen_user(r_tmp->rolename, GR_SPROLE_LEN);
53250 +
53251 + if (!len || len >= PATH_MAX)
53252 + return -EINVAL;
53253 +
53254 + if ((tmp = (char *) acl_alloc(len)) == NULL)
53255 + return -ENOMEM;
53256 +
53257 + if (copy_from_user(tmp, r_tmp->rolename, len))
53258 + return -EFAULT;
53259 +
53260 + tmp[len-1] = '\0';
53261 + r_tmp->rolename = tmp;
53262 +
53263 + if (!strcmp(r_tmp->rolename, "default")
53264 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
53265 + default_role = r_tmp;
53266 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
53267 + kernel_role = r_tmp;
53268 + }
53269 +
53270 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
53271 + return -ENOMEM;
53272 +
53273 + if (copy_from_user(ghash, r_tmp->hash, sizeof(struct gr_hash_struct)))
53274 + return -EFAULT;
53275 +
53276 + r_tmp->hash = ghash;
53277 +
53278 + num_subjs = count_user_subjs(r_tmp->hash->first);
53279 +
53280 + r_tmp->subj_hash_size = num_subjs;
53281 + r_tmp->subj_hash =
53282 + (struct acl_subject_label **)
53283 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
53284 +
53285 + if (!r_tmp->subj_hash)
53286 + return -ENOMEM;
53287 +
53288 + err = copy_user_allowedips(r_tmp);
53289 + if (err)
53290 + return err;
53291 +
53292 + /* copy domain info */
53293 + if (r_tmp->domain_children != NULL) {
53294 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
53295 + if (domainlist == NULL)
53296 + return -ENOMEM;
53297 +
53298 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
53299 + return -EFAULT;
53300 +
53301 + r_tmp->domain_children = domainlist;
53302 + }
53303 +
53304 + err = copy_user_transitions(r_tmp);
53305 + if (err)
53306 + return err;
53307 +
53308 + memset(r_tmp->subj_hash, 0,
53309 + r_tmp->subj_hash_size *
53310 + sizeof (struct acl_subject_label *));
53311 +
53312 + err = copy_user_subjs(r_tmp->hash->first, r_tmp);
53313 +
53314 + if (err)
53315 + return err;
53316 +
53317 + /* set nested subject list to null */
53318 + r_tmp->hash->first = NULL;
53319 +
53320 + insert_acl_role_label(r_tmp);
53321 + }
53322 +
53323 + if (default_role == NULL || kernel_role == NULL)
53324 + return -EINVAL;
53325 +
53326 + return err;
53327 +}
53328 +
53329 +static int
53330 +gracl_init(struct gr_arg *args)
53331 +{
53332 + int error = 0;
53333 +
53334 + memcpy(gr_system_salt, args->salt, GR_SALT_LEN);
53335 + memcpy(gr_system_sum, args->sum, GR_SHA_LEN);
53336 +
53337 + if (init_variables(args)) {
53338 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
53339 + error = -ENOMEM;
53340 + free_variables();
53341 + goto out;
53342 + }
53343 +
53344 + error = copy_user_acl(args);
53345 + free_init_variables();
53346 + if (error) {
53347 + free_variables();
53348 + goto out;
53349 + }
53350 +
53351 + if ((error = gr_set_acls(0))) {
53352 + free_variables();
53353 + goto out;
53354 + }
53355 +
53356 + pax_open_kernel();
53357 + gr_status |= GR_READY;
53358 + pax_close_kernel();
53359 +
53360 + out:
53361 + return error;
53362 +}
53363 +
53364 +/* derived from glibc fnmatch() 0: match, 1: no match*/
53365 +
53366 +static int
53367 +glob_match(const char *p, const char *n)
53368 +{
53369 + char c;
53370 +
53371 + while ((c = *p++) != '\0') {
53372 + switch (c) {
53373 + case '?':
53374 + if (*n == '\0')
53375 + return 1;
53376 + else if (*n == '/')
53377 + return 1;
53378 + break;
53379 + case '\\':
53380 + if (*n != c)
53381 + return 1;
53382 + break;
53383 + case '*':
53384 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
53385 + if (*n == '/')
53386 + return 1;
53387 + else if (c == '?') {
53388 + if (*n == '\0')
53389 + return 1;
53390 + else
53391 + ++n;
53392 + }
53393 + }
53394 + if (c == '\0') {
53395 + return 0;
53396 + } else {
53397 + const char *endp;
53398 +
53399 + if ((endp = strchr(n, '/')) == NULL)
53400 + endp = n + strlen(n);
53401 +
53402 + if (c == '[') {
53403 + for (--p; n < endp; ++n)
53404 + if (!glob_match(p, n))
53405 + return 0;
53406 + } else if (c == '/') {
53407 + while (*n != '\0' && *n != '/')
53408 + ++n;
53409 + if (*n == '/' && !glob_match(p, n + 1))
53410 + return 0;
53411 + } else {
53412 + for (--p; n < endp; ++n)
53413 + if (*n == c && !glob_match(p, n))
53414 + return 0;
53415 + }
53416 +
53417 + return 1;
53418 + }
53419 + case '[':
53420 + {
53421 + int not;
53422 + char cold;
53423 +
53424 + if (*n == '\0' || *n == '/')
53425 + return 1;
53426 +
53427 + not = (*p == '!' || *p == '^');
53428 + if (not)
53429 + ++p;
53430 +
53431 + c = *p++;
53432 + for (;;) {
53433 + unsigned char fn = (unsigned char)*n;
53434 +
53435 + if (c == '\0')
53436 + return 1;
53437 + else {
53438 + if (c == fn)
53439 + goto matched;
53440 + cold = c;
53441 + c = *p++;
53442 +
53443 + if (c == '-' && *p != ']') {
53444 + unsigned char cend = *p++;
53445 +
53446 + if (cend == '\0')
53447 + return 1;
53448 +
53449 + if (cold <= fn && fn <= cend)
53450 + goto matched;
53451 +
53452 + c = *p++;
53453 + }
53454 + }
53455 +
53456 + if (c == ']')
53457 + break;
53458 + }
53459 + if (!not)
53460 + return 1;
53461 + break;
53462 + matched:
53463 + while (c != ']') {
53464 + if (c == '\0')
53465 + return 1;
53466 +
53467 + c = *p++;
53468 + }
53469 + if (not)
53470 + return 1;
53471 + }
53472 + break;
53473 + default:
53474 + if (c != *n)
53475 + return 1;
53476 + }
53477 +
53478 + ++n;
53479 + }
53480 +
53481 + if (*n == '\0')
53482 + return 0;
53483 +
53484 + if (*n == '/')
53485 + return 0;
53486 +
53487 + return 1;
53488 +}
53489 +
53490 +static struct acl_object_label *
53491 +chk_glob_label(struct acl_object_label *globbed,
53492 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
53493 +{
53494 + struct acl_object_label *tmp;
53495 +
53496 + if (*path == NULL)
53497 + *path = gr_to_filename_nolock(dentry, mnt);
53498 +
53499 + tmp = globbed;
53500 +
53501 + while (tmp) {
53502 + if (!glob_match(tmp->filename, *path))
53503 + return tmp;
53504 + tmp = tmp->next;
53505 + }
53506 +
53507 + return NULL;
53508 +}
53509 +
53510 +static struct acl_object_label *
53511 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53512 + const ino_t curr_ino, const dev_t curr_dev,
53513 + const struct acl_subject_label *subj, char **path, const int checkglob)
53514 +{
53515 + struct acl_subject_label *tmpsubj;
53516 + struct acl_object_label *retval;
53517 + struct acl_object_label *retval2;
53518 +
53519 + tmpsubj = (struct acl_subject_label *) subj;
53520 + read_lock(&gr_inode_lock);
53521 + do {
53522 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
53523 + if (retval) {
53524 + if (checkglob && retval->globbed) {
53525 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
53526 + if (retval2)
53527 + retval = retval2;
53528 + }
53529 + break;
53530 + }
53531 + } while ((tmpsubj = tmpsubj->parent_subject));
53532 + read_unlock(&gr_inode_lock);
53533 +
53534 + return retval;
53535 +}
53536 +
53537 +static __inline__ struct acl_object_label *
53538 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
53539 + struct dentry *curr_dentry,
53540 + const struct acl_subject_label *subj, char **path, const int checkglob)
53541 +{
53542 + int newglob = checkglob;
53543 + ino_t inode;
53544 + dev_t device;
53545 +
53546 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
53547 + as we don't want a / * rule to match instead of the / object
53548 + don't do this for create lookups that call this function though, since they're looking up
53549 + on the parent and thus need globbing checks on all paths
53550 + */
53551 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
53552 + newglob = GR_NO_GLOB;
53553 +
53554 + spin_lock(&curr_dentry->d_lock);
53555 + inode = curr_dentry->d_inode->i_ino;
53556 + device = __get_dev(curr_dentry);
53557 + spin_unlock(&curr_dentry->d_lock);
53558 +
53559 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
53560 +}
53561 +
53562 +static struct acl_object_label *
53563 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53564 + const struct acl_subject_label *subj, char *path, const int checkglob)
53565 +{
53566 + struct dentry *dentry = (struct dentry *) l_dentry;
53567 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53568 + struct mount *real_mnt = real_mount(mnt);
53569 + struct acl_object_label *retval;
53570 + struct dentry *parent;
53571 +
53572 + write_seqlock(&rename_lock);
53573 + br_read_lock(&vfsmount_lock);
53574 +
53575 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
53576 +#ifdef CONFIG_NET
53577 + mnt == sock_mnt ||
53578 +#endif
53579 +#ifdef CONFIG_HUGETLBFS
53580 + (mnt == hugetlbfs_vfsmount && dentry->d_inode->i_nlink == 0) ||
53581 +#endif
53582 + /* ignore Eric Biederman */
53583 + IS_PRIVATE(l_dentry->d_inode))) {
53584 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
53585 + goto out;
53586 + }
53587 +
53588 + for (;;) {
53589 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53590 + break;
53591 +
53592 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53593 + if (!mnt_has_parent(real_mnt))
53594 + break;
53595 +
53596 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53597 + if (retval != NULL)
53598 + goto out;
53599 +
53600 + dentry = real_mnt->mnt_mountpoint;
53601 + real_mnt = real_mnt->mnt_parent;
53602 + mnt = &real_mnt->mnt;
53603 + continue;
53604 + }
53605 +
53606 + parent = dentry->d_parent;
53607 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53608 + if (retval != NULL)
53609 + goto out;
53610 +
53611 + dentry = parent;
53612 + }
53613 +
53614 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
53615 +
53616 + /* real_root is pinned so we don't have to hold a reference */
53617 + if (retval == NULL)
53618 + retval = full_lookup(l_dentry, l_mnt, real_root.dentry, subj, &path, checkglob);
53619 +out:
53620 + br_read_unlock(&vfsmount_lock);
53621 + write_sequnlock(&rename_lock);
53622 +
53623 + BUG_ON(retval == NULL);
53624 +
53625 + return retval;
53626 +}
53627 +
53628 +static __inline__ struct acl_object_label *
53629 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53630 + const struct acl_subject_label *subj)
53631 +{
53632 + char *path = NULL;
53633 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
53634 +}
53635 +
53636 +static __inline__ struct acl_object_label *
53637 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53638 + const struct acl_subject_label *subj)
53639 +{
53640 + char *path = NULL;
53641 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
53642 +}
53643 +
53644 +static __inline__ struct acl_object_label *
53645 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53646 + const struct acl_subject_label *subj, char *path)
53647 +{
53648 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
53649 +}
53650 +
53651 +static struct acl_subject_label *
53652 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
53653 + const struct acl_role_label *role)
53654 +{
53655 + struct dentry *dentry = (struct dentry *) l_dentry;
53656 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
53657 + struct mount *real_mnt = real_mount(mnt);
53658 + struct acl_subject_label *retval;
53659 + struct dentry *parent;
53660 +
53661 + write_seqlock(&rename_lock);
53662 + br_read_lock(&vfsmount_lock);
53663 +
53664 + for (;;) {
53665 + if (dentry == real_root.dentry && mnt == real_root.mnt)
53666 + break;
53667 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
53668 + if (!mnt_has_parent(real_mnt))
53669 + break;
53670 +
53671 + spin_lock(&dentry->d_lock);
53672 + read_lock(&gr_inode_lock);
53673 + retval =
53674 + lookup_acl_subj_label(dentry->d_inode->i_ino,
53675 + __get_dev(dentry), role);
53676 + read_unlock(&gr_inode_lock);
53677 + spin_unlock(&dentry->d_lock);
53678 + if (retval != NULL)
53679 + goto out;
53680 +
53681 + dentry = real_mnt->mnt_mountpoint;
53682 + real_mnt = real_mnt->mnt_parent;
53683 + mnt = &real_mnt->mnt;
53684 + continue;
53685 + }
53686 +
53687 + spin_lock(&dentry->d_lock);
53688 + read_lock(&gr_inode_lock);
53689 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53690 + __get_dev(dentry), role);
53691 + read_unlock(&gr_inode_lock);
53692 + parent = dentry->d_parent;
53693 + spin_unlock(&dentry->d_lock);
53694 +
53695 + if (retval != NULL)
53696 + goto out;
53697 +
53698 + dentry = parent;
53699 + }
53700 +
53701 + spin_lock(&dentry->d_lock);
53702 + read_lock(&gr_inode_lock);
53703 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
53704 + __get_dev(dentry), role);
53705 + read_unlock(&gr_inode_lock);
53706 + spin_unlock(&dentry->d_lock);
53707 +
53708 + if (unlikely(retval == NULL)) {
53709 + /* real_root is pinned, we don't need to hold a reference */
53710 + read_lock(&gr_inode_lock);
53711 + retval = lookup_acl_subj_label(real_root.dentry->d_inode->i_ino,
53712 + __get_dev(real_root.dentry), role);
53713 + read_unlock(&gr_inode_lock);
53714 + }
53715 +out:
53716 + br_read_unlock(&vfsmount_lock);
53717 + write_sequnlock(&rename_lock);
53718 +
53719 + BUG_ON(retval == NULL);
53720 +
53721 + return retval;
53722 +}
53723 +
53724 +static void
53725 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
53726 +{
53727 + struct task_struct *task = current;
53728 + const struct cred *cred = current_cred();
53729 +
53730 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
53731 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53732 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53733 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
53734 +
53735 + return;
53736 +}
53737 +
53738 +static void
53739 +gr_log_learn_id_change(const char type, const unsigned int real,
53740 + const unsigned int effective, const unsigned int fs)
53741 +{
53742 + struct task_struct *task = current;
53743 + const struct cred *cred = current_cred();
53744 +
53745 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
53746 + cred->uid, cred->gid, task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
53747 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
53748 + type, real, effective, fs, &task->signal->saved_ip);
53749 +
53750 + return;
53751 +}
53752 +
53753 +__u32
53754 +gr_search_file(const struct dentry * dentry, const __u32 mode,
53755 + const struct vfsmount * mnt)
53756 +{
53757 + __u32 retval = mode;
53758 + struct acl_subject_label *curracl;
53759 + struct acl_object_label *currobj;
53760 +
53761 + if (unlikely(!(gr_status & GR_READY)))
53762 + return (mode & ~GR_AUDITS);
53763 +
53764 + curracl = current->acl;
53765 +
53766 + currobj = chk_obj_label(dentry, mnt, curracl);
53767 + retval = currobj->mode & mode;
53768 +
53769 + /* if we're opening a specified transfer file for writing
53770 + (e.g. /dev/initctl), then transfer our role to init
53771 + */
53772 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
53773 + current->role->roletype & GR_ROLE_PERSIST)) {
53774 + struct task_struct *task = init_pid_ns.child_reaper;
53775 +
53776 + if (task->role != current->role) {
53777 + task->acl_sp_role = 0;
53778 + task->acl_role_id = current->acl_role_id;
53779 + task->role = current->role;
53780 + rcu_read_lock();
53781 + read_lock(&grsec_exec_file_lock);
53782 + gr_apply_subject_to_task(task);
53783 + read_unlock(&grsec_exec_file_lock);
53784 + rcu_read_unlock();
53785 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
53786 + }
53787 + }
53788 +
53789 + if (unlikely
53790 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
53791 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
53792 + __u32 new_mode = mode;
53793 +
53794 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53795 +
53796 + retval = new_mode;
53797 +
53798 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
53799 + new_mode |= GR_INHERIT;
53800 +
53801 + if (!(mode & GR_NOLEARN))
53802 + gr_log_learn(dentry, mnt, new_mode);
53803 + }
53804 +
53805 + return retval;
53806 +}
53807 +
53808 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
53809 + const struct dentry *parent,
53810 + const struct vfsmount *mnt)
53811 +{
53812 + struct name_entry *match;
53813 + struct acl_object_label *matchpo;
53814 + struct acl_subject_label *curracl;
53815 + char *path;
53816 +
53817 + if (unlikely(!(gr_status & GR_READY)))
53818 + return NULL;
53819 +
53820 + preempt_disable();
53821 + path = gr_to_filename_rbac(new_dentry, mnt);
53822 + match = lookup_name_entry_create(path);
53823 +
53824 + curracl = current->acl;
53825 +
53826 + if (match) {
53827 + read_lock(&gr_inode_lock);
53828 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
53829 + read_unlock(&gr_inode_lock);
53830 +
53831 + if (matchpo) {
53832 + preempt_enable();
53833 + return matchpo;
53834 + }
53835 + }
53836 +
53837 + // lookup parent
53838 +
53839 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
53840 +
53841 + preempt_enable();
53842 + return matchpo;
53843 +}
53844 +
53845 +__u32
53846 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
53847 + const struct vfsmount * mnt, const __u32 mode)
53848 +{
53849 + struct acl_object_label *matchpo;
53850 + __u32 retval;
53851 +
53852 + if (unlikely(!(gr_status & GR_READY)))
53853 + return (mode & ~GR_AUDITS);
53854 +
53855 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
53856 +
53857 + retval = matchpo->mode & mode;
53858 +
53859 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
53860 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
53861 + __u32 new_mode = mode;
53862 +
53863 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
53864 +
53865 + gr_log_learn(new_dentry, mnt, new_mode);
53866 + return new_mode;
53867 + }
53868 +
53869 + return retval;
53870 +}
53871 +
53872 +__u32
53873 +gr_check_link(const struct dentry * new_dentry,
53874 + const struct dentry * parent_dentry,
53875 + const struct vfsmount * parent_mnt,
53876 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
53877 +{
53878 + struct acl_object_label *obj;
53879 + __u32 oldmode, newmode;
53880 + __u32 needmode;
53881 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
53882 + GR_DELETE | GR_INHERIT;
53883 +
53884 + if (unlikely(!(gr_status & GR_READY)))
53885 + return (GR_CREATE | GR_LINK);
53886 +
53887 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
53888 + oldmode = obj->mode;
53889 +
53890 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
53891 + newmode = obj->mode;
53892 +
53893 + needmode = newmode & checkmodes;
53894 +
53895 + // old name for hardlink must have at least the permissions of the new name
53896 + if ((oldmode & needmode) != needmode)
53897 + goto bad;
53898 +
53899 + // if old name had restrictions/auditing, make sure the new name does as well
53900 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
53901 +
53902 + // don't allow hardlinking of suid/sgid/fcapped files without permission
53903 + if (is_privileged_binary(old_dentry))
53904 + needmode |= GR_SETID;
53905 +
53906 + if ((newmode & needmode) != needmode)
53907 + goto bad;
53908 +
53909 + // enforce minimum permissions
53910 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
53911 + return newmode;
53912 +bad:
53913 + needmode = oldmode;
53914 + if (is_privileged_binary(old_dentry))
53915 + needmode |= GR_SETID;
53916 +
53917 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
53918 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
53919 + return (GR_CREATE | GR_LINK);
53920 + } else if (newmode & GR_SUPPRESS)
53921 + return GR_SUPPRESS;
53922 + else
53923 + return 0;
53924 +}
53925 +
53926 +int
53927 +gr_check_hidden_task(const struct task_struct *task)
53928 +{
53929 + if (unlikely(!(gr_status & GR_READY)))
53930 + return 0;
53931 +
53932 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
53933 + return 1;
53934 +
53935 + return 0;
53936 +}
53937 +
53938 +int
53939 +gr_check_protected_task(const struct task_struct *task)
53940 +{
53941 + if (unlikely(!(gr_status & GR_READY) || !task))
53942 + return 0;
53943 +
53944 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53945 + task->acl != current->acl)
53946 + return 1;
53947 +
53948 + return 0;
53949 +}
53950 +
53951 +int
53952 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
53953 +{
53954 + struct task_struct *p;
53955 + int ret = 0;
53956 +
53957 + if (unlikely(!(gr_status & GR_READY) || !pid))
53958 + return ret;
53959 +
53960 + read_lock(&tasklist_lock);
53961 + do_each_pid_task(pid, type, p) {
53962 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
53963 + p->acl != current->acl) {
53964 + ret = 1;
53965 + goto out;
53966 + }
53967 + } while_each_pid_task(pid, type, p);
53968 +out:
53969 + read_unlock(&tasklist_lock);
53970 +
53971 + return ret;
53972 +}
53973 +
53974 +void
53975 +gr_copy_label(struct task_struct *tsk)
53976 +{
53977 + tsk->signal->used_accept = 0;
53978 + tsk->acl_sp_role = 0;
53979 + tsk->acl_role_id = current->acl_role_id;
53980 + tsk->acl = current->acl;
53981 + tsk->role = current->role;
53982 + tsk->signal->curr_ip = current->signal->curr_ip;
53983 + tsk->signal->saved_ip = current->signal->saved_ip;
53984 + if (current->exec_file)
53985 + get_file(current->exec_file);
53986 + tsk->exec_file = current->exec_file;
53987 + tsk->is_writable = current->is_writable;
53988 + if (unlikely(current->signal->used_accept)) {
53989 + current->signal->curr_ip = 0;
53990 + current->signal->saved_ip = 0;
53991 + }
53992 +
53993 + return;
53994 +}
53995 +
53996 +static void
53997 +gr_set_proc_res(struct task_struct *task)
53998 +{
53999 + struct acl_subject_label *proc;
54000 + unsigned short i;
54001 +
54002 + proc = task->acl;
54003 +
54004 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
54005 + return;
54006 +
54007 + for (i = 0; i < RLIM_NLIMITS; i++) {
54008 + if (!(proc->resmask & (1 << i)))
54009 + continue;
54010 +
54011 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
54012 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
54013 + }
54014 +
54015 + return;
54016 +}
54017 +
54018 +extern int __gr_process_user_ban(struct user_struct *user);
54019 +
54020 +int
54021 +gr_check_user_change(int real, int effective, int fs)
54022 +{
54023 + unsigned int i;
54024 + __u16 num;
54025 + uid_t *uidlist;
54026 + int curuid;
54027 + int realok = 0;
54028 + int effectiveok = 0;
54029 + int fsok = 0;
54030 +
54031 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
54032 + struct user_struct *user;
54033 +
54034 + if (real == -1)
54035 + goto skipit;
54036 +
54037 + user = find_user(real);
54038 + if (user == NULL)
54039 + goto skipit;
54040 +
54041 + if (__gr_process_user_ban(user)) {
54042 + /* for find_user */
54043 + free_uid(user);
54044 + return 1;
54045 + }
54046 +
54047 + /* for find_user */
54048 + free_uid(user);
54049 +
54050 +skipit:
54051 +#endif
54052 +
54053 + if (unlikely(!(gr_status & GR_READY)))
54054 + return 0;
54055 +
54056 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54057 + gr_log_learn_id_change('u', real, effective, fs);
54058 +
54059 + num = current->acl->user_trans_num;
54060 + uidlist = current->acl->user_transitions;
54061 +
54062 + if (uidlist == NULL)
54063 + return 0;
54064 +
54065 + if (real == -1)
54066 + realok = 1;
54067 + if (effective == -1)
54068 + effectiveok = 1;
54069 + if (fs == -1)
54070 + fsok = 1;
54071 +
54072 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
54073 + for (i = 0; i < num; i++) {
54074 + curuid = (int)uidlist[i];
54075 + if (real == curuid)
54076 + realok = 1;
54077 + if (effective == curuid)
54078 + effectiveok = 1;
54079 + if (fs == curuid)
54080 + fsok = 1;
54081 + }
54082 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
54083 + for (i = 0; i < num; i++) {
54084 + curuid = (int)uidlist[i];
54085 + if (real == curuid)
54086 + break;
54087 + if (effective == curuid)
54088 + break;
54089 + if (fs == curuid)
54090 + break;
54091 + }
54092 + /* not in deny list */
54093 + if (i == num) {
54094 + realok = 1;
54095 + effectiveok = 1;
54096 + fsok = 1;
54097 + }
54098 + }
54099 +
54100 + if (realok && effectiveok && fsok)
54101 + return 0;
54102 + else {
54103 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54104 + return 1;
54105 + }
54106 +}
54107 +
54108 +int
54109 +gr_check_group_change(int real, int effective, int fs)
54110 +{
54111 + unsigned int i;
54112 + __u16 num;
54113 + gid_t *gidlist;
54114 + int curgid;
54115 + int realok = 0;
54116 + int effectiveok = 0;
54117 + int fsok = 0;
54118 +
54119 + if (unlikely(!(gr_status & GR_READY)))
54120 + return 0;
54121 +
54122 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
54123 + gr_log_learn_id_change('g', real, effective, fs);
54124 +
54125 + num = current->acl->group_trans_num;
54126 + gidlist = current->acl->group_transitions;
54127 +
54128 + if (gidlist == NULL)
54129 + return 0;
54130 +
54131 + if (real == -1)
54132 + realok = 1;
54133 + if (effective == -1)
54134 + effectiveok = 1;
54135 + if (fs == -1)
54136 + fsok = 1;
54137 +
54138 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
54139 + for (i = 0; i < num; i++) {
54140 + curgid = (int)gidlist[i];
54141 + if (real == curgid)
54142 + realok = 1;
54143 + if (effective == curgid)
54144 + effectiveok = 1;
54145 + if (fs == curgid)
54146 + fsok = 1;
54147 + }
54148 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
54149 + for (i = 0; i < num; i++) {
54150 + curgid = (int)gidlist[i];
54151 + if (real == curgid)
54152 + break;
54153 + if (effective == curgid)
54154 + break;
54155 + if (fs == curgid)
54156 + break;
54157 + }
54158 + /* not in deny list */
54159 + if (i == num) {
54160 + realok = 1;
54161 + effectiveok = 1;
54162 + fsok = 1;
54163 + }
54164 + }
54165 +
54166 + if (realok && effectiveok && fsok)
54167 + return 0;
54168 + else {
54169 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : fs) : effective) : real);
54170 + return 1;
54171 + }
54172 +}
54173 +
54174 +extern int gr_acl_is_capable(const int cap);
54175 +
54176 +void
54177 +gr_set_role_label(struct task_struct *task, const uid_t uid, const uid_t gid)
54178 +{
54179 + struct acl_role_label *role = task->role;
54180 + struct acl_subject_label *subj = NULL;
54181 + struct acl_object_label *obj;
54182 + struct file *filp;
54183 +
54184 + if (unlikely(!(gr_status & GR_READY)))
54185 + return;
54186 +
54187 + filp = task->exec_file;
54188 +
54189 + /* kernel process, we'll give them the kernel role */
54190 + if (unlikely(!filp)) {
54191 + task->role = kernel_role;
54192 + task->acl = kernel_role->root_label;
54193 + return;
54194 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL))
54195 + role = lookup_acl_role_label(task, uid, gid);
54196 +
54197 + /* don't change the role if we're not a privileged process */
54198 + if (role && task->role != role &&
54199 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
54200 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
54201 + return;
54202 +
54203 + /* perform subject lookup in possibly new role
54204 + we can use this result below in the case where role == task->role
54205 + */
54206 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
54207 +
54208 + /* if we changed uid/gid, but result in the same role
54209 + and are using inheritance, don't lose the inherited subject
54210 + if current subject is other than what normal lookup
54211 + would result in, we arrived via inheritance, don't
54212 + lose subject
54213 + */
54214 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
54215 + (subj == task->acl)))
54216 + task->acl = subj;
54217 +
54218 + task->role = role;
54219 +
54220 + task->is_writable = 0;
54221 +
54222 + /* ignore additional mmap checks for processes that are writable
54223 + by the default ACL */
54224 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54225 + if (unlikely(obj->mode & GR_WRITE))
54226 + task->is_writable = 1;
54227 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
54228 + if (unlikely(obj->mode & GR_WRITE))
54229 + task->is_writable = 1;
54230 +
54231 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54232 + printk(KERN_ALERT "Set role label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54233 +#endif
54234 +
54235 + gr_set_proc_res(task);
54236 +
54237 + return;
54238 +}
54239 +
54240 +int
54241 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
54242 + const int unsafe_flags)
54243 +{
54244 + struct task_struct *task = current;
54245 + struct acl_subject_label *newacl;
54246 + struct acl_object_label *obj;
54247 + __u32 retmode;
54248 +
54249 + if (unlikely(!(gr_status & GR_READY)))
54250 + return 0;
54251 +
54252 + newacl = chk_subj_label(dentry, mnt, task->role);
54253 +
54254 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
54255 + did an exec
54256 + */
54257 + rcu_read_lock();
54258 + read_lock(&tasklist_lock);
54259 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
54260 + (task->parent->acl->mode & GR_POVERRIDE))) {
54261 + read_unlock(&tasklist_lock);
54262 + rcu_read_unlock();
54263 + goto skip_check;
54264 + }
54265 + read_unlock(&tasklist_lock);
54266 + rcu_read_unlock();
54267 +
54268 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
54269 + !(task->role->roletype & GR_ROLE_GOD) &&
54270 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
54271 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
54272 + if (unsafe_flags & LSM_UNSAFE_SHARE)
54273 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
54274 + else
54275 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
54276 + return -EACCES;
54277 + }
54278 +
54279 +skip_check:
54280 +
54281 + obj = chk_obj_label(dentry, mnt, task->acl);
54282 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
54283 +
54284 + if (!(task->acl->mode & GR_INHERITLEARN) &&
54285 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
54286 + if (obj->nested)
54287 + task->acl = obj->nested;
54288 + else
54289 + task->acl = newacl;
54290 + } else if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
54291 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
54292 +
54293 + task->is_writable = 0;
54294 +
54295 + /* ignore additional mmap checks for processes that are writable
54296 + by the default ACL */
54297 + obj = chk_obj_label(dentry, mnt, default_role->root_label);
54298 + if (unlikely(obj->mode & GR_WRITE))
54299 + task->is_writable = 1;
54300 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
54301 + if (unlikely(obj->mode & GR_WRITE))
54302 + task->is_writable = 1;
54303 +
54304 + gr_set_proc_res(task);
54305 +
54306 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54307 + printk(KERN_ALERT "Set subject label for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
54308 +#endif
54309 + return 0;
54310 +}
54311 +
54312 +/* always called with valid inodev ptr */
54313 +static void
54314 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
54315 +{
54316 + struct acl_object_label *matchpo;
54317 + struct acl_subject_label *matchps;
54318 + struct acl_subject_label *subj;
54319 + struct acl_role_label *role;
54320 + unsigned int x;
54321 +
54322 + FOR_EACH_ROLE_START(role)
54323 + FOR_EACH_SUBJECT_START(role, subj, x)
54324 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
54325 + matchpo->mode |= GR_DELETED;
54326 + FOR_EACH_SUBJECT_END(subj,x)
54327 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54328 + if (subj->inode == ino && subj->device == dev)
54329 + subj->mode |= GR_DELETED;
54330 + FOR_EACH_NESTED_SUBJECT_END(subj)
54331 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
54332 + matchps->mode |= GR_DELETED;
54333 + FOR_EACH_ROLE_END(role)
54334 +
54335 + inodev->nentry->deleted = 1;
54336 +
54337 + return;
54338 +}
54339 +
54340 +void
54341 +gr_handle_delete(const ino_t ino, const dev_t dev)
54342 +{
54343 + struct inodev_entry *inodev;
54344 +
54345 + if (unlikely(!(gr_status & GR_READY)))
54346 + return;
54347 +
54348 + write_lock(&gr_inode_lock);
54349 + inodev = lookup_inodev_entry(ino, dev);
54350 + if (inodev != NULL)
54351 + do_handle_delete(inodev, ino, dev);
54352 + write_unlock(&gr_inode_lock);
54353 +
54354 + return;
54355 +}
54356 +
54357 +static void
54358 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
54359 + const ino_t newinode, const dev_t newdevice,
54360 + struct acl_subject_label *subj)
54361 +{
54362 + unsigned int index = fhash(oldinode, olddevice, subj->obj_hash_size);
54363 + struct acl_object_label *match;
54364 +
54365 + match = subj->obj_hash[index];
54366 +
54367 + while (match && (match->inode != oldinode ||
54368 + match->device != olddevice ||
54369 + !(match->mode & GR_DELETED)))
54370 + match = match->next;
54371 +
54372 + if (match && (match->inode == oldinode)
54373 + && (match->device == olddevice)
54374 + && (match->mode & GR_DELETED)) {
54375 + if (match->prev == NULL) {
54376 + subj->obj_hash[index] = match->next;
54377 + if (match->next != NULL)
54378 + match->next->prev = NULL;
54379 + } else {
54380 + match->prev->next = match->next;
54381 + if (match->next != NULL)
54382 + match->next->prev = match->prev;
54383 + }
54384 + match->prev = NULL;
54385 + match->next = NULL;
54386 + match->inode = newinode;
54387 + match->device = newdevice;
54388 + match->mode &= ~GR_DELETED;
54389 +
54390 + insert_acl_obj_label(match, subj);
54391 + }
54392 +
54393 + return;
54394 +}
54395 +
54396 +static void
54397 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
54398 + const ino_t newinode, const dev_t newdevice,
54399 + struct acl_role_label *role)
54400 +{
54401 + unsigned int index = fhash(oldinode, olddevice, role->subj_hash_size);
54402 + struct acl_subject_label *match;
54403 +
54404 + match = role->subj_hash[index];
54405 +
54406 + while (match && (match->inode != oldinode ||
54407 + match->device != olddevice ||
54408 + !(match->mode & GR_DELETED)))
54409 + match = match->next;
54410 +
54411 + if (match && (match->inode == oldinode)
54412 + && (match->device == olddevice)
54413 + && (match->mode & GR_DELETED)) {
54414 + if (match->prev == NULL) {
54415 + role->subj_hash[index] = match->next;
54416 + if (match->next != NULL)
54417 + match->next->prev = NULL;
54418 + } else {
54419 + match->prev->next = match->next;
54420 + if (match->next != NULL)
54421 + match->next->prev = match->prev;
54422 + }
54423 + match->prev = NULL;
54424 + match->next = NULL;
54425 + match->inode = newinode;
54426 + match->device = newdevice;
54427 + match->mode &= ~GR_DELETED;
54428 +
54429 + insert_acl_subj_label(match, role);
54430 + }
54431 +
54432 + return;
54433 +}
54434 +
54435 +static void
54436 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
54437 + const ino_t newinode, const dev_t newdevice)
54438 +{
54439 + unsigned int index = fhash(oldinode, olddevice, inodev_set.i_size);
54440 + struct inodev_entry *match;
54441 +
54442 + match = inodev_set.i_hash[index];
54443 +
54444 + while (match && (match->nentry->inode != oldinode ||
54445 + match->nentry->device != olddevice || !match->nentry->deleted))
54446 + match = match->next;
54447 +
54448 + if (match && (match->nentry->inode == oldinode)
54449 + && (match->nentry->device == olddevice) &&
54450 + match->nentry->deleted) {
54451 + if (match->prev == NULL) {
54452 + inodev_set.i_hash[index] = match->next;
54453 + if (match->next != NULL)
54454 + match->next->prev = NULL;
54455 + } else {
54456 + match->prev->next = match->next;
54457 + if (match->next != NULL)
54458 + match->next->prev = match->prev;
54459 + }
54460 + match->prev = NULL;
54461 + match->next = NULL;
54462 + match->nentry->inode = newinode;
54463 + match->nentry->device = newdevice;
54464 + match->nentry->deleted = 0;
54465 +
54466 + insert_inodev_entry(match);
54467 + }
54468 +
54469 + return;
54470 +}
54471 +
54472 +static void
54473 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
54474 +{
54475 + struct acl_subject_label *subj;
54476 + struct acl_role_label *role;
54477 + unsigned int x;
54478 +
54479 + FOR_EACH_ROLE_START(role)
54480 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
54481 +
54482 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
54483 + if ((subj->inode == ino) && (subj->device == dev)) {
54484 + subj->inode = ino;
54485 + subj->device = dev;
54486 + }
54487 + FOR_EACH_NESTED_SUBJECT_END(subj)
54488 + FOR_EACH_SUBJECT_START(role, subj, x)
54489 + update_acl_obj_label(matchn->inode, matchn->device,
54490 + ino, dev, subj);
54491 + FOR_EACH_SUBJECT_END(subj,x)
54492 + FOR_EACH_ROLE_END(role)
54493 +
54494 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
54495 +
54496 + return;
54497 +}
54498 +
54499 +static void
54500 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
54501 + const struct vfsmount *mnt)
54502 +{
54503 + ino_t ino = dentry->d_inode->i_ino;
54504 + dev_t dev = __get_dev(dentry);
54505 +
54506 + __do_handle_create(matchn, ino, dev);
54507 +
54508 + return;
54509 +}
54510 +
54511 +void
54512 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
54513 +{
54514 + struct name_entry *matchn;
54515 +
54516 + if (unlikely(!(gr_status & GR_READY)))
54517 + return;
54518 +
54519 + preempt_disable();
54520 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
54521 +
54522 + if (unlikely((unsigned long)matchn)) {
54523 + write_lock(&gr_inode_lock);
54524 + do_handle_create(matchn, dentry, mnt);
54525 + write_unlock(&gr_inode_lock);
54526 + }
54527 + preempt_enable();
54528 +
54529 + return;
54530 +}
54531 +
54532 +void
54533 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
54534 +{
54535 + struct name_entry *matchn;
54536 +
54537 + if (unlikely(!(gr_status & GR_READY)))
54538 + return;
54539 +
54540 + preempt_disable();
54541 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
54542 +
54543 + if (unlikely((unsigned long)matchn)) {
54544 + write_lock(&gr_inode_lock);
54545 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
54546 + write_unlock(&gr_inode_lock);
54547 + }
54548 + preempt_enable();
54549 +
54550 + return;
54551 +}
54552 +
54553 +void
54554 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
54555 + struct dentry *old_dentry,
54556 + struct dentry *new_dentry,
54557 + struct vfsmount *mnt, const __u8 replace)
54558 +{
54559 + struct name_entry *matchn;
54560 + struct inodev_entry *inodev;
54561 + struct inode *inode = new_dentry->d_inode;
54562 + ino_t old_ino = old_dentry->d_inode->i_ino;
54563 + dev_t old_dev = __get_dev(old_dentry);
54564 +
54565 + /* vfs_rename swaps the name and parent link for old_dentry and
54566 + new_dentry
54567 + at this point, old_dentry has the new name, parent link, and inode
54568 + for the renamed file
54569 + if a file is being replaced by a rename, new_dentry has the inode
54570 + and name for the replaced file
54571 + */
54572 +
54573 + if (unlikely(!(gr_status & GR_READY)))
54574 + return;
54575 +
54576 + preempt_disable();
54577 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
54578 +
54579 + /* we wouldn't have to check d_inode if it weren't for
54580 + NFS silly-renaming
54581 + */
54582 +
54583 + write_lock(&gr_inode_lock);
54584 + if (unlikely(replace && inode)) {
54585 + ino_t new_ino = inode->i_ino;
54586 + dev_t new_dev = __get_dev(new_dentry);
54587 +
54588 + inodev = lookup_inodev_entry(new_ino, new_dev);
54589 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
54590 + do_handle_delete(inodev, new_ino, new_dev);
54591 + }
54592 +
54593 + inodev = lookup_inodev_entry(old_ino, old_dev);
54594 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
54595 + do_handle_delete(inodev, old_ino, old_dev);
54596 +
54597 + if (unlikely((unsigned long)matchn))
54598 + do_handle_create(matchn, old_dentry, mnt);
54599 +
54600 + write_unlock(&gr_inode_lock);
54601 + preempt_enable();
54602 +
54603 + return;
54604 +}
54605 +
54606 +static int
54607 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
54608 + unsigned char **sum)
54609 +{
54610 + struct acl_role_label *r;
54611 + struct role_allowed_ip *ipp;
54612 + struct role_transition *trans;
54613 + unsigned int i;
54614 + int found = 0;
54615 + u32 curr_ip = current->signal->curr_ip;
54616 +
54617 + current->signal->saved_ip = curr_ip;
54618 +
54619 + /* check transition table */
54620 +
54621 + for (trans = current->role->transitions; trans; trans = trans->next) {
54622 + if (!strcmp(rolename, trans->rolename)) {
54623 + found = 1;
54624 + break;
54625 + }
54626 + }
54627 +
54628 + if (!found)
54629 + return 0;
54630 +
54631 + /* handle special roles that do not require authentication
54632 + and check ip */
54633 +
54634 + FOR_EACH_ROLE_START(r)
54635 + if (!strcmp(rolename, r->rolename) &&
54636 + (r->roletype & GR_ROLE_SPECIAL)) {
54637 + found = 0;
54638 + if (r->allowed_ips != NULL) {
54639 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
54640 + if ((ntohl(curr_ip) & ipp->netmask) ==
54641 + (ntohl(ipp->addr) & ipp->netmask))
54642 + found = 1;
54643 + }
54644 + } else
54645 + found = 2;
54646 + if (!found)
54647 + return 0;
54648 +
54649 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
54650 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
54651 + *salt = NULL;
54652 + *sum = NULL;
54653 + return 1;
54654 + }
54655 + }
54656 + FOR_EACH_ROLE_END(r)
54657 +
54658 + for (i = 0; i < num_sprole_pws; i++) {
54659 + if (!strcmp(rolename, acl_special_roles[i]->rolename)) {
54660 + *salt = acl_special_roles[i]->salt;
54661 + *sum = acl_special_roles[i]->sum;
54662 + return 1;
54663 + }
54664 + }
54665 +
54666 + return 0;
54667 +}
54668 +
54669 +static void
54670 +assign_special_role(char *rolename)
54671 +{
54672 + struct acl_object_label *obj;
54673 + struct acl_role_label *r;
54674 + struct acl_role_label *assigned = NULL;
54675 + struct task_struct *tsk;
54676 + struct file *filp;
54677 +
54678 + FOR_EACH_ROLE_START(r)
54679 + if (!strcmp(rolename, r->rolename) &&
54680 + (r->roletype & GR_ROLE_SPECIAL)) {
54681 + assigned = r;
54682 + break;
54683 + }
54684 + FOR_EACH_ROLE_END(r)
54685 +
54686 + if (!assigned)
54687 + return;
54688 +
54689 + read_lock(&tasklist_lock);
54690 + read_lock(&grsec_exec_file_lock);
54691 +
54692 + tsk = current->real_parent;
54693 + if (tsk == NULL)
54694 + goto out_unlock;
54695 +
54696 + filp = tsk->exec_file;
54697 + if (filp == NULL)
54698 + goto out_unlock;
54699 +
54700 + tsk->is_writable = 0;
54701 +
54702 + tsk->acl_sp_role = 1;
54703 + tsk->acl_role_id = ++acl_sp_role_value;
54704 + tsk->role = assigned;
54705 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
54706 +
54707 + /* ignore additional mmap checks for processes that are writable
54708 + by the default ACL */
54709 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
54710 + if (unlikely(obj->mode & GR_WRITE))
54711 + tsk->is_writable = 1;
54712 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
54713 + if (unlikely(obj->mode & GR_WRITE))
54714 + tsk->is_writable = 1;
54715 +
54716 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
54717 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename, tsk->acl->filename, tsk->comm, tsk->pid);
54718 +#endif
54719 +
54720 +out_unlock:
54721 + read_unlock(&grsec_exec_file_lock);
54722 + read_unlock(&tasklist_lock);
54723 + return;
54724 +}
54725 +
54726 +int gr_check_secure_terminal(struct task_struct *task)
54727 +{
54728 + struct task_struct *p, *p2, *p3;
54729 + struct files_struct *files;
54730 + struct fdtable *fdt;
54731 + struct file *our_file = NULL, *file;
54732 + int i;
54733 +
54734 + if (task->signal->tty == NULL)
54735 + return 1;
54736 +
54737 + files = get_files_struct(task);
54738 + if (files != NULL) {
54739 + rcu_read_lock();
54740 + fdt = files_fdtable(files);
54741 + for (i=0; i < fdt->max_fds; i++) {
54742 + file = fcheck_files(files, i);
54743 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
54744 + get_file(file);
54745 + our_file = file;
54746 + }
54747 + }
54748 + rcu_read_unlock();
54749 + put_files_struct(files);
54750 + }
54751 +
54752 + if (our_file == NULL)
54753 + return 1;
54754 +
54755 + read_lock(&tasklist_lock);
54756 + do_each_thread(p2, p) {
54757 + files = get_files_struct(p);
54758 + if (files == NULL ||
54759 + (p->signal && p->signal->tty == task->signal->tty)) {
54760 + if (files != NULL)
54761 + put_files_struct(files);
54762 + continue;
54763 + }
54764 + rcu_read_lock();
54765 + fdt = files_fdtable(files);
54766 + for (i=0; i < fdt->max_fds; i++) {
54767 + file = fcheck_files(files, i);
54768 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
54769 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
54770 + p3 = task;
54771 + while (p3->pid > 0) {
54772 + if (p3 == p)
54773 + break;
54774 + p3 = p3->real_parent;
54775 + }
54776 + if (p3 == p)
54777 + break;
54778 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
54779 + gr_handle_alertkill(p);
54780 + rcu_read_unlock();
54781 + put_files_struct(files);
54782 + read_unlock(&tasklist_lock);
54783 + fput(our_file);
54784 + return 0;
54785 + }
54786 + }
54787 + rcu_read_unlock();
54788 + put_files_struct(files);
54789 + } while_each_thread(p2, p);
54790 + read_unlock(&tasklist_lock);
54791 +
54792 + fput(our_file);
54793 + return 1;
54794 +}
54795 +
54796 +static int gr_rbac_disable(void *unused)
54797 +{
54798 + pax_open_kernel();
54799 + gr_status &= ~GR_READY;
54800 + pax_close_kernel();
54801 +
54802 + return 0;
54803 +}
54804 +
54805 +ssize_t
54806 +write_grsec_handler(struct file *file, const char * buf, size_t count, loff_t *ppos)
54807 +{
54808 + struct gr_arg_wrapper uwrap;
54809 + unsigned char *sprole_salt = NULL;
54810 + unsigned char *sprole_sum = NULL;
54811 + int error = sizeof (struct gr_arg_wrapper);
54812 + int error2 = 0;
54813 +
54814 + mutex_lock(&gr_dev_mutex);
54815 +
54816 + if ((gr_status & GR_READY) && !(current->acl->mode & GR_KERNELAUTH)) {
54817 + error = -EPERM;
54818 + goto out;
54819 + }
54820 +
54821 + if (count != sizeof (struct gr_arg_wrapper)) {
54822 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)sizeof(struct gr_arg_wrapper));
54823 + error = -EINVAL;
54824 + goto out;
54825 + }
54826 +
54827 +
54828 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
54829 + gr_auth_expires = 0;
54830 + gr_auth_attempts = 0;
54831 + }
54832 +
54833 + if (copy_from_user(&uwrap, buf, sizeof (struct gr_arg_wrapper))) {
54834 + error = -EFAULT;
54835 + goto out;
54836 + }
54837 +
54838 + if ((uwrap.version != GRSECURITY_VERSION) || (uwrap.size != sizeof(struct gr_arg))) {
54839 + error = -EINVAL;
54840 + goto out;
54841 + }
54842 +
54843 + if (copy_from_user(gr_usermode, uwrap.arg, sizeof (struct gr_arg))) {
54844 + error = -EFAULT;
54845 + goto out;
54846 + }
54847 +
54848 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54849 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54850 + time_after(gr_auth_expires, get_seconds())) {
54851 + error = -EBUSY;
54852 + goto out;
54853 + }
54854 +
54855 + /* if non-root trying to do anything other than use a special role,
54856 + do not attempt authentication, do not count towards authentication
54857 + locking
54858 + */
54859 +
54860 + if (gr_usermode->mode != GR_SPROLE && gr_usermode->mode != GR_STATUS &&
54861 + gr_usermode->mode != GR_UNSPROLE && gr_usermode->mode != GR_SPROLEPAM &&
54862 + !uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
54863 + error = -EPERM;
54864 + goto out;
54865 + }
54866 +
54867 + /* ensure pw and special role name are null terminated */
54868 +
54869 + gr_usermode->pw[GR_PW_LEN - 1] = '\0';
54870 + gr_usermode->sp_role[GR_SPROLE_LEN - 1] = '\0';
54871 +
54872 + /* Okay.
54873 + * We have our enough of the argument structure..(we have yet
54874 + * to copy_from_user the tables themselves) . Copy the tables
54875 + * only if we need them, i.e. for loading operations. */
54876 +
54877 + switch (gr_usermode->mode) {
54878 + case GR_STATUS:
54879 + if (gr_status & GR_READY) {
54880 + error = 1;
54881 + if (!gr_check_secure_terminal(current))
54882 + error = 3;
54883 + } else
54884 + error = 2;
54885 + goto out;
54886 + case GR_SHUTDOWN:
54887 + if ((gr_status & GR_READY)
54888 + && !(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54889 + stop_machine(gr_rbac_disable, NULL, NULL);
54890 + free_variables();
54891 + memset(gr_usermode, 0, sizeof (struct gr_arg));
54892 + memset(gr_system_salt, 0, GR_SALT_LEN);
54893 + memset(gr_system_sum, 0, GR_SHA_LEN);
54894 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
54895 + } else if (gr_status & GR_READY) {
54896 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
54897 + error = -EPERM;
54898 + } else {
54899 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
54900 + error = -EAGAIN;
54901 + }
54902 + break;
54903 + case GR_ENABLE:
54904 + if (!(gr_status & GR_READY) && !(error2 = gracl_init(gr_usermode)))
54905 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
54906 + else {
54907 + if (gr_status & GR_READY)
54908 + error = -EAGAIN;
54909 + else
54910 + error = error2;
54911 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
54912 + }
54913 + break;
54914 + case GR_RELOAD:
54915 + if (!(gr_status & GR_READY)) {
54916 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
54917 + error = -EAGAIN;
54918 + } else if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54919 + stop_machine(gr_rbac_disable, NULL, NULL);
54920 + free_variables();
54921 + error2 = gracl_init(gr_usermode);
54922 + if (!error2)
54923 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
54924 + else {
54925 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54926 + error = error2;
54927 + }
54928 + } else {
54929 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
54930 + error = -EPERM;
54931 + }
54932 + break;
54933 + case GR_SEGVMOD:
54934 + if (unlikely(!(gr_status & GR_READY))) {
54935 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
54936 + error = -EAGAIN;
54937 + break;
54938 + }
54939 +
54940 + if (!(chkpw(gr_usermode, gr_system_salt, gr_system_sum))) {
54941 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
54942 + if (gr_usermode->segv_device && gr_usermode->segv_inode) {
54943 + struct acl_subject_label *segvacl;
54944 + segvacl =
54945 + lookup_acl_subj_label(gr_usermode->segv_inode,
54946 + gr_usermode->segv_device,
54947 + current->role);
54948 + if (segvacl) {
54949 + segvacl->crashes = 0;
54950 + segvacl->expires = 0;
54951 + }
54952 + } else if (gr_find_uid(gr_usermode->segv_uid) >= 0) {
54953 + gr_remove_uid(gr_usermode->segv_uid);
54954 + }
54955 + } else {
54956 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
54957 + error = -EPERM;
54958 + }
54959 + break;
54960 + case GR_SPROLE:
54961 + case GR_SPROLEPAM:
54962 + if (unlikely(!(gr_status & GR_READY))) {
54963 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
54964 + error = -EAGAIN;
54965 + break;
54966 + }
54967 +
54968 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
54969 + current->role->expires = 0;
54970 + current->role->auth_attempts = 0;
54971 + }
54972 +
54973 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
54974 + time_after(current->role->expires, get_seconds())) {
54975 + error = -EBUSY;
54976 + goto out;
54977 + }
54978 +
54979 + if (lookup_special_role_auth
54980 + (gr_usermode->mode, gr_usermode->sp_role, &sprole_salt, &sprole_sum)
54981 + && ((!sprole_salt && !sprole_sum)
54982 + || !(chkpw(gr_usermode, sprole_salt, sprole_sum)))) {
54983 + char *p = "";
54984 + assign_special_role(gr_usermode->sp_role);
54985 + read_lock(&tasklist_lock);
54986 + if (current->real_parent)
54987 + p = current->real_parent->role->rolename;
54988 + read_unlock(&tasklist_lock);
54989 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
54990 + p, acl_sp_role_value);
54991 + } else {
54992 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode->sp_role);
54993 + error = -EPERM;
54994 + if(!(current->role->auth_attempts++))
54995 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
54996 +
54997 + goto out;
54998 + }
54999 + break;
55000 + case GR_UNSPROLE:
55001 + if (unlikely(!(gr_status & GR_READY))) {
55002 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
55003 + error = -EAGAIN;
55004 + break;
55005 + }
55006 +
55007 + if (current->role->roletype & GR_ROLE_SPECIAL) {
55008 + char *p = "";
55009 + int i = 0;
55010 +
55011 + read_lock(&tasklist_lock);
55012 + if (current->real_parent) {
55013 + p = current->real_parent->role->rolename;
55014 + i = current->real_parent->acl_role_id;
55015 + }
55016 + read_unlock(&tasklist_lock);
55017 +
55018 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
55019 + gr_set_acls(1);
55020 + } else {
55021 + error = -EPERM;
55022 + goto out;
55023 + }
55024 + break;
55025 + default:
55026 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode->mode);
55027 + error = -EINVAL;
55028 + break;
55029 + }
55030 +
55031 + if (error != -EPERM)
55032 + goto out;
55033 +
55034 + if(!(gr_auth_attempts++))
55035 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
55036 +
55037 + out:
55038 + mutex_unlock(&gr_dev_mutex);
55039 + return error;
55040 +}
55041 +
55042 +/* must be called with
55043 + rcu_read_lock();
55044 + read_lock(&tasklist_lock);
55045 + read_lock(&grsec_exec_file_lock);
55046 +*/
55047 +int gr_apply_subject_to_task(struct task_struct *task)
55048 +{
55049 + struct acl_object_label *obj;
55050 + char *tmpname;
55051 + struct acl_subject_label *tmpsubj;
55052 + struct file *filp;
55053 + struct name_entry *nmatch;
55054 +
55055 + filp = task->exec_file;
55056 + if (filp == NULL)
55057 + return 0;
55058 +
55059 + /* the following is to apply the correct subject
55060 + on binaries running when the RBAC system
55061 + is enabled, when the binaries have been
55062 + replaced or deleted since their execution
55063 + -----
55064 + when the RBAC system starts, the inode/dev
55065 + from exec_file will be one the RBAC system
55066 + is unaware of. It only knows the inode/dev
55067 + of the present file on disk, or the absence
55068 + of it.
55069 + */
55070 + preempt_disable();
55071 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
55072 +
55073 + nmatch = lookup_name_entry(tmpname);
55074 + preempt_enable();
55075 + tmpsubj = NULL;
55076 + if (nmatch) {
55077 + if (nmatch->deleted)
55078 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
55079 + else
55080 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
55081 + if (tmpsubj != NULL)
55082 + task->acl = tmpsubj;
55083 + }
55084 + if (tmpsubj == NULL)
55085 + task->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt,
55086 + task->role);
55087 + if (task->acl) {
55088 + task->is_writable = 0;
55089 + /* ignore additional mmap checks for processes that are writable
55090 + by the default ACL */
55091 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55092 + if (unlikely(obj->mode & GR_WRITE))
55093 + task->is_writable = 1;
55094 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
55095 + if (unlikely(obj->mode & GR_WRITE))
55096 + task->is_writable = 1;
55097 +
55098 + gr_set_proc_res(task);
55099 +
55100 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
55101 + printk(KERN_ALERT "gr_set_acls for (%s:%d): role:%s, subject:%s\n", task->comm, task->pid, task->role->rolename, task->acl->filename);
55102 +#endif
55103 + } else {
55104 + return 1;
55105 + }
55106 +
55107 + return 0;
55108 +}
55109 +
55110 +int
55111 +gr_set_acls(const int type)
55112 +{
55113 + struct task_struct *task, *task2;
55114 + struct acl_role_label *role = current->role;
55115 + __u16 acl_role_id = current->acl_role_id;
55116 + const struct cred *cred;
55117 + int ret;
55118 +
55119 + rcu_read_lock();
55120 + read_lock(&tasklist_lock);
55121 + read_lock(&grsec_exec_file_lock);
55122 + do_each_thread(task2, task) {
55123 + /* check to see if we're called from the exit handler,
55124 + if so, only replace ACLs that have inherited the admin
55125 + ACL */
55126 +
55127 + if (type && (task->role != role ||
55128 + task->acl_role_id != acl_role_id))
55129 + continue;
55130 +
55131 + task->acl_role_id = 0;
55132 + task->acl_sp_role = 0;
55133 +
55134 + if (task->exec_file) {
55135 + cred = __task_cred(task);
55136 + task->role = lookup_acl_role_label(task, cred->uid, cred->gid);
55137 + ret = gr_apply_subject_to_task(task);
55138 + if (ret) {
55139 + read_unlock(&grsec_exec_file_lock);
55140 + read_unlock(&tasklist_lock);
55141 + rcu_read_unlock();
55142 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task->pid);
55143 + return ret;
55144 + }
55145 + } else {
55146 + // it's a kernel process
55147 + task->role = kernel_role;
55148 + task->acl = kernel_role->root_label;
55149 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
55150 + task->acl->mode &= ~GR_PROCFIND;
55151 +#endif
55152 + }
55153 + } while_each_thread(task2, task);
55154 + read_unlock(&grsec_exec_file_lock);
55155 + read_unlock(&tasklist_lock);
55156 + rcu_read_unlock();
55157 +
55158 + return 0;
55159 +}
55160 +
55161 +void
55162 +gr_learn_resource(const struct task_struct *task,
55163 + const int res, const unsigned long wanted, const int gt)
55164 +{
55165 + struct acl_subject_label *acl;
55166 + const struct cred *cred;
55167 +
55168 + if (unlikely((gr_status & GR_READY) &&
55169 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
55170 + goto skip_reslog;
55171 +
55172 +#ifdef CONFIG_GRKERNSEC_RESLOG
55173 + gr_log_resource(task, res, wanted, gt);
55174 +#endif
55175 + skip_reslog:
55176 +
55177 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
55178 + return;
55179 +
55180 + acl = task->acl;
55181 +
55182 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
55183 + !(acl->resmask & (1 << (unsigned short) res))))
55184 + return;
55185 +
55186 + if (wanted >= acl->res[res].rlim_cur) {
55187 + unsigned long res_add;
55188 +
55189 + res_add = wanted;
55190 + switch (res) {
55191 + case RLIMIT_CPU:
55192 + res_add += GR_RLIM_CPU_BUMP;
55193 + break;
55194 + case RLIMIT_FSIZE:
55195 + res_add += GR_RLIM_FSIZE_BUMP;
55196 + break;
55197 + case RLIMIT_DATA:
55198 + res_add += GR_RLIM_DATA_BUMP;
55199 + break;
55200 + case RLIMIT_STACK:
55201 + res_add += GR_RLIM_STACK_BUMP;
55202 + break;
55203 + case RLIMIT_CORE:
55204 + res_add += GR_RLIM_CORE_BUMP;
55205 + break;
55206 + case RLIMIT_RSS:
55207 + res_add += GR_RLIM_RSS_BUMP;
55208 + break;
55209 + case RLIMIT_NPROC:
55210 + res_add += GR_RLIM_NPROC_BUMP;
55211 + break;
55212 + case RLIMIT_NOFILE:
55213 + res_add += GR_RLIM_NOFILE_BUMP;
55214 + break;
55215 + case RLIMIT_MEMLOCK:
55216 + res_add += GR_RLIM_MEMLOCK_BUMP;
55217 + break;
55218 + case RLIMIT_AS:
55219 + res_add += GR_RLIM_AS_BUMP;
55220 + break;
55221 + case RLIMIT_LOCKS:
55222 + res_add += GR_RLIM_LOCKS_BUMP;
55223 + break;
55224 + case RLIMIT_SIGPENDING:
55225 + res_add += GR_RLIM_SIGPENDING_BUMP;
55226 + break;
55227 + case RLIMIT_MSGQUEUE:
55228 + res_add += GR_RLIM_MSGQUEUE_BUMP;
55229 + break;
55230 + case RLIMIT_NICE:
55231 + res_add += GR_RLIM_NICE_BUMP;
55232 + break;
55233 + case RLIMIT_RTPRIO:
55234 + res_add += GR_RLIM_RTPRIO_BUMP;
55235 + break;
55236 + case RLIMIT_RTTIME:
55237 + res_add += GR_RLIM_RTTIME_BUMP;
55238 + break;
55239 + }
55240 +
55241 + acl->res[res].rlim_cur = res_add;
55242 +
55243 + if (wanted > acl->res[res].rlim_max)
55244 + acl->res[res].rlim_max = res_add;
55245 +
55246 + /* only log the subject filename, since resource logging is supported for
55247 + single-subject learning only */
55248 + rcu_read_lock();
55249 + cred = __task_cred(task);
55250 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55251 + task->role->roletype, cred->uid, cred->gid, acl->filename,
55252 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
55253 + "", (unsigned long) res, &task->signal->saved_ip);
55254 + rcu_read_unlock();
55255 + }
55256 +
55257 + return;
55258 +}
55259 +
55260 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
55261 +void
55262 +pax_set_initial_flags(struct linux_binprm *bprm)
55263 +{
55264 + struct task_struct *task = current;
55265 + struct acl_subject_label *proc;
55266 + unsigned long flags;
55267 +
55268 + if (unlikely(!(gr_status & GR_READY)))
55269 + return;
55270 +
55271 + flags = pax_get_flags(task);
55272 +
55273 + proc = task->acl;
55274 +
55275 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
55276 + flags &= ~MF_PAX_PAGEEXEC;
55277 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
55278 + flags &= ~MF_PAX_SEGMEXEC;
55279 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
55280 + flags &= ~MF_PAX_RANDMMAP;
55281 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
55282 + flags &= ~MF_PAX_EMUTRAMP;
55283 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
55284 + flags &= ~MF_PAX_MPROTECT;
55285 +
55286 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
55287 + flags |= MF_PAX_PAGEEXEC;
55288 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
55289 + flags |= MF_PAX_SEGMEXEC;
55290 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
55291 + flags |= MF_PAX_RANDMMAP;
55292 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
55293 + flags |= MF_PAX_EMUTRAMP;
55294 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
55295 + flags |= MF_PAX_MPROTECT;
55296 +
55297 + pax_set_flags(task, flags);
55298 +
55299 + return;
55300 +}
55301 +#endif
55302 +
55303 +int
55304 +gr_handle_proc_ptrace(struct task_struct *task)
55305 +{
55306 + struct file *filp;
55307 + struct task_struct *tmp = task;
55308 + struct task_struct *curtemp = current;
55309 + __u32 retmode;
55310 +
55311 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55312 + if (unlikely(!(gr_status & GR_READY)))
55313 + return 0;
55314 +#endif
55315 +
55316 + read_lock(&tasklist_lock);
55317 + read_lock(&grsec_exec_file_lock);
55318 + filp = task->exec_file;
55319 +
55320 + while (tmp->pid > 0) {
55321 + if (tmp == curtemp)
55322 + break;
55323 + tmp = tmp->real_parent;
55324 + }
55325 +
55326 + if (!filp || (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55327 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
55328 + read_unlock(&grsec_exec_file_lock);
55329 + read_unlock(&tasklist_lock);
55330 + return 1;
55331 + }
55332 +
55333 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55334 + if (!(gr_status & GR_READY)) {
55335 + read_unlock(&grsec_exec_file_lock);
55336 + read_unlock(&tasklist_lock);
55337 + return 0;
55338 + }
55339 +#endif
55340 +
55341 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
55342 + read_unlock(&grsec_exec_file_lock);
55343 + read_unlock(&tasklist_lock);
55344 +
55345 + if (retmode & GR_NOPTRACE)
55346 + return 1;
55347 +
55348 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
55349 + && (current->acl != task->acl || (current->acl != current->role->root_label
55350 + && current->pid != task->pid)))
55351 + return 1;
55352 +
55353 + return 0;
55354 +}
55355 +
55356 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
55357 +{
55358 + if (unlikely(!(gr_status & GR_READY)))
55359 + return;
55360 +
55361 + if (!(current->role->roletype & GR_ROLE_GOD))
55362 + return;
55363 +
55364 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
55365 + p->role->rolename, gr_task_roletype_to_char(p),
55366 + p->acl->filename);
55367 +}
55368 +
55369 +int
55370 +gr_handle_ptrace(struct task_struct *task, const long request)
55371 +{
55372 + struct task_struct *tmp = task;
55373 + struct task_struct *curtemp = current;
55374 + __u32 retmode;
55375 +
55376 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
55377 + if (unlikely(!(gr_status & GR_READY)))
55378 + return 0;
55379 +#endif
55380 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
55381 + read_lock(&tasklist_lock);
55382 + while (tmp->pid > 0) {
55383 + if (tmp == curtemp)
55384 + break;
55385 + tmp = tmp->real_parent;
55386 + }
55387 +
55388 + if (tmp->pid == 0 && ((grsec_enable_harden_ptrace && !uid_eq(current_uid(), GLOBAL_ROOT_UID) && !(gr_status & GR_READY)) ||
55389 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
55390 + read_unlock(&tasklist_lock);
55391 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55392 + return 1;
55393 + }
55394 + read_unlock(&tasklist_lock);
55395 + }
55396 +
55397 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
55398 + if (!(gr_status & GR_READY))
55399 + return 0;
55400 +#endif
55401 +
55402 + read_lock(&grsec_exec_file_lock);
55403 + if (unlikely(!task->exec_file)) {
55404 + read_unlock(&grsec_exec_file_lock);
55405 + return 0;
55406 + }
55407 +
55408 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
55409 + read_unlock(&grsec_exec_file_lock);
55410 +
55411 + if (retmode & GR_NOPTRACE) {
55412 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55413 + return 1;
55414 + }
55415 +
55416 + if (retmode & GR_PTRACERD) {
55417 + switch (request) {
55418 + case PTRACE_SEIZE:
55419 + case PTRACE_POKETEXT:
55420 + case PTRACE_POKEDATA:
55421 + case PTRACE_POKEUSR:
55422 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
55423 + case PTRACE_SETREGS:
55424 + case PTRACE_SETFPREGS:
55425 +#endif
55426 +#ifdef CONFIG_X86
55427 + case PTRACE_SETFPXREGS:
55428 +#endif
55429 +#ifdef CONFIG_ALTIVEC
55430 + case PTRACE_SETVRREGS:
55431 +#endif
55432 + return 1;
55433 + default:
55434 + return 0;
55435 + }
55436 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
55437 + !(current->role->roletype & GR_ROLE_GOD) &&
55438 + (current->acl != task->acl)) {
55439 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
55440 + return 1;
55441 + }
55442 +
55443 + return 0;
55444 +}
55445 +
55446 +static int is_writable_mmap(const struct file *filp)
55447 +{
55448 + struct task_struct *task = current;
55449 + struct acl_object_label *obj, *obj2;
55450 +
55451 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
55452 + !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))) {
55453 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, default_role->root_label);
55454 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
55455 + task->role->root_label);
55456 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
55457 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
55458 + return 1;
55459 + }
55460 + }
55461 + return 0;
55462 +}
55463 +
55464 +int
55465 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
55466 +{
55467 + __u32 mode;
55468 +
55469 + if (unlikely(!file || !(prot & PROT_EXEC)))
55470 + return 1;
55471 +
55472 + if (is_writable_mmap(file))
55473 + return 0;
55474 +
55475 + mode =
55476 + gr_search_file(file->f_path.dentry,
55477 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55478 + file->f_path.mnt);
55479 +
55480 + if (!gr_tpe_allow(file))
55481 + return 0;
55482 +
55483 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55484 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55485 + return 0;
55486 + } else if (unlikely(!(mode & GR_EXEC))) {
55487 + return 0;
55488 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55489 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55490 + return 1;
55491 + }
55492 +
55493 + return 1;
55494 +}
55495 +
55496 +int
55497 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
55498 +{
55499 + __u32 mode;
55500 +
55501 + if (unlikely(!file || !(prot & PROT_EXEC)))
55502 + return 1;
55503 +
55504 + if (is_writable_mmap(file))
55505 + return 0;
55506 +
55507 + mode =
55508 + gr_search_file(file->f_path.dentry,
55509 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
55510 + file->f_path.mnt);
55511 +
55512 + if (!gr_tpe_allow(file))
55513 + return 0;
55514 +
55515 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
55516 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55517 + return 0;
55518 + } else if (unlikely(!(mode & GR_EXEC))) {
55519 + return 0;
55520 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
55521 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
55522 + return 1;
55523 + }
55524 +
55525 + return 1;
55526 +}
55527 +
55528 +void
55529 +gr_acl_handle_psacct(struct task_struct *task, const long code)
55530 +{
55531 + unsigned long runtime;
55532 + unsigned long cputime;
55533 + unsigned int wday, cday;
55534 + __u8 whr, chr;
55535 + __u8 wmin, cmin;
55536 + __u8 wsec, csec;
55537 + struct timespec timeval;
55538 +
55539 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
55540 + !(task->acl->mode & GR_PROCACCT)))
55541 + return;
55542 +
55543 + do_posix_clock_monotonic_gettime(&timeval);
55544 + runtime = timeval.tv_sec - task->start_time.tv_sec;
55545 + wday = runtime / (3600 * 24);
55546 + runtime -= wday * (3600 * 24);
55547 + whr = runtime / 3600;
55548 + runtime -= whr * 3600;
55549 + wmin = runtime / 60;
55550 + runtime -= wmin * 60;
55551 + wsec = runtime;
55552 +
55553 + cputime = (task->utime + task->stime) / HZ;
55554 + cday = cputime / (3600 * 24);
55555 + cputime -= cday * (3600 * 24);
55556 + chr = cputime / 3600;
55557 + cputime -= chr * 3600;
55558 + cmin = cputime / 60;
55559 + cputime -= cmin * 60;
55560 + csec = cputime;
55561 +
55562 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
55563 +
55564 + return;
55565 +}
55566 +
55567 +void gr_set_kernel_label(struct task_struct *task)
55568 +{
55569 + if (gr_status & GR_READY) {
55570 + task->role = kernel_role;
55571 + task->acl = kernel_role->root_label;
55572 + }
55573 + return;
55574 +}
55575 +
55576 +#ifdef CONFIG_TASKSTATS
55577 +int gr_is_taskstats_denied(int pid)
55578 +{
55579 + struct task_struct *task;
55580 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55581 + const struct cred *cred;
55582 +#endif
55583 + int ret = 0;
55584 +
55585 + /* restrict taskstats viewing to un-chrooted root users
55586 + who have the 'view' subject flag if the RBAC system is enabled
55587 + */
55588 +
55589 + rcu_read_lock();
55590 + read_lock(&tasklist_lock);
55591 + task = find_task_by_vpid(pid);
55592 + if (task) {
55593 +#ifdef CONFIG_GRKERNSEC_CHROOT
55594 + if (proc_is_chrooted(task))
55595 + ret = -EACCES;
55596 +#endif
55597 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55598 + cred = __task_cred(task);
55599 +#ifdef CONFIG_GRKERNSEC_PROC_USER
55600 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID))
55601 + ret = -EACCES;
55602 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
55603 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && !groups_search(cred->group_info, grsec_proc_gid))
55604 + ret = -EACCES;
55605 +#endif
55606 +#endif
55607 + if (gr_status & GR_READY) {
55608 + if (!(task->acl->mode & GR_VIEW))
55609 + ret = -EACCES;
55610 + }
55611 + } else
55612 + ret = -ENOENT;
55613 +
55614 + read_unlock(&tasklist_lock);
55615 + rcu_read_unlock();
55616 +
55617 + return ret;
55618 +}
55619 +#endif
55620 +
55621 +/* AUXV entries are filled via a descendant of search_binary_handler
55622 + after we've already applied the subject for the target
55623 +*/
55624 +int gr_acl_enable_at_secure(void)
55625 +{
55626 + if (unlikely(!(gr_status & GR_READY)))
55627 + return 0;
55628 +
55629 + if (current->acl->mode & GR_ATSECURE)
55630 + return 1;
55631 +
55632 + return 0;
55633 +}
55634 +
55635 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
55636 +{
55637 + struct task_struct *task = current;
55638 + struct dentry *dentry = file->f_path.dentry;
55639 + struct vfsmount *mnt = file->f_path.mnt;
55640 + struct acl_object_label *obj, *tmp;
55641 + struct acl_subject_label *subj;
55642 + unsigned int bufsize;
55643 + int is_not_root;
55644 + char *path;
55645 + dev_t dev = __get_dev(dentry);
55646 +
55647 + if (unlikely(!(gr_status & GR_READY)))
55648 + return 1;
55649 +
55650 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
55651 + return 1;
55652 +
55653 + /* ignore Eric Biederman */
55654 + if (IS_PRIVATE(dentry->d_inode))
55655 + return 1;
55656 +
55657 + subj = task->acl;
55658 + read_lock(&gr_inode_lock);
55659 + do {
55660 + obj = lookup_acl_obj_label(ino, dev, subj);
55661 + if (obj != NULL) {
55662 + read_unlock(&gr_inode_lock);
55663 + return (obj->mode & GR_FIND) ? 1 : 0;
55664 + }
55665 + } while ((subj = subj->parent_subject));
55666 + read_unlock(&gr_inode_lock);
55667 +
55668 + /* this is purely an optimization since we're looking for an object
55669 + for the directory we're doing a readdir on
55670 + if it's possible for any globbed object to match the entry we're
55671 + filling into the directory, then the object we find here will be
55672 + an anchor point with attached globbed objects
55673 + */
55674 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
55675 + if (obj->globbed == NULL)
55676 + return (obj->mode & GR_FIND) ? 1 : 0;
55677 +
55678 + is_not_root = ((obj->filename[0] == '/') &&
55679 + (obj->filename[1] == '\0')) ? 0 : 1;
55680 + bufsize = PAGE_SIZE - namelen - is_not_root;
55681 +
55682 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
55683 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
55684 + return 1;
55685 +
55686 + preempt_disable();
55687 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
55688 + bufsize);
55689 +
55690 + bufsize = strlen(path);
55691 +
55692 + /* if base is "/", don't append an additional slash */
55693 + if (is_not_root)
55694 + *(path + bufsize) = '/';
55695 + memcpy(path + bufsize + is_not_root, name, namelen);
55696 + *(path + bufsize + namelen + is_not_root) = '\0';
55697 +
55698 + tmp = obj->globbed;
55699 + while (tmp) {
55700 + if (!glob_match(tmp->filename, path)) {
55701 + preempt_enable();
55702 + return (tmp->mode & GR_FIND) ? 1 : 0;
55703 + }
55704 + tmp = tmp->next;
55705 + }
55706 + preempt_enable();
55707 + return (obj->mode & GR_FIND) ? 1 : 0;
55708 +}
55709 +
55710 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
55711 +EXPORT_SYMBOL(gr_acl_is_enabled);
55712 +#endif
55713 +EXPORT_SYMBOL(gr_learn_resource);
55714 +EXPORT_SYMBOL(gr_set_kernel_label);
55715 +#ifdef CONFIG_SECURITY
55716 +EXPORT_SYMBOL(gr_check_user_change);
55717 +EXPORT_SYMBOL(gr_check_group_change);
55718 +#endif
55719 +
55720 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
55721 new file mode 100644
55722 index 0000000..34fefda
55723 --- /dev/null
55724 +++ b/grsecurity/gracl_alloc.c
55725 @@ -0,0 +1,105 @@
55726 +#include <linux/kernel.h>
55727 +#include <linux/mm.h>
55728 +#include <linux/slab.h>
55729 +#include <linux/vmalloc.h>
55730 +#include <linux/gracl.h>
55731 +#include <linux/grsecurity.h>
55732 +
55733 +static unsigned long alloc_stack_next = 1;
55734 +static unsigned long alloc_stack_size = 1;
55735 +static void **alloc_stack;
55736 +
55737 +static __inline__ int
55738 +alloc_pop(void)
55739 +{
55740 + if (alloc_stack_next == 1)
55741 + return 0;
55742 +
55743 + kfree(alloc_stack[alloc_stack_next - 2]);
55744 +
55745 + alloc_stack_next--;
55746 +
55747 + return 1;
55748 +}
55749 +
55750 +static __inline__ int
55751 +alloc_push(void *buf)
55752 +{
55753 + if (alloc_stack_next >= alloc_stack_size)
55754 + return 1;
55755 +
55756 + alloc_stack[alloc_stack_next - 1] = buf;
55757 +
55758 + alloc_stack_next++;
55759 +
55760 + return 0;
55761 +}
55762 +
55763 +void *
55764 +acl_alloc(unsigned long len)
55765 +{
55766 + void *ret = NULL;
55767 +
55768 + if (!len || len > PAGE_SIZE)
55769 + goto out;
55770 +
55771 + ret = kmalloc(len, GFP_KERNEL);
55772 +
55773 + if (ret) {
55774 + if (alloc_push(ret)) {
55775 + kfree(ret);
55776 + ret = NULL;
55777 + }
55778 + }
55779 +
55780 +out:
55781 + return ret;
55782 +}
55783 +
55784 +void *
55785 +acl_alloc_num(unsigned long num, unsigned long len)
55786 +{
55787 + if (!len || (num > (PAGE_SIZE / len)))
55788 + return NULL;
55789 +
55790 + return acl_alloc(num * len);
55791 +}
55792 +
55793 +void
55794 +acl_free_all(void)
55795 +{
55796 + if (gr_acl_is_enabled() || !alloc_stack)
55797 + return;
55798 +
55799 + while (alloc_pop()) ;
55800 +
55801 + if (alloc_stack) {
55802 + if ((alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
55803 + kfree(alloc_stack);
55804 + else
55805 + vfree(alloc_stack);
55806 + }
55807 +
55808 + alloc_stack = NULL;
55809 + alloc_stack_size = 1;
55810 + alloc_stack_next = 1;
55811 +
55812 + return;
55813 +}
55814 +
55815 +int
55816 +acl_alloc_stack_init(unsigned long size)
55817 +{
55818 + if ((size * sizeof (void *)) <= PAGE_SIZE)
55819 + alloc_stack =
55820 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
55821 + else
55822 + alloc_stack = (void **) vmalloc(size * sizeof (void *));
55823 +
55824 + alloc_stack_size = size;
55825 +
55826 + if (!alloc_stack)
55827 + return 0;
55828 + else
55829 + return 1;
55830 +}
55831 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
55832 new file mode 100644
55833 index 0000000..6d21049
55834 --- /dev/null
55835 +++ b/grsecurity/gracl_cap.c
55836 @@ -0,0 +1,110 @@
55837 +#include <linux/kernel.h>
55838 +#include <linux/module.h>
55839 +#include <linux/sched.h>
55840 +#include <linux/gracl.h>
55841 +#include <linux/grsecurity.h>
55842 +#include <linux/grinternal.h>
55843 +
55844 +extern const char *captab_log[];
55845 +extern int captab_log_entries;
55846 +
55847 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
55848 +{
55849 + struct acl_subject_label *curracl;
55850 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55851 + kernel_cap_t cap_audit = __cap_empty_set;
55852 +
55853 + if (!gr_acl_is_enabled())
55854 + return 1;
55855 +
55856 + curracl = task->acl;
55857 +
55858 + cap_drop = curracl->cap_lower;
55859 + cap_mask = curracl->cap_mask;
55860 + cap_audit = curracl->cap_invert_audit;
55861 +
55862 + while ((curracl = curracl->parent_subject)) {
55863 + /* if the cap isn't specified in the current computed mask but is specified in the
55864 + current level subject, and is lowered in the current level subject, then add
55865 + it to the set of dropped capabilities
55866 + otherwise, add the current level subject's mask to the current computed mask
55867 + */
55868 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55869 + cap_raise(cap_mask, cap);
55870 + if (cap_raised(curracl->cap_lower, cap))
55871 + cap_raise(cap_drop, cap);
55872 + if (cap_raised(curracl->cap_invert_audit, cap))
55873 + cap_raise(cap_audit, cap);
55874 + }
55875 + }
55876 +
55877 + if (!cap_raised(cap_drop, cap)) {
55878 + if (cap_raised(cap_audit, cap))
55879 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
55880 + return 1;
55881 + }
55882 +
55883 + curracl = task->acl;
55884 +
55885 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
55886 + && cap_raised(cred->cap_effective, cap)) {
55887 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
55888 + task->role->roletype, cred->uid,
55889 + cred->gid, task->exec_file ?
55890 + gr_to_filename(task->exec_file->f_path.dentry,
55891 + task->exec_file->f_path.mnt) : curracl->filename,
55892 + curracl->filename, 0UL,
55893 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
55894 + return 1;
55895 + }
55896 +
55897 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
55898 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
55899 +
55900 + return 0;
55901 +}
55902 +
55903 +int
55904 +gr_acl_is_capable(const int cap)
55905 +{
55906 + return gr_task_acl_is_capable(current, current_cred(), cap);
55907 +}
55908 +
55909 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
55910 +{
55911 + struct acl_subject_label *curracl;
55912 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
55913 +
55914 + if (!gr_acl_is_enabled())
55915 + return 1;
55916 +
55917 + curracl = task->acl;
55918 +
55919 + cap_drop = curracl->cap_lower;
55920 + cap_mask = curracl->cap_mask;
55921 +
55922 + while ((curracl = curracl->parent_subject)) {
55923 + /* if the cap isn't specified in the current computed mask but is specified in the
55924 + current level subject, and is lowered in the current level subject, then add
55925 + it to the set of dropped capabilities
55926 + otherwise, add the current level subject's mask to the current computed mask
55927 + */
55928 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
55929 + cap_raise(cap_mask, cap);
55930 + if (cap_raised(curracl->cap_lower, cap))
55931 + cap_raise(cap_drop, cap);
55932 + }
55933 + }
55934 +
55935 + if (!cap_raised(cap_drop, cap))
55936 + return 1;
55937 +
55938 + return 0;
55939 +}
55940 +
55941 +int
55942 +gr_acl_is_capable_nolog(const int cap)
55943 +{
55944 + return gr_task_acl_is_capable_nolog(current, cap);
55945 +}
55946 +
55947 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
55948 new file mode 100644
55949 index 0000000..d28e241
55950 --- /dev/null
55951 +++ b/grsecurity/gracl_fs.c
55952 @@ -0,0 +1,437 @@
55953 +#include <linux/kernel.h>
55954 +#include <linux/sched.h>
55955 +#include <linux/types.h>
55956 +#include <linux/fs.h>
55957 +#include <linux/file.h>
55958 +#include <linux/stat.h>
55959 +#include <linux/grsecurity.h>
55960 +#include <linux/grinternal.h>
55961 +#include <linux/gracl.h>
55962 +
55963 +umode_t
55964 +gr_acl_umask(void)
55965 +{
55966 + if (unlikely(!gr_acl_is_enabled()))
55967 + return 0;
55968 +
55969 + return current->role->umask;
55970 +}
55971 +
55972 +__u32
55973 +gr_acl_handle_hidden_file(const struct dentry * dentry,
55974 + const struct vfsmount * mnt)
55975 +{
55976 + __u32 mode;
55977 +
55978 + if (unlikely(!dentry->d_inode))
55979 + return GR_FIND;
55980 +
55981 + mode =
55982 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
55983 +
55984 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
55985 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55986 + return mode;
55987 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
55988 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
55989 + return 0;
55990 + } else if (unlikely(!(mode & GR_FIND)))
55991 + return 0;
55992 +
55993 + return GR_FIND;
55994 +}
55995 +
55996 +__u32
55997 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
55998 + int acc_mode)
55999 +{
56000 + __u32 reqmode = GR_FIND;
56001 + __u32 mode;
56002 +
56003 + if (unlikely(!dentry->d_inode))
56004 + return reqmode;
56005 +
56006 + if (acc_mode & MAY_APPEND)
56007 + reqmode |= GR_APPEND;
56008 + else if (acc_mode & MAY_WRITE)
56009 + reqmode |= GR_WRITE;
56010 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
56011 + reqmode |= GR_READ;
56012 +
56013 + mode =
56014 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56015 + mnt);
56016 +
56017 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56018 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56019 + reqmode & GR_READ ? " reading" : "",
56020 + reqmode & GR_WRITE ? " writing" : reqmode &
56021 + GR_APPEND ? " appending" : "");
56022 + return reqmode;
56023 + } else
56024 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56025 + {
56026 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
56027 + reqmode & GR_READ ? " reading" : "",
56028 + reqmode & GR_WRITE ? " writing" : reqmode &
56029 + GR_APPEND ? " appending" : "");
56030 + return 0;
56031 + } else if (unlikely((mode & reqmode) != reqmode))
56032 + return 0;
56033 +
56034 + return reqmode;
56035 +}
56036 +
56037 +__u32
56038 +gr_acl_handle_creat(const struct dentry * dentry,
56039 + const struct dentry * p_dentry,
56040 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
56041 + const int imode)
56042 +{
56043 + __u32 reqmode = GR_WRITE | GR_CREATE;
56044 + __u32 mode;
56045 +
56046 + if (acc_mode & MAY_APPEND)
56047 + reqmode |= GR_APPEND;
56048 + // if a directory was required or the directory already exists, then
56049 + // don't count this open as a read
56050 + if ((acc_mode & MAY_READ) &&
56051 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
56052 + reqmode |= GR_READ;
56053 + if ((open_flags & O_CREAT) &&
56054 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56055 + reqmode |= GR_SETID;
56056 +
56057 + mode =
56058 + gr_check_create(dentry, p_dentry, p_mnt,
56059 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56060 +
56061 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56062 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56063 + reqmode & GR_READ ? " reading" : "",
56064 + reqmode & GR_WRITE ? " writing" : reqmode &
56065 + GR_APPEND ? " appending" : "");
56066 + return reqmode;
56067 + } else
56068 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56069 + {
56070 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
56071 + reqmode & GR_READ ? " reading" : "",
56072 + reqmode & GR_WRITE ? " writing" : reqmode &
56073 + GR_APPEND ? " appending" : "");
56074 + return 0;
56075 + } else if (unlikely((mode & reqmode) != reqmode))
56076 + return 0;
56077 +
56078 + return reqmode;
56079 +}
56080 +
56081 +__u32
56082 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
56083 + const int fmode)
56084 +{
56085 + __u32 mode, reqmode = GR_FIND;
56086 +
56087 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
56088 + reqmode |= GR_EXEC;
56089 + if (fmode & S_IWOTH)
56090 + reqmode |= GR_WRITE;
56091 + if (fmode & S_IROTH)
56092 + reqmode |= GR_READ;
56093 +
56094 + mode =
56095 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
56096 + mnt);
56097 +
56098 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
56099 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56100 + reqmode & GR_READ ? " reading" : "",
56101 + reqmode & GR_WRITE ? " writing" : "",
56102 + reqmode & GR_EXEC ? " executing" : "");
56103 + return reqmode;
56104 + } else
56105 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
56106 + {
56107 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
56108 + reqmode & GR_READ ? " reading" : "",
56109 + reqmode & GR_WRITE ? " writing" : "",
56110 + reqmode & GR_EXEC ? " executing" : "");
56111 + return 0;
56112 + } else if (unlikely((mode & reqmode) != reqmode))
56113 + return 0;
56114 +
56115 + return reqmode;
56116 +}
56117 +
56118 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
56119 +{
56120 + __u32 mode;
56121 +
56122 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
56123 +
56124 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56125 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
56126 + return mode;
56127 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56128 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
56129 + return 0;
56130 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56131 + return 0;
56132 +
56133 + return (reqmode);
56134 +}
56135 +
56136 +__u32
56137 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
56138 +{
56139 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
56140 +}
56141 +
56142 +__u32
56143 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
56144 +{
56145 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
56146 +}
56147 +
56148 +__u32
56149 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
56150 +{
56151 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
56152 +}
56153 +
56154 +__u32
56155 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
56156 +{
56157 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
56158 +}
56159 +
56160 +__u32
56161 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
56162 + umode_t *modeptr)
56163 +{
56164 + umode_t mode;
56165 +
56166 + *modeptr &= ~gr_acl_umask();
56167 + mode = *modeptr;
56168 +
56169 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
56170 + return 1;
56171 +
56172 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
56173 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
56174 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
56175 + GR_CHMOD_ACL_MSG);
56176 + } else {
56177 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
56178 + }
56179 +}
56180 +
56181 +__u32
56182 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
56183 +{
56184 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
56185 +}
56186 +
56187 +__u32
56188 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
56189 +{
56190 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
56191 +}
56192 +
56193 +__u32
56194 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
56195 +{
56196 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
56197 +}
56198 +
56199 +__u32
56200 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
56201 +{
56202 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
56203 + GR_UNIXCONNECT_ACL_MSG);
56204 +}
56205 +
56206 +/* hardlinks require at minimum create and link permission,
56207 + any additional privilege required is based on the
56208 + privilege of the file being linked to
56209 +*/
56210 +__u32
56211 +gr_acl_handle_link(const struct dentry * new_dentry,
56212 + const struct dentry * parent_dentry,
56213 + const struct vfsmount * parent_mnt,
56214 + const struct dentry * old_dentry,
56215 + const struct vfsmount * old_mnt, const char *to)
56216 +{
56217 + __u32 mode;
56218 + __u32 needmode = GR_CREATE | GR_LINK;
56219 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
56220 +
56221 + mode =
56222 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
56223 + old_mnt);
56224 +
56225 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
56226 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56227 + return mode;
56228 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56229 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to);
56230 + return 0;
56231 + } else if (unlikely((mode & needmode) != needmode))
56232 + return 0;
56233 +
56234 + return 1;
56235 +}
56236 +
56237 +__u32
56238 +gr_acl_handle_symlink(const struct dentry * new_dentry,
56239 + const struct dentry * parent_dentry,
56240 + const struct vfsmount * parent_mnt, const char *from)
56241 +{
56242 + __u32 needmode = GR_WRITE | GR_CREATE;
56243 + __u32 mode;
56244 +
56245 + mode =
56246 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
56247 + GR_CREATE | GR_AUDIT_CREATE |
56248 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
56249 +
56250 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
56251 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56252 + return mode;
56253 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
56254 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from, new_dentry, parent_mnt);
56255 + return 0;
56256 + } else if (unlikely((mode & needmode) != needmode))
56257 + return 0;
56258 +
56259 + return (GR_WRITE | GR_CREATE);
56260 +}
56261 +
56262 +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)
56263 +{
56264 + __u32 mode;
56265 +
56266 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
56267 +
56268 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
56269 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
56270 + return mode;
56271 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
56272 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
56273 + return 0;
56274 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
56275 + return 0;
56276 +
56277 + return (reqmode);
56278 +}
56279 +
56280 +__u32
56281 +gr_acl_handle_mknod(const struct dentry * new_dentry,
56282 + const struct dentry * parent_dentry,
56283 + const struct vfsmount * parent_mnt,
56284 + const int mode)
56285 +{
56286 + __u32 reqmode = GR_WRITE | GR_CREATE;
56287 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
56288 + reqmode |= GR_SETID;
56289 +
56290 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56291 + reqmode, GR_MKNOD_ACL_MSG);
56292 +}
56293 +
56294 +__u32
56295 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
56296 + const struct dentry *parent_dentry,
56297 + const struct vfsmount *parent_mnt)
56298 +{
56299 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
56300 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
56301 +}
56302 +
56303 +#define RENAME_CHECK_SUCCESS(old, new) \
56304 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
56305 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
56306 +
56307 +int
56308 +gr_acl_handle_rename(struct dentry *new_dentry,
56309 + struct dentry *parent_dentry,
56310 + const struct vfsmount *parent_mnt,
56311 + struct dentry *old_dentry,
56312 + struct inode *old_parent_inode,
56313 + struct vfsmount *old_mnt, const char *newname)
56314 +{
56315 + __u32 comp1, comp2;
56316 + int error = 0;
56317 +
56318 + if (unlikely(!gr_acl_is_enabled()))
56319 + return 0;
56320 +
56321 + if (!new_dentry->d_inode) {
56322 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
56323 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
56324 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
56325 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
56326 + GR_DELETE | GR_AUDIT_DELETE |
56327 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56328 + GR_SUPPRESS, old_mnt);
56329 + } else {
56330 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
56331 + GR_CREATE | GR_DELETE |
56332 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
56333 + GR_AUDIT_READ | GR_AUDIT_WRITE |
56334 + GR_SUPPRESS, parent_mnt);
56335 + comp2 =
56336 + gr_search_file(old_dentry,
56337 + GR_READ | GR_WRITE | GR_AUDIT_READ |
56338 + GR_DELETE | GR_AUDIT_DELETE |
56339 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
56340 + }
56341 +
56342 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
56343 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
56344 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56345 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
56346 + && !(comp2 & GR_SUPPRESS)) {
56347 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname);
56348 + error = -EACCES;
56349 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
56350 + error = -EACCES;
56351 +
56352 + return error;
56353 +}
56354 +
56355 +void
56356 +gr_acl_handle_exit(void)
56357 +{
56358 + u16 id;
56359 + char *rolename;
56360 + struct file *exec_file;
56361 +
56362 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
56363 + !(current->role->roletype & GR_ROLE_PERSIST))) {
56364 + id = current->acl_role_id;
56365 + rolename = current->role->rolename;
56366 + gr_set_acls(1);
56367 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
56368 + }
56369 +
56370 + write_lock(&grsec_exec_file_lock);
56371 + exec_file = current->exec_file;
56372 + current->exec_file = NULL;
56373 + write_unlock(&grsec_exec_file_lock);
56374 +
56375 + if (exec_file)
56376 + fput(exec_file);
56377 +}
56378 +
56379 +int
56380 +gr_acl_handle_procpidmem(const struct task_struct *task)
56381 +{
56382 + if (unlikely(!gr_acl_is_enabled()))
56383 + return 0;
56384 +
56385 + if (task != current && task->acl->mode & GR_PROTPROCFD)
56386 + return -EACCES;
56387 +
56388 + return 0;
56389 +}
56390 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
56391 new file mode 100644
56392 index 0000000..58800a7
56393 --- /dev/null
56394 +++ b/grsecurity/gracl_ip.c
56395 @@ -0,0 +1,384 @@
56396 +#include <linux/kernel.h>
56397 +#include <asm/uaccess.h>
56398 +#include <asm/errno.h>
56399 +#include <net/sock.h>
56400 +#include <linux/file.h>
56401 +#include <linux/fs.h>
56402 +#include <linux/net.h>
56403 +#include <linux/in.h>
56404 +#include <linux/skbuff.h>
56405 +#include <linux/ip.h>
56406 +#include <linux/udp.h>
56407 +#include <linux/types.h>
56408 +#include <linux/sched.h>
56409 +#include <linux/netdevice.h>
56410 +#include <linux/inetdevice.h>
56411 +#include <linux/gracl.h>
56412 +#include <linux/grsecurity.h>
56413 +#include <linux/grinternal.h>
56414 +
56415 +#define GR_BIND 0x01
56416 +#define GR_CONNECT 0x02
56417 +#define GR_INVERT 0x04
56418 +#define GR_BINDOVERRIDE 0x08
56419 +#define GR_CONNECTOVERRIDE 0x10
56420 +#define GR_SOCK_FAMILY 0x20
56421 +
56422 +static const char * gr_protocols[IPPROTO_MAX] = {
56423 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
56424 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
56425 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
56426 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
56427 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
56428 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
56429 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
56430 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
56431 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
56432 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
56433 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
56434 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
56435 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
56436 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
56437 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
56438 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
56439 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
56440 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
56441 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
56442 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
56443 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
56444 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
56445 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
56446 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
56447 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
56448 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
56449 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
56450 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
56451 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
56452 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
56453 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
56454 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
56455 + };
56456 +
56457 +static const char * gr_socktypes[SOCK_MAX] = {
56458 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
56459 + "unknown:7", "unknown:8", "unknown:9", "packet"
56460 + };
56461 +
56462 +static const char * gr_sockfamilies[AF_MAX+1] = {
56463 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
56464 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
56465 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
56466 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
56467 + };
56468 +
56469 +const char *
56470 +gr_proto_to_name(unsigned char proto)
56471 +{
56472 + return gr_protocols[proto];
56473 +}
56474 +
56475 +const char *
56476 +gr_socktype_to_name(unsigned char type)
56477 +{
56478 + return gr_socktypes[type];
56479 +}
56480 +
56481 +const char *
56482 +gr_sockfamily_to_name(unsigned char family)
56483 +{
56484 + return gr_sockfamilies[family];
56485 +}
56486 +
56487 +int
56488 +gr_search_socket(const int domain, const int type, const int protocol)
56489 +{
56490 + struct acl_subject_label *curr;
56491 + const struct cred *cred = current_cred();
56492 +
56493 + if (unlikely(!gr_acl_is_enabled()))
56494 + goto exit;
56495 +
56496 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
56497 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
56498 + goto exit; // let the kernel handle it
56499 +
56500 + curr = current->acl;
56501 +
56502 + if (curr->sock_families[domain / 32] & (1 << (domain % 32))) {
56503 + /* the family is allowed, if this is PF_INET allow it only if
56504 + the extra sock type/protocol checks pass */
56505 + if (domain == PF_INET)
56506 + goto inet_check;
56507 + goto exit;
56508 + } else {
56509 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56510 + __u32 fakeip = 0;
56511 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56512 + current->role->roletype, cred->uid,
56513 + cred->gid, current->exec_file ?
56514 + gr_to_filename(current->exec_file->f_path.dentry,
56515 + current->exec_file->f_path.mnt) :
56516 + curr->filename, curr->filename,
56517 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
56518 + &current->signal->saved_ip);
56519 + goto exit;
56520 + }
56521 + goto exit_fail;
56522 + }
56523 +
56524 +inet_check:
56525 + /* the rest of this checking is for IPv4 only */
56526 + if (!curr->ips)
56527 + goto exit;
56528 +
56529 + if ((curr->ip_type & (1 << type)) &&
56530 + (curr->ip_proto[protocol / 32] & (1 << (protocol % 32))))
56531 + goto exit;
56532 +
56533 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56534 + /* we don't place acls on raw sockets , and sometimes
56535 + dgram/ip sockets are opened for ioctl and not
56536 + bind/connect, so we'll fake a bind learn log */
56537 + if (type == SOCK_RAW || type == SOCK_PACKET) {
56538 + __u32 fakeip = 0;
56539 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56540 + current->role->roletype, cred->uid,
56541 + cred->gid, current->exec_file ?
56542 + gr_to_filename(current->exec_file->f_path.dentry,
56543 + current->exec_file->f_path.mnt) :
56544 + curr->filename, curr->filename,
56545 + &fakeip, 0, type,
56546 + protocol, GR_CONNECT, &current->signal->saved_ip);
56547 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
56548 + __u32 fakeip = 0;
56549 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56550 + current->role->roletype, cred->uid,
56551 + cred->gid, current->exec_file ?
56552 + gr_to_filename(current->exec_file->f_path.dentry,
56553 + current->exec_file->f_path.mnt) :
56554 + curr->filename, curr->filename,
56555 + &fakeip, 0, type,
56556 + protocol, GR_BIND, &current->signal->saved_ip);
56557 + }
56558 + /* we'll log when they use connect or bind */
56559 + goto exit;
56560 + }
56561 +
56562 +exit_fail:
56563 + if (domain == PF_INET)
56564 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
56565 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
56566 + else
56567 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
56568 + gr_socktype_to_name(type), protocol);
56569 +
56570 + return 0;
56571 +exit:
56572 + return 1;
56573 +}
56574 +
56575 +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)
56576 +{
56577 + if ((ip->mode & mode) &&
56578 + (ip_port >= ip->low) &&
56579 + (ip_port <= ip->high) &&
56580 + ((ntohl(ip_addr) & our_netmask) ==
56581 + (ntohl(our_addr) & our_netmask))
56582 + && (ip->proto[protocol / 32] & (1 << (protocol % 32)))
56583 + && (ip->type & (1 << type))) {
56584 + if (ip->mode & GR_INVERT)
56585 + return 2; // specifically denied
56586 + else
56587 + return 1; // allowed
56588 + }
56589 +
56590 + return 0; // not specifically allowed, may continue parsing
56591 +}
56592 +
56593 +static int
56594 +gr_search_connectbind(const int full_mode, struct sock *sk,
56595 + struct sockaddr_in *addr, const int type)
56596 +{
56597 + char iface[IFNAMSIZ] = {0};
56598 + struct acl_subject_label *curr;
56599 + struct acl_ip_label *ip;
56600 + struct inet_sock *isk;
56601 + struct net_device *dev;
56602 + struct in_device *idev;
56603 + unsigned long i;
56604 + int ret;
56605 + int mode = full_mode & (GR_BIND | GR_CONNECT);
56606 + __u32 ip_addr = 0;
56607 + __u32 our_addr;
56608 + __u32 our_netmask;
56609 + char *p;
56610 + __u16 ip_port = 0;
56611 + const struct cred *cred = current_cred();
56612 +
56613 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
56614 + return 0;
56615 +
56616 + curr = current->acl;
56617 + isk = inet_sk(sk);
56618 +
56619 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
56620 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
56621 + addr->sin_addr.s_addr = curr->inaddr_any_override;
56622 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
56623 + struct sockaddr_in saddr;
56624 + int err;
56625 +
56626 + saddr.sin_family = AF_INET;
56627 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
56628 + saddr.sin_port = isk->inet_sport;
56629 +
56630 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56631 + if (err)
56632 + return err;
56633 +
56634 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
56635 + if (err)
56636 + return err;
56637 + }
56638 +
56639 + if (!curr->ips)
56640 + return 0;
56641 +
56642 + ip_addr = addr->sin_addr.s_addr;
56643 + ip_port = ntohs(addr->sin_port);
56644 +
56645 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
56646 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
56647 + current->role->roletype, cred->uid,
56648 + cred->gid, current->exec_file ?
56649 + gr_to_filename(current->exec_file->f_path.dentry,
56650 + current->exec_file->f_path.mnt) :
56651 + curr->filename, curr->filename,
56652 + &ip_addr, ip_port, type,
56653 + sk->sk_protocol, mode, &current->signal->saved_ip);
56654 + return 0;
56655 + }
56656 +
56657 + for (i = 0; i < curr->ip_num; i++) {
56658 + ip = *(curr->ips + i);
56659 + if (ip->iface != NULL) {
56660 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
56661 + p = strchr(iface, ':');
56662 + if (p != NULL)
56663 + *p = '\0';
56664 + dev = dev_get_by_name(sock_net(sk), iface);
56665 + if (dev == NULL)
56666 + continue;
56667 + idev = in_dev_get(dev);
56668 + if (idev == NULL) {
56669 + dev_put(dev);
56670 + continue;
56671 + }
56672 + rcu_read_lock();
56673 + for_ifa(idev) {
56674 + if (!strcmp(ip->iface, ifa->ifa_label)) {
56675 + our_addr = ifa->ifa_address;
56676 + our_netmask = 0xffffffff;
56677 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56678 + if (ret == 1) {
56679 + rcu_read_unlock();
56680 + in_dev_put(idev);
56681 + dev_put(dev);
56682 + return 0;
56683 + } else if (ret == 2) {
56684 + rcu_read_unlock();
56685 + in_dev_put(idev);
56686 + dev_put(dev);
56687 + goto denied;
56688 + }
56689 + }
56690 + } endfor_ifa(idev);
56691 + rcu_read_unlock();
56692 + in_dev_put(idev);
56693 + dev_put(dev);
56694 + } else {
56695 + our_addr = ip->addr;
56696 + our_netmask = ip->netmask;
56697 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
56698 + if (ret == 1)
56699 + return 0;
56700 + else if (ret == 2)
56701 + goto denied;
56702 + }
56703 + }
56704 +
56705 +denied:
56706 + if (mode == GR_BIND)
56707 + 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));
56708 + else if (mode == GR_CONNECT)
56709 + 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));
56710 +
56711 + return -EACCES;
56712 +}
56713 +
56714 +int
56715 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
56716 +{
56717 + /* always allow disconnection of dgram sockets with connect */
56718 + if (addr->sin_family == AF_UNSPEC)
56719 + return 0;
56720 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
56721 +}
56722 +
56723 +int
56724 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
56725 +{
56726 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
56727 +}
56728 +
56729 +int gr_search_listen(struct socket *sock)
56730 +{
56731 + struct sock *sk = sock->sk;
56732 + struct sockaddr_in addr;
56733 +
56734 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56735 + addr.sin_port = inet_sk(sk)->inet_sport;
56736 +
56737 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56738 +}
56739 +
56740 +int gr_search_accept(struct socket *sock)
56741 +{
56742 + struct sock *sk = sock->sk;
56743 + struct sockaddr_in addr;
56744 +
56745 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
56746 + addr.sin_port = inet_sk(sk)->inet_sport;
56747 +
56748 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
56749 +}
56750 +
56751 +int
56752 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
56753 +{
56754 + if (addr)
56755 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
56756 + else {
56757 + struct sockaddr_in sin;
56758 + const struct inet_sock *inet = inet_sk(sk);
56759 +
56760 + sin.sin_addr.s_addr = inet->inet_daddr;
56761 + sin.sin_port = inet->inet_dport;
56762 +
56763 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56764 + }
56765 +}
56766 +
56767 +int
56768 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
56769 +{
56770 + struct sockaddr_in sin;
56771 +
56772 + if (unlikely(skb->len < sizeof (struct udphdr)))
56773 + return 0; // skip this packet
56774 +
56775 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
56776 + sin.sin_port = udp_hdr(skb)->source;
56777 +
56778 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
56779 +}
56780 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
56781 new file mode 100644
56782 index 0000000..25f54ef
56783 --- /dev/null
56784 +++ b/grsecurity/gracl_learn.c
56785 @@ -0,0 +1,207 @@
56786 +#include <linux/kernel.h>
56787 +#include <linux/mm.h>
56788 +#include <linux/sched.h>
56789 +#include <linux/poll.h>
56790 +#include <linux/string.h>
56791 +#include <linux/file.h>
56792 +#include <linux/types.h>
56793 +#include <linux/vmalloc.h>
56794 +#include <linux/grinternal.h>
56795 +
56796 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
56797 + size_t count, loff_t *ppos);
56798 +extern int gr_acl_is_enabled(void);
56799 +
56800 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
56801 +static int gr_learn_attached;
56802 +
56803 +/* use a 512k buffer */
56804 +#define LEARN_BUFFER_SIZE (512 * 1024)
56805 +
56806 +static DEFINE_SPINLOCK(gr_learn_lock);
56807 +static DEFINE_MUTEX(gr_learn_user_mutex);
56808 +
56809 +/* we need to maintain two buffers, so that the kernel context of grlearn
56810 + uses a semaphore around the userspace copying, and the other kernel contexts
56811 + use a spinlock when copying into the buffer, since they cannot sleep
56812 +*/
56813 +static char *learn_buffer;
56814 +static char *learn_buffer_user;
56815 +static int learn_buffer_len;
56816 +static int learn_buffer_user_len;
56817 +
56818 +static ssize_t
56819 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
56820 +{
56821 + DECLARE_WAITQUEUE(wait, current);
56822 + ssize_t retval = 0;
56823 +
56824 + add_wait_queue(&learn_wait, &wait);
56825 + set_current_state(TASK_INTERRUPTIBLE);
56826 + do {
56827 + mutex_lock(&gr_learn_user_mutex);
56828 + spin_lock(&gr_learn_lock);
56829 + if (learn_buffer_len)
56830 + break;
56831 + spin_unlock(&gr_learn_lock);
56832 + mutex_unlock(&gr_learn_user_mutex);
56833 + if (file->f_flags & O_NONBLOCK) {
56834 + retval = -EAGAIN;
56835 + goto out;
56836 + }
56837 + if (signal_pending(current)) {
56838 + retval = -ERESTARTSYS;
56839 + goto out;
56840 + }
56841 +
56842 + schedule();
56843 + } while (1);
56844 +
56845 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
56846 + learn_buffer_user_len = learn_buffer_len;
56847 + retval = learn_buffer_len;
56848 + learn_buffer_len = 0;
56849 +
56850 + spin_unlock(&gr_learn_lock);
56851 +
56852 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
56853 + retval = -EFAULT;
56854 +
56855 + mutex_unlock(&gr_learn_user_mutex);
56856 +out:
56857 + set_current_state(TASK_RUNNING);
56858 + remove_wait_queue(&learn_wait, &wait);
56859 + return retval;
56860 +}
56861 +
56862 +static unsigned int
56863 +poll_learn(struct file * file, poll_table * wait)
56864 +{
56865 + poll_wait(file, &learn_wait, wait);
56866 +
56867 + if (learn_buffer_len)
56868 + return (POLLIN | POLLRDNORM);
56869 +
56870 + return 0;
56871 +}
56872 +
56873 +void
56874 +gr_clear_learn_entries(void)
56875 +{
56876 + char *tmp;
56877 +
56878 + mutex_lock(&gr_learn_user_mutex);
56879 + spin_lock(&gr_learn_lock);
56880 + tmp = learn_buffer;
56881 + learn_buffer = NULL;
56882 + spin_unlock(&gr_learn_lock);
56883 + if (tmp)
56884 + vfree(tmp);
56885 + if (learn_buffer_user != NULL) {
56886 + vfree(learn_buffer_user);
56887 + learn_buffer_user = NULL;
56888 + }
56889 + learn_buffer_len = 0;
56890 + mutex_unlock(&gr_learn_user_mutex);
56891 +
56892 + return;
56893 +}
56894 +
56895 +void
56896 +gr_add_learn_entry(const char *fmt, ...)
56897 +{
56898 + va_list args;
56899 + unsigned int len;
56900 +
56901 + if (!gr_learn_attached)
56902 + return;
56903 +
56904 + spin_lock(&gr_learn_lock);
56905 +
56906 + /* leave a gap at the end so we know when it's "full" but don't have to
56907 + compute the exact length of the string we're trying to append
56908 + */
56909 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
56910 + spin_unlock(&gr_learn_lock);
56911 + wake_up_interruptible(&learn_wait);
56912 + return;
56913 + }
56914 + if (learn_buffer == NULL) {
56915 + spin_unlock(&gr_learn_lock);
56916 + return;
56917 + }
56918 +
56919 + va_start(args, fmt);
56920 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
56921 + va_end(args);
56922 +
56923 + learn_buffer_len += len + 1;
56924 +
56925 + spin_unlock(&gr_learn_lock);
56926 + wake_up_interruptible(&learn_wait);
56927 +
56928 + return;
56929 +}
56930 +
56931 +static int
56932 +open_learn(struct inode *inode, struct file *file)
56933 +{
56934 + if (file->f_mode & FMODE_READ && gr_learn_attached)
56935 + return -EBUSY;
56936 + if (file->f_mode & FMODE_READ) {
56937 + int retval = 0;
56938 + mutex_lock(&gr_learn_user_mutex);
56939 + if (learn_buffer == NULL)
56940 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
56941 + if (learn_buffer_user == NULL)
56942 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
56943 + if (learn_buffer == NULL) {
56944 + retval = -ENOMEM;
56945 + goto out_error;
56946 + }
56947 + if (learn_buffer_user == NULL) {
56948 + retval = -ENOMEM;
56949 + goto out_error;
56950 + }
56951 + learn_buffer_len = 0;
56952 + learn_buffer_user_len = 0;
56953 + gr_learn_attached = 1;
56954 +out_error:
56955 + mutex_unlock(&gr_learn_user_mutex);
56956 + return retval;
56957 + }
56958 + return 0;
56959 +}
56960 +
56961 +static int
56962 +close_learn(struct inode *inode, struct file *file)
56963 +{
56964 + if (file->f_mode & FMODE_READ) {
56965 + char *tmp = NULL;
56966 + mutex_lock(&gr_learn_user_mutex);
56967 + spin_lock(&gr_learn_lock);
56968 + tmp = learn_buffer;
56969 + learn_buffer = NULL;
56970 + spin_unlock(&gr_learn_lock);
56971 + if (tmp)
56972 + vfree(tmp);
56973 + if (learn_buffer_user != NULL) {
56974 + vfree(learn_buffer_user);
56975 + learn_buffer_user = NULL;
56976 + }
56977 + learn_buffer_len = 0;
56978 + learn_buffer_user_len = 0;
56979 + gr_learn_attached = 0;
56980 + mutex_unlock(&gr_learn_user_mutex);
56981 + }
56982 +
56983 + return 0;
56984 +}
56985 +
56986 +const struct file_operations grsec_fops = {
56987 + .read = read_learn,
56988 + .write = write_grsec_handler,
56989 + .open = open_learn,
56990 + .release = close_learn,
56991 + .poll = poll_learn,
56992 +};
56993 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
56994 new file mode 100644
56995 index 0000000..39645c9
56996 --- /dev/null
56997 +++ b/grsecurity/gracl_res.c
56998 @@ -0,0 +1,68 @@
56999 +#include <linux/kernel.h>
57000 +#include <linux/sched.h>
57001 +#include <linux/gracl.h>
57002 +#include <linux/grinternal.h>
57003 +
57004 +static const char *restab_log[] = {
57005 + [RLIMIT_CPU] = "RLIMIT_CPU",
57006 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
57007 + [RLIMIT_DATA] = "RLIMIT_DATA",
57008 + [RLIMIT_STACK] = "RLIMIT_STACK",
57009 + [RLIMIT_CORE] = "RLIMIT_CORE",
57010 + [RLIMIT_RSS] = "RLIMIT_RSS",
57011 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
57012 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
57013 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
57014 + [RLIMIT_AS] = "RLIMIT_AS",
57015 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
57016 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
57017 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
57018 + [RLIMIT_NICE] = "RLIMIT_NICE",
57019 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
57020 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
57021 + [GR_CRASH_RES] = "RLIMIT_CRASH"
57022 +};
57023 +
57024 +void
57025 +gr_log_resource(const struct task_struct *task,
57026 + const int res, const unsigned long wanted, const int gt)
57027 +{
57028 + const struct cred *cred;
57029 + unsigned long rlim;
57030 +
57031 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
57032 + return;
57033 +
57034 + // not yet supported resource
57035 + if (unlikely(!restab_log[res]))
57036 + return;
57037 +
57038 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
57039 + rlim = task_rlimit_max(task, res);
57040 + else
57041 + rlim = task_rlimit(task, res);
57042 +
57043 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
57044 + return;
57045 +
57046 + rcu_read_lock();
57047 + cred = __task_cred(task);
57048 +
57049 + if (res == RLIMIT_NPROC &&
57050 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
57051 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
57052 + goto out_rcu_unlock;
57053 + else if (res == RLIMIT_MEMLOCK &&
57054 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
57055 + goto out_rcu_unlock;
57056 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
57057 + goto out_rcu_unlock;
57058 + rcu_read_unlock();
57059 +
57060 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
57061 +
57062 + return;
57063 +out_rcu_unlock:
57064 + rcu_read_unlock();
57065 + return;
57066 +}
57067 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
57068 new file mode 100644
57069 index 0000000..25197e9
57070 --- /dev/null
57071 +++ b/grsecurity/gracl_segv.c
57072 @@ -0,0 +1,299 @@
57073 +#include <linux/kernel.h>
57074 +#include <linux/mm.h>
57075 +#include <asm/uaccess.h>
57076 +#include <asm/errno.h>
57077 +#include <asm/mman.h>
57078 +#include <net/sock.h>
57079 +#include <linux/file.h>
57080 +#include <linux/fs.h>
57081 +#include <linux/net.h>
57082 +#include <linux/in.h>
57083 +#include <linux/slab.h>
57084 +#include <linux/types.h>
57085 +#include <linux/sched.h>
57086 +#include <linux/timer.h>
57087 +#include <linux/gracl.h>
57088 +#include <linux/grsecurity.h>
57089 +#include <linux/grinternal.h>
57090 +
57091 +static struct crash_uid *uid_set;
57092 +static unsigned short uid_used;
57093 +static DEFINE_SPINLOCK(gr_uid_lock);
57094 +extern rwlock_t gr_inode_lock;
57095 +extern struct acl_subject_label *
57096 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
57097 + struct acl_role_label *role);
57098 +
57099 +#ifdef CONFIG_BTRFS_FS
57100 +extern dev_t get_btrfs_dev_from_inode(struct inode *inode);
57101 +extern int btrfs_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat);
57102 +#endif
57103 +
57104 +static inline dev_t __get_dev(const struct dentry *dentry)
57105 +{
57106 +#ifdef CONFIG_BTRFS_FS
57107 + if (dentry->d_inode->i_op && dentry->d_inode->i_op->getattr == &btrfs_getattr)
57108 + return get_btrfs_dev_from_inode(dentry->d_inode);
57109 + else
57110 +#endif
57111 + return dentry->d_inode->i_sb->s_dev;
57112 +}
57113 +
57114 +int
57115 +gr_init_uidset(void)
57116 +{
57117 + uid_set =
57118 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
57119 + uid_used = 0;
57120 +
57121 + return uid_set ? 1 : 0;
57122 +}
57123 +
57124 +void
57125 +gr_free_uidset(void)
57126 +{
57127 + if (uid_set)
57128 + kfree(uid_set);
57129 +
57130 + return;
57131 +}
57132 +
57133 +int
57134 +gr_find_uid(const uid_t uid)
57135 +{
57136 + struct crash_uid *tmp = uid_set;
57137 + uid_t buid;
57138 + int low = 0, high = uid_used - 1, mid;
57139 +
57140 + while (high >= low) {
57141 + mid = (low + high) >> 1;
57142 + buid = tmp[mid].uid;
57143 + if (buid == uid)
57144 + return mid;
57145 + if (buid > uid)
57146 + high = mid - 1;
57147 + if (buid < uid)
57148 + low = mid + 1;
57149 + }
57150 +
57151 + return -1;
57152 +}
57153 +
57154 +static __inline__ void
57155 +gr_insertsort(void)
57156 +{
57157 + unsigned short i, j;
57158 + struct crash_uid index;
57159 +
57160 + for (i = 1; i < uid_used; i++) {
57161 + index = uid_set[i];
57162 + j = i;
57163 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
57164 + uid_set[j] = uid_set[j - 1];
57165 + j--;
57166 + }
57167 + uid_set[j] = index;
57168 + }
57169 +
57170 + return;
57171 +}
57172 +
57173 +static __inline__ void
57174 +gr_insert_uid(const uid_t uid, const unsigned long expires)
57175 +{
57176 + int loc;
57177 +
57178 + if (uid_used == GR_UIDTABLE_MAX)
57179 + return;
57180 +
57181 + loc = gr_find_uid(uid);
57182 +
57183 + if (loc >= 0) {
57184 + uid_set[loc].expires = expires;
57185 + return;
57186 + }
57187 +
57188 + uid_set[uid_used].uid = uid;
57189 + uid_set[uid_used].expires = expires;
57190 + uid_used++;
57191 +
57192 + gr_insertsort();
57193 +
57194 + return;
57195 +}
57196 +
57197 +void
57198 +gr_remove_uid(const unsigned short loc)
57199 +{
57200 + unsigned short i;
57201 +
57202 + for (i = loc + 1; i < uid_used; i++)
57203 + uid_set[i - 1] = uid_set[i];
57204 +
57205 + uid_used--;
57206 +
57207 + return;
57208 +}
57209 +
57210 +int
57211 +gr_check_crash_uid(const uid_t uid)
57212 +{
57213 + int loc;
57214 + int ret = 0;
57215 +
57216 + if (unlikely(!gr_acl_is_enabled()))
57217 + return 0;
57218 +
57219 + spin_lock(&gr_uid_lock);
57220 + loc = gr_find_uid(uid);
57221 +
57222 + if (loc < 0)
57223 + goto out_unlock;
57224 +
57225 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
57226 + gr_remove_uid(loc);
57227 + else
57228 + ret = 1;
57229 +
57230 +out_unlock:
57231 + spin_unlock(&gr_uid_lock);
57232 + return ret;
57233 +}
57234 +
57235 +static __inline__ int
57236 +proc_is_setxid(const struct cred *cred)
57237 +{
57238 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
57239 + !uid_eq(cred->uid, cred->fsuid))
57240 + return 1;
57241 + if (!uid_eq(cred->gid, cred->egid) || !uid_eq(cred->gid, cred->sgid) ||
57242 + !uid_eq(cred->gid, cred->fsgid))
57243 + return 1;
57244 +
57245 + return 0;
57246 +}
57247 +
57248 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
57249 +
57250 +void
57251 +gr_handle_crash(struct task_struct *task, const int sig)
57252 +{
57253 + struct acl_subject_label *curr;
57254 + struct task_struct *tsk, *tsk2;
57255 + const struct cred *cred;
57256 + const struct cred *cred2;
57257 +
57258 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
57259 + return;
57260 +
57261 + if (unlikely(!gr_acl_is_enabled()))
57262 + return;
57263 +
57264 + curr = task->acl;
57265 +
57266 + if (!(curr->resmask & (1 << GR_CRASH_RES)))
57267 + return;
57268 +
57269 + if (time_before_eq(curr->expires, get_seconds())) {
57270 + curr->expires = 0;
57271 + curr->crashes = 0;
57272 + }
57273 +
57274 + curr->crashes++;
57275 +
57276 + if (!curr->expires)
57277 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
57278 +
57279 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57280 + time_after(curr->expires, get_seconds())) {
57281 + rcu_read_lock();
57282 + cred = __task_cred(task);
57283 + if (!uid_eq(cred->uid, GLOBAL_ROOT_UID) && proc_is_setxid(cred)) {
57284 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57285 + spin_lock(&gr_uid_lock);
57286 + gr_insert_uid(cred->uid, curr->expires);
57287 + spin_unlock(&gr_uid_lock);
57288 + curr->expires = 0;
57289 + curr->crashes = 0;
57290 + read_lock(&tasklist_lock);
57291 + do_each_thread(tsk2, tsk) {
57292 + cred2 = __task_cred(tsk);
57293 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
57294 + gr_fake_force_sig(SIGKILL, tsk);
57295 + } while_each_thread(tsk2, tsk);
57296 + read_unlock(&tasklist_lock);
57297 + } else {
57298 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
57299 + read_lock(&tasklist_lock);
57300 + read_lock(&grsec_exec_file_lock);
57301 + do_each_thread(tsk2, tsk) {
57302 + if (likely(tsk != task)) {
57303 + // if this thread has the same subject as the one that triggered
57304 + // RES_CRASH and it's the same binary, kill it
57305 + if (tsk->acl == task->acl && tsk->exec_file == task->exec_file)
57306 + gr_fake_force_sig(SIGKILL, tsk);
57307 + }
57308 + } while_each_thread(tsk2, tsk);
57309 + read_unlock(&grsec_exec_file_lock);
57310 + read_unlock(&tasklist_lock);
57311 + }
57312 + rcu_read_unlock();
57313 + }
57314 +
57315 + return;
57316 +}
57317 +
57318 +int
57319 +gr_check_crash_exec(const struct file *filp)
57320 +{
57321 + struct acl_subject_label *curr;
57322 +
57323 + if (unlikely(!gr_acl_is_enabled()))
57324 + return 0;
57325 +
57326 + read_lock(&gr_inode_lock);
57327 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
57328 + __get_dev(filp->f_path.dentry),
57329 + current->role);
57330 + read_unlock(&gr_inode_lock);
57331 +
57332 + if (!curr || !(curr->resmask & (1 << GR_CRASH_RES)) ||
57333 + (!curr->crashes && !curr->expires))
57334 + return 0;
57335 +
57336 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
57337 + time_after(curr->expires, get_seconds()))
57338 + return 1;
57339 + else if (time_before_eq(curr->expires, get_seconds())) {
57340 + curr->crashes = 0;
57341 + curr->expires = 0;
57342 + }
57343 +
57344 + return 0;
57345 +}
57346 +
57347 +void
57348 +gr_handle_alertkill(struct task_struct *task)
57349 +{
57350 + struct acl_subject_label *curracl;
57351 + __u32 curr_ip;
57352 + struct task_struct *p, *p2;
57353 +
57354 + if (unlikely(!gr_acl_is_enabled()))
57355 + return;
57356 +
57357 + curracl = task->acl;
57358 + curr_ip = task->signal->curr_ip;
57359 +
57360 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
57361 + read_lock(&tasklist_lock);
57362 + do_each_thread(p2, p) {
57363 + if (p->signal->curr_ip == curr_ip)
57364 + gr_fake_force_sig(SIGKILL, p);
57365 + } while_each_thread(p2, p);
57366 + read_unlock(&tasklist_lock);
57367 + } else if (curracl->mode & GR_KILLPROC)
57368 + gr_fake_force_sig(SIGKILL, task);
57369 +
57370 + return;
57371 +}
57372 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
57373 new file mode 100644
57374 index 0000000..9d83a69
57375 --- /dev/null
57376 +++ b/grsecurity/gracl_shm.c
57377 @@ -0,0 +1,40 @@
57378 +#include <linux/kernel.h>
57379 +#include <linux/mm.h>
57380 +#include <linux/sched.h>
57381 +#include <linux/file.h>
57382 +#include <linux/ipc.h>
57383 +#include <linux/gracl.h>
57384 +#include <linux/grsecurity.h>
57385 +#include <linux/grinternal.h>
57386 +
57387 +int
57388 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57389 + const time_t shm_createtime, const uid_t cuid, const int shmid)
57390 +{
57391 + struct task_struct *task;
57392 +
57393 + if (!gr_acl_is_enabled())
57394 + return 1;
57395 +
57396 + rcu_read_lock();
57397 + read_lock(&tasklist_lock);
57398 +
57399 + task = find_task_by_vpid(shm_cprid);
57400 +
57401 + if (unlikely(!task))
57402 + task = find_task_by_vpid(shm_lapid);
57403 +
57404 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
57405 + (task->pid == shm_lapid)) &&
57406 + (task->acl->mode & GR_PROTSHM) &&
57407 + (task->acl != current->acl))) {
57408 + read_unlock(&tasklist_lock);
57409 + rcu_read_unlock();
57410 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, cuid, shm_cprid, shmid);
57411 + return 0;
57412 + }
57413 + read_unlock(&tasklist_lock);
57414 + rcu_read_unlock();
57415 +
57416 + return 1;
57417 +}
57418 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
57419 new file mode 100644
57420 index 0000000..bc0be01
57421 --- /dev/null
57422 +++ b/grsecurity/grsec_chdir.c
57423 @@ -0,0 +1,19 @@
57424 +#include <linux/kernel.h>
57425 +#include <linux/sched.h>
57426 +#include <linux/fs.h>
57427 +#include <linux/file.h>
57428 +#include <linux/grsecurity.h>
57429 +#include <linux/grinternal.h>
57430 +
57431 +void
57432 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
57433 +{
57434 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
57435 + if ((grsec_enable_chdir && grsec_enable_group &&
57436 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
57437 + !grsec_enable_group)) {
57438 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
57439 + }
57440 +#endif
57441 + return;
57442 +}
57443 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
57444 new file mode 100644
57445 index 0000000..9807ee2
57446 --- /dev/null
57447 +++ b/grsecurity/grsec_chroot.c
57448 @@ -0,0 +1,368 @@
57449 +#include <linux/kernel.h>
57450 +#include <linux/module.h>
57451 +#include <linux/sched.h>
57452 +#include <linux/file.h>
57453 +#include <linux/fs.h>
57454 +#include <linux/mount.h>
57455 +#include <linux/types.h>
57456 +#include "../fs/mount.h"
57457 +#include <linux/grsecurity.h>
57458 +#include <linux/grinternal.h>
57459 +
57460 +void gr_set_chroot_entries(struct task_struct *task, struct path *path)
57461 +{
57462 +#ifdef CONFIG_GRKERNSEC
57463 + if (task->pid > 1 && path->dentry != init_task.fs->root.dentry &&
57464 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root)
57465 + task->gr_is_chrooted = 1;
57466 + else
57467 + task->gr_is_chrooted = 0;
57468 +
57469 + task->gr_chroot_dentry = path->dentry;
57470 +#endif
57471 + return;
57472 +}
57473 +
57474 +void gr_clear_chroot_entries(struct task_struct *task)
57475 +{
57476 +#ifdef CONFIG_GRKERNSEC
57477 + task->gr_is_chrooted = 0;
57478 + task->gr_chroot_dentry = NULL;
57479 +#endif
57480 + return;
57481 +}
57482 +
57483 +int
57484 +gr_handle_chroot_unix(const pid_t pid)
57485 +{
57486 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
57487 + struct task_struct *p;
57488 +
57489 + if (unlikely(!grsec_enable_chroot_unix))
57490 + return 1;
57491 +
57492 + if (likely(!proc_is_chrooted(current)))
57493 + return 1;
57494 +
57495 + rcu_read_lock();
57496 + read_lock(&tasklist_lock);
57497 + p = find_task_by_vpid_unrestricted(pid);
57498 + if (unlikely(p && !have_same_root(current, p))) {
57499 + read_unlock(&tasklist_lock);
57500 + rcu_read_unlock();
57501 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
57502 + return 0;
57503 + }
57504 + read_unlock(&tasklist_lock);
57505 + rcu_read_unlock();
57506 +#endif
57507 + return 1;
57508 +}
57509 +
57510 +int
57511 +gr_handle_chroot_nice(void)
57512 +{
57513 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57514 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
57515 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
57516 + return -EPERM;
57517 + }
57518 +#endif
57519 + return 0;
57520 +}
57521 +
57522 +int
57523 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
57524 +{
57525 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
57526 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
57527 + && proc_is_chrooted(current)) {
57528 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, p->pid);
57529 + return -EACCES;
57530 + }
57531 +#endif
57532 + return 0;
57533 +}
57534 +
57535 +int
57536 +gr_handle_chroot_rawio(const struct inode *inode)
57537 +{
57538 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57539 + if (grsec_enable_chroot_caps && proc_is_chrooted(current) &&
57540 + inode && S_ISBLK(inode->i_mode) && !capable(CAP_SYS_RAWIO))
57541 + return 1;
57542 +#endif
57543 + return 0;
57544 +}
57545 +
57546 +int
57547 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
57548 +{
57549 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57550 + struct task_struct *p;
57551 + int ret = 0;
57552 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
57553 + return ret;
57554 +
57555 + read_lock(&tasklist_lock);
57556 + do_each_pid_task(pid, type, p) {
57557 + if (!have_same_root(current, p)) {
57558 + ret = 1;
57559 + goto out;
57560 + }
57561 + } while_each_pid_task(pid, type, p);
57562 +out:
57563 + read_unlock(&tasklist_lock);
57564 + return ret;
57565 +#endif
57566 + return 0;
57567 +}
57568 +
57569 +int
57570 +gr_pid_is_chrooted(struct task_struct *p)
57571 +{
57572 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
57573 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
57574 + return 0;
57575 +
57576 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
57577 + !have_same_root(current, p)) {
57578 + return 1;
57579 + }
57580 +#endif
57581 + return 0;
57582 +}
57583 +
57584 +EXPORT_SYMBOL(gr_pid_is_chrooted);
57585 +
57586 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
57587 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
57588 +{
57589 + struct path path, currentroot;
57590 + int ret = 0;
57591 +
57592 + path.dentry = (struct dentry *)u_dentry;
57593 + path.mnt = (struct vfsmount *)u_mnt;
57594 + get_fs_root(current->fs, &currentroot);
57595 + if (path_is_under(&path, &currentroot))
57596 + ret = 1;
57597 + path_put(&currentroot);
57598 +
57599 + return ret;
57600 +}
57601 +#endif
57602 +
57603 +int
57604 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
57605 +{
57606 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
57607 + if (!grsec_enable_chroot_fchdir)
57608 + return 1;
57609 +
57610 + if (!proc_is_chrooted(current))
57611 + return 1;
57612 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
57613 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
57614 + return 0;
57615 + }
57616 +#endif
57617 + return 1;
57618 +}
57619 +
57620 +int
57621 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
57622 + const time_t shm_createtime)
57623 +{
57624 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
57625 + struct task_struct *p;
57626 + time_t starttime;
57627 +
57628 + if (unlikely(!grsec_enable_chroot_shmat))
57629 + return 1;
57630 +
57631 + if (likely(!proc_is_chrooted(current)))
57632 + return 1;
57633 +
57634 + rcu_read_lock();
57635 + read_lock(&tasklist_lock);
57636 +
57637 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
57638 + starttime = p->start_time.tv_sec;
57639 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
57640 + if (have_same_root(current, p)) {
57641 + goto allow;
57642 + } else {
57643 + read_unlock(&tasklist_lock);
57644 + rcu_read_unlock();
57645 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57646 + return 0;
57647 + }
57648 + }
57649 + /* creator exited, pid reuse, fall through to next check */
57650 + }
57651 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
57652 + if (unlikely(!have_same_root(current, p))) {
57653 + read_unlock(&tasklist_lock);
57654 + rcu_read_unlock();
57655 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
57656 + return 0;
57657 + }
57658 + }
57659 +
57660 +allow:
57661 + read_unlock(&tasklist_lock);
57662 + rcu_read_unlock();
57663 +#endif
57664 + return 1;
57665 +}
57666 +
57667 +void
57668 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
57669 +{
57670 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
57671 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
57672 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
57673 +#endif
57674 + return;
57675 +}
57676 +
57677 +int
57678 +gr_handle_chroot_mknod(const struct dentry *dentry,
57679 + const struct vfsmount *mnt, const int mode)
57680 +{
57681 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
57682 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
57683 + proc_is_chrooted(current)) {
57684 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
57685 + return -EPERM;
57686 + }
57687 +#endif
57688 + return 0;
57689 +}
57690 +
57691 +int
57692 +gr_handle_chroot_mount(const struct dentry *dentry,
57693 + const struct vfsmount *mnt, const char *dev_name)
57694 +{
57695 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
57696 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
57697 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
57698 + return -EPERM;
57699 + }
57700 +#endif
57701 + return 0;
57702 +}
57703 +
57704 +int
57705 +gr_handle_chroot_pivot(void)
57706 +{
57707 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
57708 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
57709 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
57710 + return -EPERM;
57711 + }
57712 +#endif
57713 + return 0;
57714 +}
57715 +
57716 +int
57717 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
57718 +{
57719 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
57720 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
57721 + !gr_is_outside_chroot(dentry, mnt)) {
57722 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
57723 + return -EPERM;
57724 + }
57725 +#endif
57726 + return 0;
57727 +}
57728 +
57729 +extern const char *captab_log[];
57730 +extern int captab_log_entries;
57731 +
57732 +int
57733 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
57734 +{
57735 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57736 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57737 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57738 + if (cap_raised(chroot_caps, cap)) {
57739 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
57740 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
57741 + }
57742 + return 0;
57743 + }
57744 + }
57745 +#endif
57746 + return 1;
57747 +}
57748 +
57749 +int
57750 +gr_chroot_is_capable(const int cap)
57751 +{
57752 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57753 + return gr_task_chroot_is_capable(current, current_cred(), cap);
57754 +#endif
57755 + return 1;
57756 +}
57757 +
57758 +int
57759 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
57760 +{
57761 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57762 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
57763 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
57764 + if (cap_raised(chroot_caps, cap)) {
57765 + return 0;
57766 + }
57767 + }
57768 +#endif
57769 + return 1;
57770 +}
57771 +
57772 +int
57773 +gr_chroot_is_capable_nolog(const int cap)
57774 +{
57775 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
57776 + return gr_task_chroot_is_capable_nolog(current, cap);
57777 +#endif
57778 + return 1;
57779 +}
57780 +
57781 +int
57782 +gr_handle_chroot_sysctl(const int op)
57783 +{
57784 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
57785 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
57786 + proc_is_chrooted(current))
57787 + return -EACCES;
57788 +#endif
57789 + return 0;
57790 +}
57791 +
57792 +void
57793 +gr_handle_chroot_chdir(struct path *path)
57794 +{
57795 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
57796 + if (grsec_enable_chroot_chdir)
57797 + set_fs_pwd(current->fs, path);
57798 +#endif
57799 + return;
57800 +}
57801 +
57802 +int
57803 +gr_handle_chroot_chmod(const struct dentry *dentry,
57804 + const struct vfsmount *mnt, const int mode)
57805 +{
57806 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
57807 + /* allow chmod +s on directories, but not files */
57808 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
57809 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
57810 + proc_is_chrooted(current)) {
57811 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
57812 + return -EPERM;
57813 + }
57814 +#endif
57815 + return 0;
57816 +}
57817 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
57818 new file mode 100644
57819 index 0000000..213ad8b
57820 --- /dev/null
57821 +++ b/grsecurity/grsec_disabled.c
57822 @@ -0,0 +1,437 @@
57823 +#include <linux/kernel.h>
57824 +#include <linux/module.h>
57825 +#include <linux/sched.h>
57826 +#include <linux/file.h>
57827 +#include <linux/fs.h>
57828 +#include <linux/kdev_t.h>
57829 +#include <linux/net.h>
57830 +#include <linux/in.h>
57831 +#include <linux/ip.h>
57832 +#include <linux/skbuff.h>
57833 +#include <linux/sysctl.h>
57834 +
57835 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57836 +void
57837 +pax_set_initial_flags(struct linux_binprm *bprm)
57838 +{
57839 + return;
57840 +}
57841 +#endif
57842 +
57843 +#ifdef CONFIG_SYSCTL
57844 +__u32
57845 +gr_handle_sysctl(const struct ctl_table * table, const int op)
57846 +{
57847 + return 0;
57848 +}
57849 +#endif
57850 +
57851 +#ifdef CONFIG_TASKSTATS
57852 +int gr_is_taskstats_denied(int pid)
57853 +{
57854 + return 0;
57855 +}
57856 +#endif
57857 +
57858 +int
57859 +gr_acl_is_enabled(void)
57860 +{
57861 + return 0;
57862 +}
57863 +
57864 +void
57865 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
57866 +{
57867 + return;
57868 +}
57869 +
57870 +int
57871 +gr_handle_rawio(const struct inode *inode)
57872 +{
57873 + return 0;
57874 +}
57875 +
57876 +void
57877 +gr_acl_handle_psacct(struct task_struct *task, const long code)
57878 +{
57879 + return;
57880 +}
57881 +
57882 +int
57883 +gr_handle_ptrace(struct task_struct *task, const long request)
57884 +{
57885 + return 0;
57886 +}
57887 +
57888 +int
57889 +gr_handle_proc_ptrace(struct task_struct *task)
57890 +{
57891 + return 0;
57892 +}
57893 +
57894 +void
57895 +gr_learn_resource(const struct task_struct *task,
57896 + const int res, const unsigned long wanted, const int gt)
57897 +{
57898 + return;
57899 +}
57900 +
57901 +int
57902 +gr_set_acls(const int type)
57903 +{
57904 + return 0;
57905 +}
57906 +
57907 +int
57908 +gr_check_hidden_task(const struct task_struct *tsk)
57909 +{
57910 + return 0;
57911 +}
57912 +
57913 +int
57914 +gr_check_protected_task(const struct task_struct *task)
57915 +{
57916 + return 0;
57917 +}
57918 +
57919 +int
57920 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
57921 +{
57922 + return 0;
57923 +}
57924 +
57925 +void
57926 +gr_copy_label(struct task_struct *tsk)
57927 +{
57928 + return;
57929 +}
57930 +
57931 +void
57932 +gr_set_pax_flags(struct task_struct *task)
57933 +{
57934 + return;
57935 +}
57936 +
57937 +int
57938 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
57939 + const int unsafe_share)
57940 +{
57941 + return 0;
57942 +}
57943 +
57944 +void
57945 +gr_handle_delete(const ino_t ino, const dev_t dev)
57946 +{
57947 + return;
57948 +}
57949 +
57950 +void
57951 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
57952 +{
57953 + return;
57954 +}
57955 +
57956 +void
57957 +gr_handle_crash(struct task_struct *task, const int sig)
57958 +{
57959 + return;
57960 +}
57961 +
57962 +int
57963 +gr_check_crash_exec(const struct file *filp)
57964 +{
57965 + return 0;
57966 +}
57967 +
57968 +int
57969 +gr_check_crash_uid(const uid_t uid)
57970 +{
57971 + return 0;
57972 +}
57973 +
57974 +void
57975 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
57976 + struct dentry *old_dentry,
57977 + struct dentry *new_dentry,
57978 + struct vfsmount *mnt, const __u8 replace)
57979 +{
57980 + return;
57981 +}
57982 +
57983 +int
57984 +gr_search_socket(const int family, const int type, const int protocol)
57985 +{
57986 + return 1;
57987 +}
57988 +
57989 +int
57990 +gr_search_connectbind(const int mode, const struct socket *sock,
57991 + const struct sockaddr_in *addr)
57992 +{
57993 + return 0;
57994 +}
57995 +
57996 +void
57997 +gr_handle_alertkill(struct task_struct *task)
57998 +{
57999 + return;
58000 +}
58001 +
58002 +__u32
58003 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
58004 +{
58005 + return 1;
58006 +}
58007 +
58008 +__u32
58009 +gr_acl_handle_hidden_file(const struct dentry * dentry,
58010 + const struct vfsmount * mnt)
58011 +{
58012 + return 1;
58013 +}
58014 +
58015 +__u32
58016 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
58017 + int acc_mode)
58018 +{
58019 + return 1;
58020 +}
58021 +
58022 +__u32
58023 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
58024 +{
58025 + return 1;
58026 +}
58027 +
58028 +__u32
58029 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
58030 +{
58031 + return 1;
58032 +}
58033 +
58034 +int
58035 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
58036 + unsigned int *vm_flags)
58037 +{
58038 + return 1;
58039 +}
58040 +
58041 +__u32
58042 +gr_acl_handle_truncate(const struct dentry * dentry,
58043 + const struct vfsmount * mnt)
58044 +{
58045 + return 1;
58046 +}
58047 +
58048 +__u32
58049 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
58050 +{
58051 + return 1;
58052 +}
58053 +
58054 +__u32
58055 +gr_acl_handle_access(const struct dentry * dentry,
58056 + const struct vfsmount * mnt, const int fmode)
58057 +{
58058 + return 1;
58059 +}
58060 +
58061 +__u32
58062 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
58063 + umode_t *mode)
58064 +{
58065 + return 1;
58066 +}
58067 +
58068 +__u32
58069 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
58070 +{
58071 + return 1;
58072 +}
58073 +
58074 +__u32
58075 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
58076 +{
58077 + return 1;
58078 +}
58079 +
58080 +void
58081 +grsecurity_init(void)
58082 +{
58083 + return;
58084 +}
58085 +
58086 +umode_t gr_acl_umask(void)
58087 +{
58088 + return 0;
58089 +}
58090 +
58091 +__u32
58092 +gr_acl_handle_mknod(const struct dentry * new_dentry,
58093 + const struct dentry * parent_dentry,
58094 + const struct vfsmount * parent_mnt,
58095 + const int mode)
58096 +{
58097 + return 1;
58098 +}
58099 +
58100 +__u32
58101 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
58102 + const struct dentry * parent_dentry,
58103 + const struct vfsmount * parent_mnt)
58104 +{
58105 + return 1;
58106 +}
58107 +
58108 +__u32
58109 +gr_acl_handle_symlink(const struct dentry * new_dentry,
58110 + const struct dentry * parent_dentry,
58111 + const struct vfsmount * parent_mnt, const char *from)
58112 +{
58113 + return 1;
58114 +}
58115 +
58116 +__u32
58117 +gr_acl_handle_link(const struct dentry * new_dentry,
58118 + const struct dentry * parent_dentry,
58119 + const struct vfsmount * parent_mnt,
58120 + const struct dentry * old_dentry,
58121 + const struct vfsmount * old_mnt, const char *to)
58122 +{
58123 + return 1;
58124 +}
58125 +
58126 +int
58127 +gr_acl_handle_rename(const struct dentry *new_dentry,
58128 + const struct dentry *parent_dentry,
58129 + const struct vfsmount *parent_mnt,
58130 + const struct dentry *old_dentry,
58131 + const struct inode *old_parent_inode,
58132 + const struct vfsmount *old_mnt, const char *newname)
58133 +{
58134 + return 0;
58135 +}
58136 +
58137 +int
58138 +gr_acl_handle_filldir(const struct file *file, const char *name,
58139 + const int namelen, const ino_t ino)
58140 +{
58141 + return 1;
58142 +}
58143 +
58144 +int
58145 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
58146 + const time_t shm_createtime, const uid_t cuid, const int shmid)
58147 +{
58148 + return 1;
58149 +}
58150 +
58151 +int
58152 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
58153 +{
58154 + return 0;
58155 +}
58156 +
58157 +int
58158 +gr_search_accept(const struct socket *sock)
58159 +{
58160 + return 0;
58161 +}
58162 +
58163 +int
58164 +gr_search_listen(const struct socket *sock)
58165 +{
58166 + return 0;
58167 +}
58168 +
58169 +int
58170 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
58171 +{
58172 + return 0;
58173 +}
58174 +
58175 +__u32
58176 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
58177 +{
58178 + return 1;
58179 +}
58180 +
58181 +__u32
58182 +gr_acl_handle_creat(const struct dentry * dentry,
58183 + const struct dentry * p_dentry,
58184 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
58185 + const int imode)
58186 +{
58187 + return 1;
58188 +}
58189 +
58190 +void
58191 +gr_acl_handle_exit(void)
58192 +{
58193 + return;
58194 +}
58195 +
58196 +int
58197 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
58198 +{
58199 + return 1;
58200 +}
58201 +
58202 +void
58203 +gr_set_role_label(const uid_t uid, const gid_t gid)
58204 +{
58205 + return;
58206 +}
58207 +
58208 +int
58209 +gr_acl_handle_procpidmem(const struct task_struct *task)
58210 +{
58211 + return 0;
58212 +}
58213 +
58214 +int
58215 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
58216 +{
58217 + return 0;
58218 +}
58219 +
58220 +int
58221 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
58222 +{
58223 + return 0;
58224 +}
58225 +
58226 +void
58227 +gr_set_kernel_label(struct task_struct *task)
58228 +{
58229 + return;
58230 +}
58231 +
58232 +int
58233 +gr_check_user_change(int real, int effective, int fs)
58234 +{
58235 + return 0;
58236 +}
58237 +
58238 +int
58239 +gr_check_group_change(int real, int effective, int fs)
58240 +{
58241 + return 0;
58242 +}
58243 +
58244 +int gr_acl_enable_at_secure(void)
58245 +{
58246 + return 0;
58247 +}
58248 +
58249 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
58250 +{
58251 + return dentry->d_inode->i_sb->s_dev;
58252 +}
58253 +
58254 +EXPORT_SYMBOL(gr_learn_resource);
58255 +EXPORT_SYMBOL(gr_set_kernel_label);
58256 +#ifdef CONFIG_SECURITY
58257 +EXPORT_SYMBOL(gr_check_user_change);
58258 +EXPORT_SYMBOL(gr_check_group_change);
58259 +#endif
58260 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
58261 new file mode 100644
58262 index 0000000..abfa971
58263 --- /dev/null
58264 +++ b/grsecurity/grsec_exec.c
58265 @@ -0,0 +1,174 @@
58266 +#include <linux/kernel.h>
58267 +#include <linux/sched.h>
58268 +#include <linux/file.h>
58269 +#include <linux/binfmts.h>
58270 +#include <linux/fs.h>
58271 +#include <linux/types.h>
58272 +#include <linux/grdefs.h>
58273 +#include <linux/grsecurity.h>
58274 +#include <linux/grinternal.h>
58275 +#include <linux/capability.h>
58276 +#include <linux/module.h>
58277 +
58278 +#include <asm/uaccess.h>
58279 +
58280 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58281 +static char gr_exec_arg_buf[132];
58282 +static DEFINE_MUTEX(gr_exec_arg_mutex);
58283 +#endif
58284 +
58285 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
58286 +
58287 +void
58288 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
58289 +{
58290 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58291 + char *grarg = gr_exec_arg_buf;
58292 + unsigned int i, x, execlen = 0;
58293 + char c;
58294 +
58295 + if (!((grsec_enable_execlog && grsec_enable_group &&
58296 + in_group_p(grsec_audit_gid))
58297 + || (grsec_enable_execlog && !grsec_enable_group)))
58298 + return;
58299 +
58300 + mutex_lock(&gr_exec_arg_mutex);
58301 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
58302 +
58303 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
58304 + const char __user *p;
58305 + unsigned int len;
58306 +
58307 + p = get_user_arg_ptr(argv, i);
58308 + if (IS_ERR(p))
58309 + goto log;
58310 +
58311 + len = strnlen_user(p, 128 - execlen);
58312 + if (len > 128 - execlen)
58313 + len = 128 - execlen;
58314 + else if (len > 0)
58315 + len--;
58316 + if (copy_from_user(grarg + execlen, p, len))
58317 + goto log;
58318 +
58319 + /* rewrite unprintable characters */
58320 + for (x = 0; x < len; x++) {
58321 + c = *(grarg + execlen + x);
58322 + if (c < 32 || c > 126)
58323 + *(grarg + execlen + x) = ' ';
58324 + }
58325 +
58326 + execlen += len;
58327 + *(grarg + execlen) = ' ';
58328 + *(grarg + execlen + 1) = '\0';
58329 + execlen++;
58330 + }
58331 +
58332 + log:
58333 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
58334 + bprm->file->f_path.mnt, grarg);
58335 + mutex_unlock(&gr_exec_arg_mutex);
58336 +#endif
58337 + return;
58338 +}
58339 +
58340 +#ifdef CONFIG_GRKERNSEC
58341 +extern int gr_acl_is_capable(const int cap);
58342 +extern int gr_acl_is_capable_nolog(const int cap);
58343 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58344 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
58345 +extern int gr_chroot_is_capable(const int cap);
58346 +extern int gr_chroot_is_capable_nolog(const int cap);
58347 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
58348 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
58349 +#endif
58350 +
58351 +const char *captab_log[] = {
58352 + "CAP_CHOWN",
58353 + "CAP_DAC_OVERRIDE",
58354 + "CAP_DAC_READ_SEARCH",
58355 + "CAP_FOWNER",
58356 + "CAP_FSETID",
58357 + "CAP_KILL",
58358 + "CAP_SETGID",
58359 + "CAP_SETUID",
58360 + "CAP_SETPCAP",
58361 + "CAP_LINUX_IMMUTABLE",
58362 + "CAP_NET_BIND_SERVICE",
58363 + "CAP_NET_BROADCAST",
58364 + "CAP_NET_ADMIN",
58365 + "CAP_NET_RAW",
58366 + "CAP_IPC_LOCK",
58367 + "CAP_IPC_OWNER",
58368 + "CAP_SYS_MODULE",
58369 + "CAP_SYS_RAWIO",
58370 + "CAP_SYS_CHROOT",
58371 + "CAP_SYS_PTRACE",
58372 + "CAP_SYS_PACCT",
58373 + "CAP_SYS_ADMIN",
58374 + "CAP_SYS_BOOT",
58375 + "CAP_SYS_NICE",
58376 + "CAP_SYS_RESOURCE",
58377 + "CAP_SYS_TIME",
58378 + "CAP_SYS_TTY_CONFIG",
58379 + "CAP_MKNOD",
58380 + "CAP_LEASE",
58381 + "CAP_AUDIT_WRITE",
58382 + "CAP_AUDIT_CONTROL",
58383 + "CAP_SETFCAP",
58384 + "CAP_MAC_OVERRIDE",
58385 + "CAP_MAC_ADMIN",
58386 + "CAP_SYSLOG",
58387 + "CAP_WAKE_ALARM"
58388 +};
58389 +
58390 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
58391 +
58392 +int gr_is_capable(const int cap)
58393 +{
58394 +#ifdef CONFIG_GRKERNSEC
58395 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
58396 + return 1;
58397 + return 0;
58398 +#else
58399 + return 1;
58400 +#endif
58401 +}
58402 +
58403 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
58404 +{
58405 +#ifdef CONFIG_GRKERNSEC
58406 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
58407 + return 1;
58408 + return 0;
58409 +#else
58410 + return 1;
58411 +#endif
58412 +}
58413 +
58414 +int gr_is_capable_nolog(const int cap)
58415 +{
58416 +#ifdef CONFIG_GRKERNSEC
58417 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
58418 + return 1;
58419 + return 0;
58420 +#else
58421 + return 1;
58422 +#endif
58423 +}
58424 +
58425 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
58426 +{
58427 +#ifdef CONFIG_GRKERNSEC
58428 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
58429 + return 1;
58430 + return 0;
58431 +#else
58432 + return 1;
58433 +#endif
58434 +}
58435 +
58436 +EXPORT_SYMBOL(gr_is_capable);
58437 +EXPORT_SYMBOL(gr_is_capable_nolog);
58438 +EXPORT_SYMBOL(gr_task_is_capable);
58439 +EXPORT_SYMBOL(gr_task_is_capable_nolog);
58440 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
58441 new file mode 100644
58442 index 0000000..d3ee748
58443 --- /dev/null
58444 +++ b/grsecurity/grsec_fifo.c
58445 @@ -0,0 +1,24 @@
58446 +#include <linux/kernel.h>
58447 +#include <linux/sched.h>
58448 +#include <linux/fs.h>
58449 +#include <linux/file.h>
58450 +#include <linux/grinternal.h>
58451 +
58452 +int
58453 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
58454 + const struct dentry *dir, const int flag, const int acc_mode)
58455 +{
58456 +#ifdef CONFIG_GRKERNSEC_FIFO
58457 + const struct cred *cred = current_cred();
58458 +
58459 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
58460 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
58461 + (dentry->d_inode->i_uid != dir->d_inode->i_uid) &&
58462 + (cred->fsuid != dentry->d_inode->i_uid)) {
58463 + if (!inode_permission(dentry->d_inode, acc_mode))
58464 + gr_log_fs_int2(GR_DONT_AUDIT, GR_FIFO_MSG, dentry, mnt, dentry->d_inode->i_uid, dentry->d_inode->i_gid);
58465 + return -EACCES;
58466 + }
58467 +#endif
58468 + return 0;
58469 +}
58470 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
58471 new file mode 100644
58472 index 0000000..8ca18bf
58473 --- /dev/null
58474 +++ b/grsecurity/grsec_fork.c
58475 @@ -0,0 +1,23 @@
58476 +#include <linux/kernel.h>
58477 +#include <linux/sched.h>
58478 +#include <linux/grsecurity.h>
58479 +#include <linux/grinternal.h>
58480 +#include <linux/errno.h>
58481 +
58482 +void
58483 +gr_log_forkfail(const int retval)
58484 +{
58485 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58486 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
58487 + switch (retval) {
58488 + case -EAGAIN:
58489 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
58490 + break;
58491 + case -ENOMEM:
58492 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
58493 + break;
58494 + }
58495 + }
58496 +#endif
58497 + return;
58498 +}
58499 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
58500 new file mode 100644
58501 index 0000000..05a6015
58502 --- /dev/null
58503 +++ b/grsecurity/grsec_init.c
58504 @@ -0,0 +1,283 @@
58505 +#include <linux/kernel.h>
58506 +#include <linux/sched.h>
58507 +#include <linux/mm.h>
58508 +#include <linux/gracl.h>
58509 +#include <linux/slab.h>
58510 +#include <linux/vmalloc.h>
58511 +#include <linux/percpu.h>
58512 +#include <linux/module.h>
58513 +
58514 +int grsec_enable_ptrace_readexec;
58515 +int grsec_enable_setxid;
58516 +int grsec_enable_symlinkown;
58517 +int grsec_symlinkown_gid;
58518 +int grsec_enable_brute;
58519 +int grsec_enable_link;
58520 +int grsec_enable_dmesg;
58521 +int grsec_enable_harden_ptrace;
58522 +int grsec_enable_fifo;
58523 +int grsec_enable_execlog;
58524 +int grsec_enable_signal;
58525 +int grsec_enable_forkfail;
58526 +int grsec_enable_audit_ptrace;
58527 +int grsec_enable_time;
58528 +int grsec_enable_audit_textrel;
58529 +int grsec_enable_group;
58530 +int grsec_audit_gid;
58531 +int grsec_enable_chdir;
58532 +int grsec_enable_mount;
58533 +int grsec_enable_rofs;
58534 +int grsec_enable_chroot_findtask;
58535 +int grsec_enable_chroot_mount;
58536 +int grsec_enable_chroot_shmat;
58537 +int grsec_enable_chroot_fchdir;
58538 +int grsec_enable_chroot_double;
58539 +int grsec_enable_chroot_pivot;
58540 +int grsec_enable_chroot_chdir;
58541 +int grsec_enable_chroot_chmod;
58542 +int grsec_enable_chroot_mknod;
58543 +int grsec_enable_chroot_nice;
58544 +int grsec_enable_chroot_execlog;
58545 +int grsec_enable_chroot_caps;
58546 +int grsec_enable_chroot_sysctl;
58547 +int grsec_enable_chroot_unix;
58548 +int grsec_enable_tpe;
58549 +int grsec_tpe_gid;
58550 +int grsec_enable_blackhole;
58551 +#ifdef CONFIG_IPV6_MODULE
58552 +EXPORT_SYMBOL(grsec_enable_blackhole);
58553 +#endif
58554 +int grsec_lastack_retries;
58555 +int grsec_enable_tpe_all;
58556 +int grsec_enable_tpe_invert;
58557 +int grsec_enable_socket_all;
58558 +int grsec_socket_all_gid;
58559 +int grsec_enable_socket_client;
58560 +int grsec_socket_client_gid;
58561 +int grsec_enable_socket_server;
58562 +int grsec_socket_server_gid;
58563 +int grsec_resource_logging;
58564 +int grsec_disable_privio;
58565 +int grsec_enable_log_rwxmaps;
58566 +int grsec_lock;
58567 +
58568 +DEFINE_SPINLOCK(grsec_alert_lock);
58569 +unsigned long grsec_alert_wtime = 0;
58570 +unsigned long grsec_alert_fyet = 0;
58571 +
58572 +DEFINE_SPINLOCK(grsec_audit_lock);
58573 +
58574 +DEFINE_RWLOCK(grsec_exec_file_lock);
58575 +
58576 +char *gr_shared_page[4];
58577 +
58578 +char *gr_alert_log_fmt;
58579 +char *gr_audit_log_fmt;
58580 +char *gr_alert_log_buf;
58581 +char *gr_audit_log_buf;
58582 +
58583 +extern struct gr_arg *gr_usermode;
58584 +extern unsigned char *gr_system_salt;
58585 +extern unsigned char *gr_system_sum;
58586 +
58587 +void __init
58588 +grsecurity_init(void)
58589 +{
58590 + int j;
58591 + /* create the per-cpu shared pages */
58592 +
58593 +#ifdef CONFIG_X86
58594 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
58595 +#endif
58596 +
58597 + for (j = 0; j < 4; j++) {
58598 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
58599 + if (gr_shared_page[j] == NULL) {
58600 + panic("Unable to allocate grsecurity shared page");
58601 + return;
58602 + }
58603 + }
58604 +
58605 + /* allocate log buffers */
58606 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
58607 + if (!gr_alert_log_fmt) {
58608 + panic("Unable to allocate grsecurity alert log format buffer");
58609 + return;
58610 + }
58611 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
58612 + if (!gr_audit_log_fmt) {
58613 + panic("Unable to allocate grsecurity audit log format buffer");
58614 + return;
58615 + }
58616 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58617 + if (!gr_alert_log_buf) {
58618 + panic("Unable to allocate grsecurity alert log buffer");
58619 + return;
58620 + }
58621 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
58622 + if (!gr_audit_log_buf) {
58623 + panic("Unable to allocate grsecurity audit log buffer");
58624 + return;
58625 + }
58626 +
58627 + /* allocate memory for authentication structure */
58628 + gr_usermode = kmalloc(sizeof(struct gr_arg), GFP_KERNEL);
58629 + gr_system_salt = kmalloc(GR_SALT_LEN, GFP_KERNEL);
58630 + gr_system_sum = kmalloc(GR_SHA_LEN, GFP_KERNEL);
58631 +
58632 + if (!gr_usermode || !gr_system_salt || !gr_system_sum) {
58633 + panic("Unable to allocate grsecurity authentication structure");
58634 + return;
58635 + }
58636 +
58637 +
58638 +#ifdef CONFIG_GRKERNSEC_IO
58639 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
58640 + grsec_disable_privio = 1;
58641 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58642 + grsec_disable_privio = 1;
58643 +#else
58644 + grsec_disable_privio = 0;
58645 +#endif
58646 +#endif
58647 +
58648 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
58649 + /* for backward compatibility, tpe_invert always defaults to on if
58650 + enabled in the kernel
58651 + */
58652 + grsec_enable_tpe_invert = 1;
58653 +#endif
58654 +
58655 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
58656 +#ifndef CONFIG_GRKERNSEC_SYSCTL
58657 + grsec_lock = 1;
58658 +#endif
58659 +
58660 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
58661 + grsec_enable_audit_textrel = 1;
58662 +#endif
58663 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
58664 + grsec_enable_log_rwxmaps = 1;
58665 +#endif
58666 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
58667 + grsec_enable_group = 1;
58668 + grsec_audit_gid = CONFIG_GRKERNSEC_AUDIT_GID;
58669 +#endif
58670 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
58671 + grsec_enable_ptrace_readexec = 1;
58672 +#endif
58673 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
58674 + grsec_enable_chdir = 1;
58675 +#endif
58676 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
58677 + grsec_enable_harden_ptrace = 1;
58678 +#endif
58679 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
58680 + grsec_enable_mount = 1;
58681 +#endif
58682 +#ifdef CONFIG_GRKERNSEC_LINK
58683 + grsec_enable_link = 1;
58684 +#endif
58685 +#ifdef CONFIG_GRKERNSEC_BRUTE
58686 + grsec_enable_brute = 1;
58687 +#endif
58688 +#ifdef CONFIG_GRKERNSEC_DMESG
58689 + grsec_enable_dmesg = 1;
58690 +#endif
58691 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
58692 + grsec_enable_blackhole = 1;
58693 + grsec_lastack_retries = 4;
58694 +#endif
58695 +#ifdef CONFIG_GRKERNSEC_FIFO
58696 + grsec_enable_fifo = 1;
58697 +#endif
58698 +#ifdef CONFIG_GRKERNSEC_EXECLOG
58699 + grsec_enable_execlog = 1;
58700 +#endif
58701 +#ifdef CONFIG_GRKERNSEC_SETXID
58702 + grsec_enable_setxid = 1;
58703 +#endif
58704 +#ifdef CONFIG_GRKERNSEC_SIGNAL
58705 + grsec_enable_signal = 1;
58706 +#endif
58707 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
58708 + grsec_enable_forkfail = 1;
58709 +#endif
58710 +#ifdef CONFIG_GRKERNSEC_TIME
58711 + grsec_enable_time = 1;
58712 +#endif
58713 +#ifdef CONFIG_GRKERNSEC_RESLOG
58714 + grsec_resource_logging = 1;
58715 +#endif
58716 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
58717 + grsec_enable_chroot_findtask = 1;
58718 +#endif
58719 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
58720 + grsec_enable_chroot_unix = 1;
58721 +#endif
58722 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
58723 + grsec_enable_chroot_mount = 1;
58724 +#endif
58725 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
58726 + grsec_enable_chroot_fchdir = 1;
58727 +#endif
58728 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
58729 + grsec_enable_chroot_shmat = 1;
58730 +#endif
58731 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
58732 + grsec_enable_audit_ptrace = 1;
58733 +#endif
58734 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
58735 + grsec_enable_chroot_double = 1;
58736 +#endif
58737 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
58738 + grsec_enable_chroot_pivot = 1;
58739 +#endif
58740 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
58741 + grsec_enable_chroot_chdir = 1;
58742 +#endif
58743 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
58744 + grsec_enable_chroot_chmod = 1;
58745 +#endif
58746 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
58747 + grsec_enable_chroot_mknod = 1;
58748 +#endif
58749 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
58750 + grsec_enable_chroot_nice = 1;
58751 +#endif
58752 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
58753 + grsec_enable_chroot_execlog = 1;
58754 +#endif
58755 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
58756 + grsec_enable_chroot_caps = 1;
58757 +#endif
58758 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
58759 + grsec_enable_chroot_sysctl = 1;
58760 +#endif
58761 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58762 + grsec_enable_symlinkown = 1;
58763 + grsec_symlinkown_gid = CONFIG_GRKERNSEC_SYMLINKOWN_GID;
58764 +#endif
58765 +#ifdef CONFIG_GRKERNSEC_TPE
58766 + grsec_enable_tpe = 1;
58767 + grsec_tpe_gid = CONFIG_GRKERNSEC_TPE_GID;
58768 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
58769 + grsec_enable_tpe_all = 1;
58770 +#endif
58771 +#endif
58772 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
58773 + grsec_enable_socket_all = 1;
58774 + grsec_socket_all_gid = CONFIG_GRKERNSEC_SOCKET_ALL_GID;
58775 +#endif
58776 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
58777 + grsec_enable_socket_client = 1;
58778 + grsec_socket_client_gid = CONFIG_GRKERNSEC_SOCKET_CLIENT_GID;
58779 +#endif
58780 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
58781 + grsec_enable_socket_server = 1;
58782 + grsec_socket_server_gid = CONFIG_GRKERNSEC_SOCKET_SERVER_GID;
58783 +#endif
58784 +#endif
58785 +
58786 + return;
58787 +}
58788 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
58789 new file mode 100644
58790 index 0000000..589481f
58791 --- /dev/null
58792 +++ b/grsecurity/grsec_link.c
58793 @@ -0,0 +1,58 @@
58794 +#include <linux/kernel.h>
58795 +#include <linux/sched.h>
58796 +#include <linux/fs.h>
58797 +#include <linux/file.h>
58798 +#include <linux/grinternal.h>
58799 +
58800 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
58801 +{
58802 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
58803 + const struct inode *link_inode = link->dentry->d_inode;
58804 +
58805 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
58806 + /* ignore root-owned links, e.g. /proc/self */
58807 + !uid_eq(link_inode->i_uid, GLOBAL_ROOT_UID) && target &&
58808 + !uid_eq(link_inode->i_uid, target->i_uid)) {
58809 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
58810 + return 1;
58811 + }
58812 +#endif
58813 + return 0;
58814 +}
58815 +
58816 +int
58817 +gr_handle_follow_link(const struct inode *parent,
58818 + const struct inode *inode,
58819 + const struct dentry *dentry, const struct vfsmount *mnt)
58820 +{
58821 +#ifdef CONFIG_GRKERNSEC_LINK
58822 + const struct cred *cred = current_cred();
58823 +
58824 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
58825 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
58826 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
58827 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
58828 + return -EACCES;
58829 + }
58830 +#endif
58831 + return 0;
58832 +}
58833 +
58834 +int
58835 +gr_handle_hardlink(const struct dentry *dentry,
58836 + const struct vfsmount *mnt,
58837 + struct inode *inode, const int mode, const char *to)
58838 +{
58839 +#ifdef CONFIG_GRKERNSEC_LINK
58840 + const struct cred *cred = current_cred();
58841 +
58842 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
58843 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
58844 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
58845 + !capable(CAP_FOWNER) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
58846 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to);
58847 + return -EPERM;
58848 + }
58849 +#endif
58850 + return 0;
58851 +}
58852 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
58853 new file mode 100644
58854 index 0000000..a45d2e9
58855 --- /dev/null
58856 +++ b/grsecurity/grsec_log.c
58857 @@ -0,0 +1,322 @@
58858 +#include <linux/kernel.h>
58859 +#include <linux/sched.h>
58860 +#include <linux/file.h>
58861 +#include <linux/tty.h>
58862 +#include <linux/fs.h>
58863 +#include <linux/grinternal.h>
58864 +
58865 +#ifdef CONFIG_TREE_PREEMPT_RCU
58866 +#define DISABLE_PREEMPT() preempt_disable()
58867 +#define ENABLE_PREEMPT() preempt_enable()
58868 +#else
58869 +#define DISABLE_PREEMPT()
58870 +#define ENABLE_PREEMPT()
58871 +#endif
58872 +
58873 +#define BEGIN_LOCKS(x) \
58874 + DISABLE_PREEMPT(); \
58875 + rcu_read_lock(); \
58876 + read_lock(&tasklist_lock); \
58877 + read_lock(&grsec_exec_file_lock); \
58878 + if (x != GR_DO_AUDIT) \
58879 + spin_lock(&grsec_alert_lock); \
58880 + else \
58881 + spin_lock(&grsec_audit_lock)
58882 +
58883 +#define END_LOCKS(x) \
58884 + if (x != GR_DO_AUDIT) \
58885 + spin_unlock(&grsec_alert_lock); \
58886 + else \
58887 + spin_unlock(&grsec_audit_lock); \
58888 + read_unlock(&grsec_exec_file_lock); \
58889 + read_unlock(&tasklist_lock); \
58890 + rcu_read_unlock(); \
58891 + ENABLE_PREEMPT(); \
58892 + if (x == GR_DONT_AUDIT) \
58893 + gr_handle_alertkill(current)
58894 +
58895 +enum {
58896 + FLOODING,
58897 + NO_FLOODING
58898 +};
58899 +
58900 +extern char *gr_alert_log_fmt;
58901 +extern char *gr_audit_log_fmt;
58902 +extern char *gr_alert_log_buf;
58903 +extern char *gr_audit_log_buf;
58904 +
58905 +static int gr_log_start(int audit)
58906 +{
58907 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
58908 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
58909 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58910 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
58911 + unsigned long curr_secs = get_seconds();
58912 +
58913 + if (audit == GR_DO_AUDIT)
58914 + goto set_fmt;
58915 +
58916 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
58917 + grsec_alert_wtime = curr_secs;
58918 + grsec_alert_fyet = 0;
58919 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
58920 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
58921 + grsec_alert_fyet++;
58922 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
58923 + grsec_alert_wtime = curr_secs;
58924 + grsec_alert_fyet++;
58925 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
58926 + return FLOODING;
58927 + }
58928 + else return FLOODING;
58929 +
58930 +set_fmt:
58931 +#endif
58932 + memset(buf, 0, PAGE_SIZE);
58933 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
58934 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
58935 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58936 + } else if (current->signal->curr_ip) {
58937 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
58938 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
58939 + } else if (gr_acl_is_enabled()) {
58940 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
58941 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
58942 + } else {
58943 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
58944 + strcpy(buf, fmt);
58945 + }
58946 +
58947 + return NO_FLOODING;
58948 +}
58949 +
58950 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58951 + __attribute__ ((format (printf, 2, 0)));
58952 +
58953 +static void gr_log_middle(int audit, const char *msg, va_list ap)
58954 +{
58955 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58956 + unsigned int len = strlen(buf);
58957 +
58958 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58959 +
58960 + return;
58961 +}
58962 +
58963 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58964 + __attribute__ ((format (printf, 2, 3)));
58965 +
58966 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
58967 +{
58968 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58969 + unsigned int len = strlen(buf);
58970 + va_list ap;
58971 +
58972 + va_start(ap, msg);
58973 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
58974 + va_end(ap);
58975 +
58976 + return;
58977 +}
58978 +
58979 +static void gr_log_end(int audit, int append_default)
58980 +{
58981 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
58982 +
58983 + if (append_default) {
58984 + unsigned int len = strlen(buf);
58985 + snprintf(buf + len, PAGE_SIZE - len - 1, DEFAULTSECMSG, DEFAULTSECARGS(current, current_cred(), __task_cred(current->real_parent)));
58986 + }
58987 +
58988 + printk("%s\n", buf);
58989 +
58990 + return;
58991 +}
58992 +
58993 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
58994 +{
58995 + int logtype;
58996 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
58997 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
58998 + void *voidptr = NULL;
58999 + int num1 = 0, num2 = 0;
59000 + unsigned long ulong1 = 0, ulong2 = 0;
59001 + struct dentry *dentry = NULL;
59002 + struct vfsmount *mnt = NULL;
59003 + struct file *file = NULL;
59004 + struct task_struct *task = NULL;
59005 + const struct cred *cred, *pcred;
59006 + va_list ap;
59007 +
59008 + BEGIN_LOCKS(audit);
59009 + logtype = gr_log_start(audit);
59010 + if (logtype == FLOODING) {
59011 + END_LOCKS(audit);
59012 + return;
59013 + }
59014 + va_start(ap, argtypes);
59015 + switch (argtypes) {
59016 + case GR_TTYSNIFF:
59017 + task = va_arg(ap, struct task_struct *);
59018 + gr_log_middle_varargs(audit, msg, &task->signal->curr_ip, gr_task_fullpath0(task), task->comm, task->pid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid);
59019 + break;
59020 + case GR_SYSCTL_HIDDEN:
59021 + str1 = va_arg(ap, char *);
59022 + gr_log_middle_varargs(audit, msg, result, str1);
59023 + break;
59024 + case GR_RBAC:
59025 + dentry = va_arg(ap, struct dentry *);
59026 + mnt = va_arg(ap, struct vfsmount *);
59027 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
59028 + break;
59029 + case GR_RBAC_STR:
59030 + dentry = va_arg(ap, struct dentry *);
59031 + mnt = va_arg(ap, struct vfsmount *);
59032 + str1 = va_arg(ap, char *);
59033 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
59034 + break;
59035 + case GR_STR_RBAC:
59036 + str1 = va_arg(ap, char *);
59037 + dentry = va_arg(ap, struct dentry *);
59038 + mnt = va_arg(ap, struct vfsmount *);
59039 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
59040 + break;
59041 + case GR_RBAC_MODE2:
59042 + dentry = va_arg(ap, struct dentry *);
59043 + mnt = va_arg(ap, struct vfsmount *);
59044 + str1 = va_arg(ap, char *);
59045 + str2 = va_arg(ap, char *);
59046 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
59047 + break;
59048 + case GR_RBAC_MODE3:
59049 + dentry = va_arg(ap, struct dentry *);
59050 + mnt = va_arg(ap, struct vfsmount *);
59051 + str1 = va_arg(ap, char *);
59052 + str2 = va_arg(ap, char *);
59053 + str3 = va_arg(ap, char *);
59054 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
59055 + break;
59056 + case GR_FILENAME:
59057 + dentry = va_arg(ap, struct dentry *);
59058 + mnt = va_arg(ap, struct vfsmount *);
59059 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
59060 + break;
59061 + case GR_STR_FILENAME:
59062 + str1 = va_arg(ap, char *);
59063 + dentry = va_arg(ap, struct dentry *);
59064 + mnt = va_arg(ap, struct vfsmount *);
59065 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
59066 + break;
59067 + case GR_FILENAME_STR:
59068 + dentry = va_arg(ap, struct dentry *);
59069 + mnt = va_arg(ap, struct vfsmount *);
59070 + str1 = va_arg(ap, char *);
59071 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
59072 + break;
59073 + case GR_FILENAME_TWO_INT:
59074 + dentry = va_arg(ap, struct dentry *);
59075 + mnt = va_arg(ap, struct vfsmount *);
59076 + num1 = va_arg(ap, int);
59077 + num2 = va_arg(ap, int);
59078 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
59079 + break;
59080 + case GR_FILENAME_TWO_INT_STR:
59081 + dentry = va_arg(ap, struct dentry *);
59082 + mnt = va_arg(ap, struct vfsmount *);
59083 + num1 = va_arg(ap, int);
59084 + num2 = va_arg(ap, int);
59085 + str1 = va_arg(ap, char *);
59086 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
59087 + break;
59088 + case GR_TEXTREL:
59089 + file = va_arg(ap, struct file *);
59090 + ulong1 = va_arg(ap, unsigned long);
59091 + ulong2 = va_arg(ap, unsigned long);
59092 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
59093 + break;
59094 + case GR_PTRACE:
59095 + task = va_arg(ap, struct task_struct *);
59096 + 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);
59097 + break;
59098 + case GR_RESOURCE:
59099 + task = va_arg(ap, struct task_struct *);
59100 + cred = __task_cred(task);
59101 + pcred = __task_cred(task->real_parent);
59102 + ulong1 = va_arg(ap, unsigned long);
59103 + str1 = va_arg(ap, char *);
59104 + ulong2 = va_arg(ap, unsigned long);
59105 + gr_log_middle_varargs(audit, msg, ulong1, str1, ulong2, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
59106 + break;
59107 + case GR_CAP:
59108 + task = va_arg(ap, struct task_struct *);
59109 + cred = __task_cred(task);
59110 + pcred = __task_cred(task->real_parent);
59111 + str1 = va_arg(ap, char *);
59112 + gr_log_middle_varargs(audit, msg, str1, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
59113 + break;
59114 + case GR_SIG:
59115 + str1 = va_arg(ap, char *);
59116 + voidptr = va_arg(ap, void *);
59117 + gr_log_middle_varargs(audit, msg, str1, voidptr);
59118 + break;
59119 + case GR_SIG2:
59120 + task = va_arg(ap, struct task_struct *);
59121 + cred = __task_cred(task);
59122 + pcred = __task_cred(task->real_parent);
59123 + num1 = va_arg(ap, int);
59124 + gr_log_middle_varargs(audit, msg, num1, gr_task_fullpath0(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath0(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid);
59125 + break;
59126 + case GR_CRASH1:
59127 + task = va_arg(ap, struct task_struct *);
59128 + cred = __task_cred(task);
59129 + pcred = __task_cred(task->real_parent);
59130 + ulong1 = va_arg(ap, unsigned long);
59131 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, cred->uid, ulong1);
59132 + break;
59133 + case GR_CRASH2:
59134 + task = va_arg(ap, struct task_struct *);
59135 + cred = __task_cred(task);
59136 + pcred = __task_cred(task->real_parent);
59137 + ulong1 = va_arg(ap, unsigned long);
59138 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, cred->uid, cred->euid, cred->gid, cred->egid, gr_parent_task_fullpath(task), task->real_parent->comm, task->real_parent->pid, pcred->uid, pcred->euid, pcred->gid, pcred->egid, ulong1);
59139 + break;
59140 + case GR_RWXMAP:
59141 + file = va_arg(ap, struct file *);
59142 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
59143 + break;
59144 + case GR_PSACCT:
59145 + {
59146 + unsigned int wday, cday;
59147 + __u8 whr, chr;
59148 + __u8 wmin, cmin;
59149 + __u8 wsec, csec;
59150 + char cur_tty[64] = { 0 };
59151 + char parent_tty[64] = { 0 };
59152 +
59153 + task = va_arg(ap, struct task_struct *);
59154 + wday = va_arg(ap, unsigned int);
59155 + cday = va_arg(ap, unsigned int);
59156 + whr = va_arg(ap, int);
59157 + chr = va_arg(ap, int);
59158 + wmin = va_arg(ap, int);
59159 + cmin = va_arg(ap, int);
59160 + wsec = va_arg(ap, int);
59161 + csec = va_arg(ap, int);
59162 + ulong1 = va_arg(ap, unsigned long);
59163 + cred = __task_cred(task);
59164 + pcred = __task_cred(task->real_parent);
59165 +
59166 + gr_log_middle_varargs(audit, msg, gr_task_fullpath(task), task->comm, task->pid, &task->signal->curr_ip, tty_name(task->signal->tty, cur_tty), cred->uid, cred->euid, cred->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->real_parent->pid, &task->real_parent->signal->curr_ip, tty_name(task->real_parent->signal->tty, parent_tty), pcred->uid, pcred->euid, pcred->gid, pcred->egid);
59167 + }
59168 + break;
59169 + default:
59170 + gr_log_middle(audit, msg, ap);
59171 + }
59172 + va_end(ap);
59173 + // these don't need DEFAULTSECARGS printed on the end
59174 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
59175 + gr_log_end(audit, 0);
59176 + else
59177 + gr_log_end(audit, 1);
59178 + END_LOCKS(audit);
59179 +}
59180 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
59181 new file mode 100644
59182 index 0000000..f536303
59183 --- /dev/null
59184 +++ b/grsecurity/grsec_mem.c
59185 @@ -0,0 +1,40 @@
59186 +#include <linux/kernel.h>
59187 +#include <linux/sched.h>
59188 +#include <linux/mm.h>
59189 +#include <linux/mman.h>
59190 +#include <linux/grinternal.h>
59191 +
59192 +void
59193 +gr_handle_ioperm(void)
59194 +{
59195 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
59196 + return;
59197 +}
59198 +
59199 +void
59200 +gr_handle_iopl(void)
59201 +{
59202 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
59203 + return;
59204 +}
59205 +
59206 +void
59207 +gr_handle_mem_readwrite(u64 from, u64 to)
59208 +{
59209 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
59210 + return;
59211 +}
59212 +
59213 +void
59214 +gr_handle_vm86(void)
59215 +{
59216 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
59217 + return;
59218 +}
59219 +
59220 +void
59221 +gr_log_badprocpid(const char *entry)
59222 +{
59223 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
59224 + return;
59225 +}
59226 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
59227 new file mode 100644
59228 index 0000000..2131422
59229 --- /dev/null
59230 +++ b/grsecurity/grsec_mount.c
59231 @@ -0,0 +1,62 @@
59232 +#include <linux/kernel.h>
59233 +#include <linux/sched.h>
59234 +#include <linux/mount.h>
59235 +#include <linux/grsecurity.h>
59236 +#include <linux/grinternal.h>
59237 +
59238 +void
59239 +gr_log_remount(const char *devname, const int retval)
59240 +{
59241 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59242 + if (grsec_enable_mount && (retval >= 0))
59243 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
59244 +#endif
59245 + return;
59246 +}
59247 +
59248 +void
59249 +gr_log_unmount(const char *devname, const int retval)
59250 +{
59251 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59252 + if (grsec_enable_mount && (retval >= 0))
59253 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
59254 +#endif
59255 + return;
59256 +}
59257 +
59258 +void
59259 +gr_log_mount(const char *from, const char *to, const int retval)
59260 +{
59261 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
59262 + if (grsec_enable_mount && (retval >= 0))
59263 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
59264 +#endif
59265 + return;
59266 +}
59267 +
59268 +int
59269 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
59270 +{
59271 +#ifdef CONFIG_GRKERNSEC_ROFS
59272 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
59273 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
59274 + return -EPERM;
59275 + } else
59276 + return 0;
59277 +#endif
59278 + return 0;
59279 +}
59280 +
59281 +int
59282 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
59283 +{
59284 +#ifdef CONFIG_GRKERNSEC_ROFS
59285 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
59286 + dentry->d_inode && S_ISBLK(dentry->d_inode->i_mode)) {
59287 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
59288 + return -EPERM;
59289 + } else
59290 + return 0;
59291 +#endif
59292 + return 0;
59293 +}
59294 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
59295 new file mode 100644
59296 index 0000000..a3b12a0
59297 --- /dev/null
59298 +++ b/grsecurity/grsec_pax.c
59299 @@ -0,0 +1,36 @@
59300 +#include <linux/kernel.h>
59301 +#include <linux/sched.h>
59302 +#include <linux/mm.h>
59303 +#include <linux/file.h>
59304 +#include <linux/grinternal.h>
59305 +#include <linux/grsecurity.h>
59306 +
59307 +void
59308 +gr_log_textrel(struct vm_area_struct * vma)
59309 +{
59310 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
59311 + if (grsec_enable_audit_textrel)
59312 + gr_log_textrel_ulong_ulong(GR_DO_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
59313 +#endif
59314 + return;
59315 +}
59316 +
59317 +void
59318 +gr_log_rwxmmap(struct file *file)
59319 +{
59320 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59321 + if (grsec_enable_log_rwxmaps)
59322 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
59323 +#endif
59324 + return;
59325 +}
59326 +
59327 +void
59328 +gr_log_rwxmprotect(struct file *file)
59329 +{
59330 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59331 + if (grsec_enable_log_rwxmaps)
59332 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, file);
59333 +#endif
59334 + return;
59335 +}
59336 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
59337 new file mode 100644
59338 index 0000000..f7f29aa
59339 --- /dev/null
59340 +++ b/grsecurity/grsec_ptrace.c
59341 @@ -0,0 +1,30 @@
59342 +#include <linux/kernel.h>
59343 +#include <linux/sched.h>
59344 +#include <linux/grinternal.h>
59345 +#include <linux/security.h>
59346 +
59347 +void
59348 +gr_audit_ptrace(struct task_struct *task)
59349 +{
59350 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
59351 + if (grsec_enable_audit_ptrace)
59352 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
59353 +#endif
59354 + return;
59355 +}
59356 +
59357 +int
59358 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
59359 +{
59360 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59361 + const struct dentry *dentry = file->f_path.dentry;
59362 + const struct vfsmount *mnt = file->f_path.mnt;
59363 +
59364 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
59365 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
59366 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
59367 + return -EACCES;
59368 + }
59369 +#endif
59370 + return 0;
59371 +}
59372 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
59373 new file mode 100644
59374 index 0000000..b4ac94c
59375 --- /dev/null
59376 +++ b/grsecurity/grsec_sig.c
59377 @@ -0,0 +1,209 @@
59378 +#include <linux/kernel.h>
59379 +#include <linux/sched.h>
59380 +#include <linux/delay.h>
59381 +#include <linux/grsecurity.h>
59382 +#include <linux/grinternal.h>
59383 +#include <linux/hardirq.h>
59384 +
59385 +char *signames[] = {
59386 + [SIGSEGV] = "Segmentation fault",
59387 + [SIGILL] = "Illegal instruction",
59388 + [SIGABRT] = "Abort",
59389 + [SIGBUS] = "Invalid alignment/Bus error"
59390 +};
59391 +
59392 +void
59393 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
59394 +{
59395 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59396 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
59397 + (sig == SIGABRT) || (sig == SIGBUS))) {
59398 + if (t->pid == current->pid) {
59399 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
59400 + } else {
59401 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
59402 + }
59403 + }
59404 +#endif
59405 + return;
59406 +}
59407 +
59408 +int
59409 +gr_handle_signal(const struct task_struct *p, const int sig)
59410 +{
59411 +#ifdef CONFIG_GRKERNSEC
59412 + /* ignore the 0 signal for protected task checks */
59413 + if (current->pid > 1 && sig && gr_check_protected_task(p)) {
59414 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
59415 + return -EPERM;
59416 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
59417 + return -EPERM;
59418 + }
59419 +#endif
59420 + return 0;
59421 +}
59422 +
59423 +#ifdef CONFIG_GRKERNSEC
59424 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
59425 +
59426 +int gr_fake_force_sig(int sig, struct task_struct *t)
59427 +{
59428 + unsigned long int flags;
59429 + int ret, blocked, ignored;
59430 + struct k_sigaction *action;
59431 +
59432 + spin_lock_irqsave(&t->sighand->siglock, flags);
59433 + action = &t->sighand->action[sig-1];
59434 + ignored = action->sa.sa_handler == SIG_IGN;
59435 + blocked = sigismember(&t->blocked, sig);
59436 + if (blocked || ignored) {
59437 + action->sa.sa_handler = SIG_DFL;
59438 + if (blocked) {
59439 + sigdelset(&t->blocked, sig);
59440 + recalc_sigpending_and_wake(t);
59441 + }
59442 + }
59443 + if (action->sa.sa_handler == SIG_DFL)
59444 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
59445 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
59446 +
59447 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
59448 +
59449 + return ret;
59450 +}
59451 +#endif
59452 +
59453 +#ifdef CONFIG_GRKERNSEC_BRUTE
59454 +#define GR_USER_BAN_TIME (15 * 60)
59455 +
59456 +static int __get_dumpable(unsigned long mm_flags)
59457 +{
59458 + int ret;
59459 +
59460 + ret = mm_flags & MMF_DUMPABLE_MASK;
59461 + return (ret >= 2) ? 2 : ret;
59462 +}
59463 +#endif
59464 +
59465 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags)
59466 +{
59467 +#ifdef CONFIG_GRKERNSEC_BRUTE
59468 + kuid_t uid = GLOBAL_ROOT_UID;
59469 +
59470 + if (!grsec_enable_brute)
59471 + return;
59472 +
59473 + rcu_read_lock();
59474 + read_lock(&tasklist_lock);
59475 + read_lock(&grsec_exec_file_lock);
59476 + if (p->real_parent && p->real_parent->exec_file == p->exec_file)
59477 + p->real_parent->brute = 1;
59478 + else {
59479 + const struct cred *cred = __task_cred(p), *cred2;
59480 + struct task_struct *tsk, *tsk2;
59481 +
59482 + if (!__get_dumpable(mm_flags) && !uid_eq(cred->uid, GLOBAL_ROOT_UID)) {
59483 + struct user_struct *user;
59484 +
59485 + uid = cred->uid;
59486 +
59487 + /* this is put upon execution past expiration */
59488 + user = find_user(uid);
59489 + if (user == NULL)
59490 + goto unlock;
59491 + user->banned = 1;
59492 + user->ban_expires = get_seconds() + GR_USER_BAN_TIME;
59493 + if (user->ban_expires == ~0UL)
59494 + user->ban_expires--;
59495 +
59496 + do_each_thread(tsk2, tsk) {
59497 + cred2 = __task_cred(tsk);
59498 + if (tsk != p && uid_eq(cred2->uid, uid))
59499 + gr_fake_force_sig(SIGKILL, tsk);
59500 + } while_each_thread(tsk2, tsk);
59501 + }
59502 + }
59503 +unlock:
59504 + read_unlock(&grsec_exec_file_lock);
59505 + read_unlock(&tasklist_lock);
59506 + rcu_read_unlock();
59507 +
59508 + if (!uid_eq(uid, GLOBAL_ROOT_UID))
59509 + printk(KERN_ALERT "grsec: bruteforce prevention initiated against uid %u, banning for %d minutes\n",
59510 + from_kuid_munged(&init_user_ns, uid), GR_USER_BAN_TIME / 60);
59511 +
59512 +#endif
59513 + return;
59514 +}
59515 +
59516 +void gr_handle_brute_check(void)
59517 +{
59518 +#ifdef CONFIG_GRKERNSEC_BRUTE
59519 + if (current->brute)
59520 + msleep(30 * 1000);
59521 +#endif
59522 + return;
59523 +}
59524 +
59525 +void gr_handle_kernel_exploit(void)
59526 +{
59527 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
59528 + const struct cred *cred;
59529 + struct task_struct *tsk, *tsk2;
59530 + struct user_struct *user;
59531 + kuid_t uid;
59532 +
59533 + if (in_irq() || in_serving_softirq() || in_nmi())
59534 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
59535 +
59536 + uid = current_uid();
59537 +
59538 + if (uid_eq(uid, GLOBAL_ROOT_UID))
59539 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
59540 + else {
59541 + /* kill all the processes of this user, hold a reference
59542 + to their creds struct, and prevent them from creating
59543 + another process until system reset
59544 + */
59545 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
59546 + from_kuid_munged(&init_user_ns, uid));
59547 + /* we intentionally leak this ref */
59548 + user = get_uid(current->cred->user);
59549 + if (user) {
59550 + user->banned = 1;
59551 + user->ban_expires = ~0UL;
59552 + }
59553 +
59554 + read_lock(&tasklist_lock);
59555 + do_each_thread(tsk2, tsk) {
59556 + cred = __task_cred(tsk);
59557 + if (uid_eq(cred->uid, uid))
59558 + gr_fake_force_sig(SIGKILL, tsk);
59559 + } while_each_thread(tsk2, tsk);
59560 + read_unlock(&tasklist_lock);
59561 + }
59562 +#endif
59563 +}
59564 +
59565 +int __gr_process_user_ban(struct user_struct *user)
59566 +{
59567 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59568 + if (unlikely(user->banned)) {
59569 + if (user->ban_expires != ~0UL && time_after_eq(get_seconds(), user->ban_expires)) {
59570 + user->banned = 0;
59571 + user->ban_expires = 0;
59572 + free_uid(user);
59573 + } else
59574 + return -EPERM;
59575 + }
59576 +#endif
59577 + return 0;
59578 +}
59579 +
59580 +int gr_process_user_ban(void)
59581 +{
59582 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
59583 + return __gr_process_user_ban(current->cred->user);
59584 +#endif
59585 + return 0;
59586 +}
59587 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
59588 new file mode 100644
59589 index 0000000..4030d57
59590 --- /dev/null
59591 +++ b/grsecurity/grsec_sock.c
59592 @@ -0,0 +1,244 @@
59593 +#include <linux/kernel.h>
59594 +#include <linux/module.h>
59595 +#include <linux/sched.h>
59596 +#include <linux/file.h>
59597 +#include <linux/net.h>
59598 +#include <linux/in.h>
59599 +#include <linux/ip.h>
59600 +#include <net/sock.h>
59601 +#include <net/inet_sock.h>
59602 +#include <linux/grsecurity.h>
59603 +#include <linux/grinternal.h>
59604 +#include <linux/gracl.h>
59605 +
59606 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
59607 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
59608 +
59609 +EXPORT_SYMBOL(gr_search_udp_recvmsg);
59610 +EXPORT_SYMBOL(gr_search_udp_sendmsg);
59611 +
59612 +#ifdef CONFIG_UNIX_MODULE
59613 +EXPORT_SYMBOL(gr_acl_handle_unix);
59614 +EXPORT_SYMBOL(gr_acl_handle_mknod);
59615 +EXPORT_SYMBOL(gr_handle_chroot_unix);
59616 +EXPORT_SYMBOL(gr_handle_create);
59617 +#endif
59618 +
59619 +#ifdef CONFIG_GRKERNSEC
59620 +#define gr_conn_table_size 32749
59621 +struct conn_table_entry {
59622 + struct conn_table_entry *next;
59623 + struct signal_struct *sig;
59624 +};
59625 +
59626 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
59627 +DEFINE_SPINLOCK(gr_conn_table_lock);
59628 +
59629 +extern const char * gr_socktype_to_name(unsigned char type);
59630 +extern const char * gr_proto_to_name(unsigned char proto);
59631 +extern const char * gr_sockfamily_to_name(unsigned char family);
59632 +
59633 +static __inline__ int
59634 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
59635 +{
59636 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
59637 +}
59638 +
59639 +static __inline__ int
59640 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
59641 + __u16 sport, __u16 dport)
59642 +{
59643 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
59644 + sig->gr_sport == sport && sig->gr_dport == dport))
59645 + return 1;
59646 + else
59647 + return 0;
59648 +}
59649 +
59650 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
59651 +{
59652 + struct conn_table_entry **match;
59653 + unsigned int index;
59654 +
59655 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59656 + sig->gr_sport, sig->gr_dport,
59657 + gr_conn_table_size);
59658 +
59659 + newent->sig = sig;
59660 +
59661 + match = &gr_conn_table[index];
59662 + newent->next = *match;
59663 + *match = newent;
59664 +
59665 + return;
59666 +}
59667 +
59668 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
59669 +{
59670 + struct conn_table_entry *match, *last = NULL;
59671 + unsigned int index;
59672 +
59673 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
59674 + sig->gr_sport, sig->gr_dport,
59675 + gr_conn_table_size);
59676 +
59677 + match = gr_conn_table[index];
59678 + while (match && !conn_match(match->sig,
59679 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
59680 + sig->gr_dport)) {
59681 + last = match;
59682 + match = match->next;
59683 + }
59684 +
59685 + if (match) {
59686 + if (last)
59687 + last->next = match->next;
59688 + else
59689 + gr_conn_table[index] = NULL;
59690 + kfree(match);
59691 + }
59692 +
59693 + return;
59694 +}
59695 +
59696 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
59697 + __u16 sport, __u16 dport)
59698 +{
59699 + struct conn_table_entry *match;
59700 + unsigned int index;
59701 +
59702 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
59703 +
59704 + match = gr_conn_table[index];
59705 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
59706 + match = match->next;
59707 +
59708 + if (match)
59709 + return match->sig;
59710 + else
59711 + return NULL;
59712 +}
59713 +
59714 +#endif
59715 +
59716 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
59717 +{
59718 +#ifdef CONFIG_GRKERNSEC
59719 + struct signal_struct *sig = task->signal;
59720 + struct conn_table_entry *newent;
59721 +
59722 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
59723 + if (newent == NULL)
59724 + return;
59725 + /* no bh lock needed since we are called with bh disabled */
59726 + spin_lock(&gr_conn_table_lock);
59727 + gr_del_task_from_ip_table_nolock(sig);
59728 + sig->gr_saddr = inet->inet_rcv_saddr;
59729 + sig->gr_daddr = inet->inet_daddr;
59730 + sig->gr_sport = inet->inet_sport;
59731 + sig->gr_dport = inet->inet_dport;
59732 + gr_add_to_task_ip_table_nolock(sig, newent);
59733 + spin_unlock(&gr_conn_table_lock);
59734 +#endif
59735 + return;
59736 +}
59737 +
59738 +void gr_del_task_from_ip_table(struct task_struct *task)
59739 +{
59740 +#ifdef CONFIG_GRKERNSEC
59741 + spin_lock_bh(&gr_conn_table_lock);
59742 + gr_del_task_from_ip_table_nolock(task->signal);
59743 + spin_unlock_bh(&gr_conn_table_lock);
59744 +#endif
59745 + return;
59746 +}
59747 +
59748 +void
59749 +gr_attach_curr_ip(const struct sock *sk)
59750 +{
59751 +#ifdef CONFIG_GRKERNSEC
59752 + struct signal_struct *p, *set;
59753 + const struct inet_sock *inet = inet_sk(sk);
59754 +
59755 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
59756 + return;
59757 +
59758 + set = current->signal;
59759 +
59760 + spin_lock_bh(&gr_conn_table_lock);
59761 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
59762 + inet->inet_dport, inet->inet_sport);
59763 + if (unlikely(p != NULL)) {
59764 + set->curr_ip = p->curr_ip;
59765 + set->used_accept = 1;
59766 + gr_del_task_from_ip_table_nolock(p);
59767 + spin_unlock_bh(&gr_conn_table_lock);
59768 + return;
59769 + }
59770 + spin_unlock_bh(&gr_conn_table_lock);
59771 +
59772 + set->curr_ip = inet->inet_daddr;
59773 + set->used_accept = 1;
59774 +#endif
59775 + return;
59776 +}
59777 +
59778 +int
59779 +gr_handle_sock_all(const int family, const int type, const int protocol)
59780 +{
59781 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
59782 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
59783 + (family != AF_UNIX)) {
59784 + if (family == AF_INET)
59785 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
59786 + else
59787 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
59788 + return -EACCES;
59789 + }
59790 +#endif
59791 + return 0;
59792 +}
59793 +
59794 +int
59795 +gr_handle_sock_server(const struct sockaddr *sck)
59796 +{
59797 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59798 + if (grsec_enable_socket_server &&
59799 + in_group_p(grsec_socket_server_gid) &&
59800 + sck && (sck->sa_family != AF_UNIX) &&
59801 + (sck->sa_family != AF_LOCAL)) {
59802 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59803 + return -EACCES;
59804 + }
59805 +#endif
59806 + return 0;
59807 +}
59808 +
59809 +int
59810 +gr_handle_sock_server_other(const struct sock *sck)
59811 +{
59812 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
59813 + if (grsec_enable_socket_server &&
59814 + in_group_p(grsec_socket_server_gid) &&
59815 + sck && (sck->sk_family != AF_UNIX) &&
59816 + (sck->sk_family != AF_LOCAL)) {
59817 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
59818 + return -EACCES;
59819 + }
59820 +#endif
59821 + return 0;
59822 +}
59823 +
59824 +int
59825 +gr_handle_sock_client(const struct sockaddr *sck)
59826 +{
59827 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
59828 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
59829 + sck && (sck->sa_family != AF_UNIX) &&
59830 + (sck->sa_family != AF_LOCAL)) {
59831 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
59832 + return -EACCES;
59833 + }
59834 +#endif
59835 + return 0;
59836 +}
59837 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
59838 new file mode 100644
59839 index 0000000..f55ef0f
59840 --- /dev/null
59841 +++ b/grsecurity/grsec_sysctl.c
59842 @@ -0,0 +1,469 @@
59843 +#include <linux/kernel.h>
59844 +#include <linux/sched.h>
59845 +#include <linux/sysctl.h>
59846 +#include <linux/grsecurity.h>
59847 +#include <linux/grinternal.h>
59848 +
59849 +int
59850 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
59851 +{
59852 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59853 + if (dirname == NULL || name == NULL)
59854 + return 0;
59855 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
59856 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
59857 + return -EACCES;
59858 + }
59859 +#endif
59860 + return 0;
59861 +}
59862 +
59863 +#ifdef CONFIG_GRKERNSEC_ROFS
59864 +static int __maybe_unused one = 1;
59865 +#endif
59866 +
59867 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
59868 +struct ctl_table grsecurity_table[] = {
59869 +#ifdef CONFIG_GRKERNSEC_SYSCTL
59870 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
59871 +#ifdef CONFIG_GRKERNSEC_IO
59872 + {
59873 + .procname = "disable_priv_io",
59874 + .data = &grsec_disable_privio,
59875 + .maxlen = sizeof(int),
59876 + .mode = 0600,
59877 + .proc_handler = &proc_dointvec,
59878 + },
59879 +#endif
59880 +#endif
59881 +#ifdef CONFIG_GRKERNSEC_LINK
59882 + {
59883 + .procname = "linking_restrictions",
59884 + .data = &grsec_enable_link,
59885 + .maxlen = sizeof(int),
59886 + .mode = 0600,
59887 + .proc_handler = &proc_dointvec,
59888 + },
59889 +#endif
59890 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
59891 + {
59892 + .procname = "enforce_symlinksifowner",
59893 + .data = &grsec_enable_symlinkown,
59894 + .maxlen = sizeof(int),
59895 + .mode = 0600,
59896 + .proc_handler = &proc_dointvec,
59897 + },
59898 + {
59899 + .procname = "symlinkown_gid",
59900 + .data = &grsec_symlinkown_gid,
59901 + .maxlen = sizeof(int),
59902 + .mode = 0600,
59903 + .proc_handler = &proc_dointvec,
59904 + },
59905 +#endif
59906 +#ifdef CONFIG_GRKERNSEC_BRUTE
59907 + {
59908 + .procname = "deter_bruteforce",
59909 + .data = &grsec_enable_brute,
59910 + .maxlen = sizeof(int),
59911 + .mode = 0600,
59912 + .proc_handler = &proc_dointvec,
59913 + },
59914 +#endif
59915 +#ifdef CONFIG_GRKERNSEC_FIFO
59916 + {
59917 + .procname = "fifo_restrictions",
59918 + .data = &grsec_enable_fifo,
59919 + .maxlen = sizeof(int),
59920 + .mode = 0600,
59921 + .proc_handler = &proc_dointvec,
59922 + },
59923 +#endif
59924 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
59925 + {
59926 + .procname = "ptrace_readexec",
59927 + .data = &grsec_enable_ptrace_readexec,
59928 + .maxlen = sizeof(int),
59929 + .mode = 0600,
59930 + .proc_handler = &proc_dointvec,
59931 + },
59932 +#endif
59933 +#ifdef CONFIG_GRKERNSEC_SETXID
59934 + {
59935 + .procname = "consistent_setxid",
59936 + .data = &grsec_enable_setxid,
59937 + .maxlen = sizeof(int),
59938 + .mode = 0600,
59939 + .proc_handler = &proc_dointvec,
59940 + },
59941 +#endif
59942 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
59943 + {
59944 + .procname = "ip_blackhole",
59945 + .data = &grsec_enable_blackhole,
59946 + .maxlen = sizeof(int),
59947 + .mode = 0600,
59948 + .proc_handler = &proc_dointvec,
59949 + },
59950 + {
59951 + .procname = "lastack_retries",
59952 + .data = &grsec_lastack_retries,
59953 + .maxlen = sizeof(int),
59954 + .mode = 0600,
59955 + .proc_handler = &proc_dointvec,
59956 + },
59957 +#endif
59958 +#ifdef CONFIG_GRKERNSEC_EXECLOG
59959 + {
59960 + .procname = "exec_logging",
59961 + .data = &grsec_enable_execlog,
59962 + .maxlen = sizeof(int),
59963 + .mode = 0600,
59964 + .proc_handler = &proc_dointvec,
59965 + },
59966 +#endif
59967 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
59968 + {
59969 + .procname = "rwxmap_logging",
59970 + .data = &grsec_enable_log_rwxmaps,
59971 + .maxlen = sizeof(int),
59972 + .mode = 0600,
59973 + .proc_handler = &proc_dointvec,
59974 + },
59975 +#endif
59976 +#ifdef CONFIG_GRKERNSEC_SIGNAL
59977 + {
59978 + .procname = "signal_logging",
59979 + .data = &grsec_enable_signal,
59980 + .maxlen = sizeof(int),
59981 + .mode = 0600,
59982 + .proc_handler = &proc_dointvec,
59983 + },
59984 +#endif
59985 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
59986 + {
59987 + .procname = "forkfail_logging",
59988 + .data = &grsec_enable_forkfail,
59989 + .maxlen = sizeof(int),
59990 + .mode = 0600,
59991 + .proc_handler = &proc_dointvec,
59992 + },
59993 +#endif
59994 +#ifdef CONFIG_GRKERNSEC_TIME
59995 + {
59996 + .procname = "timechange_logging",
59997 + .data = &grsec_enable_time,
59998 + .maxlen = sizeof(int),
59999 + .mode = 0600,
60000 + .proc_handler = &proc_dointvec,
60001 + },
60002 +#endif
60003 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
60004 + {
60005 + .procname = "chroot_deny_shmat",
60006 + .data = &grsec_enable_chroot_shmat,
60007 + .maxlen = sizeof(int),
60008 + .mode = 0600,
60009 + .proc_handler = &proc_dointvec,
60010 + },
60011 +#endif
60012 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
60013 + {
60014 + .procname = "chroot_deny_unix",
60015 + .data = &grsec_enable_chroot_unix,
60016 + .maxlen = sizeof(int),
60017 + .mode = 0600,
60018 + .proc_handler = &proc_dointvec,
60019 + },
60020 +#endif
60021 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
60022 + {
60023 + .procname = "chroot_deny_mount",
60024 + .data = &grsec_enable_chroot_mount,
60025 + .maxlen = sizeof(int),
60026 + .mode = 0600,
60027 + .proc_handler = &proc_dointvec,
60028 + },
60029 +#endif
60030 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
60031 + {
60032 + .procname = "chroot_deny_fchdir",
60033 + .data = &grsec_enable_chroot_fchdir,
60034 + .maxlen = sizeof(int),
60035 + .mode = 0600,
60036 + .proc_handler = &proc_dointvec,
60037 + },
60038 +#endif
60039 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
60040 + {
60041 + .procname = "chroot_deny_chroot",
60042 + .data = &grsec_enable_chroot_double,
60043 + .maxlen = sizeof(int),
60044 + .mode = 0600,
60045 + .proc_handler = &proc_dointvec,
60046 + },
60047 +#endif
60048 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
60049 + {
60050 + .procname = "chroot_deny_pivot",
60051 + .data = &grsec_enable_chroot_pivot,
60052 + .maxlen = sizeof(int),
60053 + .mode = 0600,
60054 + .proc_handler = &proc_dointvec,
60055 + },
60056 +#endif
60057 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
60058 + {
60059 + .procname = "chroot_enforce_chdir",
60060 + .data = &grsec_enable_chroot_chdir,
60061 + .maxlen = sizeof(int),
60062 + .mode = 0600,
60063 + .proc_handler = &proc_dointvec,
60064 + },
60065 +#endif
60066 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
60067 + {
60068 + .procname = "chroot_deny_chmod",
60069 + .data = &grsec_enable_chroot_chmod,
60070 + .maxlen = sizeof(int),
60071 + .mode = 0600,
60072 + .proc_handler = &proc_dointvec,
60073 + },
60074 +#endif
60075 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
60076 + {
60077 + .procname = "chroot_deny_mknod",
60078 + .data = &grsec_enable_chroot_mknod,
60079 + .maxlen = sizeof(int),
60080 + .mode = 0600,
60081 + .proc_handler = &proc_dointvec,
60082 + },
60083 +#endif
60084 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
60085 + {
60086 + .procname = "chroot_restrict_nice",
60087 + .data = &grsec_enable_chroot_nice,
60088 + .maxlen = sizeof(int),
60089 + .mode = 0600,
60090 + .proc_handler = &proc_dointvec,
60091 + },
60092 +#endif
60093 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
60094 + {
60095 + .procname = "chroot_execlog",
60096 + .data = &grsec_enable_chroot_execlog,
60097 + .maxlen = sizeof(int),
60098 + .mode = 0600,
60099 + .proc_handler = &proc_dointvec,
60100 + },
60101 +#endif
60102 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
60103 + {
60104 + .procname = "chroot_caps",
60105 + .data = &grsec_enable_chroot_caps,
60106 + .maxlen = sizeof(int),
60107 + .mode = 0600,
60108 + .proc_handler = &proc_dointvec,
60109 + },
60110 +#endif
60111 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
60112 + {
60113 + .procname = "chroot_deny_sysctl",
60114 + .data = &grsec_enable_chroot_sysctl,
60115 + .maxlen = sizeof(int),
60116 + .mode = 0600,
60117 + .proc_handler = &proc_dointvec,
60118 + },
60119 +#endif
60120 +#ifdef CONFIG_GRKERNSEC_TPE
60121 + {
60122 + .procname = "tpe",
60123 + .data = &grsec_enable_tpe,
60124 + .maxlen = sizeof(int),
60125 + .mode = 0600,
60126 + .proc_handler = &proc_dointvec,
60127 + },
60128 + {
60129 + .procname = "tpe_gid",
60130 + .data = &grsec_tpe_gid,
60131 + .maxlen = sizeof(int),
60132 + .mode = 0600,
60133 + .proc_handler = &proc_dointvec,
60134 + },
60135 +#endif
60136 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60137 + {
60138 + .procname = "tpe_invert",
60139 + .data = &grsec_enable_tpe_invert,
60140 + .maxlen = sizeof(int),
60141 + .mode = 0600,
60142 + .proc_handler = &proc_dointvec,
60143 + },
60144 +#endif
60145 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60146 + {
60147 + .procname = "tpe_restrict_all",
60148 + .data = &grsec_enable_tpe_all,
60149 + .maxlen = sizeof(int),
60150 + .mode = 0600,
60151 + .proc_handler = &proc_dointvec,
60152 + },
60153 +#endif
60154 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
60155 + {
60156 + .procname = "socket_all",
60157 + .data = &grsec_enable_socket_all,
60158 + .maxlen = sizeof(int),
60159 + .mode = 0600,
60160 + .proc_handler = &proc_dointvec,
60161 + },
60162 + {
60163 + .procname = "socket_all_gid",
60164 + .data = &grsec_socket_all_gid,
60165 + .maxlen = sizeof(int),
60166 + .mode = 0600,
60167 + .proc_handler = &proc_dointvec,
60168 + },
60169 +#endif
60170 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
60171 + {
60172 + .procname = "socket_client",
60173 + .data = &grsec_enable_socket_client,
60174 + .maxlen = sizeof(int),
60175 + .mode = 0600,
60176 + .proc_handler = &proc_dointvec,
60177 + },
60178 + {
60179 + .procname = "socket_client_gid",
60180 + .data = &grsec_socket_client_gid,
60181 + .maxlen = sizeof(int),
60182 + .mode = 0600,
60183 + .proc_handler = &proc_dointvec,
60184 + },
60185 +#endif
60186 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
60187 + {
60188 + .procname = "socket_server",
60189 + .data = &grsec_enable_socket_server,
60190 + .maxlen = sizeof(int),
60191 + .mode = 0600,
60192 + .proc_handler = &proc_dointvec,
60193 + },
60194 + {
60195 + .procname = "socket_server_gid",
60196 + .data = &grsec_socket_server_gid,
60197 + .maxlen = sizeof(int),
60198 + .mode = 0600,
60199 + .proc_handler = &proc_dointvec,
60200 + },
60201 +#endif
60202 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
60203 + {
60204 + .procname = "audit_group",
60205 + .data = &grsec_enable_group,
60206 + .maxlen = sizeof(int),
60207 + .mode = 0600,
60208 + .proc_handler = &proc_dointvec,
60209 + },
60210 + {
60211 + .procname = "audit_gid",
60212 + .data = &grsec_audit_gid,
60213 + .maxlen = sizeof(int),
60214 + .mode = 0600,
60215 + .proc_handler = &proc_dointvec,
60216 + },
60217 +#endif
60218 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
60219 + {
60220 + .procname = "audit_chdir",
60221 + .data = &grsec_enable_chdir,
60222 + .maxlen = sizeof(int),
60223 + .mode = 0600,
60224 + .proc_handler = &proc_dointvec,
60225 + },
60226 +#endif
60227 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
60228 + {
60229 + .procname = "audit_mount",
60230 + .data = &grsec_enable_mount,
60231 + .maxlen = sizeof(int),
60232 + .mode = 0600,
60233 + .proc_handler = &proc_dointvec,
60234 + },
60235 +#endif
60236 +#ifdef CONFIG_GRKERNSEC_AUDIT_TEXTREL
60237 + {
60238 + .procname = "audit_textrel",
60239 + .data = &grsec_enable_audit_textrel,
60240 + .maxlen = sizeof(int),
60241 + .mode = 0600,
60242 + .proc_handler = &proc_dointvec,
60243 + },
60244 +#endif
60245 +#ifdef CONFIG_GRKERNSEC_DMESG
60246 + {
60247 + .procname = "dmesg",
60248 + .data = &grsec_enable_dmesg,
60249 + .maxlen = sizeof(int),
60250 + .mode = 0600,
60251 + .proc_handler = &proc_dointvec,
60252 + },
60253 +#endif
60254 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
60255 + {
60256 + .procname = "chroot_findtask",
60257 + .data = &grsec_enable_chroot_findtask,
60258 + .maxlen = sizeof(int),
60259 + .mode = 0600,
60260 + .proc_handler = &proc_dointvec,
60261 + },
60262 +#endif
60263 +#ifdef CONFIG_GRKERNSEC_RESLOG
60264 + {
60265 + .procname = "resource_logging",
60266 + .data = &grsec_resource_logging,
60267 + .maxlen = sizeof(int),
60268 + .mode = 0600,
60269 + .proc_handler = &proc_dointvec,
60270 + },
60271 +#endif
60272 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
60273 + {
60274 + .procname = "audit_ptrace",
60275 + .data = &grsec_enable_audit_ptrace,
60276 + .maxlen = sizeof(int),
60277 + .mode = 0600,
60278 + .proc_handler = &proc_dointvec,
60279 + },
60280 +#endif
60281 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
60282 + {
60283 + .procname = "harden_ptrace",
60284 + .data = &grsec_enable_harden_ptrace,
60285 + .maxlen = sizeof(int),
60286 + .mode = 0600,
60287 + .proc_handler = &proc_dointvec,
60288 + },
60289 +#endif
60290 + {
60291 + .procname = "grsec_lock",
60292 + .data = &grsec_lock,
60293 + .maxlen = sizeof(int),
60294 + .mode = 0600,
60295 + .proc_handler = &proc_dointvec,
60296 + },
60297 +#endif
60298 +#ifdef CONFIG_GRKERNSEC_ROFS
60299 + {
60300 + .procname = "romount_protect",
60301 + .data = &grsec_enable_rofs,
60302 + .maxlen = sizeof(int),
60303 + .mode = 0600,
60304 + .proc_handler = &proc_dointvec_minmax,
60305 + .extra1 = &one,
60306 + .extra2 = &one,
60307 + },
60308 +#endif
60309 + { }
60310 +};
60311 +#endif
60312 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
60313 new file mode 100644
60314 index 0000000..0dc13c3
60315 --- /dev/null
60316 +++ b/grsecurity/grsec_time.c
60317 @@ -0,0 +1,16 @@
60318 +#include <linux/kernel.h>
60319 +#include <linux/sched.h>
60320 +#include <linux/grinternal.h>
60321 +#include <linux/module.h>
60322 +
60323 +void
60324 +gr_log_timechange(void)
60325 +{
60326 +#ifdef CONFIG_GRKERNSEC_TIME
60327 + if (grsec_enable_time)
60328 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
60329 +#endif
60330 + return;
60331 +}
60332 +
60333 +EXPORT_SYMBOL(gr_log_timechange);
60334 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
60335 new file mode 100644
60336 index 0000000..07e0dc0
60337 --- /dev/null
60338 +++ b/grsecurity/grsec_tpe.c
60339 @@ -0,0 +1,73 @@
60340 +#include <linux/kernel.h>
60341 +#include <linux/sched.h>
60342 +#include <linux/file.h>
60343 +#include <linux/fs.h>
60344 +#include <linux/grinternal.h>
60345 +
60346 +extern int gr_acl_tpe_check(void);
60347 +
60348 +int
60349 +gr_tpe_allow(const struct file *file)
60350 +{
60351 +#ifdef CONFIG_GRKERNSEC
60352 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
60353 + const struct cred *cred = current_cred();
60354 + char *msg = NULL;
60355 + char *msg2 = NULL;
60356 +
60357 + // never restrict root
60358 + if (!cred->uid)
60359 + return 1;
60360 +
60361 + if (grsec_enable_tpe) {
60362 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
60363 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
60364 + msg = "not being in trusted group";
60365 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
60366 + msg = "being in untrusted group";
60367 +#else
60368 + if (in_group_p(grsec_tpe_gid))
60369 + msg = "being in untrusted group";
60370 +#endif
60371 + }
60372 + if (!msg && gr_acl_tpe_check())
60373 + msg = "being in untrusted role";
60374 +
60375 + // not in any affected group/role
60376 + if (!msg)
60377 + goto next_check;
60378 +
60379 + if (inode->i_uid)
60380 + msg2 = "file in non-root-owned directory";
60381 + else if (inode->i_mode & S_IWOTH)
60382 + msg2 = "file in world-writable directory";
60383 + else if (inode->i_mode & S_IWGRP)
60384 + msg2 = "file in group-writable directory";
60385 +
60386 + if (msg && msg2) {
60387 + char fullmsg[70] = {0};
60388 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
60389 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
60390 + return 0;
60391 + }
60392 + msg = NULL;
60393 +next_check:
60394 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
60395 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
60396 + return 1;
60397 +
60398 + if (inode->i_uid && (inode->i_uid != cred->uid))
60399 + msg = "directory not owned by user";
60400 + else if (inode->i_mode & S_IWOTH)
60401 + msg = "file in world-writable directory";
60402 + else if (inode->i_mode & S_IWGRP)
60403 + msg = "file in group-writable directory";
60404 +
60405 + if (msg) {
60406 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
60407 + return 0;
60408 + }
60409 +#endif
60410 +#endif
60411 + return 1;
60412 +}
60413 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
60414 new file mode 100644
60415 index 0000000..9f7b1ac
60416 --- /dev/null
60417 +++ b/grsecurity/grsum.c
60418 @@ -0,0 +1,61 @@
60419 +#include <linux/err.h>
60420 +#include <linux/kernel.h>
60421 +#include <linux/sched.h>
60422 +#include <linux/mm.h>
60423 +#include <linux/scatterlist.h>
60424 +#include <linux/crypto.h>
60425 +#include <linux/gracl.h>
60426 +
60427 +
60428 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
60429 +#error "crypto and sha256 must be built into the kernel"
60430 +#endif
60431 +
60432 +int
60433 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
60434 +{
60435 + char *p;
60436 + struct crypto_hash *tfm;
60437 + struct hash_desc desc;
60438 + struct scatterlist sg;
60439 + unsigned char temp_sum[GR_SHA_LEN];
60440 + volatile int retval = 0;
60441 + volatile int dummy = 0;
60442 + unsigned int i;
60443 +
60444 + sg_init_table(&sg, 1);
60445 +
60446 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
60447 + if (IS_ERR(tfm)) {
60448 + /* should never happen, since sha256 should be built in */
60449 + return 1;
60450 + }
60451 +
60452 + desc.tfm = tfm;
60453 + desc.flags = 0;
60454 +
60455 + crypto_hash_init(&desc);
60456 +
60457 + p = salt;
60458 + sg_set_buf(&sg, p, GR_SALT_LEN);
60459 + crypto_hash_update(&desc, &sg, sg.length);
60460 +
60461 + p = entry->pw;
60462 + sg_set_buf(&sg, p, strlen(p));
60463 +
60464 + crypto_hash_update(&desc, &sg, sg.length);
60465 +
60466 + crypto_hash_final(&desc, temp_sum);
60467 +
60468 + memset(entry->pw, 0, GR_PW_LEN);
60469 +
60470 + for (i = 0; i < GR_SHA_LEN; i++)
60471 + if (sum[i] != temp_sum[i])
60472 + retval = 1;
60473 + else
60474 + dummy = 1; // waste a cycle
60475 +
60476 + crypto_free_hash(tfm);
60477 +
60478 + return retval;
60479 +}
60480 diff --git a/include/acpi/acpi_bus.h b/include/acpi/acpi_bus.h
60481 index 9e6e1c6..d47b906 100644
60482 --- a/include/acpi/acpi_bus.h
60483 +++ b/include/acpi/acpi_bus.h
60484 @@ -138,7 +138,7 @@ struct acpi_device_ops {
60485 acpi_op_bind bind;
60486 acpi_op_unbind unbind;
60487 acpi_op_notify notify;
60488 -};
60489 +} __no_const;
60490
60491 #define ACPI_DRIVER_ALL_NOTIFY_EVENTS 0x1 /* system AND device events */
60492
60493 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
60494 index 77ff547..181834f 100644
60495 --- a/include/asm-generic/4level-fixup.h
60496 +++ b/include/asm-generic/4level-fixup.h
60497 @@ -13,8 +13,10 @@
60498 #define pmd_alloc(mm, pud, address) \
60499 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
60500 NULL: pmd_offset(pud, address))
60501 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
60502
60503 #define pud_alloc(mm, pgd, address) (pgd)
60504 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
60505 #define pud_offset(pgd, start) (pgd)
60506 #define pud_none(pud) 0
60507 #define pud_bad(pud) 0
60508 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
60509 index b7babf0..3ba8aee 100644
60510 --- a/include/asm-generic/atomic-long.h
60511 +++ b/include/asm-generic/atomic-long.h
60512 @@ -22,6 +22,12 @@
60513
60514 typedef atomic64_t atomic_long_t;
60515
60516 +#ifdef CONFIG_PAX_REFCOUNT
60517 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
60518 +#else
60519 +typedef atomic64_t atomic_long_unchecked_t;
60520 +#endif
60521 +
60522 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
60523
60524 static inline long atomic_long_read(atomic_long_t *l)
60525 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60526 return (long)atomic64_read(v);
60527 }
60528
60529 +#ifdef CONFIG_PAX_REFCOUNT
60530 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60531 +{
60532 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60533 +
60534 + return (long)atomic64_read_unchecked(v);
60535 +}
60536 +#endif
60537 +
60538 static inline void atomic_long_set(atomic_long_t *l, long i)
60539 {
60540 atomic64_t *v = (atomic64_t *)l;
60541 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60542 atomic64_set(v, i);
60543 }
60544
60545 +#ifdef CONFIG_PAX_REFCOUNT
60546 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60547 +{
60548 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60549 +
60550 + atomic64_set_unchecked(v, i);
60551 +}
60552 +#endif
60553 +
60554 static inline void atomic_long_inc(atomic_long_t *l)
60555 {
60556 atomic64_t *v = (atomic64_t *)l;
60557 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60558 atomic64_inc(v);
60559 }
60560
60561 +#ifdef CONFIG_PAX_REFCOUNT
60562 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60563 +{
60564 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60565 +
60566 + atomic64_inc_unchecked(v);
60567 +}
60568 +#endif
60569 +
60570 static inline void atomic_long_dec(atomic_long_t *l)
60571 {
60572 atomic64_t *v = (atomic64_t *)l;
60573 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60574 atomic64_dec(v);
60575 }
60576
60577 +#ifdef CONFIG_PAX_REFCOUNT
60578 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60579 +{
60580 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60581 +
60582 + atomic64_dec_unchecked(v);
60583 +}
60584 +#endif
60585 +
60586 static inline void atomic_long_add(long i, atomic_long_t *l)
60587 {
60588 atomic64_t *v = (atomic64_t *)l;
60589 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60590 atomic64_add(i, v);
60591 }
60592
60593 +#ifdef CONFIG_PAX_REFCOUNT
60594 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60595 +{
60596 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60597 +
60598 + atomic64_add_unchecked(i, v);
60599 +}
60600 +#endif
60601 +
60602 static inline void atomic_long_sub(long i, atomic_long_t *l)
60603 {
60604 atomic64_t *v = (atomic64_t *)l;
60605 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60606 atomic64_sub(i, v);
60607 }
60608
60609 +#ifdef CONFIG_PAX_REFCOUNT
60610 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60611 +{
60612 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60613 +
60614 + atomic64_sub_unchecked(i, v);
60615 +}
60616 +#endif
60617 +
60618 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60619 {
60620 atomic64_t *v = (atomic64_t *)l;
60621 @@ -115,6 +175,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60622 return (long)atomic64_inc_return(v);
60623 }
60624
60625 +#ifdef CONFIG_PAX_REFCOUNT
60626 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60627 +{
60628 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
60629 +
60630 + return (long)atomic64_inc_return_unchecked(v);
60631 +}
60632 +#endif
60633 +
60634 static inline long atomic_long_dec_return(atomic_long_t *l)
60635 {
60636 atomic64_t *v = (atomic64_t *)l;
60637 @@ -140,6 +209,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60638
60639 typedef atomic_t atomic_long_t;
60640
60641 +#ifdef CONFIG_PAX_REFCOUNT
60642 +typedef atomic_unchecked_t atomic_long_unchecked_t;
60643 +#else
60644 +typedef atomic_t atomic_long_unchecked_t;
60645 +#endif
60646 +
60647 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
60648 static inline long atomic_long_read(atomic_long_t *l)
60649 {
60650 @@ -148,6 +223,15 @@ static inline long atomic_long_read(atomic_long_t *l)
60651 return (long)atomic_read(v);
60652 }
60653
60654 +#ifdef CONFIG_PAX_REFCOUNT
60655 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
60656 +{
60657 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60658 +
60659 + return (long)atomic_read_unchecked(v);
60660 +}
60661 +#endif
60662 +
60663 static inline void atomic_long_set(atomic_long_t *l, long i)
60664 {
60665 atomic_t *v = (atomic_t *)l;
60666 @@ -155,6 +239,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
60667 atomic_set(v, i);
60668 }
60669
60670 +#ifdef CONFIG_PAX_REFCOUNT
60671 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
60672 +{
60673 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60674 +
60675 + atomic_set_unchecked(v, i);
60676 +}
60677 +#endif
60678 +
60679 static inline void atomic_long_inc(atomic_long_t *l)
60680 {
60681 atomic_t *v = (atomic_t *)l;
60682 @@ -162,6 +255,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
60683 atomic_inc(v);
60684 }
60685
60686 +#ifdef CONFIG_PAX_REFCOUNT
60687 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
60688 +{
60689 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60690 +
60691 + atomic_inc_unchecked(v);
60692 +}
60693 +#endif
60694 +
60695 static inline void atomic_long_dec(atomic_long_t *l)
60696 {
60697 atomic_t *v = (atomic_t *)l;
60698 @@ -169,6 +271,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
60699 atomic_dec(v);
60700 }
60701
60702 +#ifdef CONFIG_PAX_REFCOUNT
60703 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
60704 +{
60705 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60706 +
60707 + atomic_dec_unchecked(v);
60708 +}
60709 +#endif
60710 +
60711 static inline void atomic_long_add(long i, atomic_long_t *l)
60712 {
60713 atomic_t *v = (atomic_t *)l;
60714 @@ -176,6 +287,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
60715 atomic_add(i, v);
60716 }
60717
60718 +#ifdef CONFIG_PAX_REFCOUNT
60719 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
60720 +{
60721 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60722 +
60723 + atomic_add_unchecked(i, v);
60724 +}
60725 +#endif
60726 +
60727 static inline void atomic_long_sub(long i, atomic_long_t *l)
60728 {
60729 atomic_t *v = (atomic_t *)l;
60730 @@ -183,6 +303,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
60731 atomic_sub(i, v);
60732 }
60733
60734 +#ifdef CONFIG_PAX_REFCOUNT
60735 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
60736 +{
60737 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60738 +
60739 + atomic_sub_unchecked(i, v);
60740 +}
60741 +#endif
60742 +
60743 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
60744 {
60745 atomic_t *v = (atomic_t *)l;
60746 @@ -232,6 +361,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
60747 return (long)atomic_inc_return(v);
60748 }
60749
60750 +#ifdef CONFIG_PAX_REFCOUNT
60751 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
60752 +{
60753 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
60754 +
60755 + return (long)atomic_inc_return_unchecked(v);
60756 +}
60757 +#endif
60758 +
60759 static inline long atomic_long_dec_return(atomic_long_t *l)
60760 {
60761 atomic_t *v = (atomic_t *)l;
60762 @@ -255,4 +393,55 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
60763
60764 #endif /* BITS_PER_LONG == 64 */
60765
60766 +#ifdef CONFIG_PAX_REFCOUNT
60767 +static inline void pax_refcount_needs_these_functions(void)
60768 +{
60769 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
60770 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
60771 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
60772 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
60773 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
60774 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
60775 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
60776 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
60777 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
60778 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
60779 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
60780 +#ifdef CONFIG_X86
60781 + atomic_clear_mask_unchecked(0, NULL);
60782 + atomic_set_mask_unchecked(0, NULL);
60783 +#endif
60784 +
60785 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
60786 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
60787 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
60788 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
60789 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
60790 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
60791 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
60792 +}
60793 +#else
60794 +#define atomic_read_unchecked(v) atomic_read(v)
60795 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
60796 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
60797 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
60798 +#define atomic_inc_unchecked(v) atomic_inc(v)
60799 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
60800 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
60801 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
60802 +#define atomic_dec_unchecked(v) atomic_dec(v)
60803 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
60804 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
60805 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
60806 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
60807 +
60808 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
60809 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
60810 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
60811 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
60812 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
60813 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
60814 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
60815 +#endif
60816 +
60817 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
60818 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
60819 index 1ced641..c896ee8 100644
60820 --- a/include/asm-generic/atomic.h
60821 +++ b/include/asm-generic/atomic.h
60822 @@ -159,7 +159,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
60823 * Atomically clears the bits set in @mask from @v
60824 */
60825 #ifndef atomic_clear_mask
60826 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
60827 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
60828 {
60829 unsigned long flags;
60830
60831 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
60832 index b18ce4f..2ee2843 100644
60833 --- a/include/asm-generic/atomic64.h
60834 +++ b/include/asm-generic/atomic64.h
60835 @@ -16,6 +16,8 @@ typedef struct {
60836 long long counter;
60837 } atomic64_t;
60838
60839 +typedef atomic64_t atomic64_unchecked_t;
60840 +
60841 #define ATOMIC64_INIT(i) { (i) }
60842
60843 extern long long atomic64_read(const atomic64_t *v);
60844 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
60845 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
60846 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
60847
60848 +#define atomic64_read_unchecked(v) atomic64_read(v)
60849 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
60850 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
60851 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
60852 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
60853 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
60854 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
60855 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
60856 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
60857 +
60858 #endif /* _ASM_GENERIC_ATOMIC64_H */
60859 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
60860 index 1bfcfe5..e04c5c9 100644
60861 --- a/include/asm-generic/cache.h
60862 +++ b/include/asm-generic/cache.h
60863 @@ -6,7 +6,7 @@
60864 * cache lines need to provide their own cache.h.
60865 */
60866
60867 -#define L1_CACHE_SHIFT 5
60868 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
60869 +#define L1_CACHE_SHIFT 5UL
60870 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
60871
60872 #endif /* __ASM_GENERIC_CACHE_H */
60873 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
60874 index 0d68a1e..b74a761 100644
60875 --- a/include/asm-generic/emergency-restart.h
60876 +++ b/include/asm-generic/emergency-restart.h
60877 @@ -1,7 +1,7 @@
60878 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
60879 #define _ASM_GENERIC_EMERGENCY_RESTART_H
60880
60881 -static inline void machine_emergency_restart(void)
60882 +static inline __noreturn void machine_emergency_restart(void)
60883 {
60884 machine_restart(NULL);
60885 }
60886 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
60887 index 0232ccb..13d9165 100644
60888 --- a/include/asm-generic/kmap_types.h
60889 +++ b/include/asm-generic/kmap_types.h
60890 @@ -29,10 +29,11 @@ KMAP_D(16) KM_IRQ_PTE,
60891 KMAP_D(17) KM_NMI,
60892 KMAP_D(18) KM_NMI_PTE,
60893 KMAP_D(19) KM_KDB,
60894 +KMAP_D(20) KM_CLEARPAGE,
60895 /*
60896 * Remember to update debug_kmap_atomic() when adding new kmap types!
60897 */
60898 -KMAP_D(20) KM_TYPE_NR
60899 +KMAP_D(21) KM_TYPE_NR
60900 };
60901
60902 #undef KMAP_D
60903 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
60904 index 9ceb03b..2efbcbd 100644
60905 --- a/include/asm-generic/local.h
60906 +++ b/include/asm-generic/local.h
60907 @@ -39,6 +39,7 @@ typedef struct
60908 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
60909 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
60910 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
60911 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
60912
60913 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
60914 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
60915 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
60916 index 725612b..9cc513a 100644
60917 --- a/include/asm-generic/pgtable-nopmd.h
60918 +++ b/include/asm-generic/pgtable-nopmd.h
60919 @@ -1,14 +1,19 @@
60920 #ifndef _PGTABLE_NOPMD_H
60921 #define _PGTABLE_NOPMD_H
60922
60923 -#ifndef __ASSEMBLY__
60924 -
60925 #include <asm-generic/pgtable-nopud.h>
60926
60927 -struct mm_struct;
60928 -
60929 #define __PAGETABLE_PMD_FOLDED
60930
60931 +#define PMD_SHIFT PUD_SHIFT
60932 +#define PTRS_PER_PMD 1
60933 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
60934 +#define PMD_MASK (~(PMD_SIZE-1))
60935 +
60936 +#ifndef __ASSEMBLY__
60937 +
60938 +struct mm_struct;
60939 +
60940 /*
60941 * Having the pmd type consist of a pud gets the size right, and allows
60942 * us to conceptually access the pud entry that this pmd is folded into
60943 @@ -16,11 +21,6 @@ struct mm_struct;
60944 */
60945 typedef struct { pud_t pud; } pmd_t;
60946
60947 -#define PMD_SHIFT PUD_SHIFT
60948 -#define PTRS_PER_PMD 1
60949 -#define PMD_SIZE (1UL << PMD_SHIFT)
60950 -#define PMD_MASK (~(PMD_SIZE-1))
60951 -
60952 /*
60953 * The "pud_xxx()" functions here are trivial for a folded two-level
60954 * setup: the pmd is never bad, and a pmd always exists (as it's folded
60955 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
60956 index 810431d..0ec4804f 100644
60957 --- a/include/asm-generic/pgtable-nopud.h
60958 +++ b/include/asm-generic/pgtable-nopud.h
60959 @@ -1,10 +1,15 @@
60960 #ifndef _PGTABLE_NOPUD_H
60961 #define _PGTABLE_NOPUD_H
60962
60963 -#ifndef __ASSEMBLY__
60964 -
60965 #define __PAGETABLE_PUD_FOLDED
60966
60967 +#define PUD_SHIFT PGDIR_SHIFT
60968 +#define PTRS_PER_PUD 1
60969 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
60970 +#define PUD_MASK (~(PUD_SIZE-1))
60971 +
60972 +#ifndef __ASSEMBLY__
60973 +
60974 /*
60975 * Having the pud type consist of a pgd gets the size right, and allows
60976 * us to conceptually access the pgd entry that this pud is folded into
60977 @@ -12,11 +17,6 @@
60978 */
60979 typedef struct { pgd_t pgd; } pud_t;
60980
60981 -#define PUD_SHIFT PGDIR_SHIFT
60982 -#define PTRS_PER_PUD 1
60983 -#define PUD_SIZE (1UL << PUD_SHIFT)
60984 -#define PUD_MASK (~(PUD_SIZE-1))
60985 -
60986 /*
60987 * The "pgd_xxx()" functions here are trivial for a folded two-level
60988 * setup: the pud is never bad, and a pud always exists (as it's folded
60989 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
60990 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
60991
60992 #define pgd_populate(mm, pgd, pud) do { } while (0)
60993 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
60994 /*
60995 * (puds are folded into pgds so this doesn't get actually called,
60996 * but the define is needed for a generic inline function.)
60997 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
60998 index ff4947b..f48183f 100644
60999 --- a/include/asm-generic/pgtable.h
61000 +++ b/include/asm-generic/pgtable.h
61001 @@ -530,6 +530,14 @@ static inline int pmd_trans_unstable(pmd_t *pmd)
61002 #endif
61003 }
61004
61005 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
61006 +static inline unsigned long pax_open_kernel(void) { return 0; }
61007 +#endif
61008 +
61009 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
61010 +static inline unsigned long pax_close_kernel(void) { return 0; }
61011 +#endif
61012 +
61013 #endif /* CONFIG_MMU */
61014
61015 #endif /* !__ASSEMBLY__ */
61016 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
61017 index 4e2e1cc..12c266b 100644
61018 --- a/include/asm-generic/vmlinux.lds.h
61019 +++ b/include/asm-generic/vmlinux.lds.h
61020 @@ -218,6 +218,7 @@
61021 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
61022 VMLINUX_SYMBOL(__start_rodata) = .; \
61023 *(.rodata) *(.rodata.*) \
61024 + *(.data..read_only) \
61025 *(__vermagic) /* Kernel version magic */ \
61026 . = ALIGN(8); \
61027 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
61028 @@ -716,17 +717,18 @@
61029 * section in the linker script will go there too. @phdr should have
61030 * a leading colon.
61031 *
61032 - * Note that this macros defines __per_cpu_load as an absolute symbol.
61033 + * Note that this macros defines per_cpu_load as an absolute symbol.
61034 * If there is no need to put the percpu section at a predetermined
61035 * address, use PERCPU_SECTION.
61036 */
61037 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
61038 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
61039 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
61040 + per_cpu_load = .; \
61041 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
61042 - LOAD_OFFSET) { \
61043 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
61044 PERCPU_INPUT(cacheline) \
61045 } phdr \
61046 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
61047 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
61048
61049 /**
61050 * PERCPU_SECTION - define output section for percpu area, simple version
61051 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
61052 index 31ad880..4e79884 100644
61053 --- a/include/drm/drmP.h
61054 +++ b/include/drm/drmP.h
61055 @@ -72,6 +72,7 @@
61056 #include <linux/workqueue.h>
61057 #include <linux/poll.h>
61058 #include <asm/pgalloc.h>
61059 +#include <asm/local.h>
61060 #include "drm.h"
61061
61062 #include <linux/idr.h>
61063 @@ -1074,7 +1075,7 @@ struct drm_device {
61064
61065 /** \name Usage Counters */
61066 /*@{ */
61067 - int open_count; /**< Outstanding files open */
61068 + local_t open_count; /**< Outstanding files open */
61069 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
61070 atomic_t vma_count; /**< Outstanding vma areas open */
61071 int buf_use; /**< Buffers in use -- cannot alloc */
61072 @@ -1085,7 +1086,7 @@ struct drm_device {
61073 /*@{ */
61074 unsigned long counters;
61075 enum drm_stat_type types[15];
61076 - atomic_t counts[15];
61077 + atomic_unchecked_t counts[15];
61078 /*@} */
61079
61080 struct list_head filelist;
61081 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
61082 index 7988e55..ec974c9 100644
61083 --- a/include/drm/drm_crtc_helper.h
61084 +++ b/include/drm/drm_crtc_helper.h
61085 @@ -81,7 +81,7 @@ struct drm_crtc_helper_funcs {
61086
61087 /* disable crtc when not in use - more explicit than dpms off */
61088 void (*disable)(struct drm_crtc *crtc);
61089 -};
61090 +} __no_const;
61091
61092 /**
61093 * drm_encoder_helper_funcs - helper operations for encoders
61094 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
61095 struct drm_connector *connector);
61096 /* disable encoder when not in use - more explicit than dpms off */
61097 void (*disable)(struct drm_encoder *encoder);
61098 -};
61099 +} __no_const;
61100
61101 /**
61102 * drm_connector_helper_funcs - helper operations for connectors
61103 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
61104 index d6d1da4..fdd1ac5 100644
61105 --- a/include/drm/ttm/ttm_memory.h
61106 +++ b/include/drm/ttm/ttm_memory.h
61107 @@ -48,7 +48,7 @@
61108
61109 struct ttm_mem_shrink {
61110 int (*do_shrink) (struct ttm_mem_shrink *);
61111 -};
61112 +} __no_const;
61113
61114 /**
61115 * struct ttm_mem_global - Global memory accounting structure.
61116 diff --git a/include/linux/a.out.h b/include/linux/a.out.h
61117 index e86dfca..40cc55f 100644
61118 --- a/include/linux/a.out.h
61119 +++ b/include/linux/a.out.h
61120 @@ -39,6 +39,14 @@ enum machine_type {
61121 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
61122 };
61123
61124 +/* Constants for the N_FLAGS field */
61125 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61126 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
61127 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
61128 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
61129 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61130 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61131 +
61132 #if !defined (N_MAGIC)
61133 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
61134 #endif
61135 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
61136 index 06fd4bb..1caec0d 100644
61137 --- a/include/linux/atmdev.h
61138 +++ b/include/linux/atmdev.h
61139 @@ -237,7 +237,7 @@ struct compat_atm_iobuf {
61140 #endif
61141
61142 struct k_atm_aal_stats {
61143 -#define __HANDLE_ITEM(i) atomic_t i
61144 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
61145 __AAL_STAT_ITEMS
61146 #undef __HANDLE_ITEM
61147 };
61148 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
61149 index 366422b..1fa7f84 100644
61150 --- a/include/linux/binfmts.h
61151 +++ b/include/linux/binfmts.h
61152 @@ -89,6 +89,7 @@ struct linux_binfmt {
61153 int (*load_binary)(struct linux_binprm *, struct pt_regs * regs);
61154 int (*load_shlib)(struct file *);
61155 int (*core_dump)(struct coredump_params *cprm);
61156 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
61157 unsigned long min_coredump; /* minimal dump size */
61158 };
61159
61160 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
61161 index 07954b0..cb2ae71 100644
61162 --- a/include/linux/blkdev.h
61163 +++ b/include/linux/blkdev.h
61164 @@ -1393,7 +1393,7 @@ struct block_device_operations {
61165 /* this callback is with swap_lock and sometimes page table lock held */
61166 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
61167 struct module *owner;
61168 -};
61169 +} __do_const;
61170
61171 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
61172 unsigned long);
61173 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
61174 index 4d1a074..88f929a 100644
61175 --- a/include/linux/blktrace_api.h
61176 +++ b/include/linux/blktrace_api.h
61177 @@ -162,7 +162,7 @@ struct blk_trace {
61178 struct dentry *dir;
61179 struct dentry *dropped_file;
61180 struct dentry *msg_file;
61181 - atomic_t dropped;
61182 + atomic_unchecked_t dropped;
61183 };
61184
61185 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
61186 diff --git a/include/linux/byteorder/little_endian.h b/include/linux/byteorder/little_endian.h
61187 index 83195fb..0b0f77d 100644
61188 --- a/include/linux/byteorder/little_endian.h
61189 +++ b/include/linux/byteorder/little_endian.h
61190 @@ -42,51 +42,51 @@
61191
61192 static inline __le64 __cpu_to_le64p(const __u64 *p)
61193 {
61194 - return (__force __le64)*p;
61195 + return (__force const __le64)*p;
61196 }
61197 static inline __u64 __le64_to_cpup(const __le64 *p)
61198 {
61199 - return (__force __u64)*p;
61200 + return (__force const __u64)*p;
61201 }
61202 static inline __le32 __cpu_to_le32p(const __u32 *p)
61203 {
61204 - return (__force __le32)*p;
61205 + return (__force const __le32)*p;
61206 }
61207 static inline __u32 __le32_to_cpup(const __le32 *p)
61208 {
61209 - return (__force __u32)*p;
61210 + return (__force const __u32)*p;
61211 }
61212 static inline __le16 __cpu_to_le16p(const __u16 *p)
61213 {
61214 - return (__force __le16)*p;
61215 + return (__force const __le16)*p;
61216 }
61217 static inline __u16 __le16_to_cpup(const __le16 *p)
61218 {
61219 - return (__force __u16)*p;
61220 + return (__force const __u16)*p;
61221 }
61222 static inline __be64 __cpu_to_be64p(const __u64 *p)
61223 {
61224 - return (__force __be64)__swab64p(p);
61225 + return (__force const __be64)__swab64p(p);
61226 }
61227 static inline __u64 __be64_to_cpup(const __be64 *p)
61228 {
61229 - return __swab64p((__u64 *)p);
61230 + return __swab64p((const __u64 *)p);
61231 }
61232 static inline __be32 __cpu_to_be32p(const __u32 *p)
61233 {
61234 - return (__force __be32)__swab32p(p);
61235 + return (__force const __be32)__swab32p(p);
61236 }
61237 static inline __u32 __be32_to_cpup(const __be32 *p)
61238 {
61239 - return __swab32p((__u32 *)p);
61240 + return __swab32p((const __u32 *)p);
61241 }
61242 static inline __be16 __cpu_to_be16p(const __u16 *p)
61243 {
61244 - return (__force __be16)__swab16p(p);
61245 + return (__force const __be16)__swab16p(p);
61246 }
61247 static inline __u16 __be16_to_cpup(const __be16 *p)
61248 {
61249 - return __swab16p((__u16 *)p);
61250 + return __swab16p((const __u16 *)p);
61251 }
61252 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
61253 #define __le64_to_cpus(x) do { (void)(x); } while (0)
61254 diff --git a/include/linux/cache.h b/include/linux/cache.h
61255 index 4c57065..4307975 100644
61256 --- a/include/linux/cache.h
61257 +++ b/include/linux/cache.h
61258 @@ -16,6 +16,10 @@
61259 #define __read_mostly
61260 #endif
61261
61262 +#ifndef __read_only
61263 +#define __read_only __read_mostly
61264 +#endif
61265 +
61266 #ifndef ____cacheline_aligned
61267 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
61268 #endif
61269 diff --git a/include/linux/capability.h b/include/linux/capability.h
61270 index d10b7ed..0288b79 100644
61271 --- a/include/linux/capability.h
61272 +++ b/include/linux/capability.h
61273 @@ -553,10 +553,15 @@ extern bool capable(int cap);
61274 extern bool ns_capable(struct user_namespace *ns, int cap);
61275 extern bool nsown_capable(int cap);
61276 extern bool inode_capable(const struct inode *inode, int cap);
61277 +extern bool capable_nolog(int cap);
61278 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
61279 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
61280
61281 /* audit system wants to get cap info from files as well */
61282 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
61283
61284 +extern int is_privileged_binary(const struct dentry *dentry);
61285 +
61286 #endif /* __KERNEL__ */
61287
61288 #endif /* !_LINUX_CAPABILITY_H */
61289 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
61290 index 42e55de..1cd0e66 100644
61291 --- a/include/linux/cleancache.h
61292 +++ b/include/linux/cleancache.h
61293 @@ -31,7 +31,7 @@ struct cleancache_ops {
61294 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
61295 void (*invalidate_inode)(int, struct cleancache_filekey);
61296 void (*invalidate_fs)(int);
61297 -};
61298 +} __no_const;
61299
61300 extern struct cleancache_ops
61301 cleancache_register_ops(struct cleancache_ops *ops);
61302 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
61303 index 4a0b483..f1f70ba 100644
61304 --- a/include/linux/clk-provider.h
61305 +++ b/include/linux/clk-provider.h
61306 @@ -110,6 +110,7 @@ struct clk_ops {
61307 unsigned long);
61308 void (*init)(struct clk_hw *hw);
61309 };
61310 +typedef struct clk_ops __no_const clk_ops_no_const;
61311
61312 /**
61313 * struct clk_init_data - holds init data that's common to all clocks and is
61314 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
61315 index 2f40791..938880e 100644
61316 --- a/include/linux/compiler-gcc4.h
61317 +++ b/include/linux/compiler-gcc4.h
61318 @@ -32,6 +32,21 @@
61319 #define __linktime_error(message) __attribute__((__error__(message)))
61320
61321 #if __GNUC_MINOR__ >= 5
61322 +
61323 +#ifdef CONSTIFY_PLUGIN
61324 +#define __no_const __attribute__((no_const))
61325 +#define __do_const __attribute__((do_const))
61326 +#endif
61327 +
61328 +#ifdef SIZE_OVERFLOW_PLUGIN
61329 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
61330 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
61331 +#endif
61332 +
61333 +#ifdef LATENT_ENTROPY_PLUGIN
61334 +#define __latent_entropy __attribute__((latent_entropy))
61335 +#endif
61336 +
61337 /*
61338 * Mark a position in code as unreachable. This can be used to
61339 * suppress control flow warnings after asm blocks that transfer
61340 @@ -47,6 +62,11 @@
61341 #define __noclone __attribute__((__noclone__))
61342
61343 #endif
61344 +
61345 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
61346 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
61347 +#define __bos0(ptr) __bos((ptr), 0)
61348 +#define __bos1(ptr) __bos((ptr), 1)
61349 #endif
61350
61351 #if __GNUC_MINOR__ > 0
61352 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
61353 index 923d093..3625de1 100644
61354 --- a/include/linux/compiler.h
61355 +++ b/include/linux/compiler.h
61356 @@ -5,31 +5,62 @@
61357
61358 #ifdef __CHECKER__
61359 # define __user __attribute__((noderef, address_space(1)))
61360 +# define __force_user __force __user
61361 # define __kernel __attribute__((address_space(0)))
61362 +# define __force_kernel __force __kernel
61363 # define __safe __attribute__((safe))
61364 # define __force __attribute__((force))
61365 # define __nocast __attribute__((nocast))
61366 # define __iomem __attribute__((noderef, address_space(2)))
61367 +# define __force_iomem __force __iomem
61368 # define __acquires(x) __attribute__((context(x,0,1)))
61369 # define __releases(x) __attribute__((context(x,1,0)))
61370 # define __acquire(x) __context__(x,1)
61371 # define __release(x) __context__(x,-1)
61372 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
61373 # define __percpu __attribute__((noderef, address_space(3)))
61374 +# define __force_percpu __force __percpu
61375 #ifdef CONFIG_SPARSE_RCU_POINTER
61376 # define __rcu __attribute__((noderef, address_space(4)))
61377 +# define __force_rcu __force __rcu
61378 #else
61379 # define __rcu
61380 +# define __force_rcu
61381 #endif
61382 extern void __chk_user_ptr(const volatile void __user *);
61383 extern void __chk_io_ptr(const volatile void __iomem *);
61384 +#elif defined(CHECKER_PLUGIN)
61385 +//# define __user
61386 +//# define __force_user
61387 +//# define __kernel
61388 +//# define __force_kernel
61389 +# define __safe
61390 +# define __force
61391 +# define __nocast
61392 +# define __iomem
61393 +# define __force_iomem
61394 +# define __chk_user_ptr(x) (void)0
61395 +# define __chk_io_ptr(x) (void)0
61396 +# define __builtin_warning(x, y...) (1)
61397 +# define __acquires(x)
61398 +# define __releases(x)
61399 +# define __acquire(x) (void)0
61400 +# define __release(x) (void)0
61401 +# define __cond_lock(x,c) (c)
61402 +# define __percpu
61403 +# define __force_percpu
61404 +# define __rcu
61405 +# define __force_rcu
61406 #else
61407 # define __user
61408 +# define __force_user
61409 # define __kernel
61410 +# define __force_kernel
61411 # define __safe
61412 # define __force
61413 # define __nocast
61414 # define __iomem
61415 +# define __force_iomem
61416 # define __chk_user_ptr(x) (void)0
61417 # define __chk_io_ptr(x) (void)0
61418 # define __builtin_warning(x, y...) (1)
61419 @@ -39,7 +70,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
61420 # define __release(x) (void)0
61421 # define __cond_lock(x,c) (c)
61422 # define __percpu
61423 +# define __force_percpu
61424 # define __rcu
61425 +# define __force_rcu
61426 #endif
61427
61428 #ifdef __KERNEL__
61429 @@ -264,6 +297,26 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61430 # define __attribute_const__ /* unimplemented */
61431 #endif
61432
61433 +#ifndef __no_const
61434 +# define __no_const
61435 +#endif
61436 +
61437 +#ifndef __do_const
61438 +# define __do_const
61439 +#endif
61440 +
61441 +#ifndef __size_overflow
61442 +# define __size_overflow(...)
61443 +#endif
61444 +
61445 +#ifndef __latent_entropy
61446 +# define __latent_entropy
61447 +#endif
61448 +
61449 +#ifndef __intentional_overflow
61450 +# define __intentional_overflow(...)
61451 +#endif
61452 +
61453 /*
61454 * Tell gcc if a function is cold. The compiler will assume any path
61455 * directly leading to the call is unlikely.
61456 @@ -273,6 +326,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61457 #define __cold
61458 #endif
61459
61460 +#ifndef __alloc_size
61461 +#define __alloc_size(...)
61462 +#endif
61463 +
61464 +#ifndef __bos
61465 +#define __bos(ptr, arg)
61466 +#endif
61467 +
61468 +#ifndef __bos0
61469 +#define __bos0(ptr)
61470 +#endif
61471 +
61472 +#ifndef __bos1
61473 +#define __bos1(ptr)
61474 +#endif
61475 +
61476 /* Simple shorthand for a section definition */
61477 #ifndef __section
61478 # define __section(S) __attribute__ ((__section__(#S)))
61479 @@ -308,6 +377,7 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
61480 * use is to mediate communication between process-level code and irq/NMI
61481 * handlers, all running on the same CPU.
61482 */
61483 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
61484 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
61485 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
61486
61487 #endif /* __LINUX_COMPILER_H */
61488 diff --git a/include/linux/cred.h b/include/linux/cred.h
61489 index ebbed2c..908cc2c 100644
61490 --- a/include/linux/cred.h
61491 +++ b/include/linux/cred.h
61492 @@ -208,6 +208,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
61493 static inline void validate_process_creds(void)
61494 {
61495 }
61496 +static inline void validate_task_creds(struct task_struct *task)
61497 +{
61498 +}
61499 #endif
61500
61501 /**
61502 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
61503 index b92eadf..b4ecdc1 100644
61504 --- a/include/linux/crypto.h
61505 +++ b/include/linux/crypto.h
61506 @@ -373,7 +373,7 @@ struct cipher_tfm {
61507 const u8 *key, unsigned int keylen);
61508 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61509 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
61510 -};
61511 +} __no_const;
61512
61513 struct hash_tfm {
61514 int (*init)(struct hash_desc *desc);
61515 @@ -394,13 +394,13 @@ struct compress_tfm {
61516 int (*cot_decompress)(struct crypto_tfm *tfm,
61517 const u8 *src, unsigned int slen,
61518 u8 *dst, unsigned int *dlen);
61519 -};
61520 +} __no_const;
61521
61522 struct rng_tfm {
61523 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
61524 unsigned int dlen);
61525 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
61526 -};
61527 +} __no_const;
61528
61529 #define crt_ablkcipher crt_u.ablkcipher
61530 #define crt_aead crt_u.aead
61531 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
61532 index 7925bf0..d5143d2 100644
61533 --- a/include/linux/decompress/mm.h
61534 +++ b/include/linux/decompress/mm.h
61535 @@ -77,7 +77,7 @@ static void free(void *where)
61536 * warnings when not needed (indeed large_malloc / large_free are not
61537 * needed by inflate */
61538
61539 -#define malloc(a) kmalloc(a, GFP_KERNEL)
61540 +#define malloc(a) kmalloc((a), GFP_KERNEL)
61541 #define free(a) kfree(a)
61542
61543 #define large_malloc(a) vmalloc(a)
61544 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
61545 index dfc099e..e583e66 100644
61546 --- a/include/linux/dma-mapping.h
61547 +++ b/include/linux/dma-mapping.h
61548 @@ -51,7 +51,7 @@ struct dma_map_ops {
61549 u64 (*get_required_mask)(struct device *dev);
61550 #endif
61551 int is_phys;
61552 -};
61553 +} __do_const;
61554
61555 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
61556
61557 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
61558 index 56377df..4eb4990 100644
61559 --- a/include/linux/dmaengine.h
61560 +++ b/include/linux/dmaengine.h
61561 @@ -1007,9 +1007,9 @@ struct dma_pinned_list {
61562 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
61563 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
61564
61565 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61566 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
61567 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
61568 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61569 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
61570 struct dma_pinned_list *pinned_list, struct page *page,
61571 unsigned int offset, size_t len);
61572
61573 diff --git a/include/linux/efi.h b/include/linux/efi.h
61574 index ec45ccd..9923c32 100644
61575 --- a/include/linux/efi.h
61576 +++ b/include/linux/efi.h
61577 @@ -635,7 +635,7 @@ struct efivar_operations {
61578 efi_get_variable_t *get_variable;
61579 efi_get_next_variable_t *get_next_variable;
61580 efi_set_variable_t *set_variable;
61581 -};
61582 +} __no_const;
61583
61584 struct efivars {
61585 /*
61586 diff --git a/include/linux/elf.h b/include/linux/elf.h
61587 index 999b4f5..57753b4 100644
61588 --- a/include/linux/elf.h
61589 +++ b/include/linux/elf.h
61590 @@ -40,6 +40,17 @@ typedef __s64 Elf64_Sxword;
61591 #define PT_GNU_EH_FRAME 0x6474e550
61592
61593 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
61594 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
61595 +
61596 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
61597 +
61598 +/* Constants for the e_flags field */
61599 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
61600 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
61601 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
61602 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
61603 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
61604 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
61605
61606 /*
61607 * Extended Numbering
61608 @@ -97,6 +108,8 @@ typedef __s64 Elf64_Sxword;
61609 #define DT_DEBUG 21
61610 #define DT_TEXTREL 22
61611 #define DT_JMPREL 23
61612 +#define DT_FLAGS 30
61613 + #define DF_TEXTREL 0x00000004
61614 #define DT_ENCODING 32
61615 #define OLD_DT_LOOS 0x60000000
61616 #define DT_LOOS 0x6000000d
61617 @@ -243,6 +256,19 @@ typedef struct elf64_hdr {
61618 #define PF_W 0x2
61619 #define PF_X 0x1
61620
61621 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
61622 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
61623 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
61624 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
61625 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
61626 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
61627 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
61628 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
61629 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
61630 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
61631 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
61632 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
61633 +
61634 typedef struct elf32_phdr{
61635 Elf32_Word p_type;
61636 Elf32_Off p_offset;
61637 @@ -335,6 +361,8 @@ typedef struct elf64_shdr {
61638 #define EI_OSABI 7
61639 #define EI_PAD 8
61640
61641 +#define EI_PAX 14
61642 +
61643 #define ELFMAG0 0x7f /* EI_MAG */
61644 #define ELFMAG1 'E'
61645 #define ELFMAG2 'L'
61646 @@ -421,6 +449,7 @@ extern Elf32_Dyn _DYNAMIC [];
61647 #define elf_note elf32_note
61648 #define elf_addr_t Elf32_Off
61649 #define Elf_Half Elf32_Half
61650 +#define elf_dyn Elf32_Dyn
61651
61652 #else
61653
61654 @@ -431,6 +460,7 @@ extern Elf64_Dyn _DYNAMIC [];
61655 #define elf_note elf64_note
61656 #define elf_addr_t Elf64_Off
61657 #define Elf_Half Elf64_Half
61658 +#define elf_dyn Elf64_Dyn
61659
61660 #endif
61661
61662 diff --git a/include/linux/filter.h b/include/linux/filter.h
61663 index 82b0135..917914d 100644
61664 --- a/include/linux/filter.h
61665 +++ b/include/linux/filter.h
61666 @@ -146,6 +146,7 @@ struct compat_sock_fprog {
61667
61668 struct sk_buff;
61669 struct sock;
61670 +struct bpf_jit_work;
61671
61672 struct sk_filter
61673 {
61674 @@ -153,6 +154,9 @@ struct sk_filter
61675 unsigned int len; /* Number of filter blocks */
61676 unsigned int (*bpf_func)(const struct sk_buff *skb,
61677 const struct sock_filter *filter);
61678 +#ifdef CONFIG_BPF_JIT
61679 + struct bpf_jit_work *work;
61680 +#endif
61681 struct rcu_head rcu;
61682 struct sock_filter insns[0];
61683 };
61684 diff --git a/include/linux/firewire.h b/include/linux/firewire.h
61685 index 7edcf10..714d5e8 100644
61686 --- a/include/linux/firewire.h
61687 +++ b/include/linux/firewire.h
61688 @@ -430,7 +430,7 @@ struct fw_iso_context {
61689 union {
61690 fw_iso_callback_t sc;
61691 fw_iso_mc_callback_t mc;
61692 - } callback;
61693 + } __no_const callback;
61694 void *callback_data;
61695 };
61696
61697 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
61698 index 0e4e2ee..4ff4312 100644
61699 --- a/include/linux/frontswap.h
61700 +++ b/include/linux/frontswap.h
61701 @@ -11,7 +11,7 @@ struct frontswap_ops {
61702 int (*load)(unsigned, pgoff_t, struct page *);
61703 void (*invalidate_page)(unsigned, pgoff_t);
61704 void (*invalidate_area)(unsigned);
61705 -};
61706 +} __no_const;
61707
61708 extern bool frontswap_enabled;
61709 extern struct frontswap_ops
61710 diff --git a/include/linux/fs.h b/include/linux/fs.h
61711 index 17fd887..8eebca0 100644
61712 --- a/include/linux/fs.h
61713 +++ b/include/linux/fs.h
61714 @@ -1663,7 +1663,8 @@ struct file_operations {
61715 int (*setlease)(struct file *, long, struct file_lock **);
61716 long (*fallocate)(struct file *file, int mode, loff_t offset,
61717 loff_t len);
61718 -};
61719 +} __do_const;
61720 +typedef struct file_operations __no_const file_operations_no_const;
61721
61722 struct inode_operations {
61723 struct dentry * (*lookup) (struct inode *,struct dentry *, struct nameidata *);
61724 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
61725 index 003dc0f..3c4ea97 100644
61726 --- a/include/linux/fs_struct.h
61727 +++ b/include/linux/fs_struct.h
61728 @@ -6,7 +6,7 @@
61729 #include <linux/seqlock.h>
61730
61731 struct fs_struct {
61732 - int users;
61733 + atomic_t users;
61734 spinlock_t lock;
61735 seqcount_t seq;
61736 int umask;
61737 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
61738 index ce31408..b1ad003 100644
61739 --- a/include/linux/fscache-cache.h
61740 +++ b/include/linux/fscache-cache.h
61741 @@ -102,7 +102,7 @@ struct fscache_operation {
61742 fscache_operation_release_t release;
61743 };
61744
61745 -extern atomic_t fscache_op_debug_id;
61746 +extern atomic_unchecked_t fscache_op_debug_id;
61747 extern void fscache_op_work_func(struct work_struct *work);
61748
61749 extern void fscache_enqueue_operation(struct fscache_operation *);
61750 @@ -122,7 +122,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
61751 {
61752 INIT_WORK(&op->work, fscache_op_work_func);
61753 atomic_set(&op->usage, 1);
61754 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
61755 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
61756 op->processor = processor;
61757 op->release = release;
61758 INIT_LIST_HEAD(&op->pend_link);
61759 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
61760 index a6dfe69..569586df 100644
61761 --- a/include/linux/fsnotify.h
61762 +++ b/include/linux/fsnotify.h
61763 @@ -315,7 +315,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
61764 */
61765 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
61766 {
61767 - return kstrdup(name, GFP_KERNEL);
61768 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
61769 }
61770
61771 /*
61772 diff --git a/include/linux/fsnotify_backend.h b/include/linux/fsnotify_backend.h
61773 index 63d966d..cdcb717 100644
61774 --- a/include/linux/fsnotify_backend.h
61775 +++ b/include/linux/fsnotify_backend.h
61776 @@ -105,6 +105,7 @@ struct fsnotify_ops {
61777 void (*freeing_mark)(struct fsnotify_mark *mark, struct fsnotify_group *group);
61778 void (*free_event_priv)(struct fsnotify_event_private_data *priv);
61779 };
61780 +typedef struct fsnotify_ops __no_const fsnotify_ops_no_const;
61781
61782 /*
61783 * A group is a "thing" that wants to receive notification about filesystem
61784 diff --git a/include/linux/ftrace_event.h b/include/linux/ftrace_event.h
61785 index 176a939..1462211 100644
61786 --- a/include/linux/ftrace_event.h
61787 +++ b/include/linux/ftrace_event.h
61788 @@ -97,7 +97,7 @@ struct trace_event_functions {
61789 trace_print_func raw;
61790 trace_print_func hex;
61791 trace_print_func binary;
61792 -};
61793 +} __no_const;
61794
61795 struct trace_event {
61796 struct hlist_node node;
61797 @@ -263,7 +263,7 @@ extern int trace_define_field(struct ftrace_event_call *call, const char *type,
61798 extern int trace_add_event_call(struct ftrace_event_call *call);
61799 extern void trace_remove_event_call(struct ftrace_event_call *call);
61800
61801 -#define is_signed_type(type) (((type)(-1)) < 0)
61802 +#define is_signed_type(type) (((type)(-1)) < (type)1)
61803
61804 int trace_set_clr_event(const char *system, const char *event, int set);
61805
61806 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
61807 index 017a7fb..33a8507 100644
61808 --- a/include/linux/genhd.h
61809 +++ b/include/linux/genhd.h
61810 @@ -185,7 +185,7 @@ struct gendisk {
61811 struct kobject *slave_dir;
61812
61813 struct timer_rand_state *random;
61814 - atomic_t sync_io; /* RAID */
61815 + atomic_unchecked_t sync_io; /* RAID */
61816 struct disk_events *ev;
61817 #ifdef CONFIG_BLK_DEV_INTEGRITY
61818 struct blk_integrity *integrity;
61819 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
61820 index 1e49be4..b8a9305 100644
61821 --- a/include/linux/gfp.h
61822 +++ b/include/linux/gfp.h
61823 @@ -38,6 +38,12 @@ struct vm_area_struct;
61824 #define ___GFP_OTHER_NODE 0x800000u
61825 #define ___GFP_WRITE 0x1000000u
61826
61827 +#ifdef CONFIG_PAX_USERCOPY_SLABS
61828 +#define ___GFP_USERCOPY 0x2000000u
61829 +#else
61830 +#define ___GFP_USERCOPY 0
61831 +#endif
61832 +
61833 /*
61834 * GFP bitmasks..
61835 *
61836 @@ -87,6 +93,7 @@ struct vm_area_struct;
61837 #define __GFP_NO_KSWAPD ((__force gfp_t)___GFP_NO_KSWAPD)
61838 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
61839 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
61840 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
61841
61842 /*
61843 * This may seem redundant, but it's a way of annotating false positives vs.
61844 @@ -94,7 +101,7 @@ struct vm_area_struct;
61845 */
61846 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
61847
61848 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
61849 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
61850 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
61851
61852 /* This equals 0, but use constants in case they ever change */
61853 @@ -148,6 +155,8 @@ struct vm_area_struct;
61854 /* 4GB DMA on some platforms */
61855 #define GFP_DMA32 __GFP_DMA32
61856
61857 +#define GFP_USERCOPY __GFP_USERCOPY
61858 +
61859 /* Convert GFP flags to their corresponding migrate type */
61860 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
61861 {
61862 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
61863 new file mode 100644
61864 index 0000000..c938b1f
61865 --- /dev/null
61866 +++ b/include/linux/gracl.h
61867 @@ -0,0 +1,319 @@
61868 +#ifndef GR_ACL_H
61869 +#define GR_ACL_H
61870 +
61871 +#include <linux/grdefs.h>
61872 +#include <linux/resource.h>
61873 +#include <linux/capability.h>
61874 +#include <linux/dcache.h>
61875 +#include <asm/resource.h>
61876 +
61877 +/* Major status information */
61878 +
61879 +#define GR_VERSION "grsecurity 2.9.1"
61880 +#define GRSECURITY_VERSION 0x2901
61881 +
61882 +enum {
61883 + GR_SHUTDOWN = 0,
61884 + GR_ENABLE = 1,
61885 + GR_SPROLE = 2,
61886 + GR_RELOAD = 3,
61887 + GR_SEGVMOD = 4,
61888 + GR_STATUS = 5,
61889 + GR_UNSPROLE = 6,
61890 + GR_PASSSET = 7,
61891 + GR_SPROLEPAM = 8,
61892 +};
61893 +
61894 +/* Password setup definitions
61895 + * kernel/grhash.c */
61896 +enum {
61897 + GR_PW_LEN = 128,
61898 + GR_SALT_LEN = 16,
61899 + GR_SHA_LEN = 32,
61900 +};
61901 +
61902 +enum {
61903 + GR_SPROLE_LEN = 64,
61904 +};
61905 +
61906 +enum {
61907 + GR_NO_GLOB = 0,
61908 + GR_REG_GLOB,
61909 + GR_CREATE_GLOB
61910 +};
61911 +
61912 +#define GR_NLIMITS 32
61913 +
61914 +/* Begin Data Structures */
61915 +
61916 +struct sprole_pw {
61917 + unsigned char *rolename;
61918 + unsigned char salt[GR_SALT_LEN];
61919 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
61920 +};
61921 +
61922 +struct name_entry {
61923 + __u32 key;
61924 + ino_t inode;
61925 + dev_t device;
61926 + char *name;
61927 + __u16 len;
61928 + __u8 deleted;
61929 + struct name_entry *prev;
61930 + struct name_entry *next;
61931 +};
61932 +
61933 +struct inodev_entry {
61934 + struct name_entry *nentry;
61935 + struct inodev_entry *prev;
61936 + struct inodev_entry *next;
61937 +};
61938 +
61939 +struct acl_role_db {
61940 + struct acl_role_label **r_hash;
61941 + __u32 r_size;
61942 +};
61943 +
61944 +struct inodev_db {
61945 + struct inodev_entry **i_hash;
61946 + __u32 i_size;
61947 +};
61948 +
61949 +struct name_db {
61950 + struct name_entry **n_hash;
61951 + __u32 n_size;
61952 +};
61953 +
61954 +struct crash_uid {
61955 + uid_t uid;
61956 + unsigned long expires;
61957 +};
61958 +
61959 +struct gr_hash_struct {
61960 + void **table;
61961 + void **nametable;
61962 + void *first;
61963 + __u32 table_size;
61964 + __u32 used_size;
61965 + int type;
61966 +};
61967 +
61968 +/* Userspace Grsecurity ACL data structures */
61969 +
61970 +struct acl_subject_label {
61971 + char *filename;
61972 + ino_t inode;
61973 + dev_t device;
61974 + __u32 mode;
61975 + kernel_cap_t cap_mask;
61976 + kernel_cap_t cap_lower;
61977 + kernel_cap_t cap_invert_audit;
61978 +
61979 + struct rlimit res[GR_NLIMITS];
61980 + __u32 resmask;
61981 +
61982 + __u8 user_trans_type;
61983 + __u8 group_trans_type;
61984 + uid_t *user_transitions;
61985 + gid_t *group_transitions;
61986 + __u16 user_trans_num;
61987 + __u16 group_trans_num;
61988 +
61989 + __u32 sock_families[2];
61990 + __u32 ip_proto[8];
61991 + __u32 ip_type;
61992 + struct acl_ip_label **ips;
61993 + __u32 ip_num;
61994 + __u32 inaddr_any_override;
61995 +
61996 + __u32 crashes;
61997 + unsigned long expires;
61998 +
61999 + struct acl_subject_label *parent_subject;
62000 + struct gr_hash_struct *hash;
62001 + struct acl_subject_label *prev;
62002 + struct acl_subject_label *next;
62003 +
62004 + struct acl_object_label **obj_hash;
62005 + __u32 obj_hash_size;
62006 + __u16 pax_flags;
62007 +};
62008 +
62009 +struct role_allowed_ip {
62010 + __u32 addr;
62011 + __u32 netmask;
62012 +
62013 + struct role_allowed_ip *prev;
62014 + struct role_allowed_ip *next;
62015 +};
62016 +
62017 +struct role_transition {
62018 + char *rolename;
62019 +
62020 + struct role_transition *prev;
62021 + struct role_transition *next;
62022 +};
62023 +
62024 +struct acl_role_label {
62025 + char *rolename;
62026 + uid_t uidgid;
62027 + __u16 roletype;
62028 +
62029 + __u16 auth_attempts;
62030 + unsigned long expires;
62031 +
62032 + struct acl_subject_label *root_label;
62033 + struct gr_hash_struct *hash;
62034 +
62035 + struct acl_role_label *prev;
62036 + struct acl_role_label *next;
62037 +
62038 + struct role_transition *transitions;
62039 + struct role_allowed_ip *allowed_ips;
62040 + uid_t *domain_children;
62041 + __u16 domain_child_num;
62042 +
62043 + umode_t umask;
62044 +
62045 + struct acl_subject_label **subj_hash;
62046 + __u32 subj_hash_size;
62047 +};
62048 +
62049 +struct user_acl_role_db {
62050 + struct acl_role_label **r_table;
62051 + __u32 num_pointers; /* Number of allocations to track */
62052 + __u32 num_roles; /* Number of roles */
62053 + __u32 num_domain_children; /* Number of domain children */
62054 + __u32 num_subjects; /* Number of subjects */
62055 + __u32 num_objects; /* Number of objects */
62056 +};
62057 +
62058 +struct acl_object_label {
62059 + char *filename;
62060 + ino_t inode;
62061 + dev_t device;
62062 + __u32 mode;
62063 +
62064 + struct acl_subject_label *nested;
62065 + struct acl_object_label *globbed;
62066 +
62067 + /* next two structures not used */
62068 +
62069 + struct acl_object_label *prev;
62070 + struct acl_object_label *next;
62071 +};
62072 +
62073 +struct acl_ip_label {
62074 + char *iface;
62075 + __u32 addr;
62076 + __u32 netmask;
62077 + __u16 low, high;
62078 + __u8 mode;
62079 + __u32 type;
62080 + __u32 proto[8];
62081 +
62082 + /* next two structures not used */
62083 +
62084 + struct acl_ip_label *prev;
62085 + struct acl_ip_label *next;
62086 +};
62087 +
62088 +struct gr_arg {
62089 + struct user_acl_role_db role_db;
62090 + unsigned char pw[GR_PW_LEN];
62091 + unsigned char salt[GR_SALT_LEN];
62092 + unsigned char sum[GR_SHA_LEN];
62093 + unsigned char sp_role[GR_SPROLE_LEN];
62094 + struct sprole_pw *sprole_pws;
62095 + dev_t segv_device;
62096 + ino_t segv_inode;
62097 + uid_t segv_uid;
62098 + __u16 num_sprole_pws;
62099 + __u16 mode;
62100 +};
62101 +
62102 +struct gr_arg_wrapper {
62103 + struct gr_arg *arg;
62104 + __u32 version;
62105 + __u32 size;
62106 +};
62107 +
62108 +struct subject_map {
62109 + struct acl_subject_label *user;
62110 + struct acl_subject_label *kernel;
62111 + struct subject_map *prev;
62112 + struct subject_map *next;
62113 +};
62114 +
62115 +struct acl_subj_map_db {
62116 + struct subject_map **s_hash;
62117 + __u32 s_size;
62118 +};
62119 +
62120 +/* End Data Structures Section */
62121 +
62122 +/* Hash functions generated by empirical testing by Brad Spengler
62123 + Makes good use of the low bits of the inode. Generally 0-1 times
62124 + in loop for successful match. 0-3 for unsuccessful match.
62125 + Shift/add algorithm with modulus of table size and an XOR*/
62126 +
62127 +static __inline__ unsigned int
62128 +rhash(const uid_t uid, const __u16 type, const unsigned int sz)
62129 +{
62130 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
62131 +}
62132 +
62133 + static __inline__ unsigned int
62134 +shash(const struct acl_subject_label *userp, const unsigned int sz)
62135 +{
62136 + return ((const unsigned long)userp % sz);
62137 +}
62138 +
62139 +static __inline__ unsigned int
62140 +fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
62141 +{
62142 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
62143 +}
62144 +
62145 +static __inline__ unsigned int
62146 +nhash(const char *name, const __u16 len, const unsigned int sz)
62147 +{
62148 + return full_name_hash((const unsigned char *)name, len) % sz;
62149 +}
62150 +
62151 +#define FOR_EACH_ROLE_START(role) \
62152 + role = role_list; \
62153 + while (role) {
62154 +
62155 +#define FOR_EACH_ROLE_END(role) \
62156 + role = role->prev; \
62157 + }
62158 +
62159 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
62160 + subj = NULL; \
62161 + iter = 0; \
62162 + while (iter < role->subj_hash_size) { \
62163 + if (subj == NULL) \
62164 + subj = role->subj_hash[iter]; \
62165 + if (subj == NULL) { \
62166 + iter++; \
62167 + continue; \
62168 + }
62169 +
62170 +#define FOR_EACH_SUBJECT_END(subj,iter) \
62171 + subj = subj->next; \
62172 + if (subj == NULL) \
62173 + iter++; \
62174 + }
62175 +
62176 +
62177 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
62178 + subj = role->hash->first; \
62179 + while (subj != NULL) {
62180 +
62181 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
62182 + subj = subj->next; \
62183 + }
62184 +
62185 +#endif
62186 +
62187 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
62188 new file mode 100644
62189 index 0000000..323ecf2
62190 --- /dev/null
62191 +++ b/include/linux/gralloc.h
62192 @@ -0,0 +1,9 @@
62193 +#ifndef __GRALLOC_H
62194 +#define __GRALLOC_H
62195 +
62196 +void acl_free_all(void);
62197 +int acl_alloc_stack_init(unsigned long size);
62198 +void *acl_alloc(unsigned long len);
62199 +void *acl_alloc_num(unsigned long num, unsigned long len);
62200 +
62201 +#endif
62202 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
62203 new file mode 100644
62204 index 0000000..b30e9bc
62205 --- /dev/null
62206 +++ b/include/linux/grdefs.h
62207 @@ -0,0 +1,140 @@
62208 +#ifndef GRDEFS_H
62209 +#define GRDEFS_H
62210 +
62211 +/* Begin grsecurity status declarations */
62212 +
62213 +enum {
62214 + GR_READY = 0x01,
62215 + GR_STATUS_INIT = 0x00 // disabled state
62216 +};
62217 +
62218 +/* Begin ACL declarations */
62219 +
62220 +/* Role flags */
62221 +
62222 +enum {
62223 + GR_ROLE_USER = 0x0001,
62224 + GR_ROLE_GROUP = 0x0002,
62225 + GR_ROLE_DEFAULT = 0x0004,
62226 + GR_ROLE_SPECIAL = 0x0008,
62227 + GR_ROLE_AUTH = 0x0010,
62228 + GR_ROLE_NOPW = 0x0020,
62229 + GR_ROLE_GOD = 0x0040,
62230 + GR_ROLE_LEARN = 0x0080,
62231 + GR_ROLE_TPE = 0x0100,
62232 + GR_ROLE_DOMAIN = 0x0200,
62233 + GR_ROLE_PAM = 0x0400,
62234 + GR_ROLE_PERSIST = 0x0800
62235 +};
62236 +
62237 +/* ACL Subject and Object mode flags */
62238 +enum {
62239 + GR_DELETED = 0x80000000
62240 +};
62241 +
62242 +/* ACL Object-only mode flags */
62243 +enum {
62244 + GR_READ = 0x00000001,
62245 + GR_APPEND = 0x00000002,
62246 + GR_WRITE = 0x00000004,
62247 + GR_EXEC = 0x00000008,
62248 + GR_FIND = 0x00000010,
62249 + GR_INHERIT = 0x00000020,
62250 + GR_SETID = 0x00000040,
62251 + GR_CREATE = 0x00000080,
62252 + GR_DELETE = 0x00000100,
62253 + GR_LINK = 0x00000200,
62254 + GR_AUDIT_READ = 0x00000400,
62255 + GR_AUDIT_APPEND = 0x00000800,
62256 + GR_AUDIT_WRITE = 0x00001000,
62257 + GR_AUDIT_EXEC = 0x00002000,
62258 + GR_AUDIT_FIND = 0x00004000,
62259 + GR_AUDIT_INHERIT= 0x00008000,
62260 + GR_AUDIT_SETID = 0x00010000,
62261 + GR_AUDIT_CREATE = 0x00020000,
62262 + GR_AUDIT_DELETE = 0x00040000,
62263 + GR_AUDIT_LINK = 0x00080000,
62264 + GR_PTRACERD = 0x00100000,
62265 + GR_NOPTRACE = 0x00200000,
62266 + GR_SUPPRESS = 0x00400000,
62267 + GR_NOLEARN = 0x00800000,
62268 + GR_INIT_TRANSFER= 0x01000000
62269 +};
62270 +
62271 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
62272 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
62273 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
62274 +
62275 +/* ACL subject-only mode flags */
62276 +enum {
62277 + GR_KILL = 0x00000001,
62278 + GR_VIEW = 0x00000002,
62279 + GR_PROTECTED = 0x00000004,
62280 + GR_LEARN = 0x00000008,
62281 + GR_OVERRIDE = 0x00000010,
62282 + /* just a placeholder, this mode is only used in userspace */
62283 + GR_DUMMY = 0x00000020,
62284 + GR_PROTSHM = 0x00000040,
62285 + GR_KILLPROC = 0x00000080,
62286 + GR_KILLIPPROC = 0x00000100,
62287 + /* just a placeholder, this mode is only used in userspace */
62288 + GR_NOTROJAN = 0x00000200,
62289 + GR_PROTPROCFD = 0x00000400,
62290 + GR_PROCACCT = 0x00000800,
62291 + GR_RELAXPTRACE = 0x00001000,
62292 + GR_NESTED = 0x00002000,
62293 + GR_INHERITLEARN = 0x00004000,
62294 + GR_PROCFIND = 0x00008000,
62295 + GR_POVERRIDE = 0x00010000,
62296 + GR_KERNELAUTH = 0x00020000,
62297 + GR_ATSECURE = 0x00040000,
62298 + GR_SHMEXEC = 0x00080000
62299 +};
62300 +
62301 +enum {
62302 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
62303 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
62304 + GR_PAX_ENABLE_MPROTECT = 0x0004,
62305 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
62306 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
62307 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
62308 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
62309 + GR_PAX_DISABLE_MPROTECT = 0x0400,
62310 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
62311 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
62312 +};
62313 +
62314 +enum {
62315 + GR_ID_USER = 0x01,
62316 + GR_ID_GROUP = 0x02,
62317 +};
62318 +
62319 +enum {
62320 + GR_ID_ALLOW = 0x01,
62321 + GR_ID_DENY = 0x02,
62322 +};
62323 +
62324 +#define GR_CRASH_RES 31
62325 +#define GR_UIDTABLE_MAX 500
62326 +
62327 +/* begin resource learning section */
62328 +enum {
62329 + GR_RLIM_CPU_BUMP = 60,
62330 + GR_RLIM_FSIZE_BUMP = 50000,
62331 + GR_RLIM_DATA_BUMP = 10000,
62332 + GR_RLIM_STACK_BUMP = 1000,
62333 + GR_RLIM_CORE_BUMP = 10000,
62334 + GR_RLIM_RSS_BUMP = 500000,
62335 + GR_RLIM_NPROC_BUMP = 1,
62336 + GR_RLIM_NOFILE_BUMP = 5,
62337 + GR_RLIM_MEMLOCK_BUMP = 50000,
62338 + GR_RLIM_AS_BUMP = 500000,
62339 + GR_RLIM_LOCKS_BUMP = 2,
62340 + GR_RLIM_SIGPENDING_BUMP = 5,
62341 + GR_RLIM_MSGQUEUE_BUMP = 10000,
62342 + GR_RLIM_NICE_BUMP = 1,
62343 + GR_RLIM_RTPRIO_BUMP = 1,
62344 + GR_RLIM_RTTIME_BUMP = 1000000
62345 +};
62346 +
62347 +#endif
62348 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
62349 new file mode 100644
62350 index 0000000..c9292f7
62351 --- /dev/null
62352 +++ b/include/linux/grinternal.h
62353 @@ -0,0 +1,223 @@
62354 +#ifndef __GRINTERNAL_H
62355 +#define __GRINTERNAL_H
62356 +
62357 +#ifdef CONFIG_GRKERNSEC
62358 +
62359 +#include <linux/fs.h>
62360 +#include <linux/mnt_namespace.h>
62361 +#include <linux/nsproxy.h>
62362 +#include <linux/gracl.h>
62363 +#include <linux/grdefs.h>
62364 +#include <linux/grmsg.h>
62365 +
62366 +void gr_add_learn_entry(const char *fmt, ...)
62367 + __attribute__ ((format (printf, 1, 2)));
62368 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
62369 + const struct vfsmount *mnt);
62370 +__u32 gr_check_create(const struct dentry *new_dentry,
62371 + const struct dentry *parent,
62372 + const struct vfsmount *mnt, const __u32 mode);
62373 +int gr_check_protected_task(const struct task_struct *task);
62374 +__u32 to_gr_audit(const __u32 reqmode);
62375 +int gr_set_acls(const int type);
62376 +int gr_apply_subject_to_task(struct task_struct *task);
62377 +int gr_acl_is_enabled(void);
62378 +char gr_roletype_to_char(void);
62379 +
62380 +void gr_handle_alertkill(struct task_struct *task);
62381 +char *gr_to_filename(const struct dentry *dentry,
62382 + const struct vfsmount *mnt);
62383 +char *gr_to_filename1(const struct dentry *dentry,
62384 + const struct vfsmount *mnt);
62385 +char *gr_to_filename2(const struct dentry *dentry,
62386 + const struct vfsmount *mnt);
62387 +char *gr_to_filename3(const struct dentry *dentry,
62388 + const struct vfsmount *mnt);
62389 +
62390 +extern int grsec_enable_ptrace_readexec;
62391 +extern int grsec_enable_harden_ptrace;
62392 +extern int grsec_enable_link;
62393 +extern int grsec_enable_fifo;
62394 +extern int grsec_enable_execve;
62395 +extern int grsec_enable_shm;
62396 +extern int grsec_enable_execlog;
62397 +extern int grsec_enable_signal;
62398 +extern int grsec_enable_audit_ptrace;
62399 +extern int grsec_enable_forkfail;
62400 +extern int grsec_enable_time;
62401 +extern int grsec_enable_rofs;
62402 +extern int grsec_enable_chroot_shmat;
62403 +extern int grsec_enable_chroot_mount;
62404 +extern int grsec_enable_chroot_double;
62405 +extern int grsec_enable_chroot_pivot;
62406 +extern int grsec_enable_chroot_chdir;
62407 +extern int grsec_enable_chroot_chmod;
62408 +extern int grsec_enable_chroot_mknod;
62409 +extern int grsec_enable_chroot_fchdir;
62410 +extern int grsec_enable_chroot_nice;
62411 +extern int grsec_enable_chroot_execlog;
62412 +extern int grsec_enable_chroot_caps;
62413 +extern int grsec_enable_chroot_sysctl;
62414 +extern int grsec_enable_chroot_unix;
62415 +extern int grsec_enable_symlinkown;
62416 +extern int grsec_symlinkown_gid;
62417 +extern int grsec_enable_tpe;
62418 +extern int grsec_tpe_gid;
62419 +extern int grsec_enable_tpe_all;
62420 +extern int grsec_enable_tpe_invert;
62421 +extern int grsec_enable_socket_all;
62422 +extern int grsec_socket_all_gid;
62423 +extern int grsec_enable_socket_client;
62424 +extern int grsec_socket_client_gid;
62425 +extern int grsec_enable_socket_server;
62426 +extern int grsec_socket_server_gid;
62427 +extern int grsec_audit_gid;
62428 +extern int grsec_enable_group;
62429 +extern int grsec_enable_audit_textrel;
62430 +extern int grsec_enable_log_rwxmaps;
62431 +extern int grsec_enable_mount;
62432 +extern int grsec_enable_chdir;
62433 +extern int grsec_resource_logging;
62434 +extern int grsec_enable_blackhole;
62435 +extern int grsec_lastack_retries;
62436 +extern int grsec_enable_brute;
62437 +extern int grsec_lock;
62438 +
62439 +extern spinlock_t grsec_alert_lock;
62440 +extern unsigned long grsec_alert_wtime;
62441 +extern unsigned long grsec_alert_fyet;
62442 +
62443 +extern spinlock_t grsec_audit_lock;
62444 +
62445 +extern rwlock_t grsec_exec_file_lock;
62446 +
62447 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
62448 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
62449 + (tsk)->exec_file->f_vfsmnt) : "/")
62450 +
62451 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
62452 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
62453 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62454 +
62455 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
62456 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
62457 + (tsk)->exec_file->f_vfsmnt) : "/")
62458 +
62459 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
62460 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
62461 + (tsk)->real_parent->exec_file->f_vfsmnt) : "/")
62462 +
62463 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
62464 +
62465 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
62466 +
62467 +#define DEFAULTSECARGS(task, cred, pcred) gr_task_fullpath(task), (task)->comm, \
62468 + (task)->pid, (cred)->uid, \
62469 + (cred)->euid, (cred)->gid, (cred)->egid, \
62470 + gr_parent_task_fullpath(task), \
62471 + (task)->real_parent->comm, (task)->real_parent->pid, \
62472 + (pcred)->uid, (pcred)->euid, \
62473 + (pcred)->gid, (pcred)->egid
62474 +
62475 +#define GR_CHROOT_CAPS {{ \
62476 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
62477 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
62478 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
62479 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
62480 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
62481 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
62482 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
62483 +
62484 +#define security_learn(normal_msg,args...) \
62485 +({ \
62486 + read_lock(&grsec_exec_file_lock); \
62487 + gr_add_learn_entry(normal_msg "\n", ## args); \
62488 + read_unlock(&grsec_exec_file_lock); \
62489 +})
62490 +
62491 +enum {
62492 + GR_DO_AUDIT,
62493 + GR_DONT_AUDIT,
62494 + /* used for non-audit messages that we shouldn't kill the task on */
62495 + GR_DONT_AUDIT_GOOD
62496 +};
62497 +
62498 +enum {
62499 + GR_TTYSNIFF,
62500 + GR_RBAC,
62501 + GR_RBAC_STR,
62502 + GR_STR_RBAC,
62503 + GR_RBAC_MODE2,
62504 + GR_RBAC_MODE3,
62505 + GR_FILENAME,
62506 + GR_SYSCTL_HIDDEN,
62507 + GR_NOARGS,
62508 + GR_ONE_INT,
62509 + GR_ONE_INT_TWO_STR,
62510 + GR_ONE_STR,
62511 + GR_STR_INT,
62512 + GR_TWO_STR_INT,
62513 + GR_TWO_INT,
62514 + GR_TWO_U64,
62515 + GR_THREE_INT,
62516 + GR_FIVE_INT_TWO_STR,
62517 + GR_TWO_STR,
62518 + GR_THREE_STR,
62519 + GR_FOUR_STR,
62520 + GR_STR_FILENAME,
62521 + GR_FILENAME_STR,
62522 + GR_FILENAME_TWO_INT,
62523 + GR_FILENAME_TWO_INT_STR,
62524 + GR_TEXTREL,
62525 + GR_PTRACE,
62526 + GR_RESOURCE,
62527 + GR_CAP,
62528 + GR_SIG,
62529 + GR_SIG2,
62530 + GR_CRASH1,
62531 + GR_CRASH2,
62532 + GR_PSACCT,
62533 + GR_RWXMAP
62534 +};
62535 +
62536 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
62537 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
62538 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
62539 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
62540 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
62541 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
62542 +#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)
62543 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
62544 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
62545 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
62546 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
62547 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
62548 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
62549 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
62550 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
62551 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
62552 +#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)
62553 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
62554 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
62555 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
62556 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
62557 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
62558 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
62559 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
62560 +#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)
62561 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
62562 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
62563 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
62564 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
62565 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
62566 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
62567 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
62568 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
62569 +#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)
62570 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
62571 +
62572 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
62573 +
62574 +#endif
62575 +
62576 +#endif
62577 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
62578 new file mode 100644
62579 index 0000000..54f4e85
62580 --- /dev/null
62581 +++ b/include/linux/grmsg.h
62582 @@ -0,0 +1,110 @@
62583 +#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"
62584 +#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"
62585 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
62586 +#define GR_STOPMOD_MSG "denied modification of module state by "
62587 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
62588 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
62589 +#define GR_IOPERM_MSG "denied use of ioperm() by "
62590 +#define GR_IOPL_MSG "denied use of iopl() by "
62591 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
62592 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
62593 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
62594 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
62595 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
62596 +#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"
62597 +#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"
62598 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
62599 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
62600 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
62601 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
62602 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
62603 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
62604 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
62605 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
62606 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
62607 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
62608 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
62609 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
62610 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
62611 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
62612 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
62613 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
62614 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
62615 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
62616 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
62617 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
62618 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
62619 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
62620 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
62621 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
62622 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
62623 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
62624 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
62625 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
62626 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
62627 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
62628 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
62629 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
62630 +#define GR_SETXATTR_ACL_MSG "%s setting extended attributes of %.950s by "
62631 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
62632 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
62633 +#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"
62634 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
62635 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
62636 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
62637 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
62638 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
62639 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
62640 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
62641 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
62642 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
62643 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
62644 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
62645 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
62646 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
62647 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
62648 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
62649 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
62650 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
62651 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
62652 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
62653 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
62654 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
62655 +#define GR_NICE_CHROOT_MSG "denied priority change by "
62656 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
62657 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
62658 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
62659 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
62660 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
62661 +#define GR_TIME_MSG "time set by "
62662 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
62663 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
62664 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
62665 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
62666 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
62667 +#define GR_BIND_MSG "denied bind() by "
62668 +#define GR_CONNECT_MSG "denied connect() by "
62669 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
62670 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
62671 +#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"
62672 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
62673 +#define GR_CAP_ACL_MSG "use of %s denied for "
62674 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
62675 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
62676 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
62677 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
62678 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
62679 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
62680 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
62681 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
62682 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
62683 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
62684 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
62685 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
62686 +#define GR_TEXTREL_AUDIT_MSG "text relocation in %s, VMA:0x%08lx 0x%08lx by "
62687 +#define GR_VM86_MSG "denied use of vm86 by "
62688 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
62689 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
62690 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
62691 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
62692 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
62693 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
62694 new file mode 100644
62695 index 0000000..f9b9a21
62696 --- /dev/null
62697 +++ b/include/linux/grsecurity.h
62698 @@ -0,0 +1,238 @@
62699 +#ifndef GR_SECURITY_H
62700 +#define GR_SECURITY_H
62701 +#include <linux/fs.h>
62702 +#include <linux/fs_struct.h>
62703 +#include <linux/binfmts.h>
62704 +#include <linux/gracl.h>
62705 +
62706 +/* notify of brain-dead configs */
62707 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62708 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
62709 +#endif
62710 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
62711 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
62712 +#endif
62713 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
62714 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
62715 +#endif
62716 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
62717 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
62718 +#endif
62719 +
62720 +#include <linux/compat.h>
62721 +
62722 +struct user_arg_ptr {
62723 +#ifdef CONFIG_COMPAT
62724 + bool is_compat;
62725 +#endif
62726 + union {
62727 + const char __user *const __user *native;
62728 +#ifdef CONFIG_COMPAT
62729 + compat_uptr_t __user *compat;
62730 +#endif
62731 + } ptr;
62732 +};
62733 +
62734 +void gr_handle_brute_attach(struct task_struct *p, unsigned long mm_flags);
62735 +void gr_handle_brute_check(void);
62736 +void gr_handle_kernel_exploit(void);
62737 +int gr_process_user_ban(void);
62738 +
62739 +char gr_roletype_to_char(void);
62740 +
62741 +int gr_acl_enable_at_secure(void);
62742 +
62743 +int gr_check_user_change(int real, int effective, int fs);
62744 +int gr_check_group_change(int real, int effective, int fs);
62745 +
62746 +void gr_del_task_from_ip_table(struct task_struct *p);
62747 +
62748 +int gr_pid_is_chrooted(struct task_struct *p);
62749 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
62750 +int gr_handle_chroot_nice(void);
62751 +int gr_handle_chroot_sysctl(const int op);
62752 +int gr_handle_chroot_setpriority(struct task_struct *p,
62753 + const int niceval);
62754 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
62755 +int gr_handle_chroot_chroot(const struct dentry *dentry,
62756 + const struct vfsmount *mnt);
62757 +void gr_handle_chroot_chdir(struct path *path);
62758 +int gr_handle_chroot_chmod(const struct dentry *dentry,
62759 + const struct vfsmount *mnt, const int mode);
62760 +int gr_handle_chroot_mknod(const struct dentry *dentry,
62761 + const struct vfsmount *mnt, const int mode);
62762 +int gr_handle_chroot_mount(const struct dentry *dentry,
62763 + const struct vfsmount *mnt,
62764 + const char *dev_name);
62765 +int gr_handle_chroot_pivot(void);
62766 +int gr_handle_chroot_unix(const pid_t pid);
62767 +
62768 +int gr_handle_rawio(const struct inode *inode);
62769 +
62770 +void gr_handle_ioperm(void);
62771 +void gr_handle_iopl(void);
62772 +
62773 +umode_t gr_acl_umask(void);
62774 +
62775 +int gr_tpe_allow(const struct file *file);
62776 +
62777 +void gr_set_chroot_entries(struct task_struct *task, struct path *path);
62778 +void gr_clear_chroot_entries(struct task_struct *task);
62779 +
62780 +void gr_log_forkfail(const int retval);
62781 +void gr_log_timechange(void);
62782 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
62783 +void gr_log_chdir(const struct dentry *dentry,
62784 + const struct vfsmount *mnt);
62785 +void gr_log_chroot_exec(const struct dentry *dentry,
62786 + const struct vfsmount *mnt);
62787 +void gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv);
62788 +void gr_log_remount(const char *devname, const int retval);
62789 +void gr_log_unmount(const char *devname, const int retval);
62790 +void gr_log_mount(const char *from, const char *to, const int retval);
62791 +void gr_log_textrel(struct vm_area_struct *vma);
62792 +void gr_log_rwxmmap(struct file *file);
62793 +void gr_log_rwxmprotect(struct file *file);
62794 +
62795 +int gr_handle_follow_link(const struct inode *parent,
62796 + const struct inode *inode,
62797 + const struct dentry *dentry,
62798 + const struct vfsmount *mnt);
62799 +int gr_handle_fifo(const struct dentry *dentry,
62800 + const struct vfsmount *mnt,
62801 + const struct dentry *dir, const int flag,
62802 + const int acc_mode);
62803 +int gr_handle_hardlink(const struct dentry *dentry,
62804 + const struct vfsmount *mnt,
62805 + struct inode *inode,
62806 + const int mode, const char *to);
62807 +
62808 +int gr_is_capable(const int cap);
62809 +int gr_is_capable_nolog(const int cap);
62810 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
62811 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
62812 +
62813 +void gr_learn_resource(const struct task_struct *task, const int limit,
62814 + const unsigned long wanted, const int gt);
62815 +void gr_copy_label(struct task_struct *tsk);
62816 +void gr_handle_crash(struct task_struct *task, const int sig);
62817 +int gr_handle_signal(const struct task_struct *p, const int sig);
62818 +int gr_check_crash_uid(const uid_t uid);
62819 +int gr_check_protected_task(const struct task_struct *task);
62820 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
62821 +int gr_acl_handle_mmap(const struct file *file,
62822 + const unsigned long prot);
62823 +int gr_acl_handle_mprotect(const struct file *file,
62824 + const unsigned long prot);
62825 +int gr_check_hidden_task(const struct task_struct *tsk);
62826 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
62827 + const struct vfsmount *mnt);
62828 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
62829 + const struct vfsmount *mnt);
62830 +__u32 gr_acl_handle_access(const struct dentry *dentry,
62831 + const struct vfsmount *mnt, const int fmode);
62832 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
62833 + const struct vfsmount *mnt, umode_t *mode);
62834 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
62835 + const struct vfsmount *mnt);
62836 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
62837 + const struct vfsmount *mnt);
62838 +int gr_handle_ptrace(struct task_struct *task, const long request);
62839 +int gr_handle_proc_ptrace(struct task_struct *task);
62840 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
62841 + const struct vfsmount *mnt);
62842 +int gr_check_crash_exec(const struct file *filp);
62843 +int gr_acl_is_enabled(void);
62844 +void gr_set_kernel_label(struct task_struct *task);
62845 +void gr_set_role_label(struct task_struct *task, const uid_t uid,
62846 + const gid_t gid);
62847 +int gr_set_proc_label(const struct dentry *dentry,
62848 + const struct vfsmount *mnt,
62849 + const int unsafe_flags);
62850 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
62851 + const struct vfsmount *mnt);
62852 +__u32 gr_acl_handle_open(const struct dentry *dentry,
62853 + const struct vfsmount *mnt, int acc_mode);
62854 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
62855 + const struct dentry *p_dentry,
62856 + const struct vfsmount *p_mnt,
62857 + int open_flags, int acc_mode, const int imode);
62858 +void gr_handle_create(const struct dentry *dentry,
62859 + const struct vfsmount *mnt);
62860 +void gr_handle_proc_create(const struct dentry *dentry,
62861 + const struct inode *inode);
62862 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
62863 + const struct dentry *parent_dentry,
62864 + const struct vfsmount *parent_mnt,
62865 + const int mode);
62866 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
62867 + const struct dentry *parent_dentry,
62868 + const struct vfsmount *parent_mnt);
62869 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
62870 + const struct vfsmount *mnt);
62871 +void gr_handle_delete(const ino_t ino, const dev_t dev);
62872 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
62873 + const struct vfsmount *mnt);
62874 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
62875 + const struct dentry *parent_dentry,
62876 + const struct vfsmount *parent_mnt,
62877 + const char *from);
62878 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
62879 + const struct dentry *parent_dentry,
62880 + const struct vfsmount *parent_mnt,
62881 + const struct dentry *old_dentry,
62882 + const struct vfsmount *old_mnt, const char *to);
62883 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
62884 +int gr_acl_handle_rename(struct dentry *new_dentry,
62885 + struct dentry *parent_dentry,
62886 + const struct vfsmount *parent_mnt,
62887 + struct dentry *old_dentry,
62888 + struct inode *old_parent_inode,
62889 + struct vfsmount *old_mnt, const char *newname);
62890 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
62891 + struct dentry *old_dentry,
62892 + struct dentry *new_dentry,
62893 + struct vfsmount *mnt, const __u8 replace);
62894 +__u32 gr_check_link(const struct dentry *new_dentry,
62895 + const struct dentry *parent_dentry,
62896 + const struct vfsmount *parent_mnt,
62897 + const struct dentry *old_dentry,
62898 + const struct vfsmount *old_mnt);
62899 +int gr_acl_handle_filldir(const struct file *file, const char *name,
62900 + const unsigned int namelen, const ino_t ino);
62901 +
62902 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
62903 + const struct vfsmount *mnt);
62904 +void gr_acl_handle_exit(void);
62905 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
62906 +int gr_acl_handle_procpidmem(const struct task_struct *task);
62907 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
62908 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
62909 +void gr_audit_ptrace(struct task_struct *task);
62910 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
62911 +
62912 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
62913 +
62914 +#ifdef CONFIG_GRKERNSEC
62915 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
62916 +void gr_handle_vm86(void);
62917 +void gr_handle_mem_readwrite(u64 from, u64 to);
62918 +
62919 +void gr_log_badprocpid(const char *entry);
62920 +
62921 +extern int grsec_enable_dmesg;
62922 +extern int grsec_disable_privio;
62923 +
62924 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62925 +extern int grsec_proc_gid;
62926 +#endif
62927 +
62928 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
62929 +extern int grsec_enable_chroot_findtask;
62930 +#endif
62931 +#ifdef CONFIG_GRKERNSEC_SETXID
62932 +extern int grsec_enable_setxid;
62933 +#endif
62934 +#endif
62935 +
62936 +#endif
62937 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
62938 new file mode 100644
62939 index 0000000..e7ffaaf
62940 --- /dev/null
62941 +++ b/include/linux/grsock.h
62942 @@ -0,0 +1,19 @@
62943 +#ifndef __GRSOCK_H
62944 +#define __GRSOCK_H
62945 +
62946 +extern void gr_attach_curr_ip(const struct sock *sk);
62947 +extern int gr_handle_sock_all(const int family, const int type,
62948 + const int protocol);
62949 +extern int gr_handle_sock_server(const struct sockaddr *sck);
62950 +extern int gr_handle_sock_server_other(const struct sock *sck);
62951 +extern int gr_handle_sock_client(const struct sockaddr *sck);
62952 +extern int gr_search_connect(struct socket * sock,
62953 + struct sockaddr_in * addr);
62954 +extern int gr_search_bind(struct socket * sock,
62955 + struct sockaddr_in * addr);
62956 +extern int gr_search_listen(struct socket * sock);
62957 +extern int gr_search_accept(struct socket * sock);
62958 +extern int gr_search_socket(const int domain, const int type,
62959 + const int protocol);
62960 +
62961 +#endif
62962 diff --git a/include/linux/hid.h b/include/linux/hid.h
62963 index 449fa38..b37c8cc 100644
62964 --- a/include/linux/hid.h
62965 +++ b/include/linux/hid.h
62966 @@ -704,7 +704,7 @@ struct hid_ll_driver {
62967 unsigned int code, int value);
62968
62969 int (*parse)(struct hid_device *hdev);
62970 -};
62971 +} __no_const;
62972
62973 #define PM_HINT_FULLON 1<<5
62974 #define PM_HINT_NORMAL 1<<1
62975 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
62976 index d3999b4..1304cb4 100644
62977 --- a/include/linux/highmem.h
62978 +++ b/include/linux/highmem.h
62979 @@ -221,6 +221,18 @@ static inline void clear_highpage(struct page *page)
62980 kunmap_atomic(kaddr);
62981 }
62982
62983 +static inline void sanitize_highpage(struct page *page)
62984 +{
62985 + void *kaddr;
62986 + unsigned long flags;
62987 +
62988 + local_irq_save(flags);
62989 + kaddr = kmap_atomic(page);
62990 + clear_page(kaddr);
62991 + kunmap_atomic(kaddr);
62992 + local_irq_restore(flags);
62993 +}
62994 +
62995 static inline void zero_user_segments(struct page *page,
62996 unsigned start1, unsigned end1,
62997 unsigned start2, unsigned end2)
62998 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
62999 index ddfa041..a44cfff 100644
63000 --- a/include/linux/i2c.h
63001 +++ b/include/linux/i2c.h
63002 @@ -366,6 +366,7 @@ struct i2c_algorithm {
63003 /* To determine what the adapter supports */
63004 u32 (*functionality) (struct i2c_adapter *);
63005 };
63006 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
63007
63008 /*
63009 * i2c_adapter is the structure used to identify a physical i2c bus along
63010 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
63011 index d23c3c2..eb63c81 100644
63012 --- a/include/linux/i2o.h
63013 +++ b/include/linux/i2o.h
63014 @@ -565,7 +565,7 @@ struct i2o_controller {
63015 struct i2o_device *exec; /* Executive */
63016 #if BITS_PER_LONG == 64
63017 spinlock_t context_list_lock; /* lock for context_list */
63018 - atomic_t context_list_counter; /* needed for unique contexts */
63019 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
63020 struct list_head context_list; /* list of context id's
63021 and pointers */
63022 #endif
63023 diff --git a/include/linux/if_team.h b/include/linux/if_team.h
63024 index 8185f57..7b2d222 100644
63025 --- a/include/linux/if_team.h
63026 +++ b/include/linux/if_team.h
63027 @@ -74,6 +74,7 @@ struct team_mode_ops {
63028 void (*port_leave)(struct team *team, struct team_port *port);
63029 void (*port_change_mac)(struct team *team, struct team_port *port);
63030 };
63031 +typedef struct team_mode_ops __no_const team_mode_ops_no_const;
63032
63033 enum team_option_type {
63034 TEAM_OPTION_TYPE_U32,
63035 @@ -136,7 +137,7 @@ struct team {
63036 struct list_head option_inst_list; /* list of option instances */
63037
63038 const struct team_mode *mode;
63039 - struct team_mode_ops ops;
63040 + team_mode_ops_no_const ops;
63041 long mode_priv[TEAM_MODE_PRIV_LONGS];
63042 };
63043
63044 diff --git a/include/linux/init.h b/include/linux/init.h
63045 index 6b95109..7616d09 100644
63046 --- a/include/linux/init.h
63047 +++ b/include/linux/init.h
63048 @@ -39,9 +39,15 @@
63049 * Also note, that this data cannot be "const".
63050 */
63051
63052 +#ifdef MODULE
63053 +#define add_latent_entropy
63054 +#else
63055 +#define add_latent_entropy __latent_entropy
63056 +#endif
63057 +
63058 /* These are for everybody (although not all archs will actually
63059 discard it in modules) */
63060 -#define __init __section(.init.text) __cold notrace
63061 +#define __init __section(.init.text) __cold notrace add_latent_entropy
63062 #define __initdata __section(.init.data)
63063 #define __initconst __section(.init.rodata)
63064 #define __exitdata __section(.exit.data)
63065 @@ -83,7 +89,7 @@
63066 #define __exit __section(.exit.text) __exitused __cold notrace
63067
63068 /* Used for HOTPLUG */
63069 -#define __devinit __section(.devinit.text) __cold notrace
63070 +#define __devinit __section(.devinit.text) __cold notrace add_latent_entropy
63071 #define __devinitdata __section(.devinit.data)
63072 #define __devinitconst __section(.devinit.rodata)
63073 #define __devexit __section(.devexit.text) __exitused __cold notrace
63074 @@ -91,7 +97,7 @@
63075 #define __devexitconst __section(.devexit.rodata)
63076
63077 /* Used for HOTPLUG_CPU */
63078 -#define __cpuinit __section(.cpuinit.text) __cold notrace
63079 +#define __cpuinit __section(.cpuinit.text) __cold notrace add_latent_entropy
63080 #define __cpuinitdata __section(.cpuinit.data)
63081 #define __cpuinitconst __section(.cpuinit.rodata)
63082 #define __cpuexit __section(.cpuexit.text) __exitused __cold notrace
63083 @@ -99,7 +105,7 @@
63084 #define __cpuexitconst __section(.cpuexit.rodata)
63085
63086 /* Used for MEMORY_HOTPLUG */
63087 -#define __meminit __section(.meminit.text) __cold notrace
63088 +#define __meminit __section(.meminit.text) __cold notrace add_latent_entropy
63089 #define __meminitdata __section(.meminit.data)
63090 #define __meminitconst __section(.meminit.rodata)
63091 #define __memexit __section(.memexit.text) __exitused __cold notrace
63092 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
63093 index b806b82..2e2837e 100644
63094 --- a/include/linux/init_task.h
63095 +++ b/include/linux/init_task.h
63096 @@ -143,6 +143,12 @@ extern struct task_group root_task_group;
63097
63098 #define INIT_TASK_COMM "swapper"
63099
63100 +#ifdef CONFIG_X86
63101 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
63102 +#else
63103 +#define INIT_TASK_THREAD_INFO
63104 +#endif
63105 +
63106 /*
63107 * INIT_TASK is used to set up the first task table, touch at
63108 * your own risk!. Base=0, limit=0x1fffff (=2MB)
63109 @@ -182,6 +188,7 @@ extern struct task_group root_task_group;
63110 RCU_INIT_POINTER(.cred, &init_cred), \
63111 .comm = INIT_TASK_COMM, \
63112 .thread = INIT_THREAD, \
63113 + INIT_TASK_THREAD_INFO \
63114 .fs = &init_fs, \
63115 .files = &init_files, \
63116 .signal = &init_signals, \
63117 diff --git a/include/linux/intel-iommu.h b/include/linux/intel-iommu.h
63118 index e6ca56d..8583707 100644
63119 --- a/include/linux/intel-iommu.h
63120 +++ b/include/linux/intel-iommu.h
63121 @@ -296,7 +296,7 @@ struct iommu_flush {
63122 u8 fm, u64 type);
63123 void (*flush_iotlb)(struct intel_iommu *iommu, u16 did, u64 addr,
63124 unsigned int size_order, u64 type);
63125 -};
63126 +} __no_const;
63127
63128 enum {
63129 SR_DMAR_FECTL_REG,
63130 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
63131 index e68a8e5..811b9af 100644
63132 --- a/include/linux/interrupt.h
63133 +++ b/include/linux/interrupt.h
63134 @@ -435,7 +435,7 @@ enum
63135 /* map softirq index to softirq name. update 'softirq_to_name' in
63136 * kernel/softirq.c when adding a new softirq.
63137 */
63138 -extern char *softirq_to_name[NR_SOFTIRQS];
63139 +extern const char * const softirq_to_name[NR_SOFTIRQS];
63140
63141 /* softirq mask and active fields moved to irq_cpustat_t in
63142 * asm/hardirq.h to get better cache usage. KAO
63143 @@ -443,12 +443,12 @@ extern char *softirq_to_name[NR_SOFTIRQS];
63144
63145 struct softirq_action
63146 {
63147 - void (*action)(struct softirq_action *);
63148 + void (*action)(void);
63149 };
63150
63151 asmlinkage void do_softirq(void);
63152 asmlinkage void __do_softirq(void);
63153 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
63154 +extern void open_softirq(int nr, void (*action)(void));
63155 extern void softirq_init(void);
63156 extern void __raise_softirq_irqoff(unsigned int nr);
63157
63158 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
63159 index 6883e19..06992b1 100644
63160 --- a/include/linux/kallsyms.h
63161 +++ b/include/linux/kallsyms.h
63162 @@ -15,7 +15,8 @@
63163
63164 struct module;
63165
63166 -#ifdef CONFIG_KALLSYMS
63167 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
63168 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
63169 /* Lookup the address for a symbol. Returns 0 if not found. */
63170 unsigned long kallsyms_lookup_name(const char *name);
63171
63172 @@ -106,6 +107,17 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
63173 /* Stupid that this does nothing, but I didn't create this mess. */
63174 #define __print_symbol(fmt, addr)
63175 #endif /*CONFIG_KALLSYMS*/
63176 +#else /* when included by kallsyms.c, vsnprintf.c, or
63177 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
63178 +extern void __print_symbol(const char *fmt, unsigned long address);
63179 +extern int sprint_backtrace(char *buffer, unsigned long address);
63180 +extern int sprint_symbol(char *buffer, unsigned long address);
63181 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
63182 +const char *kallsyms_lookup(unsigned long addr,
63183 + unsigned long *symbolsize,
63184 + unsigned long *offset,
63185 + char **modname, char *namebuf);
63186 +#endif
63187
63188 /* This macro allows us to keep printk typechecking */
63189 static __printf(1, 2)
63190 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
63191 index c4d2fc1..5df9c19 100644
63192 --- a/include/linux/kgdb.h
63193 +++ b/include/linux/kgdb.h
63194 @@ -53,7 +53,7 @@ extern int kgdb_connected;
63195 extern int kgdb_io_module_registered;
63196
63197 extern atomic_t kgdb_setting_breakpoint;
63198 -extern atomic_t kgdb_cpu_doing_single_step;
63199 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
63200
63201 extern struct task_struct *kgdb_usethread;
63202 extern struct task_struct *kgdb_contthread;
63203 @@ -252,7 +252,7 @@ struct kgdb_arch {
63204 void (*disable_hw_break)(struct pt_regs *regs);
63205 void (*remove_all_hw_break)(void);
63206 void (*correct_hw_break)(void);
63207 -};
63208 +} __do_const;
63209
63210 /**
63211 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
63212 @@ -277,7 +277,7 @@ struct kgdb_io {
63213 void (*pre_exception) (void);
63214 void (*post_exception) (void);
63215 int is_console;
63216 -};
63217 +} __do_const;
63218
63219 extern struct kgdb_arch arch_kgdb_ops;
63220
63221 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
63222 index 5398d58..5883a34 100644
63223 --- a/include/linux/kmod.h
63224 +++ b/include/linux/kmod.h
63225 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
63226 * usually useless though. */
63227 extern __printf(2, 3)
63228 int __request_module(bool wait, const char *name, ...);
63229 +extern __printf(3, 4)
63230 +int ___request_module(bool wait, char *param_name, const char *name, ...);
63231 #define request_module(mod...) __request_module(true, mod)
63232 #define request_module_nowait(mod...) __request_module(false, mod)
63233 #define try_then_request_module(x, mod...) \
63234 diff --git a/include/linux/kref.h b/include/linux/kref.h
63235 index 9c07dce..a92fa71 100644
63236 --- a/include/linux/kref.h
63237 +++ b/include/linux/kref.h
63238 @@ -63,7 +63,7 @@ static inline void kref_get(struct kref *kref)
63239 static inline int kref_sub(struct kref *kref, unsigned int count,
63240 void (*release)(struct kref *kref))
63241 {
63242 - WARN_ON(release == NULL);
63243 + BUG_ON(release == NULL);
63244
63245 if (atomic_sub_and_test((int) count, &kref->refcount)) {
63246 release(kref);
63247 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
63248 index 96c158a..1864db5 100644
63249 --- a/include/linux/kvm_host.h
63250 +++ b/include/linux/kvm_host.h
63251 @@ -345,7 +345,7 @@ void kvm_vcpu_uninit(struct kvm_vcpu *vcpu);
63252 void vcpu_load(struct kvm_vcpu *vcpu);
63253 void vcpu_put(struct kvm_vcpu *vcpu);
63254
63255 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63256 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
63257 struct module *module);
63258 void kvm_exit(void);
63259
63260 @@ -511,7 +511,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
63261 struct kvm_guest_debug *dbg);
63262 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
63263
63264 -int kvm_arch_init(void *opaque);
63265 +int kvm_arch_init(const void *opaque);
63266 void kvm_arch_exit(void);
63267
63268 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
63269 diff --git a/include/linux/libata.h b/include/linux/libata.h
63270 index 6e887c7..4539601 100644
63271 --- a/include/linux/libata.h
63272 +++ b/include/linux/libata.h
63273 @@ -910,7 +910,7 @@ struct ata_port_operations {
63274 * fields must be pointers.
63275 */
63276 const struct ata_port_operations *inherits;
63277 -};
63278 +} __do_const;
63279
63280 struct ata_port_info {
63281 unsigned long flags;
63282 diff --git a/include/linux/memory.h b/include/linux/memory.h
63283 index ff9a9f8..c715deb 100644
63284 --- a/include/linux/memory.h
63285 +++ b/include/linux/memory.h
63286 @@ -143,7 +143,7 @@ struct memory_accessor {
63287 size_t count);
63288 ssize_t (*write)(struct memory_accessor *, const char *buf,
63289 off_t offset, size_t count);
63290 -};
63291 +} __no_const;
63292
63293 /*
63294 * Kernel text modification mutex, used for code patching. Users of this lock
63295 diff --git a/include/linux/mfd/abx500.h b/include/linux/mfd/abx500.h
63296 index 1318ca6..7521340 100644
63297 --- a/include/linux/mfd/abx500.h
63298 +++ b/include/linux/mfd/abx500.h
63299 @@ -452,6 +452,7 @@ struct abx500_ops {
63300 int (*event_registers_startup_state_get) (struct device *, u8 *);
63301 int (*startup_irq_enabled) (struct device *, unsigned int);
63302 };
63303 +typedef struct abx500_ops __no_const abx500_ops_no_const;
63304
63305 int abx500_register_ops(struct device *core_dev, struct abx500_ops *ops);
63306 void abx500_remove_ops(struct device *dev);
63307 diff --git a/include/linux/mfd/abx500/ux500_chargalg.h b/include/linux/mfd/abx500/ux500_chargalg.h
63308 index 9b07725..3d55001 100644
63309 --- a/include/linux/mfd/abx500/ux500_chargalg.h
63310 +++ b/include/linux/mfd/abx500/ux500_chargalg.h
63311 @@ -19,7 +19,7 @@ struct ux500_charger_ops {
63312 int (*enable) (struct ux500_charger *, int, int, int);
63313 int (*kick_wd) (struct ux500_charger *);
63314 int (*update_curr) (struct ux500_charger *, int);
63315 -};
63316 +} __no_const;
63317
63318 /**
63319 * struct ux500_charger - power supply ux500 charger sub class
63320 diff --git a/include/linux/mm.h b/include/linux/mm.h
63321 index f9f279c..198da78 100644
63322 --- a/include/linux/mm.h
63323 +++ b/include/linux/mm.h
63324 @@ -116,7 +116,14 @@ extern unsigned int kobjsize(const void *objp);
63325
63326 #define VM_CAN_NONLINEAR 0x08000000 /* Has ->fault & does nonlinear pages */
63327 #define VM_MIXEDMAP 0x10000000 /* Can contain "struct page" and pure PFN pages */
63328 +
63329 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
63330 +#define VM_SAO 0x00000000 /* Strong Access Ordering (powerpc) */
63331 +#define VM_PAGEEXEC 0x20000000 /* vma->vm_page_prot needs special handling */
63332 +#else
63333 #define VM_SAO 0x20000000 /* Strong Access Ordering (powerpc) */
63334 +#endif
63335 +
63336 #define VM_PFN_AT_MMAP 0x40000000 /* PFNMAP vma that is fully mapped at mmap time */
63337 #define VM_MERGEABLE 0x80000000 /* KSM may merge identical pages */
63338
63339 @@ -1009,34 +1016,6 @@ int set_page_dirty(struct page *page);
63340 int set_page_dirty_lock(struct page *page);
63341 int clear_page_dirty_for_io(struct page *page);
63342
63343 -/* Is the vma a continuation of the stack vma above it? */
63344 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
63345 -{
63346 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
63347 -}
63348 -
63349 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
63350 - unsigned long addr)
63351 -{
63352 - return (vma->vm_flags & VM_GROWSDOWN) &&
63353 - (vma->vm_start == addr) &&
63354 - !vma_growsdown(vma->vm_prev, addr);
63355 -}
63356 -
63357 -/* Is the vma a continuation of the stack vma below it? */
63358 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
63359 -{
63360 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
63361 -}
63362 -
63363 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
63364 - unsigned long addr)
63365 -{
63366 - return (vma->vm_flags & VM_GROWSUP) &&
63367 - (vma->vm_end == addr) &&
63368 - !vma_growsup(vma->vm_next, addr);
63369 -}
63370 -
63371 extern pid_t
63372 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
63373
63374 @@ -1135,6 +1114,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
63375 }
63376 #endif
63377
63378 +#ifdef CONFIG_MMU
63379 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
63380 +#else
63381 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
63382 +{
63383 + return __pgprot(0);
63384 +}
63385 +#endif
63386 +
63387 int vma_wants_writenotify(struct vm_area_struct *vma);
63388
63389 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
63390 @@ -1153,8 +1141,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
63391 {
63392 return 0;
63393 }
63394 +
63395 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
63396 + unsigned long address)
63397 +{
63398 + return 0;
63399 +}
63400 #else
63401 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63402 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
63403 #endif
63404
63405 #ifdef __PAGETABLE_PMD_FOLDED
63406 @@ -1163,8 +1158,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
63407 {
63408 return 0;
63409 }
63410 +
63411 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
63412 + unsigned long address)
63413 +{
63414 + return 0;
63415 +}
63416 #else
63417 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
63418 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
63419 #endif
63420
63421 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
63422 @@ -1182,11 +1184,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
63423 NULL: pud_offset(pgd, address);
63424 }
63425
63426 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
63427 +{
63428 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
63429 + NULL: pud_offset(pgd, address);
63430 +}
63431 +
63432 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
63433 {
63434 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
63435 NULL: pmd_offset(pud, address);
63436 }
63437 +
63438 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
63439 +{
63440 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
63441 + NULL: pmd_offset(pud, address);
63442 +}
63443 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
63444
63445 #if USE_SPLIT_PTLOCKS
63446 @@ -1396,6 +1410,7 @@ extern unsigned long do_mmap_pgoff(struct file *, unsigned long,
63447 unsigned long, unsigned long,
63448 unsigned long, unsigned long);
63449 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
63450 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
63451
63452 /* These take the mm semaphore themselves */
63453 extern unsigned long vm_brk(unsigned long, unsigned long);
63454 @@ -1458,6 +1473,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
63455 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
63456 struct vm_area_struct **pprev);
63457
63458 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
63459 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
63460 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
63461 +
63462 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
63463 NULL if none. Assume start_addr < end_addr. */
63464 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
63465 @@ -1486,15 +1505,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
63466 return vma;
63467 }
63468
63469 -#ifdef CONFIG_MMU
63470 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
63471 -#else
63472 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
63473 -{
63474 - return __pgprot(0);
63475 -}
63476 -#endif
63477 -
63478 struct vm_area_struct *find_extend_vma(struct mm_struct *, unsigned long addr);
63479 int remap_pfn_range(struct vm_area_struct *, unsigned long addr,
63480 unsigned long pfn, unsigned long size, pgprot_t);
63481 @@ -1599,7 +1609,7 @@ extern int unpoison_memory(unsigned long pfn);
63482 extern int sysctl_memory_failure_early_kill;
63483 extern int sysctl_memory_failure_recovery;
63484 extern void shake_page(struct page *p, int access);
63485 -extern atomic_long_t mce_bad_pages;
63486 +extern atomic_long_unchecked_t mce_bad_pages;
63487 extern int soft_offline_page(struct page *page, int flags);
63488
63489 extern void dump_page(struct page *page);
63490 @@ -1630,5 +1640,11 @@ static inline unsigned int debug_guardpage_minorder(void) { return 0; }
63491 static inline bool page_is_guard(struct page *page) { return false; }
63492 #endif /* CONFIG_DEBUG_PAGEALLOC */
63493
63494 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63495 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
63496 +#else
63497 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
63498 +#endif
63499 +
63500 #endif /* __KERNEL__ */
63501 #endif /* _LINUX_MM_H */
63502 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
63503 index 704a626..bb0705a 100644
63504 --- a/include/linux/mm_types.h
63505 +++ b/include/linux/mm_types.h
63506 @@ -263,6 +263,8 @@ struct vm_area_struct {
63507 #ifdef CONFIG_NUMA
63508 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
63509 #endif
63510 +
63511 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
63512 };
63513
63514 struct core_thread {
63515 @@ -337,7 +339,7 @@ struct mm_struct {
63516 unsigned long def_flags;
63517 unsigned long nr_ptes; /* Page table pages */
63518 unsigned long start_code, end_code, start_data, end_data;
63519 - unsigned long start_brk, brk, start_stack;
63520 + unsigned long brk_gap, start_brk, brk, start_stack;
63521 unsigned long arg_start, arg_end, env_start, env_end;
63522
63523 unsigned long saved_auxv[AT_VECTOR_SIZE]; /* for /proc/PID/auxv */
63524 @@ -389,6 +391,24 @@ struct mm_struct {
63525 struct cpumask cpumask_allocation;
63526 #endif
63527 struct uprobes_state uprobes_state;
63528 +
63529 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
63530 + unsigned long pax_flags;
63531 +#endif
63532 +
63533 +#ifdef CONFIG_PAX_DLRESOLVE
63534 + unsigned long call_dl_resolve;
63535 +#endif
63536 +
63537 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
63538 + unsigned long call_syscall;
63539 +#endif
63540 +
63541 +#ifdef CONFIG_PAX_ASLR
63542 + unsigned long delta_mmap; /* randomized offset */
63543 + unsigned long delta_stack; /* randomized offset */
63544 +#endif
63545 +
63546 };
63547
63548 static inline void mm_init_cpumask(struct mm_struct *mm)
63549 diff --git a/include/linux/mmu_notifier.h b/include/linux/mmu_notifier.h
63550 index 1d1b1e1..2a13c78 100644
63551 --- a/include/linux/mmu_notifier.h
63552 +++ b/include/linux/mmu_notifier.h
63553 @@ -255,12 +255,12 @@ static inline void mmu_notifier_mm_destroy(struct mm_struct *mm)
63554 */
63555 #define ptep_clear_flush_notify(__vma, __address, __ptep) \
63556 ({ \
63557 - pte_t __pte; \
63558 + pte_t ___pte; \
63559 struct vm_area_struct *___vma = __vma; \
63560 unsigned long ___address = __address; \
63561 - __pte = ptep_clear_flush(___vma, ___address, __ptep); \
63562 + ___pte = ptep_clear_flush(___vma, ___address, __ptep); \
63563 mmu_notifier_invalidate_page(___vma->vm_mm, ___address); \
63564 - __pte; \
63565 + ___pte; \
63566 })
63567
63568 #define pmdp_clear_flush_notify(__vma, __address, __pmdp) \
63569 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
63570 index 68c569f..5f43753 100644
63571 --- a/include/linux/mmzone.h
63572 +++ b/include/linux/mmzone.h
63573 @@ -411,7 +411,7 @@ struct zone {
63574 unsigned long flags; /* zone flags, see below */
63575
63576 /* Zone statistics */
63577 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63578 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
63579
63580 /*
63581 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
63582 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
63583 index 5db9382..50e801d 100644
63584 --- a/include/linux/mod_devicetable.h
63585 +++ b/include/linux/mod_devicetable.h
63586 @@ -12,7 +12,7 @@
63587 typedef unsigned long kernel_ulong_t;
63588 #endif
63589
63590 -#define PCI_ANY_ID (~0)
63591 +#define PCI_ANY_ID ((__u16)~0)
63592
63593 struct pci_device_id {
63594 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
63595 @@ -131,7 +131,7 @@ struct usb_device_id {
63596 #define USB_DEVICE_ID_MATCH_INT_SUBCLASS 0x0100
63597 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
63598
63599 -#define HID_ANY_ID (~0)
63600 +#define HID_ANY_ID (~0U)
63601 #define HID_BUS_ANY 0xffff
63602 #define HID_GROUP_ANY 0x0000
63603
63604 diff --git a/include/linux/module.h b/include/linux/module.h
63605 index fbcafe2..e5d9587 100644
63606 --- a/include/linux/module.h
63607 +++ b/include/linux/module.h
63608 @@ -17,6 +17,7 @@
63609 #include <linux/moduleparam.h>
63610 #include <linux/tracepoint.h>
63611 #include <linux/export.h>
63612 +#include <linux/fs.h>
63613
63614 #include <linux/percpu.h>
63615 #include <asm/module.h>
63616 @@ -273,19 +274,16 @@ struct module
63617 int (*init)(void);
63618
63619 /* If this is non-NULL, vfree after init() returns */
63620 - void *module_init;
63621 + void *module_init_rx, *module_init_rw;
63622
63623 /* Here is the actual code + data, vfree'd on unload. */
63624 - void *module_core;
63625 + void *module_core_rx, *module_core_rw;
63626
63627 /* Here are the sizes of the init and core sections */
63628 - unsigned int init_size, core_size;
63629 + unsigned int init_size_rw, core_size_rw;
63630
63631 /* The size of the executable code in each section. */
63632 - unsigned int init_text_size, core_text_size;
63633 -
63634 - /* Size of RO sections of the module (text+rodata) */
63635 - unsigned int init_ro_size, core_ro_size;
63636 + unsigned int init_size_rx, core_size_rx;
63637
63638 /* Arch-specific module values */
63639 struct mod_arch_specific arch;
63640 @@ -341,6 +339,10 @@ struct module
63641 #ifdef CONFIG_EVENT_TRACING
63642 struct ftrace_event_call **trace_events;
63643 unsigned int num_trace_events;
63644 + struct file_operations trace_id;
63645 + struct file_operations trace_enable;
63646 + struct file_operations trace_format;
63647 + struct file_operations trace_filter;
63648 #endif
63649 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
63650 unsigned int num_ftrace_callsites;
63651 @@ -388,16 +390,46 @@ bool is_module_address(unsigned long addr);
63652 bool is_module_percpu_address(unsigned long addr);
63653 bool is_module_text_address(unsigned long addr);
63654
63655 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
63656 +{
63657 +
63658 +#ifdef CONFIG_PAX_KERNEXEC
63659 + if (ktla_ktva(addr) >= (unsigned long)start &&
63660 + ktla_ktva(addr) < (unsigned long)start + size)
63661 + return 1;
63662 +#endif
63663 +
63664 + return ((void *)addr >= start && (void *)addr < start + size);
63665 +}
63666 +
63667 +static inline int within_module_core_rx(unsigned long addr, struct module *mod)
63668 +{
63669 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
63670 +}
63671 +
63672 +static inline int within_module_core_rw(unsigned long addr, struct module *mod)
63673 +{
63674 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
63675 +}
63676 +
63677 +static inline int within_module_init_rx(unsigned long addr, struct module *mod)
63678 +{
63679 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
63680 +}
63681 +
63682 +static inline int within_module_init_rw(unsigned long addr, struct module *mod)
63683 +{
63684 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
63685 +}
63686 +
63687 static inline int within_module_core(unsigned long addr, struct module *mod)
63688 {
63689 - return (unsigned long)mod->module_core <= addr &&
63690 - addr < (unsigned long)mod->module_core + mod->core_size;
63691 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
63692 }
63693
63694 static inline int within_module_init(unsigned long addr, struct module *mod)
63695 {
63696 - return (unsigned long)mod->module_init <= addr &&
63697 - addr < (unsigned long)mod->module_init + mod->init_size;
63698 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
63699 }
63700
63701 /* Search for module by name: must hold module_mutex. */
63702 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
63703 index b2be02e..72d2f78 100644
63704 --- a/include/linux/moduleloader.h
63705 +++ b/include/linux/moduleloader.h
63706 @@ -23,11 +23,23 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
63707
63708 /* Allocator used for allocating struct module, core sections and init
63709 sections. Returns NULL on failure. */
63710 -void *module_alloc(unsigned long size);
63711 +void *module_alloc(unsigned long size) __size_overflow(1);
63712 +
63713 +#ifdef CONFIG_PAX_KERNEXEC
63714 +void *module_alloc_exec(unsigned long size) __size_overflow(1);
63715 +#else
63716 +#define module_alloc_exec(x) module_alloc(x)
63717 +#endif
63718
63719 /* Free memory returned from module_alloc. */
63720 void module_free(struct module *mod, void *module_region);
63721
63722 +#ifdef CONFIG_PAX_KERNEXEC
63723 +void module_free_exec(struct module *mod, void *module_region);
63724 +#else
63725 +#define module_free_exec(x, y) module_free((x), (y))
63726 +#endif
63727 +
63728 /* Apply the given relocation to the (simplified) ELF. Return -error
63729 or 0. */
63730 int apply_relocate(Elf_Shdr *sechdrs,
63731 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
63732 index d6a5806..7c13347 100644
63733 --- a/include/linux/moduleparam.h
63734 +++ b/include/linux/moduleparam.h
63735 @@ -286,7 +286,7 @@ static inline void __kernel_param_unlock(void)
63736 * @len is usually just sizeof(string).
63737 */
63738 #define module_param_string(name, string, len, perm) \
63739 - static const struct kparam_string __param_string_##name \
63740 + static const struct kparam_string __param_string_##name __used \
63741 = { len, string }; \
63742 __module_param_call(MODULE_PARAM_PREFIX, name, \
63743 &param_ops_string, \
63744 @@ -425,7 +425,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
63745 */
63746 #define module_param_array_named(name, array, type, nump, perm) \
63747 param_check_##type(name, &(array)[0]); \
63748 - static const struct kparam_array __param_arr_##name \
63749 + static const struct kparam_array __param_arr_##name __used \
63750 = { .max = ARRAY_SIZE(array), .num = nump, \
63751 .ops = &param_ops_##type, \
63752 .elemsize = sizeof(array[0]), .elem = array }; \
63753 diff --git a/include/linux/namei.h b/include/linux/namei.h
63754 index ffc0213..2c1f2cb 100644
63755 --- a/include/linux/namei.h
63756 +++ b/include/linux/namei.h
63757 @@ -24,7 +24,7 @@ struct nameidata {
63758 unsigned seq;
63759 int last_type;
63760 unsigned depth;
63761 - char *saved_names[MAX_NESTED_LINKS + 1];
63762 + const char *saved_names[MAX_NESTED_LINKS + 1];
63763
63764 /* Intent data */
63765 union {
63766 @@ -94,12 +94,12 @@ extern int follow_up(struct path *);
63767 extern struct dentry *lock_rename(struct dentry *, struct dentry *);
63768 extern void unlock_rename(struct dentry *, struct dentry *);
63769
63770 -static inline void nd_set_link(struct nameidata *nd, char *path)
63771 +static inline void nd_set_link(struct nameidata *nd, const char *path)
63772 {
63773 nd->saved_names[nd->depth] = path;
63774 }
63775
63776 -static inline char *nd_get_link(struct nameidata *nd)
63777 +static inline const char *nd_get_link(const struct nameidata *nd)
63778 {
63779 return nd->saved_names[nd->depth];
63780 }
63781 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
63782 index b52070a..ea67208 100644
63783 --- a/include/linux/netdevice.h
63784 +++ b/include/linux/netdevice.h
63785 @@ -1026,6 +1026,7 @@ struct net_device_ops {
63786 struct net_device *dev,
63787 int idx);
63788 };
63789 +typedef struct net_device_ops __no_const net_device_ops_no_const;
63790
63791 /*
63792 * The DEVICE structure.
63793 @@ -1087,7 +1088,7 @@ struct net_device {
63794 int iflink;
63795
63796 struct net_device_stats stats;
63797 - atomic_long_t rx_dropped; /* dropped packets by core network
63798 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
63799 * Do not use this in drivers.
63800 */
63801
63802 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
63803 new file mode 100644
63804 index 0000000..33f4af8
63805 --- /dev/null
63806 +++ b/include/linux/netfilter/xt_gradm.h
63807 @@ -0,0 +1,9 @@
63808 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
63809 +#define _LINUX_NETFILTER_XT_GRADM_H 1
63810 +
63811 +struct xt_gradm_mtinfo {
63812 + __u16 flags;
63813 + __u16 invflags;
63814 +};
63815 +
63816 +#endif
63817 diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h
63818 index c65a18a..0c05f3a 100644
63819 --- a/include/linux/of_pdt.h
63820 +++ b/include/linux/of_pdt.h
63821 @@ -32,7 +32,7 @@ struct of_pdt_ops {
63822
63823 /* return 0 on success; fill in 'len' with number of bytes in path */
63824 int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
63825 -};
63826 +} __no_const;
63827
63828 extern void *prom_early_alloc(unsigned long size);
63829
63830 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
63831 index a4c5624..79d6d88 100644
63832 --- a/include/linux/oprofile.h
63833 +++ b/include/linux/oprofile.h
63834 @@ -139,9 +139,9 @@ int oprofilefs_create_ulong(struct super_block * sb, struct dentry * root,
63835 int oprofilefs_create_ro_ulong(struct super_block * sb, struct dentry * root,
63836 char const * name, ulong * val);
63837
63838 -/** Create a file for read-only access to an atomic_t. */
63839 +/** Create a file for read-only access to an atomic_unchecked_t. */
63840 int oprofilefs_create_ro_atomic(struct super_block * sb, struct dentry * root,
63841 - char const * name, atomic_t * val);
63842 + char const * name, atomic_unchecked_t * val);
63843
63844 /** create a directory */
63845 struct dentry * oprofilefs_mkdir(struct super_block * sb, struct dentry * root,
63846 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
63847 index c3c98a6..c57555e 100644
63848 --- a/include/linux/perf_event.h
63849 +++ b/include/linux/perf_event.h
63850 @@ -881,8 +881,8 @@ struct perf_event {
63851
63852 enum perf_event_active_state state;
63853 unsigned int attach_state;
63854 - local64_t count;
63855 - atomic64_t child_count;
63856 + local64_t count; /* PaX: fix it one day */
63857 + atomic64_unchecked_t child_count;
63858
63859 /*
63860 * These are the total time in nanoseconds that the event
63861 @@ -933,8 +933,8 @@ struct perf_event {
63862 * These accumulate total time (in nanoseconds) that children
63863 * events have been enabled and running, respectively.
63864 */
63865 - atomic64_t child_total_time_enabled;
63866 - atomic64_t child_total_time_running;
63867 + atomic64_unchecked_t child_total_time_enabled;
63868 + atomic64_unchecked_t child_total_time_running;
63869
63870 /*
63871 * Protect attach/detach and child_list:
63872 diff --git a/include/linux/personality.h b/include/linux/personality.h
63873 index 8fc7dd1a..c19d89e 100644
63874 --- a/include/linux/personality.h
63875 +++ b/include/linux/personality.h
63876 @@ -44,6 +44,7 @@ enum {
63877 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
63878 ADDR_NO_RANDOMIZE | \
63879 ADDR_COMPAT_LAYOUT | \
63880 + ADDR_LIMIT_3GB | \
63881 MMAP_PAGE_ZERO)
63882
63883 /*
63884 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
63885 index e1ac1ce..0675fed 100644
63886 --- a/include/linux/pipe_fs_i.h
63887 +++ b/include/linux/pipe_fs_i.h
63888 @@ -45,9 +45,9 @@ struct pipe_buffer {
63889 struct pipe_inode_info {
63890 wait_queue_head_t wait;
63891 unsigned int nrbufs, curbuf, buffers;
63892 - unsigned int readers;
63893 - unsigned int writers;
63894 - unsigned int waiting_writers;
63895 + atomic_t readers;
63896 + atomic_t writers;
63897 + atomic_t waiting_writers;
63898 unsigned int r_counter;
63899 unsigned int w_counter;
63900 struct page *tmp_page;
63901 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
63902 index f271860..6b3bec5 100644
63903 --- a/include/linux/pm_runtime.h
63904 +++ b/include/linux/pm_runtime.h
63905 @@ -97,7 +97,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
63906
63907 static inline void pm_runtime_mark_last_busy(struct device *dev)
63908 {
63909 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
63910 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
63911 }
63912
63913 #else /* !CONFIG_PM_RUNTIME */
63914 diff --git a/include/linux/poison.h b/include/linux/poison.h
63915 index 2110a81..13a11bb 100644
63916 --- a/include/linux/poison.h
63917 +++ b/include/linux/poison.h
63918 @@ -19,8 +19,8 @@
63919 * under normal circumstances, used to verify that nobody uses
63920 * non-initialized list entries.
63921 */
63922 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
63923 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
63924 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
63925 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
63926
63927 /********** include/linux/timer.h **********/
63928 /*
63929 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
63930 index 5a710b9..0b0dab9 100644
63931 --- a/include/linux/preempt.h
63932 +++ b/include/linux/preempt.h
63933 @@ -126,7 +126,7 @@ struct preempt_ops {
63934 void (*sched_in)(struct preempt_notifier *notifier, int cpu);
63935 void (*sched_out)(struct preempt_notifier *notifier,
63936 struct task_struct *next);
63937 -};
63938 +} __no_const;
63939
63940 /**
63941 * preempt_notifier - key for installing preemption notifiers
63942 diff --git a/include/linux/printk.h b/include/linux/printk.h
63943 index 1bec2f7..b66e833 100644
63944 --- a/include/linux/printk.h
63945 +++ b/include/linux/printk.h
63946 @@ -94,6 +94,8 @@ void early_printk(const char *fmt, ...);
63947 extern int printk_needs_cpu(int cpu);
63948 extern void printk_tick(void);
63949
63950 +extern int kptr_restrict;
63951 +
63952 #ifdef CONFIG_PRINTK
63953 asmlinkage __printf(5, 0)
63954 int vprintk_emit(int facility, int level,
63955 @@ -128,7 +130,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
63956
63957 extern int printk_delay_msec;
63958 extern int dmesg_restrict;
63959 -extern int kptr_restrict;
63960
63961 void log_buf_kexec_setup(void);
63962 void __init setup_log_buf(int early);
63963 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
63964 index 3fd2e87..d93a721 100644
63965 --- a/include/linux/proc_fs.h
63966 +++ b/include/linux/proc_fs.h
63967 @@ -155,6 +155,18 @@ static inline struct proc_dir_entry *proc_create(const char *name, umode_t mode,
63968 return proc_create_data(name, mode, parent, proc_fops, NULL);
63969 }
63970
63971 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
63972 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
63973 +{
63974 +#ifdef CONFIG_GRKERNSEC_PROC_USER
63975 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
63976 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
63977 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
63978 +#else
63979 + return proc_create_data(name, mode, parent, proc_fops, NULL);
63980 +#endif
63981 +}
63982 +
63983 static inline struct proc_dir_entry *create_proc_read_entry(const char *name,
63984 umode_t mode, struct proc_dir_entry *base,
63985 read_proc_t *read_proc, void * data)
63986 @@ -258,7 +270,7 @@ union proc_op {
63987 int (*proc_show)(struct seq_file *m,
63988 struct pid_namespace *ns, struct pid *pid,
63989 struct task_struct *task);
63990 -};
63991 +} __no_const;
63992
63993 struct ctl_table_header;
63994 struct ctl_table;
63995 diff --git a/include/linux/random.h b/include/linux/random.h
63996 index ac621ce..c1215f3 100644
63997 --- a/include/linux/random.h
63998 +++ b/include/linux/random.h
63999 @@ -53,6 +53,10 @@ extern void add_input_randomness(unsigned int type, unsigned int code,
64000 unsigned int value);
64001 extern void add_interrupt_randomness(int irq, int irq_flags);
64002
64003 +#ifdef CONFIG_PAX_LATENT_ENTROPY
64004 +extern void transfer_latent_entropy(void);
64005 +#endif
64006 +
64007 extern void get_random_bytes(void *buf, int nbytes);
64008 extern void get_random_bytes_arch(void *buf, int nbytes);
64009 void generate_random_uuid(unsigned char uuid_out[16]);
64010 @@ -69,12 +73,17 @@ void srandom32(u32 seed);
64011
64012 u32 prandom32(struct rnd_state *);
64013
64014 +static inline unsigned long pax_get_random_long(void)
64015 +{
64016 + return random32() + (sizeof(long) > 4 ? (unsigned long)random32() << 32 : 0);
64017 +}
64018 +
64019 /*
64020 * Handle minimum values for seeds
64021 */
64022 static inline u32 __seed(u32 x, u32 m)
64023 {
64024 - return (x < m) ? x + m : x;
64025 + return (x <= m) ? x + m + 1 : x;
64026 }
64027
64028 /**
64029 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
64030 index e0879a7..a12f962 100644
64031 --- a/include/linux/reboot.h
64032 +++ b/include/linux/reboot.h
64033 @@ -52,9 +52,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
64034 * Architecture-specific implementations of sys_reboot commands.
64035 */
64036
64037 -extern void machine_restart(char *cmd);
64038 -extern void machine_halt(void);
64039 -extern void machine_power_off(void);
64040 +extern void machine_restart(char *cmd) __noreturn;
64041 +extern void machine_halt(void) __noreturn;
64042 +extern void machine_power_off(void) __noreturn;
64043
64044 extern void machine_shutdown(void);
64045 struct pt_regs;
64046 @@ -65,9 +65,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
64047 */
64048
64049 extern void kernel_restart_prepare(char *cmd);
64050 -extern void kernel_restart(char *cmd);
64051 -extern void kernel_halt(void);
64052 -extern void kernel_power_off(void);
64053 +extern void kernel_restart(char *cmd) __noreturn;
64054 +extern void kernel_halt(void) __noreturn;
64055 +extern void kernel_power_off(void) __noreturn;
64056
64057 extern int C_A_D; /* for sysctl */
64058 void ctrl_alt_del(void);
64059 @@ -81,7 +81,7 @@ extern int orderly_poweroff(bool force);
64060 * Emergency restart, callable from an interrupt handler.
64061 */
64062
64063 -extern void emergency_restart(void);
64064 +extern void emergency_restart(void) __noreturn;
64065 #include <asm/emergency-restart.h>
64066
64067 #endif
64068 diff --git a/include/linux/relay.h b/include/linux/relay.h
64069 index 91cacc3..b55ff74 100644
64070 --- a/include/linux/relay.h
64071 +++ b/include/linux/relay.h
64072 @@ -160,7 +160,7 @@ struct rchan_callbacks
64073 * The callback should return 0 if successful, negative if not.
64074 */
64075 int (*remove_buf_file)(struct dentry *dentry);
64076 -};
64077 +} __no_const;
64078
64079 /*
64080 * CONFIG_RELAY kernel API, kernel/relay.c
64081 diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h
64082 index 6fdf027..ff72610 100644
64083 --- a/include/linux/rfkill.h
64084 +++ b/include/linux/rfkill.h
64085 @@ -147,6 +147,7 @@ struct rfkill_ops {
64086 void (*query)(struct rfkill *rfkill, void *data);
64087 int (*set_block)(void *data, bool blocked);
64088 };
64089 +typedef struct rfkill_ops __no_const rfkill_ops_no_const;
64090
64091 #if defined(CONFIG_RFKILL) || defined(CONFIG_RFKILL_MODULE)
64092 /**
64093 diff --git a/include/linux/rio.h b/include/linux/rio.h
64094 index a90ebad..fd87b5d 100644
64095 --- a/include/linux/rio.h
64096 +++ b/include/linux/rio.h
64097 @@ -321,7 +321,7 @@ struct rio_ops {
64098 int mbox, void *buffer, size_t len);
64099 int (*add_inb_buffer)(struct rio_mport *mport, int mbox, void *buf);
64100 void *(*get_inb_message)(struct rio_mport *mport, int mbox);
64101 -};
64102 +} __no_const;
64103
64104 #define RIO_RESOURCE_MEM 0x00000100
64105 #define RIO_RESOURCE_DOORBELL 0x00000200
64106 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
64107 index 3fce545..b4fed6e 100644
64108 --- a/include/linux/rmap.h
64109 +++ b/include/linux/rmap.h
64110 @@ -119,9 +119,9 @@ static inline void anon_vma_unlock(struct anon_vma *anon_vma)
64111 void anon_vma_init(void); /* create anon_vma_cachep */
64112 int anon_vma_prepare(struct vm_area_struct *);
64113 void unlink_anon_vmas(struct vm_area_struct *);
64114 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
64115 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
64116 void anon_vma_moveto_tail(struct vm_area_struct *);
64117 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
64118 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
64119
64120 static inline void anon_vma_merge(struct vm_area_struct *vma,
64121 struct vm_area_struct *next)
64122 diff --git a/include/linux/sched.h b/include/linux/sched.h
64123 index e63650f..7dfd1b3 100644
64124 --- a/include/linux/sched.h
64125 +++ b/include/linux/sched.h
64126 @@ -101,6 +101,7 @@ struct bio_list;
64127 struct fs_struct;
64128 struct perf_event_context;
64129 struct blk_plug;
64130 +struct linux_binprm;
64131
64132 /*
64133 * List of flags we want to share for kernel threads,
64134 @@ -384,10 +385,13 @@ struct user_namespace;
64135 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
64136
64137 extern int sysctl_max_map_count;
64138 +extern unsigned long sysctl_heap_stack_gap;
64139
64140 #include <linux/aio.h>
64141
64142 #ifdef CONFIG_MMU
64143 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len);
64144 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len);
64145 extern void arch_pick_mmap_layout(struct mm_struct *mm);
64146 extern unsigned long
64147 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
64148 @@ -406,6 +410,11 @@ static inline void arch_pick_mmap_layout(struct mm_struct *mm) {}
64149 extern void set_dumpable(struct mm_struct *mm, int value);
64150 extern int get_dumpable(struct mm_struct *mm);
64151
64152 +/* get/set_dumpable() values */
64153 +#define SUID_DUMPABLE_DISABLED 0
64154 +#define SUID_DUMPABLE_ENABLED 1
64155 +#define SUID_DUMPABLE_SAFE 2
64156 +
64157 /* mm flags */
64158 /* dumpable bits */
64159 #define MMF_DUMPABLE 0 /* core dump is permitted */
64160 @@ -646,6 +655,17 @@ struct signal_struct {
64161 #ifdef CONFIG_TASKSTATS
64162 struct taskstats *stats;
64163 #endif
64164 +
64165 +#ifdef CONFIG_GRKERNSEC
64166 + u32 curr_ip;
64167 + u32 saved_ip;
64168 + u32 gr_saddr;
64169 + u32 gr_daddr;
64170 + u16 gr_sport;
64171 + u16 gr_dport;
64172 + u8 used_accept:1;
64173 +#endif
64174 +
64175 #ifdef CONFIG_AUDIT
64176 unsigned audit_tty;
64177 struct tty_audit_buf *tty_audit_buf;
64178 @@ -729,6 +749,11 @@ struct user_struct {
64179 struct key *session_keyring; /* UID's default session keyring */
64180 #endif
64181
64182 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT) || defined(CONFIG_GRKERNSEC_BRUTE)
64183 + unsigned int banned;
64184 + unsigned long ban_expires;
64185 +#endif
64186 +
64187 /* Hash table maintenance information */
64188 struct hlist_node uidhash_node;
64189 kuid_t uid;
64190 @@ -1351,8 +1376,8 @@ struct task_struct {
64191 struct list_head thread_group;
64192
64193 struct completion *vfork_done; /* for vfork() */
64194 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
64195 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64196 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
64197 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
64198
64199 cputime_t utime, stime, utimescaled, stimescaled;
64200 cputime_t gtime;
64201 @@ -1368,11 +1393,6 @@ struct task_struct {
64202 struct task_cputime cputime_expires;
64203 struct list_head cpu_timers[3];
64204
64205 -/* process credentials */
64206 - const struct cred __rcu *real_cred; /* objective and real subjective task
64207 - * credentials (COW) */
64208 - const struct cred __rcu *cred; /* effective (overridable) subjective task
64209 - * credentials (COW) */
64210 char comm[TASK_COMM_LEN]; /* executable name excluding path
64211 - access with [gs]et_task_comm (which lock
64212 it with task_lock())
64213 @@ -1389,8 +1409,16 @@ struct task_struct {
64214 #endif
64215 /* CPU-specific state of this task */
64216 struct thread_struct thread;
64217 +/* thread_info moved to task_struct */
64218 +#ifdef CONFIG_X86
64219 + struct thread_info tinfo;
64220 +#endif
64221 /* filesystem information */
64222 struct fs_struct *fs;
64223 +
64224 + const struct cred __rcu *cred; /* effective (overridable) subjective task
64225 + * credentials (COW) */
64226 +
64227 /* open file information */
64228 struct files_struct *files;
64229 /* namespaces */
64230 @@ -1434,6 +1462,11 @@ struct task_struct {
64231 struct rt_mutex_waiter *pi_blocked_on;
64232 #endif
64233
64234 +/* process credentials */
64235 + const struct cred __rcu *real_cred; /* objective and real subjective task
64236 + * credentials (COW) */
64237 + struct cred *replacement_session_keyring; /* for KEYCTL_SESSION_TO_PARENT */
64238 +
64239 #ifdef CONFIG_DEBUG_MUTEXES
64240 /* mutex deadlock detection */
64241 struct mutex_waiter *blocked_on;
64242 @@ -1550,6 +1583,27 @@ struct task_struct {
64243 unsigned long default_timer_slack_ns;
64244
64245 struct list_head *scm_work_list;
64246 +
64247 +#ifdef CONFIG_GRKERNSEC
64248 + /* grsecurity */
64249 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64250 + u64 exec_id;
64251 +#endif
64252 +#ifdef CONFIG_GRKERNSEC_SETXID
64253 + const struct cred *delayed_cred;
64254 +#endif
64255 + struct dentry *gr_chroot_dentry;
64256 + struct acl_subject_label *acl;
64257 + struct acl_role_label *role;
64258 + struct file *exec_file;
64259 + u16 acl_role_id;
64260 + /* is this the task that authenticated to the special role */
64261 + u8 acl_sp_role;
64262 + u8 is_writable;
64263 + u8 brute;
64264 + u8 gr_is_chrooted;
64265 +#endif
64266 +
64267 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
64268 /* Index of current stored address in ret_stack */
64269 int curr_ret_stack;
64270 @@ -1588,6 +1642,51 @@ struct task_struct {
64271 #endif
64272 };
64273
64274 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
64275 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
64276 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
64277 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
64278 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
64279 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
64280 +
64281 +#ifdef CONFIG_PAX_SOFTMODE
64282 +extern int pax_softmode;
64283 +#endif
64284 +
64285 +extern int pax_check_flags(unsigned long *);
64286 +
64287 +/* if tsk != current then task_lock must be held on it */
64288 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
64289 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
64290 +{
64291 + if (likely(tsk->mm))
64292 + return tsk->mm->pax_flags;
64293 + else
64294 + return 0UL;
64295 +}
64296 +
64297 +/* if tsk != current then task_lock must be held on it */
64298 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
64299 +{
64300 + if (likely(tsk->mm)) {
64301 + tsk->mm->pax_flags = flags;
64302 + return 0;
64303 + }
64304 + return -EINVAL;
64305 +}
64306 +#endif
64307 +
64308 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
64309 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
64310 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
64311 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
64312 +#endif
64313 +
64314 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
64315 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
64316 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
64317 +extern void check_object_size(const void *ptr, unsigned long n, bool to);
64318 +
64319 /* Future-safe accessor for struct task_struct's cpus_allowed. */
64320 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
64321
64322 @@ -2115,7 +2214,9 @@ void yield(void);
64323 extern struct exec_domain default_exec_domain;
64324
64325 union thread_union {
64326 +#ifndef CONFIG_X86
64327 struct thread_info thread_info;
64328 +#endif
64329 unsigned long stack[THREAD_SIZE/sizeof(long)];
64330 };
64331
64332 @@ -2148,6 +2249,7 @@ extern struct pid_namespace init_pid_ns;
64333 */
64334
64335 extern struct task_struct *find_task_by_vpid(pid_t nr);
64336 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
64337 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
64338 struct pid_namespace *ns);
64339
64340 @@ -2304,7 +2406,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
64341 extern void exit_itimers(struct signal_struct *);
64342 extern void flush_itimer_signals(void);
64343
64344 -extern void do_group_exit(int);
64345 +extern __noreturn void do_group_exit(int);
64346
64347 extern void daemonize(const char *, ...);
64348 extern int allow_signal(int);
64349 @@ -2505,9 +2607,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
64350
64351 #endif
64352
64353 -static inline int object_is_on_stack(void *obj)
64354 +static inline int object_starts_on_stack(void *obj)
64355 {
64356 - void *stack = task_stack_page(current);
64357 + const void *stack = task_stack_page(current);
64358
64359 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
64360 }
64361 diff --git a/include/linux/screen_info.h b/include/linux/screen_info.h
64362 index 899fbb4..1cb4138 100644
64363 --- a/include/linux/screen_info.h
64364 +++ b/include/linux/screen_info.h
64365 @@ -43,7 +43,8 @@ struct screen_info {
64366 __u16 pages; /* 0x32 */
64367 __u16 vesa_attributes; /* 0x34 */
64368 __u32 capabilities; /* 0x36 */
64369 - __u8 _reserved[6]; /* 0x3a */
64370 + __u16 vesapm_size; /* 0x3a */
64371 + __u8 _reserved[4]; /* 0x3c */
64372 } __attribute__((packed));
64373
64374 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
64375 diff --git a/include/linux/security.h b/include/linux/security.h
64376 index d143b8e..9f27b95 100644
64377 --- a/include/linux/security.h
64378 +++ b/include/linux/security.h
64379 @@ -26,6 +26,7 @@
64380 #include <linux/capability.h>
64381 #include <linux/slab.h>
64382 #include <linux/err.h>
64383 +#include <linux/grsecurity.h>
64384
64385 struct linux_binprm;
64386 struct cred;
64387 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
64388 index fc61854..d7c490b 100644
64389 --- a/include/linux/seq_file.h
64390 +++ b/include/linux/seq_file.h
64391 @@ -25,6 +25,9 @@ struct seq_file {
64392 struct mutex lock;
64393 const struct seq_operations *op;
64394 int poll_event;
64395 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
64396 + u64 exec_id;
64397 +#endif
64398 void *private;
64399 };
64400
64401 @@ -34,6 +37,7 @@ struct seq_operations {
64402 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
64403 int (*show) (struct seq_file *m, void *v);
64404 };
64405 +typedef struct seq_operations __no_const seq_operations_no_const;
64406
64407 #define SEQ_SKIP 1
64408
64409 diff --git a/include/linux/shm.h b/include/linux/shm.h
64410 index 92808b8..c28cac4 100644
64411 --- a/include/linux/shm.h
64412 +++ b/include/linux/shm.h
64413 @@ -98,6 +98,10 @@ struct shmid_kernel /* private to the kernel */
64414
64415 /* The task created the shm object. NULL if the task is dead. */
64416 struct task_struct *shm_creator;
64417 +#ifdef CONFIG_GRKERNSEC
64418 + time_t shm_createtime;
64419 + pid_t shm_lapid;
64420 +#endif
64421 };
64422
64423 /* shm_mode upper byte flags */
64424 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
64425 index 642cb73..2efdb98 100644
64426 --- a/include/linux/skbuff.h
64427 +++ b/include/linux/skbuff.h
64428 @@ -567,7 +567,7 @@ extern bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
64429 extern struct sk_buff *__alloc_skb(unsigned int size,
64430 gfp_t priority, int fclone, int node);
64431 extern struct sk_buff *build_skb(void *data, unsigned int frag_size);
64432 -static inline struct sk_buff *alloc_skb(unsigned int size,
64433 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
64434 gfp_t priority)
64435 {
64436 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
64437 @@ -680,7 +680,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
64438 */
64439 static inline int skb_queue_empty(const struct sk_buff_head *list)
64440 {
64441 - return list->next == (struct sk_buff *)list;
64442 + return list->next == (const struct sk_buff *)list;
64443 }
64444
64445 /**
64446 @@ -693,7 +693,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
64447 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64448 const struct sk_buff *skb)
64449 {
64450 - return skb->next == (struct sk_buff *)list;
64451 + return skb->next == (const struct sk_buff *)list;
64452 }
64453
64454 /**
64455 @@ -706,7 +706,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
64456 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
64457 const struct sk_buff *skb)
64458 {
64459 - return skb->prev == (struct sk_buff *)list;
64460 + return skb->prev == (const struct sk_buff *)list;
64461 }
64462
64463 /**
64464 @@ -1605,7 +1605,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
64465 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
64466 */
64467 #ifndef NET_SKB_PAD
64468 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
64469 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
64470 #endif
64471
64472 extern int ___pskb_trim(struct sk_buff *skb, unsigned int len);
64473 @@ -2112,7 +2112,7 @@ extern struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags,
64474 int noblock, int *err);
64475 extern unsigned int datagram_poll(struct file *file, struct socket *sock,
64476 struct poll_table_struct *wait);
64477 -extern int skb_copy_datagram_iovec(const struct sk_buff *from,
64478 +extern int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from,
64479 int offset, struct iovec *to,
64480 int size);
64481 extern int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb,
64482 diff --git a/include/linux/slab.h b/include/linux/slab.h
64483 index 67d5d94..bbd740b 100644
64484 --- a/include/linux/slab.h
64485 +++ b/include/linux/slab.h
64486 @@ -11,12 +11,20 @@
64487
64488 #include <linux/gfp.h>
64489 #include <linux/types.h>
64490 +#include <linux/err.h>
64491
64492 /*
64493 * Flags to pass to kmem_cache_create().
64494 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
64495 */
64496 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
64497 +
64498 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64499 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
64500 +#else
64501 +#define SLAB_USERCOPY 0x00000000UL
64502 +#endif
64503 +
64504 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
64505 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
64506 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
64507 @@ -87,10 +95,13 @@
64508 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
64509 * Both make kfree a no-op.
64510 */
64511 -#define ZERO_SIZE_PTR ((void *)16)
64512 +#define ZERO_SIZE_PTR \
64513 +({ \
64514 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
64515 + (void *)(-MAX_ERRNO-1L); \
64516 +})
64517
64518 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
64519 - (unsigned long)ZERO_SIZE_PTR)
64520 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
64521
64522 /*
64523 * struct kmem_cache related prototypes
64524 @@ -161,6 +172,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
64525 void kfree(const void *);
64526 void kzfree(const void *);
64527 size_t ksize(const void *);
64528 +const char *check_heap_object(const void *ptr, unsigned long n, bool to);
64529 +bool is_usercopy_object(const void *ptr);
64530
64531 /*
64532 * Allocator specific definitions. These are mainly used to establish optimized
64533 @@ -298,7 +311,7 @@ static inline void *kmem_cache_alloc_node(struct kmem_cache *cachep,
64534 */
64535 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64536 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64537 -extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64538 +extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long) __size_overflow(1);
64539 #define kmalloc_track_caller(size, flags) \
64540 __kmalloc_track_caller(size, flags, _RET_IP_)
64541 #else
64542 @@ -317,7 +330,7 @@ extern void *__kmalloc_track_caller(size_t, gfp_t, unsigned long);
64543 */
64544 #if defined(CONFIG_DEBUG_SLAB) || defined(CONFIG_SLUB) || \
64545 (defined(CONFIG_SLAB) && defined(CONFIG_TRACING))
64546 -extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long);
64547 +extern void *__kmalloc_node_track_caller(size_t, gfp_t, int, unsigned long) __size_overflow(1);
64548 #define kmalloc_node_track_caller(size, flags, node) \
64549 __kmalloc_node_track_caller(size, flags, node, \
64550 _RET_IP_)
64551 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
64552 index fbd1117..0a3d314 100644
64553 --- a/include/linux/slab_def.h
64554 +++ b/include/linux/slab_def.h
64555 @@ -66,10 +66,10 @@ struct kmem_cache {
64556 unsigned long node_allocs;
64557 unsigned long node_frees;
64558 unsigned long node_overflow;
64559 - atomic_t allochit;
64560 - atomic_t allocmiss;
64561 - atomic_t freehit;
64562 - atomic_t freemiss;
64563 + atomic_unchecked_t allochit;
64564 + atomic_unchecked_t allocmiss;
64565 + atomic_unchecked_t freehit;
64566 + atomic_unchecked_t freemiss;
64567
64568 /*
64569 * If debugging is enabled, then the allocator can add additional
64570 @@ -103,11 +103,16 @@ struct cache_sizes {
64571 #ifdef CONFIG_ZONE_DMA
64572 struct kmem_cache *cs_dmacachep;
64573 #endif
64574 +
64575 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64576 + struct kmem_cache *cs_usercopycachep;
64577 +#endif
64578 +
64579 };
64580 extern struct cache_sizes malloc_sizes[];
64581
64582 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64583 -void *__kmalloc(size_t size, gfp_t flags);
64584 +void *__kmalloc(size_t size, gfp_t flags) __size_overflow(1);
64585
64586 #ifdef CONFIG_TRACING
64587 extern void *kmem_cache_alloc_trace(size_t size,
64588 @@ -150,6 +155,13 @@ found:
64589 cachep = malloc_sizes[i].cs_dmacachep;
64590 else
64591 #endif
64592 +
64593 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64594 + if (flags & GFP_USERCOPY)
64595 + cachep = malloc_sizes[i].cs_usercopycachep;
64596 + else
64597 +#endif
64598 +
64599 cachep = malloc_sizes[i].cs_cachep;
64600
64601 ret = kmem_cache_alloc_trace(size, cachep, flags);
64602 @@ -160,7 +172,7 @@ found:
64603 }
64604
64605 #ifdef CONFIG_NUMA
64606 -extern void *__kmalloc_node(size_t size, gfp_t flags, int node);
64607 +extern void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64608 extern void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64609
64610 #ifdef CONFIG_TRACING
64611 @@ -203,6 +215,13 @@ found:
64612 cachep = malloc_sizes[i].cs_dmacachep;
64613 else
64614 #endif
64615 +
64616 +#ifdef CONFIG_PAX_USERCOPY_SLABS
64617 + if (flags & GFP_USERCOPY)
64618 + cachep = malloc_sizes[i].cs_usercopycachep;
64619 + else
64620 +#endif
64621 +
64622 cachep = malloc_sizes[i].cs_cachep;
64623
64624 return kmem_cache_alloc_node_trace(size, cachep, flags, node);
64625 diff --git a/include/linux/slob_def.h b/include/linux/slob_def.h
64626 index 0ec00b3..22b4715 100644
64627 --- a/include/linux/slob_def.h
64628 +++ b/include/linux/slob_def.h
64629 @@ -9,7 +9,7 @@ static __always_inline void *kmem_cache_alloc(struct kmem_cache *cachep,
64630 return kmem_cache_alloc_node(cachep, flags, -1);
64631 }
64632
64633 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64634 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64635
64636 static __always_inline void *kmalloc_node(size_t size, gfp_t flags, int node)
64637 {
64638 @@ -29,7 +29,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64639 return __kmalloc_node(size, flags, -1);
64640 }
64641
64642 -static __always_inline void *__kmalloc(size_t size, gfp_t flags)
64643 +static __always_inline __size_overflow(1) void *__kmalloc(size_t size, gfp_t flags)
64644 {
64645 return kmalloc(size, flags);
64646 }
64647 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
64648 index c2f8c8b..d992a41 100644
64649 --- a/include/linux/slub_def.h
64650 +++ b/include/linux/slub_def.h
64651 @@ -92,7 +92,7 @@ struct kmem_cache {
64652 struct kmem_cache_order_objects max;
64653 struct kmem_cache_order_objects min;
64654 gfp_t allocflags; /* gfp flags to use on each alloc */
64655 - int refcount; /* Refcount for slab cache destroy */
64656 + atomic_t refcount; /* Refcount for slab cache destroy */
64657 void (*ctor)(void *);
64658 int inuse; /* Offset to metadata */
64659 int align; /* Alignment */
64660 @@ -153,7 +153,7 @@ extern struct kmem_cache *kmalloc_caches[SLUB_PAGE_SHIFT];
64661 * Sorry that the following has to be that ugly but some versions of GCC
64662 * have trouble with constant propagation and loops.
64663 */
64664 -static __always_inline int kmalloc_index(size_t size)
64665 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
64666 {
64667 if (!size)
64668 return 0;
64669 @@ -218,7 +218,7 @@ static __always_inline struct kmem_cache *kmalloc_slab(size_t size)
64670 }
64671
64672 void *kmem_cache_alloc(struct kmem_cache *, gfp_t);
64673 -void *__kmalloc(size_t size, gfp_t flags);
64674 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1) __size_overflow(1);
64675
64676 static __always_inline void *
64677 kmalloc_order(size_t size, gfp_t flags, unsigned int order)
64678 @@ -259,7 +259,7 @@ kmalloc_order_trace(size_t size, gfp_t flags, unsigned int order)
64679 }
64680 #endif
64681
64682 -static __always_inline void *kmalloc_large(size_t size, gfp_t flags)
64683 +static __always_inline __size_overflow(1) void *kmalloc_large(size_t size, gfp_t flags)
64684 {
64685 unsigned int order = get_order(size);
64686 return kmalloc_order_trace(size, flags, order);
64687 @@ -284,7 +284,7 @@ static __always_inline void *kmalloc(size_t size, gfp_t flags)
64688 }
64689
64690 #ifdef CONFIG_NUMA
64691 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
64692 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __size_overflow(1);
64693 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
64694
64695 #ifdef CONFIG_TRACING
64696 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
64697 index de8832d..0147b46 100644
64698 --- a/include/linux/sonet.h
64699 +++ b/include/linux/sonet.h
64700 @@ -61,7 +61,7 @@ struct sonet_stats {
64701 #include <linux/atomic.h>
64702
64703 struct k_sonet_stats {
64704 -#define __HANDLE_ITEM(i) atomic_t i
64705 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
64706 __SONET_ITEMS
64707 #undef __HANDLE_ITEM
64708 };
64709 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
64710 index 523547e..2cb7140 100644
64711 --- a/include/linux/sunrpc/clnt.h
64712 +++ b/include/linux/sunrpc/clnt.h
64713 @@ -174,9 +174,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
64714 {
64715 switch (sap->sa_family) {
64716 case AF_INET:
64717 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
64718 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
64719 case AF_INET6:
64720 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
64721 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
64722 }
64723 return 0;
64724 }
64725 @@ -209,7 +209,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
64726 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
64727 const struct sockaddr *src)
64728 {
64729 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
64730 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
64731 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
64732
64733 dsin->sin_family = ssin->sin_family;
64734 @@ -312,7 +312,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
64735 if (sa->sa_family != AF_INET6)
64736 return 0;
64737
64738 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
64739 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
64740 }
64741
64742 #endif /* __KERNEL__ */
64743 diff --git a/include/linux/sunrpc/sched.h b/include/linux/sunrpc/sched.h
64744 index dc0c3cc..8503fb6 100644
64745 --- a/include/linux/sunrpc/sched.h
64746 +++ b/include/linux/sunrpc/sched.h
64747 @@ -106,6 +106,7 @@ struct rpc_call_ops {
64748 void (*rpc_count_stats)(struct rpc_task *, void *);
64749 void (*rpc_release)(void *);
64750 };
64751 +typedef struct rpc_call_ops __no_const rpc_call_ops_no_const;
64752
64753 struct rpc_task_setup {
64754 struct rpc_task *task;
64755 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
64756 index 0b8e3e6..33e0a01 100644
64757 --- a/include/linux/sunrpc/svc_rdma.h
64758 +++ b/include/linux/sunrpc/svc_rdma.h
64759 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
64760 extern unsigned int svcrdma_max_requests;
64761 extern unsigned int svcrdma_max_req_size;
64762
64763 -extern atomic_t rdma_stat_recv;
64764 -extern atomic_t rdma_stat_read;
64765 -extern atomic_t rdma_stat_write;
64766 -extern atomic_t rdma_stat_sq_starve;
64767 -extern atomic_t rdma_stat_rq_starve;
64768 -extern atomic_t rdma_stat_rq_poll;
64769 -extern atomic_t rdma_stat_rq_prod;
64770 -extern atomic_t rdma_stat_sq_poll;
64771 -extern atomic_t rdma_stat_sq_prod;
64772 +extern atomic_unchecked_t rdma_stat_recv;
64773 +extern atomic_unchecked_t rdma_stat_read;
64774 +extern atomic_unchecked_t rdma_stat_write;
64775 +extern atomic_unchecked_t rdma_stat_sq_starve;
64776 +extern atomic_unchecked_t rdma_stat_rq_starve;
64777 +extern atomic_unchecked_t rdma_stat_rq_poll;
64778 +extern atomic_unchecked_t rdma_stat_rq_prod;
64779 +extern atomic_unchecked_t rdma_stat_sq_poll;
64780 +extern atomic_unchecked_t rdma_stat_sq_prod;
64781
64782 #define RPCRDMA_VERSION 1
64783
64784 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
64785 index c34b4c8..a65b67d 100644
64786 --- a/include/linux/sysctl.h
64787 +++ b/include/linux/sysctl.h
64788 @@ -155,7 +155,11 @@ enum
64789 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
64790 };
64791
64792 -
64793 +#ifdef CONFIG_PAX_SOFTMODE
64794 +enum {
64795 + PAX_SOFTMODE=1 /* PaX: disable/enable soft mode */
64796 +};
64797 +#endif
64798
64799 /* CTL_VM names: */
64800 enum
64801 @@ -948,6 +952,8 @@ typedef int proc_handler (struct ctl_table *ctl, int write,
64802
64803 extern int proc_dostring(struct ctl_table *, int,
64804 void __user *, size_t *, loff_t *);
64805 +extern int proc_dostring_modpriv(struct ctl_table *, int,
64806 + void __user *, size_t *, loff_t *);
64807 extern int proc_dointvec(struct ctl_table *, int,
64808 void __user *, size_t *, loff_t *);
64809 extern int proc_dointvec_minmax(struct ctl_table *, int,
64810 diff --git a/include/linux/tty.h b/include/linux/tty.h
64811 index 9f47ab5..73da944 100644
64812 --- a/include/linux/tty.h
64813 +++ b/include/linux/tty.h
64814 @@ -225,7 +225,7 @@ struct tty_port {
64815 const struct tty_port_operations *ops; /* Port operations */
64816 spinlock_t lock; /* Lock protecting tty field */
64817 int blocked_open; /* Waiting to open */
64818 - int count; /* Usage count */
64819 + atomic_t count; /* Usage count */
64820 wait_queue_head_t open_wait; /* Open waiters */
64821 wait_queue_head_t close_wait; /* Close waiters */
64822 wait_queue_head_t delta_msr_wait; /* Modem status change */
64823 @@ -525,7 +525,7 @@ extern int tty_port_open(struct tty_port *port,
64824 struct tty_struct *tty, struct file *filp);
64825 static inline int tty_port_users(struct tty_port *port)
64826 {
64827 - return port->count + port->blocked_open;
64828 + return atomic_read(&port->count) + port->blocked_open;
64829 }
64830
64831 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
64832 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
64833 index fb79dd8d..07d4773 100644
64834 --- a/include/linux/tty_ldisc.h
64835 +++ b/include/linux/tty_ldisc.h
64836 @@ -149,7 +149,7 @@ struct tty_ldisc_ops {
64837
64838 struct module *owner;
64839
64840 - int refcount;
64841 + atomic_t refcount;
64842 };
64843
64844 struct tty_ldisc {
64845 diff --git a/include/linux/types.h b/include/linux/types.h
64846 index 9c1bd53..c2370f6 100644
64847 --- a/include/linux/types.h
64848 +++ b/include/linux/types.h
64849 @@ -220,10 +220,26 @@ typedef struct {
64850 int counter;
64851 } atomic_t;
64852
64853 +#ifdef CONFIG_PAX_REFCOUNT
64854 +typedef struct {
64855 + int counter;
64856 +} atomic_unchecked_t;
64857 +#else
64858 +typedef atomic_t atomic_unchecked_t;
64859 +#endif
64860 +
64861 #ifdef CONFIG_64BIT
64862 typedef struct {
64863 long counter;
64864 } atomic64_t;
64865 +
64866 +#ifdef CONFIG_PAX_REFCOUNT
64867 +typedef struct {
64868 + long counter;
64869 +} atomic64_unchecked_t;
64870 +#else
64871 +typedef atomic64_t atomic64_unchecked_t;
64872 +#endif
64873 #endif
64874
64875 struct list_head {
64876 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
64877 index 5ca0951..ab496a5 100644
64878 --- a/include/linux/uaccess.h
64879 +++ b/include/linux/uaccess.h
64880 @@ -76,11 +76,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
64881 long ret; \
64882 mm_segment_t old_fs = get_fs(); \
64883 \
64884 - set_fs(KERNEL_DS); \
64885 pagefault_disable(); \
64886 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
64887 - pagefault_enable(); \
64888 + set_fs(KERNEL_DS); \
64889 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
64890 set_fs(old_fs); \
64891 + pagefault_enable(); \
64892 ret; \
64893 })
64894
64895 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
64896 index 99c1b4d..bb94261 100644
64897 --- a/include/linux/unaligned/access_ok.h
64898 +++ b/include/linux/unaligned/access_ok.h
64899 @@ -6,32 +6,32 @@
64900
64901 static inline u16 get_unaligned_le16(const void *p)
64902 {
64903 - return le16_to_cpup((__le16 *)p);
64904 + return le16_to_cpup((const __le16 *)p);
64905 }
64906
64907 static inline u32 get_unaligned_le32(const void *p)
64908 {
64909 - return le32_to_cpup((__le32 *)p);
64910 + return le32_to_cpup((const __le32 *)p);
64911 }
64912
64913 static inline u64 get_unaligned_le64(const void *p)
64914 {
64915 - return le64_to_cpup((__le64 *)p);
64916 + return le64_to_cpup((const __le64 *)p);
64917 }
64918
64919 static inline u16 get_unaligned_be16(const void *p)
64920 {
64921 - return be16_to_cpup((__be16 *)p);
64922 + return be16_to_cpup((const __be16 *)p);
64923 }
64924
64925 static inline u32 get_unaligned_be32(const void *p)
64926 {
64927 - return be32_to_cpup((__be32 *)p);
64928 + return be32_to_cpup((const __be32 *)p);
64929 }
64930
64931 static inline u64 get_unaligned_be64(const void *p)
64932 {
64933 - return be64_to_cpup((__be64 *)p);
64934 + return be64_to_cpup((const __be64 *)p);
64935 }
64936
64937 static inline void put_unaligned_le16(u16 val, void *p)
64938 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
64939 index 547e59c..db6ad19 100644
64940 --- a/include/linux/usb/renesas_usbhs.h
64941 +++ b/include/linux/usb/renesas_usbhs.h
64942 @@ -39,7 +39,7 @@ enum {
64943 */
64944 struct renesas_usbhs_driver_callback {
64945 int (*notify_hotplug)(struct platform_device *pdev);
64946 -};
64947 +} __no_const;
64948
64949 /*
64950 * callback functions for platform
64951 @@ -97,7 +97,7 @@ struct renesas_usbhs_platform_callback {
64952 * VBUS control is needed for Host
64953 */
64954 int (*set_vbus)(struct platform_device *pdev, int enable);
64955 -};
64956 +} __no_const;
64957
64958 /*
64959 * parameters for renesas usbhs
64960 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
64961 index 6f8fbcf..8259001 100644
64962 --- a/include/linux/vermagic.h
64963 +++ b/include/linux/vermagic.h
64964 @@ -25,9 +25,35 @@
64965 #define MODULE_ARCH_VERMAGIC ""
64966 #endif
64967
64968 +#ifdef CONFIG_PAX_REFCOUNT
64969 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
64970 +#else
64971 +#define MODULE_PAX_REFCOUNT ""
64972 +#endif
64973 +
64974 +#ifdef CONSTIFY_PLUGIN
64975 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
64976 +#else
64977 +#define MODULE_CONSTIFY_PLUGIN ""
64978 +#endif
64979 +
64980 +#ifdef STACKLEAK_PLUGIN
64981 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
64982 +#else
64983 +#define MODULE_STACKLEAK_PLUGIN ""
64984 +#endif
64985 +
64986 +#ifdef CONFIG_GRKERNSEC
64987 +#define MODULE_GRSEC "GRSEC "
64988 +#else
64989 +#define MODULE_GRSEC ""
64990 +#endif
64991 +
64992 #define VERMAGIC_STRING \
64993 UTS_RELEASE " " \
64994 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
64995 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
64996 - MODULE_ARCH_VERMAGIC
64997 + MODULE_ARCH_VERMAGIC \
64998 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
64999 + MODULE_GRSEC
65000
65001 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
65002 index dcdfc2b..ec79ab5 100644
65003 --- a/include/linux/vmalloc.h
65004 +++ b/include/linux/vmalloc.h
65005 @@ -14,6 +14,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
65006 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
65007 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
65008 #define VM_UNLIST 0x00000020 /* vm_struct is not listed in vmlist */
65009 +
65010 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
65011 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
65012 +#endif
65013 +
65014 /* bits [20..32] reserved for arch specific ioremap internals */
65015
65016 /*
65017 @@ -62,7 +67,7 @@ extern void *vmalloc_32_user(unsigned long size);
65018 extern void *__vmalloc(unsigned long size, gfp_t gfp_mask, pgprot_t prot);
65019 extern void *__vmalloc_node_range(unsigned long size, unsigned long align,
65020 unsigned long start, unsigned long end, gfp_t gfp_mask,
65021 - pgprot_t prot, int node, void *caller);
65022 + pgprot_t prot, int node, void *caller) __size_overflow(1);
65023 extern void vfree(const void *addr);
65024
65025 extern void *vmap(struct page **pages, unsigned int count,
65026 @@ -123,8 +128,8 @@ extern struct vm_struct *alloc_vm_area(size_t size, pte_t **ptes);
65027 extern void free_vm_area(struct vm_struct *area);
65028
65029 /* for /dev/kmem */
65030 -extern long vread(char *buf, char *addr, unsigned long count);
65031 -extern long vwrite(char *buf, char *addr, unsigned long count);
65032 +extern long vread(char *buf, char *addr, unsigned long count) __size_overflow(3);
65033 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
65034
65035 /*
65036 * Internals. Dont't use..
65037 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
65038 index 65efb92..137adbb 100644
65039 --- a/include/linux/vmstat.h
65040 +++ b/include/linux/vmstat.h
65041 @@ -87,18 +87,18 @@ static inline void vm_events_fold_cpu(int cpu)
65042 /*
65043 * Zone based page accounting with per cpu differentials.
65044 */
65045 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65046 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
65047
65048 static inline void zone_page_state_add(long x, struct zone *zone,
65049 enum zone_stat_item item)
65050 {
65051 - atomic_long_add(x, &zone->vm_stat[item]);
65052 - atomic_long_add(x, &vm_stat[item]);
65053 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
65054 + atomic_long_add_unchecked(x, &vm_stat[item]);
65055 }
65056
65057 static inline unsigned long global_page_state(enum zone_stat_item item)
65058 {
65059 - long x = atomic_long_read(&vm_stat[item]);
65060 + long x = atomic_long_read_unchecked(&vm_stat[item]);
65061 #ifdef CONFIG_SMP
65062 if (x < 0)
65063 x = 0;
65064 @@ -109,7 +109,7 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
65065 static inline unsigned long zone_page_state(struct zone *zone,
65066 enum zone_stat_item item)
65067 {
65068 - long x = atomic_long_read(&zone->vm_stat[item]);
65069 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65070 #ifdef CONFIG_SMP
65071 if (x < 0)
65072 x = 0;
65073 @@ -126,7 +126,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
65074 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
65075 enum zone_stat_item item)
65076 {
65077 - long x = atomic_long_read(&zone->vm_stat[item]);
65078 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
65079
65080 #ifdef CONFIG_SMP
65081 int cpu;
65082 @@ -221,8 +221,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
65083
65084 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
65085 {
65086 - atomic_long_inc(&zone->vm_stat[item]);
65087 - atomic_long_inc(&vm_stat[item]);
65088 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
65089 + atomic_long_inc_unchecked(&vm_stat[item]);
65090 }
65091
65092 static inline void __inc_zone_page_state(struct page *page,
65093 @@ -233,8 +233,8 @@ static inline void __inc_zone_page_state(struct page *page,
65094
65095 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
65096 {
65097 - atomic_long_dec(&zone->vm_stat[item]);
65098 - atomic_long_dec(&vm_stat[item]);
65099 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
65100 + atomic_long_dec_unchecked(&vm_stat[item]);
65101 }
65102
65103 static inline void __dec_zone_page_state(struct page *page,
65104 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
65105 index e5d1220..ef6e406 100644
65106 --- a/include/linux/xattr.h
65107 +++ b/include/linux/xattr.h
65108 @@ -57,6 +57,11 @@
65109 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
65110 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
65111
65112 +/* User namespace */
65113 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
65114 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
65115 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
65116 +
65117 #ifdef __KERNEL__
65118
65119 #include <linux/types.h>
65120 diff --git a/include/linux/xfrm.h b/include/linux/xfrm.h
65121 index 22e61fd..28e493b 100644
65122 --- a/include/linux/xfrm.h
65123 +++ b/include/linux/xfrm.h
65124 @@ -84,6 +84,8 @@ struct xfrm_replay_state {
65125 __u32 bitmap;
65126 };
65127
65128 +#define XFRMA_REPLAY_ESN_MAX 4096
65129 +
65130 struct xfrm_replay_state_esn {
65131 unsigned int bmp_len;
65132 __u32 oseq;
65133 diff --git a/include/media/saa7146_vv.h b/include/media/saa7146_vv.h
65134 index 944ecdf..a3994fc 100644
65135 --- a/include/media/saa7146_vv.h
65136 +++ b/include/media/saa7146_vv.h
65137 @@ -161,8 +161,8 @@ struct saa7146_ext_vv
65138 int (*std_callback)(struct saa7146_dev*, struct saa7146_standard *);
65139
65140 /* the extension can override this */
65141 - struct v4l2_ioctl_ops vid_ops;
65142 - struct v4l2_ioctl_ops vbi_ops;
65143 + v4l2_ioctl_ops_no_const vid_ops;
65144 + v4l2_ioctl_ops_no_const vbi_ops;
65145 /* pointer to the saa7146 core ops */
65146 const struct v4l2_ioctl_ops *core_ops;
65147
65148 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
65149 index a056e6e..31023a5 100644
65150 --- a/include/media/v4l2-dev.h
65151 +++ b/include/media/v4l2-dev.h
65152 @@ -73,7 +73,8 @@ struct v4l2_file_operations {
65153 int (*mmap) (struct file *, struct vm_area_struct *);
65154 int (*open) (struct file *);
65155 int (*release) (struct file *);
65156 -};
65157 +} __do_const;
65158 +typedef struct v4l2_file_operations __no_const v4l2_file_operations_no_const;
65159
65160 /*
65161 * Newer version of video_device, handled by videodev2.c
65162 diff --git a/include/media/v4l2-ioctl.h b/include/media/v4l2-ioctl.h
65163 index d8b76f7..7d5aa18 100644
65164 --- a/include/media/v4l2-ioctl.h
65165 +++ b/include/media/v4l2-ioctl.h
65166 @@ -287,7 +287,7 @@ struct v4l2_ioctl_ops {
65167 long (*vidioc_default) (struct file *file, void *fh,
65168 bool valid_prio, int cmd, void *arg);
65169 };
65170 -
65171 +typedef struct v4l2_ioctl_ops __no_const v4l2_ioctl_ops_no_const;
65172
65173 /* v4l debugging and diagnostics */
65174
65175 diff --git a/include/net/caif/caif_hsi.h b/include/net/caif/caif_hsi.h
65176 index 439dadc..1c67e3f 100644
65177 --- a/include/net/caif/caif_hsi.h
65178 +++ b/include/net/caif/caif_hsi.h
65179 @@ -98,7 +98,7 @@ struct cfhsi_drv {
65180 void (*rx_done_cb) (struct cfhsi_drv *drv);
65181 void (*wake_up_cb) (struct cfhsi_drv *drv);
65182 void (*wake_down_cb) (struct cfhsi_drv *drv);
65183 -};
65184 +} __no_const;
65185
65186 /* Structure implemented by HSI device. */
65187 struct cfhsi_dev {
65188 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
65189 index 9e5425b..8136ffc 100644
65190 --- a/include/net/caif/cfctrl.h
65191 +++ b/include/net/caif/cfctrl.h
65192 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
65193 void (*radioset_rsp)(void);
65194 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
65195 struct cflayer *client_layer);
65196 -};
65197 +} __no_const;
65198
65199 /* Link Setup Parameters for CAIF-Links. */
65200 struct cfctrl_link_param {
65201 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
65202 struct cfctrl {
65203 struct cfsrvl serv;
65204 struct cfctrl_rsp res;
65205 - atomic_t req_seq_no;
65206 - atomic_t rsp_seq_no;
65207 + atomic_unchecked_t req_seq_no;
65208 + atomic_unchecked_t rsp_seq_no;
65209 struct list_head list;
65210 /* Protects from simultaneous access to first_req list */
65211 spinlock_t info_list_lock;
65212 diff --git a/include/net/flow.h b/include/net/flow.h
65213 index 6c469db..7743b8e 100644
65214 --- a/include/net/flow.h
65215 +++ b/include/net/flow.h
65216 @@ -221,6 +221,6 @@ extern struct flow_cache_object *flow_cache_lookup(
65217
65218 extern void flow_cache_flush(void);
65219 extern void flow_cache_flush_deferred(void);
65220 -extern atomic_t flow_cache_genid;
65221 +extern atomic_unchecked_t flow_cache_genid;
65222
65223 #endif
65224 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
65225 index 2040bff..f4c0733 100644
65226 --- a/include/net/inetpeer.h
65227 +++ b/include/net/inetpeer.h
65228 @@ -51,8 +51,8 @@ struct inet_peer {
65229 */
65230 union {
65231 struct {
65232 - atomic_t rid; /* Frag reception counter */
65233 - atomic_t ip_id_count; /* IP ID for the next packet */
65234 + atomic_unchecked_t rid; /* Frag reception counter */
65235 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
65236 __u32 tcp_ts;
65237 __u32 tcp_ts_stamp;
65238 };
65239 @@ -118,11 +118,11 @@ static inline int inet_getid(struct inet_peer *p, int more)
65240 more++;
65241 inet_peer_refcheck(p);
65242 do {
65243 - old = atomic_read(&p->ip_id_count);
65244 + old = atomic_read_unchecked(&p->ip_id_count);
65245 new = old + more;
65246 if (!new)
65247 new = 1;
65248 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
65249 + } while (atomic_cmpxchg_unchecked(&p->ip_id_count, old, new) != old);
65250 return new;
65251 }
65252
65253 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
65254 index 78df0866..00e5c9b 100644
65255 --- a/include/net/ip_fib.h
65256 +++ b/include/net/ip_fib.h
65257 @@ -146,7 +146,7 @@ extern __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
65258
65259 #define FIB_RES_SADDR(net, res) \
65260 ((FIB_RES_NH(res).nh_saddr_genid == \
65261 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
65262 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
65263 FIB_RES_NH(res).nh_saddr : \
65264 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
65265 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
65266 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
65267 index 95374d1..2300e36 100644
65268 --- a/include/net/ip_vs.h
65269 +++ b/include/net/ip_vs.h
65270 @@ -510,7 +510,7 @@ struct ip_vs_conn {
65271 struct ip_vs_conn *control; /* Master control connection */
65272 atomic_t n_control; /* Number of controlled ones */
65273 struct ip_vs_dest *dest; /* real server */
65274 - atomic_t in_pkts; /* incoming packet counter */
65275 + atomic_unchecked_t in_pkts; /* incoming packet counter */
65276
65277 /* packet transmitter for different forwarding methods. If it
65278 mangles the packet, it must return NF_DROP or better NF_STOLEN,
65279 @@ -648,7 +648,7 @@ struct ip_vs_dest {
65280 __be16 port; /* port number of the server */
65281 union nf_inet_addr addr; /* IP address of the server */
65282 volatile unsigned int flags; /* dest status flags */
65283 - atomic_t conn_flags; /* flags to copy to conn */
65284 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
65285 atomic_t weight; /* server weight */
65286
65287 atomic_t refcnt; /* reference counter */
65288 diff --git a/include/net/irda/ircomm_core.h b/include/net/irda/ircomm_core.h
65289 index 69b610a..fe3962c 100644
65290 --- a/include/net/irda/ircomm_core.h
65291 +++ b/include/net/irda/ircomm_core.h
65292 @@ -51,7 +51,7 @@ typedef struct {
65293 int (*connect_response)(struct ircomm_cb *, struct sk_buff *);
65294 int (*disconnect_request)(struct ircomm_cb *, struct sk_buff *,
65295 struct ircomm_info *);
65296 -} call_t;
65297 +} __no_const call_t;
65298
65299 struct ircomm_cb {
65300 irda_queue_t queue;
65301 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
65302 index 59ba38bc..d515662 100644
65303 --- a/include/net/irda/ircomm_tty.h
65304 +++ b/include/net/irda/ircomm_tty.h
65305 @@ -35,6 +35,7 @@
65306 #include <linux/termios.h>
65307 #include <linux/timer.h>
65308 #include <linux/tty.h> /* struct tty_struct */
65309 +#include <asm/local.h>
65310
65311 #include <net/irda/irias_object.h>
65312 #include <net/irda/ircomm_core.h>
65313 @@ -105,8 +106,8 @@ struct ircomm_tty_cb {
65314 unsigned short close_delay;
65315 unsigned short closing_wait; /* time to wait before closing */
65316
65317 - int open_count;
65318 - int blocked_open; /* # of blocked opens */
65319 + local_t open_count;
65320 + local_t blocked_open; /* # of blocked opens */
65321
65322 /* Protect concurent access to :
65323 * o self->open_count
65324 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
65325 index cc7c197..9f2da2a 100644
65326 --- a/include/net/iucv/af_iucv.h
65327 +++ b/include/net/iucv/af_iucv.h
65328 @@ -141,7 +141,7 @@ struct iucv_sock {
65329 struct iucv_sock_list {
65330 struct hlist_head head;
65331 rwlock_t lock;
65332 - atomic_t autobind_name;
65333 + atomic_unchecked_t autobind_name;
65334 };
65335
65336 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
65337 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
65338 index 6cdfeed..55a0256 100644
65339 --- a/include/net/neighbour.h
65340 +++ b/include/net/neighbour.h
65341 @@ -123,7 +123,7 @@ struct neigh_ops {
65342 void (*error_report)(struct neighbour *, struct sk_buff *);
65343 int (*output)(struct neighbour *, struct sk_buff *);
65344 int (*connected_output)(struct neighbour *, struct sk_buff *);
65345 -};
65346 +} __do_const;
65347
65348 struct pneigh_entry {
65349 struct pneigh_entry *next;
65350 diff --git a/include/net/netdma.h b/include/net/netdma.h
65351 index 8ba8ce2..99b7fff 100644
65352 --- a/include/net/netdma.h
65353 +++ b/include/net/netdma.h
65354 @@ -24,7 +24,7 @@
65355 #include <linux/dmaengine.h>
65356 #include <linux/skbuff.h>
65357
65358 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65359 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
65360 struct sk_buff *skb, int offset, struct iovec *to,
65361 size_t len, struct dma_pinned_list *pinned_list);
65362
65363 diff --git a/include/net/netlink.h b/include/net/netlink.h
65364 index 785f37a..c81dc0c 100644
65365 --- a/include/net/netlink.h
65366 +++ b/include/net/netlink.h
65367 @@ -520,7 +520,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
65368 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
65369 {
65370 if (mark)
65371 - skb_trim(skb, (unsigned char *) mark - skb->data);
65372 + skb_trim(skb, (const unsigned char *) mark - skb->data);
65373 }
65374
65375 /**
65376 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
65377 index bbd023a..97c6d0d 100644
65378 --- a/include/net/netns/ipv4.h
65379 +++ b/include/net/netns/ipv4.h
65380 @@ -57,8 +57,8 @@ struct netns_ipv4 {
65381 unsigned int sysctl_ping_group_range[2];
65382 long sysctl_tcp_mem[3];
65383
65384 - atomic_t rt_genid;
65385 - atomic_t dev_addr_genid;
65386 + atomic_unchecked_t rt_genid;
65387 + atomic_unchecked_t dev_addr_genid;
65388
65389 #ifdef CONFIG_IP_MROUTE
65390 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
65391 diff --git a/include/net/sctp/sctp.h b/include/net/sctp/sctp.h
65392 index a2ef814..31a8e3f 100644
65393 --- a/include/net/sctp/sctp.h
65394 +++ b/include/net/sctp/sctp.h
65395 @@ -318,9 +318,9 @@ do { \
65396
65397 #else /* SCTP_DEBUG */
65398
65399 -#define SCTP_DEBUG_PRINTK(whatever...)
65400 -#define SCTP_DEBUG_PRINTK_CONT(fmt, args...)
65401 -#define SCTP_DEBUG_PRINTK_IPADDR(whatever...)
65402 +#define SCTP_DEBUG_PRINTK(whatever...) do {} while (0)
65403 +#define SCTP_DEBUG_PRINTK_CONT(fmt, args...) do {} while (0)
65404 +#define SCTP_DEBUG_PRINTK_IPADDR(whatever...) do {} while (0)
65405 #define SCTP_ENABLE_DEBUG
65406 #define SCTP_DISABLE_DEBUG
65407 #define SCTP_ASSERT(expr, str, func)
65408 diff --git a/include/net/sock.h b/include/net/sock.h
65409 index 5de6557..0bad07b 100644
65410 --- a/include/net/sock.h
65411 +++ b/include/net/sock.h
65412 @@ -304,7 +304,7 @@ struct sock {
65413 #ifdef CONFIG_RPS
65414 __u32 sk_rxhash;
65415 #endif
65416 - atomic_t sk_drops;
65417 + atomic_unchecked_t sk_drops;
65418 int sk_rcvbuf;
65419
65420 struct sk_filter __rcu *sk_filter;
65421 @@ -1728,7 +1728,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
65422 }
65423
65424 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
65425 - char __user *from, char *to,
65426 + char __user *from, unsigned char *to,
65427 int copy, int offset)
65428 {
65429 if (skb->ip_summed == CHECKSUM_NONE) {
65430 @@ -1987,7 +1987,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
65431 }
65432 }
65433
65434 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65435 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
65436
65437 static inline struct page *sk_stream_alloc_page(struct sock *sk)
65438 {
65439 diff --git a/include/net/tcp.h b/include/net/tcp.h
65440 index e79aa48..05e52de 100644
65441 --- a/include/net/tcp.h
65442 +++ b/include/net/tcp.h
65443 @@ -476,7 +476,7 @@ extern void tcp_retransmit_timer(struct sock *sk);
65444 extern void tcp_xmit_retransmit_queue(struct sock *);
65445 extern void tcp_simple_retransmit(struct sock *);
65446 extern int tcp_trim_head(struct sock *, struct sk_buff *, u32);
65447 -extern int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65448 +extern int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
65449
65450 extern void tcp_send_probe0(struct sock *);
65451 extern void tcp_send_partial(struct sock *);
65452 @@ -643,8 +643,8 @@ struct tcp_skb_cb {
65453 struct inet6_skb_parm h6;
65454 #endif
65455 } header; /* For incoming frames */
65456 - __u32 seq; /* Starting sequence number */
65457 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
65458 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
65459 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
65460 __u32 when; /* used to compute rtt's */
65461 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
65462
65463 @@ -658,7 +658,7 @@ struct tcp_skb_cb {
65464
65465 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
65466 /* 1 byte hole */
65467 - __u32 ack_seq; /* Sequence number ACK'd */
65468 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
65469 };
65470
65471 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
65472 @@ -1459,7 +1459,7 @@ struct tcp_seq_afinfo {
65473 char *name;
65474 sa_family_t family;
65475 const struct file_operations *seq_fops;
65476 - struct seq_operations seq_ops;
65477 + seq_operations_no_const seq_ops;
65478 };
65479
65480 struct tcp_iter_state {
65481 diff --git a/include/net/udp.h b/include/net/udp.h
65482 index 065f379..b661b40 100644
65483 --- a/include/net/udp.h
65484 +++ b/include/net/udp.h
65485 @@ -244,7 +244,7 @@ struct udp_seq_afinfo {
65486 sa_family_t family;
65487 struct udp_table *udp_table;
65488 const struct file_operations *seq_fops;
65489 - struct seq_operations seq_ops;
65490 + seq_operations_no_const seq_ops;
65491 };
65492
65493 struct udp_iter_state {
65494 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
65495 index e0a55df..5890bca07 100644
65496 --- a/include/net/xfrm.h
65497 +++ b/include/net/xfrm.h
65498 @@ -505,7 +505,7 @@ struct xfrm_policy {
65499 struct timer_list timer;
65500
65501 struct flow_cache_object flo;
65502 - atomic_t genid;
65503 + atomic_unchecked_t genid;
65504 u32 priority;
65505 u32 index;
65506 struct xfrm_mark mark;
65507 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
65508 index 1a046b1..ee0bef0 100644
65509 --- a/include/rdma/iw_cm.h
65510 +++ b/include/rdma/iw_cm.h
65511 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
65512 int backlog);
65513
65514 int (*destroy_listen)(struct iw_cm_id *cm_id);
65515 -};
65516 +} __no_const;
65517
65518 /**
65519 * iw_create_cm_id - Create an IW CM identifier.
65520 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
65521 index 8f9dfba..610ab6c 100644
65522 --- a/include/scsi/libfc.h
65523 +++ b/include/scsi/libfc.h
65524 @@ -756,6 +756,7 @@ struct libfc_function_template {
65525 */
65526 void (*disc_stop_final) (struct fc_lport *);
65527 };
65528 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
65529
65530 /**
65531 * struct fc_disc - Discovery context
65532 @@ -861,7 +862,7 @@ struct fc_lport {
65533 struct fc_vport *vport;
65534
65535 /* Operational Information */
65536 - struct libfc_function_template tt;
65537 + libfc_function_template_no_const tt;
65538 u8 link_up;
65539 u8 qfull;
65540 enum fc_lport_state state;
65541 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
65542 index ba96988..ecf2eb9 100644
65543 --- a/include/scsi/scsi_device.h
65544 +++ b/include/scsi/scsi_device.h
65545 @@ -163,9 +163,9 @@ struct scsi_device {
65546 unsigned int max_device_blocked; /* what device_blocked counts down from */
65547 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
65548
65549 - atomic_t iorequest_cnt;
65550 - atomic_t iodone_cnt;
65551 - atomic_t ioerr_cnt;
65552 + atomic_unchecked_t iorequest_cnt;
65553 + atomic_unchecked_t iodone_cnt;
65554 + atomic_unchecked_t ioerr_cnt;
65555
65556 struct device sdev_gendev,
65557 sdev_dev;
65558 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
65559 index 719faf1..07b6728 100644
65560 --- a/include/scsi/scsi_transport_fc.h
65561 +++ b/include/scsi/scsi_transport_fc.h
65562 @@ -739,7 +739,8 @@ struct fc_function_template {
65563 unsigned long show_host_system_hostname:1;
65564
65565 unsigned long disable_target_scan:1;
65566 -};
65567 +} __do_const;
65568 +typedef struct fc_function_template __no_const fc_function_template_no_const;
65569
65570
65571 /**
65572 diff --git a/include/sound/ak4xxx-adda.h b/include/sound/ak4xxx-adda.h
65573 index 030b87c..98a6954 100644
65574 --- a/include/sound/ak4xxx-adda.h
65575 +++ b/include/sound/ak4xxx-adda.h
65576 @@ -35,7 +35,7 @@ struct snd_ak4xxx_ops {
65577 void (*write)(struct snd_akm4xxx *ak, int chip, unsigned char reg,
65578 unsigned char val);
65579 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
65580 -};
65581 +} __no_const;
65582
65583 #define AK4XXX_IMAGE_SIZE (AK4XXX_MAX_CHIPS * 16) /* 64 bytes */
65584
65585 diff --git a/include/sound/hwdep.h b/include/sound/hwdep.h
65586 index 8c05e47..2b5df97 100644
65587 --- a/include/sound/hwdep.h
65588 +++ b/include/sound/hwdep.h
65589 @@ -49,7 +49,7 @@ struct snd_hwdep_ops {
65590 struct snd_hwdep_dsp_status *status);
65591 int (*dsp_load)(struct snd_hwdep *hw,
65592 struct snd_hwdep_dsp_image *image);
65593 -};
65594 +} __no_const;
65595
65596 struct snd_hwdep {
65597 struct snd_card *card;
65598 diff --git a/include/sound/info.h b/include/sound/info.h
65599 index 9ca1a49..aba1728 100644
65600 --- a/include/sound/info.h
65601 +++ b/include/sound/info.h
65602 @@ -44,7 +44,7 @@ struct snd_info_entry_text {
65603 struct snd_info_buffer *buffer);
65604 void (*write)(struct snd_info_entry *entry,
65605 struct snd_info_buffer *buffer);
65606 -};
65607 +} __no_const;
65608
65609 struct snd_info_entry_ops {
65610 int (*open)(struct snd_info_entry *entry,
65611 diff --git a/include/sound/pcm.h b/include/sound/pcm.h
65612 index 0d11128..814178e 100644
65613 --- a/include/sound/pcm.h
65614 +++ b/include/sound/pcm.h
65615 @@ -81,6 +81,7 @@ struct snd_pcm_ops {
65616 int (*mmap)(struct snd_pcm_substream *substream, struct vm_area_struct *vma);
65617 int (*ack)(struct snd_pcm_substream *substream);
65618 };
65619 +typedef struct snd_pcm_ops __no_const snd_pcm_ops_no_const;
65620
65621 /*
65622 *
65623 diff --git a/include/sound/sb16_csp.h b/include/sound/sb16_csp.h
65624 index af1b49e..a5d55a5 100644
65625 --- a/include/sound/sb16_csp.h
65626 +++ b/include/sound/sb16_csp.h
65627 @@ -146,7 +146,7 @@ struct snd_sb_csp_ops {
65628 int (*csp_start) (struct snd_sb_csp * p, int sample_width, int channels);
65629 int (*csp_stop) (struct snd_sb_csp * p);
65630 int (*csp_qsound_transfer) (struct snd_sb_csp * p);
65631 -};
65632 +} __no_const;
65633
65634 /*
65635 * CSP private data
65636 diff --git a/include/sound/soc.h b/include/sound/soc.h
65637 index c703871..f7fbbbd 100644
65638 --- a/include/sound/soc.h
65639 +++ b/include/sound/soc.h
65640 @@ -757,7 +757,7 @@ struct snd_soc_platform_driver {
65641 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
65642 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
65643 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
65644 -};
65645 +} __do_const;
65646
65647 struct snd_soc_platform {
65648 const char *name;
65649 @@ -949,7 +949,7 @@ struct snd_soc_pcm_runtime {
65650 struct snd_soc_dai_link *dai_link;
65651 struct mutex pcm_mutex;
65652 enum snd_soc_pcm_subclass pcm_subclass;
65653 - struct snd_pcm_ops ops;
65654 + snd_pcm_ops_no_const ops;
65655
65656 unsigned int dev_registered:1;
65657
65658 diff --git a/include/sound/tea575x-tuner.h b/include/sound/tea575x-tuner.h
65659 index 0c3c2fb..d9d9990 100644
65660 --- a/include/sound/tea575x-tuner.h
65661 +++ b/include/sound/tea575x-tuner.h
65662 @@ -44,7 +44,7 @@ struct snd_tea575x_ops {
65663
65664 struct snd_tea575x {
65665 struct v4l2_device *v4l2_dev;
65666 - struct v4l2_file_operations fops;
65667 + v4l2_file_operations_no_const fops;
65668 struct video_device vd; /* video device */
65669 int radio_nr; /* radio_nr */
65670 bool tea5759; /* 5759 chip is present */
65671 diff --git a/include/sound/ymfpci.h b/include/sound/ymfpci.h
65672 index 4119966..1a4671c 100644
65673 --- a/include/sound/ymfpci.h
65674 +++ b/include/sound/ymfpci.h
65675 @@ -358,7 +358,7 @@ struct snd_ymfpci {
65676 spinlock_t reg_lock;
65677 spinlock_t voice_lock;
65678 wait_queue_head_t interrupt_sleep;
65679 - atomic_t interrupt_sleep_count;
65680 + atomic_unchecked_t interrupt_sleep_count;
65681 struct snd_info_entry *proc_entry;
65682 const struct firmware *dsp_microcode;
65683 const struct firmware *controller_microcode;
65684 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
65685 index 362e0d9..36b9a83 100644
65686 --- a/include/target/target_core_base.h
65687 +++ b/include/target/target_core_base.h
65688 @@ -441,7 +441,7 @@ struct t10_reservation_ops {
65689 int (*t10_seq_non_holder)(struct se_cmd *, unsigned char *, u32);
65690 int (*t10_pr_register)(struct se_cmd *);
65691 int (*t10_pr_clear)(struct se_cmd *);
65692 -};
65693 +} __no_const;
65694
65695 struct t10_reservation {
65696 /* Reservation effects all target ports */
65697 @@ -780,7 +780,7 @@ struct se_device {
65698 spinlock_t stats_lock;
65699 /* Active commands on this virtual SE device */
65700 atomic_t simple_cmds;
65701 - atomic_t dev_ordered_id;
65702 + atomic_unchecked_t dev_ordered_id;
65703 atomic_t execute_tasks;
65704 atomic_t dev_ordered_sync;
65705 atomic_t dev_qf_count;
65706 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
65707 new file mode 100644
65708 index 0000000..2efe49d
65709 --- /dev/null
65710 +++ b/include/trace/events/fs.h
65711 @@ -0,0 +1,53 @@
65712 +#undef TRACE_SYSTEM
65713 +#define TRACE_SYSTEM fs
65714 +
65715 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
65716 +#define _TRACE_FS_H
65717 +
65718 +#include <linux/fs.h>
65719 +#include <linux/tracepoint.h>
65720 +
65721 +TRACE_EVENT(do_sys_open,
65722 +
65723 + TP_PROTO(char *filename, int flags, int mode),
65724 +
65725 + TP_ARGS(filename, flags, mode),
65726 +
65727 + TP_STRUCT__entry(
65728 + __string( filename, filename )
65729 + __field( int, flags )
65730 + __field( int, mode )
65731 + ),
65732 +
65733 + TP_fast_assign(
65734 + __assign_str(filename, filename);
65735 + __entry->flags = flags;
65736 + __entry->mode = mode;
65737 + ),
65738 +
65739 + TP_printk("\"%s\" %x %o",
65740 + __get_str(filename), __entry->flags, __entry->mode)
65741 +);
65742 +
65743 +TRACE_EVENT(open_exec,
65744 +
65745 + TP_PROTO(const char *filename),
65746 +
65747 + TP_ARGS(filename),
65748 +
65749 + TP_STRUCT__entry(
65750 + __string( filename, filename )
65751 + ),
65752 +
65753 + TP_fast_assign(
65754 + __assign_str(filename, filename);
65755 + ),
65756 +
65757 + TP_printk("\"%s\"",
65758 + __get_str(filename))
65759 +);
65760 +
65761 +#endif /* _TRACE_FS_H */
65762 +
65763 +/* This part must be outside protection */
65764 +#include <trace/define_trace.h>
65765 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
65766 index 1c09820..7f5ec79 100644
65767 --- a/include/trace/events/irq.h
65768 +++ b/include/trace/events/irq.h
65769 @@ -36,7 +36,7 @@ struct softirq_action;
65770 */
65771 TRACE_EVENT(irq_handler_entry,
65772
65773 - TP_PROTO(int irq, struct irqaction *action),
65774 + TP_PROTO(int irq, const struct irqaction *action),
65775
65776 TP_ARGS(irq, action),
65777
65778 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
65779 */
65780 TRACE_EVENT(irq_handler_exit,
65781
65782 - TP_PROTO(int irq, struct irqaction *action, int ret),
65783 + TP_PROTO(int irq, const struct irqaction *action, int ret),
65784
65785 TP_ARGS(irq, action, ret),
65786
65787 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
65788 index f9466fa..f4e2b81 100644
65789 --- a/include/video/udlfb.h
65790 +++ b/include/video/udlfb.h
65791 @@ -53,10 +53,10 @@ struct dlfb_data {
65792 u32 pseudo_palette[256];
65793 int blank_mode; /*one of FB_BLANK_ */
65794 /* blit-only rendering path metrics, exposed through sysfs */
65795 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65796 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
65797 - atomic_t bytes_sent; /* to usb, after compression including overhead */
65798 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
65799 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
65800 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
65801 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
65802 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
65803 };
65804
65805 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
65806 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
65807 index 0993a22..32ba2fe 100644
65808 --- a/include/video/uvesafb.h
65809 +++ b/include/video/uvesafb.h
65810 @@ -177,6 +177,7 @@ struct uvesafb_par {
65811 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
65812 u8 pmi_setpal; /* PMI for palette changes */
65813 u16 *pmi_base; /* protected mode interface location */
65814 + u8 *pmi_code; /* protected mode code location */
65815 void *pmi_start;
65816 void *pmi_pal;
65817 u8 *vbe_state_orig; /*
65818 diff --git a/init/Kconfig b/init/Kconfig
65819 index d07dcf9..fa47d0e 100644
65820 --- a/init/Kconfig
65821 +++ b/init/Kconfig
65822 @@ -835,6 +835,7 @@ endif # CGROUPS
65823
65824 config CHECKPOINT_RESTORE
65825 bool "Checkpoint/restore support" if EXPERT
65826 + depends on !GRKERNSEC
65827 default n
65828 help
65829 Enables additional kernel features in a sake of checkpoint/restore.
65830 @@ -1014,6 +1015,7 @@ config UIDGID_CONVERTED
65831 # Security modules
65832 depends on SECURITY_TOMOYO = n
65833 depends on SECURITY_APPARMOR = n
65834 + depends on GRKERNSEC = n
65835
65836 config UIDGID_STRICT_TYPE_CHECKS
65837 bool "Require conversions between uid/gids and their internal representation"
65838 @@ -1401,7 +1403,7 @@ config SLUB_DEBUG
65839
65840 config COMPAT_BRK
65841 bool "Disable heap randomization"
65842 - default y
65843 + default n
65844 help
65845 Randomizing heap placement makes heap exploits harder, but it
65846 also breaks ancient binaries (including anything libc5 based).
65847 @@ -1584,7 +1586,7 @@ config INIT_ALL_POSSIBLE
65848 config STOP_MACHINE
65849 bool
65850 default y
65851 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
65852 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
65853 help
65854 Need stop_machine() primitive.
65855
65856 diff --git a/init/Makefile b/init/Makefile
65857 index 7bc47ee..6da2dc7 100644
65858 --- a/init/Makefile
65859 +++ b/init/Makefile
65860 @@ -2,6 +2,9 @@
65861 # Makefile for the linux kernel.
65862 #
65863
65864 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
65865 +asflags-y := $(GCC_PLUGINS_AFLAGS)
65866 +
65867 obj-y := main.o version.o mounts.o
65868 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
65869 obj-y += noinitramfs.o
65870 diff --git a/init/do_mounts.c b/init/do_mounts.c
65871 index d3f0aee..c9322f5 100644
65872 --- a/init/do_mounts.c
65873 +++ b/init/do_mounts.c
65874 @@ -336,11 +336,11 @@ static void __init get_fs_names(char *page)
65875 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
65876 {
65877 struct super_block *s;
65878 - int err = sys_mount(name, "/root", fs, flags, data);
65879 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
65880 if (err)
65881 return err;
65882
65883 - sys_chdir("/root");
65884 + sys_chdir((const char __force_user *)"/root");
65885 s = current->fs->pwd.dentry->d_sb;
65886 ROOT_DEV = s->s_dev;
65887 printk(KERN_INFO
65888 @@ -460,18 +460,18 @@ void __init change_floppy(char *fmt, ...)
65889 va_start(args, fmt);
65890 vsprintf(buf, fmt, args);
65891 va_end(args);
65892 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
65893 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
65894 if (fd >= 0) {
65895 sys_ioctl(fd, FDEJECT, 0);
65896 sys_close(fd);
65897 }
65898 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
65899 - fd = sys_open("/dev/console", O_RDWR, 0);
65900 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
65901 if (fd >= 0) {
65902 sys_ioctl(fd, TCGETS, (long)&termios);
65903 termios.c_lflag &= ~ICANON;
65904 sys_ioctl(fd, TCSETSF, (long)&termios);
65905 - sys_read(fd, &c, 1);
65906 + sys_read(fd, (char __user *)&c, 1);
65907 termios.c_lflag |= ICANON;
65908 sys_ioctl(fd, TCSETSF, (long)&termios);
65909 sys_close(fd);
65910 @@ -565,6 +565,6 @@ void __init prepare_namespace(void)
65911 mount_root();
65912 out:
65913 devtmpfs_mount("dev");
65914 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65915 - sys_chroot(".");
65916 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65917 + sys_chroot((const char __force_user *)".");
65918 }
65919 diff --git a/init/do_mounts.h b/init/do_mounts.h
65920 index f5b978a..69dbfe8 100644
65921 --- a/init/do_mounts.h
65922 +++ b/init/do_mounts.h
65923 @@ -15,15 +15,15 @@ extern int root_mountflags;
65924
65925 static inline int create_dev(char *name, dev_t dev)
65926 {
65927 - sys_unlink(name);
65928 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
65929 + sys_unlink((char __force_user *)name);
65930 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
65931 }
65932
65933 #if BITS_PER_LONG == 32
65934 static inline u32 bstat(char *name)
65935 {
65936 struct stat64 stat;
65937 - if (sys_stat64(name, &stat) != 0)
65938 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
65939 return 0;
65940 if (!S_ISBLK(stat.st_mode))
65941 return 0;
65942 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
65943 static inline u32 bstat(char *name)
65944 {
65945 struct stat stat;
65946 - if (sys_newstat(name, &stat) != 0)
65947 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
65948 return 0;
65949 if (!S_ISBLK(stat.st_mode))
65950 return 0;
65951 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
65952 index 135959a2..28a3f43 100644
65953 --- a/init/do_mounts_initrd.c
65954 +++ b/init/do_mounts_initrd.c
65955 @@ -53,13 +53,13 @@ static void __init handle_initrd(void)
65956 create_dev("/dev/root.old", Root_RAM0);
65957 /* mount initrd on rootfs' /root */
65958 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
65959 - sys_mkdir("/old", 0700);
65960 - root_fd = sys_open("/", 0, 0);
65961 - old_fd = sys_open("/old", 0, 0);
65962 + sys_mkdir((const char __force_user *)"/old", 0700);
65963 + root_fd = sys_open((const char __force_user *)"/", 0, 0);
65964 + old_fd = sys_open((const char __force_user *)"/old", 0, 0);
65965 /* move initrd over / and chdir/chroot in initrd root */
65966 - sys_chdir("/root");
65967 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
65968 - sys_chroot(".");
65969 + sys_chdir((const char __force_user *)"/root");
65970 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
65971 + sys_chroot((const char __force_user *)".");
65972
65973 /*
65974 * In case that a resume from disk is carried out by linuxrc or one of
65975 @@ -76,15 +76,15 @@ static void __init handle_initrd(void)
65976
65977 /* move initrd to rootfs' /old */
65978 sys_fchdir(old_fd);
65979 - sys_mount("/", ".", NULL, MS_MOVE, NULL);
65980 + sys_mount((char __force_user *)"/", (char __force_user *)".", NULL, MS_MOVE, NULL);
65981 /* switch root and cwd back to / of rootfs */
65982 sys_fchdir(root_fd);
65983 - sys_chroot(".");
65984 + sys_chroot((const char __force_user *)".");
65985 sys_close(old_fd);
65986 sys_close(root_fd);
65987
65988 if (new_decode_dev(real_root_dev) == Root_RAM0) {
65989 - sys_chdir("/old");
65990 + sys_chdir((const char __force_user *)"/old");
65991 return;
65992 }
65993
65994 @@ -92,17 +92,17 @@ static void __init handle_initrd(void)
65995 mount_root();
65996
65997 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
65998 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
65999 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
66000 if (!error)
66001 printk("okay\n");
66002 else {
66003 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
66004 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
66005 if (error == -ENOENT)
66006 printk("/initrd does not exist. Ignored.\n");
66007 else
66008 printk("failed\n");
66009 printk(KERN_NOTICE "Unmounting old root\n");
66010 - sys_umount("/old", MNT_DETACH);
66011 + sys_umount((char __force_user *)"/old", MNT_DETACH);
66012 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
66013 if (fd < 0) {
66014 error = fd;
66015 @@ -125,11 +125,11 @@ int __init initrd_load(void)
66016 * mounted in the normal path.
66017 */
66018 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
66019 - sys_unlink("/initrd.image");
66020 + sys_unlink((const char __force_user *)"/initrd.image");
66021 handle_initrd();
66022 return 1;
66023 }
66024 }
66025 - sys_unlink("/initrd.image");
66026 + sys_unlink((const char __force_user *)"/initrd.image");
66027 return 0;
66028 }
66029 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
66030 index 8cb6db5..d729f50 100644
66031 --- a/init/do_mounts_md.c
66032 +++ b/init/do_mounts_md.c
66033 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
66034 partitioned ? "_d" : "", minor,
66035 md_setup_args[ent].device_names);
66036
66037 - fd = sys_open(name, 0, 0);
66038 + fd = sys_open((char __force_user *)name, 0, 0);
66039 if (fd < 0) {
66040 printk(KERN_ERR "md: open failed - cannot start "
66041 "array %s\n", name);
66042 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
66043 * array without it
66044 */
66045 sys_close(fd);
66046 - fd = sys_open(name, 0, 0);
66047 + fd = sys_open((char __force_user *)name, 0, 0);
66048 sys_ioctl(fd, BLKRRPART, 0);
66049 }
66050 sys_close(fd);
66051 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
66052
66053 wait_for_device_probe();
66054
66055 - fd = sys_open("/dev/md0", 0, 0);
66056 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
66057 if (fd >= 0) {
66058 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
66059 sys_close(fd);
66060 diff --git a/init/init_task.c b/init/init_task.c
66061 index 8b2f399..f0797c9 100644
66062 --- a/init/init_task.c
66063 +++ b/init/init_task.c
66064 @@ -20,5 +20,9 @@ EXPORT_SYMBOL(init_task);
66065 * Initial thread structure. Alignment of this is handled by a special
66066 * linker map entry.
66067 */
66068 +#ifdef CONFIG_X86
66069 +union thread_union init_thread_union __init_task_data;
66070 +#else
66071 union thread_union init_thread_union __init_task_data =
66072 { INIT_THREAD_INFO(init_task) };
66073 +#endif
66074 diff --git a/init/initramfs.c b/init/initramfs.c
66075 index 84c6bf1..8899338 100644
66076 --- a/init/initramfs.c
66077 +++ b/init/initramfs.c
66078 @@ -84,7 +84,7 @@ static void __init free_hash(void)
66079 }
66080 }
66081
66082 -static long __init do_utime(char *filename, time_t mtime)
66083 +static long __init do_utime(char __force_user *filename, time_t mtime)
66084 {
66085 struct timespec t[2];
66086
66087 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
66088 struct dir_entry *de, *tmp;
66089 list_for_each_entry_safe(de, tmp, &dir_list, list) {
66090 list_del(&de->list);
66091 - do_utime(de->name, de->mtime);
66092 + do_utime((char __force_user *)de->name, de->mtime);
66093 kfree(de->name);
66094 kfree(de);
66095 }
66096 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
66097 if (nlink >= 2) {
66098 char *old = find_link(major, minor, ino, mode, collected);
66099 if (old)
66100 - return (sys_link(old, collected) < 0) ? -1 : 1;
66101 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
66102 }
66103 return 0;
66104 }
66105 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
66106 {
66107 struct stat st;
66108
66109 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
66110 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
66111 if (S_ISDIR(st.st_mode))
66112 - sys_rmdir(path);
66113 + sys_rmdir((char __force_user *)path);
66114 else
66115 - sys_unlink(path);
66116 + sys_unlink((char __force_user *)path);
66117 }
66118 }
66119
66120 @@ -315,7 +315,7 @@ static int __init do_name(void)
66121 int openflags = O_WRONLY|O_CREAT;
66122 if (ml != 1)
66123 openflags |= O_TRUNC;
66124 - wfd = sys_open(collected, openflags, mode);
66125 + wfd = sys_open((char __force_user *)collected, openflags, mode);
66126
66127 if (wfd >= 0) {
66128 sys_fchown(wfd, uid, gid);
66129 @@ -327,17 +327,17 @@ static int __init do_name(void)
66130 }
66131 }
66132 } else if (S_ISDIR(mode)) {
66133 - sys_mkdir(collected, mode);
66134 - sys_chown(collected, uid, gid);
66135 - sys_chmod(collected, mode);
66136 + sys_mkdir((char __force_user *)collected, mode);
66137 + sys_chown((char __force_user *)collected, uid, gid);
66138 + sys_chmod((char __force_user *)collected, mode);
66139 dir_add(collected, mtime);
66140 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
66141 S_ISFIFO(mode) || S_ISSOCK(mode)) {
66142 if (maybe_link() == 0) {
66143 - sys_mknod(collected, mode, rdev);
66144 - sys_chown(collected, uid, gid);
66145 - sys_chmod(collected, mode);
66146 - do_utime(collected, mtime);
66147 + sys_mknod((char __force_user *)collected, mode, rdev);
66148 + sys_chown((char __force_user *)collected, uid, gid);
66149 + sys_chmod((char __force_user *)collected, mode);
66150 + do_utime((char __force_user *)collected, mtime);
66151 }
66152 }
66153 return 0;
66154 @@ -346,15 +346,15 @@ static int __init do_name(void)
66155 static int __init do_copy(void)
66156 {
66157 if (count >= body_len) {
66158 - sys_write(wfd, victim, body_len);
66159 + sys_write(wfd, (char __force_user *)victim, body_len);
66160 sys_close(wfd);
66161 - do_utime(vcollected, mtime);
66162 + do_utime((char __force_user *)vcollected, mtime);
66163 kfree(vcollected);
66164 eat(body_len);
66165 state = SkipIt;
66166 return 0;
66167 } else {
66168 - sys_write(wfd, victim, count);
66169 + sys_write(wfd, (char __force_user *)victim, count);
66170 body_len -= count;
66171 eat(count);
66172 return 1;
66173 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
66174 {
66175 collected[N_ALIGN(name_len) + body_len] = '\0';
66176 clean_path(collected, 0);
66177 - sys_symlink(collected + N_ALIGN(name_len), collected);
66178 - sys_lchown(collected, uid, gid);
66179 - do_utime(collected, mtime);
66180 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
66181 + sys_lchown((char __force_user *)collected, uid, gid);
66182 + do_utime((char __force_user *)collected, mtime);
66183 state = SkipIt;
66184 next_state = Reset;
66185 return 0;
66186 diff --git a/init/main.c b/init/main.c
66187 index b5cc0a7..9eeb061 100644
66188 --- a/init/main.c
66189 +++ b/init/main.c
66190 @@ -95,6 +95,8 @@ static inline void mark_rodata_ro(void) { }
66191 extern void tc_init(void);
66192 #endif
66193
66194 +extern void grsecurity_init(void);
66195 +
66196 /*
66197 * Debug helper: via this flag we know that we are in 'early bootup code'
66198 * where only the boot processor is running with IRQ disabled. This means
66199 @@ -148,6 +150,60 @@ static int __init set_reset_devices(char *str)
66200
66201 __setup("reset_devices", set_reset_devices);
66202
66203 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
66204 +int grsec_proc_gid = CONFIG_GRKERNSEC_PROC_GID;
66205 +static int __init setup_grsec_proc_gid(char *str)
66206 +{
66207 + get_option(&str, &grsec_proc_gid);
66208 +}
66209 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
66210 +#endif
66211 +
66212 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
66213 +extern char pax_enter_kernel_user[];
66214 +extern char pax_exit_kernel_user[];
66215 +extern pgdval_t clone_pgd_mask;
66216 +#endif
66217 +
66218 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
66219 +static int __init setup_pax_nouderef(char *str)
66220 +{
66221 +#ifdef CONFIG_X86_32
66222 + unsigned int cpu;
66223 + struct desc_struct *gdt;
66224 +
66225 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
66226 + gdt = get_cpu_gdt_table(cpu);
66227 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
66228 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
66229 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
66230 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
66231 + }
66232 + loadsegment(ds, __KERNEL_DS);
66233 + loadsegment(es, __KERNEL_DS);
66234 + loadsegment(ss, __KERNEL_DS);
66235 +#else
66236 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
66237 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
66238 + clone_pgd_mask = ~(pgdval_t)0UL;
66239 +#endif
66240 +
66241 + return 0;
66242 +}
66243 +early_param("pax_nouderef", setup_pax_nouderef);
66244 +#endif
66245 +
66246 +#ifdef CONFIG_PAX_SOFTMODE
66247 +int pax_softmode;
66248 +
66249 +static int __init setup_pax_softmode(char *str)
66250 +{
66251 + get_option(&str, &pax_softmode);
66252 + return 1;
66253 +}
66254 +__setup("pax_softmode=", setup_pax_softmode);
66255 +#endif
66256 +
66257 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
66258 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
66259 static const char *panic_later, *panic_param;
66260 @@ -674,6 +730,7 @@ int __init_or_module do_one_initcall(initcall_t fn)
66261 {
66262 int count = preempt_count();
66263 int ret;
66264 + const char *msg1 = "", *msg2 = "";
66265
66266 if (initcall_debug)
66267 ret = do_one_initcall_debug(fn);
66268 @@ -686,15 +743,15 @@ int __init_or_module do_one_initcall(initcall_t fn)
66269 sprintf(msgbuf, "error code %d ", ret);
66270
66271 if (preempt_count() != count) {
66272 - strlcat(msgbuf, "preemption imbalance ", sizeof(msgbuf));
66273 + msg1 = " preemption imbalance";
66274 preempt_count() = count;
66275 }
66276 if (irqs_disabled()) {
66277 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
66278 + msg2 = " disabled interrupts";
66279 local_irq_enable();
66280 }
66281 - if (msgbuf[0]) {
66282 - printk("initcall %pF returned with %s\n", fn, msgbuf);
66283 + if (msgbuf[0] || *msg1 || *msg2) {
66284 + printk("initcall %pF returned with %s%s%s\n", fn, msgbuf, msg1, msg2);
66285 }
66286
66287 return ret;
66288 @@ -747,8 +804,14 @@ static void __init do_initcall_level(int level)
66289 level, level,
66290 &repair_env_string);
66291
66292 - for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++)
66293 + for (fn = initcall_levels[level]; fn < initcall_levels[level+1]; fn++) {
66294 do_one_initcall(*fn);
66295 +
66296 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66297 + transfer_latent_entropy();
66298 +#endif
66299 +
66300 + }
66301 }
66302
66303 static void __init do_initcalls(void)
66304 @@ -782,8 +845,14 @@ static void __init do_pre_smp_initcalls(void)
66305 {
66306 initcall_t *fn;
66307
66308 - for (fn = __initcall_start; fn < __initcall0_start; fn++)
66309 + for (fn = __initcall_start; fn < __initcall0_start; fn++) {
66310 do_one_initcall(*fn);
66311 +
66312 +#ifdef CONFIG_PAX_LATENT_ENTROPY
66313 + transfer_latent_entropy();
66314 +#endif
66315 +
66316 + }
66317 }
66318
66319 static void run_init_process(const char *init_filename)
66320 @@ -865,7 +934,7 @@ static int __init kernel_init(void * unused)
66321 do_basic_setup();
66322
66323 /* Open the /dev/console on the rootfs, this should never fail */
66324 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
66325 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
66326 printk(KERN_WARNING "Warning: unable to open an initial console.\n");
66327
66328 (void) sys_dup(0);
66329 @@ -878,11 +947,13 @@ static int __init kernel_init(void * unused)
66330 if (!ramdisk_execute_command)
66331 ramdisk_execute_command = "/init";
66332
66333 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
66334 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
66335 ramdisk_execute_command = NULL;
66336 prepare_namespace();
66337 }
66338
66339 + grsecurity_init();
66340 +
66341 /*
66342 * Ok, we have completed the initial bootup, and
66343 * we're essentially up and running. Get rid of the
66344 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
66345 index 8ce5769..4666884 100644
66346 --- a/ipc/mqueue.c
66347 +++ b/ipc/mqueue.c
66348 @@ -279,6 +279,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
66349 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
66350 info->attr.mq_msgsize);
66351
66352 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
66353 spin_lock(&mq_lock);
66354 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
66355 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
66356 diff --git a/ipc/msg.c b/ipc/msg.c
66357 index 7385de2..a8180e08 100644
66358 --- a/ipc/msg.c
66359 +++ b/ipc/msg.c
66360 @@ -309,18 +309,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
66361 return security_msg_queue_associate(msq, msgflg);
66362 }
66363
66364 +static struct ipc_ops msg_ops = {
66365 + .getnew = newque,
66366 + .associate = msg_security,
66367 + .more_checks = NULL
66368 +};
66369 +
66370 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
66371 {
66372 struct ipc_namespace *ns;
66373 - struct ipc_ops msg_ops;
66374 struct ipc_params msg_params;
66375
66376 ns = current->nsproxy->ipc_ns;
66377
66378 - msg_ops.getnew = newque;
66379 - msg_ops.associate = msg_security;
66380 - msg_ops.more_checks = NULL;
66381 -
66382 msg_params.key = key;
66383 msg_params.flg = msgflg;
66384
66385 diff --git a/ipc/sem.c b/ipc/sem.c
66386 index 5215a81..cfc0cac 100644
66387 --- a/ipc/sem.c
66388 +++ b/ipc/sem.c
66389 @@ -364,10 +364,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
66390 return 0;
66391 }
66392
66393 +static struct ipc_ops sem_ops = {
66394 + .getnew = newary,
66395 + .associate = sem_security,
66396 + .more_checks = sem_more_checks
66397 +};
66398 +
66399 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66400 {
66401 struct ipc_namespace *ns;
66402 - struct ipc_ops sem_ops;
66403 struct ipc_params sem_params;
66404
66405 ns = current->nsproxy->ipc_ns;
66406 @@ -375,10 +380,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
66407 if (nsems < 0 || nsems > ns->sc_semmsl)
66408 return -EINVAL;
66409
66410 - sem_ops.getnew = newary;
66411 - sem_ops.associate = sem_security;
66412 - sem_ops.more_checks = sem_more_checks;
66413 -
66414 sem_params.key = key;
66415 sem_params.flg = semflg;
66416 sem_params.u.nsems = nsems;
66417 diff --git a/ipc/shm.c b/ipc/shm.c
66418 index 41c1285..cf6404c 100644
66419 --- a/ipc/shm.c
66420 +++ b/ipc/shm.c
66421 @@ -69,6 +69,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
66422 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
66423 #endif
66424
66425 +#ifdef CONFIG_GRKERNSEC
66426 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66427 + const time_t shm_createtime, const uid_t cuid,
66428 + const int shmid);
66429 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
66430 + const time_t shm_createtime);
66431 +#endif
66432 +
66433 void shm_init_ns(struct ipc_namespace *ns)
66434 {
66435 ns->shm_ctlmax = SHMMAX;
66436 @@ -520,6 +528,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
66437 shp->shm_lprid = 0;
66438 shp->shm_atim = shp->shm_dtim = 0;
66439 shp->shm_ctim = get_seconds();
66440 +#ifdef CONFIG_GRKERNSEC
66441 + {
66442 + struct timespec timeval;
66443 + do_posix_clock_monotonic_gettime(&timeval);
66444 +
66445 + shp->shm_createtime = timeval.tv_sec;
66446 + }
66447 +#endif
66448 shp->shm_segsz = size;
66449 shp->shm_nattch = 0;
66450 shp->shm_file = file;
66451 @@ -571,18 +587,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
66452 return 0;
66453 }
66454
66455 +static struct ipc_ops shm_ops = {
66456 + .getnew = newseg,
66457 + .associate = shm_security,
66458 + .more_checks = shm_more_checks
66459 +};
66460 +
66461 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
66462 {
66463 struct ipc_namespace *ns;
66464 - struct ipc_ops shm_ops;
66465 struct ipc_params shm_params;
66466
66467 ns = current->nsproxy->ipc_ns;
66468
66469 - shm_ops.getnew = newseg;
66470 - shm_ops.associate = shm_security;
66471 - shm_ops.more_checks = shm_more_checks;
66472 -
66473 shm_params.key = key;
66474 shm_params.flg = shmflg;
66475 shm_params.u.size = size;
66476 @@ -1000,6 +1017,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
66477 f_mode = FMODE_READ | FMODE_WRITE;
66478 }
66479 if (shmflg & SHM_EXEC) {
66480 +
66481 +#ifdef CONFIG_PAX_MPROTECT
66482 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
66483 + goto out;
66484 +#endif
66485 +
66486 prot |= PROT_EXEC;
66487 acc_mode |= S_IXUGO;
66488 }
66489 @@ -1023,9 +1046,21 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr)
66490 if (err)
66491 goto out_unlock;
66492
66493 +#ifdef CONFIG_GRKERNSEC
66494 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
66495 + shp->shm_perm.cuid, shmid) ||
66496 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
66497 + err = -EACCES;
66498 + goto out_unlock;
66499 + }
66500 +#endif
66501 +
66502 path = shp->shm_file->f_path;
66503 path_get(&path);
66504 shp->shm_nattch++;
66505 +#ifdef CONFIG_GRKERNSEC
66506 + shp->shm_lapid = current->pid;
66507 +#endif
66508 size = i_size_read(path.dentry->d_inode);
66509 shm_unlock(shp);
66510
66511 diff --git a/kernel/acct.c b/kernel/acct.c
66512 index 02e6167..54824f7 100644
66513 --- a/kernel/acct.c
66514 +++ b/kernel/acct.c
66515 @@ -550,7 +550,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
66516 */
66517 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
66518 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
66519 - file->f_op->write(file, (char *)&ac,
66520 + file->f_op->write(file, (char __force_user *)&ac,
66521 sizeof(acct_t), &file->f_pos);
66522 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
66523 set_fs(fs);
66524 diff --git a/kernel/audit.c b/kernel/audit.c
66525 index 1c7f2c6..9ba5359 100644
66526 --- a/kernel/audit.c
66527 +++ b/kernel/audit.c
66528 @@ -115,7 +115,7 @@ u32 audit_sig_sid = 0;
66529 3) suppressed due to audit_rate_limit
66530 4) suppressed due to audit_backlog_limit
66531 */
66532 -static atomic_t audit_lost = ATOMIC_INIT(0);
66533 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
66534
66535 /* The netlink socket. */
66536 static struct sock *audit_sock;
66537 @@ -237,7 +237,7 @@ void audit_log_lost(const char *message)
66538 unsigned long now;
66539 int print;
66540
66541 - atomic_inc(&audit_lost);
66542 + atomic_inc_unchecked(&audit_lost);
66543
66544 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
66545
66546 @@ -256,7 +256,7 @@ void audit_log_lost(const char *message)
66547 printk(KERN_WARNING
66548 "audit: audit_lost=%d audit_rate_limit=%d "
66549 "audit_backlog_limit=%d\n",
66550 - atomic_read(&audit_lost),
66551 + atomic_read_unchecked(&audit_lost),
66552 audit_rate_limit,
66553 audit_backlog_limit);
66554 audit_panic(message);
66555 @@ -689,7 +689,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
66556 status_set.pid = audit_pid;
66557 status_set.rate_limit = audit_rate_limit;
66558 status_set.backlog_limit = audit_backlog_limit;
66559 - status_set.lost = atomic_read(&audit_lost);
66560 + status_set.lost = atomic_read_unchecked(&audit_lost);
66561 status_set.backlog = skb_queue_len(&audit_skb_queue);
66562 audit_send_reply(NETLINK_CB(skb).pid, seq, AUDIT_GET, 0, 0,
66563 &status_set, sizeof(status_set));
66564 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
66565 index 4b96415..d8c16ee 100644
66566 --- a/kernel/auditsc.c
66567 +++ b/kernel/auditsc.c
66568 @@ -2289,7 +2289,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
66569 }
66570
66571 /* global counter which is incremented every time something logs in */
66572 -static atomic_t session_id = ATOMIC_INIT(0);
66573 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
66574
66575 /**
66576 * audit_set_loginuid - set current task's audit_context loginuid
66577 @@ -2313,7 +2313,7 @@ int audit_set_loginuid(uid_t loginuid)
66578 return -EPERM;
66579 #endif /* CONFIG_AUDIT_LOGINUID_IMMUTABLE */
66580
66581 - sessionid = atomic_inc_return(&session_id);
66582 + sessionid = atomic_inc_return_unchecked(&session_id);
66583 if (context && context->in_syscall) {
66584 struct audit_buffer *ab;
66585
66586 diff --git a/kernel/capability.c b/kernel/capability.c
66587 index 493d972..ea17248 100644
66588 --- a/kernel/capability.c
66589 +++ b/kernel/capability.c
66590 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
66591 * before modification is attempted and the application
66592 * fails.
66593 */
66594 + if (tocopy > ARRAY_SIZE(kdata))
66595 + return -EFAULT;
66596 +
66597 if (copy_to_user(dataptr, kdata, tocopy
66598 * sizeof(struct __user_cap_data_struct))) {
66599 return -EFAULT;
66600 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
66601 int ret;
66602
66603 rcu_read_lock();
66604 - ret = security_capable(__task_cred(t), ns, cap);
66605 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
66606 + gr_task_is_capable(t, __task_cred(t), cap);
66607 rcu_read_unlock();
66608
66609 - return (ret == 0);
66610 + return ret;
66611 }
66612
66613 /**
66614 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
66615 int ret;
66616
66617 rcu_read_lock();
66618 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
66619 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
66620 rcu_read_unlock();
66621
66622 - return (ret == 0);
66623 + return ret;
66624 }
66625
66626 /**
66627 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
66628 BUG();
66629 }
66630
66631 - if (security_capable(current_cred(), ns, cap) == 0) {
66632 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
66633 current->flags |= PF_SUPERPRIV;
66634 return true;
66635 }
66636 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
66637 }
66638 EXPORT_SYMBOL(ns_capable);
66639
66640 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
66641 +{
66642 + if (unlikely(!cap_valid(cap))) {
66643 + printk(KERN_CRIT "capable() called with invalid cap=%u\n", cap);
66644 + BUG();
66645 + }
66646 +
66647 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
66648 + current->flags |= PF_SUPERPRIV;
66649 + return true;
66650 + }
66651 + return false;
66652 +}
66653 +EXPORT_SYMBOL(ns_capable_nolog);
66654 +
66655 /**
66656 * capable - Determine if the current task has a superior capability in effect
66657 * @cap: The capability to be tested for
66658 @@ -408,6 +427,12 @@ bool capable(int cap)
66659 }
66660 EXPORT_SYMBOL(capable);
66661
66662 +bool capable_nolog(int cap)
66663 +{
66664 + return ns_capable_nolog(&init_user_ns, cap);
66665 +}
66666 +EXPORT_SYMBOL(capable_nolog);
66667 +
66668 /**
66669 * nsown_capable - Check superior capability to one's own user_ns
66670 * @cap: The capability in question
66671 @@ -440,3 +465,10 @@ bool inode_capable(const struct inode *inode, int cap)
66672
66673 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66674 }
66675 +
66676 +bool inode_capable_nolog(const struct inode *inode, int cap)
66677 +{
66678 + struct user_namespace *ns = current_user_ns();
66679 +
66680 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
66681 +}
66682 diff --git a/kernel/compat.c b/kernel/compat.c
66683 index c28a306..b4d0cf3 100644
66684 --- a/kernel/compat.c
66685 +++ b/kernel/compat.c
66686 @@ -13,6 +13,7 @@
66687
66688 #include <linux/linkage.h>
66689 #include <linux/compat.h>
66690 +#include <linux/module.h>
66691 #include <linux/errno.h>
66692 #include <linux/time.h>
66693 #include <linux/signal.h>
66694 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
66695 mm_segment_t oldfs;
66696 long ret;
66697
66698 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
66699 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
66700 oldfs = get_fs();
66701 set_fs(KERNEL_DS);
66702 ret = hrtimer_nanosleep_restart(restart);
66703 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
66704 oldfs = get_fs();
66705 set_fs(KERNEL_DS);
66706 ret = hrtimer_nanosleep(&tu,
66707 - rmtp ? (struct timespec __user *)&rmt : NULL,
66708 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
66709 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
66710 set_fs(oldfs);
66711
66712 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
66713 mm_segment_t old_fs = get_fs();
66714
66715 set_fs(KERNEL_DS);
66716 - ret = sys_sigpending((old_sigset_t __user *) &s);
66717 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
66718 set_fs(old_fs);
66719 if (ret == 0)
66720 ret = put_user(s, set);
66721 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
66722 mm_segment_t old_fs = get_fs();
66723
66724 set_fs(KERNEL_DS);
66725 - ret = sys_old_getrlimit(resource, &r);
66726 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
66727 set_fs(old_fs);
66728
66729 if (!ret) {
66730 @@ -523,7 +524,7 @@ asmlinkage long compat_sys_getrusage(int who, struct compat_rusage __user *ru)
66731 mm_segment_t old_fs = get_fs();
66732
66733 set_fs(KERNEL_DS);
66734 - ret = sys_getrusage(who, (struct rusage __user *) &r);
66735 + ret = sys_getrusage(who, (struct rusage __force_user *) &r);
66736 set_fs(old_fs);
66737
66738 if (ret)
66739 @@ -550,8 +551,8 @@ compat_sys_wait4(compat_pid_t pid, compat_uint_t __user *stat_addr, int options,
66740 set_fs (KERNEL_DS);
66741 ret = sys_wait4(pid,
66742 (stat_addr ?
66743 - (unsigned int __user *) &status : NULL),
66744 - options, (struct rusage __user *) &r);
66745 + (unsigned int __force_user *) &status : NULL),
66746 + options, (struct rusage __force_user *) &r);
66747 set_fs (old_fs);
66748
66749 if (ret > 0) {
66750 @@ -576,8 +577,8 @@ asmlinkage long compat_sys_waitid(int which, compat_pid_t pid,
66751 memset(&info, 0, sizeof(info));
66752
66753 set_fs(KERNEL_DS);
66754 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
66755 - uru ? (struct rusage __user *)&ru : NULL);
66756 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
66757 + uru ? (struct rusage __force_user *)&ru : NULL);
66758 set_fs(old_fs);
66759
66760 if ((ret < 0) || (info.si_signo == 0))
66761 @@ -707,8 +708,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
66762 oldfs = get_fs();
66763 set_fs(KERNEL_DS);
66764 err = sys_timer_settime(timer_id, flags,
66765 - (struct itimerspec __user *) &newts,
66766 - (struct itimerspec __user *) &oldts);
66767 + (struct itimerspec __force_user *) &newts,
66768 + (struct itimerspec __force_user *) &oldts);
66769 set_fs(oldfs);
66770 if (!err && old && put_compat_itimerspec(old, &oldts))
66771 return -EFAULT;
66772 @@ -725,7 +726,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
66773 oldfs = get_fs();
66774 set_fs(KERNEL_DS);
66775 err = sys_timer_gettime(timer_id,
66776 - (struct itimerspec __user *) &ts);
66777 + (struct itimerspec __force_user *) &ts);
66778 set_fs(oldfs);
66779 if (!err && put_compat_itimerspec(setting, &ts))
66780 return -EFAULT;
66781 @@ -744,7 +745,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
66782 oldfs = get_fs();
66783 set_fs(KERNEL_DS);
66784 err = sys_clock_settime(which_clock,
66785 - (struct timespec __user *) &ts);
66786 + (struct timespec __force_user *) &ts);
66787 set_fs(oldfs);
66788 return err;
66789 }
66790 @@ -759,7 +760,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
66791 oldfs = get_fs();
66792 set_fs(KERNEL_DS);
66793 err = sys_clock_gettime(which_clock,
66794 - (struct timespec __user *) &ts);
66795 + (struct timespec __force_user *) &ts);
66796 set_fs(oldfs);
66797 if (!err && put_compat_timespec(&ts, tp))
66798 return -EFAULT;
66799 @@ -779,7 +780,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
66800
66801 oldfs = get_fs();
66802 set_fs(KERNEL_DS);
66803 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
66804 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
66805 set_fs(oldfs);
66806
66807 err = compat_put_timex(utp, &txc);
66808 @@ -799,7 +800,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
66809 oldfs = get_fs();
66810 set_fs(KERNEL_DS);
66811 err = sys_clock_getres(which_clock,
66812 - (struct timespec __user *) &ts);
66813 + (struct timespec __force_user *) &ts);
66814 set_fs(oldfs);
66815 if (!err && tp && put_compat_timespec(&ts, tp))
66816 return -EFAULT;
66817 @@ -811,9 +812,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
66818 long err;
66819 mm_segment_t oldfs;
66820 struct timespec tu;
66821 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
66822 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
66823
66824 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
66825 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
66826 oldfs = get_fs();
66827 set_fs(KERNEL_DS);
66828 err = clock_nanosleep_restart(restart);
66829 @@ -845,8 +846,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
66830 oldfs = get_fs();
66831 set_fs(KERNEL_DS);
66832 err = sys_clock_nanosleep(which_clock, flags,
66833 - (struct timespec __user *) &in,
66834 - (struct timespec __user *) &out);
66835 + (struct timespec __force_user *) &in,
66836 + (struct timespec __force_user *) &out);
66837 set_fs(oldfs);
66838
66839 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
66840 diff --git a/kernel/configs.c b/kernel/configs.c
66841 index 42e8fa0..9e7406b 100644
66842 --- a/kernel/configs.c
66843 +++ b/kernel/configs.c
66844 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
66845 struct proc_dir_entry *entry;
66846
66847 /* create the current config file */
66848 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
66849 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
66850 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
66851 + &ikconfig_file_ops);
66852 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
66853 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
66854 + &ikconfig_file_ops);
66855 +#endif
66856 +#else
66857 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
66858 &ikconfig_file_ops);
66859 +#endif
66860 +
66861 if (!entry)
66862 return -ENOMEM;
66863
66864 diff --git a/kernel/cred.c b/kernel/cred.c
66865 index de728ac..e3c267c 100644
66866 --- a/kernel/cred.c
66867 +++ b/kernel/cred.c
66868 @@ -207,6 +207,16 @@ void exit_creds(struct task_struct *tsk)
66869 validate_creds(cred);
66870 alter_cred_subscribers(cred, -1);
66871 put_cred(cred);
66872 +
66873 +#ifdef CONFIG_GRKERNSEC_SETXID
66874 + cred = (struct cred *) tsk->delayed_cred;
66875 + if (cred != NULL) {
66876 + tsk->delayed_cred = NULL;
66877 + validate_creds(cred);
66878 + alter_cred_subscribers(cred, -1);
66879 + put_cred(cred);
66880 + }
66881 +#endif
66882 }
66883
66884 /**
66885 @@ -469,7 +479,7 @@ error_put:
66886 * Always returns 0 thus allowing this function to be tail-called at the end
66887 * of, say, sys_setgid().
66888 */
66889 -int commit_creds(struct cred *new)
66890 +static int __commit_creds(struct cred *new)
66891 {
66892 struct task_struct *task = current;
66893 const struct cred *old = task->real_cred;
66894 @@ -488,6 +498,8 @@ int commit_creds(struct cred *new)
66895
66896 get_cred(new); /* we will require a ref for the subj creds too */
66897
66898 + gr_set_role_label(task, new->uid, new->gid);
66899 +
66900 /* dumpability changes */
66901 if (!uid_eq(old->euid, new->euid) ||
66902 !gid_eq(old->egid, new->egid) ||
66903 @@ -537,6 +549,101 @@ int commit_creds(struct cred *new)
66904 put_cred(old);
66905 return 0;
66906 }
66907 +#ifdef CONFIG_GRKERNSEC_SETXID
66908 +extern int set_user(struct cred *new);
66909 +
66910 +void gr_delayed_cred_worker(void)
66911 +{
66912 + const struct cred *new = current->delayed_cred;
66913 + struct cred *ncred;
66914 +
66915 + current->delayed_cred = NULL;
66916 +
66917 + if (current_uid() && new != NULL) {
66918 + // from doing get_cred on it when queueing this
66919 + put_cred(new);
66920 + return;
66921 + } else if (new == NULL)
66922 + return;
66923 +
66924 + ncred = prepare_creds();
66925 + if (!ncred)
66926 + goto die;
66927 + // uids
66928 + ncred->uid = new->uid;
66929 + ncred->euid = new->euid;
66930 + ncred->suid = new->suid;
66931 + ncred->fsuid = new->fsuid;
66932 + // gids
66933 + ncred->gid = new->gid;
66934 + ncred->egid = new->egid;
66935 + ncred->sgid = new->sgid;
66936 + ncred->fsgid = new->fsgid;
66937 + // groups
66938 + if (set_groups(ncred, new->group_info) < 0) {
66939 + abort_creds(ncred);
66940 + goto die;
66941 + }
66942 + // caps
66943 + ncred->securebits = new->securebits;
66944 + ncred->cap_inheritable = new->cap_inheritable;
66945 + ncred->cap_permitted = new->cap_permitted;
66946 + ncred->cap_effective = new->cap_effective;
66947 + ncred->cap_bset = new->cap_bset;
66948 +
66949 + if (set_user(ncred)) {
66950 + abort_creds(ncred);
66951 + goto die;
66952 + }
66953 +
66954 + // from doing get_cred on it when queueing this
66955 + put_cred(new);
66956 +
66957 + __commit_creds(ncred);
66958 + return;
66959 +die:
66960 + // from doing get_cred on it when queueing this
66961 + put_cred(new);
66962 + do_group_exit(SIGKILL);
66963 +}
66964 +#endif
66965 +
66966 +int commit_creds(struct cred *new)
66967 +{
66968 +#ifdef CONFIG_GRKERNSEC_SETXID
66969 + int ret;
66970 + int schedule_it = 0;
66971 + struct task_struct *t;
66972 +
66973 + /* we won't get called with tasklist_lock held for writing
66974 + and interrupts disabled as the cred struct in that case is
66975 + init_cred
66976 + */
66977 + if (grsec_enable_setxid && !current_is_single_threaded() &&
66978 + !current_uid() && new->uid) {
66979 + schedule_it = 1;
66980 + }
66981 + ret = __commit_creds(new);
66982 + if (schedule_it) {
66983 + rcu_read_lock();
66984 + read_lock(&tasklist_lock);
66985 + for (t = next_thread(current); t != current;
66986 + t = next_thread(t)) {
66987 + if (t->delayed_cred == NULL) {
66988 + t->delayed_cred = get_cred(new);
66989 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
66990 + set_tsk_need_resched(t);
66991 + }
66992 + }
66993 + read_unlock(&tasklist_lock);
66994 + rcu_read_unlock();
66995 + }
66996 + return ret;
66997 +#else
66998 + return __commit_creds(new);
66999 +#endif
67000 +}
67001 +
67002 EXPORT_SYMBOL(commit_creds);
67003
67004 /**
67005 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
67006 index 0557f24..1a00d9a 100644
67007 --- a/kernel/debug/debug_core.c
67008 +++ b/kernel/debug/debug_core.c
67009 @@ -122,7 +122,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
67010 */
67011 static atomic_t masters_in_kgdb;
67012 static atomic_t slaves_in_kgdb;
67013 -static atomic_t kgdb_break_tasklet_var;
67014 +static atomic_unchecked_t kgdb_break_tasklet_var;
67015 atomic_t kgdb_setting_breakpoint;
67016
67017 struct task_struct *kgdb_usethread;
67018 @@ -132,7 +132,7 @@ int kgdb_single_step;
67019 static pid_t kgdb_sstep_pid;
67020
67021 /* to keep track of the CPU which is doing the single stepping*/
67022 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67023 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
67024
67025 /*
67026 * If you are debugging a problem where roundup (the collection of
67027 @@ -540,7 +540,7 @@ return_normal:
67028 * kernel will only try for the value of sstep_tries before
67029 * giving up and continuing on.
67030 */
67031 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
67032 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
67033 (kgdb_info[cpu].task &&
67034 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
67035 atomic_set(&kgdb_active, -1);
67036 @@ -634,8 +634,8 @@ cpu_master_loop:
67037 }
67038
67039 kgdb_restore:
67040 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
67041 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
67042 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
67043 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
67044 if (kgdb_info[sstep_cpu].task)
67045 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
67046 else
67047 @@ -861,18 +861,18 @@ static void kgdb_unregister_callbacks(void)
67048 static void kgdb_tasklet_bpt(unsigned long ing)
67049 {
67050 kgdb_breakpoint();
67051 - atomic_set(&kgdb_break_tasklet_var, 0);
67052 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
67053 }
67054
67055 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
67056
67057 void kgdb_schedule_breakpoint(void)
67058 {
67059 - if (atomic_read(&kgdb_break_tasklet_var) ||
67060 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
67061 atomic_read(&kgdb_active) != -1 ||
67062 atomic_read(&kgdb_setting_breakpoint))
67063 return;
67064 - atomic_inc(&kgdb_break_tasklet_var);
67065 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
67066 tasklet_schedule(&kgdb_tasklet_breakpoint);
67067 }
67068 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
67069 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
67070 index 1f91413..362a0a1 100644
67071 --- a/kernel/debug/kdb/kdb_main.c
67072 +++ b/kernel/debug/kdb/kdb_main.c
67073 @@ -1984,7 +1984,7 @@ static int kdb_lsmod(int argc, const char **argv)
67074 list_for_each_entry(mod, kdb_modules, list) {
67075
67076 kdb_printf("%-20s%8u 0x%p ", mod->name,
67077 - mod->core_size, (void *)mod);
67078 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
67079 #ifdef CONFIG_MODULE_UNLOAD
67080 kdb_printf("%4ld ", module_refcount(mod));
67081 #endif
67082 @@ -1994,7 +1994,7 @@ static int kdb_lsmod(int argc, const char **argv)
67083 kdb_printf(" (Loading)");
67084 else
67085 kdb_printf(" (Live)");
67086 - kdb_printf(" 0x%p", mod->module_core);
67087 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
67088
67089 #ifdef CONFIG_MODULE_UNLOAD
67090 {
67091 diff --git a/kernel/events/core.c b/kernel/events/core.c
67092 index 11409af..b6ec863 100644
67093 --- a/kernel/events/core.c
67094 +++ b/kernel/events/core.c
67095 @@ -181,7 +181,7 @@ int perf_proc_update_handler(struct ctl_table *table, int write,
67096 return 0;
67097 }
67098
67099 -static atomic64_t perf_event_id;
67100 +static atomic64_unchecked_t perf_event_id;
67101
67102 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
67103 enum event_type_t event_type);
67104 @@ -2663,7 +2663,7 @@ static void __perf_event_read(void *info)
67105
67106 static inline u64 perf_event_count(struct perf_event *event)
67107 {
67108 - return local64_read(&event->count) + atomic64_read(&event->child_count);
67109 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
67110 }
67111
67112 static u64 perf_event_read(struct perf_event *event)
67113 @@ -2993,9 +2993,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
67114 mutex_lock(&event->child_mutex);
67115 total += perf_event_read(event);
67116 *enabled += event->total_time_enabled +
67117 - atomic64_read(&event->child_total_time_enabled);
67118 + atomic64_read_unchecked(&event->child_total_time_enabled);
67119 *running += event->total_time_running +
67120 - atomic64_read(&event->child_total_time_running);
67121 + atomic64_read_unchecked(&event->child_total_time_running);
67122
67123 list_for_each_entry(child, &event->child_list, child_list) {
67124 total += perf_event_read(child);
67125 @@ -3404,10 +3404,10 @@ void perf_event_update_userpage(struct perf_event *event)
67126 userpg->offset -= local64_read(&event->hw.prev_count);
67127
67128 userpg->time_enabled = enabled +
67129 - atomic64_read(&event->child_total_time_enabled);
67130 + atomic64_read_unchecked(&event->child_total_time_enabled);
67131
67132 userpg->time_running = running +
67133 - atomic64_read(&event->child_total_time_running);
67134 + atomic64_read_unchecked(&event->child_total_time_running);
67135
67136 arch_perf_update_userpage(userpg, now);
67137
67138 @@ -3840,11 +3840,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
67139 values[n++] = perf_event_count(event);
67140 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
67141 values[n++] = enabled +
67142 - atomic64_read(&event->child_total_time_enabled);
67143 + atomic64_read_unchecked(&event->child_total_time_enabled);
67144 }
67145 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
67146 values[n++] = running +
67147 - atomic64_read(&event->child_total_time_running);
67148 + atomic64_read_unchecked(&event->child_total_time_running);
67149 }
67150 if (read_format & PERF_FORMAT_ID)
67151 values[n++] = primary_event_id(event);
67152 @@ -4522,12 +4522,12 @@ static void perf_event_mmap_event(struct perf_mmap_event *mmap_event)
67153 * need to add enough zero bytes after the string to handle
67154 * the 64bit alignment we do later.
67155 */
67156 - buf = kzalloc(PATH_MAX + sizeof(u64), GFP_KERNEL);
67157 + buf = kzalloc(PATH_MAX, GFP_KERNEL);
67158 if (!buf) {
67159 name = strncpy(tmp, "//enomem", sizeof(tmp));
67160 goto got_name;
67161 }
67162 - name = d_path(&file->f_path, buf, PATH_MAX);
67163 + name = d_path(&file->f_path, buf, PATH_MAX - sizeof(u64));
67164 if (IS_ERR(name)) {
67165 name = strncpy(tmp, "//toolong", sizeof(tmp));
67166 goto got_name;
67167 @@ -5940,7 +5940,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
67168 event->parent = parent_event;
67169
67170 event->ns = get_pid_ns(current->nsproxy->pid_ns);
67171 - event->id = atomic64_inc_return(&perf_event_id);
67172 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
67173
67174 event->state = PERF_EVENT_STATE_INACTIVE;
67175
67176 @@ -6500,10 +6500,10 @@ static void sync_child_event(struct perf_event *child_event,
67177 /*
67178 * Add back the child's count to the parent's count:
67179 */
67180 - atomic64_add(child_val, &parent_event->child_count);
67181 - atomic64_add(child_event->total_time_enabled,
67182 + atomic64_add_unchecked(child_val, &parent_event->child_count);
67183 + atomic64_add_unchecked(child_event->total_time_enabled,
67184 &parent_event->child_total_time_enabled);
67185 - atomic64_add(child_event->total_time_running,
67186 + atomic64_add_unchecked(child_event->total_time_running,
67187 &parent_event->child_total_time_running);
67188
67189 /*
67190 diff --git a/kernel/exit.c b/kernel/exit.c
67191 index 46ce8da..c648f3a 100644
67192 --- a/kernel/exit.c
67193 +++ b/kernel/exit.c
67194 @@ -59,6 +59,10 @@
67195 #include <asm/pgtable.h>
67196 #include <asm/mmu_context.h>
67197
67198 +#ifdef CONFIG_GRKERNSEC
67199 +extern rwlock_t grsec_exec_file_lock;
67200 +#endif
67201 +
67202 static void exit_mm(struct task_struct * tsk);
67203
67204 static void __unhash_process(struct task_struct *p, bool group_dead)
67205 @@ -182,6 +186,10 @@ void release_task(struct task_struct * p)
67206 struct task_struct *leader;
67207 int zap_leader;
67208 repeat:
67209 +#ifdef CONFIG_NET
67210 + gr_del_task_from_ip_table(p);
67211 +#endif
67212 +
67213 /* don't need to get the RCU readlock here - the process is dead and
67214 * can't be modifying its own credentials. But shut RCU-lockdep up */
67215 rcu_read_lock();
67216 @@ -394,7 +402,7 @@ int allow_signal(int sig)
67217 * know it'll be handled, so that they don't get converted to
67218 * SIGKILL or just silently dropped.
67219 */
67220 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
67221 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
67222 recalc_sigpending();
67223 spin_unlock_irq(&current->sighand->siglock);
67224 return 0;
67225 @@ -430,6 +438,17 @@ void daemonize(const char *name, ...)
67226 vsnprintf(current->comm, sizeof(current->comm), name, args);
67227 va_end(args);
67228
67229 +#ifdef CONFIG_GRKERNSEC
67230 + write_lock(&grsec_exec_file_lock);
67231 + if (current->exec_file) {
67232 + fput(current->exec_file);
67233 + current->exec_file = NULL;
67234 + }
67235 + write_unlock(&grsec_exec_file_lock);
67236 +#endif
67237 +
67238 + gr_set_kernel_label(current);
67239 +
67240 /*
67241 * If we were started as result of loading a module, close all of the
67242 * user space pages. We don't need them, and if we didn't close them
67243 @@ -907,6 +926,8 @@ void do_exit(long code)
67244 struct task_struct *tsk = current;
67245 int group_dead;
67246
67247 + set_fs(USER_DS);
67248 +
67249 profile_task_exit(tsk);
67250
67251 WARN_ON(blk_needs_flush_plug(tsk));
67252 @@ -923,7 +944,6 @@ void do_exit(long code)
67253 * mm_release()->clear_child_tid() from writing to a user-controlled
67254 * kernel address.
67255 */
67256 - set_fs(USER_DS);
67257
67258 ptrace_event(PTRACE_EVENT_EXIT, code);
67259
67260 @@ -985,6 +1005,9 @@ void do_exit(long code)
67261 tsk->exit_code = code;
67262 taskstats_exit(tsk, group_dead);
67263
67264 + gr_acl_handle_psacct(tsk, code);
67265 + gr_acl_handle_exit();
67266 +
67267 exit_mm(tsk);
67268
67269 if (group_dead)
67270 @@ -1101,7 +1124,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
67271 * Take down every thread in the group. This is called by fatal signals
67272 * as well as by sys_exit_group (below).
67273 */
67274 -void
67275 +__noreturn void
67276 do_group_exit(int exit_code)
67277 {
67278 struct signal_struct *sig = current->signal;
67279 diff --git a/kernel/fork.c b/kernel/fork.c
67280 index f9d0499..e4f8f44 100644
67281 --- a/kernel/fork.c
67282 +++ b/kernel/fork.c
67283 @@ -321,7 +321,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
67284 *stackend = STACK_END_MAGIC; /* for overflow detection */
67285
67286 #ifdef CONFIG_CC_STACKPROTECTOR
67287 - tsk->stack_canary = get_random_int();
67288 + tsk->stack_canary = pax_get_random_long();
67289 #endif
67290
67291 /*
67292 @@ -345,13 +345,78 @@ out:
67293 }
67294
67295 #ifdef CONFIG_MMU
67296 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
67297 +{
67298 + struct vm_area_struct *tmp;
67299 + unsigned long charge;
67300 + struct mempolicy *pol;
67301 + struct file *file;
67302 +
67303 + charge = 0;
67304 + if (mpnt->vm_flags & VM_ACCOUNT) {
67305 + unsigned long len;
67306 + len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67307 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67308 + goto fail_nomem;
67309 + charge = len;
67310 + }
67311 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67312 + if (!tmp)
67313 + goto fail_nomem;
67314 + *tmp = *mpnt;
67315 + tmp->vm_mm = mm;
67316 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
67317 + pol = mpol_dup(vma_policy(mpnt));
67318 + if (IS_ERR(pol))
67319 + goto fail_nomem_policy;
67320 + vma_set_policy(tmp, pol);
67321 + if (anon_vma_fork(tmp, mpnt))
67322 + goto fail_nomem_anon_vma_fork;
67323 + tmp->vm_flags &= ~VM_LOCKED;
67324 + tmp->vm_next = tmp->vm_prev = NULL;
67325 + tmp->vm_mirror = NULL;
67326 + file = tmp->vm_file;
67327 + if (file) {
67328 + struct inode *inode = file->f_path.dentry->d_inode;
67329 + struct address_space *mapping = file->f_mapping;
67330 +
67331 + get_file(file);
67332 + if (tmp->vm_flags & VM_DENYWRITE)
67333 + atomic_dec(&inode->i_writecount);
67334 + mutex_lock(&mapping->i_mmap_mutex);
67335 + if (tmp->vm_flags & VM_SHARED)
67336 + mapping->i_mmap_writable++;
67337 + flush_dcache_mmap_lock(mapping);
67338 + /* insert tmp into the share list, just after mpnt */
67339 + vma_prio_tree_add(tmp, mpnt);
67340 + flush_dcache_mmap_unlock(mapping);
67341 + mutex_unlock(&mapping->i_mmap_mutex);
67342 + }
67343 +
67344 + /*
67345 + * Clear hugetlb-related page reserves for children. This only
67346 + * affects MAP_PRIVATE mappings. Faults generated by the child
67347 + * are not guaranteed to succeed, even if read-only
67348 + */
67349 + if (is_vm_hugetlb_page(tmp))
67350 + reset_vma_resv_huge_pages(tmp);
67351 +
67352 + return tmp;
67353 +
67354 +fail_nomem_anon_vma_fork:
67355 + mpol_put(pol);
67356 +fail_nomem_policy:
67357 + kmem_cache_free(vm_area_cachep, tmp);
67358 +fail_nomem:
67359 + vm_unacct_memory(charge);
67360 + return NULL;
67361 +}
67362 +
67363 static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67364 {
67365 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
67366 struct rb_node **rb_link, *rb_parent;
67367 int retval;
67368 - unsigned long charge;
67369 - struct mempolicy *pol;
67370
67371 down_write(&oldmm->mmap_sem);
67372 flush_cache_dup_mm(oldmm);
67373 @@ -363,8 +428,8 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67374 mm->locked_vm = 0;
67375 mm->mmap = NULL;
67376 mm->mmap_cache = NULL;
67377 - mm->free_area_cache = oldmm->mmap_base;
67378 - mm->cached_hole_size = ~0UL;
67379 + mm->free_area_cache = oldmm->free_area_cache;
67380 + mm->cached_hole_size = oldmm->cached_hole_size;
67381 mm->map_count = 0;
67382 cpumask_clear(mm_cpumask(mm));
67383 mm->mm_rb = RB_ROOT;
67384 @@ -380,8 +445,6 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67385
67386 prev = NULL;
67387 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
67388 - struct file *file;
67389 -
67390 if (mpnt->vm_flags & VM_DONTCOPY) {
67391 long pages = vma_pages(mpnt);
67392 mm->total_vm -= pages;
67393 @@ -389,54 +452,11 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67394 -pages);
67395 continue;
67396 }
67397 - charge = 0;
67398 - if (mpnt->vm_flags & VM_ACCOUNT) {
67399 - unsigned long len;
67400 - len = (mpnt->vm_end - mpnt->vm_start) >> PAGE_SHIFT;
67401 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
67402 - goto fail_nomem;
67403 - charge = len;
67404 + tmp = dup_vma(mm, oldmm, mpnt);
67405 + if (!tmp) {
67406 + retval = -ENOMEM;
67407 + goto out;
67408 }
67409 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
67410 - if (!tmp)
67411 - goto fail_nomem;
67412 - *tmp = *mpnt;
67413 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
67414 - pol = mpol_dup(vma_policy(mpnt));
67415 - retval = PTR_ERR(pol);
67416 - if (IS_ERR(pol))
67417 - goto fail_nomem_policy;
67418 - vma_set_policy(tmp, pol);
67419 - tmp->vm_mm = mm;
67420 - if (anon_vma_fork(tmp, mpnt))
67421 - goto fail_nomem_anon_vma_fork;
67422 - tmp->vm_flags &= ~VM_LOCKED;
67423 - tmp->vm_next = tmp->vm_prev = NULL;
67424 - file = tmp->vm_file;
67425 - if (file) {
67426 - struct inode *inode = file->f_path.dentry->d_inode;
67427 - struct address_space *mapping = file->f_mapping;
67428 -
67429 - get_file(file);
67430 - if (tmp->vm_flags & VM_DENYWRITE)
67431 - atomic_dec(&inode->i_writecount);
67432 - mutex_lock(&mapping->i_mmap_mutex);
67433 - if (tmp->vm_flags & VM_SHARED)
67434 - mapping->i_mmap_writable++;
67435 - flush_dcache_mmap_lock(mapping);
67436 - /* insert tmp into the share list, just after mpnt */
67437 - vma_prio_tree_add(tmp, mpnt);
67438 - flush_dcache_mmap_unlock(mapping);
67439 - mutex_unlock(&mapping->i_mmap_mutex);
67440 - }
67441 -
67442 - /*
67443 - * Clear hugetlb-related page reserves for children. This only
67444 - * affects MAP_PRIVATE mappings. Faults generated by the child
67445 - * are not guaranteed to succeed, even if read-only
67446 - */
67447 - if (is_vm_hugetlb_page(tmp))
67448 - reset_vma_resv_huge_pages(tmp);
67449
67450 /*
67451 * Link in the new vma and copy the page table entries.
67452 @@ -459,9 +479,34 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
67453 if (retval)
67454 goto out;
67455
67456 - if (file)
67457 + if (tmp->vm_file)
67458 uprobe_mmap(tmp);
67459 }
67460 +
67461 +#ifdef CONFIG_PAX_SEGMEXEC
67462 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
67463 + struct vm_area_struct *mpnt_m;
67464 +
67465 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
67466 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
67467 +
67468 + if (!mpnt->vm_mirror)
67469 + continue;
67470 +
67471 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
67472 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
67473 + mpnt->vm_mirror = mpnt_m;
67474 + } else {
67475 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
67476 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
67477 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
67478 + mpnt->vm_mirror->vm_mirror = mpnt;
67479 + }
67480 + }
67481 + BUG_ON(mpnt_m);
67482 + }
67483 +#endif
67484 +
67485 /* a new mm has just been created */
67486 arch_dup_mmap(oldmm, mm);
67487 retval = 0;
67488 @@ -470,14 +515,6 @@ out:
67489 flush_tlb_mm(oldmm);
67490 up_write(&oldmm->mmap_sem);
67491 return retval;
67492 -fail_nomem_anon_vma_fork:
67493 - mpol_put(pol);
67494 -fail_nomem_policy:
67495 - kmem_cache_free(vm_area_cachep, tmp);
67496 -fail_nomem:
67497 - retval = -ENOMEM;
67498 - vm_unacct_memory(charge);
67499 - goto out;
67500 }
67501
67502 static inline int mm_alloc_pgd(struct mm_struct *mm)
67503 @@ -714,8 +751,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
67504 return ERR_PTR(err);
67505
67506 mm = get_task_mm(task);
67507 - if (mm && mm != current->mm &&
67508 - !ptrace_may_access(task, mode)) {
67509 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
67510 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
67511 mmput(mm);
67512 mm = ERR_PTR(-EACCES);
67513 }
67514 @@ -936,13 +973,14 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
67515 spin_unlock(&fs->lock);
67516 return -EAGAIN;
67517 }
67518 - fs->users++;
67519 + atomic_inc(&fs->users);
67520 spin_unlock(&fs->lock);
67521 return 0;
67522 }
67523 tsk->fs = copy_fs_struct(fs);
67524 if (!tsk->fs)
67525 return -ENOMEM;
67526 + gr_set_chroot_entries(tsk, &tsk->fs->root);
67527 return 0;
67528 }
67529
67530 @@ -1209,6 +1247,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67531 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
67532 #endif
67533 retval = -EAGAIN;
67534 +
67535 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
67536 +
67537 if (atomic_read(&p->real_cred->user->processes) >=
67538 task_rlimit(p, RLIMIT_NPROC)) {
67539 if (!capable(CAP_SYS_ADMIN) && !capable(CAP_SYS_RESOURCE) &&
67540 @@ -1431,6 +1472,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
67541 /* Need tasklist lock for parent etc handling! */
67542 write_lock_irq(&tasklist_lock);
67543
67544 + /* synchronizes with gr_set_acls() */
67545 + gr_copy_label(p);
67546 +
67547 /* CLONE_PARENT re-uses the old parent */
67548 if (clone_flags & (CLONE_PARENT|CLONE_THREAD)) {
67549 p->real_parent = current->real_parent;
67550 @@ -1541,6 +1585,8 @@ bad_fork_cleanup_count:
67551 bad_fork_free:
67552 free_task(p);
67553 fork_out:
67554 + gr_log_forkfail(retval);
67555 +
67556 return ERR_PTR(retval);
67557 }
67558
67559 @@ -1641,6 +1687,8 @@ long do_fork(unsigned long clone_flags,
67560 if (clone_flags & CLONE_PARENT_SETTID)
67561 put_user(nr, parent_tidptr);
67562
67563 + gr_handle_brute_check();
67564 +
67565 if (clone_flags & CLONE_VFORK) {
67566 p->vfork_done = &vfork;
67567 init_completion(&vfork);
67568 @@ -1739,7 +1787,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
67569 return 0;
67570
67571 /* don't need lock here; in the worst case we'll do useless copy */
67572 - if (fs->users == 1)
67573 + if (atomic_read(&fs->users) == 1)
67574 return 0;
67575
67576 *new_fsp = copy_fs_struct(fs);
67577 @@ -1828,7 +1876,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
67578 fs = current->fs;
67579 spin_lock(&fs->lock);
67580 current->fs = new_fs;
67581 - if (--fs->users)
67582 + gr_set_chroot_entries(current, &current->fs->root);
67583 + if (atomic_dec_return(&fs->users))
67584 new_fs = NULL;
67585 else
67586 new_fs = fs;
67587 diff --git a/kernel/futex.c b/kernel/futex.c
67588 index 3717e7b..473c750 100644
67589 --- a/kernel/futex.c
67590 +++ b/kernel/futex.c
67591 @@ -54,6 +54,7 @@
67592 #include <linux/mount.h>
67593 #include <linux/pagemap.h>
67594 #include <linux/syscalls.h>
67595 +#include <linux/ptrace.h>
67596 #include <linux/signal.h>
67597 #include <linux/export.h>
67598 #include <linux/magic.h>
67599 @@ -239,6 +240,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
67600 struct page *page, *page_head;
67601 int err, ro = 0;
67602
67603 +#ifdef CONFIG_PAX_SEGMEXEC
67604 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
67605 + return -EFAULT;
67606 +#endif
67607 +
67608 /*
67609 * The futex address must be "naturally" aligned.
67610 */
67611 @@ -2714,6 +2720,7 @@ static int __init futex_init(void)
67612 {
67613 u32 curval;
67614 int i;
67615 + mm_segment_t oldfs;
67616
67617 /*
67618 * This will fail and we want it. Some arch implementations do
67619 @@ -2725,8 +2732,11 @@ static int __init futex_init(void)
67620 * implementation, the non-functional ones will return
67621 * -ENOSYS.
67622 */
67623 + oldfs = get_fs();
67624 + set_fs(USER_DS);
67625 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
67626 futex_cmpxchg_enabled = 1;
67627 + set_fs(oldfs);
67628
67629 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
67630 plist_head_init(&futex_queues[i].chain);
67631 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
67632 index 9b22d03..6295b62 100644
67633 --- a/kernel/gcov/base.c
67634 +++ b/kernel/gcov/base.c
67635 @@ -102,11 +102,6 @@ void gcov_enable_events(void)
67636 }
67637
67638 #ifdef CONFIG_MODULES
67639 -static inline int within(void *addr, void *start, unsigned long size)
67640 -{
67641 - return ((addr >= start) && (addr < start + size));
67642 -}
67643 -
67644 /* Update list and generate events when modules are unloaded. */
67645 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67646 void *data)
67647 @@ -121,7 +116,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
67648 prev = NULL;
67649 /* Remove entries located in module from linked list. */
67650 for (info = gcov_info_head; info; info = info->next) {
67651 - if (within(info, mod->module_core, mod->core_size)) {
67652 + if (within_module_core_rw((unsigned long)info, mod)) {
67653 if (prev)
67654 prev->next = info->next;
67655 else
67656 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
67657 index 6db7a5e..25b6648 100644
67658 --- a/kernel/hrtimer.c
67659 +++ b/kernel/hrtimer.c
67660 @@ -1407,7 +1407,7 @@ void hrtimer_peek_ahead_timers(void)
67661 local_irq_restore(flags);
67662 }
67663
67664 -static void run_hrtimer_softirq(struct softirq_action *h)
67665 +static void run_hrtimer_softirq(void)
67666 {
67667 struct hrtimer_cpu_base *cpu_base = &__get_cpu_var(hrtimer_bases);
67668
67669 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
67670 index 4304919..408c4c0 100644
67671 --- a/kernel/jump_label.c
67672 +++ b/kernel/jump_label.c
67673 @@ -13,6 +13,7 @@
67674 #include <linux/sort.h>
67675 #include <linux/err.h>
67676 #include <linux/static_key.h>
67677 +#include <linux/mm.h>
67678
67679 #ifdef HAVE_JUMP_LABEL
67680
67681 @@ -50,7 +51,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
67682
67683 size = (((unsigned long)stop - (unsigned long)start)
67684 / sizeof(struct jump_entry));
67685 + pax_open_kernel();
67686 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
67687 + pax_close_kernel();
67688 }
67689
67690 static void jump_label_update(struct static_key *key, int enable);
67691 @@ -356,10 +359,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
67692 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
67693 struct jump_entry *iter;
67694
67695 + pax_open_kernel();
67696 for (iter = iter_start; iter < iter_stop; iter++) {
67697 if (within_module_init(iter->code, mod))
67698 iter->code = 0;
67699 }
67700 + pax_close_kernel();
67701 }
67702
67703 static int
67704 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
67705 index 2169fee..45c017a 100644
67706 --- a/kernel/kallsyms.c
67707 +++ b/kernel/kallsyms.c
67708 @@ -11,6 +11,9 @@
67709 * Changed the compression method from stem compression to "table lookup"
67710 * compression (see scripts/kallsyms.c for a more complete description)
67711 */
67712 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67713 +#define __INCLUDED_BY_HIDESYM 1
67714 +#endif
67715 #include <linux/kallsyms.h>
67716 #include <linux/module.h>
67717 #include <linux/init.h>
67718 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
67719
67720 static inline int is_kernel_inittext(unsigned long addr)
67721 {
67722 + if (system_state != SYSTEM_BOOTING)
67723 + return 0;
67724 +
67725 if (addr >= (unsigned long)_sinittext
67726 && addr <= (unsigned long)_einittext)
67727 return 1;
67728 return 0;
67729 }
67730
67731 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67732 +#ifdef CONFIG_MODULES
67733 +static inline int is_module_text(unsigned long addr)
67734 +{
67735 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
67736 + return 1;
67737 +
67738 + addr = ktla_ktva(addr);
67739 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
67740 +}
67741 +#else
67742 +static inline int is_module_text(unsigned long addr)
67743 +{
67744 + return 0;
67745 +}
67746 +#endif
67747 +#endif
67748 +
67749 static inline int is_kernel_text(unsigned long addr)
67750 {
67751 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
67752 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
67753
67754 static inline int is_kernel(unsigned long addr)
67755 {
67756 +
67757 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67758 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
67759 + return 1;
67760 +
67761 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
67762 +#else
67763 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
67764 +#endif
67765 +
67766 return 1;
67767 return in_gate_area_no_mm(addr);
67768 }
67769
67770 static int is_ksym_addr(unsigned long addr)
67771 {
67772 +
67773 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
67774 + if (is_module_text(addr))
67775 + return 0;
67776 +#endif
67777 +
67778 if (all_var)
67779 return is_kernel(addr);
67780
67781 @@ -470,7 +509,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
67782
67783 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
67784 {
67785 - iter->name[0] = '\0';
67786 iter->nameoff = get_symbol_offset(new_pos);
67787 iter->pos = new_pos;
67788 }
67789 @@ -518,6 +556,11 @@ static int s_show(struct seq_file *m, void *p)
67790 {
67791 struct kallsym_iter *iter = m->private;
67792
67793 +#ifdef CONFIG_GRKERNSEC_HIDESYM
67794 + if (current_uid())
67795 + return 0;
67796 +#endif
67797 +
67798 /* Some debugging symbols have no name. Ignore them. */
67799 if (!iter->name[0])
67800 return 0;
67801 @@ -531,6 +574,7 @@ static int s_show(struct seq_file *m, void *p)
67802 */
67803 type = iter->exported ? toupper(iter->type) :
67804 tolower(iter->type);
67805 +
67806 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
67807 type, iter->name, iter->module_name);
67808 } else
67809 @@ -556,7 +600,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
67810 struct kallsym_iter *iter;
67811 int ret;
67812
67813 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
67814 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
67815 if (!iter)
67816 return -ENOMEM;
67817 reset_iter(iter, 0);
67818 diff --git a/kernel/kexec.c b/kernel/kexec.c
67819 index 4e2e472..cd0c7ae 100644
67820 --- a/kernel/kexec.c
67821 +++ b/kernel/kexec.c
67822 @@ -1046,7 +1046,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
67823 unsigned long flags)
67824 {
67825 struct compat_kexec_segment in;
67826 - struct kexec_segment out, __user *ksegments;
67827 + struct kexec_segment out;
67828 + struct kexec_segment __user *ksegments;
67829 unsigned long i, result;
67830
67831 /* Don't allow clients that don't understand the native
67832 diff --git a/kernel/kmod.c b/kernel/kmod.c
67833 index ff2c7cb..085d7af 100644
67834 --- a/kernel/kmod.c
67835 +++ b/kernel/kmod.c
67836 @@ -66,7 +66,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
67837 kfree(info->argv);
67838 }
67839
67840 -static int call_modprobe(char *module_name, int wait)
67841 +static int call_modprobe(char *module_name, char *module_param, int wait)
67842 {
67843 static char *envp[] = {
67844 "HOME=/",
67845 @@ -75,7 +75,7 @@ static int call_modprobe(char *module_name, int wait)
67846 NULL
67847 };
67848
67849 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
67850 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
67851 if (!argv)
67852 goto out;
67853
67854 @@ -87,7 +87,8 @@ static int call_modprobe(char *module_name, int wait)
67855 argv[1] = "-q";
67856 argv[2] = "--";
67857 argv[3] = module_name; /* check free_modprobe_argv() */
67858 - argv[4] = NULL;
67859 + argv[4] = module_param;
67860 + argv[5] = NULL;
67861
67862 return call_usermodehelper_fns(modprobe_path, argv, envp,
67863 wait | UMH_KILLABLE, NULL, free_modprobe_argv, NULL);
67864 @@ -112,9 +113,8 @@ out:
67865 * If module auto-loading support is disabled then this function
67866 * becomes a no-operation.
67867 */
67868 -int __request_module(bool wait, const char *fmt, ...)
67869 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
67870 {
67871 - va_list args;
67872 char module_name[MODULE_NAME_LEN];
67873 unsigned int max_modprobes;
67874 int ret;
67875 @@ -122,9 +122,7 @@ int __request_module(bool wait, const char *fmt, ...)
67876 #define MAX_KMOD_CONCURRENT 50 /* Completely arbitrary value - KAO */
67877 static int kmod_loop_msg;
67878
67879 - va_start(args, fmt);
67880 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
67881 - va_end(args);
67882 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
67883 if (ret >= MODULE_NAME_LEN)
67884 return -ENAMETOOLONG;
67885
67886 @@ -132,6 +130,20 @@ int __request_module(bool wait, const char *fmt, ...)
67887 if (ret)
67888 return ret;
67889
67890 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67891 + if (!current_uid()) {
67892 + /* hack to workaround consolekit/udisks stupidity */
67893 + read_lock(&tasklist_lock);
67894 + if (!strcmp(current->comm, "mount") &&
67895 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
67896 + read_unlock(&tasklist_lock);
67897 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
67898 + return -EPERM;
67899 + }
67900 + read_unlock(&tasklist_lock);
67901 + }
67902 +#endif
67903 +
67904 /* If modprobe needs a service that is in a module, we get a recursive
67905 * loop. Limit the number of running kmod threads to max_threads/2 or
67906 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
67907 @@ -160,11 +172,52 @@ int __request_module(bool wait, const char *fmt, ...)
67908
67909 trace_module_request(module_name, wait, _RET_IP_);
67910
67911 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67912 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
67913
67914 atomic_dec(&kmod_concurrent);
67915 return ret;
67916 }
67917 +
67918 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
67919 +{
67920 + va_list args;
67921 + int ret;
67922 +
67923 + va_start(args, fmt);
67924 + ret = ____request_module(wait, module_param, fmt, args);
67925 + va_end(args);
67926 +
67927 + return ret;
67928 +}
67929 +
67930 +int __request_module(bool wait, const char *fmt, ...)
67931 +{
67932 + va_list args;
67933 + int ret;
67934 +
67935 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
67936 + if (current_uid()) {
67937 + char module_param[MODULE_NAME_LEN];
67938 +
67939 + memset(module_param, 0, sizeof(module_param));
67940 +
67941 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", current_uid());
67942 +
67943 + va_start(args, fmt);
67944 + ret = ____request_module(wait, module_param, fmt, args);
67945 + va_end(args);
67946 +
67947 + return ret;
67948 + }
67949 +#endif
67950 +
67951 + va_start(args, fmt);
67952 + ret = ____request_module(wait, NULL, fmt, args);
67953 + va_end(args);
67954 +
67955 + return ret;
67956 +}
67957 +
67958 EXPORT_SYMBOL(__request_module);
67959 #endif /* CONFIG_MODULES */
67960
67961 @@ -266,7 +319,7 @@ static int wait_for_helper(void *data)
67962 *
67963 * Thus the __user pointer cast is valid here.
67964 */
67965 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
67966 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
67967
67968 /*
67969 * If ret is 0, either ____call_usermodehelper failed and the
67970 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
67971 index c62b854..cb67968 100644
67972 --- a/kernel/kprobes.c
67973 +++ b/kernel/kprobes.c
67974 @@ -185,7 +185,7 @@ static kprobe_opcode_t __kprobes *__get_insn_slot(struct kprobe_insn_cache *c)
67975 * kernel image and loaded module images reside. This is required
67976 * so x86_64 can correctly handle the %rip-relative fixups.
67977 */
67978 - kip->insns = module_alloc(PAGE_SIZE);
67979 + kip->insns = module_alloc_exec(PAGE_SIZE);
67980 if (!kip->insns) {
67981 kfree(kip);
67982 return NULL;
67983 @@ -225,7 +225,7 @@ static int __kprobes collect_one_slot(struct kprobe_insn_page *kip, int idx)
67984 */
67985 if (!list_is_singular(&kip->list)) {
67986 list_del(&kip->list);
67987 - module_free(NULL, kip->insns);
67988 + module_free_exec(NULL, kip->insns);
67989 kfree(kip);
67990 }
67991 return 1;
67992 @@ -1955,7 +1955,7 @@ static int __init init_kprobes(void)
67993 {
67994 int i, err = 0;
67995 unsigned long offset = 0, size = 0;
67996 - char *modname, namebuf[128];
67997 + char *modname, namebuf[KSYM_NAME_LEN];
67998 const char *symbol_name;
67999 void *addr;
68000 struct kprobe_blackpoint *kb;
68001 @@ -2081,7 +2081,7 @@ static int __kprobes show_kprobe_addr(struct seq_file *pi, void *v)
68002 const char *sym = NULL;
68003 unsigned int i = *(loff_t *) v;
68004 unsigned long offset = 0;
68005 - char *modname, namebuf[128];
68006 + char *modname, namebuf[KSYM_NAME_LEN];
68007
68008 head = &kprobe_table[i];
68009 preempt_disable();
68010 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
68011 index 4e316e1..5501eef 100644
68012 --- a/kernel/ksysfs.c
68013 +++ b/kernel/ksysfs.c
68014 @@ -47,6 +47,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
68015 {
68016 if (count+1 > UEVENT_HELPER_PATH_LEN)
68017 return -ENOENT;
68018 + if (!capable(CAP_SYS_ADMIN))
68019 + return -EPERM;
68020 memcpy(uevent_helper, buf, count);
68021 uevent_helper[count] = '\0';
68022 if (count && uevent_helper[count-1] == '\n')
68023 diff --git a/kernel/lockdep.c b/kernel/lockdep.c
68024 index ea9ee45..67ebc8f 100644
68025 --- a/kernel/lockdep.c
68026 +++ b/kernel/lockdep.c
68027 @@ -590,6 +590,10 @@ static int static_obj(void *obj)
68028 end = (unsigned long) &_end,
68029 addr = (unsigned long) obj;
68030
68031 +#ifdef CONFIG_PAX_KERNEXEC
68032 + start = ktla_ktva(start);
68033 +#endif
68034 +
68035 /*
68036 * static variable?
68037 */
68038 @@ -730,6 +734,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
68039 if (!static_obj(lock->key)) {
68040 debug_locks_off();
68041 printk("INFO: trying to register non-static key.\n");
68042 + printk("lock:%pS key:%pS.\n", lock, lock->key);
68043 printk("the code is fine but needs lockdep annotation.\n");
68044 printk("turning off the locking correctness validator.\n");
68045 dump_stack();
68046 @@ -3042,7 +3047,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
68047 if (!class)
68048 return 0;
68049 }
68050 - atomic_inc((atomic_t *)&class->ops);
68051 + atomic_inc_unchecked((atomic_unchecked_t *)&class->ops);
68052 if (very_verbose(class)) {
68053 printk("\nacquire class [%p] %s", class->key, class->name);
68054 if (class->name_version > 1)
68055 diff --git a/kernel/lockdep_proc.c b/kernel/lockdep_proc.c
68056 index 91c32a0..b2c71c5 100644
68057 --- a/kernel/lockdep_proc.c
68058 +++ b/kernel/lockdep_proc.c
68059 @@ -39,7 +39,7 @@ static void l_stop(struct seq_file *m, void *v)
68060
68061 static void print_name(struct seq_file *m, struct lock_class *class)
68062 {
68063 - char str[128];
68064 + char str[KSYM_NAME_LEN];
68065 const char *name = class->name;
68066
68067 if (!name) {
68068 diff --git a/kernel/module.c b/kernel/module.c
68069 index 4edbd9c..165e780 100644
68070 --- a/kernel/module.c
68071 +++ b/kernel/module.c
68072 @@ -58,6 +58,7 @@
68073 #include <linux/jump_label.h>
68074 #include <linux/pfn.h>
68075 #include <linux/bsearch.h>
68076 +#include <linux/grsecurity.h>
68077
68078 #define CREATE_TRACE_POINTS
68079 #include <trace/events/module.h>
68080 @@ -114,7 +115,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
68081
68082 /* Bounds of module allocation, for speeding __module_address.
68083 * Protected by module_mutex. */
68084 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
68085 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
68086 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
68087
68088 int register_module_notifier(struct notifier_block * nb)
68089 {
68090 @@ -278,7 +280,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68091 return true;
68092
68093 list_for_each_entry_rcu(mod, &modules, list) {
68094 - struct symsearch arr[] = {
68095 + struct symsearch modarr[] = {
68096 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
68097 NOT_GPL_ONLY, false },
68098 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
68099 @@ -300,7 +302,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
68100 #endif
68101 };
68102
68103 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
68104 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
68105 return true;
68106 }
68107 return false;
68108 @@ -432,7 +434,7 @@ static inline void __percpu *mod_percpu(struct module *mod)
68109 static int percpu_modalloc(struct module *mod,
68110 unsigned long size, unsigned long align)
68111 {
68112 - if (align > PAGE_SIZE) {
68113 + if (align-1 >= PAGE_SIZE) {
68114 printk(KERN_WARNING "%s: per-cpu alignment %li > %li\n",
68115 mod->name, align, PAGE_SIZE);
68116 align = PAGE_SIZE;
68117 @@ -1032,7 +1034,7 @@ struct module_attribute module_uevent =
68118 static ssize_t show_coresize(struct module_attribute *mattr,
68119 struct module_kobject *mk, char *buffer)
68120 {
68121 - return sprintf(buffer, "%u\n", mk->mod->core_size);
68122 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
68123 }
68124
68125 static struct module_attribute modinfo_coresize =
68126 @@ -1041,7 +1043,7 @@ static struct module_attribute modinfo_coresize =
68127 static ssize_t show_initsize(struct module_attribute *mattr,
68128 struct module_kobject *mk, char *buffer)
68129 {
68130 - return sprintf(buffer, "%u\n", mk->mod->init_size);
68131 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
68132 }
68133
68134 static struct module_attribute modinfo_initsize =
68135 @@ -1255,7 +1257,7 @@ resolve_symbol_wait(struct module *mod,
68136 */
68137 #ifdef CONFIG_SYSFS
68138
68139 -#ifdef CONFIG_KALLSYMS
68140 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
68141 static inline bool sect_empty(const Elf_Shdr *sect)
68142 {
68143 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
68144 @@ -1721,21 +1723,21 @@ static void set_section_ro_nx(void *base,
68145
68146 static void unset_module_core_ro_nx(struct module *mod)
68147 {
68148 - set_page_attributes(mod->module_core + mod->core_text_size,
68149 - mod->module_core + mod->core_size,
68150 + set_page_attributes(mod->module_core_rw,
68151 + mod->module_core_rw + mod->core_size_rw,
68152 set_memory_x);
68153 - set_page_attributes(mod->module_core,
68154 - mod->module_core + mod->core_ro_size,
68155 + set_page_attributes(mod->module_core_rx,
68156 + mod->module_core_rx + mod->core_size_rx,
68157 set_memory_rw);
68158 }
68159
68160 static void unset_module_init_ro_nx(struct module *mod)
68161 {
68162 - set_page_attributes(mod->module_init + mod->init_text_size,
68163 - mod->module_init + mod->init_size,
68164 + set_page_attributes(mod->module_init_rw,
68165 + mod->module_init_rw + mod->init_size_rw,
68166 set_memory_x);
68167 - set_page_attributes(mod->module_init,
68168 - mod->module_init + mod->init_ro_size,
68169 + set_page_attributes(mod->module_init_rx,
68170 + mod->module_init_rx + mod->init_size_rx,
68171 set_memory_rw);
68172 }
68173
68174 @@ -1746,14 +1748,14 @@ void set_all_modules_text_rw(void)
68175
68176 mutex_lock(&module_mutex);
68177 list_for_each_entry_rcu(mod, &modules, list) {
68178 - if ((mod->module_core) && (mod->core_text_size)) {
68179 - set_page_attributes(mod->module_core,
68180 - mod->module_core + mod->core_text_size,
68181 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68182 + set_page_attributes(mod->module_core_rx,
68183 + mod->module_core_rx + mod->core_size_rx,
68184 set_memory_rw);
68185 }
68186 - if ((mod->module_init) && (mod->init_text_size)) {
68187 - set_page_attributes(mod->module_init,
68188 - mod->module_init + mod->init_text_size,
68189 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68190 + set_page_attributes(mod->module_init_rx,
68191 + mod->module_init_rx + mod->init_size_rx,
68192 set_memory_rw);
68193 }
68194 }
68195 @@ -1767,14 +1769,14 @@ void set_all_modules_text_ro(void)
68196
68197 mutex_lock(&module_mutex);
68198 list_for_each_entry_rcu(mod, &modules, list) {
68199 - if ((mod->module_core) && (mod->core_text_size)) {
68200 - set_page_attributes(mod->module_core,
68201 - mod->module_core + mod->core_text_size,
68202 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
68203 + set_page_attributes(mod->module_core_rx,
68204 + mod->module_core_rx + mod->core_size_rx,
68205 set_memory_ro);
68206 }
68207 - if ((mod->module_init) && (mod->init_text_size)) {
68208 - set_page_attributes(mod->module_init,
68209 - mod->module_init + mod->init_text_size,
68210 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
68211 + set_page_attributes(mod->module_init_rx,
68212 + mod->module_init_rx + mod->init_size_rx,
68213 set_memory_ro);
68214 }
68215 }
68216 @@ -1820,16 +1822,19 @@ static void free_module(struct module *mod)
68217
68218 /* This may be NULL, but that's OK */
68219 unset_module_init_ro_nx(mod);
68220 - module_free(mod, mod->module_init);
68221 + module_free(mod, mod->module_init_rw);
68222 + module_free_exec(mod, mod->module_init_rx);
68223 kfree(mod->args);
68224 percpu_modfree(mod);
68225
68226 /* Free lock-classes: */
68227 - lockdep_free_key_range(mod->module_core, mod->core_size);
68228 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
68229 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
68230
68231 /* Finally, free the core (containing the module structure) */
68232 unset_module_core_ro_nx(mod);
68233 - module_free(mod, mod->module_core);
68234 + module_free_exec(mod, mod->module_core_rx);
68235 + module_free(mod, mod->module_core_rw);
68236
68237 #ifdef CONFIG_MPU
68238 update_protections(current->mm);
68239 @@ -1899,9 +1904,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68240 int ret = 0;
68241 const struct kernel_symbol *ksym;
68242
68243 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68244 + int is_fs_load = 0;
68245 + int register_filesystem_found = 0;
68246 + char *p;
68247 +
68248 + p = strstr(mod->args, "grsec_modharden_fs");
68249 + if (p) {
68250 + char *endptr = p + strlen("grsec_modharden_fs");
68251 + /* copy \0 as well */
68252 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
68253 + is_fs_load = 1;
68254 + }
68255 +#endif
68256 +
68257 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
68258 const char *name = info->strtab + sym[i].st_name;
68259
68260 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68261 + /* it's a real shame this will never get ripped and copied
68262 + upstream! ;(
68263 + */
68264 + if (is_fs_load && !strcmp(name, "register_filesystem"))
68265 + register_filesystem_found = 1;
68266 +#endif
68267 +
68268 switch (sym[i].st_shndx) {
68269 case SHN_COMMON:
68270 /* We compiled with -fno-common. These are not
68271 @@ -1922,7 +1949,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68272 ksym = resolve_symbol_wait(mod, info, name);
68273 /* Ok if resolved. */
68274 if (ksym && !IS_ERR(ksym)) {
68275 + pax_open_kernel();
68276 sym[i].st_value = ksym->value;
68277 + pax_close_kernel();
68278 break;
68279 }
68280
68281 @@ -1941,11 +1970,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
68282 secbase = (unsigned long)mod_percpu(mod);
68283 else
68284 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
68285 + pax_open_kernel();
68286 sym[i].st_value += secbase;
68287 + pax_close_kernel();
68288 break;
68289 }
68290 }
68291
68292 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68293 + if (is_fs_load && !register_filesystem_found) {
68294 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
68295 + ret = -EPERM;
68296 + }
68297 +#endif
68298 +
68299 return ret;
68300 }
68301
68302 @@ -2049,22 +2087,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
68303 || s->sh_entsize != ~0UL
68304 || strstarts(sname, ".init"))
68305 continue;
68306 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
68307 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68308 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
68309 + else
68310 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
68311 pr_debug("\t%s\n", sname);
68312 }
68313 - switch (m) {
68314 - case 0: /* executable */
68315 - mod->core_size = debug_align(mod->core_size);
68316 - mod->core_text_size = mod->core_size;
68317 - break;
68318 - case 1: /* RO: text and ro-data */
68319 - mod->core_size = debug_align(mod->core_size);
68320 - mod->core_ro_size = mod->core_size;
68321 - break;
68322 - case 3: /* whole core */
68323 - mod->core_size = debug_align(mod->core_size);
68324 - break;
68325 - }
68326 }
68327
68328 pr_debug("Init section allocation order:\n");
68329 @@ -2078,23 +2106,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
68330 || s->sh_entsize != ~0UL
68331 || !strstarts(sname, ".init"))
68332 continue;
68333 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
68334 - | INIT_OFFSET_MASK);
68335 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
68336 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
68337 + else
68338 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
68339 + s->sh_entsize |= INIT_OFFSET_MASK;
68340 pr_debug("\t%s\n", sname);
68341 }
68342 - switch (m) {
68343 - case 0: /* executable */
68344 - mod->init_size = debug_align(mod->init_size);
68345 - mod->init_text_size = mod->init_size;
68346 - break;
68347 - case 1: /* RO: text and ro-data */
68348 - mod->init_size = debug_align(mod->init_size);
68349 - mod->init_ro_size = mod->init_size;
68350 - break;
68351 - case 3: /* whole init */
68352 - mod->init_size = debug_align(mod->init_size);
68353 - break;
68354 - }
68355 }
68356 }
68357
68358 @@ -2266,7 +2284,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68359
68360 /* Put symbol section at end of init part of module. */
68361 symsect->sh_flags |= SHF_ALLOC;
68362 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
68363 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
68364 info->index.sym) | INIT_OFFSET_MASK;
68365 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
68366
68367 @@ -2281,13 +2299,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
68368 }
68369
68370 /* Append room for core symbols at end of core part. */
68371 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
68372 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
68373 - mod->core_size += strtab_size;
68374 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
68375 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
68376 + mod->core_size_rx += strtab_size;
68377
68378 /* Put string table section at end of init part of module. */
68379 strsect->sh_flags |= SHF_ALLOC;
68380 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
68381 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
68382 info->index.str) | INIT_OFFSET_MASK;
68383 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
68384 }
68385 @@ -2305,12 +2323,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68386 /* Make sure we get permanent strtab: don't use info->strtab. */
68387 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
68388
68389 + pax_open_kernel();
68390 +
68391 /* Set types up while we still have access to sections. */
68392 for (i = 0; i < mod->num_symtab; i++)
68393 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
68394
68395 - mod->core_symtab = dst = mod->module_core + info->symoffs;
68396 - mod->core_strtab = s = mod->module_core + info->stroffs;
68397 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
68398 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
68399 src = mod->symtab;
68400 *dst = *src;
68401 *s++ = 0;
68402 @@ -2323,6 +2343,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
68403 s += strlcpy(s, &mod->strtab[src->st_name], KSYM_NAME_LEN) + 1;
68404 }
68405 mod->core_num_syms = ndst;
68406 +
68407 + pax_close_kernel();
68408 }
68409 #else
68410 static inline void layout_symtab(struct module *mod, struct load_info *info)
68411 @@ -2356,17 +2378,33 @@ void * __weak module_alloc(unsigned long size)
68412 return size == 0 ? NULL : vmalloc_exec(size);
68413 }
68414
68415 -static void *module_alloc_update_bounds(unsigned long size)
68416 +static void *module_alloc_update_bounds_rw(unsigned long size)
68417 {
68418 void *ret = module_alloc(size);
68419
68420 if (ret) {
68421 mutex_lock(&module_mutex);
68422 /* Update module bounds. */
68423 - if ((unsigned long)ret < module_addr_min)
68424 - module_addr_min = (unsigned long)ret;
68425 - if ((unsigned long)ret + size > module_addr_max)
68426 - module_addr_max = (unsigned long)ret + size;
68427 + if ((unsigned long)ret < module_addr_min_rw)
68428 + module_addr_min_rw = (unsigned long)ret;
68429 + if ((unsigned long)ret + size > module_addr_max_rw)
68430 + module_addr_max_rw = (unsigned long)ret + size;
68431 + mutex_unlock(&module_mutex);
68432 + }
68433 + return ret;
68434 +}
68435 +
68436 +static void *module_alloc_update_bounds_rx(unsigned long size)
68437 +{
68438 + void *ret = module_alloc_exec(size);
68439 +
68440 + if (ret) {
68441 + mutex_lock(&module_mutex);
68442 + /* Update module bounds. */
68443 + if ((unsigned long)ret < module_addr_min_rx)
68444 + module_addr_min_rx = (unsigned long)ret;
68445 + if ((unsigned long)ret + size > module_addr_max_rx)
68446 + module_addr_max_rx = (unsigned long)ret + size;
68447 mutex_unlock(&module_mutex);
68448 }
68449 return ret;
68450 @@ -2544,8 +2582,14 @@ static struct module *setup_load_info(struct load_info *info)
68451 static int check_modinfo(struct module *mod, struct load_info *info)
68452 {
68453 const char *modmagic = get_modinfo(info, "vermagic");
68454 + const char *license = get_modinfo(info, "license");
68455 int err;
68456
68457 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
68458 + if (!license || !license_is_gpl_compatible(license))
68459 + return -ENOEXEC;
68460 +#endif
68461 +
68462 /* This is allowed: modprobe --force will invalidate it. */
68463 if (!modmagic) {
68464 err = try_to_force_load(mod, "bad vermagic");
68465 @@ -2568,7 +2612,7 @@ static int check_modinfo(struct module *mod, struct load_info *info)
68466 }
68467
68468 /* Set up license info based on the info section */
68469 - set_license(mod, get_modinfo(info, "license"));
68470 + set_license(mod, license);
68471
68472 return 0;
68473 }
68474 @@ -2662,7 +2706,7 @@ static int move_module(struct module *mod, struct load_info *info)
68475 void *ptr;
68476
68477 /* Do the allocs. */
68478 - ptr = module_alloc_update_bounds(mod->core_size);
68479 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
68480 /*
68481 * The pointer to this block is stored in the module structure
68482 * which is inside the block. Just mark it as not being a
68483 @@ -2672,23 +2716,50 @@ static int move_module(struct module *mod, struct load_info *info)
68484 if (!ptr)
68485 return -ENOMEM;
68486
68487 - memset(ptr, 0, mod->core_size);
68488 - mod->module_core = ptr;
68489 + memset(ptr, 0, mod->core_size_rw);
68490 + mod->module_core_rw = ptr;
68491
68492 - ptr = module_alloc_update_bounds(mod->init_size);
68493 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
68494 /*
68495 * The pointer to this block is stored in the module structure
68496 * which is inside the block. This block doesn't need to be
68497 * scanned as it contains data and code that will be freed
68498 * after the module is initialized.
68499 */
68500 - kmemleak_ignore(ptr);
68501 - if (!ptr && mod->init_size) {
68502 - module_free(mod, mod->module_core);
68503 + kmemleak_not_leak(ptr);
68504 + if (!ptr && mod->init_size_rw) {
68505 + module_free(mod, mod->module_core_rw);
68506 return -ENOMEM;
68507 }
68508 - memset(ptr, 0, mod->init_size);
68509 - mod->module_init = ptr;
68510 + memset(ptr, 0, mod->init_size_rw);
68511 + mod->module_init_rw = ptr;
68512 +
68513 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
68514 + kmemleak_not_leak(ptr);
68515 + if (!ptr) {
68516 + module_free(mod, mod->module_init_rw);
68517 + module_free(mod, mod->module_core_rw);
68518 + return -ENOMEM;
68519 + }
68520 +
68521 + pax_open_kernel();
68522 + memset(ptr, 0, mod->core_size_rx);
68523 + pax_close_kernel();
68524 + mod->module_core_rx = ptr;
68525 +
68526 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
68527 + kmemleak_not_leak(ptr);
68528 + if (!ptr && mod->init_size_rx) {
68529 + module_free_exec(mod, mod->module_core_rx);
68530 + module_free(mod, mod->module_init_rw);
68531 + module_free(mod, mod->module_core_rw);
68532 + return -ENOMEM;
68533 + }
68534 +
68535 + pax_open_kernel();
68536 + memset(ptr, 0, mod->init_size_rx);
68537 + pax_close_kernel();
68538 + mod->module_init_rx = ptr;
68539
68540 /* Transfer each section which specifies SHF_ALLOC */
68541 pr_debug("final section addresses:\n");
68542 @@ -2699,16 +2770,45 @@ static int move_module(struct module *mod, struct load_info *info)
68543 if (!(shdr->sh_flags & SHF_ALLOC))
68544 continue;
68545
68546 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
68547 - dest = mod->module_init
68548 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68549 - else
68550 - dest = mod->module_core + shdr->sh_entsize;
68551 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
68552 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68553 + dest = mod->module_init_rw
68554 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68555 + else
68556 + dest = mod->module_init_rx
68557 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
68558 + } else {
68559 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
68560 + dest = mod->module_core_rw + shdr->sh_entsize;
68561 + else
68562 + dest = mod->module_core_rx + shdr->sh_entsize;
68563 + }
68564 +
68565 + if (shdr->sh_type != SHT_NOBITS) {
68566 +
68567 +#ifdef CONFIG_PAX_KERNEXEC
68568 +#ifdef CONFIG_X86_64
68569 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
68570 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
68571 +#endif
68572 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
68573 + pax_open_kernel();
68574 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68575 + pax_close_kernel();
68576 + } else
68577 +#endif
68578
68579 - if (shdr->sh_type != SHT_NOBITS)
68580 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
68581 + }
68582 /* Update sh_addr to point to copy in image. */
68583 - shdr->sh_addr = (unsigned long)dest;
68584 +
68585 +#ifdef CONFIG_PAX_KERNEXEC
68586 + if (shdr->sh_flags & SHF_EXECINSTR)
68587 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
68588 + else
68589 +#endif
68590 +
68591 + shdr->sh_addr = (unsigned long)dest;
68592 pr_debug("\t0x%lx %s\n",
68593 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
68594 }
68595 @@ -2759,12 +2859,12 @@ static void flush_module_icache(const struct module *mod)
68596 * Do it before processing of module parameters, so the module
68597 * can provide parameter accessor functions of its own.
68598 */
68599 - if (mod->module_init)
68600 - flush_icache_range((unsigned long)mod->module_init,
68601 - (unsigned long)mod->module_init
68602 - + mod->init_size);
68603 - flush_icache_range((unsigned long)mod->module_core,
68604 - (unsigned long)mod->module_core + mod->core_size);
68605 + if (mod->module_init_rx)
68606 + flush_icache_range((unsigned long)mod->module_init_rx,
68607 + (unsigned long)mod->module_init_rx
68608 + + mod->init_size_rx);
68609 + flush_icache_range((unsigned long)mod->module_core_rx,
68610 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
68611
68612 set_fs(old_fs);
68613 }
68614 @@ -2834,8 +2934,10 @@ out:
68615 static void module_deallocate(struct module *mod, struct load_info *info)
68616 {
68617 percpu_modfree(mod);
68618 - module_free(mod, mod->module_init);
68619 - module_free(mod, mod->module_core);
68620 + module_free_exec(mod, mod->module_init_rx);
68621 + module_free_exec(mod, mod->module_core_rx);
68622 + module_free(mod, mod->module_init_rw);
68623 + module_free(mod, mod->module_core_rw);
68624 }
68625
68626 int __weak module_finalize(const Elf_Ehdr *hdr,
68627 @@ -2848,7 +2950,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
68628 static int post_relocation(struct module *mod, const struct load_info *info)
68629 {
68630 /* Sort exception table now relocations are done. */
68631 + pax_open_kernel();
68632 sort_extable(mod->extable, mod->extable + mod->num_exentries);
68633 + pax_close_kernel();
68634
68635 /* Copy relocated percpu area over. */
68636 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
68637 @@ -2899,9 +3003,38 @@ static struct module *load_module(void __user *umod,
68638 if (err)
68639 goto free_unload;
68640
68641 + /* Now copy in args */
68642 + mod->args = strndup_user(uargs, ~0UL >> 1);
68643 + if (IS_ERR(mod->args)) {
68644 + err = PTR_ERR(mod->args);
68645 + goto free_unload;
68646 + }
68647 +
68648 /* Set up MODINFO_ATTR fields */
68649 setup_modinfo(mod, &info);
68650
68651 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
68652 + {
68653 + char *p, *p2;
68654 +
68655 + if (strstr(mod->args, "grsec_modharden_netdev")) {
68656 + 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);
68657 + err = -EPERM;
68658 + goto free_modinfo;
68659 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
68660 + p += strlen("grsec_modharden_normal");
68661 + p2 = strstr(p, "_");
68662 + if (p2) {
68663 + *p2 = '\0';
68664 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
68665 + *p2 = '_';
68666 + }
68667 + err = -EPERM;
68668 + goto free_modinfo;
68669 + }
68670 + }
68671 +#endif
68672 +
68673 /* Fix up syms, so that st_value is a pointer to location. */
68674 err = simplify_symbols(mod, &info);
68675 if (err < 0)
68676 @@ -2917,13 +3050,6 @@ static struct module *load_module(void __user *umod,
68677
68678 flush_module_icache(mod);
68679
68680 - /* Now copy in args */
68681 - mod->args = strndup_user(uargs, ~0UL >> 1);
68682 - if (IS_ERR(mod->args)) {
68683 - err = PTR_ERR(mod->args);
68684 - goto free_arch_cleanup;
68685 - }
68686 -
68687 /* Mark state as coming so strong_try_module_get() ignores us. */
68688 mod->state = MODULE_STATE_COMING;
68689
68690 @@ -2981,11 +3107,10 @@ static struct module *load_module(void __user *umod,
68691 unlock:
68692 mutex_unlock(&module_mutex);
68693 synchronize_sched();
68694 - kfree(mod->args);
68695 - free_arch_cleanup:
68696 module_arch_cleanup(mod);
68697 free_modinfo:
68698 free_modinfo(mod);
68699 + kfree(mod->args);
68700 free_unload:
68701 module_unload_free(mod);
68702 free_module:
68703 @@ -3026,16 +3151,16 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68704 MODULE_STATE_COMING, mod);
68705
68706 /* Set RO and NX regions for core */
68707 - set_section_ro_nx(mod->module_core,
68708 - mod->core_text_size,
68709 - mod->core_ro_size,
68710 - mod->core_size);
68711 + set_section_ro_nx(mod->module_core_rx,
68712 + mod->core_size_rx,
68713 + mod->core_size_rx,
68714 + mod->core_size_rx);
68715
68716 /* Set RO and NX regions for init */
68717 - set_section_ro_nx(mod->module_init,
68718 - mod->init_text_size,
68719 - mod->init_ro_size,
68720 - mod->init_size);
68721 + set_section_ro_nx(mod->module_init_rx,
68722 + mod->init_size_rx,
68723 + mod->init_size_rx,
68724 + mod->init_size_rx);
68725
68726 do_mod_ctors(mod);
68727 /* Start the module */
68728 @@ -3081,11 +3206,12 @@ SYSCALL_DEFINE3(init_module, void __user *, umod,
68729 mod->strtab = mod->core_strtab;
68730 #endif
68731 unset_module_init_ro_nx(mod);
68732 - module_free(mod, mod->module_init);
68733 - mod->module_init = NULL;
68734 - mod->init_size = 0;
68735 - mod->init_ro_size = 0;
68736 - mod->init_text_size = 0;
68737 + module_free(mod, mod->module_init_rw);
68738 + module_free_exec(mod, mod->module_init_rx);
68739 + mod->module_init_rw = NULL;
68740 + mod->module_init_rx = NULL;
68741 + mod->init_size_rw = 0;
68742 + mod->init_size_rx = 0;
68743 mutex_unlock(&module_mutex);
68744
68745 return 0;
68746 @@ -3116,10 +3242,16 @@ static const char *get_ksymbol(struct module *mod,
68747 unsigned long nextval;
68748
68749 /* At worse, next value is at end of module */
68750 - if (within_module_init(addr, mod))
68751 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
68752 + if (within_module_init_rx(addr, mod))
68753 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
68754 + else if (within_module_init_rw(addr, mod))
68755 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
68756 + else if (within_module_core_rx(addr, mod))
68757 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
68758 + else if (within_module_core_rw(addr, mod))
68759 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
68760 else
68761 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
68762 + return NULL;
68763
68764 /* Scan for closest preceding symbol, and next symbol. (ELF
68765 starts real symbols at 1). */
68766 @@ -3354,7 +3486,7 @@ static int m_show(struct seq_file *m, void *p)
68767 char buf[8];
68768
68769 seq_printf(m, "%s %u",
68770 - mod->name, mod->init_size + mod->core_size);
68771 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
68772 print_unload_info(m, mod);
68773
68774 /* Informative for users. */
68775 @@ -3363,7 +3495,7 @@ static int m_show(struct seq_file *m, void *p)
68776 mod->state == MODULE_STATE_COMING ? "Loading":
68777 "Live");
68778 /* Used by oprofile and other similar tools. */
68779 - seq_printf(m, " 0x%pK", mod->module_core);
68780 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
68781
68782 /* Taints info */
68783 if (mod->taints)
68784 @@ -3399,7 +3531,17 @@ static const struct file_operations proc_modules_operations = {
68785
68786 static int __init proc_modules_init(void)
68787 {
68788 +#ifndef CONFIG_GRKERNSEC_HIDESYM
68789 +#ifdef CONFIG_GRKERNSEC_PROC_USER
68790 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68791 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
68792 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
68793 +#else
68794 proc_create("modules", 0, NULL, &proc_modules_operations);
68795 +#endif
68796 +#else
68797 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
68798 +#endif
68799 return 0;
68800 }
68801 module_init(proc_modules_init);
68802 @@ -3458,12 +3600,12 @@ struct module *__module_address(unsigned long addr)
68803 {
68804 struct module *mod;
68805
68806 - if (addr < module_addr_min || addr > module_addr_max)
68807 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
68808 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
68809 return NULL;
68810
68811 list_for_each_entry_rcu(mod, &modules, list)
68812 - if (within_module_core(addr, mod)
68813 - || within_module_init(addr, mod))
68814 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
68815 return mod;
68816 return NULL;
68817 }
68818 @@ -3497,11 +3639,20 @@ bool is_module_text_address(unsigned long addr)
68819 */
68820 struct module *__module_text_address(unsigned long addr)
68821 {
68822 - struct module *mod = __module_address(addr);
68823 + struct module *mod;
68824 +
68825 +#ifdef CONFIG_X86_32
68826 + addr = ktla_ktva(addr);
68827 +#endif
68828 +
68829 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
68830 + return NULL;
68831 +
68832 + mod = __module_address(addr);
68833 +
68834 if (mod) {
68835 /* Make sure it's within the text section. */
68836 - if (!within(addr, mod->module_init, mod->init_text_size)
68837 - && !within(addr, mod->module_core, mod->core_text_size))
68838 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
68839 mod = NULL;
68840 }
68841 return mod;
68842 diff --git a/kernel/mutex-debug.c b/kernel/mutex-debug.c
68843 index 7e3443f..b2a1e6b 100644
68844 --- a/kernel/mutex-debug.c
68845 +++ b/kernel/mutex-debug.c
68846 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
68847 }
68848
68849 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68850 - struct thread_info *ti)
68851 + struct task_struct *task)
68852 {
68853 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
68854
68855 /* Mark the current thread as blocked on the lock: */
68856 - ti->task->blocked_on = waiter;
68857 + task->blocked_on = waiter;
68858 }
68859
68860 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68861 - struct thread_info *ti)
68862 + struct task_struct *task)
68863 {
68864 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
68865 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
68866 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
68867 - ti->task->blocked_on = NULL;
68868 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
68869 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
68870 + task->blocked_on = NULL;
68871
68872 list_del_init(&waiter->list);
68873 waiter->task = NULL;
68874 diff --git a/kernel/mutex-debug.h b/kernel/mutex-debug.h
68875 index 0799fd3..d06ae3b 100644
68876 --- a/kernel/mutex-debug.h
68877 +++ b/kernel/mutex-debug.h
68878 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
68879 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
68880 extern void debug_mutex_add_waiter(struct mutex *lock,
68881 struct mutex_waiter *waiter,
68882 - struct thread_info *ti);
68883 + struct task_struct *task);
68884 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
68885 - struct thread_info *ti);
68886 + struct task_struct *task);
68887 extern void debug_mutex_unlock(struct mutex *lock);
68888 extern void debug_mutex_init(struct mutex *lock, const char *name,
68889 struct lock_class_key *key);
68890 diff --git a/kernel/mutex.c b/kernel/mutex.c
68891 index a307cc9..27fd2e9 100644
68892 --- a/kernel/mutex.c
68893 +++ b/kernel/mutex.c
68894 @@ -198,7 +198,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68895 spin_lock_mutex(&lock->wait_lock, flags);
68896
68897 debug_mutex_lock_common(lock, &waiter);
68898 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
68899 + debug_mutex_add_waiter(lock, &waiter, task);
68900
68901 /* add waiting tasks to the end of the waitqueue (FIFO): */
68902 list_add_tail(&waiter.list, &lock->wait_list);
68903 @@ -227,8 +227,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68904 * TASK_UNINTERRUPTIBLE case.)
68905 */
68906 if (unlikely(signal_pending_state(state, task))) {
68907 - mutex_remove_waiter(lock, &waiter,
68908 - task_thread_info(task));
68909 + mutex_remove_waiter(lock, &waiter, task);
68910 mutex_release(&lock->dep_map, 1, ip);
68911 spin_unlock_mutex(&lock->wait_lock, flags);
68912
68913 @@ -247,7 +246,7 @@ __mutex_lock_common(struct mutex *lock, long state, unsigned int subclass,
68914 done:
68915 lock_acquired(&lock->dep_map, ip);
68916 /* got the lock - rejoice! */
68917 - mutex_remove_waiter(lock, &waiter, current_thread_info());
68918 + mutex_remove_waiter(lock, &waiter, task);
68919 mutex_set_owner(lock);
68920
68921 /* set it to 0 if there are no waiters left: */
68922 diff --git a/kernel/panic.c b/kernel/panic.c
68923 index d2a5f4e..5edc1d9 100644
68924 --- a/kernel/panic.c
68925 +++ b/kernel/panic.c
68926 @@ -75,6 +75,14 @@ void panic(const char *fmt, ...)
68927 int state = 0;
68928
68929 /*
68930 + * Disable local interrupts. This will prevent panic_smp_self_stop
68931 + * from deadlocking the first cpu that invokes the panic, since
68932 + * there is nothing to prevent an interrupt handler (that runs
68933 + * after the panic_lock is acquired) from invoking panic again.
68934 + */
68935 + local_irq_disable();
68936 +
68937 + /*
68938 * It's possible to come here directly from a panic-assertion and
68939 * not have preempt disabled. Some functions called from here want
68940 * preempt to be disabled. No point enabling it later though...
68941 @@ -402,7 +410,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
68942 const char *board;
68943
68944 printk(KERN_WARNING "------------[ cut here ]------------\n");
68945 - printk(KERN_WARNING "WARNING: at %s:%d %pS()\n", file, line, caller);
68946 + printk(KERN_WARNING "WARNING: at %s:%d %pA()\n", file, line, caller);
68947 board = dmi_get_system_info(DMI_PRODUCT_NAME);
68948 if (board)
68949 printk(KERN_WARNING "Hardware name: %s\n", board);
68950 @@ -457,7 +465,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
68951 */
68952 void __stack_chk_fail(void)
68953 {
68954 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
68955 + dump_stack();
68956 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
68957 __builtin_return_address(0));
68958 }
68959 EXPORT_SYMBOL(__stack_chk_fail);
68960 diff --git a/kernel/pid.c b/kernel/pid.c
68961 index e86b291a..e8b0fb5 100644
68962 --- a/kernel/pid.c
68963 +++ b/kernel/pid.c
68964 @@ -33,6 +33,7 @@
68965 #include <linux/rculist.h>
68966 #include <linux/bootmem.h>
68967 #include <linux/hash.h>
68968 +#include <linux/security.h>
68969 #include <linux/pid_namespace.h>
68970 #include <linux/init_task.h>
68971 #include <linux/syscalls.h>
68972 @@ -45,7 +46,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
68973
68974 int pid_max = PID_MAX_DEFAULT;
68975
68976 -#define RESERVED_PIDS 300
68977 +#define RESERVED_PIDS 500
68978
68979 int pid_max_min = RESERVED_PIDS + 1;
68980 int pid_max_max = PID_MAX_LIMIT;
68981 @@ -420,10 +421,18 @@ EXPORT_SYMBOL(pid_task);
68982 */
68983 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
68984 {
68985 + struct task_struct *task;
68986 +
68987 rcu_lockdep_assert(rcu_read_lock_held(),
68988 "find_task_by_pid_ns() needs rcu_read_lock()"
68989 " protection");
68990 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68991 +
68992 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
68993 +
68994 + if (gr_pid_is_chrooted(task))
68995 + return NULL;
68996 +
68997 + return task;
68998 }
68999
69000 struct task_struct *find_task_by_vpid(pid_t vnr)
69001 @@ -431,6 +440,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
69002 return find_task_by_pid_ns(vnr, current->nsproxy->pid_ns);
69003 }
69004
69005 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
69006 +{
69007 + rcu_lockdep_assert(rcu_read_lock_held(),
69008 + "find_task_by_pid_ns() needs rcu_read_lock()"
69009 + " protection");
69010 + return pid_task(find_pid_ns(vnr, current->nsproxy->pid_ns), PIDTYPE_PID);
69011 +}
69012 +
69013 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
69014 {
69015 struct pid *pid;
69016 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
69017 index b3c7fd5..6144bab 100644
69018 --- a/kernel/pid_namespace.c
69019 +++ b/kernel/pid_namespace.c
69020 @@ -232,15 +232,19 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
69021 */
69022
69023 tmp.data = &current->nsproxy->pid_ns->last_pid;
69024 - return proc_dointvec(&tmp, write, buffer, lenp, ppos);
69025 + return proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
69026 }
69027
69028 +extern int pid_max;
69029 +static int zero = 0;
69030 static struct ctl_table pid_ns_ctl_table[] = {
69031 {
69032 .procname = "ns_last_pid",
69033 .maxlen = sizeof(int),
69034 .mode = 0666, /* permissions are checked in the handler */
69035 .proc_handler = pid_ns_ctl_handler,
69036 + .extra1 = &zero,
69037 + .extra2 = &pid_max,
69038 },
69039 { }
69040 };
69041 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
69042 index 125cb67..a4d1c30 100644
69043 --- a/kernel/posix-cpu-timers.c
69044 +++ b/kernel/posix-cpu-timers.c
69045 @@ -6,6 +6,7 @@
69046 #include <linux/posix-timers.h>
69047 #include <linux/errno.h>
69048 #include <linux/math64.h>
69049 +#include <linux/security.h>
69050 #include <asm/uaccess.h>
69051 #include <linux/kernel_stat.h>
69052 #include <trace/events/timer.h>
69053 @@ -1578,14 +1579,14 @@ struct k_clock clock_posix_cpu = {
69054
69055 static __init int init_posix_cpu_timers(void)
69056 {
69057 - struct k_clock process = {
69058 + static struct k_clock process = {
69059 .clock_getres = process_cpu_clock_getres,
69060 .clock_get = process_cpu_clock_get,
69061 .timer_create = process_cpu_timer_create,
69062 .nsleep = process_cpu_nsleep,
69063 .nsleep_restart = process_cpu_nsleep_restart,
69064 };
69065 - struct k_clock thread = {
69066 + static struct k_clock thread = {
69067 .clock_getres = thread_cpu_clock_getres,
69068 .clock_get = thread_cpu_clock_get,
69069 .timer_create = thread_cpu_timer_create,
69070 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
69071 index 69185ae..cc2847a 100644
69072 --- a/kernel/posix-timers.c
69073 +++ b/kernel/posix-timers.c
69074 @@ -43,6 +43,7 @@
69075 #include <linux/idr.h>
69076 #include <linux/posix-clock.h>
69077 #include <linux/posix-timers.h>
69078 +#include <linux/grsecurity.h>
69079 #include <linux/syscalls.h>
69080 #include <linux/wait.h>
69081 #include <linux/workqueue.h>
69082 @@ -129,7 +130,7 @@ static DEFINE_SPINLOCK(idr_lock);
69083 * which we beg off on and pass to do_sys_settimeofday().
69084 */
69085
69086 -static struct k_clock posix_clocks[MAX_CLOCKS];
69087 +static struct k_clock *posix_clocks[MAX_CLOCKS];
69088
69089 /*
69090 * These ones are defined below.
69091 @@ -227,7 +228,7 @@ static int posix_get_boottime(const clockid_t which_clock, struct timespec *tp)
69092 */
69093 static __init int init_posix_timers(void)
69094 {
69095 - struct k_clock clock_realtime = {
69096 + static struct k_clock clock_realtime = {
69097 .clock_getres = hrtimer_get_res,
69098 .clock_get = posix_clock_realtime_get,
69099 .clock_set = posix_clock_realtime_set,
69100 @@ -239,7 +240,7 @@ static __init int init_posix_timers(void)
69101 .timer_get = common_timer_get,
69102 .timer_del = common_timer_del,
69103 };
69104 - struct k_clock clock_monotonic = {
69105 + static struct k_clock clock_monotonic = {
69106 .clock_getres = hrtimer_get_res,
69107 .clock_get = posix_ktime_get_ts,
69108 .nsleep = common_nsleep,
69109 @@ -249,19 +250,19 @@ static __init int init_posix_timers(void)
69110 .timer_get = common_timer_get,
69111 .timer_del = common_timer_del,
69112 };
69113 - struct k_clock clock_monotonic_raw = {
69114 + static struct k_clock clock_monotonic_raw = {
69115 .clock_getres = hrtimer_get_res,
69116 .clock_get = posix_get_monotonic_raw,
69117 };
69118 - struct k_clock clock_realtime_coarse = {
69119 + static struct k_clock clock_realtime_coarse = {
69120 .clock_getres = posix_get_coarse_res,
69121 .clock_get = posix_get_realtime_coarse,
69122 };
69123 - struct k_clock clock_monotonic_coarse = {
69124 + static struct k_clock clock_monotonic_coarse = {
69125 .clock_getres = posix_get_coarse_res,
69126 .clock_get = posix_get_monotonic_coarse,
69127 };
69128 - struct k_clock clock_boottime = {
69129 + static struct k_clock clock_boottime = {
69130 .clock_getres = hrtimer_get_res,
69131 .clock_get = posix_get_boottime,
69132 .nsleep = common_nsleep,
69133 @@ -473,7 +474,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
69134 return;
69135 }
69136
69137 - posix_clocks[clock_id] = *new_clock;
69138 + posix_clocks[clock_id] = new_clock;
69139 }
69140 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
69141
69142 @@ -519,9 +520,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
69143 return (id & CLOCKFD_MASK) == CLOCKFD ?
69144 &clock_posix_dynamic : &clock_posix_cpu;
69145
69146 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
69147 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
69148 return NULL;
69149 - return &posix_clocks[id];
69150 + return posix_clocks[id];
69151 }
69152
69153 static int common_timer_create(struct k_itimer *new_timer)
69154 @@ -959,6 +960,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
69155 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
69156 return -EFAULT;
69157
69158 + /* only the CLOCK_REALTIME clock can be set, all other clocks
69159 + have their clock_set fptr set to a nosettime dummy function
69160 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
69161 + call common_clock_set, which calls do_sys_settimeofday, which
69162 + we hook
69163 + */
69164 +
69165 return kc->clock_set(which_clock, &new_tp);
69166 }
69167
69168 diff --git a/kernel/power/poweroff.c b/kernel/power/poweroff.c
69169 index d523593..68197a4 100644
69170 --- a/kernel/power/poweroff.c
69171 +++ b/kernel/power/poweroff.c
69172 @@ -37,7 +37,7 @@ static struct sysrq_key_op sysrq_poweroff_op = {
69173 .enable_mask = SYSRQ_ENABLE_BOOT,
69174 };
69175
69176 -static int pm_sysrq_init(void)
69177 +static int __init pm_sysrq_init(void)
69178 {
69179 register_sysrq_key('o', &sysrq_poweroff_op);
69180 return 0;
69181 diff --git a/kernel/power/process.c b/kernel/power/process.c
69182 index 19db29f..33b52b6 100644
69183 --- a/kernel/power/process.c
69184 +++ b/kernel/power/process.c
69185 @@ -33,6 +33,7 @@ static int try_to_freeze_tasks(bool user_only)
69186 u64 elapsed_csecs64;
69187 unsigned int elapsed_csecs;
69188 bool wakeup = false;
69189 + bool timedout = false;
69190
69191 do_gettimeofday(&start);
69192
69193 @@ -43,6 +44,8 @@ static int try_to_freeze_tasks(bool user_only)
69194
69195 while (true) {
69196 todo = 0;
69197 + if (time_after(jiffies, end_time))
69198 + timedout = true;
69199 read_lock(&tasklist_lock);
69200 do_each_thread(g, p) {
69201 if (p == current || !freeze_task(p))
69202 @@ -58,9 +61,13 @@ static int try_to_freeze_tasks(bool user_only)
69203 * guaranteed that TASK_STOPPED/TRACED -> TASK_RUNNING
69204 * transition can't race with task state testing here.
69205 */
69206 - if (!task_is_stopped_or_traced(p) &&
69207 - !freezer_should_skip(p))
69208 + if (!task_is_stopped_or_traced(p) && !freezer_should_skip(p)) {
69209 todo++;
69210 + if (timedout) {
69211 + printk(KERN_ERR "Task refusing to freeze:\n");
69212 + sched_show_task(p);
69213 + }
69214 + }
69215 } while_each_thread(g, p);
69216 read_unlock(&tasklist_lock);
69217
69218 @@ -69,7 +76,7 @@ static int try_to_freeze_tasks(bool user_only)
69219 todo += wq_busy;
69220 }
69221
69222 - if (!todo || time_after(jiffies, end_time))
69223 + if (!todo || timedout)
69224 break;
69225
69226 if (pm_wakeup_pending()) {
69227 diff --git a/kernel/printk.c b/kernel/printk.c
69228 index 146827f..a501fec 100644
69229 --- a/kernel/printk.c
69230 +++ b/kernel/printk.c
69231 @@ -782,6 +782,11 @@ static int check_syslog_permissions(int type, bool from_file)
69232 if (from_file && type != SYSLOG_ACTION_OPEN)
69233 return 0;
69234
69235 +#ifdef CONFIG_GRKERNSEC_DMESG
69236 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
69237 + return -EPERM;
69238 +#endif
69239 +
69240 if (syslog_action_restricted(type)) {
69241 if (capable(CAP_SYSLOG))
69242 return 0;
69243 diff --git a/kernel/profile.c b/kernel/profile.c
69244 index 76b8e77..a2930e8 100644
69245 --- a/kernel/profile.c
69246 +++ b/kernel/profile.c
69247 @@ -39,7 +39,7 @@ struct profile_hit {
69248 /* Oprofile timer tick hook */
69249 static int (*timer_hook)(struct pt_regs *) __read_mostly;
69250
69251 -static atomic_t *prof_buffer;
69252 +static atomic_unchecked_t *prof_buffer;
69253 static unsigned long prof_len, prof_shift;
69254
69255 int prof_on __read_mostly;
69256 @@ -281,7 +281,7 @@ static void profile_flip_buffers(void)
69257 hits[i].pc = 0;
69258 continue;
69259 }
69260 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69261 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69262 hits[i].hits = hits[i].pc = 0;
69263 }
69264 }
69265 @@ -342,9 +342,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69266 * Add the current hit(s) and flush the write-queue out
69267 * to the global buffer:
69268 */
69269 - atomic_add(nr_hits, &prof_buffer[pc]);
69270 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
69271 for (i = 0; i < NR_PROFILE_HIT; ++i) {
69272 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
69273 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
69274 hits[i].pc = hits[i].hits = 0;
69275 }
69276 out:
69277 @@ -419,7 +419,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
69278 {
69279 unsigned long pc;
69280 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
69281 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69282 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
69283 }
69284 #endif /* !CONFIG_SMP */
69285
69286 @@ -517,7 +517,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
69287 return -EFAULT;
69288 buf++; p++; count--; read++;
69289 }
69290 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
69291 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
69292 if (copy_to_user(buf, (void *)pnt, count))
69293 return -EFAULT;
69294 read += count;
69295 @@ -548,7 +548,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
69296 }
69297 #endif
69298 profile_discard_flip_buffers();
69299 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
69300 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
69301 return count;
69302 }
69303
69304 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
69305 index a232bb5..2a65ef9 100644
69306 --- a/kernel/ptrace.c
69307 +++ b/kernel/ptrace.c
69308 @@ -279,7 +279,7 @@ static int ptrace_attach(struct task_struct *task, long request,
69309
69310 if (seize)
69311 flags |= PT_SEIZED;
69312 - if (ns_capable(task_user_ns(task), CAP_SYS_PTRACE))
69313 + if (ns_capable_nolog(task_user_ns(task), CAP_SYS_PTRACE))
69314 flags |= PT_PTRACE_CAP;
69315 task->ptrace = flags;
69316
69317 @@ -486,7 +486,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
69318 break;
69319 return -EIO;
69320 }
69321 - if (copy_to_user(dst, buf, retval))
69322 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
69323 return -EFAULT;
69324 copied += retval;
69325 src += retval;
69326 @@ -671,7 +671,7 @@ int ptrace_request(struct task_struct *child, long request,
69327 bool seized = child->ptrace & PT_SEIZED;
69328 int ret = -EIO;
69329 siginfo_t siginfo, *si;
69330 - void __user *datavp = (void __user *) data;
69331 + void __user *datavp = (__force void __user *) data;
69332 unsigned long __user *datalp = datavp;
69333 unsigned long flags;
69334
69335 @@ -873,14 +873,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
69336 goto out;
69337 }
69338
69339 + if (gr_handle_ptrace(child, request)) {
69340 + ret = -EPERM;
69341 + goto out_put_task_struct;
69342 + }
69343 +
69344 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69345 ret = ptrace_attach(child, request, addr, data);
69346 /*
69347 * Some architectures need to do book-keeping after
69348 * a ptrace attach.
69349 */
69350 - if (!ret)
69351 + if (!ret) {
69352 arch_ptrace_attach(child);
69353 + gr_audit_ptrace(child);
69354 + }
69355 goto out_put_task_struct;
69356 }
69357
69358 @@ -906,7 +913,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
69359 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
69360 if (copied != sizeof(tmp))
69361 return -EIO;
69362 - return put_user(tmp, (unsigned long __user *)data);
69363 + return put_user(tmp, (__force unsigned long __user *)data);
69364 }
69365
69366 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
69367 @@ -1016,14 +1023,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
69368 goto out;
69369 }
69370
69371 + if (gr_handle_ptrace(child, request)) {
69372 + ret = -EPERM;
69373 + goto out_put_task_struct;
69374 + }
69375 +
69376 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
69377 ret = ptrace_attach(child, request, addr, data);
69378 /*
69379 * Some architectures need to do book-keeping after
69380 * a ptrace attach.
69381 */
69382 - if (!ret)
69383 + if (!ret) {
69384 arch_ptrace_attach(child);
69385 + gr_audit_ptrace(child);
69386 + }
69387 goto out_put_task_struct;
69388 }
69389
69390 diff --git a/kernel/rcutiny.c b/kernel/rcutiny.c
69391 index 37a5444..eec170a 100644
69392 --- a/kernel/rcutiny.c
69393 +++ b/kernel/rcutiny.c
69394 @@ -46,7 +46,7 @@
69395 struct rcu_ctrlblk;
69396 static void invoke_rcu_callbacks(void);
69397 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
69398 -static void rcu_process_callbacks(struct softirq_action *unused);
69399 +static void rcu_process_callbacks(void);
69400 static void __call_rcu(struct rcu_head *head,
69401 void (*func)(struct rcu_head *rcu),
69402 struct rcu_ctrlblk *rcp);
69403 @@ -307,7 +307,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
69404 rcu_is_callbacks_kthread()));
69405 }
69406
69407 -static void rcu_process_callbacks(struct softirq_action *unused)
69408 +static void rcu_process_callbacks(void)
69409 {
69410 __rcu_process_callbacks(&rcu_sched_ctrlblk);
69411 __rcu_process_callbacks(&rcu_bh_ctrlblk);
69412 diff --git a/kernel/rcutiny_plugin.h b/kernel/rcutiny_plugin.h
69413 index fc31a2d..be2ec04 100644
69414 --- a/kernel/rcutiny_plugin.h
69415 +++ b/kernel/rcutiny_plugin.h
69416 @@ -939,7 +939,7 @@ static int rcu_kthread(void *arg)
69417 have_rcu_kthread_work = morework;
69418 local_irq_restore(flags);
69419 if (work)
69420 - rcu_process_callbacks(NULL);
69421 + rcu_process_callbacks();
69422 schedule_timeout_interruptible(1); /* Leave CPU for others. */
69423 }
69424
69425 diff --git a/kernel/rcutorture.c b/kernel/rcutorture.c
69426 index e66b34a..4b8b626 100644
69427 --- a/kernel/rcutorture.c
69428 +++ b/kernel/rcutorture.c
69429 @@ -163,12 +163,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
69430 { 0 };
69431 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
69432 { 0 };
69433 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69434 -static atomic_t n_rcu_torture_alloc;
69435 -static atomic_t n_rcu_torture_alloc_fail;
69436 -static atomic_t n_rcu_torture_free;
69437 -static atomic_t n_rcu_torture_mberror;
69438 -static atomic_t n_rcu_torture_error;
69439 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
69440 +static atomic_unchecked_t n_rcu_torture_alloc;
69441 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
69442 +static atomic_unchecked_t n_rcu_torture_free;
69443 +static atomic_unchecked_t n_rcu_torture_mberror;
69444 +static atomic_unchecked_t n_rcu_torture_error;
69445 static long n_rcu_torture_barrier_error;
69446 static long n_rcu_torture_boost_ktrerror;
69447 static long n_rcu_torture_boost_rterror;
69448 @@ -265,11 +265,11 @@ rcu_torture_alloc(void)
69449
69450 spin_lock_bh(&rcu_torture_lock);
69451 if (list_empty(&rcu_torture_freelist)) {
69452 - atomic_inc(&n_rcu_torture_alloc_fail);
69453 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
69454 spin_unlock_bh(&rcu_torture_lock);
69455 return NULL;
69456 }
69457 - atomic_inc(&n_rcu_torture_alloc);
69458 + atomic_inc_unchecked(&n_rcu_torture_alloc);
69459 p = rcu_torture_freelist.next;
69460 list_del_init(p);
69461 spin_unlock_bh(&rcu_torture_lock);
69462 @@ -282,7 +282,7 @@ rcu_torture_alloc(void)
69463 static void
69464 rcu_torture_free(struct rcu_torture *p)
69465 {
69466 - atomic_inc(&n_rcu_torture_free);
69467 + atomic_inc_unchecked(&n_rcu_torture_free);
69468 spin_lock_bh(&rcu_torture_lock);
69469 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
69470 spin_unlock_bh(&rcu_torture_lock);
69471 @@ -403,7 +403,7 @@ rcu_torture_cb(struct rcu_head *p)
69472 i = rp->rtort_pipe_count;
69473 if (i > RCU_TORTURE_PIPE_LEN)
69474 i = RCU_TORTURE_PIPE_LEN;
69475 - atomic_inc(&rcu_torture_wcount[i]);
69476 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69477 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69478 rp->rtort_mbtest = 0;
69479 rcu_torture_free(rp);
69480 @@ -451,7 +451,7 @@ static void rcu_sync_torture_deferred_free(struct rcu_torture *p)
69481 i = rp->rtort_pipe_count;
69482 if (i > RCU_TORTURE_PIPE_LEN)
69483 i = RCU_TORTURE_PIPE_LEN;
69484 - atomic_inc(&rcu_torture_wcount[i]);
69485 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69486 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
69487 rp->rtort_mbtest = 0;
69488 list_del(&rp->rtort_free);
69489 @@ -983,7 +983,7 @@ rcu_torture_writer(void *arg)
69490 i = old_rp->rtort_pipe_count;
69491 if (i > RCU_TORTURE_PIPE_LEN)
69492 i = RCU_TORTURE_PIPE_LEN;
69493 - atomic_inc(&rcu_torture_wcount[i]);
69494 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
69495 old_rp->rtort_pipe_count++;
69496 cur_ops->deferred_free(old_rp);
69497 }
69498 @@ -1064,7 +1064,7 @@ static void rcu_torture_timer(unsigned long unused)
69499 }
69500 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69501 if (p->rtort_mbtest == 0)
69502 - atomic_inc(&n_rcu_torture_mberror);
69503 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69504 spin_lock(&rand_lock);
69505 cur_ops->read_delay(&rand);
69506 n_rcu_torture_timers++;
69507 @@ -1128,7 +1128,7 @@ rcu_torture_reader(void *arg)
69508 }
69509 do_trace_rcu_torture_read(cur_ops->name, &p->rtort_rcu);
69510 if (p->rtort_mbtest == 0)
69511 - atomic_inc(&n_rcu_torture_mberror);
69512 + atomic_inc_unchecked(&n_rcu_torture_mberror);
69513 cur_ops->read_delay(&rand);
69514 preempt_disable();
69515 pipe_count = p->rtort_pipe_count;
69516 @@ -1191,10 +1191,10 @@ rcu_torture_printk(char *page)
69517 rcu_torture_current,
69518 rcu_torture_current_version,
69519 list_empty(&rcu_torture_freelist),
69520 - atomic_read(&n_rcu_torture_alloc),
69521 - atomic_read(&n_rcu_torture_alloc_fail),
69522 - atomic_read(&n_rcu_torture_free),
69523 - atomic_read(&n_rcu_torture_mberror),
69524 + atomic_read_unchecked(&n_rcu_torture_alloc),
69525 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
69526 + atomic_read_unchecked(&n_rcu_torture_free),
69527 + atomic_read_unchecked(&n_rcu_torture_mberror),
69528 n_rcu_torture_boost_ktrerror,
69529 n_rcu_torture_boost_rterror,
69530 n_rcu_torture_boost_failure,
69531 @@ -1208,14 +1208,14 @@ rcu_torture_printk(char *page)
69532 n_barrier_attempts,
69533 n_rcu_torture_barrier_error);
69534 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
69535 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
69536 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
69537 n_rcu_torture_barrier_error != 0 ||
69538 n_rcu_torture_boost_ktrerror != 0 ||
69539 n_rcu_torture_boost_rterror != 0 ||
69540 n_rcu_torture_boost_failure != 0 ||
69541 i > 1) {
69542 cnt += sprintf(&page[cnt], "!!! ");
69543 - atomic_inc(&n_rcu_torture_error);
69544 + atomic_inc_unchecked(&n_rcu_torture_error);
69545 WARN_ON_ONCE(1);
69546 }
69547 cnt += sprintf(&page[cnt], "Reader Pipe: ");
69548 @@ -1229,7 +1229,7 @@ rcu_torture_printk(char *page)
69549 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
69550 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69551 cnt += sprintf(&page[cnt], " %d",
69552 - atomic_read(&rcu_torture_wcount[i]));
69553 + atomic_read_unchecked(&rcu_torture_wcount[i]));
69554 }
69555 cnt += sprintf(&page[cnt], "\n");
69556 if (cur_ops->stats)
69557 @@ -1888,7 +1888,7 @@ rcu_torture_cleanup(void)
69558
69559 if (cur_ops->cleanup)
69560 cur_ops->cleanup();
69561 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69562 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
69563 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
69564 else if (n_online_successes != n_online_attempts ||
69565 n_offline_successes != n_offline_attempts)
69566 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
69567
69568 rcu_torture_current = NULL;
69569 rcu_torture_current_version = 0;
69570 - atomic_set(&n_rcu_torture_alloc, 0);
69571 - atomic_set(&n_rcu_torture_alloc_fail, 0);
69572 - atomic_set(&n_rcu_torture_free, 0);
69573 - atomic_set(&n_rcu_torture_mberror, 0);
69574 - atomic_set(&n_rcu_torture_error, 0);
69575 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
69576 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
69577 + atomic_set_unchecked(&n_rcu_torture_free, 0);
69578 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
69579 + atomic_set_unchecked(&n_rcu_torture_error, 0);
69580 n_rcu_torture_barrier_error = 0;
69581 n_rcu_torture_boost_ktrerror = 0;
69582 n_rcu_torture_boost_rterror = 0;
69583 n_rcu_torture_boost_failure = 0;
69584 n_rcu_torture_boosts = 0;
69585 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
69586 - atomic_set(&rcu_torture_wcount[i], 0);
69587 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
69588 for_each_possible_cpu(cpu) {
69589 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
69590 per_cpu(rcu_torture_count, cpu)[i] = 0;
69591 diff --git a/kernel/rcutree.c b/kernel/rcutree.c
69592 index 4b97bba..b92c9d2 100644
69593 --- a/kernel/rcutree.c
69594 +++ b/kernel/rcutree.c
69595 @@ -366,9 +366,9 @@ static void rcu_idle_enter_common(struct rcu_dynticks *rdtp, long long oldval)
69596 rcu_prepare_for_idle(smp_processor_id());
69597 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69598 smp_mb__before_atomic_inc(); /* See above. */
69599 - atomic_inc(&rdtp->dynticks);
69600 + atomic_inc_unchecked(&rdtp->dynticks);
69601 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
69602 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69603 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69604
69605 /*
69606 * The idle task is not permitted to enter the idle loop while
69607 @@ -457,10 +457,10 @@ void rcu_irq_exit(void)
69608 static void rcu_idle_exit_common(struct rcu_dynticks *rdtp, long long oldval)
69609 {
69610 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
69611 - atomic_inc(&rdtp->dynticks);
69612 + atomic_inc_unchecked(&rdtp->dynticks);
69613 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69614 smp_mb__after_atomic_inc(); /* See above. */
69615 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69616 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69617 rcu_cleanup_after_idle(smp_processor_id());
69618 trace_rcu_dyntick("End", oldval, rdtp->dynticks_nesting);
69619 if (!is_idle_task(current)) {
69620 @@ -554,14 +554,14 @@ void rcu_nmi_enter(void)
69621 struct rcu_dynticks *rdtp = &__get_cpu_var(rcu_dynticks);
69622
69623 if (rdtp->dynticks_nmi_nesting == 0 &&
69624 - (atomic_read(&rdtp->dynticks) & 0x1))
69625 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
69626 return;
69627 rdtp->dynticks_nmi_nesting++;
69628 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
69629 - atomic_inc(&rdtp->dynticks);
69630 + atomic_inc_unchecked(&rdtp->dynticks);
69631 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
69632 smp_mb__after_atomic_inc(); /* See above. */
69633 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
69634 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
69635 }
69636
69637 /**
69638 @@ -580,9 +580,9 @@ void rcu_nmi_exit(void)
69639 return;
69640 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
69641 smp_mb__before_atomic_inc(); /* See above. */
69642 - atomic_inc(&rdtp->dynticks);
69643 + atomic_inc_unchecked(&rdtp->dynticks);
69644 smp_mb__after_atomic_inc(); /* Force delay to next write. */
69645 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
69646 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
69647 }
69648
69649 #ifdef CONFIG_PROVE_RCU
69650 @@ -598,7 +598,7 @@ int rcu_is_cpu_idle(void)
69651 int ret;
69652
69653 preempt_disable();
69654 - ret = (atomic_read(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69655 + ret = (atomic_read_unchecked(&__get_cpu_var(rcu_dynticks).dynticks) & 0x1) == 0;
69656 preempt_enable();
69657 return ret;
69658 }
69659 @@ -668,7 +668,7 @@ int rcu_is_cpu_rrupt_from_idle(void)
69660 */
69661 static int dyntick_save_progress_counter(struct rcu_data *rdp)
69662 {
69663 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
69664 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69665 return (rdp->dynticks_snap & 0x1) == 0;
69666 }
69667
69668 @@ -683,7 +683,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp)
69669 unsigned int curr;
69670 unsigned int snap;
69671
69672 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
69673 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
69674 snap = (unsigned int)rdp->dynticks_snap;
69675
69676 /*
69677 @@ -713,10 +713,10 @@ static int jiffies_till_stall_check(void)
69678 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
69679 */
69680 if (till_stall_check < 3) {
69681 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
69682 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
69683 till_stall_check = 3;
69684 } else if (till_stall_check > 300) {
69685 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
69686 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
69687 till_stall_check = 300;
69688 }
69689 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
69690 @@ -1824,7 +1824,7 @@ __rcu_process_callbacks(struct rcu_state *rsp, struct rcu_data *rdp)
69691 /*
69692 * Do RCU core processing for the current CPU.
69693 */
69694 -static void rcu_process_callbacks(struct softirq_action *unused)
69695 +static void rcu_process_callbacks(void)
69696 {
69697 trace_rcu_utilization("Start RCU core");
69698 __rcu_process_callbacks(&rcu_sched_state,
69699 @@ -2042,8 +2042,8 @@ void synchronize_rcu_bh(void)
69700 }
69701 EXPORT_SYMBOL_GPL(synchronize_rcu_bh);
69702
69703 -static atomic_t sync_sched_expedited_started = ATOMIC_INIT(0);
69704 -static atomic_t sync_sched_expedited_done = ATOMIC_INIT(0);
69705 +static atomic_unchecked_t sync_sched_expedited_started = ATOMIC_INIT(0);
69706 +static atomic_unchecked_t sync_sched_expedited_done = ATOMIC_INIT(0);
69707
69708 static int synchronize_sched_expedited_cpu_stop(void *data)
69709 {
69710 @@ -2104,7 +2104,7 @@ void synchronize_sched_expedited(void)
69711 int firstsnap, s, snap, trycount = 0;
69712
69713 /* Note that atomic_inc_return() implies full memory barrier. */
69714 - firstsnap = snap = atomic_inc_return(&sync_sched_expedited_started);
69715 + firstsnap = snap = atomic_inc_return_unchecked(&sync_sched_expedited_started);
69716 get_online_cpus();
69717 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
69718
69719 @@ -2126,7 +2126,7 @@ void synchronize_sched_expedited(void)
69720 }
69721
69722 /* Check to see if someone else did our work for us. */
69723 - s = atomic_read(&sync_sched_expedited_done);
69724 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69725 if (UINT_CMP_GE((unsigned)s, (unsigned)firstsnap)) {
69726 smp_mb(); /* ensure test happens before caller kfree */
69727 return;
69728 @@ -2141,7 +2141,7 @@ void synchronize_sched_expedited(void)
69729 * grace period works for us.
69730 */
69731 get_online_cpus();
69732 - snap = atomic_read(&sync_sched_expedited_started);
69733 + snap = atomic_read_unchecked(&sync_sched_expedited_started);
69734 smp_mb(); /* ensure read is before try_stop_cpus(). */
69735 }
69736
69737 @@ -2152,12 +2152,12 @@ void synchronize_sched_expedited(void)
69738 * than we did beat us to the punch.
69739 */
69740 do {
69741 - s = atomic_read(&sync_sched_expedited_done);
69742 + s = atomic_read_unchecked(&sync_sched_expedited_done);
69743 if (UINT_CMP_GE((unsigned)s, (unsigned)snap)) {
69744 smp_mb(); /* ensure test happens before caller kfree */
69745 break;
69746 }
69747 - } while (atomic_cmpxchg(&sync_sched_expedited_done, s, snap) != s);
69748 + } while (atomic_cmpxchg_unchecked(&sync_sched_expedited_done, s, snap) != s);
69749
69750 put_online_cpus();
69751 }
69752 @@ -2421,7 +2421,7 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
69753 rdp->qlen = 0;
69754 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
69755 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
69756 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
69757 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
69758 rdp->cpu = cpu;
69759 rdp->rsp = rsp;
69760 raw_spin_unlock_irqrestore(&rnp->lock, flags);
69761 @@ -2449,8 +2449,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
69762 rdp->n_force_qs_snap = rsp->n_force_qs;
69763 rdp->blimit = blimit;
69764 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
69765 - atomic_set(&rdp->dynticks->dynticks,
69766 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
69767 + atomic_set_unchecked(&rdp->dynticks->dynticks,
69768 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
69769 rcu_prepare_for_idle_init(cpu);
69770 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
69771
69772 diff --git a/kernel/rcutree.h b/kernel/rcutree.h
69773 index 19b61ac..5c60a94 100644
69774 --- a/kernel/rcutree.h
69775 +++ b/kernel/rcutree.h
69776 @@ -83,7 +83,7 @@ struct rcu_dynticks {
69777 long long dynticks_nesting; /* Track irq/process nesting level. */
69778 /* Process level is worth LLONG_MAX/2. */
69779 int dynticks_nmi_nesting; /* Track NMI nesting level. */
69780 - atomic_t dynticks; /* Even value for idle, else odd. */
69781 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
69782 #ifdef CONFIG_RCU_FAST_NO_HZ
69783 int dyntick_drain; /* Prepare-for-idle state variable. */
69784 unsigned long dyntick_holdoff;
69785 diff --git a/kernel/rcutree_plugin.h b/kernel/rcutree_plugin.h
69786 index 3e48994..d94f03a 100644
69787 --- a/kernel/rcutree_plugin.h
69788 +++ b/kernel/rcutree_plugin.h
69789 @@ -909,7 +909,7 @@ void synchronize_rcu_expedited(void)
69790
69791 /* Clean up and exit. */
69792 smp_mb(); /* ensure expedited GP seen before counter increment. */
69793 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
69794 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
69795 unlock_mb_ret:
69796 mutex_unlock(&sync_rcu_preempt_exp_mutex);
69797 mb_ret:
69798 diff --git a/kernel/rcutree_trace.c b/kernel/rcutree_trace.c
69799 index d4bc16d..c234a5c 100644
69800 --- a/kernel/rcutree_trace.c
69801 +++ b/kernel/rcutree_trace.c
69802 @@ -68,7 +68,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
69803 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69804 rdp->qs_pending);
69805 seq_printf(m, " dt=%d/%llx/%d df=%lu",
69806 - atomic_read(&rdp->dynticks->dynticks),
69807 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69808 rdp->dynticks->dynticks_nesting,
69809 rdp->dynticks->dynticks_nmi_nesting,
69810 rdp->dynticks_fqs);
69811 @@ -140,7 +140,7 @@ static void print_one_rcu_data_csv(struct seq_file *m, struct rcu_data *rdp)
69812 rdp->passed_quiesce, rdp->passed_quiesce_gpnum,
69813 rdp->qs_pending);
69814 seq_printf(m, ",%d,%llx,%d,%lu",
69815 - atomic_read(&rdp->dynticks->dynticks),
69816 + atomic_read_unchecked(&rdp->dynticks->dynticks),
69817 rdp->dynticks->dynticks_nesting,
69818 rdp->dynticks->dynticks_nmi_nesting,
69819 rdp->dynticks_fqs);
69820 diff --git a/kernel/resource.c b/kernel/resource.c
69821 index e1d2b8e..24820bb 100644
69822 --- a/kernel/resource.c
69823 +++ b/kernel/resource.c
69824 @@ -141,8 +141,18 @@ static const struct file_operations proc_iomem_operations = {
69825
69826 static int __init ioresources_init(void)
69827 {
69828 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
69829 +#ifdef CONFIG_GRKERNSEC_PROC_USER
69830 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
69831 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
69832 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
69833 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
69834 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
69835 +#endif
69836 +#else
69837 proc_create("ioports", 0, NULL, &proc_ioports_operations);
69838 proc_create("iomem", 0, NULL, &proc_iomem_operations);
69839 +#endif
69840 return 0;
69841 }
69842 __initcall(ioresources_init);
69843 diff --git a/kernel/rtmutex-tester.c b/kernel/rtmutex-tester.c
69844 index 98ec494..4241d6d 100644
69845 --- a/kernel/rtmutex-tester.c
69846 +++ b/kernel/rtmutex-tester.c
69847 @@ -20,7 +20,7 @@
69848 #define MAX_RT_TEST_MUTEXES 8
69849
69850 static spinlock_t rttest_lock;
69851 -static atomic_t rttest_event;
69852 +static atomic_unchecked_t rttest_event;
69853
69854 struct test_thread_data {
69855 int opcode;
69856 @@ -61,7 +61,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69857
69858 case RTTEST_LOCKCONT:
69859 td->mutexes[td->opdata] = 1;
69860 - td->event = atomic_add_return(1, &rttest_event);
69861 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69862 return 0;
69863
69864 case RTTEST_RESET:
69865 @@ -74,7 +74,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69866 return 0;
69867
69868 case RTTEST_RESETEVENT:
69869 - atomic_set(&rttest_event, 0);
69870 + atomic_set_unchecked(&rttest_event, 0);
69871 return 0;
69872
69873 default:
69874 @@ -91,9 +91,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69875 return ret;
69876
69877 td->mutexes[id] = 1;
69878 - td->event = atomic_add_return(1, &rttest_event);
69879 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69880 rt_mutex_lock(&mutexes[id]);
69881 - td->event = atomic_add_return(1, &rttest_event);
69882 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69883 td->mutexes[id] = 4;
69884 return 0;
69885
69886 @@ -104,9 +104,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69887 return ret;
69888
69889 td->mutexes[id] = 1;
69890 - td->event = atomic_add_return(1, &rttest_event);
69891 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69892 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
69893 - td->event = atomic_add_return(1, &rttest_event);
69894 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69895 td->mutexes[id] = ret ? 0 : 4;
69896 return ret ? -EINTR : 0;
69897
69898 @@ -115,9 +115,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
69899 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
69900 return ret;
69901
69902 - td->event = atomic_add_return(1, &rttest_event);
69903 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69904 rt_mutex_unlock(&mutexes[id]);
69905 - td->event = atomic_add_return(1, &rttest_event);
69906 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69907 td->mutexes[id] = 0;
69908 return 0;
69909
69910 @@ -164,7 +164,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69911 break;
69912
69913 td->mutexes[dat] = 2;
69914 - td->event = atomic_add_return(1, &rttest_event);
69915 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69916 break;
69917
69918 default:
69919 @@ -184,7 +184,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69920 return;
69921
69922 td->mutexes[dat] = 3;
69923 - td->event = atomic_add_return(1, &rttest_event);
69924 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69925 break;
69926
69927 case RTTEST_LOCKNOWAIT:
69928 @@ -196,7 +196,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
69929 return;
69930
69931 td->mutexes[dat] = 1;
69932 - td->event = atomic_add_return(1, &rttest_event);
69933 + td->event = atomic_add_return_unchecked(1, &rttest_event);
69934 return;
69935
69936 default:
69937 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
69938 index 0984a21..939f183 100644
69939 --- a/kernel/sched/auto_group.c
69940 +++ b/kernel/sched/auto_group.c
69941 @@ -11,7 +11,7 @@
69942
69943 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
69944 static struct autogroup autogroup_default;
69945 -static atomic_t autogroup_seq_nr;
69946 +static atomic_unchecked_t autogroup_seq_nr;
69947
69948 void __init autogroup_init(struct task_struct *init_task)
69949 {
69950 @@ -78,7 +78,7 @@ static inline struct autogroup *autogroup_create(void)
69951
69952 kref_init(&ag->kref);
69953 init_rwsem(&ag->lock);
69954 - ag->id = atomic_inc_return(&autogroup_seq_nr);
69955 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
69956 ag->tg = tg;
69957 #ifdef CONFIG_RT_GROUP_SCHED
69958 /*
69959 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
69960 index c04c9ff..98c54bf 100644
69961 --- a/kernel/sched/core.c
69962 +++ b/kernel/sched/core.c
69963 @@ -4103,6 +4103,8 @@ int can_nice(const struct task_struct *p, const int nice)
69964 /* convert nice value [19,-20] to rlimit style value [1,40] */
69965 int nice_rlim = 20 - nice;
69966
69967 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
69968 +
69969 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
69970 capable(CAP_SYS_NICE));
69971 }
69972 @@ -4136,7 +4138,8 @@ SYSCALL_DEFINE1(nice, int, increment)
69973 if (nice > 19)
69974 nice = 19;
69975
69976 - if (increment < 0 && !can_nice(current, nice))
69977 + if (increment < 0 && (!can_nice(current, nice) ||
69978 + gr_handle_chroot_nice()))
69979 return -EPERM;
69980
69981 retval = security_task_setnice(current, nice);
69982 @@ -4290,6 +4293,7 @@ recheck:
69983 unsigned long rlim_rtprio =
69984 task_rlimit(p, RLIMIT_RTPRIO);
69985
69986 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
69987 /* can't set/change the rt policy */
69988 if (policy != p->policy && !rlim_rtprio)
69989 return -EPERM;
69990 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
69991 index c099cc6..06aec4f 100644
69992 --- a/kernel/sched/fair.c
69993 +++ b/kernel/sched/fair.c
69994 @@ -4846,7 +4846,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
69995 * run_rebalance_domains is triggered when needed from the scheduler tick.
69996 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
69997 */
69998 -static void run_rebalance_domains(struct softirq_action *h)
69999 +static void run_rebalance_domains(void)
70000 {
70001 int this_cpu = smp_processor_id();
70002 struct rq *this_rq = cpu_rq(this_cpu);
70003 diff --git a/kernel/signal.c b/kernel/signal.c
70004 index 6771027..763e51e 100644
70005 --- a/kernel/signal.c
70006 +++ b/kernel/signal.c
70007 @@ -48,12 +48,12 @@ static struct kmem_cache *sigqueue_cachep;
70008
70009 int print_fatal_signals __read_mostly;
70010
70011 -static void __user *sig_handler(struct task_struct *t, int sig)
70012 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
70013 {
70014 return t->sighand->action[sig - 1].sa.sa_handler;
70015 }
70016
70017 -static int sig_handler_ignored(void __user *handler, int sig)
70018 +static int sig_handler_ignored(__sighandler_t handler, int sig)
70019 {
70020 /* Is it explicitly or implicitly ignored? */
70021 return handler == SIG_IGN ||
70022 @@ -62,7 +62,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
70023
70024 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
70025 {
70026 - void __user *handler;
70027 + __sighandler_t handler;
70028
70029 handler = sig_handler(t, sig);
70030
70031 @@ -366,6 +366,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
70032 atomic_inc(&user->sigpending);
70033 rcu_read_unlock();
70034
70035 + if (!override_rlimit)
70036 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
70037 +
70038 if (override_rlimit ||
70039 atomic_read(&user->sigpending) <=
70040 task_rlimit(t, RLIMIT_SIGPENDING)) {
70041 @@ -490,7 +493,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
70042
70043 int unhandled_signal(struct task_struct *tsk, int sig)
70044 {
70045 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
70046 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
70047 if (is_global_init(tsk))
70048 return 1;
70049 if (handler != SIG_IGN && handler != SIG_DFL)
70050 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
70051 }
70052 }
70053
70054 + /* allow glibc communication via tgkill to other threads in our
70055 + thread group */
70056 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
70057 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
70058 + && gr_handle_signal(t, sig))
70059 + return -EPERM;
70060 +
70061 return security_task_kill(t, info, sig, 0);
70062 }
70063
70064 @@ -1197,7 +1207,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70065 return send_signal(sig, info, p, 1);
70066 }
70067
70068 -static int
70069 +int
70070 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70071 {
70072 return send_signal(sig, info, t, 0);
70073 @@ -1234,6 +1244,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70074 unsigned long int flags;
70075 int ret, blocked, ignored;
70076 struct k_sigaction *action;
70077 + int is_unhandled = 0;
70078
70079 spin_lock_irqsave(&t->sighand->siglock, flags);
70080 action = &t->sighand->action[sig-1];
70081 @@ -1248,9 +1259,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
70082 }
70083 if (action->sa.sa_handler == SIG_DFL)
70084 t->signal->flags &= ~SIGNAL_UNKILLABLE;
70085 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
70086 + is_unhandled = 1;
70087 ret = specific_send_sig_info(sig, info, t);
70088 spin_unlock_irqrestore(&t->sighand->siglock, flags);
70089
70090 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
70091 + normal operation */
70092 + if (is_unhandled) {
70093 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
70094 + gr_handle_crash(t, sig);
70095 + }
70096 +
70097 return ret;
70098 }
70099
70100 @@ -1317,8 +1337,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
70101 ret = check_kill_permission(sig, info, p);
70102 rcu_read_unlock();
70103
70104 - if (!ret && sig)
70105 + if (!ret && sig) {
70106 ret = do_send_sig_info(sig, info, p, true);
70107 + if (!ret)
70108 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
70109 + }
70110
70111 return ret;
70112 }
70113 @@ -2858,7 +2881,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
70114 int error = -ESRCH;
70115
70116 rcu_read_lock();
70117 - p = find_task_by_vpid(pid);
70118 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
70119 + /* allow glibc communication via tgkill to other threads in our
70120 + thread group */
70121 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
70122 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
70123 + p = find_task_by_vpid_unrestricted(pid);
70124 + else
70125 +#endif
70126 + p = find_task_by_vpid(pid);
70127 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
70128 error = check_kill_permission(sig, info, p);
70129 /*
70130 diff --git a/kernel/smp.c b/kernel/smp.c
70131 index d0ae5b2..b87c5a8 100644
70132 --- a/kernel/smp.c
70133 +++ b/kernel/smp.c
70134 @@ -582,22 +582,22 @@ int smp_call_function(smp_call_func_t func, void *info, int wait)
70135 }
70136 EXPORT_SYMBOL(smp_call_function);
70137
70138 -void ipi_call_lock(void)
70139 +void ipi_call_lock(void) __acquires(call_function.lock)
70140 {
70141 raw_spin_lock(&call_function.lock);
70142 }
70143
70144 -void ipi_call_unlock(void)
70145 +void ipi_call_unlock(void) __releases(call_function.lock)
70146 {
70147 raw_spin_unlock(&call_function.lock);
70148 }
70149
70150 -void ipi_call_lock_irq(void)
70151 +void ipi_call_lock_irq(void) __acquires(call_function.lock)
70152 {
70153 raw_spin_lock_irq(&call_function.lock);
70154 }
70155
70156 -void ipi_call_unlock_irq(void)
70157 +void ipi_call_unlock_irq(void) __releases(call_function.lock)
70158 {
70159 raw_spin_unlock_irq(&call_function.lock);
70160 }
70161 diff --git a/kernel/softirq.c b/kernel/softirq.c
70162 index 671f959..91c51cb 100644
70163 --- a/kernel/softirq.c
70164 +++ b/kernel/softirq.c
70165 @@ -56,7 +56,7 @@ static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp
70166
70167 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
70168
70169 -char *softirq_to_name[NR_SOFTIRQS] = {
70170 +const char * const softirq_to_name[NR_SOFTIRQS] = {
70171 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
70172 "TASKLET", "SCHED", "HRTIMER", "RCU"
70173 };
70174 @@ -235,7 +235,7 @@ restart:
70175 kstat_incr_softirqs_this_cpu(vec_nr);
70176
70177 trace_softirq_entry(vec_nr);
70178 - h->action(h);
70179 + h->action();
70180 trace_softirq_exit(vec_nr);
70181 if (unlikely(prev_count != preempt_count())) {
70182 printk(KERN_ERR "huh, entered softirq %u %s %p"
70183 @@ -381,9 +381,11 @@ void __raise_softirq_irqoff(unsigned int nr)
70184 or_softirq_pending(1UL << nr);
70185 }
70186
70187 -void open_softirq(int nr, void (*action)(struct softirq_action *))
70188 +void open_softirq(int nr, void (*action)(void))
70189 {
70190 - softirq_vec[nr].action = action;
70191 + pax_open_kernel();
70192 + *(void **)&softirq_vec[nr].action = action;
70193 + pax_close_kernel();
70194 }
70195
70196 /*
70197 @@ -437,7 +439,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
70198
70199 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
70200
70201 -static void tasklet_action(struct softirq_action *a)
70202 +static void tasklet_action(void)
70203 {
70204 struct tasklet_struct *list;
70205
70206 @@ -472,7 +474,7 @@ static void tasklet_action(struct softirq_action *a)
70207 }
70208 }
70209
70210 -static void tasklet_hi_action(struct softirq_action *a)
70211 +static void tasklet_hi_action(void)
70212 {
70213 struct tasklet_struct *list;
70214
70215 diff --git a/kernel/srcu.c b/kernel/srcu.c
70216 index 2095be3..9a5b89d 100644
70217 --- a/kernel/srcu.c
70218 +++ b/kernel/srcu.c
70219 @@ -302,9 +302,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
70220 preempt_disable();
70221 idx = rcu_dereference_index_check(sp->completed,
70222 rcu_read_lock_sched_held()) & 0x1;
70223 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70224 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
70225 smp_mb(); /* B */ /* Avoid leaking the critical section. */
70226 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70227 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
70228 preempt_enable();
70229 return idx;
70230 }
70231 @@ -320,7 +320,7 @@ void __srcu_read_unlock(struct srcu_struct *sp, int idx)
70232 {
70233 preempt_disable();
70234 smp_mb(); /* C */ /* Avoid leaking the critical section. */
70235 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70236 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) -= 1;
70237 preempt_enable();
70238 }
70239 EXPORT_SYMBOL_GPL(__srcu_read_unlock);
70240 diff --git a/kernel/sys.c b/kernel/sys.c
70241 index 2d39a84..1c3abe4 100644
70242 --- a/kernel/sys.c
70243 +++ b/kernel/sys.c
70244 @@ -157,6 +157,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
70245 error = -EACCES;
70246 goto out;
70247 }
70248 +
70249 + if (gr_handle_chroot_setpriority(p, niceval)) {
70250 + error = -EACCES;
70251 + goto out;
70252 + }
70253 +
70254 no_nice = security_task_setnice(p, niceval);
70255 if (no_nice) {
70256 error = no_nice;
70257 @@ -594,6 +600,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
70258 goto error;
70259 }
70260
70261 + if (gr_check_group_change(new->gid, new->egid, -1))
70262 + goto error;
70263 +
70264 if (rgid != (gid_t) -1 ||
70265 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
70266 new->sgid = new->egid;
70267 @@ -629,6 +638,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
70268 old = current_cred();
70269
70270 retval = -EPERM;
70271 +
70272 + if (gr_check_group_change(kgid, kgid, kgid))
70273 + goto error;
70274 +
70275 if (nsown_capable(CAP_SETGID))
70276 new->gid = new->egid = new->sgid = new->fsgid = kgid;
70277 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
70278 @@ -646,7 +659,7 @@ error:
70279 /*
70280 * change the user struct in a credentials set to match the new UID
70281 */
70282 -static int set_user(struct cred *new)
70283 +int set_user(struct cred *new)
70284 {
70285 struct user_struct *new_user;
70286
70287 @@ -726,6 +739,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
70288 goto error;
70289 }
70290
70291 + if (gr_check_user_change(new->uid, new->euid, -1))
70292 + goto error;
70293 +
70294 if (!uid_eq(new->uid, old->uid)) {
70295 retval = set_user(new);
70296 if (retval < 0)
70297 @@ -776,6 +792,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
70298 old = current_cred();
70299
70300 retval = -EPERM;
70301 +
70302 + if (gr_check_crash_uid(kuid))
70303 + goto error;
70304 + if (gr_check_user_change(kuid, kuid, kuid))
70305 + goto error;
70306 +
70307 if (nsown_capable(CAP_SETUID)) {
70308 new->suid = new->uid = kuid;
70309 if (!uid_eq(kuid, old->uid)) {
70310 @@ -845,6 +867,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
70311 goto error;
70312 }
70313
70314 + if (gr_check_user_change(kruid, keuid, -1))
70315 + goto error;
70316 +
70317 if (ruid != (uid_t) -1) {
70318 new->uid = kruid;
70319 if (!uid_eq(kruid, old->uid)) {
70320 @@ -927,6 +952,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
70321 goto error;
70322 }
70323
70324 + if (gr_check_group_change(krgid, kegid, -1))
70325 + goto error;
70326 +
70327 if (rgid != (gid_t) -1)
70328 new->gid = krgid;
70329 if (egid != (gid_t) -1)
70330 @@ -980,6 +1008,9 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70331 if (!uid_valid(kuid))
70332 return old_fsuid;
70333
70334 + if (gr_check_user_change(-1, -1, kuid))
70335 + goto error;
70336 +
70337 new = prepare_creds();
70338 if (!new)
70339 return old_fsuid;
70340 @@ -994,6 +1025,7 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
70341 }
70342 }
70343
70344 +error:
70345 abort_creds(new);
70346 return old_fsuid;
70347
70348 @@ -1026,12 +1058,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
70349 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
70350 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
70351 nsown_capable(CAP_SETGID)) {
70352 + if (gr_check_group_change(-1, -1, kgid))
70353 + goto error;
70354 +
70355 if (!gid_eq(kgid, old->fsgid)) {
70356 new->fsgid = kgid;
70357 goto change_okay;
70358 }
70359 }
70360
70361 +error:
70362 abort_creds(new);
70363 return old_fsgid;
70364
70365 @@ -1264,13 +1300,13 @@ DECLARE_RWSEM(uts_sem);
70366 * Work around broken programs that cannot handle "Linux 3.0".
70367 * Instead we map 3.x to 2.6.40+x, so e.g. 3.0 would be 2.6.40
70368 */
70369 -static int override_release(char __user *release, int len)
70370 +static int override_release(char __user *release, size_t len)
70371 {
70372 int ret = 0;
70373 - char buf[65];
70374
70375 if (current->personality & UNAME26) {
70376 - char *rest = UTS_RELEASE;
70377 + char buf[65] = { 0 };
70378 + const char *rest = UTS_RELEASE;
70379 int ndots = 0;
70380 unsigned v;
70381
70382 @@ -1282,7 +1318,10 @@ static int override_release(char __user *release, int len)
70383 rest++;
70384 }
70385 v = ((LINUX_VERSION_CODE >> 8) & 0xff) + 40;
70386 + if (sizeof buf < len)
70387 + len = sizeof buf;
70388 snprintf(buf, len, "2.6.%u%s", v, rest);
70389 + buf[len - 1] = 0;
70390 ret = copy_to_user(release, buf, len);
70391 }
70392 return ret;
70393 @@ -1337,19 +1376,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
70394 return -EFAULT;
70395
70396 down_read(&uts_sem);
70397 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
70398 + error = __copy_to_user(name->sysname, &utsname()->sysname,
70399 __OLD_UTS_LEN);
70400 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
70401 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
70402 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
70403 __OLD_UTS_LEN);
70404 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
70405 - error |= __copy_to_user(&name->release, &utsname()->release,
70406 + error |= __copy_to_user(name->release, &utsname()->release,
70407 __OLD_UTS_LEN);
70408 error |= __put_user(0, name->release + __OLD_UTS_LEN);
70409 - error |= __copy_to_user(&name->version, &utsname()->version,
70410 + error |= __copy_to_user(name->version, &utsname()->version,
70411 __OLD_UTS_LEN);
70412 error |= __put_user(0, name->version + __OLD_UTS_LEN);
70413 - error |= __copy_to_user(&name->machine, &utsname()->machine,
70414 + error |= __copy_to_user(name->machine, &utsname()->machine,
70415 __OLD_UTS_LEN);
70416 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
70417 up_read(&uts_sem);
70418 @@ -2024,7 +2063,7 @@ SYSCALL_DEFINE5(prctl, int, option, unsigned long, arg2, unsigned long, arg3,
70419 error = get_dumpable(me->mm);
70420 break;
70421 case PR_SET_DUMPABLE:
70422 - if (arg2 < 0 || arg2 > 1) {
70423 + if (arg2 > 1) {
70424 error = -EINVAL;
70425 break;
70426 }
70427 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
70428 index 4ab1187..33f4f2b 100644
70429 --- a/kernel/sysctl.c
70430 +++ b/kernel/sysctl.c
70431 @@ -91,7 +91,6 @@
70432
70433
70434 #if defined(CONFIG_SYSCTL)
70435 -
70436 /* External variables not in a header file. */
70437 extern int sysctl_overcommit_memory;
70438 extern int sysctl_overcommit_ratio;
70439 @@ -169,10 +168,13 @@ static int proc_taint(struct ctl_table *table, int write,
70440 void __user *buffer, size_t *lenp, loff_t *ppos);
70441 #endif
70442
70443 -#ifdef CONFIG_PRINTK
70444 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70445 void __user *buffer, size_t *lenp, loff_t *ppos);
70446 -#endif
70447 +
70448 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70449 + void __user *buffer, size_t *lenp, loff_t *ppos);
70450 +static int proc_dostring_coredump(struct ctl_table *table, int write,
70451 + void __user *buffer, size_t *lenp, loff_t *ppos);
70452
70453 #ifdef CONFIG_MAGIC_SYSRQ
70454 /* Note: sysrq code uses it's own private copy */
70455 @@ -196,6 +198,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
70456
70457 #endif
70458
70459 +extern struct ctl_table grsecurity_table[];
70460 +
70461 static struct ctl_table kern_table[];
70462 static struct ctl_table vm_table[];
70463 static struct ctl_table fs_table[];
70464 @@ -210,6 +214,20 @@ extern struct ctl_table epoll_table[];
70465 int sysctl_legacy_va_layout;
70466 #endif
70467
70468 +#ifdef CONFIG_PAX_SOFTMODE
70469 +static ctl_table pax_table[] = {
70470 + {
70471 + .procname = "softmode",
70472 + .data = &pax_softmode,
70473 + .maxlen = sizeof(unsigned int),
70474 + .mode = 0600,
70475 + .proc_handler = &proc_dointvec,
70476 + },
70477 +
70478 + { }
70479 +};
70480 +#endif
70481 +
70482 /* The default sysctl tables: */
70483
70484 static struct ctl_table sysctl_base_table[] = {
70485 @@ -256,6 +274,22 @@ static int max_extfrag_threshold = 1000;
70486 #endif
70487
70488 static struct ctl_table kern_table[] = {
70489 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
70490 + {
70491 + .procname = "grsecurity",
70492 + .mode = 0500,
70493 + .child = grsecurity_table,
70494 + },
70495 +#endif
70496 +
70497 +#ifdef CONFIG_PAX_SOFTMODE
70498 + {
70499 + .procname = "pax",
70500 + .mode = 0500,
70501 + .child = pax_table,
70502 + },
70503 +#endif
70504 +
70505 {
70506 .procname = "sched_child_runs_first",
70507 .data = &sysctl_sched_child_runs_first,
70508 @@ -410,7 +444,7 @@ static struct ctl_table kern_table[] = {
70509 .data = core_pattern,
70510 .maxlen = CORENAME_MAX_SIZE,
70511 .mode = 0644,
70512 - .proc_handler = proc_dostring,
70513 + .proc_handler = proc_dostring_coredump,
70514 },
70515 {
70516 .procname = "core_pipe_limit",
70517 @@ -540,7 +574,7 @@ static struct ctl_table kern_table[] = {
70518 .data = &modprobe_path,
70519 .maxlen = KMOD_PATH_LEN,
70520 .mode = 0644,
70521 - .proc_handler = proc_dostring,
70522 + .proc_handler = proc_dostring_modpriv,
70523 },
70524 {
70525 .procname = "modules_disabled",
70526 @@ -707,16 +741,20 @@ static struct ctl_table kern_table[] = {
70527 .extra1 = &zero,
70528 .extra2 = &one,
70529 },
70530 +#endif
70531 {
70532 .procname = "kptr_restrict",
70533 .data = &kptr_restrict,
70534 .maxlen = sizeof(int),
70535 .mode = 0644,
70536 .proc_handler = proc_dointvec_minmax_sysadmin,
70537 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70538 + .extra1 = &two,
70539 +#else
70540 .extra1 = &zero,
70541 +#endif
70542 .extra2 = &two,
70543 },
70544 -#endif
70545 {
70546 .procname = "ngroups_max",
70547 .data = &ngroups_max,
70548 @@ -1215,6 +1253,13 @@ static struct ctl_table vm_table[] = {
70549 .proc_handler = proc_dointvec_minmax,
70550 .extra1 = &zero,
70551 },
70552 + {
70553 + .procname = "heap_stack_gap",
70554 + .data = &sysctl_heap_stack_gap,
70555 + .maxlen = sizeof(sysctl_heap_stack_gap),
70556 + .mode = 0644,
70557 + .proc_handler = proc_doulongvec_minmax,
70558 + },
70559 #else
70560 {
70561 .procname = "nr_trim_pages",
70562 @@ -1498,7 +1543,7 @@ static struct ctl_table fs_table[] = {
70563 .data = &suid_dumpable,
70564 .maxlen = sizeof(int),
70565 .mode = 0644,
70566 - .proc_handler = proc_dointvec_minmax,
70567 + .proc_handler = proc_dointvec_minmax_coredump,
70568 .extra1 = &zero,
70569 .extra2 = &two,
70570 },
70571 @@ -1645,6 +1690,16 @@ int proc_dostring(struct ctl_table *table, int write,
70572 buffer, lenp, ppos);
70573 }
70574
70575 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70576 + void __user *buffer, size_t *lenp, loff_t *ppos)
70577 +{
70578 + if (write && !capable(CAP_SYS_MODULE))
70579 + return -EPERM;
70580 +
70581 + return _proc_do_string(table->data, table->maxlen, write,
70582 + buffer, lenp, ppos);
70583 +}
70584 +
70585 static size_t proc_skip_spaces(char **buf)
70586 {
70587 size_t ret;
70588 @@ -1750,6 +1805,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
70589 len = strlen(tmp);
70590 if (len > *size)
70591 len = *size;
70592 + if (len > sizeof(tmp))
70593 + len = sizeof(tmp);
70594 if (copy_to_user(*buf, tmp, len))
70595 return -EFAULT;
70596 *size -= len;
70597 @@ -1942,7 +1999,6 @@ static int proc_taint(struct ctl_table *table, int write,
70598 return err;
70599 }
70600
70601 -#ifdef CONFIG_PRINTK
70602 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70603 void __user *buffer, size_t *lenp, loff_t *ppos)
70604 {
70605 @@ -1951,7 +2007,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
70606
70607 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70608 }
70609 -#endif
70610
70611 struct do_proc_dointvec_minmax_conv_param {
70612 int *min;
70613 @@ -2009,6 +2064,34 @@ int proc_dointvec_minmax(struct ctl_table *table, int write,
70614 do_proc_dointvec_minmax_conv, &param);
70615 }
70616
70617 +static void validate_coredump_safety(void)
70618 +{
70619 + if (suid_dumpable == SUID_DUMPABLE_SAFE &&
70620 + core_pattern[0] != '/' && core_pattern[0] != '|') {
70621 + printk(KERN_WARNING "Unsafe core_pattern used with "\
70622 + "suid_dumpable=2. Pipe handler or fully qualified "\
70623 + "core dump path required.\n");
70624 + }
70625 +}
70626 +
70627 +static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
70628 + void __user *buffer, size_t *lenp, loff_t *ppos)
70629 +{
70630 + int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
70631 + if (!error)
70632 + validate_coredump_safety();
70633 + return error;
70634 +}
70635 +
70636 +static int proc_dostring_coredump(struct ctl_table *table, int write,
70637 + void __user *buffer, size_t *lenp, loff_t *ppos)
70638 +{
70639 + int error = proc_dostring(table, write, buffer, lenp, ppos);
70640 + if (!error)
70641 + validate_coredump_safety();
70642 + return error;
70643 +}
70644 +
70645 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
70646 void __user *buffer,
70647 size_t *lenp, loff_t *ppos,
70648 @@ -2066,8 +2149,11 @@ static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int
70649 *i = val;
70650 } else {
70651 val = convdiv * (*i) / convmul;
70652 - if (!first)
70653 + if (!first) {
70654 err = proc_put_char(&buffer, &left, '\t');
70655 + if (err)
70656 + break;
70657 + }
70658 err = proc_put_long(&buffer, &left, val, false);
70659 if (err)
70660 break;
70661 @@ -2459,6 +2545,12 @@ int proc_dostring(struct ctl_table *table, int write,
70662 return -ENOSYS;
70663 }
70664
70665 +int proc_dostring_modpriv(struct ctl_table *table, int write,
70666 + void __user *buffer, size_t *lenp, loff_t *ppos)
70667 +{
70668 + return -ENOSYS;
70669 +}
70670 +
70671 int proc_dointvec(struct ctl_table *table, int write,
70672 void __user *buffer, size_t *lenp, loff_t *ppos)
70673 {
70674 @@ -2515,5 +2607,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
70675 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
70676 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
70677 EXPORT_SYMBOL(proc_dostring);
70678 +EXPORT_SYMBOL(proc_dostring_modpriv);
70679 EXPORT_SYMBOL(proc_doulongvec_minmax);
70680 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
70681 diff --git a/kernel/sysctl_binary.c b/kernel/sysctl_binary.c
70682 index a650694..aaeeb20 100644
70683 --- a/kernel/sysctl_binary.c
70684 +++ b/kernel/sysctl_binary.c
70685 @@ -989,7 +989,7 @@ static ssize_t bin_intvec(struct file *file,
70686 int i;
70687
70688 set_fs(KERNEL_DS);
70689 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70690 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70691 set_fs(old_fs);
70692 if (result < 0)
70693 goto out_kfree;
70694 @@ -1034,7 +1034,7 @@ static ssize_t bin_intvec(struct file *file,
70695 }
70696
70697 set_fs(KERNEL_DS);
70698 - result = vfs_write(file, buffer, str - buffer, &pos);
70699 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70700 set_fs(old_fs);
70701 if (result < 0)
70702 goto out_kfree;
70703 @@ -1067,7 +1067,7 @@ static ssize_t bin_ulongvec(struct file *file,
70704 int i;
70705
70706 set_fs(KERNEL_DS);
70707 - result = vfs_read(file, buffer, BUFSZ - 1, &pos);
70708 + result = vfs_read(file, (char __force_user *)buffer, BUFSZ - 1, &pos);
70709 set_fs(old_fs);
70710 if (result < 0)
70711 goto out_kfree;
70712 @@ -1112,7 +1112,7 @@ static ssize_t bin_ulongvec(struct file *file,
70713 }
70714
70715 set_fs(KERNEL_DS);
70716 - result = vfs_write(file, buffer, str - buffer, &pos);
70717 + result = vfs_write(file, (const char __force_user *)buffer, str - buffer, &pos);
70718 set_fs(old_fs);
70719 if (result < 0)
70720 goto out_kfree;
70721 @@ -1138,7 +1138,7 @@ static ssize_t bin_uuid(struct file *file,
70722 int i;
70723
70724 set_fs(KERNEL_DS);
70725 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70726 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70727 set_fs(old_fs);
70728 if (result < 0)
70729 goto out;
70730 @@ -1185,7 +1185,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70731 __le16 dnaddr;
70732
70733 set_fs(KERNEL_DS);
70734 - result = vfs_read(file, buf, sizeof(buf) - 1, &pos);
70735 + result = vfs_read(file, (char __force_user *)buf, sizeof(buf) - 1, &pos);
70736 set_fs(old_fs);
70737 if (result < 0)
70738 goto out;
70739 @@ -1233,7 +1233,7 @@ static ssize_t bin_dn_node_address(struct file *file,
70740 le16_to_cpu(dnaddr) & 0x3ff);
70741
70742 set_fs(KERNEL_DS);
70743 - result = vfs_write(file, buf, len, &pos);
70744 + result = vfs_write(file, (const char __force_user *)buf, len, &pos);
70745 set_fs(old_fs);
70746 if (result < 0)
70747 goto out;
70748 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
70749 index e660464..c8b9e67 100644
70750 --- a/kernel/taskstats.c
70751 +++ b/kernel/taskstats.c
70752 @@ -27,9 +27,12 @@
70753 #include <linux/cgroup.h>
70754 #include <linux/fs.h>
70755 #include <linux/file.h>
70756 +#include <linux/grsecurity.h>
70757 #include <net/genetlink.h>
70758 #include <linux/atomic.h>
70759
70760 +extern int gr_is_taskstats_denied(int pid);
70761 +
70762 /*
70763 * Maximum length of a cpumask that can be specified in
70764 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
70765 @@ -556,6 +559,9 @@ err:
70766
70767 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
70768 {
70769 + if (gr_is_taskstats_denied(current->pid))
70770 + return -EACCES;
70771 +
70772 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
70773 return cmd_attr_register_cpumask(info);
70774 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
70775 diff --git a/kernel/time.c b/kernel/time.c
70776 index ba744cf..267b7c5 100644
70777 --- a/kernel/time.c
70778 +++ b/kernel/time.c
70779 @@ -163,6 +163,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
70780 return error;
70781
70782 if (tz) {
70783 + /* we log in do_settimeofday called below, so don't log twice
70784 + */
70785 + if (!tv)
70786 + gr_log_timechange();
70787 +
70788 sys_tz = *tz;
70789 update_vsyscall_tz();
70790 if (firsttime) {
70791 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
70792 index aa27d39..34d221c 100644
70793 --- a/kernel/time/alarmtimer.c
70794 +++ b/kernel/time/alarmtimer.c
70795 @@ -779,7 +779,7 @@ static int __init alarmtimer_init(void)
70796 struct platform_device *pdev;
70797 int error = 0;
70798 int i;
70799 - struct k_clock alarm_clock = {
70800 + static struct k_clock alarm_clock = {
70801 .clock_getres = alarm_clock_getres,
70802 .clock_get = alarm_clock_get,
70803 .timer_create = alarm_timer_create,
70804 diff --git a/kernel/time/tick-broadcast.c b/kernel/time/tick-broadcast.c
70805 index f113755..ec24223 100644
70806 --- a/kernel/time/tick-broadcast.c
70807 +++ b/kernel/time/tick-broadcast.c
70808 @@ -115,7 +115,7 @@ int tick_device_uses_broadcast(struct clock_event_device *dev, int cpu)
70809 * then clear the broadcast bit.
70810 */
70811 if (!(dev->features & CLOCK_EVT_FEAT_C3STOP)) {
70812 - int cpu = smp_processor_id();
70813 + cpu = smp_processor_id();
70814
70815 cpumask_clear_cpu(cpu, tick_get_broadcast_mask());
70816 tick_broadcast_clear_oneshot(cpu);
70817 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
70818 index 63c88c1..8fd3c2f 100644
70819 --- a/kernel/time/timekeeping.c
70820 +++ b/kernel/time/timekeeping.c
70821 @@ -14,6 +14,7 @@
70822 #include <linux/init.h>
70823 #include <linux/mm.h>
70824 #include <linux/sched.h>
70825 +#include <linux/grsecurity.h>
70826 #include <linux/syscore_ops.h>
70827 #include <linux/clocksource.h>
70828 #include <linux/jiffies.h>
70829 @@ -387,6 +388,8 @@ int do_settimeofday(const struct timespec *tv)
70830 if (!timespec_valid_strict(tv))
70831 return -EINVAL;
70832
70833 + gr_log_timechange();
70834 +
70835 write_seqlock_irqsave(&timekeeper.lock, flags);
70836
70837 timekeeping_forward_now();
70838 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
70839 index 3258455..f35227d 100644
70840 --- a/kernel/time/timer_list.c
70841 +++ b/kernel/time/timer_list.c
70842 @@ -38,12 +38,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
70843
70844 static void print_name_offset(struct seq_file *m, void *sym)
70845 {
70846 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70847 + SEQ_printf(m, "<%p>", NULL);
70848 +#else
70849 char symname[KSYM_NAME_LEN];
70850
70851 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
70852 SEQ_printf(m, "<%pK>", sym);
70853 else
70854 SEQ_printf(m, "%s", symname);
70855 +#endif
70856 }
70857
70858 static void
70859 @@ -112,7 +116,11 @@ next_one:
70860 static void
70861 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
70862 {
70863 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70864 + SEQ_printf(m, " .base: %p\n", NULL);
70865 +#else
70866 SEQ_printf(m, " .base: %pK\n", base);
70867 +#endif
70868 SEQ_printf(m, " .index: %d\n",
70869 base->index);
70870 SEQ_printf(m, " .resolution: %Lu nsecs\n",
70871 @@ -293,7 +301,11 @@ static int __init init_timer_list_procfs(void)
70872 {
70873 struct proc_dir_entry *pe;
70874
70875 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70876 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
70877 +#else
70878 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
70879 +#endif
70880 if (!pe)
70881 return -ENOMEM;
70882 return 0;
70883 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
70884 index 0b537f2..9e71eca 100644
70885 --- a/kernel/time/timer_stats.c
70886 +++ b/kernel/time/timer_stats.c
70887 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
70888 static unsigned long nr_entries;
70889 static struct entry entries[MAX_ENTRIES];
70890
70891 -static atomic_t overflow_count;
70892 +static atomic_unchecked_t overflow_count;
70893
70894 /*
70895 * The entries are in a hash-table, for fast lookup:
70896 @@ -140,7 +140,7 @@ static void reset_entries(void)
70897 nr_entries = 0;
70898 memset(entries, 0, sizeof(entries));
70899 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
70900 - atomic_set(&overflow_count, 0);
70901 + atomic_set_unchecked(&overflow_count, 0);
70902 }
70903
70904 static struct entry *alloc_entry(void)
70905 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70906 if (likely(entry))
70907 entry->count++;
70908 else
70909 - atomic_inc(&overflow_count);
70910 + atomic_inc_unchecked(&overflow_count);
70911
70912 out_unlock:
70913 raw_spin_unlock_irqrestore(lock, flags);
70914 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
70915
70916 static void print_name_offset(struct seq_file *m, unsigned long addr)
70917 {
70918 +#ifdef CONFIG_GRKERNSEC_HIDESYM
70919 + seq_printf(m, "<%p>", NULL);
70920 +#else
70921 char symname[KSYM_NAME_LEN];
70922
70923 if (lookup_symbol_name(addr, symname) < 0)
70924 seq_printf(m, "<%p>", (void *)addr);
70925 else
70926 seq_printf(m, "%s", symname);
70927 +#endif
70928 }
70929
70930 static int tstats_show(struct seq_file *m, void *v)
70931 @@ -300,9 +304,9 @@ static int tstats_show(struct seq_file *m, void *v)
70932
70933 seq_puts(m, "Timer Stats Version: v0.2\n");
70934 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
70935 - if (atomic_read(&overflow_count))
70936 + if (atomic_read_unchecked(&overflow_count))
70937 seq_printf(m, "Overflow: %d entries\n",
70938 - atomic_read(&overflow_count));
70939 + atomic_read_unchecked(&overflow_count));
70940
70941 for (i = 0; i < nr_entries; i++) {
70942 entry = entries + i;
70943 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
70944 {
70945 struct proc_dir_entry *pe;
70946
70947 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
70948 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
70949 +#else
70950 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
70951 +#endif
70952 if (!pe)
70953 return -ENOMEM;
70954 return 0;
70955 diff --git a/kernel/timer.c b/kernel/timer.c
70956 index 6ec7e7e..cbc448b 100644
70957 --- a/kernel/timer.c
70958 +++ b/kernel/timer.c
70959 @@ -1362,7 +1362,7 @@ void update_process_times(int user_tick)
70960 /*
70961 * This function runs timers and the timer-tq in bottom half context.
70962 */
70963 -static void run_timer_softirq(struct softirq_action *h)
70964 +static void run_timer_softirq(void)
70965 {
70966 struct tvec_base *base = __this_cpu_read(tvec_bases);
70967
70968 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
70969 index c0bd030..62a1927 100644
70970 --- a/kernel/trace/blktrace.c
70971 +++ b/kernel/trace/blktrace.c
70972 @@ -317,7 +317,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
70973 struct blk_trace *bt = filp->private_data;
70974 char buf[16];
70975
70976 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
70977 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
70978
70979 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
70980 }
70981 @@ -375,7 +375,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
70982 return 1;
70983
70984 bt = buf->chan->private_data;
70985 - atomic_inc(&bt->dropped);
70986 + atomic_inc_unchecked(&bt->dropped);
70987 return 0;
70988 }
70989
70990 @@ -476,7 +476,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
70991
70992 bt->dir = dir;
70993 bt->dev = dev;
70994 - atomic_set(&bt->dropped, 0);
70995 + atomic_set_unchecked(&bt->dropped, 0);
70996
70997 ret = -EIO;
70998 bt->dropped_file = debugfs_create_file("dropped", 0444, dir, bt,
70999 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
71000 index a008663..30d7429 100644
71001 --- a/kernel/trace/ftrace.c
71002 +++ b/kernel/trace/ftrace.c
71003 @@ -1785,12 +1785,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
71004 if (unlikely(ftrace_disabled))
71005 return 0;
71006
71007 + ret = ftrace_arch_code_modify_prepare();
71008 + FTRACE_WARN_ON(ret);
71009 + if (ret)
71010 + return 0;
71011 +
71012 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
71013 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
71014 if (ret) {
71015 ftrace_bug(ret, ip);
71016 - return 0;
71017 }
71018 - return 1;
71019 + return ret ? 0 : 1;
71020 }
71021
71022 /*
71023 @@ -2885,7 +2890,7 @@ static void ftrace_free_entry_rcu(struct rcu_head *rhp)
71024
71025 int
71026 register_ftrace_function_probe(char *glob, struct ftrace_probe_ops *ops,
71027 - void *data)
71028 + void *data)
71029 {
71030 struct ftrace_func_probe *entry;
71031 struct ftrace_page *pg;
71032 @@ -3697,8 +3702,10 @@ static int ftrace_process_locs(struct module *mod,
71033 if (!count)
71034 return 0;
71035
71036 + pax_open_kernel();
71037 sort(start, count, sizeof(*start),
71038 ftrace_cmp_ips, ftrace_swap_ips);
71039 + pax_close_kernel();
71040
71041 start_pg = ftrace_allocate_pages(count);
71042 if (!start_pg)
71043 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
71044 index a7fa070..403bc8d 100644
71045 --- a/kernel/trace/trace.c
71046 +++ b/kernel/trace/trace.c
71047 @@ -4421,10 +4421,9 @@ static const struct file_operations tracing_dyn_info_fops = {
71048 };
71049 #endif
71050
71051 -static struct dentry *d_tracer;
71052 -
71053 struct dentry *tracing_init_dentry(void)
71054 {
71055 + static struct dentry *d_tracer;
71056 static int once;
71057
71058 if (d_tracer)
71059 @@ -4444,10 +4443,9 @@ struct dentry *tracing_init_dentry(void)
71060 return d_tracer;
71061 }
71062
71063 -static struct dentry *d_percpu;
71064 -
71065 struct dentry *tracing_dentry_percpu(void)
71066 {
71067 + static struct dentry *d_percpu;
71068 static int once;
71069 struct dentry *d_tracer;
71070
71071 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
71072 index 29111da..d190fe2 100644
71073 --- a/kernel/trace/trace_events.c
71074 +++ b/kernel/trace/trace_events.c
71075 @@ -1308,10 +1308,6 @@ static LIST_HEAD(ftrace_module_file_list);
71076 struct ftrace_module_file_ops {
71077 struct list_head list;
71078 struct module *mod;
71079 - struct file_operations id;
71080 - struct file_operations enable;
71081 - struct file_operations format;
71082 - struct file_operations filter;
71083 };
71084
71085 static struct ftrace_module_file_ops *
71086 @@ -1332,17 +1328,12 @@ trace_create_file_ops(struct module *mod)
71087
71088 file_ops->mod = mod;
71089
71090 - file_ops->id = ftrace_event_id_fops;
71091 - file_ops->id.owner = mod;
71092 -
71093 - file_ops->enable = ftrace_enable_fops;
71094 - file_ops->enable.owner = mod;
71095 -
71096 - file_ops->filter = ftrace_event_filter_fops;
71097 - file_ops->filter.owner = mod;
71098 -
71099 - file_ops->format = ftrace_event_format_fops;
71100 - file_ops->format.owner = mod;
71101 + pax_open_kernel();
71102 + *(void **)&mod->trace_id.owner = mod;
71103 + *(void **)&mod->trace_enable.owner = mod;
71104 + *(void **)&mod->trace_filter.owner = mod;
71105 + *(void **)&mod->trace_format.owner = mod;
71106 + pax_close_kernel();
71107
71108 list_add(&file_ops->list, &ftrace_module_file_list);
71109
71110 @@ -1366,8 +1357,8 @@ static void trace_module_add_events(struct module *mod)
71111
71112 for_each_event(call, start, end) {
71113 __trace_add_event_call(*call, mod,
71114 - &file_ops->id, &file_ops->enable,
71115 - &file_ops->filter, &file_ops->format);
71116 + &mod->trace_id, &mod->trace_enable,
71117 + &mod->trace_filter, &mod->trace_format);
71118 }
71119 }
71120
71121 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
71122 index fd3c8aa..5f324a6 100644
71123 --- a/kernel/trace/trace_mmiotrace.c
71124 +++ b/kernel/trace/trace_mmiotrace.c
71125 @@ -24,7 +24,7 @@ struct header_iter {
71126 static struct trace_array *mmio_trace_array;
71127 static bool overrun_detected;
71128 static unsigned long prev_overruns;
71129 -static atomic_t dropped_count;
71130 +static atomic_unchecked_t dropped_count;
71131
71132 static void mmio_reset_data(struct trace_array *tr)
71133 {
71134 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
71135
71136 static unsigned long count_overruns(struct trace_iterator *iter)
71137 {
71138 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
71139 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
71140 unsigned long over = ring_buffer_overruns(iter->tr->buffer);
71141
71142 if (over > prev_overruns)
71143 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
71144 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
71145 sizeof(*entry), 0, pc);
71146 if (!event) {
71147 - atomic_inc(&dropped_count);
71148 + atomic_inc_unchecked(&dropped_count);
71149 return;
71150 }
71151 entry = ring_buffer_event_data(event);
71152 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
71153 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
71154 sizeof(*entry), 0, pc);
71155 if (!event) {
71156 - atomic_inc(&dropped_count);
71157 + atomic_inc_unchecked(&dropped_count);
71158 return;
71159 }
71160 entry = ring_buffer_event_data(event);
71161 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
71162 index df611a0..10d8b32 100644
71163 --- a/kernel/trace/trace_output.c
71164 +++ b/kernel/trace/trace_output.c
71165 @@ -278,7 +278,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
71166
71167 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
71168 if (!IS_ERR(p)) {
71169 - p = mangle_path(s->buffer + s->len, p, "\n");
71170 + p = mangle_path(s->buffer + s->len, p, "\n\\");
71171 if (p) {
71172 s->len = p - s->buffer;
71173 return 1;
71174 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
71175 index d4545f4..a9010a1 100644
71176 --- a/kernel/trace/trace_stack.c
71177 +++ b/kernel/trace/trace_stack.c
71178 @@ -53,7 +53,7 @@ static inline void check_stack(void)
71179 return;
71180
71181 /* we do not handle interrupt stacks yet */
71182 - if (!object_is_on_stack(&this_size))
71183 + if (!object_starts_on_stack(&this_size))
71184 return;
71185
71186 local_irq_save(flags);
71187 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
71188 index 2016347..070fbbe 100644
71189 --- a/kernel/workqueue.c
71190 +++ b/kernel/workqueue.c
71191 @@ -3451,7 +3451,7 @@ static int __cpuinit trustee_thread(void *__gcwq)
71192 */
71193 worker_flags |= WORKER_REBIND;
71194 worker_flags &= ~WORKER_ROGUE;
71195 - ACCESS_ONCE(worker->flags) = worker_flags;
71196 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
71197
71198 /* queue rebind_work, wq doesn't matter, use the default one */
71199 if (test_and_set_bit(WORK_STRUCT_PENDING_BIT,
71200 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
71201 index ff5bdee..e68c124 100644
71202 --- a/lib/Kconfig.debug
71203 +++ b/lib/Kconfig.debug
71204 @@ -1165,6 +1165,7 @@ config LATENCYTOP
71205 depends on DEBUG_KERNEL
71206 depends on STACKTRACE_SUPPORT
71207 depends on PROC_FS
71208 + depends on !GRKERNSEC_HIDESYM
71209 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND
71210 select KALLSYMS
71211 select KALLSYMS_ALL
71212 @@ -1180,7 +1181,7 @@ source kernel/trace/Kconfig
71213
71214 config PROVIDE_OHCI1394_DMA_INIT
71215 bool "Remote debugging over FireWire early on boot"
71216 - depends on PCI && X86
71217 + depends on PCI && X86 && !GRKERNSEC
71218 help
71219 If you want to debug problems which hang or crash the kernel early
71220 on boot and the crashing machine has a FireWire port, you can use
71221 @@ -1209,7 +1210,7 @@ config PROVIDE_OHCI1394_DMA_INIT
71222
71223 config FIREWIRE_OHCI_REMOTE_DMA
71224 bool "Remote debugging over FireWire with firewire-ohci"
71225 - depends on FIREWIRE_OHCI
71226 + depends on FIREWIRE_OHCI && !GRKERNSEC
71227 help
71228 This option lets you use the FireWire bus for remote debugging
71229 with help of the firewire-ohci driver. It enables unfiltered
71230 diff --git a/lib/bitmap.c b/lib/bitmap.c
71231 index 06fdfa1..97c5c7d 100644
71232 --- a/lib/bitmap.c
71233 +++ b/lib/bitmap.c
71234 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
71235 {
71236 int c, old_c, totaldigits, ndigits, nchunks, nbits;
71237 u32 chunk;
71238 - const char __user __force *ubuf = (const char __user __force *)buf;
71239 + const char __user *ubuf = (const char __force_user *)buf;
71240
71241 bitmap_zero(maskp, nmaskbits);
71242
71243 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
71244 {
71245 if (!access_ok(VERIFY_READ, ubuf, ulen))
71246 return -EFAULT;
71247 - return __bitmap_parse((const char __force *)ubuf,
71248 + return __bitmap_parse((const char __force_kernel *)ubuf,
71249 ulen, 1, maskp, nmaskbits);
71250
71251 }
71252 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
71253 {
71254 unsigned a, b;
71255 int c, old_c, totaldigits;
71256 - const char __user __force *ubuf = (const char __user __force *)buf;
71257 + const char __user *ubuf = (const char __force_user *)buf;
71258 int exp_digit, in_range;
71259
71260 totaldigits = c = 0;
71261 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
71262 {
71263 if (!access_ok(VERIFY_READ, ubuf, ulen))
71264 return -EFAULT;
71265 - return __bitmap_parselist((const char __force *)ubuf,
71266 + return __bitmap_parselist((const char __force_kernel *)ubuf,
71267 ulen, 1, maskp, nmaskbits);
71268 }
71269 EXPORT_SYMBOL(bitmap_parselist_user);
71270 diff --git a/lib/bug.c b/lib/bug.c
71271 index a28c141..2bd3d95 100644
71272 --- a/lib/bug.c
71273 +++ b/lib/bug.c
71274 @@ -133,6 +133,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
71275 return BUG_TRAP_TYPE_NONE;
71276
71277 bug = find_bug(bugaddr);
71278 + if (!bug)
71279 + return BUG_TRAP_TYPE_NONE;
71280
71281 file = NULL;
71282 line = 0;
71283 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
71284 index d11808c..dc2d6f8 100644
71285 --- a/lib/debugobjects.c
71286 +++ b/lib/debugobjects.c
71287 @@ -287,7 +287,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
71288 if (limit > 4)
71289 return;
71290
71291 - is_on_stack = object_is_on_stack(addr);
71292 + is_on_stack = object_starts_on_stack(addr);
71293 if (is_on_stack == onstack)
71294 return;
71295
71296 diff --git a/lib/devres.c b/lib/devres.c
71297 index 80b9c76..9e32279 100644
71298 --- a/lib/devres.c
71299 +++ b/lib/devres.c
71300 @@ -80,7 +80,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
71301 void devm_iounmap(struct device *dev, void __iomem *addr)
71302 {
71303 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
71304 - (void *)addr));
71305 + (void __force *)addr));
71306 iounmap(addr);
71307 }
71308 EXPORT_SYMBOL(devm_iounmap);
71309 @@ -192,7 +192,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
71310 {
71311 ioport_unmap(addr);
71312 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
71313 - devm_ioport_map_match, (void *)addr));
71314 + devm_ioport_map_match, (void __force *)addr));
71315 }
71316 EXPORT_SYMBOL(devm_ioport_unmap);
71317
71318 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
71319 index 66ce414..6f0a0dd 100644
71320 --- a/lib/dma-debug.c
71321 +++ b/lib/dma-debug.c
71322 @@ -924,7 +924,7 @@ out:
71323
71324 static void check_for_stack(struct device *dev, void *addr)
71325 {
71326 - if (object_is_on_stack(addr))
71327 + if (object_starts_on_stack(addr))
71328 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
71329 "stack [addr=%p]\n", addr);
71330 }
71331 diff --git a/lib/inflate.c b/lib/inflate.c
71332 index 013a761..c28f3fc 100644
71333 --- a/lib/inflate.c
71334 +++ b/lib/inflate.c
71335 @@ -269,7 +269,7 @@ static void free(void *where)
71336 malloc_ptr = free_mem_ptr;
71337 }
71338 #else
71339 -#define malloc(a) kmalloc(a, GFP_KERNEL)
71340 +#define malloc(a) kmalloc((a), GFP_KERNEL)
71341 #define free(a) kfree(a)
71342 #endif
71343
71344 diff --git a/lib/ioremap.c b/lib/ioremap.c
71345 index 0c9216c..863bd89 100644
71346 --- a/lib/ioremap.c
71347 +++ b/lib/ioremap.c
71348 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
71349 unsigned long next;
71350
71351 phys_addr -= addr;
71352 - pmd = pmd_alloc(&init_mm, pud, addr);
71353 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
71354 if (!pmd)
71355 return -ENOMEM;
71356 do {
71357 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
71358 unsigned long next;
71359
71360 phys_addr -= addr;
71361 - pud = pud_alloc(&init_mm, pgd, addr);
71362 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
71363 if (!pud)
71364 return -ENOMEM;
71365 do {
71366 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
71367 index bd2bea9..6b3c95e 100644
71368 --- a/lib/is_single_threaded.c
71369 +++ b/lib/is_single_threaded.c
71370 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
71371 struct task_struct *p, *t;
71372 bool ret;
71373
71374 + if (!mm)
71375 + return true;
71376 +
71377 if (atomic_read(&task->signal->live) != 1)
71378 return false;
71379
71380 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
71381 index e796429..6e38f9f 100644
71382 --- a/lib/radix-tree.c
71383 +++ b/lib/radix-tree.c
71384 @@ -92,7 +92,7 @@ struct radix_tree_preload {
71385 int nr;
71386 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
71387 };
71388 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
71389 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
71390
71391 static inline void *ptr_to_indirect(void *ptr)
71392 {
71393 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
71394 index 598a73e..5c5aeb5 100644
71395 --- a/lib/vsprintf.c
71396 +++ b/lib/vsprintf.c
71397 @@ -16,6 +16,9 @@
71398 * - scnprintf and vscnprintf
71399 */
71400
71401 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71402 +#define __INCLUDED_BY_HIDESYM 1
71403 +#endif
71404 #include <stdarg.h>
71405 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
71406 #include <linux/types.h>
71407 @@ -536,7 +539,7 @@ char *symbol_string(char *buf, char *end, void *ptr,
71408 char sym[KSYM_SYMBOL_LEN];
71409 if (ext == 'B')
71410 sprint_backtrace(sym, value);
71411 - else if (ext != 'f' && ext != 's')
71412 + else if (ext != 'f' && ext != 's' && ext != 'a')
71413 sprint_symbol(sym, value);
71414 else
71415 sprint_symbol_no_offset(sym, value);
71416 @@ -912,7 +915,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
71417 return number(buf, end, *(const netdev_features_t *)addr, spec);
71418 }
71419
71420 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71421 +int kptr_restrict __read_mostly = 2;
71422 +#else
71423 int kptr_restrict __read_mostly;
71424 +#endif
71425
71426 /*
71427 * Show a '%p' thing. A kernel extension is that the '%p' is followed
71428 @@ -926,6 +933,8 @@ int kptr_restrict __read_mostly;
71429 * - 'S' For symbolic direct pointers with offset
71430 * - 's' For symbolic direct pointers without offset
71431 * - 'B' For backtraced symbolic direct pointers with offset
71432 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
71433 + * - 'a' For symbolic direct pointers without offset approved for use with GRKERNSEC_HIDESYM
71434 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
71435 * - 'r' For raw struct resource, e.g., [mem 0x0-0x1f flags 0x201]
71436 * - 'M' For a 6-byte MAC address, it prints the address in the
71437 @@ -973,12 +982,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71438
71439 if (!ptr && *fmt != 'K') {
71440 /*
71441 - * Print (null) with the same width as a pointer so it makes
71442 + * Print (nil) with the same width as a pointer so it makes
71443 * tabular output look nice.
71444 */
71445 if (spec.field_width == -1)
71446 spec.field_width = default_width;
71447 - return string(buf, end, "(null)", spec);
71448 + return string(buf, end, "(nil)", spec);
71449 }
71450
71451 switch (*fmt) {
71452 @@ -988,6 +997,13 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71453 /* Fallthrough */
71454 case 'S':
71455 case 's':
71456 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71457 + break;
71458 +#else
71459 + return symbol_string(buf, end, ptr, spec, *fmt);
71460 +#endif
71461 + case 'A':
71462 + case 'a':
71463 case 'B':
71464 return symbol_string(buf, end, ptr, spec, *fmt);
71465 case 'R':
71466 @@ -1025,6 +1041,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71467 va_end(va);
71468 return buf;
71469 }
71470 + case 'P':
71471 + break;
71472 case 'K':
71473 /*
71474 * %pK cannot be used in IRQ context because its test
71475 @@ -1048,6 +1066,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
71476 }
71477 break;
71478 }
71479 +
71480 +#ifdef CONFIG_GRKERNSEC_HIDESYM
71481 + /* 'P' = approved pointers to copy to userland,
71482 + as in the /proc/kallsyms case, as we make it display nothing
71483 + for non-root users, and the real contents for root users
71484 + Also ignore 'K' pointers, since we force their NULLing for non-root users
71485 + above
71486 + */
71487 + if (ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
71488 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
71489 + dump_stack();
71490 + ptr = NULL;
71491 + }
71492 +#endif
71493 +
71494 spec.flags |= SMALL;
71495 if (spec.field_width == -1) {
71496 spec.field_width = default_width;
71497 @@ -1759,11 +1792,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71498 typeof(type) value; \
71499 if (sizeof(type) == 8) { \
71500 args = PTR_ALIGN(args, sizeof(u32)); \
71501 - *(u32 *)&value = *(u32 *)args; \
71502 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
71503 + *(u32 *)&value = *(const u32 *)args; \
71504 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
71505 } else { \
71506 args = PTR_ALIGN(args, sizeof(type)); \
71507 - value = *(typeof(type) *)args; \
71508 + value = *(const typeof(type) *)args; \
71509 } \
71510 args += sizeof(type); \
71511 value; \
71512 @@ -1826,7 +1859,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
71513 case FORMAT_TYPE_STR: {
71514 const char *str_arg = args;
71515 args += strlen(str_arg) + 1;
71516 - str = string(str, end, (char *)str_arg, spec);
71517 + str = string(str, end, str_arg, spec);
71518 break;
71519 }
71520
71521 diff --git a/localversion-grsec b/localversion-grsec
71522 new file mode 100644
71523 index 0000000..7cd6065
71524 --- /dev/null
71525 +++ b/localversion-grsec
71526 @@ -0,0 +1 @@
71527 +-grsec
71528 diff --git a/mm/Kconfig b/mm/Kconfig
71529 index 82fed4e..979e814 100644
71530 --- a/mm/Kconfig
71531 +++ b/mm/Kconfig
71532 @@ -247,10 +247,10 @@ config KSM
71533 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
71534
71535 config DEFAULT_MMAP_MIN_ADDR
71536 - int "Low address space to protect from user allocation"
71537 + int "Low address space to protect from user allocation"
71538 depends on MMU
71539 - default 4096
71540 - help
71541 + default 65536
71542 + help
71543 This is the portion of low virtual memory which should be protected
71544 from userspace allocation. Keeping a user from writing to low pages
71545 can help reduce the impact of kernel NULL pointer bugs.
71546 @@ -280,7 +280,7 @@ config MEMORY_FAILURE
71547
71548 config HWPOISON_INJECT
71549 tristate "HWPoison pages injector"
71550 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
71551 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
71552 select PROC_PAGE_MONITOR
71553
71554 config NOMMU_INITIAL_TRIM_EXCESS
71555 diff --git a/mm/filemap.c b/mm/filemap.c
71556 index a4a5260..6151dc5 100644
71557 --- a/mm/filemap.c
71558 +++ b/mm/filemap.c
71559 @@ -1723,7 +1723,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
71560 struct address_space *mapping = file->f_mapping;
71561
71562 if (!mapping->a_ops->readpage)
71563 - return -ENOEXEC;
71564 + return -ENODEV;
71565 file_accessed(file);
71566 vma->vm_ops = &generic_file_vm_ops;
71567 vma->vm_flags |= VM_CAN_NONLINEAR;
71568 @@ -2064,6 +2064,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
71569 *pos = i_size_read(inode);
71570
71571 if (limit != RLIM_INFINITY) {
71572 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
71573 if (*pos >= limit) {
71574 send_sig(SIGXFSZ, current, 0);
71575 return -EFBIG;
71576 diff --git a/mm/fremap.c b/mm/fremap.c
71577 index 9ed4fd4..c42648d 100644
71578 --- a/mm/fremap.c
71579 +++ b/mm/fremap.c
71580 @@ -155,6 +155,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
71581 retry:
71582 vma = find_vma(mm, start);
71583
71584 +#ifdef CONFIG_PAX_SEGMEXEC
71585 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
71586 + goto out;
71587 +#endif
71588 +
71589 /*
71590 * Make sure the vma is shared, that it supports prefaulting,
71591 * and that the remapped range is valid and fully within
71592 diff --git a/mm/highmem.c b/mm/highmem.c
71593 index 57d82c6..e9e0552 100644
71594 --- a/mm/highmem.c
71595 +++ b/mm/highmem.c
71596 @@ -125,9 +125,10 @@ static void flush_all_zero_pkmaps(void)
71597 * So no dangers, even with speculative execution.
71598 */
71599 page = pte_page(pkmap_page_table[i]);
71600 + pax_open_kernel();
71601 pte_clear(&init_mm, (unsigned long)page_address(page),
71602 &pkmap_page_table[i]);
71603 -
71604 + pax_close_kernel();
71605 set_page_address(page, NULL);
71606 need_flush = 1;
71607 }
71608 @@ -186,9 +187,11 @@ start:
71609 }
71610 }
71611 vaddr = PKMAP_ADDR(last_pkmap_nr);
71612 +
71613 + pax_open_kernel();
71614 set_pte_at(&init_mm, vaddr,
71615 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
71616 -
71617 + pax_close_kernel();
71618 pkmap_count[last_pkmap_nr] = 1;
71619 set_page_address(page, (void *)vaddr);
71620
71621 diff --git a/mm/huge_memory.c b/mm/huge_memory.c
71622 index 57c4b93..24b8f59 100644
71623 --- a/mm/huge_memory.c
71624 +++ b/mm/huge_memory.c
71625 @@ -735,7 +735,7 @@ out:
71626 * run pte_offset_map on the pmd, if an huge pmd could
71627 * materialize from under us from a different thread.
71628 */
71629 - if (unlikely(__pte_alloc(mm, vma, pmd, address)))
71630 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
71631 return VM_FAULT_OOM;
71632 /* if an huge pmd materialized from under us just retry later */
71633 if (unlikely(pmd_trans_huge(*pmd)))
71634 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
71635 index 19558df..f7743b3 100644
71636 --- a/mm/hugetlb.c
71637 +++ b/mm/hugetlb.c
71638 @@ -2463,6 +2463,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
71639 return 1;
71640 }
71641
71642 +#ifdef CONFIG_PAX_SEGMEXEC
71643 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
71644 +{
71645 + struct mm_struct *mm = vma->vm_mm;
71646 + struct vm_area_struct *vma_m;
71647 + unsigned long address_m;
71648 + pte_t *ptep_m;
71649 +
71650 + vma_m = pax_find_mirror_vma(vma);
71651 + if (!vma_m)
71652 + return;
71653 +
71654 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
71655 + address_m = address + SEGMEXEC_TASK_SIZE;
71656 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
71657 + get_page(page_m);
71658 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
71659 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
71660 +}
71661 +#endif
71662 +
71663 /*
71664 * Hugetlb_cow() should be called with page lock of the original hugepage held.
71665 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
71666 @@ -2575,6 +2596,11 @@ retry_avoidcopy:
71667 make_huge_pte(vma, new_page, 1));
71668 page_remove_rmap(old_page);
71669 hugepage_add_new_anon_rmap(new_page, vma, address);
71670 +
71671 +#ifdef CONFIG_PAX_SEGMEXEC
71672 + pax_mirror_huge_pte(vma, address, new_page);
71673 +#endif
71674 +
71675 /* Make the old page be freed below */
71676 new_page = old_page;
71677 mmu_notifier_invalidate_range_end(mm,
71678 @@ -2729,6 +2755,10 @@ retry:
71679 && (vma->vm_flags & VM_SHARED)));
71680 set_huge_pte_at(mm, address, ptep, new_pte);
71681
71682 +#ifdef CONFIG_PAX_SEGMEXEC
71683 + pax_mirror_huge_pte(vma, address, page);
71684 +#endif
71685 +
71686 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
71687 /* Optimization, do the COW without a second fault */
71688 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page);
71689 @@ -2758,6 +2788,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71690 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
71691 struct hstate *h = hstate_vma(vma);
71692
71693 +#ifdef CONFIG_PAX_SEGMEXEC
71694 + struct vm_area_struct *vma_m;
71695 +#endif
71696 +
71697 address &= huge_page_mask(h);
71698
71699 ptep = huge_pte_offset(mm, address);
71700 @@ -2771,6 +2805,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
71701 VM_FAULT_SET_HINDEX(h - hstates);
71702 }
71703
71704 +#ifdef CONFIG_PAX_SEGMEXEC
71705 + vma_m = pax_find_mirror_vma(vma);
71706 + if (vma_m) {
71707 + unsigned long address_m;
71708 +
71709 + if (vma->vm_start > vma_m->vm_start) {
71710 + address_m = address;
71711 + address -= SEGMEXEC_TASK_SIZE;
71712 + vma = vma_m;
71713 + h = hstate_vma(vma);
71714 + } else
71715 + address_m = address + SEGMEXEC_TASK_SIZE;
71716 +
71717 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
71718 + return VM_FAULT_OOM;
71719 + address_m &= HPAGE_MASK;
71720 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
71721 + }
71722 +#endif
71723 +
71724 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
71725 if (!ptep)
71726 return VM_FAULT_OOM;
71727 diff --git a/mm/internal.h b/mm/internal.h
71728 index 8052379..47029d1 100644
71729 --- a/mm/internal.h
71730 +++ b/mm/internal.h
71731 @@ -95,6 +95,7 @@ extern void putback_lru_page(struct page *page);
71732 * in mm/page_alloc.c
71733 */
71734 extern void __free_pages_bootmem(struct page *page, unsigned int order);
71735 +extern void free_compound_page(struct page *page);
71736 extern void prep_compound_page(struct page *page, unsigned long order);
71737 #ifdef CONFIG_MEMORY_FAILURE
71738 extern bool is_free_buddy_page(struct page *page);
71739 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
71740 index 45eb621..6ccd8ea 100644
71741 --- a/mm/kmemleak.c
71742 +++ b/mm/kmemleak.c
71743 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
71744
71745 for (i = 0; i < object->trace_len; i++) {
71746 void *ptr = (void *)object->trace[i];
71747 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
71748 + seq_printf(seq, " [<%p>] %pA\n", ptr, ptr);
71749 }
71750 }
71751
71752 diff --git a/mm/maccess.c b/mm/maccess.c
71753 index d53adf9..03a24bf 100644
71754 --- a/mm/maccess.c
71755 +++ b/mm/maccess.c
71756 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
71757 set_fs(KERNEL_DS);
71758 pagefault_disable();
71759 ret = __copy_from_user_inatomic(dst,
71760 - (__force const void __user *)src, size);
71761 + (const void __force_user *)src, size);
71762 pagefault_enable();
71763 set_fs(old_fs);
71764
71765 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
71766
71767 set_fs(KERNEL_DS);
71768 pagefault_disable();
71769 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
71770 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
71771 pagefault_enable();
71772 set_fs(old_fs);
71773
71774 diff --git a/mm/madvise.c b/mm/madvise.c
71775 index 14d260f..b2a80fd 100644
71776 --- a/mm/madvise.c
71777 +++ b/mm/madvise.c
71778 @@ -48,6 +48,10 @@ static long madvise_behavior(struct vm_area_struct * vma,
71779 pgoff_t pgoff;
71780 unsigned long new_flags = vma->vm_flags;
71781
71782 +#ifdef CONFIG_PAX_SEGMEXEC
71783 + struct vm_area_struct *vma_m;
71784 +#endif
71785 +
71786 switch (behavior) {
71787 case MADV_NORMAL:
71788 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
71789 @@ -119,6 +123,13 @@ success:
71790 /*
71791 * vm_flags is protected by the mmap_sem held in write mode.
71792 */
71793 +
71794 +#ifdef CONFIG_PAX_SEGMEXEC
71795 + vma_m = pax_find_mirror_vma(vma);
71796 + if (vma_m)
71797 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
71798 +#endif
71799 +
71800 vma->vm_flags = new_flags;
71801
71802 out:
71803 @@ -177,6 +188,11 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71804 struct vm_area_struct ** prev,
71805 unsigned long start, unsigned long end)
71806 {
71807 +
71808 +#ifdef CONFIG_PAX_SEGMEXEC
71809 + struct vm_area_struct *vma_m;
71810 +#endif
71811 +
71812 *prev = vma;
71813 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
71814 return -EINVAL;
71815 @@ -189,6 +205,21 @@ static long madvise_dontneed(struct vm_area_struct * vma,
71816 zap_page_range(vma, start, end - start, &details);
71817 } else
71818 zap_page_range(vma, start, end - start, NULL);
71819 +
71820 +#ifdef CONFIG_PAX_SEGMEXEC
71821 + vma_m = pax_find_mirror_vma(vma);
71822 + if (vma_m) {
71823 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
71824 + struct zap_details details = {
71825 + .nonlinear_vma = vma_m,
71826 + .last_index = ULONG_MAX,
71827 + };
71828 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
71829 + } else
71830 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
71831 + }
71832 +#endif
71833 +
71834 return 0;
71835 }
71836
71837 @@ -393,6 +424,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
71838 if (end < start)
71839 goto out;
71840
71841 +#ifdef CONFIG_PAX_SEGMEXEC
71842 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
71843 + if (end > SEGMEXEC_TASK_SIZE)
71844 + goto out;
71845 + } else
71846 +#endif
71847 +
71848 + if (end > TASK_SIZE)
71849 + goto out;
71850 +
71851 error = 0;
71852 if (end == start)
71853 goto out;
71854 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
71855 index 6de0d61..da836cf 100644
71856 --- a/mm/memory-failure.c
71857 +++ b/mm/memory-failure.c
71858 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
71859
71860 int sysctl_memory_failure_recovery __read_mostly = 1;
71861
71862 -atomic_long_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71863 +atomic_long_unchecked_t mce_bad_pages __read_mostly = ATOMIC_LONG_INIT(0);
71864
71865 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
71866
71867 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
71868 pfn, t->comm, t->pid);
71869 si.si_signo = SIGBUS;
71870 si.si_errno = 0;
71871 - si.si_addr = (void *)addr;
71872 + si.si_addr = (void __user *)addr;
71873 #ifdef __ARCH_SI_TRAPNO
71874 si.si_trapno = trapno;
71875 #endif
71876 @@ -1038,7 +1038,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71877 }
71878
71879 nr_pages = 1 << compound_trans_order(hpage);
71880 - atomic_long_add(nr_pages, &mce_bad_pages);
71881 + atomic_long_add_unchecked(nr_pages, &mce_bad_pages);
71882
71883 /*
71884 * We need/can do nothing about count=0 pages.
71885 @@ -1068,7 +1068,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71886 if (!PageHWPoison(hpage)
71887 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
71888 || (p != hpage && TestSetPageHWPoison(hpage))) {
71889 - atomic_long_sub(nr_pages, &mce_bad_pages);
71890 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71891 return 0;
71892 }
71893 set_page_hwpoison_huge_page(hpage);
71894 @@ -1126,7 +1126,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
71895 }
71896 if (hwpoison_filter(p)) {
71897 if (TestClearPageHWPoison(p))
71898 - atomic_long_sub(nr_pages, &mce_bad_pages);
71899 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71900 unlock_page(hpage);
71901 put_page(hpage);
71902 return 0;
71903 @@ -1321,7 +1321,7 @@ int unpoison_memory(unsigned long pfn)
71904 return 0;
71905 }
71906 if (TestClearPageHWPoison(p))
71907 - atomic_long_sub(nr_pages, &mce_bad_pages);
71908 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71909 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
71910 return 0;
71911 }
71912 @@ -1335,7 +1335,7 @@ int unpoison_memory(unsigned long pfn)
71913 */
71914 if (TestClearPageHWPoison(page)) {
71915 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
71916 - atomic_long_sub(nr_pages, &mce_bad_pages);
71917 + atomic_long_sub_unchecked(nr_pages, &mce_bad_pages);
71918 freeit = 1;
71919 if (PageHuge(page))
71920 clear_page_hwpoison_huge_page(page);
71921 @@ -1448,7 +1448,7 @@ static int soft_offline_huge_page(struct page *page, int flags)
71922 }
71923 done:
71924 if (!PageHWPoison(hpage))
71925 - atomic_long_add(1 << compound_trans_order(hpage), &mce_bad_pages);
71926 + atomic_long_add_unchecked(1 << compound_trans_order(hpage), &mce_bad_pages);
71927 set_page_hwpoison_huge_page(hpage);
71928 dequeue_hwpoisoned_huge_page(hpage);
71929 /* keep elevated page count for bad page */
71930 @@ -1579,7 +1579,7 @@ int soft_offline_page(struct page *page, int flags)
71931 return ret;
71932
71933 done:
71934 - atomic_long_add(1, &mce_bad_pages);
71935 + atomic_long_add_unchecked(1, &mce_bad_pages);
71936 SetPageHWPoison(page);
71937 /* keep elevated page count for bad page */
71938 return ret;
71939 diff --git a/mm/memory.c b/mm/memory.c
71940 index 2466d12..595ed79 100644
71941 --- a/mm/memory.c
71942 +++ b/mm/memory.c
71943 @@ -422,6 +422,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71944 free_pte_range(tlb, pmd, addr);
71945 } while (pmd++, addr = next, addr != end);
71946
71947 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
71948 start &= PUD_MASK;
71949 if (start < floor)
71950 return;
71951 @@ -436,6 +437,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
71952 pmd = pmd_offset(pud, start);
71953 pud_clear(pud);
71954 pmd_free_tlb(tlb, pmd, start);
71955 +#endif
71956 +
71957 }
71958
71959 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71960 @@ -455,6 +458,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71961 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
71962 } while (pud++, addr = next, addr != end);
71963
71964 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
71965 start &= PGDIR_MASK;
71966 if (start < floor)
71967 return;
71968 @@ -469,6 +473,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
71969 pud = pud_offset(pgd, start);
71970 pgd_clear(pgd);
71971 pud_free_tlb(tlb, pud, start);
71972 +#endif
71973 +
71974 }
71975
71976 /*
71977 @@ -1602,12 +1608,6 @@ no_page_table:
71978 return page;
71979 }
71980
71981 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
71982 -{
71983 - return stack_guard_page_start(vma, addr) ||
71984 - stack_guard_page_end(vma, addr+PAGE_SIZE);
71985 -}
71986 -
71987 /**
71988 * __get_user_pages() - pin user pages in memory
71989 * @tsk: task_struct of target task
71990 @@ -1680,10 +1680,10 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
71991 (VM_MAYREAD | VM_MAYWRITE) : (VM_READ | VM_WRITE);
71992 i = 0;
71993
71994 - do {
71995 + while (nr_pages) {
71996 struct vm_area_struct *vma;
71997
71998 - vma = find_extend_vma(mm, start);
71999 + vma = find_vma(mm, start);
72000 if (!vma && in_gate_area(mm, start)) {
72001 unsigned long pg = start & PAGE_MASK;
72002 pgd_t *pgd;
72003 @@ -1731,7 +1731,7 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72004 goto next_page;
72005 }
72006
72007 - if (!vma ||
72008 + if (!vma || start < vma->vm_start ||
72009 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
72010 !(vm_flags & vma->vm_flags))
72011 return i ? : -EFAULT;
72012 @@ -1758,11 +1758,6 @@ int __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
72013 int ret;
72014 unsigned int fault_flags = 0;
72015
72016 - /* For mlock, just skip the stack guard page. */
72017 - if (foll_flags & FOLL_MLOCK) {
72018 - if (stack_guard_page(vma, start))
72019 - goto next_page;
72020 - }
72021 if (foll_flags & FOLL_WRITE)
72022 fault_flags |= FAULT_FLAG_WRITE;
72023 if (nonblocking)
72024 @@ -1836,7 +1831,7 @@ next_page:
72025 start += PAGE_SIZE;
72026 nr_pages--;
72027 } while (nr_pages && start < vma->vm_end);
72028 - } while (nr_pages);
72029 + }
72030 return i;
72031 }
72032 EXPORT_SYMBOL(__get_user_pages);
72033 @@ -2043,6 +2038,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
72034 page_add_file_rmap(page);
72035 set_pte_at(mm, addr, pte, mk_pte(page, prot));
72036
72037 +#ifdef CONFIG_PAX_SEGMEXEC
72038 + pax_mirror_file_pte(vma, addr, page, ptl);
72039 +#endif
72040 +
72041 retval = 0;
72042 pte_unmap_unlock(pte, ptl);
72043 return retval;
72044 @@ -2077,10 +2076,22 @@ out:
72045 int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
72046 struct page *page)
72047 {
72048 +
72049 +#ifdef CONFIG_PAX_SEGMEXEC
72050 + struct vm_area_struct *vma_m;
72051 +#endif
72052 +
72053 if (addr < vma->vm_start || addr >= vma->vm_end)
72054 return -EFAULT;
72055 if (!page_count(page))
72056 return -EINVAL;
72057 +
72058 +#ifdef CONFIG_PAX_SEGMEXEC
72059 + vma_m = pax_find_mirror_vma(vma);
72060 + if (vma_m)
72061 + vma_m->vm_flags |= VM_INSERTPAGE;
72062 +#endif
72063 +
72064 vma->vm_flags |= VM_INSERTPAGE;
72065 return insert_page(vma, addr, page, vma->vm_page_prot);
72066 }
72067 @@ -2166,6 +2177,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
72068 unsigned long pfn)
72069 {
72070 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
72071 + BUG_ON(vma->vm_mirror);
72072
72073 if (addr < vma->vm_start || addr >= vma->vm_end)
72074 return -EFAULT;
72075 @@ -2373,7 +2385,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
72076
72077 BUG_ON(pud_huge(*pud));
72078
72079 - pmd = pmd_alloc(mm, pud, addr);
72080 + pmd = (mm == &init_mm) ?
72081 + pmd_alloc_kernel(mm, pud, addr) :
72082 + pmd_alloc(mm, pud, addr);
72083 if (!pmd)
72084 return -ENOMEM;
72085 do {
72086 @@ -2393,7 +2407,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
72087 unsigned long next;
72088 int err;
72089
72090 - pud = pud_alloc(mm, pgd, addr);
72091 + pud = (mm == &init_mm) ?
72092 + pud_alloc_kernel(mm, pgd, addr) :
72093 + pud_alloc(mm, pgd, addr);
72094 if (!pud)
72095 return -ENOMEM;
72096 do {
72097 @@ -2481,6 +2497,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
72098 copy_user_highpage(dst, src, va, vma);
72099 }
72100
72101 +#ifdef CONFIG_PAX_SEGMEXEC
72102 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
72103 +{
72104 + struct mm_struct *mm = vma->vm_mm;
72105 + spinlock_t *ptl;
72106 + pte_t *pte, entry;
72107 +
72108 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
72109 + entry = *pte;
72110 + if (!pte_present(entry)) {
72111 + if (!pte_none(entry)) {
72112 + BUG_ON(pte_file(entry));
72113 + free_swap_and_cache(pte_to_swp_entry(entry));
72114 + pte_clear_not_present_full(mm, address, pte, 0);
72115 + }
72116 + } else {
72117 + struct page *page;
72118 +
72119 + flush_cache_page(vma, address, pte_pfn(entry));
72120 + entry = ptep_clear_flush(vma, address, pte);
72121 + BUG_ON(pte_dirty(entry));
72122 + page = vm_normal_page(vma, address, entry);
72123 + if (page) {
72124 + update_hiwater_rss(mm);
72125 + if (PageAnon(page))
72126 + dec_mm_counter_fast(mm, MM_ANONPAGES);
72127 + else
72128 + dec_mm_counter_fast(mm, MM_FILEPAGES);
72129 + page_remove_rmap(page);
72130 + page_cache_release(page);
72131 + }
72132 + }
72133 + pte_unmap_unlock(pte, ptl);
72134 +}
72135 +
72136 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
72137 + *
72138 + * the ptl of the lower mapped page is held on entry and is not released on exit
72139 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
72140 + */
72141 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72142 +{
72143 + struct mm_struct *mm = vma->vm_mm;
72144 + unsigned long address_m;
72145 + spinlock_t *ptl_m;
72146 + struct vm_area_struct *vma_m;
72147 + pmd_t *pmd_m;
72148 + pte_t *pte_m, entry_m;
72149 +
72150 + BUG_ON(!page_m || !PageAnon(page_m));
72151 +
72152 + vma_m = pax_find_mirror_vma(vma);
72153 + if (!vma_m)
72154 + return;
72155 +
72156 + BUG_ON(!PageLocked(page_m));
72157 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72158 + address_m = address + SEGMEXEC_TASK_SIZE;
72159 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72160 + pte_m = pte_offset_map(pmd_m, address_m);
72161 + ptl_m = pte_lockptr(mm, pmd_m);
72162 + if (ptl != ptl_m) {
72163 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72164 + if (!pte_none(*pte_m))
72165 + goto out;
72166 + }
72167 +
72168 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72169 + page_cache_get(page_m);
72170 + page_add_anon_rmap(page_m, vma_m, address_m);
72171 + inc_mm_counter_fast(mm, MM_ANONPAGES);
72172 + set_pte_at(mm, address_m, pte_m, entry_m);
72173 + update_mmu_cache(vma_m, address_m, entry_m);
72174 +out:
72175 + if (ptl != ptl_m)
72176 + spin_unlock(ptl_m);
72177 + pte_unmap(pte_m);
72178 + unlock_page(page_m);
72179 +}
72180 +
72181 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
72182 +{
72183 + struct mm_struct *mm = vma->vm_mm;
72184 + unsigned long address_m;
72185 + spinlock_t *ptl_m;
72186 + struct vm_area_struct *vma_m;
72187 + pmd_t *pmd_m;
72188 + pte_t *pte_m, entry_m;
72189 +
72190 + BUG_ON(!page_m || PageAnon(page_m));
72191 +
72192 + vma_m = pax_find_mirror_vma(vma);
72193 + if (!vma_m)
72194 + return;
72195 +
72196 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72197 + address_m = address + SEGMEXEC_TASK_SIZE;
72198 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72199 + pte_m = pte_offset_map(pmd_m, address_m);
72200 + ptl_m = pte_lockptr(mm, pmd_m);
72201 + if (ptl != ptl_m) {
72202 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72203 + if (!pte_none(*pte_m))
72204 + goto out;
72205 + }
72206 +
72207 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
72208 + page_cache_get(page_m);
72209 + page_add_file_rmap(page_m);
72210 + inc_mm_counter_fast(mm, MM_FILEPAGES);
72211 + set_pte_at(mm, address_m, pte_m, entry_m);
72212 + update_mmu_cache(vma_m, address_m, entry_m);
72213 +out:
72214 + if (ptl != ptl_m)
72215 + spin_unlock(ptl_m);
72216 + pte_unmap(pte_m);
72217 +}
72218 +
72219 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
72220 +{
72221 + struct mm_struct *mm = vma->vm_mm;
72222 + unsigned long address_m;
72223 + spinlock_t *ptl_m;
72224 + struct vm_area_struct *vma_m;
72225 + pmd_t *pmd_m;
72226 + pte_t *pte_m, entry_m;
72227 +
72228 + vma_m = pax_find_mirror_vma(vma);
72229 + if (!vma_m)
72230 + return;
72231 +
72232 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
72233 + address_m = address + SEGMEXEC_TASK_SIZE;
72234 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
72235 + pte_m = pte_offset_map(pmd_m, address_m);
72236 + ptl_m = pte_lockptr(mm, pmd_m);
72237 + if (ptl != ptl_m) {
72238 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
72239 + if (!pte_none(*pte_m))
72240 + goto out;
72241 + }
72242 +
72243 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
72244 + set_pte_at(mm, address_m, pte_m, entry_m);
72245 +out:
72246 + if (ptl != ptl_m)
72247 + spin_unlock(ptl_m);
72248 + pte_unmap(pte_m);
72249 +}
72250 +
72251 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
72252 +{
72253 + struct page *page_m;
72254 + pte_t entry;
72255 +
72256 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
72257 + goto out;
72258 +
72259 + entry = *pte;
72260 + page_m = vm_normal_page(vma, address, entry);
72261 + if (!page_m)
72262 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
72263 + else if (PageAnon(page_m)) {
72264 + if (pax_find_mirror_vma(vma)) {
72265 + pte_unmap_unlock(pte, ptl);
72266 + lock_page(page_m);
72267 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
72268 + if (pte_same(entry, *pte))
72269 + pax_mirror_anon_pte(vma, address, page_m, ptl);
72270 + else
72271 + unlock_page(page_m);
72272 + }
72273 + } else
72274 + pax_mirror_file_pte(vma, address, page_m, ptl);
72275 +
72276 +out:
72277 + pte_unmap_unlock(pte, ptl);
72278 +}
72279 +#endif
72280 +
72281 /*
72282 * This routine handles present pages, when users try to write
72283 * to a shared page. It is done by copying the page to a new address
72284 @@ -2692,6 +2888,12 @@ gotten:
72285 */
72286 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72287 if (likely(pte_same(*page_table, orig_pte))) {
72288 +
72289 +#ifdef CONFIG_PAX_SEGMEXEC
72290 + if (pax_find_mirror_vma(vma))
72291 + BUG_ON(!trylock_page(new_page));
72292 +#endif
72293 +
72294 if (old_page) {
72295 if (!PageAnon(old_page)) {
72296 dec_mm_counter_fast(mm, MM_FILEPAGES);
72297 @@ -2743,6 +2945,10 @@ gotten:
72298 page_remove_rmap(old_page);
72299 }
72300
72301 +#ifdef CONFIG_PAX_SEGMEXEC
72302 + pax_mirror_anon_pte(vma, address, new_page, ptl);
72303 +#endif
72304 +
72305 /* Free the old page.. */
72306 new_page = old_page;
72307 ret |= VM_FAULT_WRITE;
72308 @@ -3022,6 +3228,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72309 swap_free(entry);
72310 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
72311 try_to_free_swap(page);
72312 +
72313 +#ifdef CONFIG_PAX_SEGMEXEC
72314 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
72315 +#endif
72316 +
72317 unlock_page(page);
72318 if (swapcache) {
72319 /*
72320 @@ -3045,6 +3256,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
72321
72322 /* No need to invalidate - it was non-present before */
72323 update_mmu_cache(vma, address, page_table);
72324 +
72325 +#ifdef CONFIG_PAX_SEGMEXEC
72326 + pax_mirror_anon_pte(vma, address, page, ptl);
72327 +#endif
72328 +
72329 unlock:
72330 pte_unmap_unlock(page_table, ptl);
72331 out:
72332 @@ -3064,40 +3280,6 @@ out_release:
72333 }
72334
72335 /*
72336 - * This is like a special single-page "expand_{down|up}wards()",
72337 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
72338 - * doesn't hit another vma.
72339 - */
72340 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
72341 -{
72342 - address &= PAGE_MASK;
72343 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
72344 - struct vm_area_struct *prev = vma->vm_prev;
72345 -
72346 - /*
72347 - * Is there a mapping abutting this one below?
72348 - *
72349 - * That's only ok if it's the same stack mapping
72350 - * that has gotten split..
72351 - */
72352 - if (prev && prev->vm_end == address)
72353 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
72354 -
72355 - expand_downwards(vma, address - PAGE_SIZE);
72356 - }
72357 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
72358 - struct vm_area_struct *next = vma->vm_next;
72359 -
72360 - /* As VM_GROWSDOWN but s/below/above/ */
72361 - if (next && next->vm_start == address + PAGE_SIZE)
72362 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
72363 -
72364 - expand_upwards(vma, address + PAGE_SIZE);
72365 - }
72366 - return 0;
72367 -}
72368 -
72369 -/*
72370 * We enter with non-exclusive mmap_sem (to exclude vma changes,
72371 * but allow concurrent faults), and pte mapped but not yet locked.
72372 * We return with mmap_sem still held, but pte unmapped and unlocked.
72373 @@ -3106,27 +3288,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72374 unsigned long address, pte_t *page_table, pmd_t *pmd,
72375 unsigned int flags)
72376 {
72377 - struct page *page;
72378 + struct page *page = NULL;
72379 spinlock_t *ptl;
72380 pte_t entry;
72381
72382 - pte_unmap(page_table);
72383 -
72384 - /* Check if we need to add a guard page to the stack */
72385 - if (check_stack_guard_page(vma, address) < 0)
72386 - return VM_FAULT_SIGBUS;
72387 -
72388 - /* Use the zero-page for reads */
72389 if (!(flags & FAULT_FLAG_WRITE)) {
72390 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
72391 vma->vm_page_prot));
72392 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
72393 + ptl = pte_lockptr(mm, pmd);
72394 + spin_lock(ptl);
72395 if (!pte_none(*page_table))
72396 goto unlock;
72397 goto setpte;
72398 }
72399
72400 /* Allocate our own private page. */
72401 + pte_unmap(page_table);
72402 +
72403 if (unlikely(anon_vma_prepare(vma)))
72404 goto oom;
72405 page = alloc_zeroed_user_highpage_movable(vma, address);
72406 @@ -3145,6 +3323,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
72407 if (!pte_none(*page_table))
72408 goto release;
72409
72410 +#ifdef CONFIG_PAX_SEGMEXEC
72411 + if (pax_find_mirror_vma(vma))
72412 + BUG_ON(!trylock_page(page));
72413 +#endif
72414 +
72415 inc_mm_counter_fast(mm, MM_ANONPAGES);
72416 page_add_new_anon_rmap(page, vma, address);
72417 setpte:
72418 @@ -3152,6 +3335,12 @@ setpte:
72419
72420 /* No need to invalidate - it was non-present before */
72421 update_mmu_cache(vma, address, page_table);
72422 +
72423 +#ifdef CONFIG_PAX_SEGMEXEC
72424 + if (page)
72425 + pax_mirror_anon_pte(vma, address, page, ptl);
72426 +#endif
72427 +
72428 unlock:
72429 pte_unmap_unlock(page_table, ptl);
72430 return 0;
72431 @@ -3295,6 +3484,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72432 */
72433 /* Only go through if we didn't race with anybody else... */
72434 if (likely(pte_same(*page_table, orig_pte))) {
72435 +
72436 +#ifdef CONFIG_PAX_SEGMEXEC
72437 + if (anon && pax_find_mirror_vma(vma))
72438 + BUG_ON(!trylock_page(page));
72439 +#endif
72440 +
72441 flush_icache_page(vma, page);
72442 entry = mk_pte(page, vma->vm_page_prot);
72443 if (flags & FAULT_FLAG_WRITE)
72444 @@ -3314,6 +3509,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72445
72446 /* no need to invalidate: a not-present page won't be cached */
72447 update_mmu_cache(vma, address, page_table);
72448 +
72449 +#ifdef CONFIG_PAX_SEGMEXEC
72450 + if (anon)
72451 + pax_mirror_anon_pte(vma, address, page, ptl);
72452 + else
72453 + pax_mirror_file_pte(vma, address, page, ptl);
72454 +#endif
72455 +
72456 } else {
72457 if (cow_page)
72458 mem_cgroup_uncharge_page(cow_page);
72459 @@ -3467,6 +3670,12 @@ int handle_pte_fault(struct mm_struct *mm,
72460 if (flags & FAULT_FLAG_WRITE)
72461 flush_tlb_fix_spurious_fault(vma, address);
72462 }
72463 +
72464 +#ifdef CONFIG_PAX_SEGMEXEC
72465 + pax_mirror_pte(vma, address, pte, pmd, ptl);
72466 + return 0;
72467 +#endif
72468 +
72469 unlock:
72470 pte_unmap_unlock(pte, ptl);
72471 return 0;
72472 @@ -3483,6 +3692,10 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72473 pmd_t *pmd;
72474 pte_t *pte;
72475
72476 +#ifdef CONFIG_PAX_SEGMEXEC
72477 + struct vm_area_struct *vma_m;
72478 +#endif
72479 +
72480 __set_current_state(TASK_RUNNING);
72481
72482 count_vm_event(PGFAULT);
72483 @@ -3494,6 +3707,34 @@ int handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
72484 if (unlikely(is_vm_hugetlb_page(vma)))
72485 return hugetlb_fault(mm, vma, address, flags);
72486
72487 +#ifdef CONFIG_PAX_SEGMEXEC
72488 + vma_m = pax_find_mirror_vma(vma);
72489 + if (vma_m) {
72490 + unsigned long address_m;
72491 + pgd_t *pgd_m;
72492 + pud_t *pud_m;
72493 + pmd_t *pmd_m;
72494 +
72495 + if (vma->vm_start > vma_m->vm_start) {
72496 + address_m = address;
72497 + address -= SEGMEXEC_TASK_SIZE;
72498 + vma = vma_m;
72499 + } else
72500 + address_m = address + SEGMEXEC_TASK_SIZE;
72501 +
72502 + pgd_m = pgd_offset(mm, address_m);
72503 + pud_m = pud_alloc(mm, pgd_m, address_m);
72504 + if (!pud_m)
72505 + return VM_FAULT_OOM;
72506 + pmd_m = pmd_alloc(mm, pud_m, address_m);
72507 + if (!pmd_m)
72508 + return VM_FAULT_OOM;
72509 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
72510 + return VM_FAULT_OOM;
72511 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
72512 + }
72513 +#endif
72514 +
72515 retry:
72516 pgd = pgd_offset(mm, address);
72517 pud = pud_alloc(mm, pgd, address);
72518 @@ -3535,7 +3776,7 @@ retry:
72519 * run pte_offset_map on the pmd, if an huge pmd could
72520 * materialize from under us from a different thread.
72521 */
72522 - if (unlikely(pmd_none(*pmd)) && __pte_alloc(mm, vma, pmd, address))
72523 + if (unlikely(pmd_none(*pmd) && __pte_alloc(mm, vma, pmd, address)))
72524 return VM_FAULT_OOM;
72525 /* if an huge pmd materialized from under us just retry later */
72526 if (unlikely(pmd_trans_huge(*pmd)))
72527 @@ -3572,6 +3813,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72528 spin_unlock(&mm->page_table_lock);
72529 return 0;
72530 }
72531 +
72532 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
72533 +{
72534 + pud_t *new = pud_alloc_one(mm, address);
72535 + if (!new)
72536 + return -ENOMEM;
72537 +
72538 + smp_wmb(); /* See comment in __pte_alloc */
72539 +
72540 + spin_lock(&mm->page_table_lock);
72541 + if (pgd_present(*pgd)) /* Another has populated it */
72542 + pud_free(mm, new);
72543 + else
72544 + pgd_populate_kernel(mm, pgd, new);
72545 + spin_unlock(&mm->page_table_lock);
72546 + return 0;
72547 +}
72548 #endif /* __PAGETABLE_PUD_FOLDED */
72549
72550 #ifndef __PAGETABLE_PMD_FOLDED
72551 @@ -3602,6 +3860,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
72552 spin_unlock(&mm->page_table_lock);
72553 return 0;
72554 }
72555 +
72556 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
72557 +{
72558 + pmd_t *new = pmd_alloc_one(mm, address);
72559 + if (!new)
72560 + return -ENOMEM;
72561 +
72562 + smp_wmb(); /* See comment in __pte_alloc */
72563 +
72564 + spin_lock(&mm->page_table_lock);
72565 +#ifndef __ARCH_HAS_4LEVEL_HACK
72566 + if (pud_present(*pud)) /* Another has populated it */
72567 + pmd_free(mm, new);
72568 + else
72569 + pud_populate_kernel(mm, pud, new);
72570 +#else
72571 + if (pgd_present(*pud)) /* Another has populated it */
72572 + pmd_free(mm, new);
72573 + else
72574 + pgd_populate_kernel(mm, pud, new);
72575 +#endif /* __ARCH_HAS_4LEVEL_HACK */
72576 + spin_unlock(&mm->page_table_lock);
72577 + return 0;
72578 +}
72579 #endif /* __PAGETABLE_PMD_FOLDED */
72580
72581 int make_pages_present(unsigned long addr, unsigned long end)
72582 @@ -3639,7 +3921,7 @@ static int __init gate_vma_init(void)
72583 gate_vma.vm_start = FIXADDR_USER_START;
72584 gate_vma.vm_end = FIXADDR_USER_END;
72585 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
72586 - gate_vma.vm_page_prot = __P101;
72587 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
72588
72589 return 0;
72590 }
72591 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
72592 index b12b28a..64b57d0 100644
72593 --- a/mm/mempolicy.c
72594 +++ b/mm/mempolicy.c
72595 @@ -619,6 +619,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72596 unsigned long vmstart;
72597 unsigned long vmend;
72598
72599 +#ifdef CONFIG_PAX_SEGMEXEC
72600 + struct vm_area_struct *vma_m;
72601 +#endif
72602 +
72603 vma = find_vma(mm, start);
72604 if (!vma || vma->vm_start > start)
72605 return -EFAULT;
72606 @@ -672,6 +676,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
72607 if (err)
72608 goto out;
72609 }
72610 +
72611 +#ifdef CONFIG_PAX_SEGMEXEC
72612 + vma_m = pax_find_mirror_vma(vma);
72613 + if (vma_m && vma_m->vm_ops && vma_m->vm_ops->set_policy) {
72614 + err = vma_m->vm_ops->set_policy(vma_m, new_pol);
72615 + if (err)
72616 + goto out;
72617 + }
72618 +#endif
72619 +
72620 }
72621
72622 out:
72623 @@ -1125,6 +1139,17 @@ static long do_mbind(unsigned long start, unsigned long len,
72624
72625 if (end < start)
72626 return -EINVAL;
72627 +
72628 +#ifdef CONFIG_PAX_SEGMEXEC
72629 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
72630 + if (end > SEGMEXEC_TASK_SIZE)
72631 + return -EINVAL;
72632 + } else
72633 +#endif
72634 +
72635 + if (end > TASK_SIZE)
72636 + return -EINVAL;
72637 +
72638 if (end == start)
72639 return 0;
72640
72641 @@ -1348,8 +1373,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72642 */
72643 tcred = __task_cred(task);
72644 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
72645 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
72646 - !capable(CAP_SYS_NICE)) {
72647 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
72648 rcu_read_unlock();
72649 err = -EPERM;
72650 goto out_put;
72651 @@ -1380,6 +1404,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
72652 goto out;
72653 }
72654
72655 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
72656 + if (mm != current->mm &&
72657 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
72658 + mmput(mm);
72659 + err = -EPERM;
72660 + goto out;
72661 + }
72662 +#endif
72663 +
72664 err = do_migrate_pages(mm, old, new,
72665 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
72666
72667 diff --git a/mm/mlock.c b/mm/mlock.c
72668 index ef726e8..cd7f1ec 100644
72669 --- a/mm/mlock.c
72670 +++ b/mm/mlock.c
72671 @@ -13,6 +13,7 @@
72672 #include <linux/pagemap.h>
72673 #include <linux/mempolicy.h>
72674 #include <linux/syscalls.h>
72675 +#include <linux/security.h>
72676 #include <linux/sched.h>
72677 #include <linux/export.h>
72678 #include <linux/rmap.h>
72679 @@ -376,7 +377,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
72680 {
72681 unsigned long nstart, end, tmp;
72682 struct vm_area_struct * vma, * prev;
72683 - int error;
72684 + int error = 0;
72685
72686 VM_BUG_ON(start & ~PAGE_MASK);
72687 VM_BUG_ON(len != PAGE_ALIGN(len));
72688 @@ -385,6 +386,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
72689 return -EINVAL;
72690 if (end == start)
72691 return 0;
72692 + if (end > TASK_SIZE)
72693 + return -EINVAL;
72694 +
72695 vma = find_vma(current->mm, start);
72696 if (!vma || vma->vm_start > start)
72697 return -ENOMEM;
72698 @@ -396,6 +400,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
72699 for (nstart = start ; ; ) {
72700 vm_flags_t newflags;
72701
72702 +#ifdef CONFIG_PAX_SEGMEXEC
72703 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72704 + break;
72705 +#endif
72706 +
72707 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
72708
72709 newflags = vma->vm_flags | VM_LOCKED;
72710 @@ -501,6 +510,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
72711 lock_limit >>= PAGE_SHIFT;
72712
72713 /* check against resource limits */
72714 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
72715 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
72716 error = do_mlock(start, len, 1);
72717 up_write(&current->mm->mmap_sem);
72718 @@ -524,17 +534,23 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len)
72719 static int do_mlockall(int flags)
72720 {
72721 struct vm_area_struct * vma, * prev = NULL;
72722 - unsigned int def_flags = 0;
72723
72724 if (flags & MCL_FUTURE)
72725 - def_flags = VM_LOCKED;
72726 - current->mm->def_flags = def_flags;
72727 + current->mm->def_flags |= VM_LOCKED;
72728 + else
72729 + current->mm->def_flags &= ~VM_LOCKED;
72730 if (flags == MCL_FUTURE)
72731 goto out;
72732
72733 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
72734 vm_flags_t newflags;
72735
72736 +#ifdef CONFIG_PAX_SEGMEXEC
72737 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
72738 + break;
72739 +#endif
72740 +
72741 + BUG_ON(vma->vm_end > TASK_SIZE);
72742 newflags = vma->vm_flags | VM_LOCKED;
72743 if (!(flags & MCL_CURRENT))
72744 newflags &= ~VM_LOCKED;
72745 @@ -567,6 +583,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
72746 lock_limit >>= PAGE_SHIFT;
72747
72748 ret = -ENOMEM;
72749 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
72750 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
72751 capable(CAP_IPC_LOCK))
72752 ret = do_mlockall(flags);
72753 diff --git a/mm/mmap.c b/mm/mmap.c
72754 index fa1f274..86de476 100644
72755 --- a/mm/mmap.c
72756 +++ b/mm/mmap.c
72757 @@ -47,6 +47,16 @@
72758 #define arch_rebalance_pgtables(addr, len) (addr)
72759 #endif
72760
72761 +static inline void verify_mm_writelocked(struct mm_struct *mm)
72762 +{
72763 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
72764 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
72765 + up_read(&mm->mmap_sem);
72766 + BUG();
72767 + }
72768 +#endif
72769 +}
72770 +
72771 static void unmap_region(struct mm_struct *mm,
72772 struct vm_area_struct *vma, struct vm_area_struct *prev,
72773 unsigned long start, unsigned long end);
72774 @@ -72,22 +82,32 @@ static void unmap_region(struct mm_struct *mm,
72775 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
72776 *
72777 */
72778 -pgprot_t protection_map[16] = {
72779 +pgprot_t protection_map[16] __read_only = {
72780 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
72781 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
72782 };
72783
72784 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
72785 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
72786 {
72787 - return __pgprot(pgprot_val(protection_map[vm_flags &
72788 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
72789 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
72790 pgprot_val(arch_vm_get_page_prot(vm_flags)));
72791 +
72792 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
72793 + if (!(__supported_pte_mask & _PAGE_NX) &&
72794 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
72795 + (vm_flags & (VM_READ | VM_WRITE)))
72796 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
72797 +#endif
72798 +
72799 + return prot;
72800 }
72801 EXPORT_SYMBOL(vm_get_page_prot);
72802
72803 int sysctl_overcommit_memory __read_mostly = OVERCOMMIT_GUESS; /* heuristic overcommit */
72804 int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
72805 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
72806 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
72807 /*
72808 * Make sure vm_committed_as in one cacheline and not cacheline shared with
72809 * other variables. It can be updated by several CPUs frequently.
72810 @@ -229,6 +249,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
72811 struct vm_area_struct *next = vma->vm_next;
72812
72813 might_sleep();
72814 + BUG_ON(vma->vm_mirror);
72815 if (vma->vm_ops && vma->vm_ops->close)
72816 vma->vm_ops->close(vma);
72817 if (vma->vm_file) {
72818 @@ -275,6 +296,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
72819 * not page aligned -Ram Gupta
72820 */
72821 rlim = rlimit(RLIMIT_DATA);
72822 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
72823 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
72824 (mm->end_data - mm->start_data) > rlim)
72825 goto out;
72826 @@ -708,6 +730,12 @@ static int
72827 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
72828 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72829 {
72830 +
72831 +#ifdef CONFIG_PAX_SEGMEXEC
72832 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
72833 + return 0;
72834 +#endif
72835 +
72836 if (is_mergeable_vma(vma, file, vm_flags) &&
72837 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72838 if (vma->vm_pgoff == vm_pgoff)
72839 @@ -727,6 +755,12 @@ static int
72840 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72841 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
72842 {
72843 +
72844 +#ifdef CONFIG_PAX_SEGMEXEC
72845 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
72846 + return 0;
72847 +#endif
72848 +
72849 if (is_mergeable_vma(vma, file, vm_flags) &&
72850 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
72851 pgoff_t vm_pglen;
72852 @@ -769,13 +803,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
72853 struct vm_area_struct *vma_merge(struct mm_struct *mm,
72854 struct vm_area_struct *prev, unsigned long addr,
72855 unsigned long end, unsigned long vm_flags,
72856 - struct anon_vma *anon_vma, struct file *file,
72857 + struct anon_vma *anon_vma, struct file *file,
72858 pgoff_t pgoff, struct mempolicy *policy)
72859 {
72860 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
72861 struct vm_area_struct *area, *next;
72862 int err;
72863
72864 +#ifdef CONFIG_PAX_SEGMEXEC
72865 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
72866 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
72867 +
72868 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
72869 +#endif
72870 +
72871 /*
72872 * We later require that vma->vm_flags == vm_flags,
72873 * so this tests vma->vm_flags & VM_SPECIAL, too.
72874 @@ -791,6 +832,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72875 if (next && next->vm_end == end) /* cases 6, 7, 8 */
72876 next = next->vm_next;
72877
72878 +#ifdef CONFIG_PAX_SEGMEXEC
72879 + if (prev)
72880 + prev_m = pax_find_mirror_vma(prev);
72881 + if (area)
72882 + area_m = pax_find_mirror_vma(area);
72883 + if (next)
72884 + next_m = pax_find_mirror_vma(next);
72885 +#endif
72886 +
72887 /*
72888 * Can it merge with the predecessor?
72889 */
72890 @@ -810,9 +860,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72891 /* cases 1, 6 */
72892 err = vma_adjust(prev, prev->vm_start,
72893 next->vm_end, prev->vm_pgoff, NULL);
72894 - } else /* cases 2, 5, 7 */
72895 +
72896 +#ifdef CONFIG_PAX_SEGMEXEC
72897 + if (!err && prev_m)
72898 + err = vma_adjust(prev_m, prev_m->vm_start,
72899 + next_m->vm_end, prev_m->vm_pgoff, NULL);
72900 +#endif
72901 +
72902 + } else { /* cases 2, 5, 7 */
72903 err = vma_adjust(prev, prev->vm_start,
72904 end, prev->vm_pgoff, NULL);
72905 +
72906 +#ifdef CONFIG_PAX_SEGMEXEC
72907 + if (!err && prev_m)
72908 + err = vma_adjust(prev_m, prev_m->vm_start,
72909 + end_m, prev_m->vm_pgoff, NULL);
72910 +#endif
72911 +
72912 + }
72913 if (err)
72914 return NULL;
72915 khugepaged_enter_vma_merge(prev);
72916 @@ -826,12 +891,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
72917 mpol_equal(policy, vma_policy(next)) &&
72918 can_vma_merge_before(next, vm_flags,
72919 anon_vma, file, pgoff+pglen)) {
72920 - if (prev && addr < prev->vm_end) /* case 4 */
72921 + if (prev && addr < prev->vm_end) { /* case 4 */
72922 err = vma_adjust(prev, prev->vm_start,
72923 addr, prev->vm_pgoff, NULL);
72924 - else /* cases 3, 8 */
72925 +
72926 +#ifdef CONFIG_PAX_SEGMEXEC
72927 + if (!err && prev_m)
72928 + err = vma_adjust(prev_m, prev_m->vm_start,
72929 + addr_m, prev_m->vm_pgoff, NULL);
72930 +#endif
72931 +
72932 + } else { /* cases 3, 8 */
72933 err = vma_adjust(area, addr, next->vm_end,
72934 next->vm_pgoff - pglen, NULL);
72935 +
72936 +#ifdef CONFIG_PAX_SEGMEXEC
72937 + if (!err && area_m)
72938 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
72939 + next_m->vm_pgoff - pglen, NULL);
72940 +#endif
72941 +
72942 + }
72943 if (err)
72944 return NULL;
72945 khugepaged_enter_vma_merge(area);
72946 @@ -940,14 +1020,11 @@ none:
72947 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
72948 struct file *file, long pages)
72949 {
72950 - const unsigned long stack_flags
72951 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
72952 -
72953 if (file) {
72954 mm->shared_vm += pages;
72955 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
72956 mm->exec_vm += pages;
72957 - } else if (flags & stack_flags)
72958 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
72959 mm->stack_vm += pages;
72960 if (flags & (VM_RESERVED|VM_IO))
72961 mm->reserved_vm += pages;
72962 @@ -985,7 +1062,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72963 * (the exception is when the underlying filesystem is noexec
72964 * mounted, in which case we dont add PROT_EXEC.)
72965 */
72966 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
72967 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
72968 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
72969 prot |= PROT_EXEC;
72970
72971 @@ -1011,7 +1088,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72972 /* Obtain the address to map to. we verify (or select) it and ensure
72973 * that it represents a valid section of the address space.
72974 */
72975 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
72976 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
72977 if (addr & ~PAGE_MASK)
72978 return addr;
72979
72980 @@ -1022,6 +1099,36 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
72981 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
72982 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
72983
72984 +#ifdef CONFIG_PAX_MPROTECT
72985 + if (mm->pax_flags & MF_PAX_MPROTECT) {
72986 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
72987 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
72988 + gr_log_rwxmmap(file);
72989 +
72990 +#ifdef CONFIG_PAX_EMUPLT
72991 + vm_flags &= ~VM_EXEC;
72992 +#else
72993 + return -EPERM;
72994 +#endif
72995 +
72996 + }
72997 +
72998 + if (!(vm_flags & VM_EXEC))
72999 + vm_flags &= ~VM_MAYEXEC;
73000 +#else
73001 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73002 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73003 +#endif
73004 + else
73005 + vm_flags &= ~VM_MAYWRITE;
73006 + }
73007 +#endif
73008 +
73009 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73010 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
73011 + vm_flags &= ~VM_PAGEEXEC;
73012 +#endif
73013 +
73014 if (flags & MAP_LOCKED)
73015 if (!can_do_mlock())
73016 return -EPERM;
73017 @@ -1033,6 +1140,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73018 locked += mm->locked_vm;
73019 lock_limit = rlimit(RLIMIT_MEMLOCK);
73020 lock_limit >>= PAGE_SHIFT;
73021 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73022 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
73023 return -EAGAIN;
73024 }
73025 @@ -1099,6 +1207,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
73026 }
73027 }
73028
73029 + if (!gr_acl_handle_mmap(file, prot))
73030 + return -EACCES;
73031 +
73032 return mmap_region(file, addr, len, flags, vm_flags, pgoff);
73033 }
73034
73035 @@ -1175,7 +1286,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
73036 vm_flags_t vm_flags = vma->vm_flags;
73037
73038 /* If it was private or non-writable, the write bit is already clear */
73039 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
73040 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
73041 return 0;
73042
73043 /* The backer wishes to know when pages are first written to? */
73044 @@ -1224,14 +1335,24 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
73045 unsigned long charged = 0;
73046 struct inode *inode = file ? file->f_path.dentry->d_inode : NULL;
73047
73048 +#ifdef CONFIG_PAX_SEGMEXEC
73049 + struct vm_area_struct *vma_m = NULL;
73050 +#endif
73051 +
73052 + /*
73053 + * mm->mmap_sem is required to protect against another thread
73054 + * changing the mappings in case we sleep.
73055 + */
73056 + verify_mm_writelocked(mm);
73057 +
73058 /* Clear old maps */
73059 error = -ENOMEM;
73060 -munmap_back:
73061 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73062 if (vma && vma->vm_start < addr + len) {
73063 if (do_munmap(mm, addr, len))
73064 return -ENOMEM;
73065 - goto munmap_back;
73066 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73067 + BUG_ON(vma && vma->vm_start < addr + len);
73068 }
73069
73070 /* Check against address space limit. */
73071 @@ -1280,6 +1401,16 @@ munmap_back:
73072 goto unacct_error;
73073 }
73074
73075 +#ifdef CONFIG_PAX_SEGMEXEC
73076 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
73077 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73078 + if (!vma_m) {
73079 + error = -ENOMEM;
73080 + goto free_vma;
73081 + }
73082 + }
73083 +#endif
73084 +
73085 vma->vm_mm = mm;
73086 vma->vm_start = addr;
73087 vma->vm_end = addr + len;
73088 @@ -1304,6 +1435,19 @@ munmap_back:
73089 error = file->f_op->mmap(file, vma);
73090 if (error)
73091 goto unmap_and_free_vma;
73092 +
73093 +#ifdef CONFIG_PAX_SEGMEXEC
73094 + if (vma_m && (vm_flags & VM_EXECUTABLE))
73095 + added_exe_file_vma(mm);
73096 +#endif
73097 +
73098 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
73099 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
73100 + vma->vm_flags |= VM_PAGEEXEC;
73101 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
73102 + }
73103 +#endif
73104 +
73105 if (vm_flags & VM_EXECUTABLE)
73106 added_exe_file_vma(mm);
73107
73108 @@ -1341,6 +1485,11 @@ munmap_back:
73109 vma_link(mm, vma, prev, rb_link, rb_parent);
73110 file = vma->vm_file;
73111
73112 +#ifdef CONFIG_PAX_SEGMEXEC
73113 + if (vma_m)
73114 + BUG_ON(pax_mirror_vma(vma_m, vma));
73115 +#endif
73116 +
73117 /* Once vma denies write, undo our temporary denial count */
73118 if (correct_wcount)
73119 atomic_inc(&inode->i_writecount);
73120 @@ -1349,6 +1498,7 @@ out:
73121
73122 mm->total_vm += len >> PAGE_SHIFT;
73123 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
73124 + track_exec_limit(mm, addr, addr + len, vm_flags);
73125 if (vm_flags & VM_LOCKED) {
73126 if (!mlock_vma_pages_range(vma, addr, addr + len))
73127 mm->locked_vm += (len >> PAGE_SHIFT);
73128 @@ -1370,6 +1520,12 @@ unmap_and_free_vma:
73129 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
73130 charged = 0;
73131 free_vma:
73132 +
73133 +#ifdef CONFIG_PAX_SEGMEXEC
73134 + if (vma_m)
73135 + kmem_cache_free(vm_area_cachep, vma_m);
73136 +#endif
73137 +
73138 kmem_cache_free(vm_area_cachep, vma);
73139 unacct_error:
73140 if (charged)
73141 @@ -1377,6 +1533,44 @@ unacct_error:
73142 return error;
73143 }
73144
73145 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len)
73146 +{
73147 + if (!vma) {
73148 +#ifdef CONFIG_STACK_GROWSUP
73149 + if (addr > sysctl_heap_stack_gap)
73150 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
73151 + else
73152 + vma = find_vma(current->mm, 0);
73153 + if (vma && (vma->vm_flags & VM_GROWSUP))
73154 + return false;
73155 +#endif
73156 + return true;
73157 + }
73158 +
73159 + if (addr + len > vma->vm_start)
73160 + return false;
73161 +
73162 + if (vma->vm_flags & VM_GROWSDOWN)
73163 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
73164 +#ifdef CONFIG_STACK_GROWSUP
73165 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
73166 + return addr - vma->vm_prev->vm_end <= sysctl_heap_stack_gap;
73167 +#endif
73168 +
73169 + return true;
73170 +}
73171 +
73172 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len)
73173 +{
73174 + if (vma->vm_start < len)
73175 + return -ENOMEM;
73176 + if (!(vma->vm_flags & VM_GROWSDOWN))
73177 + return vma->vm_start - len;
73178 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
73179 + return vma->vm_start - len - sysctl_heap_stack_gap;
73180 + return -ENOMEM;
73181 +}
73182 +
73183 /* Get an address range which is currently unmapped.
73184 * For shmat() with addr=0.
73185 *
73186 @@ -1403,18 +1597,23 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
73187 if (flags & MAP_FIXED)
73188 return addr;
73189
73190 +#ifdef CONFIG_PAX_RANDMMAP
73191 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73192 +#endif
73193 +
73194 if (addr) {
73195 addr = PAGE_ALIGN(addr);
73196 - vma = find_vma(mm, addr);
73197 - if (TASK_SIZE - len >= addr &&
73198 - (!vma || addr + len <= vma->vm_start))
73199 - return addr;
73200 + if (TASK_SIZE - len >= addr) {
73201 + vma = find_vma(mm, addr);
73202 + if (check_heap_stack_gap(vma, addr, len))
73203 + return addr;
73204 + }
73205 }
73206 if (len > mm->cached_hole_size) {
73207 - start_addr = addr = mm->free_area_cache;
73208 + start_addr = addr = mm->free_area_cache;
73209 } else {
73210 - start_addr = addr = TASK_UNMAPPED_BASE;
73211 - mm->cached_hole_size = 0;
73212 + start_addr = addr = mm->mmap_base;
73213 + mm->cached_hole_size = 0;
73214 }
73215
73216 full_search:
73217 @@ -1425,34 +1624,40 @@ full_search:
73218 * Start a new search - just in case we missed
73219 * some holes.
73220 */
73221 - if (start_addr != TASK_UNMAPPED_BASE) {
73222 - addr = TASK_UNMAPPED_BASE;
73223 - start_addr = addr;
73224 + if (start_addr != mm->mmap_base) {
73225 + start_addr = addr = mm->mmap_base;
73226 mm->cached_hole_size = 0;
73227 goto full_search;
73228 }
73229 return -ENOMEM;
73230 }
73231 - if (!vma || addr + len <= vma->vm_start) {
73232 - /*
73233 - * Remember the place where we stopped the search:
73234 - */
73235 - mm->free_area_cache = addr + len;
73236 - return addr;
73237 - }
73238 + if (check_heap_stack_gap(vma, addr, len))
73239 + break;
73240 if (addr + mm->cached_hole_size < vma->vm_start)
73241 mm->cached_hole_size = vma->vm_start - addr;
73242 addr = vma->vm_end;
73243 }
73244 +
73245 + /*
73246 + * Remember the place where we stopped the search:
73247 + */
73248 + mm->free_area_cache = addr + len;
73249 + return addr;
73250 }
73251 #endif
73252
73253 void arch_unmap_area(struct mm_struct *mm, unsigned long addr)
73254 {
73255 +
73256 +#ifdef CONFIG_PAX_SEGMEXEC
73257 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73258 + return;
73259 +#endif
73260 +
73261 /*
73262 * Is this a new hole at the lowest possible address?
73263 */
73264 - if (addr >= TASK_UNMAPPED_BASE && addr < mm->free_area_cache)
73265 + if (addr >= mm->mmap_base && addr < mm->free_area_cache)
73266 mm->free_area_cache = addr;
73267 }
73268
73269 @@ -1468,7 +1673,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73270 {
73271 struct vm_area_struct *vma;
73272 struct mm_struct *mm = current->mm;
73273 - unsigned long addr = addr0, start_addr;
73274 + unsigned long base = mm->mmap_base, addr = addr0, start_addr;
73275
73276 /* requested length too big for entire address space */
73277 if (len > TASK_SIZE)
73278 @@ -1477,13 +1682,18 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
73279 if (flags & MAP_FIXED)
73280 return addr;
73281
73282 +#ifdef CONFIG_PAX_RANDMMAP
73283 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
73284 +#endif
73285 +
73286 /* requesting a specific address */
73287 if (addr) {
73288 addr = PAGE_ALIGN(addr);
73289 - vma = find_vma(mm, addr);
73290 - if (TASK_SIZE - len >= addr &&
73291 - (!vma || addr + len <= vma->vm_start))
73292 - return addr;
73293 + if (TASK_SIZE - len >= addr) {
73294 + vma = find_vma(mm, addr);
73295 + if (check_heap_stack_gap(vma, addr, len))
73296 + return addr;
73297 + }
73298 }
73299
73300 /* check if free_area_cache is useful for us */
73301 @@ -1507,7 +1717,7 @@ try_again:
73302 * return with success:
73303 */
73304 vma = find_vma(mm, addr);
73305 - if (!vma || addr+len <= vma->vm_start)
73306 + if (check_heap_stack_gap(vma, addr, len))
73307 /* remember the address as a hint for next time */
73308 return (mm->free_area_cache = addr);
73309
73310 @@ -1516,8 +1726,8 @@ try_again:
73311 mm->cached_hole_size = vma->vm_start - addr;
73312
73313 /* try just below the current vma->vm_start */
73314 - addr = vma->vm_start-len;
73315 - } while (len < vma->vm_start);
73316 + addr = skip_heap_stack_gap(vma, len);
73317 + } while (!IS_ERR_VALUE(addr));
73318
73319 fail:
73320 /*
73321 @@ -1540,13 +1750,21 @@ fail:
73322 * can happen with large stack limits and large mmap()
73323 * allocations.
73324 */
73325 + mm->mmap_base = TASK_UNMAPPED_BASE;
73326 +
73327 +#ifdef CONFIG_PAX_RANDMMAP
73328 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73329 + mm->mmap_base += mm->delta_mmap;
73330 +#endif
73331 +
73332 + mm->free_area_cache = mm->mmap_base;
73333 mm->cached_hole_size = ~0UL;
73334 - mm->free_area_cache = TASK_UNMAPPED_BASE;
73335 addr = arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
73336 /*
73337 * Restore the topdown base:
73338 */
73339 - mm->free_area_cache = mm->mmap_base;
73340 + mm->mmap_base = base;
73341 + mm->free_area_cache = base;
73342 mm->cached_hole_size = ~0UL;
73343
73344 return addr;
73345 @@ -1555,6 +1773,12 @@ fail:
73346
73347 void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73348 {
73349 +
73350 +#ifdef CONFIG_PAX_SEGMEXEC
73351 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE <= addr)
73352 + return;
73353 +#endif
73354 +
73355 /*
73356 * Is this a new hole at the highest possible address?
73357 */
73358 @@ -1562,8 +1786,10 @@ void arch_unmap_area_topdown(struct mm_struct *mm, unsigned long addr)
73359 mm->free_area_cache = addr;
73360
73361 /* dont allow allocations above current base */
73362 - if (mm->free_area_cache > mm->mmap_base)
73363 + if (mm->free_area_cache > mm->mmap_base) {
73364 mm->free_area_cache = mm->mmap_base;
73365 + mm->cached_hole_size = ~0UL;
73366 + }
73367 }
73368
73369 unsigned long
73370 @@ -1662,6 +1888,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
73371 return vma;
73372 }
73373
73374 +#ifdef CONFIG_PAX_SEGMEXEC
73375 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
73376 +{
73377 + struct vm_area_struct *vma_m;
73378 +
73379 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
73380 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
73381 + BUG_ON(vma->vm_mirror);
73382 + return NULL;
73383 + }
73384 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
73385 + vma_m = vma->vm_mirror;
73386 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
73387 + BUG_ON(vma->vm_file != vma_m->vm_file);
73388 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
73389 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
73390 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
73391 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED | VM_RESERVED));
73392 + return vma_m;
73393 +}
73394 +#endif
73395 +
73396 /*
73397 * Verify that the stack growth is acceptable and
73398 * update accounting. This is shared with both the
73399 @@ -1678,6 +1926,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73400 return -ENOMEM;
73401
73402 /* Stack limit test */
73403 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
73404 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
73405 return -ENOMEM;
73406
73407 @@ -1688,6 +1937,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73408 locked = mm->locked_vm + grow;
73409 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
73410 limit >>= PAGE_SHIFT;
73411 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
73412 if (locked > limit && !capable(CAP_IPC_LOCK))
73413 return -ENOMEM;
73414 }
73415 @@ -1718,37 +1968,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
73416 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
73417 * vma is the last one with address > vma->vm_end. Have to extend vma.
73418 */
73419 +#ifndef CONFIG_IA64
73420 +static
73421 +#endif
73422 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73423 {
73424 int error;
73425 + bool locknext;
73426
73427 if (!(vma->vm_flags & VM_GROWSUP))
73428 return -EFAULT;
73429
73430 + /* Also guard against wrapping around to address 0. */
73431 + if (address < PAGE_ALIGN(address+1))
73432 + address = PAGE_ALIGN(address+1);
73433 + else
73434 + return -ENOMEM;
73435 +
73436 /*
73437 * We must make sure the anon_vma is allocated
73438 * so that the anon_vma locking is not a noop.
73439 */
73440 if (unlikely(anon_vma_prepare(vma)))
73441 return -ENOMEM;
73442 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
73443 + if (locknext && anon_vma_prepare(vma->vm_next))
73444 + return -ENOMEM;
73445 vma_lock_anon_vma(vma);
73446 + if (locknext)
73447 + vma_lock_anon_vma(vma->vm_next);
73448
73449 /*
73450 * vma->vm_start/vm_end cannot change under us because the caller
73451 * is required to hold the mmap_sem in read mode. We need the
73452 - * anon_vma lock to serialize against concurrent expand_stacks.
73453 - * Also guard against wrapping around to address 0.
73454 + * anon_vma locks to serialize against concurrent expand_stacks
73455 + * and expand_upwards.
73456 */
73457 - if (address < PAGE_ALIGN(address+4))
73458 - address = PAGE_ALIGN(address+4);
73459 - else {
73460 - vma_unlock_anon_vma(vma);
73461 - return -ENOMEM;
73462 - }
73463 error = 0;
73464
73465 /* Somebody else might have raced and expanded it already */
73466 - if (address > vma->vm_end) {
73467 + 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)
73468 + error = -ENOMEM;
73469 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
73470 unsigned long size, grow;
73471
73472 size = address - vma->vm_start;
73473 @@ -1763,6 +2024,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
73474 }
73475 }
73476 }
73477 + if (locknext)
73478 + vma_unlock_anon_vma(vma->vm_next);
73479 vma_unlock_anon_vma(vma);
73480 khugepaged_enter_vma_merge(vma);
73481 return error;
73482 @@ -1776,6 +2039,8 @@ int expand_downwards(struct vm_area_struct *vma,
73483 unsigned long address)
73484 {
73485 int error;
73486 + bool lockprev = false;
73487 + struct vm_area_struct *prev;
73488
73489 /*
73490 * We must make sure the anon_vma is allocated
73491 @@ -1789,6 +2054,15 @@ int expand_downwards(struct vm_area_struct *vma,
73492 if (error)
73493 return error;
73494
73495 + prev = vma->vm_prev;
73496 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
73497 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
73498 +#endif
73499 + if (lockprev && anon_vma_prepare(prev))
73500 + return -ENOMEM;
73501 + if (lockprev)
73502 + vma_lock_anon_vma(prev);
73503 +
73504 vma_lock_anon_vma(vma);
73505
73506 /*
73507 @@ -1798,9 +2072,17 @@ int expand_downwards(struct vm_area_struct *vma,
73508 */
73509
73510 /* Somebody else might have raced and expanded it already */
73511 - if (address < vma->vm_start) {
73512 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
73513 + error = -ENOMEM;
73514 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
73515 unsigned long size, grow;
73516
73517 +#ifdef CONFIG_PAX_SEGMEXEC
73518 + struct vm_area_struct *vma_m;
73519 +
73520 + vma_m = pax_find_mirror_vma(vma);
73521 +#endif
73522 +
73523 size = vma->vm_end - address;
73524 grow = (vma->vm_start - address) >> PAGE_SHIFT;
73525
73526 @@ -1810,11 +2092,22 @@ int expand_downwards(struct vm_area_struct *vma,
73527 if (!error) {
73528 vma->vm_start = address;
73529 vma->vm_pgoff -= grow;
73530 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
73531 +
73532 +#ifdef CONFIG_PAX_SEGMEXEC
73533 + if (vma_m) {
73534 + vma_m->vm_start -= grow << PAGE_SHIFT;
73535 + vma_m->vm_pgoff -= grow;
73536 + }
73537 +#endif
73538 +
73539 perf_event_mmap(vma);
73540 }
73541 }
73542 }
73543 vma_unlock_anon_vma(vma);
73544 + if (lockprev)
73545 + vma_unlock_anon_vma(prev);
73546 khugepaged_enter_vma_merge(vma);
73547 return error;
73548 }
73549 @@ -1886,6 +2179,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
73550 do {
73551 long nrpages = vma_pages(vma);
73552
73553 +#ifdef CONFIG_PAX_SEGMEXEC
73554 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
73555 + vma = remove_vma(vma);
73556 + continue;
73557 + }
73558 +#endif
73559 +
73560 if (vma->vm_flags & VM_ACCOUNT)
73561 nr_accounted += nrpages;
73562 mm->total_vm -= nrpages;
73563 @@ -1932,6 +2232,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
73564 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
73565 vma->vm_prev = NULL;
73566 do {
73567 +
73568 +#ifdef CONFIG_PAX_SEGMEXEC
73569 + if (vma->vm_mirror) {
73570 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
73571 + vma->vm_mirror->vm_mirror = NULL;
73572 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
73573 + vma->vm_mirror = NULL;
73574 + }
73575 +#endif
73576 +
73577 rb_erase(&vma->vm_rb, &mm->mm_rb);
73578 mm->map_count--;
73579 tail_vma = vma;
73580 @@ -1960,14 +2270,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73581 struct vm_area_struct *new;
73582 int err = -ENOMEM;
73583
73584 +#ifdef CONFIG_PAX_SEGMEXEC
73585 + struct vm_area_struct *vma_m, *new_m = NULL;
73586 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
73587 +#endif
73588 +
73589 if (is_vm_hugetlb_page(vma) && (addr &
73590 ~(huge_page_mask(hstate_vma(vma)))))
73591 return -EINVAL;
73592
73593 +#ifdef CONFIG_PAX_SEGMEXEC
73594 + vma_m = pax_find_mirror_vma(vma);
73595 +#endif
73596 +
73597 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73598 if (!new)
73599 goto out_err;
73600
73601 +#ifdef CONFIG_PAX_SEGMEXEC
73602 + if (vma_m) {
73603 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
73604 + if (!new_m) {
73605 + kmem_cache_free(vm_area_cachep, new);
73606 + goto out_err;
73607 + }
73608 + }
73609 +#endif
73610 +
73611 /* most fields are the same, copy all, and then fixup */
73612 *new = *vma;
73613
73614 @@ -1980,6 +2309,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73615 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
73616 }
73617
73618 +#ifdef CONFIG_PAX_SEGMEXEC
73619 + if (vma_m) {
73620 + *new_m = *vma_m;
73621 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
73622 + new_m->vm_mirror = new;
73623 + new->vm_mirror = new_m;
73624 +
73625 + if (new_below)
73626 + new_m->vm_end = addr_m;
73627 + else {
73628 + new_m->vm_start = addr_m;
73629 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
73630 + }
73631 + }
73632 +#endif
73633 +
73634 pol = mpol_dup(vma_policy(vma));
73635 if (IS_ERR(pol)) {
73636 err = PTR_ERR(pol);
73637 @@ -2005,6 +2350,42 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73638 else
73639 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
73640
73641 +#ifdef CONFIG_PAX_SEGMEXEC
73642 + if (!err && vma_m) {
73643 + if (anon_vma_clone(new_m, vma_m))
73644 + goto out_free_mpol;
73645 +
73646 + mpol_get(pol);
73647 + vma_set_policy(new_m, pol);
73648 +
73649 + if (new_m->vm_file) {
73650 + get_file(new_m->vm_file);
73651 + if (vma_m->vm_flags & VM_EXECUTABLE)
73652 + added_exe_file_vma(mm);
73653 + }
73654 +
73655 + if (new_m->vm_ops && new_m->vm_ops->open)
73656 + new_m->vm_ops->open(new_m);
73657 +
73658 + if (new_below)
73659 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
73660 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
73661 + else
73662 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
73663 +
73664 + if (err) {
73665 + if (new_m->vm_ops && new_m->vm_ops->close)
73666 + new_m->vm_ops->close(new_m);
73667 + if (new_m->vm_file) {
73668 + if (vma_m->vm_flags & VM_EXECUTABLE)
73669 + removed_exe_file_vma(mm);
73670 + fput(new_m->vm_file);
73671 + }
73672 + mpol_put(pol);
73673 + }
73674 + }
73675 +#endif
73676 +
73677 /* Success. */
73678 if (!err)
73679 return 0;
73680 @@ -2017,10 +2398,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73681 removed_exe_file_vma(mm);
73682 fput(new->vm_file);
73683 }
73684 - unlink_anon_vmas(new);
73685 out_free_mpol:
73686 mpol_put(pol);
73687 out_free_vma:
73688 +
73689 +#ifdef CONFIG_PAX_SEGMEXEC
73690 + if (new_m) {
73691 + unlink_anon_vmas(new_m);
73692 + kmem_cache_free(vm_area_cachep, new_m);
73693 + }
73694 +#endif
73695 +
73696 + unlink_anon_vmas(new);
73697 kmem_cache_free(vm_area_cachep, new);
73698 out_err:
73699 return err;
73700 @@ -2033,6 +2422,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
73701 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73702 unsigned long addr, int new_below)
73703 {
73704 +
73705 +#ifdef CONFIG_PAX_SEGMEXEC
73706 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
73707 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
73708 + if (mm->map_count >= sysctl_max_map_count-1)
73709 + return -ENOMEM;
73710 + } else
73711 +#endif
73712 +
73713 if (mm->map_count >= sysctl_max_map_count)
73714 return -ENOMEM;
73715
73716 @@ -2044,11 +2442,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
73717 * work. This now handles partial unmappings.
73718 * Jeremy Fitzhardinge <jeremy@goop.org>
73719 */
73720 +#ifdef CONFIG_PAX_SEGMEXEC
73721 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73722 {
73723 + int ret = __do_munmap(mm, start, len);
73724 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
73725 + return ret;
73726 +
73727 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
73728 +}
73729 +
73730 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73731 +#else
73732 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73733 +#endif
73734 +{
73735 unsigned long end;
73736 struct vm_area_struct *vma, *prev, *last;
73737
73738 + /*
73739 + * mm->mmap_sem is required to protect against another thread
73740 + * changing the mappings in case we sleep.
73741 + */
73742 + verify_mm_writelocked(mm);
73743 +
73744 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
73745 return -EINVAL;
73746
73747 @@ -2123,6 +2540,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
73748 /* Fix up all other VM information */
73749 remove_vma_list(mm, vma);
73750
73751 + track_exec_limit(mm, start, end, 0UL);
73752 +
73753 return 0;
73754 }
73755
73756 @@ -2131,6 +2550,13 @@ int vm_munmap(unsigned long start, size_t len)
73757 int ret;
73758 struct mm_struct *mm = current->mm;
73759
73760 +
73761 +#ifdef CONFIG_PAX_SEGMEXEC
73762 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
73763 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
73764 + return -EINVAL;
73765 +#endif
73766 +
73767 down_write(&mm->mmap_sem);
73768 ret = do_munmap(mm, start, len);
73769 up_write(&mm->mmap_sem);
73770 @@ -2144,16 +2570,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
73771 return vm_munmap(addr, len);
73772 }
73773
73774 -static inline void verify_mm_writelocked(struct mm_struct *mm)
73775 -{
73776 -#ifdef CONFIG_DEBUG_VM
73777 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
73778 - WARN_ON(1);
73779 - up_read(&mm->mmap_sem);
73780 - }
73781 -#endif
73782 -}
73783 -
73784 /*
73785 * this is really a simplified "do_mmap". it only handles
73786 * anonymous maps. eventually we may be able to do some
73787 @@ -2167,6 +2583,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73788 struct rb_node ** rb_link, * rb_parent;
73789 pgoff_t pgoff = addr >> PAGE_SHIFT;
73790 int error;
73791 + unsigned long charged;
73792
73793 len = PAGE_ALIGN(len);
73794 if (!len)
73795 @@ -2174,16 +2591,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73796
73797 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
73798
73799 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
73800 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
73801 + flags &= ~VM_EXEC;
73802 +
73803 +#ifdef CONFIG_PAX_MPROTECT
73804 + if (mm->pax_flags & MF_PAX_MPROTECT)
73805 + flags &= ~VM_MAYEXEC;
73806 +#endif
73807 +
73808 + }
73809 +#endif
73810 +
73811 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
73812 if (error & ~PAGE_MASK)
73813 return error;
73814
73815 + charged = len >> PAGE_SHIFT;
73816 +
73817 /*
73818 * mlock MCL_FUTURE?
73819 */
73820 if (mm->def_flags & VM_LOCKED) {
73821 unsigned long locked, lock_limit;
73822 - locked = len >> PAGE_SHIFT;
73823 + locked = charged;
73824 locked += mm->locked_vm;
73825 lock_limit = rlimit(RLIMIT_MEMLOCK);
73826 lock_limit >>= PAGE_SHIFT;
73827 @@ -2200,22 +2631,22 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73828 /*
73829 * Clear old maps. this also does some error checking for us
73830 */
73831 - munmap_back:
73832 vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73833 if (vma && vma->vm_start < addr + len) {
73834 if (do_munmap(mm, addr, len))
73835 return -ENOMEM;
73836 - goto munmap_back;
73837 - }
73838 + vma = find_vma_prepare(mm, addr, &prev, &rb_link, &rb_parent);
73839 + BUG_ON(vma && vma->vm_start < addr + len);
73840 + }
73841
73842 /* Check against address space limits *after* clearing old maps... */
73843 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
73844 + if (!may_expand_vm(mm, charged))
73845 return -ENOMEM;
73846
73847 if (mm->map_count > sysctl_max_map_count)
73848 return -ENOMEM;
73849
73850 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
73851 + if (security_vm_enough_memory_mm(mm, charged))
73852 return -ENOMEM;
73853
73854 /* Can we just expand an old private anonymous mapping? */
73855 @@ -2229,7 +2660,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73856 */
73857 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73858 if (!vma) {
73859 - vm_unacct_memory(len >> PAGE_SHIFT);
73860 + vm_unacct_memory(charged);
73861 return -ENOMEM;
73862 }
73863
73864 @@ -2243,11 +2674,12 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
73865 vma_link(mm, vma, prev, rb_link, rb_parent);
73866 out:
73867 perf_event_mmap(vma);
73868 - mm->total_vm += len >> PAGE_SHIFT;
73869 + mm->total_vm += charged;
73870 if (flags & VM_LOCKED) {
73871 if (!mlock_vma_pages_range(vma, addr, addr + len))
73872 - mm->locked_vm += (len >> PAGE_SHIFT);
73873 + mm->locked_vm += charged;
73874 }
73875 + track_exec_limit(mm, addr, addr + len, flags);
73876 return addr;
73877 }
73878
73879 @@ -2305,6 +2737,7 @@ void exit_mmap(struct mm_struct *mm)
73880 while (vma) {
73881 if (vma->vm_flags & VM_ACCOUNT)
73882 nr_accounted += vma_pages(vma);
73883 + vma->vm_mirror = NULL;
73884 vma = remove_vma(vma);
73885 }
73886 vm_unacct_memory(nr_accounted);
73887 @@ -2321,6 +2754,13 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73888 struct vm_area_struct * __vma, * prev;
73889 struct rb_node ** rb_link, * rb_parent;
73890
73891 +#ifdef CONFIG_PAX_SEGMEXEC
73892 + struct vm_area_struct *vma_m = NULL;
73893 +#endif
73894 +
73895 + if (security_mmap_addr(vma->vm_start))
73896 + return -EPERM;
73897 +
73898 /*
73899 * The vm_pgoff of a purely anonymous vma should be irrelevant
73900 * until its first write fault, when page's anon_vma and index
73901 @@ -2347,7 +2787,21 @@ int insert_vm_struct(struct mm_struct * mm, struct vm_area_struct * vma)
73902 if (vma->vm_file && uprobe_mmap(vma))
73903 return -EINVAL;
73904
73905 +#ifdef CONFIG_PAX_SEGMEXEC
73906 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
73907 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
73908 + if (!vma_m)
73909 + return -ENOMEM;
73910 + }
73911 +#endif
73912 +
73913 vma_link(mm, vma, prev, rb_link, rb_parent);
73914 +
73915 +#ifdef CONFIG_PAX_SEGMEXEC
73916 + if (vma_m)
73917 + BUG_ON(pax_mirror_vma(vma_m, vma));
73918 +#endif
73919 +
73920 return 0;
73921 }
73922
73923 @@ -2366,6 +2820,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73924 struct mempolicy *pol;
73925 bool faulted_in_anon_vma = true;
73926
73927 + BUG_ON(vma->vm_mirror);
73928 +
73929 /*
73930 * If anonymous vma has not yet been faulted, update new pgoff
73931 * to match new location, to increase its chance of merging.
73932 @@ -2437,6 +2893,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
73933 return NULL;
73934 }
73935
73936 +#ifdef CONFIG_PAX_SEGMEXEC
73937 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
73938 +{
73939 + struct vm_area_struct *prev_m;
73940 + struct rb_node **rb_link_m, *rb_parent_m;
73941 + struct mempolicy *pol_m;
73942 +
73943 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
73944 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
73945 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
73946 + *vma_m = *vma;
73947 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
73948 + if (anon_vma_clone(vma_m, vma))
73949 + return -ENOMEM;
73950 + pol_m = vma_policy(vma_m);
73951 + mpol_get(pol_m);
73952 + vma_set_policy(vma_m, pol_m);
73953 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
73954 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
73955 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
73956 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
73957 + if (vma_m->vm_file)
73958 + get_file(vma_m->vm_file);
73959 + if (vma_m->vm_ops && vma_m->vm_ops->open)
73960 + vma_m->vm_ops->open(vma_m);
73961 + find_vma_prepare(vma->vm_mm, vma_m->vm_start, &prev_m, &rb_link_m, &rb_parent_m);
73962 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
73963 + vma_m->vm_mirror = vma;
73964 + vma->vm_mirror = vma_m;
73965 + return 0;
73966 +}
73967 +#endif
73968 +
73969 /*
73970 * Return true if the calling process may expand its vm space by the passed
73971 * number of pages
73972 @@ -2448,6 +2937,12 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
73973
73974 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
73975
73976 +#ifdef CONFIG_PAX_RANDMMAP
73977 + if (mm->pax_flags & MF_PAX_RANDMMAP)
73978 + cur -= mm->brk_gap;
73979 +#endif
73980 +
73981 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
73982 if (cur + npages > lim)
73983 return 0;
73984 return 1;
73985 @@ -2518,6 +3013,22 @@ int install_special_mapping(struct mm_struct *mm,
73986 vma->vm_start = addr;
73987 vma->vm_end = addr + len;
73988
73989 +#ifdef CONFIG_PAX_MPROTECT
73990 + if (mm->pax_flags & MF_PAX_MPROTECT) {
73991 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
73992 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
73993 + return -EPERM;
73994 + if (!(vm_flags & VM_EXEC))
73995 + vm_flags &= ~VM_MAYEXEC;
73996 +#else
73997 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
73998 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
73999 +#endif
74000 + else
74001 + vm_flags &= ~VM_MAYWRITE;
74002 + }
74003 +#endif
74004 +
74005 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND;
74006 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
74007
74008 diff --git a/mm/mprotect.c b/mm/mprotect.c
74009 index a409926..8b32e6d 100644
74010 --- a/mm/mprotect.c
74011 +++ b/mm/mprotect.c
74012 @@ -23,10 +23,17 @@
74013 #include <linux/mmu_notifier.h>
74014 #include <linux/migrate.h>
74015 #include <linux/perf_event.h>
74016 +
74017 +#ifdef CONFIG_PAX_MPROTECT
74018 +#include <linux/elf.h>
74019 +#include <linux/binfmts.h>
74020 +#endif
74021 +
74022 #include <asm/uaccess.h>
74023 #include <asm/pgtable.h>
74024 #include <asm/cacheflush.h>
74025 #include <asm/tlbflush.h>
74026 +#include <asm/mmu_context.h>
74027
74028 #ifndef pgprot_modify
74029 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
74030 @@ -141,6 +148,48 @@ static void change_protection(struct vm_area_struct *vma,
74031 flush_tlb_range(vma, start, end);
74032 }
74033
74034 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74035 +/* called while holding the mmap semaphor for writing except stack expansion */
74036 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
74037 +{
74038 + unsigned long oldlimit, newlimit = 0UL;
74039 +
74040 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
74041 + return;
74042 +
74043 + spin_lock(&mm->page_table_lock);
74044 + oldlimit = mm->context.user_cs_limit;
74045 + if ((prot & VM_EXEC) && oldlimit < end)
74046 + /* USER_CS limit moved up */
74047 + newlimit = end;
74048 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
74049 + /* USER_CS limit moved down */
74050 + newlimit = start;
74051 +
74052 + if (newlimit) {
74053 + mm->context.user_cs_limit = newlimit;
74054 +
74055 +#ifdef CONFIG_SMP
74056 + wmb();
74057 + cpus_clear(mm->context.cpu_user_cs_mask);
74058 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
74059 +#endif
74060 +
74061 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
74062 + }
74063 + spin_unlock(&mm->page_table_lock);
74064 + if (newlimit == end) {
74065 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
74066 +
74067 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
74068 + if (is_vm_hugetlb_page(vma))
74069 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
74070 + else
74071 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma));
74072 + }
74073 +}
74074 +#endif
74075 +
74076 int
74077 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74078 unsigned long start, unsigned long end, unsigned long newflags)
74079 @@ -153,11 +202,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74080 int error;
74081 int dirty_accountable = 0;
74082
74083 +#ifdef CONFIG_PAX_SEGMEXEC
74084 + struct vm_area_struct *vma_m = NULL;
74085 + unsigned long start_m, end_m;
74086 +
74087 + start_m = start + SEGMEXEC_TASK_SIZE;
74088 + end_m = end + SEGMEXEC_TASK_SIZE;
74089 +#endif
74090 +
74091 if (newflags == oldflags) {
74092 *pprev = vma;
74093 return 0;
74094 }
74095
74096 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
74097 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
74098 +
74099 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
74100 + return -ENOMEM;
74101 +
74102 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
74103 + return -ENOMEM;
74104 + }
74105 +
74106 /*
74107 * If we make a private mapping writable we increase our commit;
74108 * but (without finer accounting) cannot reduce our commit if we
74109 @@ -174,6 +241,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
74110 }
74111 }
74112
74113 +#ifdef CONFIG_PAX_SEGMEXEC
74114 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
74115 + if (start != vma->vm_start) {
74116 + error = split_vma(mm, vma, start, 1);
74117 + if (error)
74118 + goto fail;
74119 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
74120 + *pprev = (*pprev)->vm_next;
74121 + }
74122 +
74123 + if (end != vma->vm_end) {
74124 + error = split_vma(mm, vma, end, 0);
74125 + if (error)
74126 + goto fail;
74127 + }
74128 +
74129 + if (pax_find_mirror_vma(vma)) {
74130 + error = __do_munmap(mm, start_m, end_m - start_m);
74131 + if (error)
74132 + goto fail;
74133 + } else {
74134 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
74135 + if (!vma_m) {
74136 + error = -ENOMEM;
74137 + goto fail;
74138 + }
74139 + vma->vm_flags = newflags;
74140 + error = pax_mirror_vma(vma_m, vma);
74141 + if (error) {
74142 + vma->vm_flags = oldflags;
74143 + goto fail;
74144 + }
74145 + }
74146 + }
74147 +#endif
74148 +
74149 /*
74150 * First try to merge with previous and/or next vma.
74151 */
74152 @@ -204,9 +307,21 @@ success:
74153 * vm_flags and vm_page_prot are protected by the mmap_sem
74154 * held in write mode.
74155 */
74156 +
74157 +#ifdef CONFIG_PAX_SEGMEXEC
74158 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
74159 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
74160 +#endif
74161 +
74162 vma->vm_flags = newflags;
74163 +
74164 +#ifdef CONFIG_PAX_MPROTECT
74165 + if (mm->binfmt && mm->binfmt->handle_mprotect)
74166 + mm->binfmt->handle_mprotect(vma, newflags);
74167 +#endif
74168 +
74169 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
74170 - vm_get_page_prot(newflags));
74171 + vm_get_page_prot(vma->vm_flags));
74172
74173 if (vma_wants_writenotify(vma)) {
74174 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
74175 @@ -248,6 +363,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74176 end = start + len;
74177 if (end <= start)
74178 return -ENOMEM;
74179 +
74180 +#ifdef CONFIG_PAX_SEGMEXEC
74181 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
74182 + if (end > SEGMEXEC_TASK_SIZE)
74183 + return -EINVAL;
74184 + } else
74185 +#endif
74186 +
74187 + if (end > TASK_SIZE)
74188 + return -EINVAL;
74189 +
74190 if (!arch_validate_prot(prot))
74191 return -EINVAL;
74192
74193 @@ -255,7 +381,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74194 /*
74195 * Does the application expect PROT_READ to imply PROT_EXEC:
74196 */
74197 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
74198 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
74199 prot |= PROT_EXEC;
74200
74201 vm_flags = calc_vm_prot_bits(prot);
74202 @@ -288,6 +414,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74203 if (start > vma->vm_start)
74204 prev = vma;
74205
74206 +#ifdef CONFIG_PAX_MPROTECT
74207 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
74208 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
74209 +#endif
74210 +
74211 for (nstart = start ; ; ) {
74212 unsigned long newflags;
74213
74214 @@ -297,6 +428,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74215
74216 /* newflags >> 4 shift VM_MAY% in place of VM_% */
74217 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
74218 + if (prot & (PROT_WRITE | PROT_EXEC))
74219 + gr_log_rwxmprotect(vma->vm_file);
74220 +
74221 + error = -EACCES;
74222 + goto out;
74223 + }
74224 +
74225 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
74226 error = -EACCES;
74227 goto out;
74228 }
74229 @@ -311,6 +450,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
74230 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
74231 if (error)
74232 goto out;
74233 +
74234 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
74235 +
74236 nstart = tmp;
74237
74238 if (nstart < prev->vm_end)
74239 diff --git a/mm/mremap.c b/mm/mremap.c
74240 index 21fed20..6822658 100644
74241 --- a/mm/mremap.c
74242 +++ b/mm/mremap.c
74243 @@ -106,6 +106,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
74244 continue;
74245 pte = ptep_get_and_clear(mm, old_addr, old_pte);
74246 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
74247 +
74248 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
74249 + if (!(__supported_pte_mask & _PAGE_NX) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
74250 + pte = pte_exprotect(pte);
74251 +#endif
74252 +
74253 set_pte_at(mm, new_addr, new_pte, pte);
74254 }
74255
74256 @@ -299,6 +305,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
74257 if (is_vm_hugetlb_page(vma))
74258 goto Einval;
74259
74260 +#ifdef CONFIG_PAX_SEGMEXEC
74261 + if (pax_find_mirror_vma(vma))
74262 + goto Einval;
74263 +#endif
74264 +
74265 /* We can't remap across vm area boundaries */
74266 if (old_len > vma->vm_end - addr)
74267 goto Efault;
74268 @@ -355,20 +366,25 @@ static unsigned long mremap_to(unsigned long addr,
74269 unsigned long ret = -EINVAL;
74270 unsigned long charged = 0;
74271 unsigned long map_flags;
74272 + unsigned long pax_task_size = TASK_SIZE;
74273
74274 if (new_addr & ~PAGE_MASK)
74275 goto out;
74276
74277 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
74278 +#ifdef CONFIG_PAX_SEGMEXEC
74279 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74280 + pax_task_size = SEGMEXEC_TASK_SIZE;
74281 +#endif
74282 +
74283 + pax_task_size -= PAGE_SIZE;
74284 +
74285 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
74286 goto out;
74287
74288 /* Check if the location we're moving into overlaps the
74289 * old location at all, and fail if it does.
74290 */
74291 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
74292 - goto out;
74293 -
74294 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
74295 + if (addr + old_len > new_addr && new_addr + new_len > addr)
74296 goto out;
74297
74298 ret = do_munmap(mm, new_addr, new_len);
74299 @@ -436,6 +452,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74300 struct vm_area_struct *vma;
74301 unsigned long ret = -EINVAL;
74302 unsigned long charged = 0;
74303 + unsigned long pax_task_size = TASK_SIZE;
74304
74305 down_write(&current->mm->mmap_sem);
74306
74307 @@ -456,6 +473,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74308 if (!new_len)
74309 goto out;
74310
74311 +#ifdef CONFIG_PAX_SEGMEXEC
74312 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
74313 + pax_task_size = SEGMEXEC_TASK_SIZE;
74314 +#endif
74315 +
74316 + pax_task_size -= PAGE_SIZE;
74317 +
74318 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
74319 + old_len > pax_task_size || addr > pax_task_size-old_len)
74320 + goto out;
74321 +
74322 if (flags & MREMAP_FIXED) {
74323 if (flags & MREMAP_MAYMOVE)
74324 ret = mremap_to(addr, old_len, new_addr, new_len);
74325 @@ -505,6 +533,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74326 addr + new_len);
74327 }
74328 ret = addr;
74329 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
74330 goto out;
74331 }
74332 }
74333 @@ -528,7 +557,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
74334 goto out;
74335 }
74336
74337 + map_flags = vma->vm_flags;
74338 ret = move_vma(vma, addr, old_len, new_len, new_addr);
74339 + if (!(ret & ~PAGE_MASK)) {
74340 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
74341 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
74342 + }
74343 }
74344 out:
74345 if (ret & ~PAGE_MASK)
74346 diff --git a/mm/nommu.c b/mm/nommu.c
74347 index d4b0c10..ed421b5 100644
74348 --- a/mm/nommu.c
74349 +++ b/mm/nommu.c
74350 @@ -62,7 +62,6 @@ int sysctl_overcommit_memory = OVERCOMMIT_GUESS; /* heuristic overcommit */
74351 int sysctl_overcommit_ratio = 50; /* default is 50% */
74352 int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
74353 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
74354 -int heap_stack_gap = 0;
74355
74356 atomic_long_t mmap_pages_allocated;
74357
74358 @@ -827,15 +826,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
74359 EXPORT_SYMBOL(find_vma);
74360
74361 /*
74362 - * find a VMA
74363 - * - we don't extend stack VMAs under NOMMU conditions
74364 - */
74365 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
74366 -{
74367 - return find_vma(mm, addr);
74368 -}
74369 -
74370 -/*
74371 * expand a stack to a given address
74372 * - not supported under NOMMU conditions
74373 */
74374 @@ -1551,6 +1541,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
74375
74376 /* most fields are the same, copy all, and then fixup */
74377 *new = *vma;
74378 + INIT_LIST_HEAD(&new->anon_vma_chain);
74379 *region = *vma->vm_region;
74380 new->vm_region = region;
74381
74382 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
74383 index 34d879e..62970df 100644
74384 --- a/mm/page_alloc.c
74385 +++ b/mm/page_alloc.c
74386 @@ -336,7 +336,7 @@ out:
74387 * This usage means that zero-order pages may not be compound.
74388 */
74389
74390 -static void free_compound_page(struct page *page)
74391 +void free_compound_page(struct page *page)
74392 {
74393 __free_pages_ok(page, compound_order(page));
74394 }
74395 @@ -693,6 +693,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74396 int i;
74397 int bad = 0;
74398
74399 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74400 + unsigned long index = 1UL << order;
74401 +#endif
74402 +
74403 trace_mm_page_free(page, order);
74404 kmemcheck_free_shadow(page, order);
74405
74406 @@ -708,6 +712,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
74407 debug_check_no_obj_freed(page_address(page),
74408 PAGE_SIZE << order);
74409 }
74410 +
74411 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
74412 + for (; index; --index)
74413 + sanitize_highpage(page + index - 1);
74414 +#endif
74415 +
74416 arch_free_page(page, order);
74417 kernel_map_pages(page, 1 << order, 0);
74418
74419 @@ -849,8 +859,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
74420 arch_alloc_page(page, order);
74421 kernel_map_pages(page, 1 << order, 1);
74422
74423 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
74424 if (gfp_flags & __GFP_ZERO)
74425 prep_zero_page(page, order, gfp_flags);
74426 +#endif
74427
74428 if (order && (gfp_flags & __GFP_COMP))
74429 prep_compound_page(page, order);
74430 @@ -3579,7 +3591,13 @@ static int pageblock_is_reserved(unsigned long start_pfn, unsigned long end_pfn)
74431 unsigned long pfn;
74432
74433 for (pfn = start_pfn; pfn < end_pfn; pfn++) {
74434 +#ifdef CONFIG_X86_32
74435 + /* boot failures in VMware 8 on 32bit vanilla since
74436 + this change */
74437 + if (!pfn_valid(pfn) || PageReserved(pfn_to_page(pfn)))
74438 +#else
74439 if (!pfn_valid_within(pfn) || PageReserved(pfn_to_page(pfn)))
74440 +#endif
74441 return 1;
74442 }
74443 return 0;
74444 diff --git a/mm/percpu.c b/mm/percpu.c
74445 index bb4be74..a43ea85 100644
74446 --- a/mm/percpu.c
74447 +++ b/mm/percpu.c
74448 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
74449 static unsigned int pcpu_high_unit_cpu __read_mostly;
74450
74451 /* the address of the first chunk which starts with the kernel static area */
74452 -void *pcpu_base_addr __read_mostly;
74453 +void *pcpu_base_addr __read_only;
74454 EXPORT_SYMBOL_GPL(pcpu_base_addr);
74455
74456 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
74457 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
74458 index 926b466..b23df53 100644
74459 --- a/mm/process_vm_access.c
74460 +++ b/mm/process_vm_access.c
74461 @@ -13,6 +13,7 @@
74462 #include <linux/uio.h>
74463 #include <linux/sched.h>
74464 #include <linux/highmem.h>
74465 +#include <linux/security.h>
74466 #include <linux/ptrace.h>
74467 #include <linux/slab.h>
74468 #include <linux/syscalls.h>
74469 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74470 size_t iov_l_curr_offset = 0;
74471 ssize_t iov_len;
74472
74473 + return -ENOSYS; // PaX: until properly audited
74474 +
74475 /*
74476 * Work out how many pages of struct pages we're going to need
74477 * when eventually calling get_user_pages
74478 */
74479 for (i = 0; i < riovcnt; i++) {
74480 iov_len = rvec[i].iov_len;
74481 - if (iov_len > 0) {
74482 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
74483 - + iov_len)
74484 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
74485 - / PAGE_SIZE + 1;
74486 - nr_pages = max(nr_pages, nr_pages_iov);
74487 - }
74488 + if (iov_len <= 0)
74489 + continue;
74490 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
74491 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
74492 + nr_pages = max(nr_pages, nr_pages_iov);
74493 }
74494
74495 if (nr_pages == 0)
74496 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
74497 goto free_proc_pages;
74498 }
74499
74500 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
74501 + rc = -EPERM;
74502 + goto put_task_struct;
74503 + }
74504 +
74505 mm = mm_access(task, PTRACE_MODE_ATTACH);
74506 if (!mm || IS_ERR(mm)) {
74507 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
74508 diff --git a/mm/rmap.c b/mm/rmap.c
74509 index 0f3b7cd..c5652b6 100644
74510 --- a/mm/rmap.c
74511 +++ b/mm/rmap.c
74512 @@ -167,6 +167,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74513 struct anon_vma *anon_vma = vma->anon_vma;
74514 struct anon_vma_chain *avc;
74515
74516 +#ifdef CONFIG_PAX_SEGMEXEC
74517 + struct anon_vma_chain *avc_m = NULL;
74518 +#endif
74519 +
74520 might_sleep();
74521 if (unlikely(!anon_vma)) {
74522 struct mm_struct *mm = vma->vm_mm;
74523 @@ -176,6 +180,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74524 if (!avc)
74525 goto out_enomem;
74526
74527 +#ifdef CONFIG_PAX_SEGMEXEC
74528 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
74529 + if (!avc_m)
74530 + goto out_enomem_free_avc;
74531 +#endif
74532 +
74533 anon_vma = find_mergeable_anon_vma(vma);
74534 allocated = NULL;
74535 if (!anon_vma) {
74536 @@ -189,6 +199,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74537 /* page_table_lock to protect against threads */
74538 spin_lock(&mm->page_table_lock);
74539 if (likely(!vma->anon_vma)) {
74540 +
74541 +#ifdef CONFIG_PAX_SEGMEXEC
74542 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
74543 +
74544 + if (vma_m) {
74545 + BUG_ON(vma_m->anon_vma);
74546 + vma_m->anon_vma = anon_vma;
74547 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
74548 + avc_m = NULL;
74549 + }
74550 +#endif
74551 +
74552 vma->anon_vma = anon_vma;
74553 anon_vma_chain_link(vma, avc, anon_vma);
74554 allocated = NULL;
74555 @@ -199,12 +221,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
74556
74557 if (unlikely(allocated))
74558 put_anon_vma(allocated);
74559 +
74560 +#ifdef CONFIG_PAX_SEGMEXEC
74561 + if (unlikely(avc_m))
74562 + anon_vma_chain_free(avc_m);
74563 +#endif
74564 +
74565 if (unlikely(avc))
74566 anon_vma_chain_free(avc);
74567 }
74568 return 0;
74569
74570 out_enomem_free_avc:
74571 +
74572 +#ifdef CONFIG_PAX_SEGMEXEC
74573 + if (avc_m)
74574 + anon_vma_chain_free(avc_m);
74575 +#endif
74576 +
74577 anon_vma_chain_free(avc);
74578 out_enomem:
74579 return -ENOMEM;
74580 @@ -240,7 +274,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
74581 * Attach the anon_vmas from src to dst.
74582 * Returns 0 on success, -ENOMEM on failure.
74583 */
74584 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
74585 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
74586 {
74587 struct anon_vma_chain *avc, *pavc;
74588 struct anon_vma *root = NULL;
74589 @@ -318,7 +352,7 @@ void anon_vma_moveto_tail(struct vm_area_struct *dst)
74590 * the corresponding VMA in the parent process is attached to.
74591 * Returns 0 on success, non-zero on failure.
74592 */
74593 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
74594 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
74595 {
74596 struct anon_vma_chain *avc;
74597 struct anon_vma *anon_vma;
74598 diff --git a/mm/shmem.c b/mm/shmem.c
74599 index bd10636..5c16d49 100644
74600 --- a/mm/shmem.c
74601 +++ b/mm/shmem.c
74602 @@ -31,7 +31,7 @@
74603 #include <linux/export.h>
74604 #include <linux/swap.h>
74605
74606 -static struct vfsmount *shm_mnt;
74607 +struct vfsmount *shm_mnt;
74608
74609 #ifdef CONFIG_SHMEM
74610 /*
74611 @@ -75,7 +75,7 @@ static struct vfsmount *shm_mnt;
74612 #define BOGO_DIRENT_SIZE 20
74613
74614 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
74615 -#define SHORT_SYMLINK_LEN 128
74616 +#define SHORT_SYMLINK_LEN 64
74617
74618 struct shmem_xattr {
74619 struct list_head list; /* anchored by shmem_inode_info->xattr_list */
74620 @@ -2590,8 +2590,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
74621 int err = -ENOMEM;
74622
74623 /* Round up to L1_CACHE_BYTES to resist false sharing */
74624 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
74625 - L1_CACHE_BYTES), GFP_KERNEL);
74626 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
74627 if (!sbinfo)
74628 return -ENOMEM;
74629
74630 diff --git a/mm/slab.c b/mm/slab.c
74631 index e901a36..9ff3f90 100644
74632 --- a/mm/slab.c
74633 +++ b/mm/slab.c
74634 @@ -153,7 +153,7 @@
74635
74636 /* Legal flag mask for kmem_cache_create(). */
74637 #if DEBUG
74638 -# define CREATE_MASK (SLAB_RED_ZONE | \
74639 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_RED_ZONE | \
74640 SLAB_POISON | SLAB_HWCACHE_ALIGN | \
74641 SLAB_CACHE_DMA | \
74642 SLAB_STORE_USER | \
74643 @@ -161,7 +161,7 @@
74644 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74645 SLAB_DEBUG_OBJECTS | SLAB_NOLEAKTRACE | SLAB_NOTRACK)
74646 #else
74647 -# define CREATE_MASK (SLAB_HWCACHE_ALIGN | \
74648 +# define CREATE_MASK (SLAB_USERCOPY | SLAB_HWCACHE_ALIGN | \
74649 SLAB_CACHE_DMA | \
74650 SLAB_RECLAIM_ACCOUNT | SLAB_PANIC | \
74651 SLAB_DESTROY_BY_RCU | SLAB_MEM_SPREAD | \
74652 @@ -290,7 +290,7 @@ struct kmem_list3 {
74653 * Need this for bootstrapping a per node allocator.
74654 */
74655 #define NUM_INIT_LISTS (3 * MAX_NUMNODES)
74656 -static struct kmem_list3 __initdata initkmem_list3[NUM_INIT_LISTS];
74657 +static struct kmem_list3 initkmem_list3[NUM_INIT_LISTS];
74658 #define CACHE_CACHE 0
74659 #define SIZE_AC MAX_NUMNODES
74660 #define SIZE_L3 (2 * MAX_NUMNODES)
74661 @@ -391,10 +391,10 @@ static void kmem_list3_init(struct kmem_list3 *parent)
74662 if ((x)->max_freeable < i) \
74663 (x)->max_freeable = i; \
74664 } while (0)
74665 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
74666 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
74667 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
74668 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
74669 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
74670 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
74671 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
74672 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
74673 #else
74674 #define STATS_INC_ACTIVE(x) do { } while (0)
74675 #define STATS_DEC_ACTIVE(x) do { } while (0)
74676 @@ -542,7 +542,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct slab *slab,
74677 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
74678 */
74679 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
74680 - const struct slab *slab, void *obj)
74681 + const struct slab *slab, const void *obj)
74682 {
74683 u32 offset = (obj - slab->s_mem);
74684 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
74685 @@ -563,12 +563,13 @@ EXPORT_SYMBOL(malloc_sizes);
74686 struct cache_names {
74687 char *name;
74688 char *name_dma;
74689 + char *name_usercopy;
74690 };
74691
74692 static struct cache_names __initdata cache_names[] = {
74693 -#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)" },
74694 +#define CACHE(x) { .name = "size-" #x, .name_dma = "size-" #x "(DMA)", .name_usercopy = "size-" #x "(USERCOPY)" },
74695 #include <linux/kmalloc_sizes.h>
74696 - {NULL,}
74697 + {NULL}
74698 #undef CACHE
74699 };
74700
74701 @@ -756,6 +757,12 @@ static inline struct kmem_cache *__find_general_cachep(size_t size,
74702 if (unlikely(gfpflags & GFP_DMA))
74703 return csizep->cs_dmacachep;
74704 #endif
74705 +
74706 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74707 + if (unlikely(gfpflags & GFP_USERCOPY))
74708 + return csizep->cs_usercopycachep;
74709 +#endif
74710 +
74711 return csizep->cs_cachep;
74712 }
74713
74714 @@ -1588,7 +1595,7 @@ void __init kmem_cache_init(void)
74715 sizes[INDEX_AC].cs_cachep = kmem_cache_create(names[INDEX_AC].name,
74716 sizes[INDEX_AC].cs_size,
74717 ARCH_KMALLOC_MINALIGN,
74718 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74719 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74720 NULL);
74721
74722 if (INDEX_AC != INDEX_L3) {
74723 @@ -1596,7 +1603,7 @@ void __init kmem_cache_init(void)
74724 kmem_cache_create(names[INDEX_L3].name,
74725 sizes[INDEX_L3].cs_size,
74726 ARCH_KMALLOC_MINALIGN,
74727 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74728 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74729 NULL);
74730 }
74731
74732 @@ -1614,7 +1621,7 @@ void __init kmem_cache_init(void)
74733 sizes->cs_cachep = kmem_cache_create(names->name,
74734 sizes->cs_size,
74735 ARCH_KMALLOC_MINALIGN,
74736 - ARCH_KMALLOC_FLAGS|SLAB_PANIC,
74737 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74738 NULL);
74739 }
74740 #ifdef CONFIG_ZONE_DMA
74741 @@ -1626,6 +1633,16 @@ void __init kmem_cache_init(void)
74742 SLAB_PANIC,
74743 NULL);
74744 #endif
74745 +
74746 +#ifdef CONFIG_PAX_USERCOPY_SLABS
74747 + sizes->cs_usercopycachep = kmem_cache_create(
74748 + names->name_usercopy,
74749 + sizes->cs_size,
74750 + ARCH_KMALLOC_MINALIGN,
74751 + ARCH_KMALLOC_FLAGS|SLAB_PANIC|SLAB_USERCOPY,
74752 + NULL);
74753 +#endif
74754 +
74755 sizes++;
74756 names++;
74757 }
74758 @@ -4390,10 +4407,10 @@ static int s_show(struct seq_file *m, void *p)
74759 }
74760 /* cpu stats */
74761 {
74762 - unsigned long allochit = atomic_read(&cachep->allochit);
74763 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
74764 - unsigned long freehit = atomic_read(&cachep->freehit);
74765 - unsigned long freemiss = atomic_read(&cachep->freemiss);
74766 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
74767 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
74768 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
74769 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
74770
74771 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
74772 allochit, allocmiss, freehit, freemiss);
74773 @@ -4652,13 +4669,71 @@ static int __init slab_proc_init(void)
74774 {
74775 proc_create("slabinfo",S_IWUSR|S_IRUSR,NULL,&proc_slabinfo_operations);
74776 #ifdef CONFIG_DEBUG_SLAB_LEAK
74777 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
74778 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
74779 #endif
74780 return 0;
74781 }
74782 module_init(slab_proc_init);
74783 #endif
74784
74785 +bool is_usercopy_object(const void *ptr)
74786 +{
74787 + struct page *page;
74788 + struct kmem_cache *cachep;
74789 +
74790 + if (ZERO_OR_NULL_PTR(ptr))
74791 + return false;
74792 +
74793 + if (!slab_is_available())
74794 + return false;
74795 +
74796 + if (!virt_addr_valid(ptr))
74797 + return false;
74798 +
74799 + page = virt_to_head_page(ptr);
74800 +
74801 + if (!PageSlab(page))
74802 + return false;
74803 +
74804 + cachep = page_get_cache(page);
74805 + return cachep->flags & SLAB_USERCOPY;
74806 +}
74807 +
74808 +#ifdef CONFIG_PAX_USERCOPY
74809 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
74810 +{
74811 + struct page *page;
74812 + struct kmem_cache *cachep;
74813 + struct slab *slabp;
74814 + unsigned int objnr;
74815 + unsigned long offset;
74816 +
74817 + if (ZERO_OR_NULL_PTR(ptr))
74818 + return "<null>";
74819 +
74820 + if (!virt_addr_valid(ptr))
74821 + return NULL;
74822 +
74823 + page = virt_to_head_page(ptr);
74824 +
74825 + if (!PageSlab(page))
74826 + return NULL;
74827 +
74828 + cachep = page_get_cache(page);
74829 + if (!(cachep->flags & SLAB_USERCOPY))
74830 + return cachep->name;
74831 +
74832 + slabp = page_get_slab(page);
74833 + objnr = obj_to_index(cachep, slabp, ptr);
74834 + BUG_ON(objnr >= cachep->num);
74835 + offset = ptr - index_to_obj(cachep, slabp, objnr) - obj_offset(cachep);
74836 + if (offset <= obj_size(cachep) && n <= obj_size(cachep) - offset)
74837 + return NULL;
74838 +
74839 + return cachep->name;
74840 +}
74841 +#endif
74842 +
74843 /**
74844 * ksize - get the actual amount of memory allocated for a given object
74845 * @objp: Pointer to the object
74846 diff --git a/mm/slob.c b/mm/slob.c
74847 index 8105be4..33e52d7 100644
74848 --- a/mm/slob.c
74849 +++ b/mm/slob.c
74850 @@ -29,7 +29,7 @@
74851 * If kmalloc is asked for objects of PAGE_SIZE or larger, it calls
74852 * alloc_pages() directly, allocating compound pages so the page order
74853 * does not have to be separately tracked, and also stores the exact
74854 - * allocation size in page->private so that it can be used to accurately
74855 + * allocation size in slob_page->size so that it can be used to accurately
74856 * provide ksize(). These objects are detected in kfree() because slob_page()
74857 * is false for them.
74858 *
74859 @@ -58,6 +58,7 @@
74860 */
74861
74862 #include <linux/kernel.h>
74863 +#include <linux/sched.h>
74864 #include <linux/slab.h>
74865 #include <linux/mm.h>
74866 #include <linux/swap.h> /* struct reclaim_state */
74867 @@ -100,9 +101,8 @@ struct slob_page {
74868 union {
74869 struct {
74870 unsigned long flags; /* mandatory */
74871 - atomic_t _count; /* mandatory */
74872 slobidx_t units; /* free units left in page */
74873 - unsigned long pad[2];
74874 + unsigned long size; /* size when >=PAGE_SIZE */
74875 slob_t *free; /* first free slob_t in page */
74876 struct list_head list; /* linked list of free pages */
74877 };
74878 @@ -135,7 +135,7 @@ static LIST_HEAD(free_slob_large);
74879 */
74880 static inline int is_slob_page(struct slob_page *sp)
74881 {
74882 - return PageSlab((struct page *)sp);
74883 + return PageSlab((struct page *)sp) && !sp->size;
74884 }
74885
74886 static inline void set_slob_page(struct slob_page *sp)
74887 @@ -150,7 +150,7 @@ static inline void clear_slob_page(struct slob_page *sp)
74888
74889 static inline struct slob_page *slob_page(const void *addr)
74890 {
74891 - return (struct slob_page *)virt_to_page(addr);
74892 + return (struct slob_page *)virt_to_head_page(addr);
74893 }
74894
74895 /*
74896 @@ -210,7 +210,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
74897 /*
74898 * Return the size of a slob block.
74899 */
74900 -static slobidx_t slob_units(slob_t *s)
74901 +static slobidx_t slob_units(const slob_t *s)
74902 {
74903 if (s->units > 0)
74904 return s->units;
74905 @@ -220,7 +220,7 @@ static slobidx_t slob_units(slob_t *s)
74906 /*
74907 * Return the next free slob block pointer after this one.
74908 */
74909 -static slob_t *slob_next(slob_t *s)
74910 +static slob_t *slob_next(const slob_t *s)
74911 {
74912 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
74913 slobidx_t next;
74914 @@ -235,7 +235,7 @@ static slob_t *slob_next(slob_t *s)
74915 /*
74916 * Returns true if s is the last free block in its page.
74917 */
74918 -static int slob_last(slob_t *s)
74919 +static int slob_last(const slob_t *s)
74920 {
74921 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
74922 }
74923 @@ -254,6 +254,7 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
74924 if (!page)
74925 return NULL;
74926
74927 + set_slob_page(page);
74928 return page_address(page);
74929 }
74930
74931 @@ -370,11 +371,11 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
74932 if (!b)
74933 return NULL;
74934 sp = slob_page(b);
74935 - set_slob_page(sp);
74936
74937 spin_lock_irqsave(&slob_lock, flags);
74938 sp->units = SLOB_UNITS(PAGE_SIZE);
74939 sp->free = b;
74940 + sp->size = 0;
74941 INIT_LIST_HEAD(&sp->list);
74942 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
74943 set_slob_page_free(sp, slob_list);
74944 @@ -476,10 +477,9 @@ out:
74945 * End of slob allocator proper. Begin kmem_cache_alloc and kmalloc frontend.
74946 */
74947
74948 -void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74949 +static void *__kmalloc_node_align(size_t size, gfp_t gfp, int node, int align)
74950 {
74951 - unsigned int *m;
74952 - int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74953 + slob_t *m;
74954 void *ret;
74955
74956 gfp &= gfp_allowed_mask;
74957 @@ -494,7 +494,10 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74958
74959 if (!m)
74960 return NULL;
74961 - *m = size;
74962 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
74963 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
74964 + m[0].units = size;
74965 + m[1].units = align;
74966 ret = (void *)m + align;
74967
74968 trace_kmalloc_node(_RET_IP_, ret,
74969 @@ -506,16 +509,25 @@ void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74970 gfp |= __GFP_COMP;
74971 ret = slob_new_pages(gfp, order, node);
74972 if (ret) {
74973 - struct page *page;
74974 - page = virt_to_page(ret);
74975 - page->private = size;
74976 + struct slob_page *sp;
74977 + sp = slob_page(ret);
74978 + sp->size = size;
74979 }
74980
74981 trace_kmalloc_node(_RET_IP_, ret,
74982 size, PAGE_SIZE << order, gfp, node);
74983 }
74984
74985 - kmemleak_alloc(ret, size, 1, gfp);
74986 + return ret;
74987 +}
74988 +
74989 +void *__kmalloc_node(size_t size, gfp_t gfp, int node)
74990 +{
74991 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
74992 + void *ret = __kmalloc_node_align(size, gfp, node, align);
74993 +
74994 + if (!ZERO_OR_NULL_PTR(ret))
74995 + kmemleak_alloc(ret, size, 1, gfp);
74996 return ret;
74997 }
74998 EXPORT_SYMBOL(__kmalloc_node);
74999 @@ -533,13 +545,88 @@ void kfree(const void *block)
75000 sp = slob_page(block);
75001 if (is_slob_page(sp)) {
75002 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75003 - unsigned int *m = (unsigned int *)(block - align);
75004 - slob_free(m, *m + align);
75005 - } else
75006 + slob_t *m = (slob_t *)(block - align);
75007 + slob_free(m, m[0].units + align);
75008 + } else {
75009 + clear_slob_page(sp);
75010 + free_slob_page(sp);
75011 + sp->size = 0;
75012 put_page(&sp->page);
75013 + }
75014 }
75015 EXPORT_SYMBOL(kfree);
75016
75017 +bool is_usercopy_object(const void *ptr)
75018 +{
75019 + if (!slab_is_available())
75020 + return false;
75021 +
75022 + // PAX: TODO
75023 +
75024 + return false;
75025 +}
75026 +
75027 +#ifdef CONFIG_PAX_USERCOPY
75028 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75029 +{
75030 + struct slob_page *sp;
75031 + const slob_t *free;
75032 + const void *base;
75033 + unsigned long flags;
75034 +
75035 + if (ZERO_OR_NULL_PTR(ptr))
75036 + return "<null>";
75037 +
75038 + if (!virt_addr_valid(ptr))
75039 + return NULL;
75040 +
75041 + sp = slob_page(ptr);
75042 + if (!PageSlab((struct page *)sp))
75043 + return NULL;
75044 +
75045 + if (sp->size) {
75046 + base = page_address(&sp->page);
75047 + if (base <= ptr && n <= sp->size - (ptr - base))
75048 + return NULL;
75049 + return "<slob>";
75050 + }
75051 +
75052 + /* some tricky double walking to find the chunk */
75053 + spin_lock_irqsave(&slob_lock, flags);
75054 + base = (void *)((unsigned long)ptr & PAGE_MASK);
75055 + free = sp->free;
75056 +
75057 + while ((void *)free <= ptr) {
75058 + base = free + slob_units(free);
75059 + free = slob_next(free);
75060 + }
75061 +
75062 + while (base < (void *)free) {
75063 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
75064 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
75065 + int offset;
75066 +
75067 + if (ptr < base + align)
75068 + break;
75069 +
75070 + offset = ptr - base - align;
75071 + if (offset >= m) {
75072 + base += size;
75073 + continue;
75074 + }
75075 +
75076 + if (n > m - offset)
75077 + break;
75078 +
75079 + spin_unlock_irqrestore(&slob_lock, flags);
75080 + return NULL;
75081 + }
75082 +
75083 + spin_unlock_irqrestore(&slob_lock, flags);
75084 + return "<slob>";
75085 +}
75086 +#endif
75087 +
75088 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
75089 size_t ksize(const void *block)
75090 {
75091 @@ -552,10 +639,10 @@ size_t ksize(const void *block)
75092 sp = slob_page(block);
75093 if (is_slob_page(sp)) {
75094 int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
75095 - unsigned int *m = (unsigned int *)(block - align);
75096 - return SLOB_UNITS(*m) * SLOB_UNIT;
75097 + slob_t *m = (slob_t *)(block - align);
75098 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
75099 } else
75100 - return sp->page.private;
75101 + return sp->size;
75102 }
75103 EXPORT_SYMBOL(ksize);
75104
75105 @@ -571,8 +658,13 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
75106 {
75107 struct kmem_cache *c;
75108
75109 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75110 + c = __kmalloc_node_align(sizeof(struct kmem_cache),
75111 + GFP_KERNEL, -1, ARCH_KMALLOC_MINALIGN);
75112 +#else
75113 c = slob_alloc(sizeof(struct kmem_cache),
75114 GFP_KERNEL, ARCH_KMALLOC_MINALIGN, -1);
75115 +#endif
75116
75117 if (c) {
75118 c->name = name;
75119 @@ -614,17 +706,25 @@ void *kmem_cache_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
75120
75121 lockdep_trace_alloc(flags);
75122
75123 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75124 + b = __kmalloc_node_align(c->size, flags, node, c->align);
75125 +#else
75126 if (c->size < PAGE_SIZE) {
75127 b = slob_alloc(c->size, flags, c->align, node);
75128 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75129 SLOB_UNITS(c->size) * SLOB_UNIT,
75130 flags, node);
75131 } else {
75132 + struct slob_page *sp;
75133 +
75134 b = slob_new_pages(flags, get_order(c->size), node);
75135 + sp = slob_page(b);
75136 + sp->size = c->size;
75137 trace_kmem_cache_alloc_node(_RET_IP_, b, c->size,
75138 PAGE_SIZE << get_order(c->size),
75139 flags, node);
75140 }
75141 +#endif
75142
75143 if (c->ctor)
75144 c->ctor(b);
75145 @@ -636,10 +736,16 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
75146
75147 static void __kmem_cache_free(void *b, int size)
75148 {
75149 - if (size < PAGE_SIZE)
75150 + struct slob_page *sp = slob_page(b);
75151 +
75152 + if (is_slob_page(sp))
75153 slob_free(b, size);
75154 - else
75155 + else {
75156 + clear_slob_page(sp);
75157 + free_slob_page(sp);
75158 + sp->size = 0;
75159 slob_free_pages(b, get_order(size));
75160 + }
75161 }
75162
75163 static void kmem_rcu_free(struct rcu_head *head)
75164 @@ -652,17 +758,31 @@ static void kmem_rcu_free(struct rcu_head *head)
75165
75166 void kmem_cache_free(struct kmem_cache *c, void *b)
75167 {
75168 + int size = c->size;
75169 +
75170 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75171 + if (size + c->align < PAGE_SIZE) {
75172 + size += c->align;
75173 + b -= c->align;
75174 + }
75175 +#endif
75176 +
75177 kmemleak_free_recursive(b, c->flags);
75178 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
75179 struct slob_rcu *slob_rcu;
75180 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
75181 - slob_rcu->size = c->size;
75182 + slob_rcu = b + (size - sizeof(struct slob_rcu));
75183 + slob_rcu->size = size;
75184 call_rcu(&slob_rcu->head, kmem_rcu_free);
75185 } else {
75186 - __kmem_cache_free(b, c->size);
75187 + __kmem_cache_free(b, size);
75188 }
75189
75190 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75191 + trace_kfree(_RET_IP_, b);
75192 +#else
75193 trace_kmem_cache_free(_RET_IP_, b);
75194 +#endif
75195 +
75196 }
75197 EXPORT_SYMBOL(kmem_cache_free);
75198
75199 diff --git a/mm/slub.c b/mm/slub.c
75200 index 8c691fa..2993c2b 100644
75201 --- a/mm/slub.c
75202 +++ b/mm/slub.c
75203 @@ -209,7 +209,7 @@ struct track {
75204
75205 enum track_item { TRACK_ALLOC, TRACK_FREE };
75206
75207 -#ifdef CONFIG_SYSFS
75208 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75209 static int sysfs_slab_add(struct kmem_cache *);
75210 static int sysfs_slab_alias(struct kmem_cache *, const char *);
75211 static void sysfs_slab_remove(struct kmem_cache *);
75212 @@ -538,7 +538,7 @@ static void print_track(const char *s, struct track *t)
75213 if (!t->addr)
75214 return;
75215
75216 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
75217 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
75218 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
75219 #ifdef CONFIG_STACKTRACE
75220 {
75221 @@ -2603,6 +2603,8 @@ void kmem_cache_free(struct kmem_cache *s, void *x)
75222
75223 page = virt_to_head_page(x);
75224
75225 + BUG_ON(!PageSlab(page));
75226 +
75227 slab_free(s, page, x, _RET_IP_);
75228
75229 trace_kmem_cache_free(_RET_IP_, x);
75230 @@ -2636,7 +2638,7 @@ static int slub_min_objects;
75231 * Merge control. If this is set then no merging of slab caches will occur.
75232 * (Could be removed. This was introduced to pacify the merge skeptics.)
75233 */
75234 -static int slub_nomerge;
75235 +static int slub_nomerge = 1;
75236
75237 /*
75238 * Calculate the order of allocation given an slab object size.
75239 @@ -3089,7 +3091,7 @@ static int kmem_cache_open(struct kmem_cache *s,
75240 else
75241 s->cpu_partial = 30;
75242
75243 - s->refcount = 1;
75244 + atomic_set(&s->refcount, 1);
75245 #ifdef CONFIG_NUMA
75246 s->remote_node_defrag_ratio = 1000;
75247 #endif
75248 @@ -3193,8 +3195,7 @@ static inline int kmem_cache_close(struct kmem_cache *s)
75249 void kmem_cache_destroy(struct kmem_cache *s)
75250 {
75251 down_write(&slub_lock);
75252 - s->refcount--;
75253 - if (!s->refcount) {
75254 + if (atomic_dec_and_test(&s->refcount)) {
75255 list_del(&s->list);
75256 up_write(&slub_lock);
75257 if (kmem_cache_close(s)) {
75258 @@ -3223,6 +3224,10 @@ static struct kmem_cache *kmem_cache;
75259 static struct kmem_cache *kmalloc_dma_caches[SLUB_PAGE_SHIFT];
75260 #endif
75261
75262 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75263 +static struct kmem_cache *kmalloc_usercopy_caches[SLUB_PAGE_SHIFT];
75264 +#endif
75265 +
75266 static int __init setup_slub_min_order(char *str)
75267 {
75268 get_option(&str, &slub_min_order);
75269 @@ -3337,6 +3342,13 @@ static struct kmem_cache *get_slab(size_t size, gfp_t flags)
75270 return kmalloc_dma_caches[index];
75271
75272 #endif
75273 +
75274 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75275 + if (flags & SLAB_USERCOPY)
75276 + return kmalloc_usercopy_caches[index];
75277 +
75278 +#endif
75279 +
75280 return kmalloc_caches[index];
75281 }
75282
75283 @@ -3405,6 +3417,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
75284 EXPORT_SYMBOL(__kmalloc_node);
75285 #endif
75286
75287 +bool is_usercopy_object(const void *ptr)
75288 +{
75289 + struct page *page;
75290 + struct kmem_cache *s;
75291 +
75292 + if (ZERO_OR_NULL_PTR(ptr))
75293 + return false;
75294 +
75295 + if (!slab_is_available())
75296 + return false;
75297 +
75298 + if (!virt_addr_valid(ptr))
75299 + return false;
75300 +
75301 + page = virt_to_head_page(ptr);
75302 +
75303 + if (!PageSlab(page))
75304 + return false;
75305 +
75306 + s = page->slab;
75307 + return s->flags & SLAB_USERCOPY;
75308 +}
75309 +
75310 +#ifdef CONFIG_PAX_USERCOPY
75311 +const char *check_heap_object(const void *ptr, unsigned long n, bool to)
75312 +{
75313 + struct page *page;
75314 + struct kmem_cache *s;
75315 + unsigned long offset;
75316 +
75317 + if (ZERO_OR_NULL_PTR(ptr))
75318 + return "<null>";
75319 +
75320 + if (!virt_addr_valid(ptr))
75321 + return NULL;
75322 +
75323 + page = virt_to_head_page(ptr);
75324 +
75325 + if (!PageSlab(page))
75326 + return NULL;
75327 +
75328 + s = page->slab;
75329 + if (!(s->flags & SLAB_USERCOPY))
75330 + return s->name;
75331 +
75332 + offset = (ptr - page_address(page)) % s->size;
75333 + if (offset <= s->objsize && n <= s->objsize - offset)
75334 + return NULL;
75335 +
75336 + return s->name;
75337 +}
75338 +#endif
75339 +
75340 size_t ksize(const void *object)
75341 {
75342 struct page *page;
75343 @@ -3679,7 +3744,7 @@ static void __init kmem_cache_bootstrap_fixup(struct kmem_cache *s)
75344 int node;
75345
75346 list_add(&s->list, &slab_caches);
75347 - s->refcount = -1;
75348 + atomic_set(&s->refcount, -1);
75349
75350 for_each_node_state(node, N_NORMAL_MEMORY) {
75351 struct kmem_cache_node *n = get_node(s, node);
75352 @@ -3799,17 +3864,17 @@ void __init kmem_cache_init(void)
75353
75354 /* Caches that are not of the two-to-the-power-of size */
75355 if (KMALLOC_MIN_SIZE <= 32) {
75356 - kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, 0);
75357 + kmalloc_caches[1] = create_kmalloc_cache("kmalloc-96", 96, SLAB_USERCOPY);
75358 caches++;
75359 }
75360
75361 if (KMALLOC_MIN_SIZE <= 64) {
75362 - kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, 0);
75363 + kmalloc_caches[2] = create_kmalloc_cache("kmalloc-192", 192, SLAB_USERCOPY);
75364 caches++;
75365 }
75366
75367 for (i = KMALLOC_SHIFT_LOW; i < SLUB_PAGE_SHIFT; i++) {
75368 - kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, 0);
75369 + kmalloc_caches[i] = create_kmalloc_cache("kmalloc", 1 << i, SLAB_USERCOPY);
75370 caches++;
75371 }
75372
75373 @@ -3851,6 +3916,22 @@ void __init kmem_cache_init(void)
75374 }
75375 }
75376 #endif
75377 +
75378 +#ifdef CONFIG_PAX_USERCOPY_SLABS
75379 + for (i = 0; i < SLUB_PAGE_SHIFT; i++) {
75380 + struct kmem_cache *s = kmalloc_caches[i];
75381 +
75382 + if (s && s->size) {
75383 + char *name = kasprintf(GFP_NOWAIT,
75384 + "usercopy-kmalloc-%d", s->objsize);
75385 +
75386 + BUG_ON(!name);
75387 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(name,
75388 + s->objsize, SLAB_USERCOPY);
75389 + }
75390 + }
75391 +#endif
75392 +
75393 printk(KERN_INFO
75394 "SLUB: Genslabs=%d, HWalign=%d, Order=%d-%d, MinObjects=%d,"
75395 " CPUs=%d, Nodes=%d\n",
75396 @@ -3877,7 +3958,7 @@ static int slab_unmergeable(struct kmem_cache *s)
75397 /*
75398 * We may have set a slab to be unmergeable during bootstrap.
75399 */
75400 - if (s->refcount < 0)
75401 + if (atomic_read(&s->refcount) < 0)
75402 return 1;
75403
75404 return 0;
75405 @@ -3936,7 +4017,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
75406 down_write(&slub_lock);
75407 s = find_mergeable(size, align, flags, name, ctor);
75408 if (s) {
75409 - s->refcount++;
75410 + atomic_inc(&s->refcount);
75411 /*
75412 * Adjust the object sizes so that we clear
75413 * the complete object on kzalloc.
75414 @@ -3945,7 +4026,7 @@ struct kmem_cache *kmem_cache_create(const char *name, size_t size,
75415 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
75416
75417 if (sysfs_slab_alias(s, name)) {
75418 - s->refcount--;
75419 + atomic_dec(&s->refcount);
75420 goto err;
75421 }
75422 up_write(&slub_lock);
75423 @@ -4074,7 +4155,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
75424 }
75425 #endif
75426
75427 -#ifdef CONFIG_SYSFS
75428 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75429 static int count_inuse(struct page *page)
75430 {
75431 return page->inuse;
75432 @@ -4461,12 +4542,12 @@ static void resiliency_test(void)
75433 validate_slab_cache(kmalloc_caches[9]);
75434 }
75435 #else
75436 -#ifdef CONFIG_SYSFS
75437 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75438 static void resiliency_test(void) {};
75439 #endif
75440 #endif
75441
75442 -#ifdef CONFIG_SYSFS
75443 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75444 enum slab_stat_type {
75445 SL_ALL, /* All slabs */
75446 SL_PARTIAL, /* Only partially allocated slabs */
75447 @@ -4709,7 +4790,7 @@ SLAB_ATTR_RO(ctor);
75448
75449 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
75450 {
75451 - return sprintf(buf, "%d\n", s->refcount - 1);
75452 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
75453 }
75454 SLAB_ATTR_RO(aliases);
75455
75456 @@ -5280,6 +5361,7 @@ static char *create_unique_id(struct kmem_cache *s)
75457 return name;
75458 }
75459
75460 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75461 static int sysfs_slab_add(struct kmem_cache *s)
75462 {
75463 int err;
75464 @@ -5342,6 +5424,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
75465 kobject_del(&s->kobj);
75466 kobject_put(&s->kobj);
75467 }
75468 +#endif
75469
75470 /*
75471 * Need to buffer aliases during bootup until sysfs becomes
75472 @@ -5355,6 +5438,7 @@ struct saved_alias {
75473
75474 static struct saved_alias *alias_list;
75475
75476 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
75477 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75478 {
75479 struct saved_alias *al;
75480 @@ -5377,6 +5461,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
75481 alias_list = al;
75482 return 0;
75483 }
75484 +#endif
75485
75486 static int __init slab_sysfs_init(void)
75487 {
75488 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
75489 index 1b7e22a..3fcd4f3 100644
75490 --- a/mm/sparse-vmemmap.c
75491 +++ b/mm/sparse-vmemmap.c
75492 @@ -128,7 +128,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
75493 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75494 if (!p)
75495 return NULL;
75496 - pud_populate(&init_mm, pud, p);
75497 + pud_populate_kernel(&init_mm, pud, p);
75498 }
75499 return pud;
75500 }
75501 @@ -140,7 +140,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
75502 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
75503 if (!p)
75504 return NULL;
75505 - pgd_populate(&init_mm, pgd, p);
75506 + pgd_populate_kernel(&init_mm, pgd, p);
75507 }
75508 return pgd;
75509 }
75510 diff --git a/mm/swap.c b/mm/swap.c
75511 index 4e7e2ec..0c57830 100644
75512 --- a/mm/swap.c
75513 +++ b/mm/swap.c
75514 @@ -30,6 +30,7 @@
75515 #include <linux/backing-dev.h>
75516 #include <linux/memcontrol.h>
75517 #include <linux/gfp.h>
75518 +#include <linux/hugetlb.h>
75519
75520 #include "internal.h"
75521
75522 @@ -72,6 +73,8 @@ static void __put_compound_page(struct page *page)
75523
75524 __page_cache_release(page);
75525 dtor = get_compound_page_dtor(page);
75526 + if (!PageHuge(page))
75527 + BUG_ON(dtor != free_compound_page);
75528 (*dtor)(page);
75529 }
75530
75531 diff --git a/mm/swapfile.c b/mm/swapfile.c
75532 index 71373d0..11fa7d9 100644
75533 --- a/mm/swapfile.c
75534 +++ b/mm/swapfile.c
75535 @@ -63,7 +63,7 @@ static DEFINE_MUTEX(swapon_mutex);
75536
75537 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
75538 /* Activity counter to indicate that a swapon or swapoff has occurred */
75539 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
75540 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
75541
75542 static inline unsigned char swap_count(unsigned char ent)
75543 {
75544 @@ -1663,7 +1663,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
75545 }
75546 filp_close(swap_file, NULL);
75547 err = 0;
75548 - atomic_inc(&proc_poll_event);
75549 + atomic_inc_unchecked(&proc_poll_event);
75550 wake_up_interruptible(&proc_poll_wait);
75551
75552 out_dput:
75553 @@ -1679,8 +1679,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
75554
75555 poll_wait(file, &proc_poll_wait, wait);
75556
75557 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
75558 - seq->poll_event = atomic_read(&proc_poll_event);
75559 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
75560 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75561 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
75562 }
75563
75564 @@ -1778,7 +1778,7 @@ static int swaps_open(struct inode *inode, struct file *file)
75565 return ret;
75566
75567 seq = file->private_data;
75568 - seq->poll_event = atomic_read(&proc_poll_event);
75569 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
75570 return 0;
75571 }
75572
75573 @@ -2120,7 +2120,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
75574 (frontswap_map) ? "FS" : "");
75575
75576 mutex_unlock(&swapon_mutex);
75577 - atomic_inc(&proc_poll_event);
75578 + atomic_inc_unchecked(&proc_poll_event);
75579 wake_up_interruptible(&proc_poll_wait);
75580
75581 if (S_ISREG(inode->i_mode))
75582 diff --git a/mm/util.c b/mm/util.c
75583 index 8c7265a..c96d884 100644
75584 --- a/mm/util.c
75585 +++ b/mm/util.c
75586 @@ -285,6 +285,12 @@ done:
75587 void arch_pick_mmap_layout(struct mm_struct *mm)
75588 {
75589 mm->mmap_base = TASK_UNMAPPED_BASE;
75590 +
75591 +#ifdef CONFIG_PAX_RANDMMAP
75592 + if (mm->pax_flags & MF_PAX_RANDMMAP)
75593 + mm->mmap_base += mm->delta_mmap;
75594 +#endif
75595 +
75596 mm->get_unmapped_area = arch_get_unmapped_area;
75597 mm->unmap_area = arch_unmap_area;
75598 }
75599 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
75600 index 2aad499..8aad8b1 100644
75601 --- a/mm/vmalloc.c
75602 +++ b/mm/vmalloc.c
75603 @@ -39,8 +39,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
75604
75605 pte = pte_offset_kernel(pmd, addr);
75606 do {
75607 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75608 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75609 +
75610 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75611 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
75612 + BUG_ON(!pte_exec(*pte));
75613 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
75614 + continue;
75615 + }
75616 +#endif
75617 +
75618 + {
75619 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
75620 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
75621 + }
75622 } while (pte++, addr += PAGE_SIZE, addr != end);
75623 }
75624
75625 @@ -91,6 +102,7 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75626 unsigned long end, pgprot_t prot, struct page **pages, int *nr)
75627 {
75628 pte_t *pte;
75629 + int ret = -ENOMEM;
75630
75631 /*
75632 * nr is a running index into the array which helps higher level
75633 @@ -100,17 +112,30 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
75634 pte = pte_alloc_kernel(pmd, addr);
75635 if (!pte)
75636 return -ENOMEM;
75637 +
75638 + pax_open_kernel();
75639 do {
75640 struct page *page = pages[*nr];
75641
75642 - if (WARN_ON(!pte_none(*pte)))
75643 - return -EBUSY;
75644 - if (WARN_ON(!page))
75645 - return -ENOMEM;
75646 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75647 + if (pgprot_val(prot) & _PAGE_NX)
75648 +#endif
75649 +
75650 + if (WARN_ON(!pte_none(*pte))) {
75651 + ret = -EBUSY;
75652 + goto out;
75653 + }
75654 + if (WARN_ON(!page)) {
75655 + ret = -ENOMEM;
75656 + goto out;
75657 + }
75658 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
75659 (*nr)++;
75660 } while (pte++, addr += PAGE_SIZE, addr != end);
75661 - return 0;
75662 + ret = 0;
75663 +out:
75664 + pax_close_kernel();
75665 + return ret;
75666 }
75667
75668 static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75669 @@ -119,7 +144,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
75670 pmd_t *pmd;
75671 unsigned long next;
75672
75673 - pmd = pmd_alloc(&init_mm, pud, addr);
75674 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
75675 if (!pmd)
75676 return -ENOMEM;
75677 do {
75678 @@ -136,7 +161,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
75679 pud_t *pud;
75680 unsigned long next;
75681
75682 - pud = pud_alloc(&init_mm, pgd, addr);
75683 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
75684 if (!pud)
75685 return -ENOMEM;
75686 do {
75687 @@ -191,11 +216,20 @@ int is_vmalloc_or_module_addr(const void *x)
75688 * and fall back on vmalloc() if that fails. Others
75689 * just put it in the vmalloc space.
75690 */
75691 -#if defined(CONFIG_MODULES) && defined(MODULES_VADDR)
75692 +#ifdef CONFIG_MODULES
75693 +#ifdef MODULES_VADDR
75694 unsigned long addr = (unsigned long)x;
75695 if (addr >= MODULES_VADDR && addr < MODULES_END)
75696 return 1;
75697 #endif
75698 +
75699 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
75700 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
75701 + return 1;
75702 +#endif
75703 +
75704 +#endif
75705 +
75706 return is_vmalloc_addr(x);
75707 }
75708
75709 @@ -216,8 +250,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
75710
75711 if (!pgd_none(*pgd)) {
75712 pud_t *pud = pud_offset(pgd, addr);
75713 +#ifdef CONFIG_X86
75714 + if (!pud_large(*pud))
75715 +#endif
75716 if (!pud_none(*pud)) {
75717 pmd_t *pmd = pmd_offset(pud, addr);
75718 +#ifdef CONFIG_X86
75719 + if (!pmd_large(*pmd))
75720 +#endif
75721 if (!pmd_none(*pmd)) {
75722 pte_t *ptep, pte;
75723
75724 @@ -329,7 +369,7 @@ static void purge_vmap_area_lazy(void);
75725 * Allocate a region of KVA of the specified size and alignment, within the
75726 * vstart and vend.
75727 */
75728 -static struct vmap_area *alloc_vmap_area(unsigned long size,
75729 +static __size_overflow(1) struct vmap_area *alloc_vmap_area(unsigned long size,
75730 unsigned long align,
75731 unsigned long vstart, unsigned long vend,
75732 int node, gfp_t gfp_mask)
75733 @@ -1320,6 +1360,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
75734 struct vm_struct *area;
75735
75736 BUG_ON(in_interrupt());
75737 +
75738 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75739 + if (flags & VM_KERNEXEC) {
75740 + if (start != VMALLOC_START || end != VMALLOC_END)
75741 + return NULL;
75742 + start = (unsigned long)MODULES_EXEC_VADDR;
75743 + end = (unsigned long)MODULES_EXEC_END;
75744 + }
75745 +#endif
75746 +
75747 if (flags & VM_IOREMAP) {
75748 int bit = fls(size);
75749
75750 @@ -1552,6 +1602,11 @@ void *vmap(struct page **pages, unsigned int count,
75751 if (count > totalram_pages)
75752 return NULL;
75753
75754 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75755 + if (!(pgprot_val(prot) & _PAGE_NX))
75756 + flags |= VM_KERNEXEC;
75757 +#endif
75758 +
75759 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
75760 __builtin_return_address(0));
75761 if (!area)
75762 @@ -1653,6 +1708,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
75763 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
75764 goto fail;
75765
75766 +#if defined(CONFIG_MODULES) && defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
75767 + if (!(pgprot_val(prot) & _PAGE_NX))
75768 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST | VM_KERNEXEC,
75769 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
75770 + else
75771 +#endif
75772 +
75773 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNLIST,
75774 start, end, node, gfp_mask, caller);
75775 if (!area)
75776 @@ -1826,10 +1888,9 @@ EXPORT_SYMBOL(vzalloc_node);
75777 * For tight control over page level allocator and protection flags
75778 * use __vmalloc() instead.
75779 */
75780 -
75781 void *vmalloc_exec(unsigned long size)
75782 {
75783 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
75784 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
75785 -1, __builtin_return_address(0));
75786 }
75787
75788 @@ -2124,6 +2185,8 @@ int remap_vmalloc_range(struct vm_area_struct *vma, void *addr,
75789 unsigned long uaddr = vma->vm_start;
75790 unsigned long usize = vma->vm_end - vma->vm_start;
75791
75792 + BUG_ON(vma->vm_mirror);
75793 +
75794 if ((PAGE_SIZE-1) & (unsigned long)addr)
75795 return -EINVAL;
75796
75797 @@ -2560,7 +2623,7 @@ static int s_show(struct seq_file *m, void *p)
75798 {
75799 struct vm_struct *v = p;
75800
75801 - seq_printf(m, "0x%p-0x%p %7ld",
75802 + seq_printf(m, "0x%pK-0x%pK %7ld",
75803 v->addr, v->addr + v->size, v->size);
75804
75805 if (v->caller)
75806 diff --git a/mm/vmstat.c b/mm/vmstat.c
75807 index 1bbbbd9..ff35669 100644
75808 --- a/mm/vmstat.c
75809 +++ b/mm/vmstat.c
75810 @@ -78,7 +78,7 @@ void vm_events_fold_cpu(int cpu)
75811 *
75812 * vm_stat contains the global counters
75813 */
75814 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75815 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
75816 EXPORT_SYMBOL(vm_stat);
75817
75818 #ifdef CONFIG_SMP
75819 @@ -454,7 +454,7 @@ void refresh_cpu_vm_stats(int cpu)
75820 v = p->vm_stat_diff[i];
75821 p->vm_stat_diff[i] = 0;
75822 local_irq_restore(flags);
75823 - atomic_long_add(v, &zone->vm_stat[i]);
75824 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
75825 global_diff[i] += v;
75826 #ifdef CONFIG_NUMA
75827 /* 3 seconds idle till flush */
75828 @@ -492,7 +492,7 @@ void refresh_cpu_vm_stats(int cpu)
75829
75830 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
75831 if (global_diff[i])
75832 - atomic_long_add(global_diff[i], &vm_stat[i]);
75833 + atomic_long_add_unchecked(global_diff[i], &vm_stat[i]);
75834 }
75835
75836 #endif
75837 @@ -1211,10 +1211,20 @@ static int __init setup_vmstat(void)
75838 start_cpu_timer(cpu);
75839 #endif
75840 #ifdef CONFIG_PROC_FS
75841 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
75842 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
75843 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
75844 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
75845 + {
75846 + mode_t gr_mode = S_IRUGO;
75847 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
75848 + gr_mode = S_IRUSR;
75849 +#endif
75850 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
75851 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
75852 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
75853 + proc_create("vmstat", gr_mode | S_IRGRP, NULL, &proc_vmstat_file_operations);
75854 +#else
75855 + proc_create("vmstat", gr_mode, NULL, &proc_vmstat_file_operations);
75856 +#endif
75857 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
75858 + }
75859 #endif
75860 return 0;
75861 }
75862 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
75863 index 9096bcb..43ed7bb 100644
75864 --- a/net/8021q/vlan.c
75865 +++ b/net/8021q/vlan.c
75866 @@ -557,8 +557,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
75867 err = -EPERM;
75868 if (!capable(CAP_NET_ADMIN))
75869 break;
75870 - if ((args.u.name_type >= 0) &&
75871 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
75872 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
75873 struct vlan_net *vn;
75874
75875 vn = net_generic(net, vlan_net_id);
75876 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
75877 index 6449bae..8c1f454 100644
75878 --- a/net/9p/trans_fd.c
75879 +++ b/net/9p/trans_fd.c
75880 @@ -425,7 +425,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
75881 oldfs = get_fs();
75882 set_fs(get_ds());
75883 /* The cast to a user pointer is valid due to the set_fs() */
75884 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
75885 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
75886 set_fs(oldfs);
75887
75888 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
75889 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
75890 index 876fbe8..8bbea9f 100644
75891 --- a/net/atm/atm_misc.c
75892 +++ b/net/atm/atm_misc.c
75893 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
75894 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
75895 return 1;
75896 atm_return(vcc, truesize);
75897 - atomic_inc(&vcc->stats->rx_drop);
75898 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75899 return 0;
75900 }
75901 EXPORT_SYMBOL(atm_charge);
75902 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
75903 }
75904 }
75905 atm_return(vcc, guess);
75906 - atomic_inc(&vcc->stats->rx_drop);
75907 + atomic_inc_unchecked(&vcc->stats->rx_drop);
75908 return NULL;
75909 }
75910 EXPORT_SYMBOL(atm_alloc_charge);
75911 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
75912
75913 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75914 {
75915 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75916 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75917 __SONET_ITEMS
75918 #undef __HANDLE_ITEM
75919 }
75920 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
75921
75922 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
75923 {
75924 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75925 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
75926 __SONET_ITEMS
75927 #undef __HANDLE_ITEM
75928 }
75929 diff --git a/net/atm/lec.h b/net/atm/lec.h
75930 index a86aff9..3a0d6f6 100644
75931 --- a/net/atm/lec.h
75932 +++ b/net/atm/lec.h
75933 @@ -48,7 +48,7 @@ struct lane2_ops {
75934 const u8 *tlvs, u32 sizeoftlvs);
75935 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
75936 const u8 *tlvs, u32 sizeoftlvs);
75937 -};
75938 +} __no_const;
75939
75940 /*
75941 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
75942 diff --git a/net/atm/mpc.h b/net/atm/mpc.h
75943 index 0919a88..a23d54e 100644
75944 --- a/net/atm/mpc.h
75945 +++ b/net/atm/mpc.h
75946 @@ -33,7 +33,7 @@ struct mpoa_client {
75947 struct mpc_parameters parameters; /* parameters for this client */
75948
75949 const struct net_device_ops *old_ops;
75950 - struct net_device_ops new_ops;
75951 + net_device_ops_no_const new_ops;
75952 };
75953
75954
75955 diff --git a/net/atm/proc.c b/net/atm/proc.c
75956 index 0d020de..011c7bb 100644
75957 --- a/net/atm/proc.c
75958 +++ b/net/atm/proc.c
75959 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
75960 const struct k_atm_aal_stats *stats)
75961 {
75962 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
75963 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
75964 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
75965 - atomic_read(&stats->rx_drop));
75966 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
75967 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
75968 + atomic_read_unchecked(&stats->rx_drop));
75969 }
75970
75971 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
75972 diff --git a/net/atm/resources.c b/net/atm/resources.c
75973 index 23f45ce..c748f1a 100644
75974 --- a/net/atm/resources.c
75975 +++ b/net/atm/resources.c
75976 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
75977 static void copy_aal_stats(struct k_atm_aal_stats *from,
75978 struct atm_aal_stats *to)
75979 {
75980 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
75981 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
75982 __AAL_STAT_ITEMS
75983 #undef __HANDLE_ITEM
75984 }
75985 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
75986 static void subtract_aal_stats(struct k_atm_aal_stats *from,
75987 struct atm_aal_stats *to)
75988 {
75989 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
75990 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
75991 __AAL_STAT_ITEMS
75992 #undef __HANDLE_ITEM
75993 }
75994 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
75995 index dc53798..dc66333 100644
75996 --- a/net/batman-adv/bat_iv_ogm.c
75997 +++ b/net/batman-adv/bat_iv_ogm.c
75998 @@ -63,7 +63,7 @@ static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
75999
76000 /* randomize initial seqno to avoid collision */
76001 get_random_bytes(&random_seqno, sizeof(random_seqno));
76002 - atomic_set(&hard_iface->seqno, random_seqno);
76003 + atomic_set_unchecked(&hard_iface->seqno, random_seqno);
76004
76005 hard_iface->packet_len = BATMAN_OGM_HLEN;
76006 hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);
76007 @@ -572,7 +572,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
76008
76009 /* change sequence number to network order */
76010 batman_ogm_packet->seqno =
76011 - htonl((uint32_t)atomic_read(&hard_iface->seqno));
76012 + htonl((uint32_t)atomic_read_unchecked(&hard_iface->seqno));
76013
76014 batman_ogm_packet->ttvn = atomic_read(&bat_priv->ttvn);
76015 batman_ogm_packet->tt_crc = htons((uint16_t)
76016 @@ -592,7 +592,7 @@ static void bat_iv_ogm_schedule(struct hard_iface *hard_iface,
76017 else
76018 batman_ogm_packet->gw_flags = NO_FLAGS;
76019
76020 - atomic_inc(&hard_iface->seqno);
76021 + atomic_inc_unchecked(&hard_iface->seqno);
76022
76023 slide_own_bcast_window(hard_iface);
76024 bat_iv_ogm_queue_add(bat_priv, hard_iface->packet_buff,
76025 @@ -956,7 +956,7 @@ static void bat_iv_ogm_process(const struct ethhdr *ethhdr,
76026 return;
76027
76028 /* could be changed by schedule_own_packet() */
76029 - if_incoming_seqno = atomic_read(&if_incoming->seqno);
76030 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->seqno);
76031
76032 has_directlink_flag = (batman_ogm_packet->flags & DIRECTLINK ? 1 : 0);
76033
76034 diff --git a/net/batman-adv/hard-interface.c b/net/batman-adv/hard-interface.c
76035 index dc334fa..766a01a 100644
76036 --- a/net/batman-adv/hard-interface.c
76037 +++ b/net/batman-adv/hard-interface.c
76038 @@ -321,7 +321,7 @@ int hardif_enable_interface(struct hard_iface *hard_iface,
76039 hard_iface->batman_adv_ptype.dev = hard_iface->net_dev;
76040 dev_add_pack(&hard_iface->batman_adv_ptype);
76041
76042 - atomic_set(&hard_iface->frag_seqno, 1);
76043 + atomic_set_unchecked(&hard_iface->frag_seqno, 1);
76044 bat_info(hard_iface->soft_iface, "Adding interface: %s\n",
76045 hard_iface->net_dev->name);
76046
76047 @@ -444,7 +444,7 @@ static struct hard_iface *hardif_add_interface(struct net_device *net_dev)
76048 * This can't be called via a bat_priv callback because
76049 * we have no bat_priv yet.
76050 */
76051 - atomic_set(&hard_iface->seqno, 1);
76052 + atomic_set_unchecked(&hard_iface->seqno, 1);
76053 hard_iface->packet_buff = NULL;
76054
76055 return hard_iface;
76056 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
76057 index a0ec0e4..7beb587 100644
76058 --- a/net/batman-adv/soft-interface.c
76059 +++ b/net/batman-adv/soft-interface.c
76060 @@ -214,7 +214,7 @@ static int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
76061
76062 /* set broadcast sequence number */
76063 bcast_packet->seqno =
76064 - htonl(atomic_inc_return(&bat_priv->bcast_seqno));
76065 + htonl(atomic_inc_return_unchecked(&bat_priv->bcast_seqno));
76066
76067 add_bcast_packet_to_list(bat_priv, skb, 1);
76068
76069 @@ -390,7 +390,7 @@ struct net_device *softif_create(const char *name)
76070 atomic_set(&bat_priv->batman_queue_left, BATMAN_QUEUE_LEN);
76071
76072 atomic_set(&bat_priv->mesh_state, MESH_INACTIVE);
76073 - atomic_set(&bat_priv->bcast_seqno, 1);
76074 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
76075 atomic_set(&bat_priv->ttvn, 0);
76076 atomic_set(&bat_priv->tt_local_changes, 0);
76077 atomic_set(&bat_priv->tt_ogm_append_cnt, 0);
76078 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
76079 index 61308e8..2e142b2 100644
76080 --- a/net/batman-adv/types.h
76081 +++ b/net/batman-adv/types.h
76082 @@ -38,8 +38,8 @@ struct hard_iface {
76083 int16_t if_num;
76084 char if_status;
76085 struct net_device *net_dev;
76086 - atomic_t seqno;
76087 - atomic_t frag_seqno;
76088 + atomic_unchecked_t seqno;
76089 + atomic_unchecked_t frag_seqno;
76090 unsigned char *packet_buff;
76091 int packet_len;
76092 struct kobject *hardif_obj;
76093 @@ -163,7 +163,7 @@ struct bat_priv {
76094 atomic_t orig_interval; /* uint */
76095 atomic_t hop_penalty; /* uint */
76096 atomic_t log_level; /* uint */
76097 - atomic_t bcast_seqno;
76098 + atomic_unchecked_t bcast_seqno;
76099 atomic_t bcast_queue_left;
76100 atomic_t batman_queue_left;
76101 atomic_t ttvn; /* translation table version number */
76102 diff --git a/net/batman-adv/unicast.c b/net/batman-adv/unicast.c
76103 index 74175c2..32f8901 100644
76104 --- a/net/batman-adv/unicast.c
76105 +++ b/net/batman-adv/unicast.c
76106 @@ -264,7 +264,7 @@ int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv,
76107 frag1->flags = UNI_FRAG_HEAD | large_tail;
76108 frag2->flags = large_tail;
76109
76110 - seqno = atomic_add_return(2, &hard_iface->frag_seqno);
76111 + seqno = atomic_add_return_unchecked(2, &hard_iface->frag_seqno);
76112 frag1->seqno = htons(seqno - 1);
76113 frag2->seqno = htons(seqno);
76114
76115 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
76116 index bedc768..a4a2b19 100644
76117 --- a/net/bluetooth/hci_sock.c
76118 +++ b/net/bluetooth/hci_sock.c
76119 @@ -942,7 +942,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname, char
76120 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
76121 }
76122
76123 - len = min_t(unsigned int, len, sizeof(uf));
76124 + len = min((size_t)len, sizeof(uf));
76125 if (copy_from_user(&uf, optval, len)) {
76126 err = -EFAULT;
76127 break;
76128 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
76129 index 6204170..5ae8707 100644
76130 --- a/net/bluetooth/l2cap_core.c
76131 +++ b/net/bluetooth/l2cap_core.c
76132 @@ -2800,8 +2800,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len, voi
76133 break;
76134
76135 case L2CAP_CONF_RFC:
76136 - if (olen == sizeof(rfc))
76137 - memcpy(&rfc, (void *)val, olen);
76138 + if (olen != sizeof(rfc))
76139 + break;
76140 +
76141 + memcpy(&rfc, (void *)val, olen);
76142
76143 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
76144 rfc.mode != chan->mode)
76145 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
76146 index 9c94d44..831dc8e 100644
76147 --- a/net/bluetooth/l2cap_sock.c
76148 +++ b/net/bluetooth/l2cap_sock.c
76149 @@ -452,7 +452,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76150 struct sock *sk = sock->sk;
76151 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
76152 struct l2cap_options opts;
76153 - int len, err = 0;
76154 + int err = 0;
76155 + size_t len = optlen;
76156 u32 opt;
76157
76158 BT_DBG("sk %p", sk);
76159 @@ -474,7 +475,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname, char __us
76160 opts.max_tx = chan->max_tx;
76161 opts.txwin_size = chan->tx_win;
76162
76163 - len = min_t(unsigned int, sizeof(opts), optlen);
76164 + len = min(sizeof(opts), len);
76165 if (copy_from_user((char *) &opts, optval, len)) {
76166 err = -EFAULT;
76167 break;
76168 @@ -547,7 +548,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76169 struct bt_security sec;
76170 struct bt_power pwr;
76171 struct l2cap_conn *conn;
76172 - int len, err = 0;
76173 + int err = 0;
76174 + size_t len = optlen;
76175 u32 opt;
76176
76177 BT_DBG("sk %p", sk);
76178 @@ -570,7 +572,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76179
76180 sec.level = BT_SECURITY_LOW;
76181
76182 - len = min_t(unsigned int, sizeof(sec), optlen);
76183 + len = min(sizeof(sec), len);
76184 if (copy_from_user((char *) &sec, optval, len)) {
76185 err = -EFAULT;
76186 break;
76187 @@ -667,7 +669,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname, ch
76188
76189 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
76190
76191 - len = min_t(unsigned int, sizeof(pwr), optlen);
76192 + len = min(sizeof(pwr), len);
76193 if (copy_from_user((char *) &pwr, optval, len)) {
76194 err = -EFAULT;
76195 break;
76196 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
76197 index 2df6956..4b24eef 100644
76198 --- a/net/bluetooth/rfcomm/sock.c
76199 +++ b/net/bluetooth/rfcomm/sock.c
76200 @@ -686,7 +686,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76201 struct sock *sk = sock->sk;
76202 struct bt_security sec;
76203 int err = 0;
76204 - size_t len;
76205 + size_t len = optlen;
76206 u32 opt;
76207
76208 BT_DBG("sk %p", sk);
76209 @@ -708,7 +708,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
76210
76211 sec.level = BT_SECURITY_LOW;
76212
76213 - len = min_t(unsigned int, sizeof(sec), optlen);
76214 + len = min(sizeof(sec), len);
76215 if (copy_from_user((char *) &sec, optval, len)) {
76216 err = -EFAULT;
76217 break;
76218 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
76219 index 6435296..4f8c8f6 100644
76220 --- a/net/bluetooth/rfcomm/tty.c
76221 +++ b/net/bluetooth/rfcomm/tty.c
76222 @@ -314,7 +314,7 @@ static void rfcomm_dev_del(struct rfcomm_dev *dev)
76223 BUG_ON(test_and_set_bit(RFCOMM_TTY_RELEASED, &dev->flags));
76224
76225 spin_lock_irqsave(&dev->port.lock, flags);
76226 - if (dev->port.count > 0) {
76227 + if (atomic_read(&dev->port.count) > 0) {
76228 spin_unlock_irqrestore(&dev->port.lock, flags);
76229 return;
76230 }
76231 @@ -669,10 +669,10 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
76232 return -ENODEV;
76233
76234 BT_DBG("dev %p dst %s channel %d opened %d", dev, batostr(&dev->dst),
76235 - dev->channel, dev->port.count);
76236 + dev->channel, atomic_read(&dev->port.count));
76237
76238 spin_lock_irqsave(&dev->port.lock, flags);
76239 - if (++dev->port.count > 1) {
76240 + if (atomic_inc_return(&dev->port.count) > 1) {
76241 spin_unlock_irqrestore(&dev->port.lock, flags);
76242 return 0;
76243 }
76244 @@ -737,10 +737,10 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
76245 return;
76246
76247 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
76248 - dev->port.count);
76249 + atomic_read(&dev->port.count));
76250
76251 spin_lock_irqsave(&dev->port.lock, flags);
76252 - if (!--dev->port.count) {
76253 + if (!atomic_dec_return(&dev->port.count)) {
76254 spin_unlock_irqrestore(&dev->port.lock, flags);
76255 if (dev->tty_dev->parent)
76256 device_move(dev->tty_dev, NULL, DPM_ORDER_DEV_LAST);
76257 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
76258 index 5fe2ff3..121d696 100644
76259 --- a/net/bridge/netfilter/ebtables.c
76260 +++ b/net/bridge/netfilter/ebtables.c
76261 @@ -1523,7 +1523,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
76262 tmp.valid_hooks = t->table->valid_hooks;
76263 }
76264 mutex_unlock(&ebt_mutex);
76265 - if (copy_to_user(user, &tmp, *len) != 0){
76266 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
76267 BUGPRINT("c2u Didn't work\n");
76268 ret = -EFAULT;
76269 break;
76270 @@ -2327,7 +2327,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76271 goto out;
76272 tmp.valid_hooks = t->valid_hooks;
76273
76274 - if (copy_to_user(user, &tmp, *len) != 0) {
76275 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76276 ret = -EFAULT;
76277 break;
76278 }
76279 @@ -2338,7 +2338,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
76280 tmp.entries_size = t->table->entries_size;
76281 tmp.valid_hooks = t->table->valid_hooks;
76282
76283 - if (copy_to_user(user, &tmp, *len) != 0) {
76284 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
76285 ret = -EFAULT;
76286 break;
76287 }
76288 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
76289 index 047cd0e..461fd28 100644
76290 --- a/net/caif/cfctrl.c
76291 +++ b/net/caif/cfctrl.c
76292 @@ -10,6 +10,7 @@
76293 #include <linux/spinlock.h>
76294 #include <linux/slab.h>
76295 #include <linux/pkt_sched.h>
76296 +#include <linux/sched.h>
76297 #include <net/caif/caif_layer.h>
76298 #include <net/caif/cfpkt.h>
76299 #include <net/caif/cfctrl.h>
76300 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
76301 memset(&dev_info, 0, sizeof(dev_info));
76302 dev_info.id = 0xff;
76303 cfsrvl_init(&this->serv, 0, &dev_info, false);
76304 - atomic_set(&this->req_seq_no, 1);
76305 - atomic_set(&this->rsp_seq_no, 1);
76306 + atomic_set_unchecked(&this->req_seq_no, 1);
76307 + atomic_set_unchecked(&this->rsp_seq_no, 1);
76308 this->serv.layer.receive = cfctrl_recv;
76309 sprintf(this->serv.layer.name, "ctrl");
76310 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
76311 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
76312 struct cfctrl_request_info *req)
76313 {
76314 spin_lock_bh(&ctrl->info_list_lock);
76315 - atomic_inc(&ctrl->req_seq_no);
76316 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
76317 + atomic_inc_unchecked(&ctrl->req_seq_no);
76318 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
76319 list_add_tail(&req->list, &ctrl->list);
76320 spin_unlock_bh(&ctrl->info_list_lock);
76321 }
76322 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
76323 if (p != first)
76324 pr_warn("Requests are not received in order\n");
76325
76326 - atomic_set(&ctrl->rsp_seq_no,
76327 + atomic_set_unchecked(&ctrl->rsp_seq_no,
76328 p->sequence_no);
76329 list_del(&p->list);
76330 goto out;
76331 diff --git a/net/caif/chnl_net.c b/net/caif/chnl_net.c
76332 index 69771c0..e597733 100644
76333 --- a/net/caif/chnl_net.c
76334 +++ b/net/caif/chnl_net.c
76335 @@ -94,6 +94,10 @@ static int chnl_recv_cb(struct cflayer *layr, struct cfpkt *pkt)
76336
76337 /* check the version of IP */
76338 ip_version = skb_header_pointer(skb, 0, 1, &buf);
76339 + if (!ip_version) {
76340 + kfree_skb(skb);
76341 + return -EINVAL;
76342 + }
76343
76344 switch (*ip_version >> 4) {
76345 case 4:
76346 diff --git a/net/can/gw.c b/net/can/gw.c
76347 index b41acf2..3affb3a 100644
76348 --- a/net/can/gw.c
76349 +++ b/net/can/gw.c
76350 @@ -96,7 +96,7 @@ struct cf_mod {
76351 struct {
76352 void (*xor)(struct can_frame *cf, struct cgw_csum_xor *xor);
76353 void (*crc8)(struct can_frame *cf, struct cgw_csum_crc8 *crc8);
76354 - } csumfunc;
76355 + } __no_const csumfunc;
76356 };
76357
76358
76359 diff --git a/net/compat.c b/net/compat.c
76360 index 74ed1d7..3695bd9 100644
76361 --- a/net/compat.c
76362 +++ b/net/compat.c
76363 @@ -71,9 +71,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
76364 __get_user(kmsg->msg_controllen, &umsg->msg_controllen) ||
76365 __get_user(kmsg->msg_flags, &umsg->msg_flags))
76366 return -EFAULT;
76367 - kmsg->msg_name = compat_ptr(tmp1);
76368 - kmsg->msg_iov = compat_ptr(tmp2);
76369 - kmsg->msg_control = compat_ptr(tmp3);
76370 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
76371 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
76372 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
76373 return 0;
76374 }
76375
76376 @@ -85,7 +85,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76377
76378 if (kern_msg->msg_namelen) {
76379 if (mode == VERIFY_READ) {
76380 - int err = move_addr_to_kernel(kern_msg->msg_name,
76381 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
76382 kern_msg->msg_namelen,
76383 kern_address);
76384 if (err < 0)
76385 @@ -96,7 +96,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76386 kern_msg->msg_name = NULL;
76387
76388 tot_len = iov_from_user_compat_to_kern(kern_iov,
76389 - (struct compat_iovec __user *)kern_msg->msg_iov,
76390 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
76391 kern_msg->msg_iovlen);
76392 if (tot_len >= 0)
76393 kern_msg->msg_iov = kern_iov;
76394 @@ -116,20 +116,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
76395
76396 #define CMSG_COMPAT_FIRSTHDR(msg) \
76397 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
76398 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
76399 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
76400 (struct compat_cmsghdr __user *)NULL)
76401
76402 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
76403 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
76404 (ucmlen) <= (unsigned long) \
76405 ((mhdr)->msg_controllen - \
76406 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
76407 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
76408
76409 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
76410 struct compat_cmsghdr __user *cmsg, int cmsg_len)
76411 {
76412 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
76413 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
76414 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
76415 msg->msg_controllen)
76416 return NULL;
76417 return (struct compat_cmsghdr __user *)ptr;
76418 @@ -219,7 +219,7 @@ Efault:
76419
76420 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
76421 {
76422 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76423 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76424 struct compat_cmsghdr cmhdr;
76425 struct compat_timeval ctv;
76426 struct compat_timespec cts[3];
76427 @@ -275,7 +275,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
76428
76429 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
76430 {
76431 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
76432 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
76433 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
76434 int fdnum = scm->fp->count;
76435 struct file **fp = scm->fp->fp;
76436 @@ -364,7 +364,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
76437 return -EFAULT;
76438 old_fs = get_fs();
76439 set_fs(KERNEL_DS);
76440 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
76441 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
76442 set_fs(old_fs);
76443
76444 return err;
76445 @@ -425,7 +425,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
76446 len = sizeof(ktime);
76447 old_fs = get_fs();
76448 set_fs(KERNEL_DS);
76449 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
76450 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
76451 set_fs(old_fs);
76452
76453 if (!err) {
76454 @@ -568,7 +568,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76455 case MCAST_JOIN_GROUP:
76456 case MCAST_LEAVE_GROUP:
76457 {
76458 - struct compat_group_req __user *gr32 = (void *)optval;
76459 + struct compat_group_req __user *gr32 = (void __user *)optval;
76460 struct group_req __user *kgr =
76461 compat_alloc_user_space(sizeof(struct group_req));
76462 u32 interface;
76463 @@ -589,7 +589,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76464 case MCAST_BLOCK_SOURCE:
76465 case MCAST_UNBLOCK_SOURCE:
76466 {
76467 - struct compat_group_source_req __user *gsr32 = (void *)optval;
76468 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
76469 struct group_source_req __user *kgsr = compat_alloc_user_space(
76470 sizeof(struct group_source_req));
76471 u32 interface;
76472 @@ -610,7 +610,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
76473 }
76474 case MCAST_MSFILTER:
76475 {
76476 - struct compat_group_filter __user *gf32 = (void *)optval;
76477 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76478 struct group_filter __user *kgf;
76479 u32 interface, fmode, numsrc;
76480
76481 @@ -648,7 +648,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
76482 char __user *optval, int __user *optlen,
76483 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
76484 {
76485 - struct compat_group_filter __user *gf32 = (void *)optval;
76486 + struct compat_group_filter __user *gf32 = (void __user *)optval;
76487 struct group_filter __user *kgf;
76488 int __user *koptlen;
76489 u32 interface, fmode, numsrc;
76490 @@ -797,7 +797,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
76491
76492 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
76493 return -EINVAL;
76494 - if (copy_from_user(a, args, nas[call]))
76495 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
76496 return -EFAULT;
76497 a0 = a[0];
76498 a1 = a[1];
76499 diff --git a/net/core/datagram.c b/net/core/datagram.c
76500 index ae6acf6..d5c8f66 100644
76501 --- a/net/core/datagram.c
76502 +++ b/net/core/datagram.c
76503 @@ -290,7 +290,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
76504 }
76505
76506 kfree_skb(skb);
76507 - atomic_inc(&sk->sk_drops);
76508 + atomic_inc_unchecked(&sk->sk_drops);
76509 sk_mem_reclaim_partial(sk);
76510
76511 return err;
76512 diff --git a/net/core/dev.c b/net/core/dev.c
76513 index e2215ee..b850ae4 100644
76514 --- a/net/core/dev.c
76515 +++ b/net/core/dev.c
76516 @@ -1138,9 +1138,13 @@ void dev_load(struct net *net, const char *name)
76517 if (no_module && capable(CAP_NET_ADMIN))
76518 no_module = request_module("netdev-%s", name);
76519 if (no_module && capable(CAP_SYS_MODULE)) {
76520 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
76521 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
76522 +#else
76523 if (!request_module("%s", name))
76524 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
76525 name);
76526 +#endif
76527 }
76528 }
76529 EXPORT_SYMBOL(dev_load);
76530 @@ -1605,7 +1609,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76531 {
76532 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
76533 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
76534 - atomic_long_inc(&dev->rx_dropped);
76535 + atomic_long_inc_unchecked(&dev->rx_dropped);
76536 kfree_skb(skb);
76537 return NET_RX_DROP;
76538 }
76539 @@ -1615,7 +1619,7 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
76540 nf_reset(skb);
76541
76542 if (unlikely(!is_skb_forwardable(dev, skb))) {
76543 - atomic_long_inc(&dev->rx_dropped);
76544 + atomic_long_inc_unchecked(&dev->rx_dropped);
76545 kfree_skb(skb);
76546 return NET_RX_DROP;
76547 }
76548 @@ -2056,7 +2060,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
76549
76550 struct dev_gso_cb {
76551 void (*destructor)(struct sk_buff *skb);
76552 -};
76553 +} __no_const;
76554
76555 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
76556
76557 @@ -2894,7 +2898,7 @@ enqueue:
76558
76559 local_irq_restore(flags);
76560
76561 - atomic_long_inc(&skb->dev->rx_dropped);
76562 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76563 kfree_skb(skb);
76564 return NET_RX_DROP;
76565 }
76566 @@ -2966,7 +2970,7 @@ int netif_rx_ni(struct sk_buff *skb)
76567 }
76568 EXPORT_SYMBOL(netif_rx_ni);
76569
76570 -static void net_tx_action(struct softirq_action *h)
76571 +static void net_tx_action(void)
76572 {
76573 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76574
76575 @@ -3253,7 +3257,7 @@ ncls:
76576 if (pt_prev) {
76577 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
76578 } else {
76579 - atomic_long_inc(&skb->dev->rx_dropped);
76580 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
76581 kfree_skb(skb);
76582 /* Jamal, now you will not able to escape explaining
76583 * me how you were going to use this. :-)
76584 @@ -3818,7 +3822,7 @@ void netif_napi_del(struct napi_struct *napi)
76585 }
76586 EXPORT_SYMBOL(netif_napi_del);
76587
76588 -static void net_rx_action(struct softirq_action *h)
76589 +static void net_rx_action(void)
76590 {
76591 struct softnet_data *sd = &__get_cpu_var(softnet_data);
76592 unsigned long time_limit = jiffies + 2;
76593 @@ -4288,8 +4292,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
76594 else
76595 seq_printf(seq, "%04x", ntohs(pt->type));
76596
76597 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76598 + seq_printf(seq, " %-8s %p\n",
76599 + pt->dev ? pt->dev->name : "", NULL);
76600 +#else
76601 seq_printf(seq, " %-8s %pF\n",
76602 pt->dev ? pt->dev->name : "", pt->func);
76603 +#endif
76604 }
76605
76606 return 0;
76607 @@ -5841,7 +5850,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
76608 } else {
76609 netdev_stats_to_stats64(storage, &dev->stats);
76610 }
76611 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
76612 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
76613 return storage;
76614 }
76615 EXPORT_SYMBOL(dev_get_stats);
76616 diff --git a/net/core/flow.c b/net/core/flow.c
76617 index e318c7e..168b1d0 100644
76618 --- a/net/core/flow.c
76619 +++ b/net/core/flow.c
76620 @@ -61,7 +61,7 @@ struct flow_cache {
76621 struct timer_list rnd_timer;
76622 };
76623
76624 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
76625 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
76626 EXPORT_SYMBOL(flow_cache_genid);
76627 static struct flow_cache flow_cache_global;
76628 static struct kmem_cache *flow_cachep __read_mostly;
76629 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
76630
76631 static int flow_entry_valid(struct flow_cache_entry *fle)
76632 {
76633 - if (atomic_read(&flow_cache_genid) != fle->genid)
76634 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
76635 return 0;
76636 if (fle->object && !fle->object->ops->check(fle->object))
76637 return 0;
76638 @@ -259,7 +259,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
76639 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
76640 fcp->hash_count++;
76641 }
76642 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
76643 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
76644 flo = fle->object;
76645 if (!flo)
76646 goto ret_object;
76647 @@ -280,7 +280,7 @@ nocache:
76648 }
76649 flo = resolver(net, key, family, dir, flo, ctx);
76650 if (fle) {
76651 - fle->genid = atomic_read(&flow_cache_genid);
76652 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
76653 if (!IS_ERR(flo))
76654 fle->object = flo;
76655 else
76656 diff --git a/net/core/iovec.c b/net/core/iovec.c
76657 index 7e7aeb0..2a998cb 100644
76658 --- a/net/core/iovec.c
76659 +++ b/net/core/iovec.c
76660 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76661 if (m->msg_namelen) {
76662 if (mode == VERIFY_READ) {
76663 void __user *namep;
76664 - namep = (void __user __force *) m->msg_name;
76665 + namep = (void __force_user *) m->msg_name;
76666 err = move_addr_to_kernel(namep, m->msg_namelen,
76667 address);
76668 if (err < 0)
76669 @@ -54,7 +54,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
76670 }
76671
76672 size = m->msg_iovlen * sizeof(struct iovec);
76673 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
76674 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
76675 return -EFAULT;
76676
76677 m->msg_iov = iov;
76678 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
76679 index 6c50ac0..6b4c038 100644
76680 --- a/net/core/rtnetlink.c
76681 +++ b/net/core/rtnetlink.c
76682 @@ -58,7 +58,7 @@ struct rtnl_link {
76683 rtnl_doit_func doit;
76684 rtnl_dumpit_func dumpit;
76685 rtnl_calcit_func calcit;
76686 -};
76687 +} __no_const;
76688
76689 static DEFINE_MUTEX(rtnl_mutex);
76690
76691 diff --git a/net/core/scm.c b/net/core/scm.c
76692 index 611c5ef..88f6d6d 100644
76693 --- a/net/core/scm.c
76694 +++ b/net/core/scm.c
76695 @@ -219,7 +219,7 @@ EXPORT_SYMBOL(__scm_send);
76696 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76697 {
76698 struct cmsghdr __user *cm
76699 - = (__force struct cmsghdr __user *)msg->msg_control;
76700 + = (struct cmsghdr __force_user *)msg->msg_control;
76701 struct cmsghdr cmhdr;
76702 int cmlen = CMSG_LEN(len);
76703 int err;
76704 @@ -242,7 +242,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
76705 err = -EFAULT;
76706 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
76707 goto out;
76708 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
76709 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
76710 goto out;
76711 cmlen = CMSG_SPACE(len);
76712 if (msg->msg_controllen < cmlen)
76713 @@ -258,7 +258,7 @@ EXPORT_SYMBOL(put_cmsg);
76714 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76715 {
76716 struct cmsghdr __user *cm
76717 - = (__force struct cmsghdr __user*)msg->msg_control;
76718 + = (struct cmsghdr __force_user *)msg->msg_control;
76719
76720 int fdmax = 0;
76721 int fdnum = scm->fp->count;
76722 @@ -278,7 +278,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
76723 if (fdnum < fdmax)
76724 fdmax = fdnum;
76725
76726 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
76727 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
76728 i++, cmfptr++)
76729 {
76730 int new_fd;
76731 diff --git a/net/core/sock.c b/net/core/sock.c
76732 index fcf8fdf..74437a5 100644
76733 --- a/net/core/sock.c
76734 +++ b/net/core/sock.c
76735 @@ -344,7 +344,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76736 struct sk_buff_head *list = &sk->sk_receive_queue;
76737
76738 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
76739 - atomic_inc(&sk->sk_drops);
76740 + atomic_inc_unchecked(&sk->sk_drops);
76741 trace_sock_rcvqueue_full(sk, skb);
76742 return -ENOMEM;
76743 }
76744 @@ -354,7 +354,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76745 return err;
76746
76747 if (!sk_rmem_schedule(sk, skb->truesize)) {
76748 - atomic_inc(&sk->sk_drops);
76749 + atomic_inc_unchecked(&sk->sk_drops);
76750 return -ENOBUFS;
76751 }
76752
76753 @@ -374,7 +374,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
76754 skb_dst_force(skb);
76755
76756 spin_lock_irqsave(&list->lock, flags);
76757 - skb->dropcount = atomic_read(&sk->sk_drops);
76758 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
76759 __skb_queue_tail(list, skb);
76760 spin_unlock_irqrestore(&list->lock, flags);
76761
76762 @@ -394,7 +394,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76763 skb->dev = NULL;
76764
76765 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
76766 - atomic_inc(&sk->sk_drops);
76767 + atomic_inc_unchecked(&sk->sk_drops);
76768 goto discard_and_relse;
76769 }
76770 if (nested)
76771 @@ -412,7 +412,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
76772 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
76773 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
76774 bh_unlock_sock(sk);
76775 - atomic_inc(&sk->sk_drops);
76776 + atomic_inc_unchecked(&sk->sk_drops);
76777 goto discard_and_relse;
76778 }
76779
76780 @@ -636,7 +636,8 @@ set_rcvbuf:
76781
76782 case SO_KEEPALIVE:
76783 #ifdef CONFIG_INET
76784 - if (sk->sk_protocol == IPPROTO_TCP)
76785 + if (sk->sk_protocol == IPPROTO_TCP &&
76786 + sk->sk_type == SOCK_STREAM)
76787 tcp_set_keepalive(sk, valbool);
76788 #endif
76789 sock_valbool_flag(sk, SOCK_KEEPOPEN, valbool);
76790 @@ -830,12 +831,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76791 struct timeval tm;
76792 } v;
76793
76794 - int lv = sizeof(int);
76795 - int len;
76796 + unsigned int lv = sizeof(int);
76797 + unsigned int len;
76798
76799 if (get_user(len, optlen))
76800 return -EFAULT;
76801 - if (len < 0)
76802 + if (len > INT_MAX)
76803 return -EINVAL;
76804
76805 memset(&v, 0, sizeof(v));
76806 @@ -976,18 +977,18 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76807 if (len > sizeof(peercred))
76808 len = sizeof(peercred);
76809 cred_to_ucred(sk->sk_peer_pid, sk->sk_peer_cred, &peercred);
76810 - if (copy_to_user(optval, &peercred, len))
76811 + if (len > sizeof(peercred) || copy_to_user(optval, &peercred, len))
76812 return -EFAULT;
76813 goto lenout;
76814 }
76815
76816 case SO_PEERNAME:
76817 {
76818 - char address[128];
76819 + char address[_K_SS_MAXSIZE];
76820
76821 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
76822 return -ENOTCONN;
76823 - if (lv < len)
76824 + if (lv < len || sizeof address < len)
76825 return -EINVAL;
76826 if (copy_to_user(optval, address, len))
76827 return -EFAULT;
76828 @@ -1035,7 +1036,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
76829
76830 if (len > lv)
76831 len = lv;
76832 - if (copy_to_user(optval, &v, len))
76833 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
76834 return -EFAULT;
76835 lenout:
76836 if (put_user(len, optlen))
76837 @@ -2125,7 +2126,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
76838 */
76839 smp_wmb();
76840 atomic_set(&sk->sk_refcnt, 1);
76841 - atomic_set(&sk->sk_drops, 0);
76842 + atomic_set_unchecked(&sk->sk_drops, 0);
76843 }
76844 EXPORT_SYMBOL(sock_init_data);
76845
76846 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
76847 index 5fd1467..8b70900 100644
76848 --- a/net/core/sock_diag.c
76849 +++ b/net/core/sock_diag.c
76850 @@ -16,20 +16,27 @@ static DEFINE_MUTEX(sock_diag_table_mutex);
76851
76852 int sock_diag_check_cookie(void *sk, __u32 *cookie)
76853 {
76854 +#ifndef CONFIG_GRKERNSEC_HIDESYM
76855 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
76856 cookie[1] != INET_DIAG_NOCOOKIE) &&
76857 ((u32)(unsigned long)sk != cookie[0] ||
76858 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
76859 return -ESTALE;
76860 else
76861 +#endif
76862 return 0;
76863 }
76864 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
76865
76866 void sock_diag_save_cookie(void *sk, __u32 *cookie)
76867 {
76868 +#ifdef CONFIG_GRKERNSEC_HIDESYM
76869 + cookie[0] = 0;
76870 + cookie[1] = 0;
76871 +#else
76872 cookie[0] = (u32)(unsigned long)sk;
76873 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
76874 +#endif
76875 }
76876 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
76877
76878 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
76879 index a55eecc..dd8428c 100644
76880 --- a/net/decnet/sysctl_net_decnet.c
76881 +++ b/net/decnet/sysctl_net_decnet.c
76882 @@ -174,7 +174,7 @@ static int dn_node_address_handler(ctl_table *table, int write,
76883
76884 if (len > *lenp) len = *lenp;
76885
76886 - if (copy_to_user(buffer, addr, len))
76887 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
76888 return -EFAULT;
76889
76890 *lenp = len;
76891 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(ctl_table *table, int write,
76892
76893 if (len > *lenp) len = *lenp;
76894
76895 - if (copy_to_user(buffer, devname, len))
76896 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
76897 return -EFAULT;
76898
76899 *lenp = len;
76900 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
76901 index 3854411..2201a94 100644
76902 --- a/net/ipv4/fib_frontend.c
76903 +++ b/net/ipv4/fib_frontend.c
76904 @@ -969,12 +969,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
76905 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76906 fib_sync_up(dev);
76907 #endif
76908 - atomic_inc(&net->ipv4.dev_addr_genid);
76909 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76910 rt_cache_flush(dev_net(dev), -1);
76911 break;
76912 case NETDEV_DOWN:
76913 fib_del_ifaddr(ifa, NULL);
76914 - atomic_inc(&net->ipv4.dev_addr_genid);
76915 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76916 if (ifa->ifa_dev->ifa_list == NULL) {
76917 /* Last address was deleted from this interface.
76918 * Disable IP.
76919 @@ -1010,7 +1010,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
76920 #ifdef CONFIG_IP_ROUTE_MULTIPATH
76921 fib_sync_up(dev);
76922 #endif
76923 - atomic_inc(&net->ipv4.dev_addr_genid);
76924 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
76925 rt_cache_flush(dev_net(dev), -1);
76926 break;
76927 case NETDEV_DOWN:
76928 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
76929 index e5b7182..570a90e 100644
76930 --- a/net/ipv4/fib_semantics.c
76931 +++ b/net/ipv4/fib_semantics.c
76932 @@ -698,7 +698,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
76933 nh->nh_saddr = inet_select_addr(nh->nh_dev,
76934 nh->nh_gw,
76935 nh->nh_parent->fib_scope);
76936 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
76937 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
76938
76939 return nh->nh_saddr;
76940 }
76941 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
76942 index 7880af9..70f92a3 100644
76943 --- a/net/ipv4/inet_hashtables.c
76944 +++ b/net/ipv4/inet_hashtables.c
76945 @@ -18,12 +18,15 @@
76946 #include <linux/sched.h>
76947 #include <linux/slab.h>
76948 #include <linux/wait.h>
76949 +#include <linux/security.h>
76950
76951 #include <net/inet_connection_sock.h>
76952 #include <net/inet_hashtables.h>
76953 #include <net/secure_seq.h>
76954 #include <net/ip.h>
76955
76956 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
76957 +
76958 /*
76959 * Allocate and initialize a new local port bind bucket.
76960 * The bindhash mutex for snum's hash chain must be held here.
76961 @@ -530,6 +533,8 @@ ok:
76962 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
76963 spin_unlock(&head->lock);
76964
76965 + gr_update_task_in_ip_table(current, inet_sk(sk));
76966 +
76967 if (tw) {
76968 inet_twsk_deschedule(tw, death_row);
76969 while (twrefcnt) {
76970 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
76971 index dfba343..c827d50 100644
76972 --- a/net/ipv4/inetpeer.c
76973 +++ b/net/ipv4/inetpeer.c
76974 @@ -487,8 +487,8 @@ relookup:
76975 if (p) {
76976 p->daddr = *daddr;
76977 atomic_set(&p->refcnt, 1);
76978 - atomic_set(&p->rid, 0);
76979 - atomic_set(&p->ip_id_count,
76980 + atomic_set_unchecked(&p->rid, 0);
76981 + atomic_set_unchecked(&p->ip_id_count,
76982 (daddr->family == AF_INET) ?
76983 secure_ip_id(daddr->addr.a4) :
76984 secure_ipv6_id(daddr->addr.a6));
76985 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
76986 index 9dbd3dd..0c59fb2 100644
76987 --- a/net/ipv4/ip_fragment.c
76988 +++ b/net/ipv4/ip_fragment.c
76989 @@ -318,7 +318,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
76990 return 0;
76991
76992 start = qp->rid;
76993 - end = atomic_inc_return(&peer->rid);
76994 + end = atomic_inc_return_unchecked(&peer->rid);
76995 qp->rid = end;
76996
76997 rc = qp->q.fragments && (end - start) > max;
76998 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
76999 index 0d11f23..2bb3f64 100644
77000 --- a/net/ipv4/ip_sockglue.c
77001 +++ b/net/ipv4/ip_sockglue.c
77002 @@ -1142,7 +1142,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77003 len = min_t(unsigned int, len, opt->optlen);
77004 if (put_user(len, optlen))
77005 return -EFAULT;
77006 - if (copy_to_user(optval, opt->__data, len))
77007 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
77008 + copy_to_user(optval, opt->__data, len))
77009 return -EFAULT;
77010 return 0;
77011 }
77012 @@ -1273,7 +1274,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
77013 if (sk->sk_type != SOCK_STREAM)
77014 return -ENOPROTOOPT;
77015
77016 - msg.msg_control = optval;
77017 + msg.msg_control = (void __force_kernel *)optval;
77018 msg.msg_controllen = len;
77019 msg.msg_flags = flags;
77020
77021 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
77022 index 67e8a6b..386764d 100644
77023 --- a/net/ipv4/ipconfig.c
77024 +++ b/net/ipv4/ipconfig.c
77025 @@ -321,7 +321,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
77026
77027 mm_segment_t oldfs = get_fs();
77028 set_fs(get_ds());
77029 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77030 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77031 set_fs(oldfs);
77032 return res;
77033 }
77034 @@ -332,7 +332,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
77035
77036 mm_segment_t oldfs = get_fs();
77037 set_fs(get_ds());
77038 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
77039 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
77040 set_fs(oldfs);
77041 return res;
77042 }
77043 @@ -343,7 +343,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
77044
77045 mm_segment_t oldfs = get_fs();
77046 set_fs(get_ds());
77047 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
77048 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
77049 set_fs(oldfs);
77050 return res;
77051 }
77052 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
77053 index 97e61ea..cac1bbb 100644
77054 --- a/net/ipv4/netfilter/arp_tables.c
77055 +++ b/net/ipv4/netfilter/arp_tables.c
77056 @@ -879,14 +879,14 @@ static int compat_table_info(const struct xt_table_info *info,
77057 #endif
77058
77059 static int get_info(struct net *net, void __user *user,
77060 - const int *len, int compat)
77061 + int len, int compat)
77062 {
77063 char name[XT_TABLE_MAXNAMELEN];
77064 struct xt_table *t;
77065 int ret;
77066
77067 - if (*len != sizeof(struct arpt_getinfo)) {
77068 - duprintf("length %u != %Zu\n", *len,
77069 + if (len != sizeof(struct arpt_getinfo)) {
77070 + duprintf("length %u != %Zu\n", len,
77071 sizeof(struct arpt_getinfo));
77072 return -EINVAL;
77073 }
77074 @@ -923,7 +923,7 @@ static int get_info(struct net *net, void __user *user,
77075 info.size = private->size;
77076 strcpy(info.name, name);
77077
77078 - if (copy_to_user(user, &info, *len) != 0)
77079 + if (copy_to_user(user, &info, len) != 0)
77080 ret = -EFAULT;
77081 else
77082 ret = 0;
77083 @@ -1682,7 +1682,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
77084
77085 switch (cmd) {
77086 case ARPT_SO_GET_INFO:
77087 - ret = get_info(sock_net(sk), user, len, 1);
77088 + ret = get_info(sock_net(sk), user, *len, 1);
77089 break;
77090 case ARPT_SO_GET_ENTRIES:
77091 ret = compat_get_entries(sock_net(sk), user, len);
77092 @@ -1727,7 +1727,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
77093
77094 switch (cmd) {
77095 case ARPT_SO_GET_INFO:
77096 - ret = get_info(sock_net(sk), user, len, 0);
77097 + ret = get_info(sock_net(sk), user, *len, 0);
77098 break;
77099
77100 case ARPT_SO_GET_ENTRIES:
77101 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
77102 index 170b1fd..6105b91 100644
77103 --- a/net/ipv4/netfilter/ip_tables.c
77104 +++ b/net/ipv4/netfilter/ip_tables.c
77105 @@ -1068,14 +1068,14 @@ static int compat_table_info(const struct xt_table_info *info,
77106 #endif
77107
77108 static int get_info(struct net *net, void __user *user,
77109 - const int *len, int compat)
77110 + int len, int compat)
77111 {
77112 char name[XT_TABLE_MAXNAMELEN];
77113 struct xt_table *t;
77114 int ret;
77115
77116 - if (*len != sizeof(struct ipt_getinfo)) {
77117 - duprintf("length %u != %zu\n", *len,
77118 + if (len != sizeof(struct ipt_getinfo)) {
77119 + duprintf("length %u != %zu\n", len,
77120 sizeof(struct ipt_getinfo));
77121 return -EINVAL;
77122 }
77123 @@ -1112,7 +1112,7 @@ static int get_info(struct net *net, void __user *user,
77124 info.size = private->size;
77125 strcpy(info.name, name);
77126
77127 - if (copy_to_user(user, &info, *len) != 0)
77128 + if (copy_to_user(user, &info, len) != 0)
77129 ret = -EFAULT;
77130 else
77131 ret = 0;
77132 @@ -1966,7 +1966,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77133
77134 switch (cmd) {
77135 case IPT_SO_GET_INFO:
77136 - ret = get_info(sock_net(sk), user, len, 1);
77137 + ret = get_info(sock_net(sk), user, *len, 1);
77138 break;
77139 case IPT_SO_GET_ENTRIES:
77140 ret = compat_get_entries(sock_net(sk), user, len);
77141 @@ -2013,7 +2013,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77142
77143 switch (cmd) {
77144 case IPT_SO_GET_INFO:
77145 - ret = get_info(sock_net(sk), user, len, 0);
77146 + ret = get_info(sock_net(sk), user, *len, 0);
77147 break;
77148
77149 case IPT_SO_GET_ENTRIES:
77150 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
77151 index 2c00e8b..45b3bdd 100644
77152 --- a/net/ipv4/ping.c
77153 +++ b/net/ipv4/ping.c
77154 @@ -845,7 +845,7 @@ static void ping_format_sock(struct sock *sp, struct seq_file *f,
77155 sk_rmem_alloc_get(sp),
77156 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77157 atomic_read(&sp->sk_refcnt), sp,
77158 - atomic_read(&sp->sk_drops), len);
77159 + atomic_read_unchecked(&sp->sk_drops), len);
77160 }
77161
77162 static int ping_seq_show(struct seq_file *seq, void *v)
77163 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
77164 index 4032b81..625143c 100644
77165 --- a/net/ipv4/raw.c
77166 +++ b/net/ipv4/raw.c
77167 @@ -304,7 +304,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
77168 int raw_rcv(struct sock *sk, struct sk_buff *skb)
77169 {
77170 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
77171 - atomic_inc(&sk->sk_drops);
77172 + atomic_inc_unchecked(&sk->sk_drops);
77173 kfree_skb(skb);
77174 return NET_RX_DROP;
77175 }
77176 @@ -740,16 +740,20 @@ static int raw_init(struct sock *sk)
77177
77178 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
77179 {
77180 + struct icmp_filter filter;
77181 +
77182 if (optlen > sizeof(struct icmp_filter))
77183 optlen = sizeof(struct icmp_filter);
77184 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
77185 + if (copy_from_user(&filter, optval, optlen))
77186 return -EFAULT;
77187 + raw_sk(sk)->filter = filter;
77188 return 0;
77189 }
77190
77191 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
77192 {
77193 int len, ret = -EFAULT;
77194 + struct icmp_filter filter;
77195
77196 if (get_user(len, optlen))
77197 goto out;
77198 @@ -759,8 +763,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
77199 if (len > sizeof(struct icmp_filter))
77200 len = sizeof(struct icmp_filter);
77201 ret = -EFAULT;
77202 - if (put_user(len, optlen) ||
77203 - copy_to_user(optval, &raw_sk(sk)->filter, len))
77204 + filter = raw_sk(sk)->filter;
77205 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
77206 goto out;
77207 ret = 0;
77208 out: return ret;
77209 @@ -988,7 +992,13 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77210 sk_wmem_alloc_get(sp),
77211 sk_rmem_alloc_get(sp),
77212 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77213 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77214 + atomic_read(&sp->sk_refcnt),
77215 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77216 + NULL,
77217 +#else
77218 + sp,
77219 +#endif
77220 + atomic_read_unchecked(&sp->sk_drops));
77221 }
77222
77223 static int raw_seq_show(struct seq_file *seq, void *v)
77224 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
77225 index 98b30d0..cfa3cf7 100644
77226 --- a/net/ipv4/route.c
77227 +++ b/net/ipv4/route.c
77228 @@ -313,7 +313,7 @@ static inline unsigned int rt_hash(__be32 daddr, __be32 saddr, int idx,
77229
77230 static inline int rt_genid(struct net *net)
77231 {
77232 - return atomic_read(&net->ipv4.rt_genid);
77233 + return atomic_read_unchecked(&net->ipv4.rt_genid);
77234 }
77235
77236 #ifdef CONFIG_PROC_FS
77237 @@ -937,7 +937,7 @@ static void rt_cache_invalidate(struct net *net)
77238 unsigned char shuffle;
77239
77240 get_random_bytes(&shuffle, sizeof(shuffle));
77241 - atomic_add(shuffle + 1U, &net->ipv4.rt_genid);
77242 + atomic_add_unchecked(shuffle + 1U, &net->ipv4.rt_genid);
77243 inetpeer_invalidate_tree(AF_INET);
77244 }
77245
77246 @@ -3011,7 +3011,7 @@ static int rt_fill_info(struct net *net,
77247 error = rt->dst.error;
77248 if (peer) {
77249 inet_peer_refcheck(rt->peer);
77250 - id = atomic_read(&peer->ip_id_count) & 0xffff;
77251 + id = atomic_read_unchecked(&peer->ip_id_count) & 0xffff;
77252 if (peer->tcp_ts_stamp) {
77253 ts = peer->tcp_ts;
77254 tsage = get_seconds() - peer->tcp_ts_stamp;
77255 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
77256 index 262316b..5a9f3f3 100644
77257 --- a/net/ipv4/tcp_input.c
77258 +++ b/net/ipv4/tcp_input.c
77259 @@ -4885,7 +4885,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
77260 * simplifies code)
77261 */
77262 static void
77263 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77264 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
77265 struct sk_buff *head, struct sk_buff *tail,
77266 u32 start, u32 end)
77267 {
77268 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
77269 index c8d28c4..e40f75a 100644
77270 --- a/net/ipv4/tcp_ipv4.c
77271 +++ b/net/ipv4/tcp_ipv4.c
77272 @@ -90,6 +90,10 @@ int sysctl_tcp_low_latency __read_mostly;
77273 EXPORT_SYMBOL(sysctl_tcp_low_latency);
77274
77275
77276 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77277 +extern int grsec_enable_blackhole;
77278 +#endif
77279 +
77280 #ifdef CONFIG_TCP_MD5SIG
77281 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
77282 __be32 daddr, __be32 saddr, const struct tcphdr *th);
77283 @@ -1656,6 +1660,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
77284 return 0;
77285
77286 reset:
77287 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77288 + if (!grsec_enable_blackhole)
77289 +#endif
77290 tcp_v4_send_reset(rsk, skb);
77291 discard:
77292 kfree_skb(skb);
77293 @@ -1718,12 +1725,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
77294 TCP_SKB_CB(skb)->sacked = 0;
77295
77296 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77297 - if (!sk)
77298 + if (!sk) {
77299 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77300 + ret = 1;
77301 +#endif
77302 goto no_tcp_socket;
77303 -
77304 + }
77305 process:
77306 - if (sk->sk_state == TCP_TIME_WAIT)
77307 + if (sk->sk_state == TCP_TIME_WAIT) {
77308 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77309 + ret = 2;
77310 +#endif
77311 goto do_time_wait;
77312 + }
77313
77314 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
77315 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77316 @@ -1774,6 +1788,10 @@ no_tcp_socket:
77317 bad_packet:
77318 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77319 } else {
77320 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77321 + if (!grsec_enable_blackhole || (ret == 1 &&
77322 + (skb->dev->flags & IFF_LOOPBACK)))
77323 +#endif
77324 tcp_v4_send_reset(NULL, skb);
77325 }
77326
77327 @@ -2386,7 +2404,11 @@ static void get_openreq4(const struct sock *sk, const struct request_sock *req,
77328 0, /* non standard timer */
77329 0, /* open_requests have no inode */
77330 atomic_read(&sk->sk_refcnt),
77331 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77332 + NULL,
77333 +#else
77334 req,
77335 +#endif
77336 len);
77337 }
77338
77339 @@ -2436,7 +2458,12 @@ static void get_tcp4_sock(struct sock *sk, struct seq_file *f, int i, int *len)
77340 sock_i_uid(sk),
77341 icsk->icsk_probes_out,
77342 sock_i_ino(sk),
77343 - atomic_read(&sk->sk_refcnt), sk,
77344 + atomic_read(&sk->sk_refcnt),
77345 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77346 + NULL,
77347 +#else
77348 + sk,
77349 +#endif
77350 jiffies_to_clock_t(icsk->icsk_rto),
77351 jiffies_to_clock_t(icsk->icsk_ack.ato),
77352 (icsk->icsk_ack.quick << 1) | icsk->icsk_ack.pingpong,
77353 @@ -2464,7 +2491,13 @@ static void get_timewait4_sock(const struct inet_timewait_sock *tw,
77354 " %02X %08X:%08X %02X:%08lX %08X %5d %8d %d %d %pK%n",
77355 i, src, srcp, dest, destp, tw->tw_substate, 0, 0,
77356 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77357 - atomic_read(&tw->tw_refcnt), tw, len);
77358 + atomic_read(&tw->tw_refcnt),
77359 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77360 + NULL,
77361 +#else
77362 + tw,
77363 +#endif
77364 + len);
77365 }
77366
77367 #define TMPSZ 150
77368 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
77369 index b85d9fe..4b0eed9 100644
77370 --- a/net/ipv4/tcp_minisocks.c
77371 +++ b/net/ipv4/tcp_minisocks.c
77372 @@ -27,6 +27,10 @@
77373 #include <net/inet_common.h>
77374 #include <net/xfrm.h>
77375
77376 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77377 +extern int grsec_enable_blackhole;
77378 +#endif
77379 +
77380 int sysctl_tcp_syncookies __read_mostly = 1;
77381 EXPORT_SYMBOL(sysctl_tcp_syncookies);
77382
77383 @@ -754,6 +758,10 @@ listen_overflow:
77384
77385 embryonic_reset:
77386 NET_INC_STATS_BH(sock_net(sk), LINUX_MIB_EMBRYONICRSTS);
77387 +
77388 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77389 + if (!grsec_enable_blackhole)
77390 +#endif
77391 if (!(flg & TCP_FLAG_RST))
77392 req->rsk_ops->send_reset(sk, skb);
77393
77394 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
77395 index 4526fe6..1a34e43 100644
77396 --- a/net/ipv4/tcp_probe.c
77397 +++ b/net/ipv4/tcp_probe.c
77398 @@ -204,7 +204,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
77399 if (cnt + width >= len)
77400 break;
77401
77402 - if (copy_to_user(buf + cnt, tbuf, width))
77403 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
77404 return -EFAULT;
77405 cnt += width;
77406 }
77407 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
77408 index e911e6c..d0a9356 100644
77409 --- a/net/ipv4/tcp_timer.c
77410 +++ b/net/ipv4/tcp_timer.c
77411 @@ -22,6 +22,10 @@
77412 #include <linux/gfp.h>
77413 #include <net/tcp.h>
77414
77415 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77416 +extern int grsec_lastack_retries;
77417 +#endif
77418 +
77419 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
77420 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
77421 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
77422 @@ -196,6 +200,13 @@ static int tcp_write_timeout(struct sock *sk)
77423 }
77424 }
77425
77426 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77427 + if ((sk->sk_state == TCP_LAST_ACK) &&
77428 + (grsec_lastack_retries > 0) &&
77429 + (grsec_lastack_retries < retry_until))
77430 + retry_until = grsec_lastack_retries;
77431 +#endif
77432 +
77433 if (retransmits_timed_out(sk, retry_until,
77434 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
77435 /* Has it gone just too far? */
77436 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
77437 index eaca736..60488ae 100644
77438 --- a/net/ipv4/udp.c
77439 +++ b/net/ipv4/udp.c
77440 @@ -87,6 +87,7 @@
77441 #include <linux/types.h>
77442 #include <linux/fcntl.h>
77443 #include <linux/module.h>
77444 +#include <linux/security.h>
77445 #include <linux/socket.h>
77446 #include <linux/sockios.h>
77447 #include <linux/igmp.h>
77448 @@ -110,6 +111,10 @@
77449 #include <linux/static_key.h>
77450 #include "udp_impl.h"
77451
77452 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77453 +extern int grsec_enable_blackhole;
77454 +#endif
77455 +
77456 struct udp_table udp_table __read_mostly;
77457 EXPORT_SYMBOL(udp_table);
77458
77459 @@ -568,6 +573,9 @@ found:
77460 return s;
77461 }
77462
77463 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
77464 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
77465 +
77466 /*
77467 * This routine is called by the ICMP module when it gets some
77468 * sort of error condition. If err < 0 then the socket should
77469 @@ -859,9 +867,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
77470 dport = usin->sin_port;
77471 if (dport == 0)
77472 return -EINVAL;
77473 +
77474 + err = gr_search_udp_sendmsg(sk, usin);
77475 + if (err)
77476 + return err;
77477 } else {
77478 if (sk->sk_state != TCP_ESTABLISHED)
77479 return -EDESTADDRREQ;
77480 +
77481 + err = gr_search_udp_sendmsg(sk, NULL);
77482 + if (err)
77483 + return err;
77484 +
77485 daddr = inet->inet_daddr;
77486 dport = inet->inet_dport;
77487 /* Open fast path for connected socket.
77488 @@ -1103,7 +1120,7 @@ static unsigned int first_packet_length(struct sock *sk)
77489 udp_lib_checksum_complete(skb)) {
77490 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77491 IS_UDPLITE(sk));
77492 - atomic_inc(&sk->sk_drops);
77493 + atomic_inc_unchecked(&sk->sk_drops);
77494 __skb_unlink(skb, rcvq);
77495 __skb_queue_tail(&list_kill, skb);
77496 }
77497 @@ -1189,6 +1206,10 @@ try_again:
77498 if (!skb)
77499 goto out;
77500
77501 + err = gr_search_udp_recvmsg(sk, skb);
77502 + if (err)
77503 + goto out_free;
77504 +
77505 ulen = skb->len - sizeof(struct udphdr);
77506 copied = len;
77507 if (copied > ulen)
77508 @@ -1498,7 +1519,7 @@ int udp_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77509
77510 drop:
77511 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77512 - atomic_inc(&sk->sk_drops);
77513 + atomic_inc_unchecked(&sk->sk_drops);
77514 kfree_skb(skb);
77515 return -1;
77516 }
77517 @@ -1517,7 +1538,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77518 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77519
77520 if (!skb1) {
77521 - atomic_inc(&sk->sk_drops);
77522 + atomic_inc_unchecked(&sk->sk_drops);
77523 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77524 IS_UDPLITE(sk));
77525 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77526 @@ -1686,6 +1707,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77527 goto csum_error;
77528
77529 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77530 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77531 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77532 +#endif
77533 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
77534
77535 /*
77536 @@ -2104,8 +2128,13 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
77537 sk_wmem_alloc_get(sp),
77538 sk_rmem_alloc_get(sp),
77539 0, 0L, 0, sock_i_uid(sp), 0, sock_i_ino(sp),
77540 - atomic_read(&sp->sk_refcnt), sp,
77541 - atomic_read(&sp->sk_drops), len);
77542 + atomic_read(&sp->sk_refcnt),
77543 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77544 + NULL,
77545 +#else
77546 + sp,
77547 +#endif
77548 + atomic_read_unchecked(&sp->sk_drops), len);
77549 }
77550
77551 int udp4_seq_show(struct seq_file *seq, void *v)
77552 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
77553 index 938ba6d..30c8021 100644
77554 --- a/net/ipv6/addrconf.c
77555 +++ b/net/ipv6/addrconf.c
77556 @@ -2143,7 +2143,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
77557 p.iph.ihl = 5;
77558 p.iph.protocol = IPPROTO_IPV6;
77559 p.iph.ttl = 64;
77560 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
77561 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
77562
77563 if (ops->ndo_do_ioctl) {
77564 mm_segment_t oldfs = get_fs();
77565 diff --git a/net/ipv6/esp6.c b/net/ipv6/esp6.c
77566 index db1521f..ebb3314 100644
77567 --- a/net/ipv6/esp6.c
77568 +++ b/net/ipv6/esp6.c
77569 @@ -166,8 +166,6 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
77570 struct esp_data *esp = x->data;
77571
77572 /* skb is pure payload to encrypt */
77573 - err = -ENOMEM;
77574 -
77575 aead = esp->aead;
77576 alen = crypto_aead_authsize(aead);
77577
77578 @@ -202,8 +200,10 @@ static int esp6_output(struct xfrm_state *x, struct sk_buff *skb)
77579 }
77580
77581 tmp = esp_alloc_tmp(aead, nfrags + sglists, seqhilen);
77582 - if (!tmp)
77583 + if (!tmp) {
77584 + err = -ENOMEM;
77585 goto error;
77586 + }
77587
77588 seqhi = esp_tmp_seqhi(tmp);
77589 iv = esp_tmp_iv(aead, tmp, seqhilen);
77590 diff --git a/net/ipv6/inet6_connection_sock.c b/net/ipv6/inet6_connection_sock.c
77591 index e6cee52..cf47476 100644
77592 --- a/net/ipv6/inet6_connection_sock.c
77593 +++ b/net/ipv6/inet6_connection_sock.c
77594 @@ -178,7 +178,7 @@ void __inet6_csk_dst_store(struct sock *sk, struct dst_entry *dst,
77595 #ifdef CONFIG_XFRM
77596 {
77597 struct rt6_info *rt = (struct rt6_info *)dst;
77598 - rt->rt6i_flow_cache_genid = atomic_read(&flow_cache_genid);
77599 + rt->rt6i_flow_cache_genid = atomic_read_unchecked(&flow_cache_genid);
77600 }
77601 #endif
77602 }
77603 @@ -193,7 +193,7 @@ struct dst_entry *__inet6_csk_dst_check(struct sock *sk, u32 cookie)
77604 #ifdef CONFIG_XFRM
77605 if (dst) {
77606 struct rt6_info *rt = (struct rt6_info *)dst;
77607 - if (rt->rt6i_flow_cache_genid != atomic_read(&flow_cache_genid)) {
77608 + if (rt->rt6i_flow_cache_genid != atomic_read_unchecked(&flow_cache_genid)) {
77609 __sk_dst_reset(sk);
77610 dst = NULL;
77611 }
77612 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
77613 index ba6d13d..6899122 100644
77614 --- a/net/ipv6/ipv6_sockglue.c
77615 +++ b/net/ipv6/ipv6_sockglue.c
77616 @@ -989,7 +989,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
77617 if (sk->sk_type != SOCK_STREAM)
77618 return -ENOPROTOOPT;
77619
77620 - msg.msg_control = optval;
77621 + msg.msg_control = (void __force_kernel *)optval;
77622 msg.msg_controllen = len;
77623 msg.msg_flags = flags;
77624
77625 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
77626 index d7cb045..8c0ded6 100644
77627 --- a/net/ipv6/netfilter/ip6_tables.c
77628 +++ b/net/ipv6/netfilter/ip6_tables.c
77629 @@ -1078,14 +1078,14 @@ static int compat_table_info(const struct xt_table_info *info,
77630 #endif
77631
77632 static int get_info(struct net *net, void __user *user,
77633 - const int *len, int compat)
77634 + int len, int compat)
77635 {
77636 char name[XT_TABLE_MAXNAMELEN];
77637 struct xt_table *t;
77638 int ret;
77639
77640 - if (*len != sizeof(struct ip6t_getinfo)) {
77641 - duprintf("length %u != %zu\n", *len,
77642 + if (len != sizeof(struct ip6t_getinfo)) {
77643 + duprintf("length %u != %zu\n", len,
77644 sizeof(struct ip6t_getinfo));
77645 return -EINVAL;
77646 }
77647 @@ -1122,7 +1122,7 @@ static int get_info(struct net *net, void __user *user,
77648 info.size = private->size;
77649 strcpy(info.name, name);
77650
77651 - if (copy_to_user(user, &info, *len) != 0)
77652 + if (copy_to_user(user, &info, len) != 0)
77653 ret = -EFAULT;
77654 else
77655 ret = 0;
77656 @@ -1976,7 +1976,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77657
77658 switch (cmd) {
77659 case IP6T_SO_GET_INFO:
77660 - ret = get_info(sock_net(sk), user, len, 1);
77661 + ret = get_info(sock_net(sk), user, *len, 1);
77662 break;
77663 case IP6T_SO_GET_ENTRIES:
77664 ret = compat_get_entries(sock_net(sk), user, len);
77665 @@ -2023,7 +2023,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
77666
77667 switch (cmd) {
77668 case IP6T_SO_GET_INFO:
77669 - ret = get_info(sock_net(sk), user, len, 0);
77670 + ret = get_info(sock_net(sk), user, *len, 0);
77671 break;
77672
77673 case IP6T_SO_GET_ENTRIES:
77674 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
77675 index 93d6983..8e54c4d 100644
77676 --- a/net/ipv6/raw.c
77677 +++ b/net/ipv6/raw.c
77678 @@ -377,7 +377,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
77679 {
77680 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
77681 skb_checksum_complete(skb)) {
77682 - atomic_inc(&sk->sk_drops);
77683 + atomic_inc_unchecked(&sk->sk_drops);
77684 kfree_skb(skb);
77685 return NET_RX_DROP;
77686 }
77687 @@ -405,7 +405,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77688 struct raw6_sock *rp = raw6_sk(sk);
77689
77690 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
77691 - atomic_inc(&sk->sk_drops);
77692 + atomic_inc_unchecked(&sk->sk_drops);
77693 kfree_skb(skb);
77694 return NET_RX_DROP;
77695 }
77696 @@ -429,7 +429,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
77697
77698 if (inet->hdrincl) {
77699 if (skb_checksum_complete(skb)) {
77700 - atomic_inc(&sk->sk_drops);
77701 + atomic_inc_unchecked(&sk->sk_drops);
77702 kfree_skb(skb);
77703 return NET_RX_DROP;
77704 }
77705 @@ -602,7 +602,7 @@ out:
77706 return err;
77707 }
77708
77709 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
77710 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
77711 struct flowi6 *fl6, struct dst_entry **dstp,
77712 unsigned int flags)
77713 {
77714 @@ -914,12 +914,15 @@ do_confirm:
77715 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
77716 char __user *optval, int optlen)
77717 {
77718 + struct icmp6_filter filter;
77719 +
77720 switch (optname) {
77721 case ICMPV6_FILTER:
77722 if (optlen > sizeof(struct icmp6_filter))
77723 optlen = sizeof(struct icmp6_filter);
77724 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
77725 + if (copy_from_user(&filter, optval, optlen))
77726 return -EFAULT;
77727 + raw6_sk(sk)->filter = filter;
77728 return 0;
77729 default:
77730 return -ENOPROTOOPT;
77731 @@ -932,6 +935,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77732 char __user *optval, int __user *optlen)
77733 {
77734 int len;
77735 + struct icmp6_filter filter;
77736
77737 switch (optname) {
77738 case ICMPV6_FILTER:
77739 @@ -943,7 +947,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
77740 len = sizeof(struct icmp6_filter);
77741 if (put_user(len, optlen))
77742 return -EFAULT;
77743 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
77744 + filter = raw6_sk(sk)->filter;
77745 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
77746 return -EFAULT;
77747 return 0;
77748 default:
77749 @@ -1250,7 +1255,13 @@ static void raw6_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
77750 0, 0L, 0,
77751 sock_i_uid(sp), 0,
77752 sock_i_ino(sp),
77753 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
77754 + atomic_read(&sp->sk_refcnt),
77755 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77756 + NULL,
77757 +#else
77758 + sp,
77759 +#endif
77760 + atomic_read_unchecked(&sp->sk_drops));
77761 }
77762
77763 static int raw6_seq_show(struct seq_file *seq, void *v)
77764 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
77765 index 9df64a5..39875da 100644
77766 --- a/net/ipv6/tcp_ipv6.c
77767 +++ b/net/ipv6/tcp_ipv6.c
77768 @@ -94,6 +94,10 @@ static struct tcp_md5sig_key *tcp_v6_md5_do_lookup(struct sock *sk,
77769 }
77770 #endif
77771
77772 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77773 +extern int grsec_enable_blackhole;
77774 +#endif
77775 +
77776 static void tcp_v6_hash(struct sock *sk)
77777 {
77778 if (sk->sk_state != TCP_CLOSE) {
77779 @@ -1544,6 +1548,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
77780 return 0;
77781
77782 reset:
77783 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77784 + if (!grsec_enable_blackhole)
77785 +#endif
77786 tcp_v6_send_reset(sk, skb);
77787 discard:
77788 if (opt_skb)
77789 @@ -1625,12 +1632,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
77790 TCP_SKB_CB(skb)->sacked = 0;
77791
77792 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
77793 - if (!sk)
77794 + if (!sk) {
77795 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77796 + ret = 1;
77797 +#endif
77798 goto no_tcp_socket;
77799 + }
77800
77801 process:
77802 - if (sk->sk_state == TCP_TIME_WAIT)
77803 + if (sk->sk_state == TCP_TIME_WAIT) {
77804 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77805 + ret = 2;
77806 +#endif
77807 goto do_time_wait;
77808 + }
77809
77810 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
77811 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
77812 @@ -1679,6 +1694,10 @@ no_tcp_socket:
77813 bad_packet:
77814 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
77815 } else {
77816 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77817 + if (!grsec_enable_blackhole || (ret == 1 &&
77818 + (skb->dev->flags & IFF_LOOPBACK)))
77819 +#endif
77820 tcp_v6_send_reset(NULL, skb);
77821 }
77822
77823 @@ -1885,7 +1904,13 @@ static void get_openreq6(struct seq_file *seq,
77824 uid,
77825 0, /* non standard timer */
77826 0, /* open_requests have no inode */
77827 - 0, req);
77828 + 0,
77829 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77830 + NULL
77831 +#else
77832 + req
77833 +#endif
77834 + );
77835 }
77836
77837 static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77838 @@ -1935,7 +1960,12 @@ static void get_tcp6_sock(struct seq_file *seq, struct sock *sp, int i)
77839 sock_i_uid(sp),
77840 icsk->icsk_probes_out,
77841 sock_i_ino(sp),
77842 - atomic_read(&sp->sk_refcnt), sp,
77843 + atomic_read(&sp->sk_refcnt),
77844 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77845 + NULL,
77846 +#else
77847 + sp,
77848 +#endif
77849 jiffies_to_clock_t(icsk->icsk_rto),
77850 jiffies_to_clock_t(icsk->icsk_ack.ato),
77851 (icsk->icsk_ack.quick << 1 ) | icsk->icsk_ack.pingpong,
77852 @@ -1970,7 +2000,13 @@ static void get_timewait6_sock(struct seq_file *seq,
77853 dest->s6_addr32[2], dest->s6_addr32[3], destp,
77854 tw->tw_substate, 0, 0,
77855 3, jiffies_to_clock_t(ttd), 0, 0, 0, 0,
77856 - atomic_read(&tw->tw_refcnt), tw);
77857 + atomic_read(&tw->tw_refcnt),
77858 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77859 + NULL
77860 +#else
77861 + tw
77862 +#endif
77863 + );
77864 }
77865
77866 static int tcp6_seq_show(struct seq_file *seq, void *v)
77867 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
77868 index f05099f..ea613f0 100644
77869 --- a/net/ipv6/udp.c
77870 +++ b/net/ipv6/udp.c
77871 @@ -50,6 +50,10 @@
77872 #include <linux/seq_file.h>
77873 #include "udp_impl.h"
77874
77875 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77876 +extern int grsec_enable_blackhole;
77877 +#endif
77878 +
77879 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
77880 {
77881 const struct in6_addr *sk_rcv_saddr6 = &inet6_sk(sk)->rcv_saddr;
77882 @@ -615,7 +619,7 @@ int udpv6_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
77883 return rc;
77884 drop:
77885 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
77886 - atomic_inc(&sk->sk_drops);
77887 + atomic_inc_unchecked(&sk->sk_drops);
77888 kfree_skb(skb);
77889 return -1;
77890 }
77891 @@ -673,7 +677,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
77892 if (likely(skb1 == NULL))
77893 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
77894 if (!skb1) {
77895 - atomic_inc(&sk->sk_drops);
77896 + atomic_inc_unchecked(&sk->sk_drops);
77897 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
77898 IS_UDPLITE(sk));
77899 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
77900 @@ -844,6 +848,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
77901 goto discard;
77902
77903 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
77904 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
77905 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
77906 +#endif
77907 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
77908
77909 kfree_skb(skb);
77910 @@ -1453,8 +1460,13 @@ static void udp6_sock_seq_show(struct seq_file *seq, struct sock *sp, int bucket
77911 0, 0L, 0,
77912 sock_i_uid(sp), 0,
77913 sock_i_ino(sp),
77914 - atomic_read(&sp->sk_refcnt), sp,
77915 - atomic_read(&sp->sk_drops));
77916 + atomic_read(&sp->sk_refcnt),
77917 +#ifdef CONFIG_GRKERNSEC_HIDESYM
77918 + NULL,
77919 +#else
77920 + sp,
77921 +#endif
77922 + atomic_read_unchecked(&sp->sk_drops));
77923 }
77924
77925 int udp6_seq_show(struct seq_file *seq, void *v)
77926 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
77927 index 6b9d5a0..4dffaf1 100644
77928 --- a/net/irda/ircomm/ircomm_tty.c
77929 +++ b/net/irda/ircomm/ircomm_tty.c
77930 @@ -281,16 +281,16 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77931 add_wait_queue(&self->open_wait, &wait);
77932
77933 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
77934 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77935 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77936
77937 /* As far as I can see, we protect open_count - Jean II */
77938 spin_lock_irqsave(&self->spinlock, flags);
77939 if (!tty_hung_up_p(filp)) {
77940 extra_count = 1;
77941 - self->open_count--;
77942 + local_dec(&self->open_count);
77943 }
77944 spin_unlock_irqrestore(&self->spinlock, flags);
77945 - self->blocked_open++;
77946 + local_inc(&self->blocked_open);
77947
77948 while (1) {
77949 if (tty->termios->c_cflag & CBAUD) {
77950 @@ -330,7 +330,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77951 }
77952
77953 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
77954 - __FILE__,__LINE__, tty->driver->name, self->open_count );
77955 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count) );
77956
77957 schedule();
77958 }
77959 @@ -341,13 +341,13 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
77960 if (extra_count) {
77961 /* ++ is not atomic, so this should be protected - Jean II */
77962 spin_lock_irqsave(&self->spinlock, flags);
77963 - self->open_count++;
77964 + local_inc(&self->open_count);
77965 spin_unlock_irqrestore(&self->spinlock, flags);
77966 }
77967 - self->blocked_open--;
77968 + local_dec(&self->blocked_open);
77969
77970 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
77971 - __FILE__,__LINE__, tty->driver->name, self->open_count);
77972 + __FILE__,__LINE__, tty->driver->name, local_read(&self->open_count));
77973
77974 if (!retval)
77975 self->flags |= ASYNC_NORMAL_ACTIVE;
77976 @@ -412,14 +412,14 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
77977 }
77978 /* ++ is not atomic, so this should be protected - Jean II */
77979 spin_lock_irqsave(&self->spinlock, flags);
77980 - self->open_count++;
77981 + local_inc(&self->open_count);
77982
77983 tty->driver_data = self;
77984 self->tty = tty;
77985 spin_unlock_irqrestore(&self->spinlock, flags);
77986
77987 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
77988 - self->line, self->open_count);
77989 + self->line, local_read(&self->open_count));
77990
77991 /* Not really used by us, but lets do it anyway */
77992 self->tty->low_latency = (self->flags & ASYNC_LOW_LATENCY) ? 1 : 0;
77993 @@ -505,7 +505,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
77994 return;
77995 }
77996
77997 - if ((tty->count == 1) && (self->open_count != 1)) {
77998 + if ((tty->count == 1) && (local_read(&self->open_count) != 1)) {
77999 /*
78000 * Uh, oh. tty->count is 1, which means that the tty
78001 * structure will be freed. state->count should always
78002 @@ -515,16 +515,16 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78003 */
78004 IRDA_DEBUG(0, "%s(), bad serial port count; "
78005 "tty->count is 1, state->count is %d\n", __func__ ,
78006 - self->open_count);
78007 - self->open_count = 1;
78008 + local_read(&self->open_count));
78009 + local_set(&self->open_count, 1);
78010 }
78011
78012 - if (--self->open_count < 0) {
78013 + if (local_dec_return(&self->open_count) < 0) {
78014 IRDA_ERROR("%s(), bad serial port count for ttys%d: %d\n",
78015 - __func__, self->line, self->open_count);
78016 - self->open_count = 0;
78017 + __func__, self->line, local_read(&self->open_count));
78018 + local_set(&self->open_count, 0);
78019 }
78020 - if (self->open_count) {
78021 + if (local_read(&self->open_count)) {
78022 spin_unlock_irqrestore(&self->spinlock, flags);
78023
78024 IRDA_DEBUG(0, "%s(), open count > 0\n", __func__ );
78025 @@ -556,7 +556,7 @@ static void ircomm_tty_close(struct tty_struct *tty, struct file *filp)
78026 tty->closing = 0;
78027 self->tty = NULL;
78028
78029 - if (self->blocked_open) {
78030 + if (local_read(&self->blocked_open)) {
78031 if (self->close_delay)
78032 schedule_timeout_interruptible(self->close_delay);
78033 wake_up_interruptible(&self->open_wait);
78034 @@ -1008,7 +1008,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
78035 spin_lock_irqsave(&self->spinlock, flags);
78036 self->flags &= ~ASYNC_NORMAL_ACTIVE;
78037 self->tty = NULL;
78038 - self->open_count = 0;
78039 + local_set(&self->open_count, 0);
78040 spin_unlock_irqrestore(&self->spinlock, flags);
78041
78042 wake_up_interruptible(&self->open_wait);
78043 @@ -1355,7 +1355,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
78044 seq_putc(m, '\n');
78045
78046 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
78047 - seq_printf(m, "Open count: %d\n", self->open_count);
78048 + seq_printf(m, "Open count: %d\n", local_read(&self->open_count));
78049 seq_printf(m, "Max data size: %d\n", self->max_data_size);
78050 seq_printf(m, "Max header size: %d\n", self->max_header_size);
78051
78052 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
78053 index cd6f7a9..e63fe89 100644
78054 --- a/net/iucv/af_iucv.c
78055 +++ b/net/iucv/af_iucv.c
78056 @@ -782,10 +782,10 @@ static int iucv_sock_autobind(struct sock *sk)
78057
78058 write_lock_bh(&iucv_sk_list.lock);
78059
78060 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
78061 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78062 while (__iucv_get_sock_by_name(name)) {
78063 sprintf(name, "%08x",
78064 - atomic_inc_return(&iucv_sk_list.autobind_name));
78065 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
78066 }
78067
78068 write_unlock_bh(&iucv_sk_list.lock);
78069 diff --git a/net/key/af_key.c b/net/key/af_key.c
78070 index 34e4185..8823368 100644
78071 --- a/net/key/af_key.c
78072 +++ b/net/key/af_key.c
78073 @@ -3016,10 +3016,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
78074 static u32 get_acqseq(void)
78075 {
78076 u32 res;
78077 - static atomic_t acqseq;
78078 + static atomic_unchecked_t acqseq;
78079
78080 do {
78081 - res = atomic_inc_return(&acqseq);
78082 + res = atomic_inc_return_unchecked(&acqseq);
78083 } while (!res);
78084 return res;
78085 }
78086 diff --git a/net/l2tp/l2tp_netlink.c b/net/l2tp/l2tp_netlink.c
78087 index ddc553e..1937a14 100644
78088 --- a/net/l2tp/l2tp_netlink.c
78089 +++ b/net/l2tp/l2tp_netlink.c
78090 @@ -80,8 +80,8 @@ static int l2tp_nl_cmd_noop(struct sk_buff *skb, struct genl_info *info)
78091
78092 hdr = genlmsg_put(msg, info->snd_pid, info->snd_seq,
78093 &l2tp_nl_family, 0, L2TP_CMD_NOOP);
78094 - if (IS_ERR(hdr)) {
78095 - ret = PTR_ERR(hdr);
78096 + if (!hdr) {
78097 + ret = -EMSGSIZE;
78098 goto err_out;
78099 }
78100
78101 @@ -250,8 +250,8 @@ static int l2tp_nl_tunnel_send(struct sk_buff *skb, u32 pid, u32 seq, int flags,
78102
78103 hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags,
78104 L2TP_CMD_TUNNEL_GET);
78105 - if (IS_ERR(hdr))
78106 - return PTR_ERR(hdr);
78107 + if (!hdr)
78108 + return -EMSGSIZE;
78109
78110 if (nla_put_u8(skb, L2TP_ATTR_PROTO_VERSION, tunnel->version) ||
78111 nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
78112 @@ -617,8 +617,8 @@ static int l2tp_nl_session_send(struct sk_buff *skb, u32 pid, u32 seq, int flags
78113 sk = tunnel->sock;
78114
78115 hdr = genlmsg_put(skb, pid, seq, &l2tp_nl_family, flags, L2TP_CMD_SESSION_GET);
78116 - if (IS_ERR(hdr))
78117 - return PTR_ERR(hdr);
78118 + if (!hdr)
78119 + return -EMSGSIZE;
78120
78121 if (nla_put_u32(skb, L2TP_ATTR_CONN_ID, tunnel->tunnel_id) ||
78122 nla_put_u32(skb, L2TP_ATTR_SESSION_ID, session->session_id) ||
78123 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
78124 index 3f3cd50..d2cf249 100644
78125 --- a/net/mac80211/ieee80211_i.h
78126 +++ b/net/mac80211/ieee80211_i.h
78127 @@ -28,6 +28,7 @@
78128 #include <net/ieee80211_radiotap.h>
78129 #include <net/cfg80211.h>
78130 #include <net/mac80211.h>
78131 +#include <asm/local.h>
78132 #include "key.h"
78133 #include "sta_info.h"
78134
78135 @@ -863,7 +864,7 @@ struct ieee80211_local {
78136 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
78137 spinlock_t queue_stop_reason_lock;
78138
78139 - int open_count;
78140 + local_t open_count;
78141 int monitors, cooked_mntrs;
78142 /* number of interfaces with corresponding FIF_ flags */
78143 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
78144 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
78145 index 8664111..1d6a065 100644
78146 --- a/net/mac80211/iface.c
78147 +++ b/net/mac80211/iface.c
78148 @@ -328,7 +328,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78149 break;
78150 }
78151
78152 - if (local->open_count == 0) {
78153 + if (local_read(&local->open_count) == 0) {
78154 res = drv_start(local);
78155 if (res)
78156 goto err_del_bss;
78157 @@ -371,7 +371,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78158 break;
78159 }
78160
78161 - if (local->monitors == 0 && local->open_count == 0) {
78162 + if (local->monitors == 0 && local_read(&local->open_count) == 0) {
78163 res = ieee80211_add_virtual_monitor(local);
78164 if (res)
78165 goto err_stop;
78166 @@ -468,7 +468,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78167 mutex_unlock(&local->mtx);
78168
78169 if (coming_up)
78170 - local->open_count++;
78171 + local_inc(&local->open_count);
78172
78173 if (hw_reconf_flags)
78174 ieee80211_hw_config(local, hw_reconf_flags);
78175 @@ -481,7 +481,7 @@ static int ieee80211_do_open(struct net_device *dev, bool coming_up)
78176 err_del_interface:
78177 drv_remove_interface(local, sdata);
78178 err_stop:
78179 - if (!local->open_count)
78180 + if (!local_read(&local->open_count))
78181 drv_stop(local);
78182 err_del_bss:
78183 sdata->bss = NULL;
78184 @@ -613,7 +613,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78185 }
78186
78187 if (going_down)
78188 - local->open_count--;
78189 + local_dec(&local->open_count);
78190
78191 switch (sdata->vif.type) {
78192 case NL80211_IFTYPE_AP_VLAN:
78193 @@ -685,7 +685,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78194
78195 ieee80211_recalc_ps(local, -1);
78196
78197 - if (local->open_count == 0) {
78198 + if (local_read(&local->open_count) == 0) {
78199 if (local->ops->napi_poll)
78200 napi_disable(&local->napi);
78201 ieee80211_clear_tx_pending(local);
78202 @@ -717,7 +717,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
78203 }
78204 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
78205
78206 - if (local->monitors == local->open_count && local->monitors > 0)
78207 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
78208 ieee80211_add_virtual_monitor(local);
78209 }
78210
78211 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
78212 index f5548e9..474a15f 100644
78213 --- a/net/mac80211/main.c
78214 +++ b/net/mac80211/main.c
78215 @@ -166,7 +166,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
78216 local->hw.conf.power_level = power;
78217 }
78218
78219 - if (changed && local->open_count) {
78220 + if (changed && local_read(&local->open_count)) {
78221 ret = drv_config(local, changed);
78222 /*
78223 * Goal:
78224 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
78225 index af1c4e2..24dbbe3 100644
78226 --- a/net/mac80211/pm.c
78227 +++ b/net/mac80211/pm.c
78228 @@ -34,7 +34,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78229 struct ieee80211_sub_if_data *sdata;
78230 struct sta_info *sta;
78231
78232 - if (!local->open_count)
78233 + if (!local_read(&local->open_count))
78234 goto suspend;
78235
78236 ieee80211_scan_cancel(local);
78237 @@ -72,7 +72,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78238 cancel_work_sync(&local->dynamic_ps_enable_work);
78239 del_timer_sync(&local->dynamic_ps_timer);
78240
78241 - local->wowlan = wowlan && local->open_count;
78242 + local->wowlan = wowlan && local_read(&local->open_count);
78243 if (local->wowlan) {
78244 int err = drv_suspend(local, wowlan);
78245 if (err < 0) {
78246 @@ -132,7 +132,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
78247 drv_remove_interface(local, sdata);
78248
78249 /* stop hardware - this must stop RX */
78250 - if (local->open_count)
78251 + if (local_read(&local->open_count))
78252 ieee80211_stop_device(local);
78253
78254 suspend:
78255 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
78256 index 3313c11..bec9f17 100644
78257 --- a/net/mac80211/rate.c
78258 +++ b/net/mac80211/rate.c
78259 @@ -494,7 +494,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
78260
78261 ASSERT_RTNL();
78262
78263 - if (local->open_count)
78264 + if (local_read(&local->open_count))
78265 return -EBUSY;
78266
78267 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
78268 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
78269 index c97a065..ff61928 100644
78270 --- a/net/mac80211/rc80211_pid_debugfs.c
78271 +++ b/net/mac80211/rc80211_pid_debugfs.c
78272 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
78273
78274 spin_unlock_irqrestore(&events->lock, status);
78275
78276 - if (copy_to_user(buf, pb, p))
78277 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
78278 return -EFAULT;
78279
78280 return p;
78281 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
78282 index f564b5e..22fee47 100644
78283 --- a/net/mac80211/util.c
78284 +++ b/net/mac80211/util.c
78285 @@ -1224,7 +1224,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
78286 }
78287 #endif
78288 /* everything else happens only if HW was up & running */
78289 - if (!local->open_count)
78290 + if (!local_read(&local->open_count))
78291 goto wake_up;
78292
78293 /*
78294 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
78295 index 209c1ed..39484dc 100644
78296 --- a/net/netfilter/Kconfig
78297 +++ b/net/netfilter/Kconfig
78298 @@ -851,6 +851,16 @@ config NETFILTER_XT_MATCH_ESP
78299
78300 To compile it as a module, choose M here. If unsure, say N.
78301
78302 +config NETFILTER_XT_MATCH_GRADM
78303 + tristate '"gradm" match support'
78304 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
78305 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
78306 + ---help---
78307 + The gradm match allows to match on grsecurity RBAC being enabled.
78308 + It is useful when iptables rules are applied early on bootup to
78309 + prevent connections to the machine (except from a trusted host)
78310 + while the RBAC system is disabled.
78311 +
78312 config NETFILTER_XT_MATCH_HASHLIMIT
78313 tristate '"hashlimit" match support'
78314 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
78315 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
78316 index 4e7960c..89e48d4 100644
78317 --- a/net/netfilter/Makefile
78318 +++ b/net/netfilter/Makefile
78319 @@ -87,6 +87,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
78320 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
78321 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
78322 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
78323 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
78324 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
78325 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
78326 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
78327 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
78328 index 1548df9..98ad9b4 100644
78329 --- a/net/netfilter/ipvs/ip_vs_conn.c
78330 +++ b/net/netfilter/ipvs/ip_vs_conn.c
78331 @@ -557,7 +557,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
78332 /* Increase the refcnt counter of the dest */
78333 atomic_inc(&dest->refcnt);
78334
78335 - conn_flags = atomic_read(&dest->conn_flags);
78336 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
78337 if (cp->protocol != IPPROTO_UDP)
78338 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
78339 flags = cp->flags;
78340 @@ -902,7 +902,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
78341 atomic_set(&cp->refcnt, 1);
78342
78343 atomic_set(&cp->n_control, 0);
78344 - atomic_set(&cp->in_pkts, 0);
78345 + atomic_set_unchecked(&cp->in_pkts, 0);
78346
78347 atomic_inc(&ipvs->conn_count);
78348 if (flags & IP_VS_CONN_F_NO_CPORT)
78349 @@ -1183,7 +1183,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
78350
78351 /* Don't drop the entry if its number of incoming packets is not
78352 located in [0, 8] */
78353 - i = atomic_read(&cp->in_pkts);
78354 + i = atomic_read_unchecked(&cp->in_pkts);
78355 if (i > 8 || i < 0) return 0;
78356
78357 if (!todrop_rate[i]) return 0;
78358 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
78359 index a54b018c..07e0120 100644
78360 --- a/net/netfilter/ipvs/ip_vs_core.c
78361 +++ b/net/netfilter/ipvs/ip_vs_core.c
78362 @@ -562,7 +562,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
78363 ret = cp->packet_xmit(skb, cp, pd->pp);
78364 /* do not touch skb anymore */
78365
78366 - atomic_inc(&cp->in_pkts);
78367 + atomic_inc_unchecked(&cp->in_pkts);
78368 ip_vs_conn_put(cp);
78369 return ret;
78370 }
78371 @@ -1611,7 +1611,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
78372 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
78373 pkts = sysctl_sync_threshold(ipvs);
78374 else
78375 - pkts = atomic_add_return(1, &cp->in_pkts);
78376 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78377
78378 if (ipvs->sync_state & IP_VS_STATE_MASTER)
78379 ip_vs_sync_conn(net, cp, pkts);
78380 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
78381 index 72bf32a..f91c066 100644
78382 --- a/net/netfilter/ipvs/ip_vs_ctl.c
78383 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
78384 @@ -788,7 +788,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
78385 ip_vs_rs_hash(ipvs, dest);
78386 write_unlock_bh(&ipvs->rs_lock);
78387 }
78388 - atomic_set(&dest->conn_flags, conn_flags);
78389 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
78390
78391 /* bind the service */
78392 if (!dest->svc) {
78393 @@ -2074,7 +2074,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78394 " %-7s %-6d %-10d %-10d\n",
78395 &dest->addr.in6,
78396 ntohs(dest->port),
78397 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78398 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78399 atomic_read(&dest->weight),
78400 atomic_read(&dest->activeconns),
78401 atomic_read(&dest->inactconns));
78402 @@ -2085,7 +2085,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
78403 "%-7s %-6d %-10d %-10d\n",
78404 ntohl(dest->addr.ip),
78405 ntohs(dest->port),
78406 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
78407 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
78408 atomic_read(&dest->weight),
78409 atomic_read(&dest->activeconns),
78410 atomic_read(&dest->inactconns));
78411 @@ -2555,7 +2555,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
78412
78413 entry.addr = dest->addr.ip;
78414 entry.port = dest->port;
78415 - entry.conn_flags = atomic_read(&dest->conn_flags);
78416 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
78417 entry.weight = atomic_read(&dest->weight);
78418 entry.u_threshold = dest->u_threshold;
78419 entry.l_threshold = dest->l_threshold;
78420 @@ -3090,7 +3090,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
78421 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
78422 nla_put_u16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
78423 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
78424 - (atomic_read(&dest->conn_flags) &
78425 + (atomic_read_unchecked(&dest->conn_flags) &
78426 IP_VS_CONN_F_FWD_MASK)) ||
78427 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
78428 atomic_read(&dest->weight)) ||
78429 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
78430 index effa10c..9058928 100644
78431 --- a/net/netfilter/ipvs/ip_vs_sync.c
78432 +++ b/net/netfilter/ipvs/ip_vs_sync.c
78433 @@ -596,7 +596,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
78434 cp = cp->control;
78435 if (cp) {
78436 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78437 - pkts = atomic_add_return(1, &cp->in_pkts);
78438 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78439 else
78440 pkts = sysctl_sync_threshold(ipvs);
78441 ip_vs_sync_conn(net, cp->control, pkts);
78442 @@ -758,7 +758,7 @@ control:
78443 if (!cp)
78444 return;
78445 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
78446 - pkts = atomic_add_return(1, &cp->in_pkts);
78447 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
78448 else
78449 pkts = sysctl_sync_threshold(ipvs);
78450 goto sloop;
78451 @@ -885,7 +885,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
78452
78453 if (opt)
78454 memcpy(&cp->in_seq, opt, sizeof(*opt));
78455 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78456 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
78457 cp->state = state;
78458 cp->old_state = cp->state;
78459 /*
78460 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
78461 index 7fd66de..e6fb361 100644
78462 --- a/net/netfilter/ipvs/ip_vs_xmit.c
78463 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
78464 @@ -1151,7 +1151,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
78465 else
78466 rc = NF_ACCEPT;
78467 /* do not touch skb anymore */
78468 - atomic_inc(&cp->in_pkts);
78469 + atomic_inc_unchecked(&cp->in_pkts);
78470 goto out;
78471 }
78472
78473 @@ -1272,7 +1272,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
78474 else
78475 rc = NF_ACCEPT;
78476 /* do not touch skb anymore */
78477 - atomic_inc(&cp->in_pkts);
78478 + atomic_inc_unchecked(&cp->in_pkts);
78479 goto out;
78480 }
78481
78482 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
78483 index ac3af97..c134c21 100644
78484 --- a/net/netfilter/nf_conntrack_core.c
78485 +++ b/net/netfilter/nf_conntrack_core.c
78486 @@ -1530,6 +1530,10 @@ err_proto:
78487 #define UNCONFIRMED_NULLS_VAL ((1<<30)+0)
78488 #define DYING_NULLS_VAL ((1<<30)+1)
78489
78490 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78491 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
78492 +#endif
78493 +
78494 static int nf_conntrack_init_net(struct net *net)
78495 {
78496 int ret;
78497 @@ -1543,7 +1547,11 @@ static int nf_conntrack_init_net(struct net *net)
78498 goto err_stat;
78499 }
78500
78501 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78502 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
78503 +#else
78504 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
78505 +#endif
78506 if (!net->ct.slabname) {
78507 ret = -ENOMEM;
78508 goto err_slabname;
78509 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
78510 index 3c3cfc0..7a6ea1a 100644
78511 --- a/net/netfilter/nfnetlink_log.c
78512 +++ b/net/netfilter/nfnetlink_log.c
78513 @@ -70,7 +70,7 @@ struct nfulnl_instance {
78514 };
78515
78516 static DEFINE_SPINLOCK(instances_lock);
78517 -static atomic_t global_seq;
78518 +static atomic_unchecked_t global_seq;
78519
78520 #define INSTANCE_BUCKETS 16
78521 static struct hlist_head instance_table[INSTANCE_BUCKETS];
78522 @@ -517,7 +517,7 @@ __build_packet_message(struct nfulnl_instance *inst,
78523 /* global sequence number */
78524 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
78525 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
78526 - htonl(atomic_inc_return(&global_seq))))
78527 + htonl(atomic_inc_return_unchecked(&global_seq))))
78528 goto nla_put_failure;
78529
78530 if (data_len) {
78531 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
78532 new file mode 100644
78533 index 0000000..6905327
78534 --- /dev/null
78535 +++ b/net/netfilter/xt_gradm.c
78536 @@ -0,0 +1,51 @@
78537 +/*
78538 + * gradm match for netfilter
78539 + * Copyright © Zbigniew Krzystolik, 2010
78540 + *
78541 + * This program is free software; you can redistribute it and/or modify
78542 + * it under the terms of the GNU General Public License; either version
78543 + * 2 or 3 as published by the Free Software Foundation.
78544 + */
78545 +#include <linux/module.h>
78546 +#include <linux/moduleparam.h>
78547 +#include <linux/skbuff.h>
78548 +#include <linux/netfilter/x_tables.h>
78549 +#include <linux/grsecurity.h>
78550 +#include <linux/netfilter/xt_gradm.h>
78551 +
78552 +static bool
78553 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
78554 +{
78555 + const struct xt_gradm_mtinfo *info = par->matchinfo;
78556 + bool retval = false;
78557 + if (gr_acl_is_enabled())
78558 + retval = true;
78559 + return retval ^ info->invflags;
78560 +}
78561 +
78562 +static struct xt_match gradm_mt_reg __read_mostly = {
78563 + .name = "gradm",
78564 + .revision = 0,
78565 + .family = NFPROTO_UNSPEC,
78566 + .match = gradm_mt,
78567 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
78568 + .me = THIS_MODULE,
78569 +};
78570 +
78571 +static int __init gradm_mt_init(void)
78572 +{
78573 + return xt_register_match(&gradm_mt_reg);
78574 +}
78575 +
78576 +static void __exit gradm_mt_exit(void)
78577 +{
78578 + xt_unregister_match(&gradm_mt_reg);
78579 +}
78580 +
78581 +module_init(gradm_mt_init);
78582 +module_exit(gradm_mt_exit);
78583 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
78584 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
78585 +MODULE_LICENSE("GPL");
78586 +MODULE_ALIAS("ipt_gradm");
78587 +MODULE_ALIAS("ip6t_gradm");
78588 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
78589 index 4fe4fb4..87a89e5 100644
78590 --- a/net/netfilter/xt_statistic.c
78591 +++ b/net/netfilter/xt_statistic.c
78592 @@ -19,7 +19,7 @@
78593 #include <linux/module.h>
78594
78595 struct xt_statistic_priv {
78596 - atomic_t count;
78597 + atomic_unchecked_t count;
78598 } ____cacheline_aligned_in_smp;
78599
78600 MODULE_LICENSE("GPL");
78601 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
78602 break;
78603 case XT_STATISTIC_MODE_NTH:
78604 do {
78605 - oval = atomic_read(&info->master->count);
78606 + oval = atomic_read_unchecked(&info->master->count);
78607 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
78608 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
78609 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
78610 if (nval == 0)
78611 ret = !ret;
78612 break;
78613 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
78614 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
78615 if (info->master == NULL)
78616 return -ENOMEM;
78617 - atomic_set(&info->master->count, info->u.nth.count);
78618 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
78619
78620 return 0;
78621 }
78622 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
78623 index 20b32fd..e717db9 100644
78624 --- a/net/netlink/af_netlink.c
78625 +++ b/net/netlink/af_netlink.c
78626 @@ -753,7 +753,7 @@ static void netlink_overrun(struct sock *sk)
78627 sk->sk_error_report(sk);
78628 }
78629 }
78630 - atomic_inc(&sk->sk_drops);
78631 + atomic_inc_unchecked(&sk->sk_drops);
78632 }
78633
78634 static struct sock *netlink_getsockbypid(struct sock *ssk, u32 pid)
78635 @@ -2023,7 +2023,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
78636 sk_wmem_alloc_get(s),
78637 nlk->cb,
78638 atomic_read(&s->sk_refcnt),
78639 - atomic_read(&s->sk_drops),
78640 + atomic_read_unchecked(&s->sk_drops),
78641 sock_i_ino(s)
78642 );
78643
78644 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
78645 index 06592d8..64860f6 100644
78646 --- a/net/netrom/af_netrom.c
78647 +++ b/net/netrom/af_netrom.c
78648 @@ -838,6 +838,7 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78649 struct sock *sk = sock->sk;
78650 struct nr_sock *nr = nr_sk(sk);
78651
78652 + memset(sax, 0, sizeof(*sax));
78653 lock_sock(sk);
78654 if (peer != 0) {
78655 if (sk->sk_state != TCP_ESTABLISHED) {
78656 @@ -852,7 +853,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
78657 *uaddr_len = sizeof(struct full_sockaddr_ax25);
78658 } else {
78659 sax->fsa_ax25.sax25_family = AF_NETROM;
78660 - sax->fsa_ax25.sax25_ndigis = 0;
78661 sax->fsa_ax25.sax25_call = nr->source_addr;
78662 *uaddr_len = sizeof(struct sockaddr_ax25);
78663 }
78664 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
78665 index 901cffd..7dfd21b 100644
78666 --- a/net/packet/af_packet.c
78667 +++ b/net/packet/af_packet.c
78668 @@ -1696,7 +1696,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78669
78670 spin_lock(&sk->sk_receive_queue.lock);
78671 po->stats.tp_packets++;
78672 - skb->dropcount = atomic_read(&sk->sk_drops);
78673 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
78674 __skb_queue_tail(&sk->sk_receive_queue, skb);
78675 spin_unlock(&sk->sk_receive_queue.lock);
78676 sk->sk_data_ready(sk, skb->len);
78677 @@ -1705,7 +1705,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
78678 drop_n_acct:
78679 spin_lock(&sk->sk_receive_queue.lock);
78680 po->stats.tp_drops++;
78681 - atomic_inc(&sk->sk_drops);
78682 + atomic_inc_unchecked(&sk->sk_drops);
78683 spin_unlock(&sk->sk_receive_queue.lock);
78684
78685 drop_n_restore:
78686 @@ -2649,6 +2649,7 @@ out:
78687
78688 static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78689 {
78690 + struct sock_extended_err ee;
78691 struct sock_exterr_skb *serr;
78692 struct sk_buff *skb, *skb2;
78693 int copied, err;
78694 @@ -2670,8 +2671,9 @@ static int packet_recv_error(struct sock *sk, struct msghdr *msg, int len)
78695 sock_recv_timestamp(msg, sk, skb);
78696
78697 serr = SKB_EXT_ERR(skb);
78698 + ee = serr->ee;
78699 put_cmsg(msg, SOL_PACKET, PACKET_TX_TIMESTAMP,
78700 - sizeof(serr->ee), &serr->ee);
78701 + sizeof ee, &ee);
78702
78703 msg->msg_flags |= MSG_ERRQUEUE;
78704 err = copied;
78705 @@ -3283,7 +3285,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78706 case PACKET_HDRLEN:
78707 if (len > sizeof(int))
78708 len = sizeof(int);
78709 - if (copy_from_user(&val, optval, len))
78710 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
78711 return -EFAULT;
78712 switch (val) {
78713 case TPACKET_V1:
78714 @@ -3322,7 +3324,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
78715 len = lv;
78716 if (put_user(len, optlen))
78717 return -EFAULT;
78718 - if (copy_to_user(optval, data, len))
78719 + if (len > sizeof(st) || copy_to_user(optval, data, len))
78720 return -EFAULT;
78721 return 0;
78722 }
78723 diff --git a/net/phonet/af_phonet.c b/net/phonet/af_phonet.c
78724 index 5a940db..f0b9c12 100644
78725 --- a/net/phonet/af_phonet.c
78726 +++ b/net/phonet/af_phonet.c
78727 @@ -41,7 +41,7 @@ static struct phonet_protocol *phonet_proto_get(unsigned int protocol)
78728 {
78729 struct phonet_protocol *pp;
78730
78731 - if (protocol >= PHONET_NPROTO)
78732 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78733 return NULL;
78734
78735 rcu_read_lock();
78736 @@ -469,7 +469,7 @@ int __init_or_module phonet_proto_register(unsigned int protocol,
78737 {
78738 int err = 0;
78739
78740 - if (protocol >= PHONET_NPROTO)
78741 + if (protocol < 0 || protocol >= PHONET_NPROTO)
78742 return -EINVAL;
78743
78744 err = proto_register(pp->prot, 1);
78745 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
78746 index 576f22c..bc7a71b 100644
78747 --- a/net/phonet/pep.c
78748 +++ b/net/phonet/pep.c
78749 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78750
78751 case PNS_PEP_CTRL_REQ:
78752 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
78753 - atomic_inc(&sk->sk_drops);
78754 + atomic_inc_unchecked(&sk->sk_drops);
78755 break;
78756 }
78757 __skb_pull(skb, 4);
78758 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
78759 }
78760
78761 if (pn->rx_credits == 0) {
78762 - atomic_inc(&sk->sk_drops);
78763 + atomic_inc_unchecked(&sk->sk_drops);
78764 err = -ENOBUFS;
78765 break;
78766 }
78767 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
78768 }
78769
78770 if (pn->rx_credits == 0) {
78771 - atomic_inc(&sk->sk_drops);
78772 + atomic_inc_unchecked(&sk->sk_drops);
78773 err = NET_RX_DROP;
78774 break;
78775 }
78776 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
78777 index 0acc943..c727611 100644
78778 --- a/net/phonet/socket.c
78779 +++ b/net/phonet/socket.c
78780 @@ -613,8 +613,13 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
78781 pn->resource, sk->sk_state,
78782 sk_wmem_alloc_get(sk), sk_rmem_alloc_get(sk),
78783 sock_i_uid(sk), sock_i_ino(sk),
78784 - atomic_read(&sk->sk_refcnt), sk,
78785 - atomic_read(&sk->sk_drops), &len);
78786 + atomic_read(&sk->sk_refcnt),
78787 +#ifdef CONFIG_GRKERNSEC_HIDESYM
78788 + NULL,
78789 +#else
78790 + sk,
78791 +#endif
78792 + atomic_read_unchecked(&sk->sk_drops), &len);
78793 }
78794 seq_printf(seq, "%*s\n", 127 - len, "");
78795 return 0;
78796 diff --git a/net/rds/cong.c b/net/rds/cong.c
78797 index e5b65ac..f3b6fb7 100644
78798 --- a/net/rds/cong.c
78799 +++ b/net/rds/cong.c
78800 @@ -78,7 +78,7 @@
78801 * finds that the saved generation number is smaller than the global generation
78802 * number, it wakes up the process.
78803 */
78804 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
78805 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
78806
78807 /*
78808 * Congestion monitoring
78809 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
78810 rdsdebug("waking map %p for %pI4\n",
78811 map, &map->m_addr);
78812 rds_stats_inc(s_cong_update_received);
78813 - atomic_inc(&rds_cong_generation);
78814 + atomic_inc_unchecked(&rds_cong_generation);
78815 if (waitqueue_active(&map->m_waitq))
78816 wake_up(&map->m_waitq);
78817 if (waitqueue_active(&rds_poll_waitq))
78818 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
78819
78820 int rds_cong_updated_since(unsigned long *recent)
78821 {
78822 - unsigned long gen = atomic_read(&rds_cong_generation);
78823 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
78824
78825 if (likely(*recent == gen))
78826 return 0;
78827 diff --git a/net/rds/ib.h b/net/rds/ib.h
78828 index 8d2b3d5..227ec5b 100644
78829 --- a/net/rds/ib.h
78830 +++ b/net/rds/ib.h
78831 @@ -128,7 +128,7 @@ struct rds_ib_connection {
78832 /* sending acks */
78833 unsigned long i_ack_flags;
78834 #ifdef KERNEL_HAS_ATOMIC64
78835 - atomic64_t i_ack_next; /* next ACK to send */
78836 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78837 #else
78838 spinlock_t i_ack_lock; /* protect i_ack_next */
78839 u64 i_ack_next; /* next ACK to send */
78840 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
78841 index a1e1162..265e129 100644
78842 --- a/net/rds/ib_cm.c
78843 +++ b/net/rds/ib_cm.c
78844 @@ -718,7 +718,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
78845 /* Clear the ACK state */
78846 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78847 #ifdef KERNEL_HAS_ATOMIC64
78848 - atomic64_set(&ic->i_ack_next, 0);
78849 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78850 #else
78851 ic->i_ack_next = 0;
78852 #endif
78853 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
78854 index 8d19491..05a3e65 100644
78855 --- a/net/rds/ib_recv.c
78856 +++ b/net/rds/ib_recv.c
78857 @@ -592,7 +592,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78858 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
78859 int ack_required)
78860 {
78861 - atomic64_set(&ic->i_ack_next, seq);
78862 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78863 if (ack_required) {
78864 smp_mb__before_clear_bit();
78865 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78866 @@ -604,7 +604,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
78867 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78868 smp_mb__after_clear_bit();
78869
78870 - return atomic64_read(&ic->i_ack_next);
78871 + return atomic64_read_unchecked(&ic->i_ack_next);
78872 }
78873 #endif
78874
78875 diff --git a/net/rds/iw.h b/net/rds/iw.h
78876 index 04ce3b1..48119a6 100644
78877 --- a/net/rds/iw.h
78878 +++ b/net/rds/iw.h
78879 @@ -134,7 +134,7 @@ struct rds_iw_connection {
78880 /* sending acks */
78881 unsigned long i_ack_flags;
78882 #ifdef KERNEL_HAS_ATOMIC64
78883 - atomic64_t i_ack_next; /* next ACK to send */
78884 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
78885 #else
78886 spinlock_t i_ack_lock; /* protect i_ack_next */
78887 u64 i_ack_next; /* next ACK to send */
78888 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
78889 index a91e1db..cf3053f 100644
78890 --- a/net/rds/iw_cm.c
78891 +++ b/net/rds/iw_cm.c
78892 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
78893 /* Clear the ACK state */
78894 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
78895 #ifdef KERNEL_HAS_ATOMIC64
78896 - atomic64_set(&ic->i_ack_next, 0);
78897 + atomic64_set_unchecked(&ic->i_ack_next, 0);
78898 #else
78899 ic->i_ack_next = 0;
78900 #endif
78901 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
78902 index 4503335..db566b4 100644
78903 --- a/net/rds/iw_recv.c
78904 +++ b/net/rds/iw_recv.c
78905 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78906 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
78907 int ack_required)
78908 {
78909 - atomic64_set(&ic->i_ack_next, seq);
78910 + atomic64_set_unchecked(&ic->i_ack_next, seq);
78911 if (ack_required) {
78912 smp_mb__before_clear_bit();
78913 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78914 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
78915 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
78916 smp_mb__after_clear_bit();
78917
78918 - return atomic64_read(&ic->i_ack_next);
78919 + return atomic64_read_unchecked(&ic->i_ack_next);
78920 }
78921 #endif
78922
78923 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
78924 index edac9ef..16bcb98 100644
78925 --- a/net/rds/tcp.c
78926 +++ b/net/rds/tcp.c
78927 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
78928 int val = 1;
78929
78930 set_fs(KERNEL_DS);
78931 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
78932 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
78933 sizeof(val));
78934 set_fs(oldfs);
78935 }
78936 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
78937 index 1b4fd68..2234175 100644
78938 --- a/net/rds/tcp_send.c
78939 +++ b/net/rds/tcp_send.c
78940 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
78941
78942 oldfs = get_fs();
78943 set_fs(KERNEL_DS);
78944 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
78945 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
78946 sizeof(val));
78947 set_fs(oldfs);
78948 }
78949 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
78950 index 05996d0..5a1dfe0 100644
78951 --- a/net/rxrpc/af_rxrpc.c
78952 +++ b/net/rxrpc/af_rxrpc.c
78953 @@ -39,7 +39,7 @@ static const struct proto_ops rxrpc_rpc_ops;
78954 __be32 rxrpc_epoch;
78955
78956 /* current debugging ID */
78957 -atomic_t rxrpc_debug_id;
78958 +atomic_unchecked_t rxrpc_debug_id;
78959
78960 /* count of skbs currently in use */
78961 atomic_t rxrpc_n_skbs;
78962 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
78963 index e4d9cbc..b229649 100644
78964 --- a/net/rxrpc/ar-ack.c
78965 +++ b/net/rxrpc/ar-ack.c
78966 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78967
78968 _enter("{%d,%d,%d,%d},",
78969 call->acks_hard, call->acks_unacked,
78970 - atomic_read(&call->sequence),
78971 + atomic_read_unchecked(&call->sequence),
78972 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
78973
78974 stop = 0;
78975 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
78976
78977 /* each Tx packet has a new serial number */
78978 sp->hdr.serial =
78979 - htonl(atomic_inc_return(&call->conn->serial));
78980 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
78981
78982 hdr = (struct rxrpc_header *) txb->head;
78983 hdr->serial = sp->hdr.serial;
78984 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
78985 */
78986 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
78987 {
78988 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
78989 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
78990 }
78991
78992 /*
78993 @@ -629,7 +629,7 @@ process_further:
78994
78995 latest = ntohl(sp->hdr.serial);
78996 hard = ntohl(ack.firstPacket);
78997 - tx = atomic_read(&call->sequence);
78998 + tx = atomic_read_unchecked(&call->sequence);
78999
79000 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79001 latest,
79002 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
79003 goto maybe_reschedule;
79004
79005 send_ACK_with_skew:
79006 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
79007 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
79008 ntohl(ack.serial));
79009 send_ACK:
79010 mtu = call->conn->trans->peer->if_mtu;
79011 @@ -1173,7 +1173,7 @@ send_ACK:
79012 ackinfo.rxMTU = htonl(5692);
79013 ackinfo.jumbo_max = htonl(4);
79014
79015 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79016 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79017 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
79018 ntohl(hdr.serial),
79019 ntohs(ack.maxSkew),
79020 @@ -1191,7 +1191,7 @@ send_ACK:
79021 send_message:
79022 _debug("send message");
79023
79024 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
79025 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
79026 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
79027 send_message_2:
79028
79029 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
79030 index a3bbb36..3341fb9 100644
79031 --- a/net/rxrpc/ar-call.c
79032 +++ b/net/rxrpc/ar-call.c
79033 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
79034 spin_lock_init(&call->lock);
79035 rwlock_init(&call->state_lock);
79036 atomic_set(&call->usage, 1);
79037 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
79038 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79039 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
79040
79041 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
79042 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
79043 index 4106ca9..a338d7a 100644
79044 --- a/net/rxrpc/ar-connection.c
79045 +++ b/net/rxrpc/ar-connection.c
79046 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
79047 rwlock_init(&conn->lock);
79048 spin_lock_init(&conn->state_lock);
79049 atomic_set(&conn->usage, 1);
79050 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
79051 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79052 conn->avail_calls = RXRPC_MAXCALLS;
79053 conn->size_align = 4;
79054 conn->header_size = sizeof(struct rxrpc_header);
79055 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
79056 index e7ed43a..6afa140 100644
79057 --- a/net/rxrpc/ar-connevent.c
79058 +++ b/net/rxrpc/ar-connevent.c
79059 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
79060
79061 len = iov[0].iov_len + iov[1].iov_len;
79062
79063 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79064 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79065 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
79066
79067 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79068 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
79069 index 529572f..c758ca7 100644
79070 --- a/net/rxrpc/ar-input.c
79071 +++ b/net/rxrpc/ar-input.c
79072 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
79073 /* track the latest serial number on this connection for ACK packet
79074 * information */
79075 serial = ntohl(sp->hdr.serial);
79076 - hi_serial = atomic_read(&call->conn->hi_serial);
79077 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
79078 while (serial > hi_serial)
79079 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
79080 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
79081 serial);
79082
79083 /* request ACK generation for any ACK or DATA packet that requests
79084 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
79085 index a693aca..81e7293 100644
79086 --- a/net/rxrpc/ar-internal.h
79087 +++ b/net/rxrpc/ar-internal.h
79088 @@ -272,8 +272,8 @@ struct rxrpc_connection {
79089 int error; /* error code for local abort */
79090 int debug_id; /* debug ID for printks */
79091 unsigned int call_counter; /* call ID counter */
79092 - atomic_t serial; /* packet serial number counter */
79093 - atomic_t hi_serial; /* highest serial number received */
79094 + atomic_unchecked_t serial; /* packet serial number counter */
79095 + atomic_unchecked_t hi_serial; /* highest serial number received */
79096 u8 avail_calls; /* number of calls available */
79097 u8 size_align; /* data size alignment (for security) */
79098 u8 header_size; /* rxrpc + security header size */
79099 @@ -346,7 +346,7 @@ struct rxrpc_call {
79100 spinlock_t lock;
79101 rwlock_t state_lock; /* lock for state transition */
79102 atomic_t usage;
79103 - atomic_t sequence; /* Tx data packet sequence counter */
79104 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
79105 u32 abort_code; /* local/remote abort code */
79106 enum { /* current state of call */
79107 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
79108 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
79109 */
79110 extern atomic_t rxrpc_n_skbs;
79111 extern __be32 rxrpc_epoch;
79112 -extern atomic_t rxrpc_debug_id;
79113 +extern atomic_unchecked_t rxrpc_debug_id;
79114 extern struct workqueue_struct *rxrpc_workqueue;
79115
79116 /*
79117 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
79118 index 87f7135..74d3703 100644
79119 --- a/net/rxrpc/ar-local.c
79120 +++ b/net/rxrpc/ar-local.c
79121 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
79122 spin_lock_init(&local->lock);
79123 rwlock_init(&local->services_lock);
79124 atomic_set(&local->usage, 1);
79125 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
79126 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79127 memcpy(&local->srx, srx, sizeof(*srx));
79128 }
79129
79130 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
79131 index 16ae887..d24f12b 100644
79132 --- a/net/rxrpc/ar-output.c
79133 +++ b/net/rxrpc/ar-output.c
79134 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
79135 sp->hdr.cid = call->cid;
79136 sp->hdr.callNumber = call->call_id;
79137 sp->hdr.seq =
79138 - htonl(atomic_inc_return(&call->sequence));
79139 + htonl(atomic_inc_return_unchecked(&call->sequence));
79140 sp->hdr.serial =
79141 - htonl(atomic_inc_return(&conn->serial));
79142 + htonl(atomic_inc_return_unchecked(&conn->serial));
79143 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
79144 sp->hdr.userStatus = 0;
79145 sp->hdr.securityIndex = conn->security_ix;
79146 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
79147 index bebaa43..2644591 100644
79148 --- a/net/rxrpc/ar-peer.c
79149 +++ b/net/rxrpc/ar-peer.c
79150 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
79151 INIT_LIST_HEAD(&peer->error_targets);
79152 spin_lock_init(&peer->lock);
79153 atomic_set(&peer->usage, 1);
79154 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
79155 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79156 memcpy(&peer->srx, srx, sizeof(*srx));
79157
79158 rxrpc_assess_MTU_size(peer);
79159 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
79160 index 38047f7..9f48511 100644
79161 --- a/net/rxrpc/ar-proc.c
79162 +++ b/net/rxrpc/ar-proc.c
79163 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
79164 atomic_read(&conn->usage),
79165 rxrpc_conn_states[conn->state],
79166 key_serial(conn->key),
79167 - atomic_read(&conn->serial),
79168 - atomic_read(&conn->hi_serial));
79169 + atomic_read_unchecked(&conn->serial),
79170 + atomic_read_unchecked(&conn->hi_serial));
79171
79172 return 0;
79173 }
79174 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
79175 index 92df566..87ec1bf 100644
79176 --- a/net/rxrpc/ar-transport.c
79177 +++ b/net/rxrpc/ar-transport.c
79178 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
79179 spin_lock_init(&trans->client_lock);
79180 rwlock_init(&trans->conn_lock);
79181 atomic_set(&trans->usage, 1);
79182 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
79183 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
79184
79185 if (peer->srx.transport.family == AF_INET) {
79186 switch (peer->srx.transport_type) {
79187 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
79188 index f226709..0e735a8 100644
79189 --- a/net/rxrpc/rxkad.c
79190 +++ b/net/rxrpc/rxkad.c
79191 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
79192
79193 len = iov[0].iov_len + iov[1].iov_len;
79194
79195 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
79196 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79197 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
79198
79199 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
79200 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
79201
79202 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
79203
79204 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
79205 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
79206 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
79207
79208 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
79209 diff --git a/net/sctp/proc.c b/net/sctp/proc.c
79210 index 1e2eee8..ce3967e 100644
79211 --- a/net/sctp/proc.c
79212 +++ b/net/sctp/proc.c
79213 @@ -319,7 +319,8 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
79214 seq_printf(seq,
79215 "%8pK %8pK %-3d %-3d %-2d %-4d "
79216 "%4d %8d %8d %7d %5lu %-5d %5d ",
79217 - assoc, sk, sctp_sk(sk)->type, sk->sk_state,
79218 + assoc, sk,
79219 + sctp_sk(sk)->type, sk->sk_state,
79220 assoc->state, hash,
79221 assoc->assoc_id,
79222 assoc->sndbuf_used,
79223 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
79224 index 31c7bfc..af7bfdc 100644
79225 --- a/net/sctp/socket.c
79226 +++ b/net/sctp/socket.c
79227 @@ -4577,6 +4577,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
79228 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
79229 if (space_left < addrlen)
79230 return -ENOMEM;
79231 + if (addrlen > sizeof(temp) || addrlen < 0)
79232 + return -EFAULT;
79233 if (copy_to_user(to, &temp, addrlen))
79234 return -EFAULT;
79235 to += addrlen;
79236 diff --git a/net/socket.c b/net/socket.c
79237 index bce45cc..5af9802 100644
79238 --- a/net/socket.c
79239 +++ b/net/socket.c
79240 @@ -88,6 +88,7 @@
79241 #include <linux/nsproxy.h>
79242 #include <linux/magic.h>
79243 #include <linux/slab.h>
79244 +#include <linux/in.h>
79245
79246 #include <asm/uaccess.h>
79247 #include <asm/unistd.h>
79248 @@ -105,6 +106,8 @@
79249 #include <linux/sockios.h>
79250 #include <linux/atalk.h>
79251
79252 +#include <linux/grsock.h>
79253 +
79254 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
79255 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
79256 unsigned long nr_segs, loff_t pos);
79257 @@ -321,7 +324,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
79258 &sockfs_dentry_operations, SOCKFS_MAGIC);
79259 }
79260
79261 -static struct vfsmount *sock_mnt __read_mostly;
79262 +struct vfsmount *sock_mnt __read_mostly;
79263
79264 static struct file_system_type sock_fs_type = {
79265 .name = "sockfs",
79266 @@ -1210,6 +1213,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
79267 return -EAFNOSUPPORT;
79268 if (type < 0 || type >= SOCK_MAX)
79269 return -EINVAL;
79270 + if (protocol < 0)
79271 + return -EINVAL;
79272
79273 /* Compatibility.
79274
79275 @@ -1341,6 +1346,16 @@ SYSCALL_DEFINE3(socket, int, family, int, type, int, protocol)
79276 if (SOCK_NONBLOCK != O_NONBLOCK && (flags & SOCK_NONBLOCK))
79277 flags = (flags & ~SOCK_NONBLOCK) | O_NONBLOCK;
79278
79279 + if(!gr_search_socket(family, type, protocol)) {
79280 + retval = -EACCES;
79281 + goto out;
79282 + }
79283 +
79284 + if (gr_handle_sock_all(family, type, protocol)) {
79285 + retval = -EACCES;
79286 + goto out;
79287 + }
79288 +
79289 retval = sock_create(family, type, protocol, &sock);
79290 if (retval < 0)
79291 goto out;
79292 @@ -1453,6 +1468,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79293 if (sock) {
79294 err = move_addr_to_kernel(umyaddr, addrlen, &address);
79295 if (err >= 0) {
79296 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
79297 + err = -EACCES;
79298 + goto error;
79299 + }
79300 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
79301 + if (err)
79302 + goto error;
79303 +
79304 err = security_socket_bind(sock,
79305 (struct sockaddr *)&address,
79306 addrlen);
79307 @@ -1461,6 +1484,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
79308 (struct sockaddr *)
79309 &address, addrlen);
79310 }
79311 +error:
79312 fput_light(sock->file, fput_needed);
79313 }
79314 return err;
79315 @@ -1484,10 +1508,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
79316 if ((unsigned int)backlog > somaxconn)
79317 backlog = somaxconn;
79318
79319 + if (gr_handle_sock_server_other(sock->sk)) {
79320 + err = -EPERM;
79321 + goto error;
79322 + }
79323 +
79324 + err = gr_search_listen(sock);
79325 + if (err)
79326 + goto error;
79327 +
79328 err = security_socket_listen(sock, backlog);
79329 if (!err)
79330 err = sock->ops->listen(sock, backlog);
79331
79332 +error:
79333 fput_light(sock->file, fput_needed);
79334 }
79335 return err;
79336 @@ -1531,6 +1565,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79337 newsock->type = sock->type;
79338 newsock->ops = sock->ops;
79339
79340 + if (gr_handle_sock_server_other(sock->sk)) {
79341 + err = -EPERM;
79342 + sock_release(newsock);
79343 + goto out_put;
79344 + }
79345 +
79346 + err = gr_search_accept(sock);
79347 + if (err) {
79348 + sock_release(newsock);
79349 + goto out_put;
79350 + }
79351 +
79352 /*
79353 * We don't need try_module_get here, as the listening socket (sock)
79354 * has the protocol module (sock->ops->owner) held.
79355 @@ -1569,6 +1615,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
79356 fd_install(newfd, newfile);
79357 err = newfd;
79358
79359 + gr_attach_curr_ip(newsock->sk);
79360 +
79361 out_put:
79362 fput_light(sock->file, fput_needed);
79363 out:
79364 @@ -1601,6 +1649,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79365 int, addrlen)
79366 {
79367 struct socket *sock;
79368 + struct sockaddr *sck;
79369 struct sockaddr_storage address;
79370 int err, fput_needed;
79371
79372 @@ -1611,6 +1660,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
79373 if (err < 0)
79374 goto out_put;
79375
79376 + sck = (struct sockaddr *)&address;
79377 +
79378 + if (gr_handle_sock_client(sck)) {
79379 + err = -EACCES;
79380 + goto out_put;
79381 + }
79382 +
79383 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
79384 + if (err)
79385 + goto out_put;
79386 +
79387 err =
79388 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
79389 if (err)
79390 @@ -1965,7 +2025,7 @@ static int __sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
79391 * checking falls down on this.
79392 */
79393 if (copy_from_user(ctl_buf,
79394 - (void __user __force *)msg_sys->msg_control,
79395 + (void __force_user *)msg_sys->msg_control,
79396 ctl_len))
79397 goto out_freectl;
79398 msg_sys->msg_control = ctl_buf;
79399 @@ -2133,7 +2193,7 @@ static int __sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
79400 * kernel msghdr to use the kernel address space)
79401 */
79402
79403 - uaddr = (__force void __user *)msg_sys->msg_name;
79404 + uaddr = (void __force_user *)msg_sys->msg_name;
79405 uaddr_len = COMPAT_NAMELEN(msg);
79406 if (MSG_CMSG_COMPAT & flags) {
79407 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
79408 @@ -2762,7 +2822,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79409 }
79410
79411 ifr = compat_alloc_user_space(buf_size);
79412 - rxnfc = (void *)ifr + ALIGN(sizeof(struct ifreq), 8);
79413 + rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
79414
79415 if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
79416 return -EFAULT;
79417 @@ -2786,12 +2846,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79418 offsetof(struct ethtool_rxnfc, fs.ring_cookie));
79419
79420 if (copy_in_user(rxnfc, compat_rxnfc,
79421 - (void *)(&rxnfc->fs.m_ext + 1) -
79422 - (void *)rxnfc) ||
79423 + (void __user *)(&rxnfc->fs.m_ext + 1) -
79424 + (void __user *)rxnfc) ||
79425 copy_in_user(&rxnfc->fs.ring_cookie,
79426 &compat_rxnfc->fs.ring_cookie,
79427 - (void *)(&rxnfc->fs.location + 1) -
79428 - (void *)&rxnfc->fs.ring_cookie) ||
79429 + (void __user *)(&rxnfc->fs.location + 1) -
79430 + (void __user *)&rxnfc->fs.ring_cookie) ||
79431 copy_in_user(&rxnfc->rule_cnt, &compat_rxnfc->rule_cnt,
79432 sizeof(rxnfc->rule_cnt)))
79433 return -EFAULT;
79434 @@ -2803,12 +2863,12 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
79435
79436 if (convert_out) {
79437 if (copy_in_user(compat_rxnfc, rxnfc,
79438 - (const void *)(&rxnfc->fs.m_ext + 1) -
79439 - (const void *)rxnfc) ||
79440 + (const void __user *)(&rxnfc->fs.m_ext + 1) -
79441 + (const void __user *)rxnfc) ||
79442 copy_in_user(&compat_rxnfc->fs.ring_cookie,
79443 &rxnfc->fs.ring_cookie,
79444 - (const void *)(&rxnfc->fs.location + 1) -
79445 - (const void *)&rxnfc->fs.ring_cookie) ||
79446 + (const void __user *)(&rxnfc->fs.location + 1) -
79447 + (const void __user *)&rxnfc->fs.ring_cookie) ||
79448 copy_in_user(&compat_rxnfc->rule_cnt, &rxnfc->rule_cnt,
79449 sizeof(rxnfc->rule_cnt)))
79450 return -EFAULT;
79451 @@ -2878,7 +2938,7 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
79452 old_fs = get_fs();
79453 set_fs(KERNEL_DS);
79454 err = dev_ioctl(net, cmd,
79455 - (struct ifreq __user __force *) &kifr);
79456 + (struct ifreq __force_user *) &kifr);
79457 set_fs(old_fs);
79458
79459 return err;
79460 @@ -2987,7 +3047,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
79461
79462 old_fs = get_fs();
79463 set_fs(KERNEL_DS);
79464 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
79465 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
79466 set_fs(old_fs);
79467
79468 if (cmd == SIOCGIFMAP && !err) {
79469 @@ -3092,7 +3152,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
79470 ret |= __get_user(rtdev, &(ur4->rt_dev));
79471 if (rtdev) {
79472 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
79473 - r4.rt_dev = (char __user __force *)devname;
79474 + r4.rt_dev = (char __force_user *)devname;
79475 devname[15] = 0;
79476 } else
79477 r4.rt_dev = NULL;
79478 @@ -3318,8 +3378,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
79479 int __user *uoptlen;
79480 int err;
79481
79482 - uoptval = (char __user __force *) optval;
79483 - uoptlen = (int __user __force *) optlen;
79484 + uoptval = (char __force_user *) optval;
79485 + uoptlen = (int __force_user *) optlen;
79486
79487 set_fs(KERNEL_DS);
79488 if (level == SOL_SOCKET)
79489 @@ -3339,7 +3399,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
79490 char __user *uoptval;
79491 int err;
79492
79493 - uoptval = (char __user __force *) optval;
79494 + uoptval = (char __force_user *) optval;
79495
79496 set_fs(KERNEL_DS);
79497 if (level == SOL_SOCKET)
79498 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
79499 index eda32ae..1c9fa7c 100644
79500 --- a/net/sunrpc/sched.c
79501 +++ b/net/sunrpc/sched.c
79502 @@ -240,9 +240,9 @@ static int rpc_wait_bit_killable(void *word)
79503 #ifdef RPC_DEBUG
79504 static void rpc_task_set_debuginfo(struct rpc_task *task)
79505 {
79506 - static atomic_t rpc_pid;
79507 + static atomic_unchecked_t rpc_pid;
79508
79509 - task->tk_pid = atomic_inc_return(&rpc_pid);
79510 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
79511 }
79512 #else
79513 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
79514 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
79515 index 8343737..677025e 100644
79516 --- a/net/sunrpc/xprtrdma/svc_rdma.c
79517 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
79518 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
79519 static unsigned int min_max_inline = 4096;
79520 static unsigned int max_max_inline = 65536;
79521
79522 -atomic_t rdma_stat_recv;
79523 -atomic_t rdma_stat_read;
79524 -atomic_t rdma_stat_write;
79525 -atomic_t rdma_stat_sq_starve;
79526 -atomic_t rdma_stat_rq_starve;
79527 -atomic_t rdma_stat_rq_poll;
79528 -atomic_t rdma_stat_rq_prod;
79529 -atomic_t rdma_stat_sq_poll;
79530 -atomic_t rdma_stat_sq_prod;
79531 +atomic_unchecked_t rdma_stat_recv;
79532 +atomic_unchecked_t rdma_stat_read;
79533 +atomic_unchecked_t rdma_stat_write;
79534 +atomic_unchecked_t rdma_stat_sq_starve;
79535 +atomic_unchecked_t rdma_stat_rq_starve;
79536 +atomic_unchecked_t rdma_stat_rq_poll;
79537 +atomic_unchecked_t rdma_stat_rq_prod;
79538 +atomic_unchecked_t rdma_stat_sq_poll;
79539 +atomic_unchecked_t rdma_stat_sq_prod;
79540
79541 /* Temporary NFS request map and context caches */
79542 struct kmem_cache *svc_rdma_map_cachep;
79543 @@ -110,7 +110,7 @@ static int read_reset_stat(ctl_table *table, int write,
79544 len -= *ppos;
79545 if (len > *lenp)
79546 len = *lenp;
79547 - if (len && copy_to_user(buffer, str_buf, len))
79548 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
79549 return -EFAULT;
79550 *lenp = len;
79551 *ppos += len;
79552 @@ -151,63 +151,63 @@ static ctl_table svcrdma_parm_table[] = {
79553 {
79554 .procname = "rdma_stat_read",
79555 .data = &rdma_stat_read,
79556 - .maxlen = sizeof(atomic_t),
79557 + .maxlen = sizeof(atomic_unchecked_t),
79558 .mode = 0644,
79559 .proc_handler = read_reset_stat,
79560 },
79561 {
79562 .procname = "rdma_stat_recv",
79563 .data = &rdma_stat_recv,
79564 - .maxlen = sizeof(atomic_t),
79565 + .maxlen = sizeof(atomic_unchecked_t),
79566 .mode = 0644,
79567 .proc_handler = read_reset_stat,
79568 },
79569 {
79570 .procname = "rdma_stat_write",
79571 .data = &rdma_stat_write,
79572 - .maxlen = sizeof(atomic_t),
79573 + .maxlen = sizeof(atomic_unchecked_t),
79574 .mode = 0644,
79575 .proc_handler = read_reset_stat,
79576 },
79577 {
79578 .procname = "rdma_stat_sq_starve",
79579 .data = &rdma_stat_sq_starve,
79580 - .maxlen = sizeof(atomic_t),
79581 + .maxlen = sizeof(atomic_unchecked_t),
79582 .mode = 0644,
79583 .proc_handler = read_reset_stat,
79584 },
79585 {
79586 .procname = "rdma_stat_rq_starve",
79587 .data = &rdma_stat_rq_starve,
79588 - .maxlen = sizeof(atomic_t),
79589 + .maxlen = sizeof(atomic_unchecked_t),
79590 .mode = 0644,
79591 .proc_handler = read_reset_stat,
79592 },
79593 {
79594 .procname = "rdma_stat_rq_poll",
79595 .data = &rdma_stat_rq_poll,
79596 - .maxlen = sizeof(atomic_t),
79597 + .maxlen = sizeof(atomic_unchecked_t),
79598 .mode = 0644,
79599 .proc_handler = read_reset_stat,
79600 },
79601 {
79602 .procname = "rdma_stat_rq_prod",
79603 .data = &rdma_stat_rq_prod,
79604 - .maxlen = sizeof(atomic_t),
79605 + .maxlen = sizeof(atomic_unchecked_t),
79606 .mode = 0644,
79607 .proc_handler = read_reset_stat,
79608 },
79609 {
79610 .procname = "rdma_stat_sq_poll",
79611 .data = &rdma_stat_sq_poll,
79612 - .maxlen = sizeof(atomic_t),
79613 + .maxlen = sizeof(atomic_unchecked_t),
79614 .mode = 0644,
79615 .proc_handler = read_reset_stat,
79616 },
79617 {
79618 .procname = "rdma_stat_sq_prod",
79619 .data = &rdma_stat_sq_prod,
79620 - .maxlen = sizeof(atomic_t),
79621 + .maxlen = sizeof(atomic_unchecked_t),
79622 .mode = 0644,
79623 .proc_handler = read_reset_stat,
79624 },
79625 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79626 index 41cb63b..c4a1489 100644
79627 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79628 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
79629 @@ -501,7 +501,7 @@ next_sge:
79630 svc_rdma_put_context(ctxt, 0);
79631 goto out;
79632 }
79633 - atomic_inc(&rdma_stat_read);
79634 + atomic_inc_unchecked(&rdma_stat_read);
79635
79636 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
79637 chl_map->ch[ch_no].count -= read_wr.num_sge;
79638 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79639 dto_q);
79640 list_del_init(&ctxt->dto_q);
79641 } else {
79642 - atomic_inc(&rdma_stat_rq_starve);
79643 + atomic_inc_unchecked(&rdma_stat_rq_starve);
79644 clear_bit(XPT_DATA, &xprt->xpt_flags);
79645 ctxt = NULL;
79646 }
79647 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
79648 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
79649 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
79650 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
79651 - atomic_inc(&rdma_stat_recv);
79652 + atomic_inc_unchecked(&rdma_stat_recv);
79653
79654 /* Build up the XDR from the receive buffers. */
79655 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
79656 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79657 index 42eb7ba..c887c45 100644
79658 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79659 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
79660 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
79661 write_wr.wr.rdma.remote_addr = to;
79662
79663 /* Post It */
79664 - atomic_inc(&rdma_stat_write);
79665 + atomic_inc_unchecked(&rdma_stat_write);
79666 if (svc_rdma_send(xprt, &write_wr))
79667 goto err;
79668 return 0;
79669 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79670 index 73b428b..5f3f8f3 100644
79671 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
79672 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
79673 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79674 return;
79675
79676 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
79677 - atomic_inc(&rdma_stat_rq_poll);
79678 + atomic_inc_unchecked(&rdma_stat_rq_poll);
79679
79680 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
79681 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
79682 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
79683 }
79684
79685 if (ctxt)
79686 - atomic_inc(&rdma_stat_rq_prod);
79687 + atomic_inc_unchecked(&rdma_stat_rq_prod);
79688
79689 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
79690 /*
79691 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79692 return;
79693
79694 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
79695 - atomic_inc(&rdma_stat_sq_poll);
79696 + atomic_inc_unchecked(&rdma_stat_sq_poll);
79697 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
79698 if (wc.status != IB_WC_SUCCESS)
79699 /* Close the transport */
79700 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
79701 }
79702
79703 if (ctxt)
79704 - atomic_inc(&rdma_stat_sq_prod);
79705 + atomic_inc_unchecked(&rdma_stat_sq_prod);
79706 }
79707
79708 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
79709 @@ -1266,7 +1266,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
79710 spin_lock_bh(&xprt->sc_lock);
79711 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
79712 spin_unlock_bh(&xprt->sc_lock);
79713 - atomic_inc(&rdma_stat_sq_starve);
79714 + atomic_inc_unchecked(&rdma_stat_sq_starve);
79715
79716 /* See if we can opportunistically reap SQ WR to make room */
79717 sq_cq_reap(xprt);
79718 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
79719 index e3a6e37..be2ea77 100644
79720 --- a/net/sysctl_net.c
79721 +++ b/net/sysctl_net.c
79722 @@ -43,7 +43,7 @@ static int net_ctl_permissions(struct ctl_table_root *root,
79723 struct ctl_table *table)
79724 {
79725 /* Allow network administrator to have same access as root. */
79726 - if (capable(CAP_NET_ADMIN)) {
79727 + if (capable_nolog(CAP_NET_ADMIN)) {
79728 int mode = (table->mode >> 6) & 7;
79729 return (mode << 6) | (mode << 3) | mode;
79730 }
79731 diff --git a/net/tipc/link.c b/net/tipc/link.c
79732 index 7a614f4..b14dbd2 100644
79733 --- a/net/tipc/link.c
79734 +++ b/net/tipc/link.c
79735 @@ -1164,7 +1164,7 @@ static int link_send_sections_long(struct tipc_port *sender,
79736 struct tipc_msg fragm_hdr;
79737 struct sk_buff *buf, *buf_chain, *prev;
79738 u32 fragm_crs, fragm_rest, hsz, sect_rest;
79739 - const unchar *sect_crs;
79740 + const unchar __user *sect_crs;
79741 int curr_sect;
79742 u32 fragm_no;
79743
79744 @@ -1205,7 +1205,7 @@ again:
79745
79746 if (!sect_rest) {
79747 sect_rest = msg_sect[++curr_sect].iov_len;
79748 - sect_crs = (const unchar *)msg_sect[curr_sect].iov_base;
79749 + sect_crs = (const unchar __user *)msg_sect[curr_sect].iov_base;
79750 }
79751
79752 if (sect_rest < fragm_rest)
79753 @@ -1224,7 +1224,7 @@ error:
79754 }
79755 } else
79756 skb_copy_to_linear_data_offset(buf, fragm_crs,
79757 - sect_crs, sz);
79758 + (const void __force_kernel *)sect_crs, sz);
79759 sect_crs += sz;
79760 sect_rest -= sz;
79761 fragm_crs += sz;
79762 diff --git a/net/tipc/msg.c b/net/tipc/msg.c
79763 index deea0d2..fa13bd7 100644
79764 --- a/net/tipc/msg.c
79765 +++ b/net/tipc/msg.c
79766 @@ -98,7 +98,7 @@ int tipc_msg_build(struct tipc_msg *hdr, struct iovec const *msg_sect,
79767 msg_sect[cnt].iov_len);
79768 else
79769 skb_copy_to_linear_data_offset(*buf, pos,
79770 - msg_sect[cnt].iov_base,
79771 + (const void __force_kernel *)msg_sect[cnt].iov_base,
79772 msg_sect[cnt].iov_len);
79773 pos += msg_sect[cnt].iov_len;
79774 }
79775 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
79776 index f976e9cd..560d055 100644
79777 --- a/net/tipc/subscr.c
79778 +++ b/net/tipc/subscr.c
79779 @@ -96,7 +96,7 @@ static void subscr_send_event(struct tipc_subscription *sub,
79780 {
79781 struct iovec msg_sect;
79782
79783 - msg_sect.iov_base = (void *)&sub->evt;
79784 + msg_sect.iov_base = (void __force_user *)&sub->evt;
79785 msg_sect.iov_len = sizeof(struct tipc_event);
79786
79787 sub->evt.event = htohl(event, sub->swap);
79788 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
79789 index 9aa708c..590bb48 100644
79790 --- a/net/unix/af_unix.c
79791 +++ b/net/unix/af_unix.c
79792 @@ -780,6 +780,12 @@ static struct sock *unix_find_other(struct net *net,
79793 err = -ECONNREFUSED;
79794 if (!S_ISSOCK(inode->i_mode))
79795 goto put_fail;
79796 +
79797 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
79798 + err = -EACCES;
79799 + goto put_fail;
79800 + }
79801 +
79802 u = unix_find_socket_byinode(inode);
79803 if (!u)
79804 goto put_fail;
79805 @@ -800,6 +806,13 @@ static struct sock *unix_find_other(struct net *net,
79806 if (u) {
79807 struct dentry *dentry;
79808 dentry = unix_sk(u)->path.dentry;
79809 +
79810 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
79811 + err = -EPERM;
79812 + sock_put(u);
79813 + goto fail;
79814 + }
79815 +
79816 if (dentry)
79817 touch_atime(&unix_sk(u)->path);
79818 } else
79819 @@ -882,11 +895,18 @@ static int unix_bind(struct socket *sock, struct sockaddr *uaddr, int addr_len)
79820 err = security_path_mknod(&path, dentry, mode, 0);
79821 if (err)
79822 goto out_mknod_drop_write;
79823 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
79824 + err = -EACCES;
79825 + goto out_mknod_drop_write;
79826 + }
79827 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
79828 out_mknod_drop_write:
79829 mnt_drop_write(path.mnt);
79830 if (err)
79831 goto out_mknod_dput;
79832 +
79833 + gr_handle_create(dentry, path.mnt);
79834 +
79835 mutex_unlock(&path.dentry->d_inode->i_mutex);
79836 dput(path.dentry);
79837 path.dentry = dentry;
79838 diff --git a/net/wireless/core.h b/net/wireless/core.h
79839 index bc686ef..27845e6 100644
79840 --- a/net/wireless/core.h
79841 +++ b/net/wireless/core.h
79842 @@ -27,7 +27,7 @@ struct cfg80211_registered_device {
79843 struct mutex mtx;
79844
79845 /* rfkill support */
79846 - struct rfkill_ops rfkill_ops;
79847 + rfkill_ops_no_const rfkill_ops;
79848 struct rfkill *rfkill;
79849 struct work_struct rfkill_sync;
79850
79851 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
79852 index b0eb7aa..7d73e82 100644
79853 --- a/net/wireless/wext-core.c
79854 +++ b/net/wireless/wext-core.c
79855 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79856 */
79857
79858 /* Support for very large requests */
79859 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
79860 - (user_length > descr->max_tokens)) {
79861 + if (user_length > descr->max_tokens) {
79862 /* Allow userspace to GET more than max so
79863 * we can support any size GET requests.
79864 * There is still a limit : -ENOMEM.
79865 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
79866 }
79867 }
79868
79869 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
79870 - /*
79871 - * If this is a GET, but not NOMAX, it means that the extra
79872 - * data is not bounded by userspace, but by max_tokens. Thus
79873 - * set the length to max_tokens. This matches the extra data
79874 - * allocation.
79875 - * The driver should fill it with the number of tokens it
79876 - * provided, and it may check iwp->length rather than having
79877 - * knowledge of max_tokens. If the driver doesn't change the
79878 - * iwp->length, this ioctl just copies back max_token tokens
79879 - * filled with zeroes. Hopefully the driver isn't claiming
79880 - * them to be valid data.
79881 - */
79882 - iwp->length = descr->max_tokens;
79883 - }
79884 -
79885 err = handler(dev, info, (union iwreq_data *) iwp, extra);
79886
79887 iwp->length += essid_compat;
79888 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
79889 index ccfbd32..9b61cf9f 100644
79890 --- a/net/xfrm/xfrm_policy.c
79891 +++ b/net/xfrm/xfrm_policy.c
79892 @@ -300,7 +300,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
79893 {
79894 policy->walk.dead = 1;
79895
79896 - atomic_inc(&policy->genid);
79897 + atomic_inc_unchecked(&policy->genid);
79898
79899 if (del_timer(&policy->timer))
79900 xfrm_pol_put(policy);
79901 @@ -584,7 +584,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
79902 hlist_add_head(&policy->bydst, chain);
79903 xfrm_pol_hold(policy);
79904 net->xfrm.policy_count[dir]++;
79905 - atomic_inc(&flow_cache_genid);
79906 + atomic_inc_unchecked(&flow_cache_genid);
79907 if (delpol)
79908 __xfrm_policy_unlink(delpol, dir);
79909 policy->index = delpol ? delpol->index : xfrm_gen_index(net, dir);
79910 @@ -1532,7 +1532,7 @@ free_dst:
79911 goto out;
79912 }
79913
79914 -static int inline
79915 +static inline int
79916 xfrm_dst_alloc_copy(void **target, const void *src, int size)
79917 {
79918 if (!*target) {
79919 @@ -1544,7 +1544,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
79920 return 0;
79921 }
79922
79923 -static int inline
79924 +static inline int
79925 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79926 {
79927 #ifdef CONFIG_XFRM_SUB_POLICY
79928 @@ -1556,7 +1556,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
79929 #endif
79930 }
79931
79932 -static int inline
79933 +static inline int
79934 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
79935 {
79936 #ifdef CONFIG_XFRM_SUB_POLICY
79937 @@ -1650,7 +1650,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
79938
79939 xdst->num_pols = num_pols;
79940 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
79941 - xdst->policy_genid = atomic_read(&pols[0]->genid);
79942 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
79943
79944 return xdst;
79945 }
79946 @@ -2350,7 +2350,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
79947 if (xdst->xfrm_genid != dst->xfrm->genid)
79948 return 0;
79949 if (xdst->num_pols > 0 &&
79950 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
79951 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
79952 return 0;
79953
79954 mtu = dst_mtu(dst->child);
79955 @@ -2887,7 +2887,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
79956 sizeof(pol->xfrm_vec[i].saddr));
79957 pol->xfrm_vec[i].encap_family = mp->new_family;
79958 /* flush bundles */
79959 - atomic_inc(&pol->genid);
79960 + atomic_inc_unchecked(&pol->genid);
79961 }
79962 }
79963
79964 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
79965 index 5b228f9..6aca4e3 100644
79966 --- a/net/xfrm/xfrm_state.c
79967 +++ b/net/xfrm/xfrm_state.c
79968 @@ -1981,8 +1981,10 @@ int __xfrm_init_state(struct xfrm_state *x, bool init_replay)
79969 goto error;
79970
79971 x->outer_mode = xfrm_get_mode(x->props.mode, family);
79972 - if (x->outer_mode == NULL)
79973 + if (x->outer_mode == NULL) {
79974 + err = -EPROTONOSUPPORT;
79975 goto error;
79976 + }
79977
79978 if (init_replay) {
79979 err = xfrm_init_replay(x);
79980 diff --git a/net/xfrm/xfrm_user.c b/net/xfrm/xfrm_user.c
79981 index 44293b3..1870c62 100644
79982 --- a/net/xfrm/xfrm_user.c
79983 +++ b/net/xfrm/xfrm_user.c
79984 @@ -123,9 +123,21 @@ static inline int verify_replay(struct xfrm_usersa_info *p,
79985 struct nlattr **attrs)
79986 {
79987 struct nlattr *rt = attrs[XFRMA_REPLAY_ESN_VAL];
79988 + struct xfrm_replay_state_esn *rs;
79989
79990 - if ((p->flags & XFRM_STATE_ESN) && !rt)
79991 - return -EINVAL;
79992 + if (p->flags & XFRM_STATE_ESN) {
79993 + if (!rt)
79994 + return -EINVAL;
79995 +
79996 + rs = nla_data(rt);
79997 +
79998 + if (rs->bmp_len > XFRMA_REPLAY_ESN_MAX / sizeof(rs->bmp[0]) / 8)
79999 + return -EINVAL;
80000 +
80001 + if (nla_len(rt) < xfrm_replay_state_esn_len(rs) &&
80002 + nla_len(rt) != sizeof(*rs))
80003 + return -EINVAL;
80004 + }
80005
80006 if (!rt)
80007 return 0;
80008 @@ -370,14 +382,15 @@ static inline int xfrm_replay_verify_len(struct xfrm_replay_state_esn *replay_es
80009 struct nlattr *rp)
80010 {
80011 struct xfrm_replay_state_esn *up;
80012 + int ulen;
80013
80014 if (!replay_esn || !rp)
80015 return 0;
80016
80017 up = nla_data(rp);
80018 + ulen = xfrm_replay_state_esn_len(up);
80019
80020 - if (xfrm_replay_state_esn_len(replay_esn) !=
80021 - xfrm_replay_state_esn_len(up))
80022 + if (nla_len(rp) < ulen || xfrm_replay_state_esn_len(replay_esn) != ulen)
80023 return -EINVAL;
80024
80025 return 0;
80026 @@ -388,22 +401,28 @@ static int xfrm_alloc_replay_state_esn(struct xfrm_replay_state_esn **replay_esn
80027 struct nlattr *rta)
80028 {
80029 struct xfrm_replay_state_esn *p, *pp, *up;
80030 + int klen, ulen;
80031
80032 if (!rta)
80033 return 0;
80034
80035 up = nla_data(rta);
80036 + klen = xfrm_replay_state_esn_len(up);
80037 + ulen = nla_len(rta) >= klen ? klen : sizeof(*up);
80038
80039 - p = kmemdup(up, xfrm_replay_state_esn_len(up), GFP_KERNEL);
80040 + p = kzalloc(klen, GFP_KERNEL);
80041 if (!p)
80042 return -ENOMEM;
80043
80044 - pp = kmemdup(up, xfrm_replay_state_esn_len(up), GFP_KERNEL);
80045 + pp = kzalloc(klen, GFP_KERNEL);
80046 if (!pp) {
80047 kfree(p);
80048 return -ENOMEM;
80049 }
80050
80051 + memcpy(p, up, ulen);
80052 + memcpy(pp, up, ulen);
80053 +
80054 *replay_esn = p;
80055 *preplay_esn = pp;
80056
80057 @@ -442,10 +461,11 @@ static void copy_from_user_state(struct xfrm_state *x, struct xfrm_usersa_info *
80058 * somehow made shareable and move it to xfrm_state.c - JHS
80059 *
80060 */
80061 -static void xfrm_update_ae_params(struct xfrm_state *x, struct nlattr **attrs)
80062 +static void xfrm_update_ae_params(struct xfrm_state *x, struct nlattr **attrs,
80063 + int update_esn)
80064 {
80065 struct nlattr *rp = attrs[XFRMA_REPLAY_VAL];
80066 - struct nlattr *re = attrs[XFRMA_REPLAY_ESN_VAL];
80067 + struct nlattr *re = update_esn ? attrs[XFRMA_REPLAY_ESN_VAL] : NULL;
80068 struct nlattr *lt = attrs[XFRMA_LTIME_VAL];
80069 struct nlattr *et = attrs[XFRMA_ETIMER_THRESH];
80070 struct nlattr *rt = attrs[XFRMA_REPLAY_THRESH];
80071 @@ -555,7 +575,7 @@ static struct xfrm_state *xfrm_state_construct(struct net *net,
80072 goto error;
80073
80074 /* override default values from above */
80075 - xfrm_update_ae_params(x, attrs);
80076 + xfrm_update_ae_params(x, attrs, 0);
80077
80078 return x;
80079
80080 @@ -689,6 +709,7 @@ out:
80081
80082 static void copy_to_user_state(struct xfrm_state *x, struct xfrm_usersa_info *p)
80083 {
80084 + memset(p, 0, sizeof(*p));
80085 memcpy(&p->id, &x->id, sizeof(p->id));
80086 memcpy(&p->sel, &x->sel, sizeof(p->sel));
80087 memcpy(&p->lft, &x->lft, sizeof(p->lft));
80088 @@ -742,7 +763,7 @@ static int copy_to_user_auth(struct xfrm_algo_auth *auth, struct sk_buff *skb)
80089 return -EMSGSIZE;
80090
80091 algo = nla_data(nla);
80092 - strcpy(algo->alg_name, auth->alg_name);
80093 + strncpy(algo->alg_name, auth->alg_name, sizeof(algo->alg_name));
80094 memcpy(algo->alg_key, auth->alg_key, (auth->alg_key_len + 7) / 8);
80095 algo->alg_key_len = auth->alg_key_len;
80096
80097 @@ -872,6 +893,7 @@ static struct sk_buff *xfrm_state_netlink(struct sk_buff *in_skb,
80098 {
80099 struct xfrm_dump_info info;
80100 struct sk_buff *skb;
80101 + int err;
80102
80103 skb = nlmsg_new(NLMSG_DEFAULT_SIZE, GFP_ATOMIC);
80104 if (!skb)
80105 @@ -882,9 +904,10 @@ static struct sk_buff *xfrm_state_netlink(struct sk_buff *in_skb,
80106 info.nlmsg_seq = seq;
80107 info.nlmsg_flags = 0;
80108
80109 - if (dump_one_state(x, 0, &info)) {
80110 + err = dump_one_state(x, 0, &info);
80111 + if (err) {
80112 kfree_skb(skb);
80113 - return NULL;
80114 + return ERR_PTR(err);
80115 }
80116
80117 return skb;
80118 @@ -1309,6 +1332,7 @@ static void copy_from_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy
80119
80120 static void copy_to_user_policy(struct xfrm_policy *xp, struct xfrm_userpolicy_info *p, int dir)
80121 {
80122 + memset(p, 0, sizeof(*p));
80123 memcpy(&p->sel, &xp->selector, sizeof(p->sel));
80124 memcpy(&p->lft, &xp->lft, sizeof(p->lft));
80125 memcpy(&p->curlft, &xp->curlft, sizeof(p->curlft));
80126 @@ -1413,6 +1437,7 @@ static int copy_to_user_tmpl(struct xfrm_policy *xp, struct sk_buff *skb)
80127 struct xfrm_user_tmpl *up = &vec[i];
80128 struct xfrm_tmpl *kp = &xp->xfrm_vec[i];
80129
80130 + memset(up, 0, sizeof(*up));
80131 memcpy(&up->id, &kp->id, sizeof(up->id));
80132 up->family = kp->encap_family;
80133 memcpy(&up->saddr, &kp->saddr, sizeof(up->saddr));
80134 @@ -1812,7 +1837,7 @@ static int xfrm_new_ae(struct sk_buff *skb, struct nlmsghdr *nlh,
80135 goto out;
80136
80137 spin_lock_bh(&x->lock);
80138 - xfrm_update_ae_params(x, attrs);
80139 + xfrm_update_ae_params(x, attrs, 1);
80140 spin_unlock_bh(&x->lock);
80141
80142 c.event = nlh->nlmsg_type;
80143 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
80144 index ff1720d..ed8475e 100644
80145 --- a/scripts/Makefile.build
80146 +++ b/scripts/Makefile.build
80147 @@ -111,7 +111,7 @@ endif
80148 endif
80149
80150 # Do not include host rules unless needed
80151 -ifneq ($(hostprogs-y)$(hostprogs-m),)
80152 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
80153 include scripts/Makefile.host
80154 endif
80155
80156 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
80157 index 686cb0d..9d653bf 100644
80158 --- a/scripts/Makefile.clean
80159 +++ b/scripts/Makefile.clean
80160 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
80161 __clean-files := $(extra-y) $(always) \
80162 $(targets) $(clean-files) \
80163 $(host-progs) \
80164 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
80165 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
80166 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
80167
80168 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
80169
80170 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
80171 index 1ac414f..38575f7 100644
80172 --- a/scripts/Makefile.host
80173 +++ b/scripts/Makefile.host
80174 @@ -31,6 +31,8 @@
80175 # Note: Shared libraries consisting of C++ files are not supported
80176
80177 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
80178 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
80179 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
80180
80181 # C code
80182 # Executables compiled from a single .c file
80183 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
80184 # Shared libaries (only .c supported)
80185 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
80186 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
80187 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
80188 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
80189 # Remove .so files from "xxx-objs"
80190 host-cobjs := $(filter-out %.so,$(host-cobjs))
80191 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
80192
80193 -#Object (.o) files used by the shared libaries
80194 +# Object (.o) files used by the shared libaries
80195 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
80196 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
80197
80198 # output directory for programs/.o files
80199 # hostprogs-y := tools/build may have been specified. Retrieve directory
80200 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
80201 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
80202 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
80203 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
80204 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
80205 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
80206 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
80207 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
80208
80209 obj-dirs += $(host-objdirs)
80210 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
80211 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
80212 $(call if_changed_dep,host-cshobjs)
80213
80214 +# Compile .c file, create position independent .o file
80215 +# host-cxxshobjs -> .o
80216 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
80217 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
80218 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
80219 + $(call if_changed_dep,host-cxxshobjs)
80220 +
80221 # Link a shared library, based on position independent .o files
80222 # *.o -> .so shared library (host-cshlib)
80223 quiet_cmd_host-cshlib = HOSTLLD -shared $@
80224 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
80225 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
80226 $(call if_changed,host-cshlib)
80227
80228 +# Link a shared library, based on position independent .o files
80229 +# *.o -> .so shared library (host-cxxshlib)
80230 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
80231 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
80232 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
80233 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
80234 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
80235 + $(call if_changed,host-cxxshlib)
80236 +
80237 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
80238 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
80239 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
80240
80241 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
80242 index cb1f50c..cef2a7c 100644
80243 --- a/scripts/basic/fixdep.c
80244 +++ b/scripts/basic/fixdep.c
80245 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
80246 /*
80247 * Lookup a value in the configuration string.
80248 */
80249 -static int is_defined_config(const char *name, int len, unsigned int hash)
80250 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
80251 {
80252 struct item *aux;
80253
80254 @@ -211,10 +211,10 @@ static void clear_config(void)
80255 /*
80256 * Record the use of a CONFIG_* word.
80257 */
80258 -static void use_config(const char *m, int slen)
80259 +static void use_config(const char *m, unsigned int slen)
80260 {
80261 unsigned int hash = strhash(m, slen);
80262 - int c, i;
80263 + unsigned int c, i;
80264
80265 if (is_defined_config(m, slen, hash))
80266 return;
80267 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
80268
80269 static void parse_config_file(const char *map, size_t len)
80270 {
80271 - const int *end = (const int *) (map + len);
80272 + const unsigned int *end = (const unsigned int *) (map + len);
80273 /* start at +1, so that p can never be < map */
80274 - const int *m = (const int *) map + 1;
80275 + const unsigned int *m = (const unsigned int *) map + 1;
80276 const char *p, *q;
80277
80278 for (; m < end; m++) {
80279 @@ -406,7 +406,7 @@ static void print_deps(void)
80280 static void traps(void)
80281 {
80282 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
80283 - int *p = (int *)test;
80284 + unsigned int *p = (unsigned int *)test;
80285
80286 if (*p != INT_CONF) {
80287 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianess? %#x\n",
80288 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
80289 new file mode 100644
80290 index 0000000..008ac1a
80291 --- /dev/null
80292 +++ b/scripts/gcc-plugin.sh
80293 @@ -0,0 +1,17 @@
80294 +#!/bin/bash
80295 +plugincc=`$1 -x c -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
80296 +#include "gcc-plugin.h"
80297 +#include "tree.h"
80298 +#include "tm.h"
80299 +#include "rtl.h"
80300 +#ifdef ENABLE_BUILD_WITH_CXX
80301 +#warning $2
80302 +#else
80303 +#warning $1
80304 +#endif
80305 +EOF`
80306 +if [ $? -eq 0 ]
80307 +then
80308 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
80309 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
80310 +fi
80311 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
80312 index cd9c6c6..0c8f0fa 100644
80313 --- a/scripts/link-vmlinux.sh
80314 +++ b/scripts/link-vmlinux.sh
80315 @@ -147,7 +147,7 @@ else
80316 fi;
80317
80318 # final build of init/
80319 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
80320 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
80321
80322 kallsymso=""
80323 kallsyms_vmlinux=""
80324 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
80325 index 5759751..b170367 100644
80326 --- a/scripts/mod/file2alias.c
80327 +++ b/scripts/mod/file2alias.c
80328 @@ -128,7 +128,7 @@ static void device_id_check(const char *modname, const char *device_id,
80329 unsigned long size, unsigned long id_size,
80330 void *symval)
80331 {
80332 - int i;
80333 + unsigned int i;
80334
80335 if (size % id_size || size < id_size) {
80336 if (cross_build != 0)
80337 @@ -158,7 +158,7 @@ static void device_id_check(const char *modname, const char *device_id,
80338 /* USB is special because the bcdDevice can be matched against a numeric range */
80339 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipN" */
80340 static void do_usb_entry(struct usb_device_id *id,
80341 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
80342 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
80343 unsigned char range_lo, unsigned char range_hi,
80344 unsigned char max, struct module *mod)
80345 {
80346 @@ -259,7 +259,7 @@ static void do_usb_entry_multi(struct usb_device_id *id, struct module *mod)
80347 {
80348 unsigned int devlo, devhi;
80349 unsigned char chi, clo, max;
80350 - int ndigits;
80351 + unsigned int ndigits;
80352
80353 id->match_flags = TO_NATIVE(id->match_flags);
80354 id->idVendor = TO_NATIVE(id->idVendor);
80355 @@ -504,7 +504,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
80356 for (i = 0; i < count; i++) {
80357 const char *id = (char *)devs[i].id;
80358 char acpi_id[sizeof(devs[0].id)];
80359 - int j;
80360 + unsigned int j;
80361
80362 buf_printf(&mod->dev_table_buf,
80363 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80364 @@ -534,7 +534,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80365
80366 for (j = 0; j < PNP_MAX_DEVICES; j++) {
80367 const char *id = (char *)card->devs[j].id;
80368 - int i2, j2;
80369 + unsigned int i2, j2;
80370 int dup = 0;
80371
80372 if (!id[0])
80373 @@ -560,7 +560,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
80374 /* add an individual alias for every device entry */
80375 if (!dup) {
80376 char acpi_id[sizeof(card->devs[0].id)];
80377 - int k;
80378 + unsigned int k;
80379
80380 buf_printf(&mod->dev_table_buf,
80381 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
80382 @@ -885,7 +885,7 @@ static void dmi_ascii_filter(char *d, const char *s)
80383 static int do_dmi_entry(const char *filename, struct dmi_system_id *id,
80384 char *alias)
80385 {
80386 - int i, j;
80387 + unsigned int i, j;
80388
80389 sprintf(alias, "dmi*");
80390
80391 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
80392 index 0f84bb3..2d42035 100644
80393 --- a/scripts/mod/modpost.c
80394 +++ b/scripts/mod/modpost.c
80395 @@ -925,6 +925,7 @@ enum mismatch {
80396 ANY_INIT_TO_ANY_EXIT,
80397 ANY_EXIT_TO_ANY_INIT,
80398 EXPORT_TO_INIT_EXIT,
80399 + DATA_TO_TEXT
80400 };
80401
80402 struct sectioncheck {
80403 @@ -1033,6 +1034,12 @@ const struct sectioncheck sectioncheck[] = {
80404 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
80405 .mismatch = EXPORT_TO_INIT_EXIT,
80406 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
80407 +},
80408 +/* Do not reference code from writable data */
80409 +{
80410 + .fromsec = { DATA_SECTIONS, NULL },
80411 + .tosec = { TEXT_SECTIONS, NULL },
80412 + .mismatch = DATA_TO_TEXT
80413 }
80414 };
80415
80416 @@ -1155,10 +1162,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
80417 continue;
80418 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
80419 continue;
80420 - if (sym->st_value == addr)
80421 - return sym;
80422 /* Find a symbol nearby - addr are maybe negative */
80423 d = sym->st_value - addr;
80424 + if (d == 0)
80425 + return sym;
80426 if (d < 0)
80427 d = addr - sym->st_value;
80428 if (d < distance) {
80429 @@ -1437,6 +1444,14 @@ static void report_sec_mismatch(const char *modname,
80430 tosym, prl_to, prl_to, tosym);
80431 free(prl_to);
80432 break;
80433 + case DATA_TO_TEXT:
80434 +#if 0
80435 + fprintf(stderr,
80436 + "The %s %s:%s references\n"
80437 + "the %s %s:%s%s\n",
80438 + from, fromsec, fromsym, to, tosec, tosym, to_p);
80439 +#endif
80440 + break;
80441 }
80442 fprintf(stderr, "\n");
80443 }
80444 @@ -1671,7 +1686,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
80445 static void check_sec_ref(struct module *mod, const char *modname,
80446 struct elf_info *elf)
80447 {
80448 - int i;
80449 + unsigned int i;
80450 Elf_Shdr *sechdrs = elf->sechdrs;
80451
80452 /* Walk through all sections */
80453 @@ -1769,7 +1784,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
80454 va_end(ap);
80455 }
80456
80457 -void buf_write(struct buffer *buf, const char *s, int len)
80458 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
80459 {
80460 if (buf->size - buf->pos < len) {
80461 buf->size += len + SZ;
80462 @@ -1987,7 +2002,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
80463 if (fstat(fileno(file), &st) < 0)
80464 goto close_write;
80465
80466 - if (st.st_size != b->pos)
80467 + if (st.st_size != (off_t)b->pos)
80468 goto close_write;
80469
80470 tmp = NOFAIL(malloc(b->pos));
80471 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
80472 index 51207e4..f7d603d 100644
80473 --- a/scripts/mod/modpost.h
80474 +++ b/scripts/mod/modpost.h
80475 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
80476
80477 struct buffer {
80478 char *p;
80479 - int pos;
80480 - int size;
80481 + unsigned int pos;
80482 + unsigned int size;
80483 };
80484
80485 void __attribute__((format(printf, 2, 3)))
80486 buf_printf(struct buffer *buf, const char *fmt, ...);
80487
80488 void
80489 -buf_write(struct buffer *buf, const char *s, int len);
80490 +buf_write(struct buffer *buf, const char *s, unsigned int len);
80491
80492 struct module {
80493 struct module *next;
80494 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
80495 index 9dfcd6d..099068e 100644
80496 --- a/scripts/mod/sumversion.c
80497 +++ b/scripts/mod/sumversion.c
80498 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
80499 goto out;
80500 }
80501
80502 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
80503 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
80504 warn("writing sum in %s failed: %s\n",
80505 filename, strerror(errno));
80506 goto out;
80507 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
80508 index 5c11312..72742b5 100644
80509 --- a/scripts/pnmtologo.c
80510 +++ b/scripts/pnmtologo.c
80511 @@ -237,14 +237,14 @@ static void write_header(void)
80512 fprintf(out, " * Linux logo %s\n", logoname);
80513 fputs(" */\n\n", out);
80514 fputs("#include <linux/linux_logo.h>\n\n", out);
80515 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
80516 + fprintf(out, "static unsigned char %s_data[] = {\n",
80517 logoname);
80518 }
80519
80520 static void write_footer(void)
80521 {
80522 fputs("\n};\n\n", out);
80523 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
80524 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
80525 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
80526 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
80527 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
80528 @@ -374,7 +374,7 @@ static void write_logo_clut224(void)
80529 fputs("\n};\n\n", out);
80530
80531 /* write logo clut */
80532 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
80533 + fprintf(out, "static unsigned char %s_clut[] = {\n",
80534 logoname);
80535 write_hex_cnt = 0;
80536 for (i = 0; i < logo_clutsize; i++) {
80537 diff --git a/security/Kconfig b/security/Kconfig
80538 index e9c6ac7..e7feb0d 100644
80539 --- a/security/Kconfig
80540 +++ b/security/Kconfig
80541 @@ -4,6 +4,896 @@
80542
80543 menu "Security options"
80544
80545 +menu "Grsecurity"
80546 +
80547 + config ARCH_TRACK_EXEC_LIMIT
80548 + bool
80549 +
80550 + config PAX_KERNEXEC_PLUGIN
80551 + bool
80552 +
80553 + config PAX_PER_CPU_PGD
80554 + bool
80555 +
80556 + config TASK_SIZE_MAX_SHIFT
80557 + int
80558 + depends on X86_64
80559 + default 47 if !PAX_PER_CPU_PGD
80560 + default 42 if PAX_PER_CPU_PGD
80561 +
80562 + config PAX_ENABLE_PAE
80563 + bool
80564 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
80565 +
80566 + config PAX_USERCOPY_SLABS
80567 + bool
80568 +
80569 +config GRKERNSEC
80570 + bool "Grsecurity"
80571 + select CRYPTO
80572 + select CRYPTO_SHA256
80573 + select PROC_FS
80574 + select STOP_MACHINE
80575 + help
80576 + If you say Y here, you will be able to configure many features
80577 + that will enhance the security of your system. It is highly
80578 + recommended that you say Y here and read through the help
80579 + for each option so that you fully understand the features and
80580 + can evaluate their usefulness for your machine.
80581 +
80582 +choice
80583 + prompt "Configuration Method"
80584 + depends on GRKERNSEC
80585 + default GRKERNSEC_CONFIG_CUSTOM
80586 + help
80587 +
80588 +config GRKERNSEC_CONFIG_AUTO
80589 + bool "Automatic"
80590 + help
80591 + If you choose this configuration method, you'll be able to answer a small
80592 + number of simple questions about how you plan to use this kernel.
80593 + The settings of grsecurity and PaX will be automatically configured for
80594 + the highest commonly-used settings within the provided constraints.
80595 +
80596 + If you require additional configuration, custom changes can still be made
80597 + from the "custom configuration" menu.
80598 +
80599 +config GRKERNSEC_CONFIG_CUSTOM
80600 + bool "Custom"
80601 + help
80602 + If you choose this configuration method, you'll be able to configure all
80603 + grsecurity and PaX settings manually. Via this method, no options are
80604 + automatically enabled.
80605 +
80606 +endchoice
80607 +
80608 +choice
80609 + prompt "Usage Type"
80610 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80611 + default GRKERNSEC_CONFIG_SERVER
80612 + help
80613 +
80614 +config GRKERNSEC_CONFIG_SERVER
80615 + bool "Server"
80616 + help
80617 + Choose this option if you plan to use this kernel on a server.
80618 +
80619 +config GRKERNSEC_CONFIG_DESKTOP
80620 + bool "Desktop"
80621 + help
80622 + Choose this option if you plan to use this kernel on a desktop.
80623 +
80624 +endchoice
80625 +
80626 +choice
80627 + prompt "Virtualization Type"
80628 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
80629 + default GRKERNSEC_CONFIG_VIRT_NONE
80630 + help
80631 +
80632 +config GRKERNSEC_CONFIG_VIRT_NONE
80633 + bool "None"
80634 + help
80635 + Choose this option if this kernel will be run on bare metal.
80636 +
80637 +config GRKERNSEC_CONFIG_VIRT_GUEST
80638 + bool "Guest"
80639 + help
80640 + Choose this option if this kernel will be run as a VM guest.
80641 +
80642 +config GRKERNSEC_CONFIG_VIRT_HOST
80643 + bool "Host"
80644 + help
80645 + Choose this option if this kernel will be run as a VM host.
80646 +
80647 +endchoice
80648 +
80649 +choice
80650 + prompt "Virtualization Hardware"
80651 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80652 + help
80653 +
80654 +config GRKERNSEC_CONFIG_VIRT_EPT
80655 + bool "EPT/RVI Processor Support"
80656 + depends on X86
80657 + help
80658 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
80659 + hardware virtualization. This allows for additional kernel hardening protections
80660 + to operate without additional performance impact.
80661 +
80662 + To see if your Intel processor supports EPT, see:
80663 + http://ark.intel.com/Products/VirtualizationTechnology
80664 + (Most Core i3/5/7 support EPT)
80665 +
80666 + To see if your AMD processor supports RVI, see:
80667 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
80668 +
80669 +config GRKERNSEC_CONFIG_VIRT_SOFT
80670 + bool "First-gen/No Hardware Virtualization"
80671 + help
80672 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
80673 + support hardware virtualization or doesn't support the EPT/RVI extensions.
80674 +
80675 +endchoice
80676 +
80677 +choice
80678 + prompt "Virtualization Software"
80679 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
80680 + help
80681 +
80682 +config GRKERNSEC_CONFIG_VIRT_XEN
80683 + bool "Xen"
80684 + help
80685 + Choose this option if this kernel is running as a Xen guest or host.
80686 +
80687 +config GRKERNSEC_CONFIG_VIRT_VMWARE
80688 + bool "VMWare"
80689 + help
80690 + Choose this option if this kernel is running as a VMWare guest or host.
80691 +
80692 +config GRKERNSEC_CONFIG_VIRT_KVM
80693 + bool "KVM"
80694 + help
80695 + Choose this option if this kernel is running as a KVM guest or host.
80696 +
80697 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
80698 + bool "VirtualBox"
80699 + help
80700 + Choose this option if this kernel is running as a VirtualBox guest or host.
80701 +
80702 +endchoice
80703 +
80704 +choice
80705 + prompt "Required Priorities"
80706 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80707 + default GRKERNSEC_CONFIG_PRIORITY_PERF
80708 + help
80709 +
80710 +config GRKERNSEC_CONFIG_PRIORITY_PERF
80711 + bool "Performance"
80712 + help
80713 + Choose this option if performance is of highest priority for this deployment
80714 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
80715 + and freed memory sanitizing will be disabled.
80716 +
80717 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
80718 + bool "Security"
80719 + help
80720 + Choose this option if security is of highest priority for this deployment of
80721 + grsecurity. UDEREF, kernel stack clearing, and freed memory sanitizing will
80722 + be enabled for this kernel. In a worst-case scenario, these features can
80723 + introduce a 20% performance hit (UDEREF on x64 contributing half of this hit).
80724 +
80725 +endchoice
80726 +
80727 +menu "Default Special Groups"
80728 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
80729 +
80730 +config GRKERNSEC_PROC_GID
80731 + int "GID exempted from /proc restrictions"
80732 + default 1001
80733 + help
80734 + Setting this GID determines which group will be exempted from
80735 + grsecurity's /proc restrictions, allowing users of the specified
80736 + group to view network statistics and the existence of other users'
80737 + processes on the system. This GID may also be chosen at boot time
80738 + via "grsec_proc_gid=" on the kernel commandline.
80739 +
80740 +config GRKERNSEC_TPE_UNTRUSTED_GID
80741 + int "GID for TPE-untrusted users"
80742 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
80743 + default 1005
80744 + help
80745 + Setting this GID determines which group untrusted users should
80746 + be added to. These users will be placed under grsecurity's Trusted Path
80747 + Execution mechanism, preventing them from executing their own binaries.
80748 + The users will only be able to execute binaries in directories owned and
80749 + writable only by the root user. If the sysctl option is enabled, a sysctl
80750 + option with name "tpe_gid" is created.
80751 +
80752 +config GRKERNSEC_TPE_TRUSTED_GID
80753 + int "GID for TPE-trusted users"
80754 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
80755 + default 1005
80756 + help
80757 + Setting this GID determines what group TPE restrictions will be
80758 + *disabled* for. If the sysctl option is enabled, a sysctl option
80759 + with name "tpe_gid" is created.
80760 +
80761 +config GRKERNSEC_SYMLINKOWN_GID
80762 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
80763 + depends on GRKERNSEC_CONFIG_SERVER
80764 + default 1006
80765 + help
80766 + Setting this GID determines what group kernel-enforced
80767 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
80768 + is enabled, a sysctl option with name "symlinkown_gid" is created.
80769 +
80770 +
80771 +endmenu
80772 +
80773 +menu "Customize Configuration"
80774 +depends on GRKERNSEC
80775 +
80776 +menu "PaX"
80777 +
80778 +config PAX
80779 + bool "Enable various PaX features"
80780 + default y if GRKERNSEC_CONFIG_AUTO
80781 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
80782 + help
80783 + This allows you to enable various PaX features. PaX adds
80784 + intrusion prevention mechanisms to the kernel that reduce
80785 + the risks posed by exploitable memory corruption bugs.
80786 +
80787 +menu "PaX Control"
80788 + depends on PAX
80789 +
80790 +config PAX_SOFTMODE
80791 + bool 'Support soft mode'
80792 + help
80793 + Enabling this option will allow you to run PaX in soft mode, that
80794 + is, PaX features will not be enforced by default, only on executables
80795 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
80796 + support as they are the only way to mark executables for soft mode use.
80797 +
80798 + Soft mode can be activated by using the "pax_softmode=1" kernel command
80799 + line option on boot. Furthermore you can control various PaX features
80800 + at runtime via the entries in /proc/sys/kernel/pax.
80801 +
80802 +config PAX_EI_PAX
80803 + bool 'Use legacy ELF header marking'
80804 + default y if GRKERNSEC_CONFIG_AUTO
80805 + help
80806 + Enabling this option will allow you to control PaX features on
80807 + a per executable basis via the 'chpax' utility available at
80808 + http://pax.grsecurity.net/. The control flags will be read from
80809 + an otherwise reserved part of the ELF header. This marking has
80810 + numerous drawbacks (no support for soft-mode, toolchain does not
80811 + know about the non-standard use of the ELF header) therefore it
80812 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
80813 + support.
80814 +
80815 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
80816 + support as well, they will override the legacy EI_PAX marks.
80817 +
80818 + If you enable none of the marking options then all applications
80819 + will run with PaX enabled on them by default.
80820 +
80821 +config PAX_PT_PAX_FLAGS
80822 + bool 'Use ELF program header marking'
80823 + default y if GRKERNSEC_CONFIG_AUTO
80824 + help
80825 + Enabling this option will allow you to control PaX features on
80826 + a per executable basis via the 'paxctl' utility available at
80827 + http://pax.grsecurity.net/. The control flags will be read from
80828 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
80829 + has the benefits of supporting both soft mode and being fully
80830 + integrated into the toolchain (the binutils patch is available
80831 + from http://pax.grsecurity.net).
80832 +
80833 + Note that if you enable the legacy EI_PAX marking support as well,
80834 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
80835 +
80836 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80837 + must make sure that the marks are the same if a binary has both marks.
80838 +
80839 + If you enable none of the marking options then all applications
80840 + will run with PaX enabled on them by default.
80841 +
80842 +config PAX_XATTR_PAX_FLAGS
80843 + bool 'Use filesystem extended attributes marking'
80844 + default y if GRKERNSEC_CONFIG_AUTO
80845 + select CIFS_XATTR if CIFS
80846 + select EXT2_FS_XATTR if EXT2_FS
80847 + select EXT3_FS_XATTR if EXT3_FS
80848 + select EXT4_FS_XATTR if EXT4_FS
80849 + select JFFS2_FS_XATTR if JFFS2_FS
80850 + select REISERFS_FS_XATTR if REISERFS_FS
80851 + select SQUASHFS_XATTR if SQUASHFS
80852 + select TMPFS_XATTR if TMPFS
80853 + select UBIFS_FS_XATTR if UBIFS_FS
80854 + help
80855 + Enabling this option will allow you to control PaX features on
80856 + a per executable basis via the 'setfattr' utility. The control
80857 + flags will be read from the user.pax.flags extended attribute of
80858 + the file. This marking has the benefit of supporting binary-only
80859 + applications that self-check themselves (e.g., skype) and would
80860 + not tolerate chpax/paxctl changes. The main drawback is that
80861 + extended attributes are not supported by some filesystems (e.g.,
80862 + isofs, udf, vfat) so copying files through such filesystems will
80863 + lose the extended attributes and these PaX markings.
80864 +
80865 + Note that if you enable the legacy EI_PAX marking support as well,
80866 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
80867 +
80868 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
80869 + must make sure that the marks are the same if a binary has both marks.
80870 +
80871 + If you enable none of the marking options then all applications
80872 + will run with PaX enabled on them by default.
80873 +
80874 +choice
80875 + prompt 'MAC system integration'
80876 + default PAX_HAVE_ACL_FLAGS
80877 + help
80878 + Mandatory Access Control systems have the option of controlling
80879 + PaX flags on a per executable basis, choose the method supported
80880 + by your particular system.
80881 +
80882 + - "none": if your MAC system does not interact with PaX,
80883 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
80884 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
80885 +
80886 + NOTE: this option is for developers/integrators only.
80887 +
80888 + config PAX_NO_ACL_FLAGS
80889 + bool 'none'
80890 +
80891 + config PAX_HAVE_ACL_FLAGS
80892 + bool 'direct'
80893 +
80894 + config PAX_HOOK_ACL_FLAGS
80895 + bool 'hook'
80896 +endchoice
80897 +
80898 +endmenu
80899 +
80900 +menu "Non-executable pages"
80901 + depends on PAX
80902 +
80903 +config PAX_NOEXEC
80904 + bool "Enforce non-executable pages"
80905 + default y if GRKERNSEC_CONFIG_AUTO
80906 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
80907 + help
80908 + By design some architectures do not allow for protecting memory
80909 + pages against execution or even if they do, Linux does not make
80910 + use of this feature. In practice this means that if a page is
80911 + readable (such as the stack or heap) it is also executable.
80912 +
80913 + There is a well known exploit technique that makes use of this
80914 + fact and a common programming mistake where an attacker can
80915 + introduce code of his choice somewhere in the attacked program's
80916 + memory (typically the stack or the heap) and then execute it.
80917 +
80918 + If the attacked program was running with different (typically
80919 + higher) privileges than that of the attacker, then he can elevate
80920 + his own privilege level (e.g. get a root shell, write to files for
80921 + which he does not have write access to, etc).
80922 +
80923 + Enabling this option will let you choose from various features
80924 + that prevent the injection and execution of 'foreign' code in
80925 + a program.
80926 +
80927 + This will also break programs that rely on the old behaviour and
80928 + expect that dynamically allocated memory via the malloc() family
80929 + of functions is executable (which it is not). Notable examples
80930 + are the XFree86 4.x server, the java runtime and wine.
80931 +
80932 +config PAX_PAGEEXEC
80933 + bool "Paging based non-executable pages"
80934 + default y if GRKERNSEC_CONFIG_AUTO
80935 + 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)
80936 + select S390_SWITCH_AMODE if S390
80937 + select S390_EXEC_PROTECT if S390
80938 + select ARCH_TRACK_EXEC_LIMIT if X86_32
80939 + help
80940 + This implementation is based on the paging feature of the CPU.
80941 + On i386 without hardware non-executable bit support there is a
80942 + variable but usually low performance impact, however on Intel's
80943 + P4 core based CPUs it is very high so you should not enable this
80944 + for kernels meant to be used on such CPUs.
80945 +
80946 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
80947 + with hardware non-executable bit support there is no performance
80948 + impact, on ppc the impact is negligible.
80949 +
80950 + Note that several architectures require various emulations due to
80951 + badly designed userland ABIs, this will cause a performance impact
80952 + but will disappear as soon as userland is fixed. For example, ppc
80953 + userland MUST have been built with secure-plt by a recent toolchain.
80954 +
80955 +config PAX_SEGMEXEC
80956 + bool "Segmentation based non-executable pages"
80957 + default y if GRKERNSEC_CONFIG_AUTO
80958 + depends on PAX_NOEXEC && X86_32
80959 + help
80960 + This implementation is based on the segmentation feature of the
80961 + CPU and has a very small performance impact, however applications
80962 + will be limited to a 1.5 GB address space instead of the normal
80963 + 3 GB.
80964 +
80965 +config PAX_EMUTRAMP
80966 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
80967 + default y if PARISC
80968 + help
80969 + There are some programs and libraries that for one reason or
80970 + another attempt to execute special small code snippets from
80971 + non-executable memory pages. Most notable examples are the
80972 + signal handler return code generated by the kernel itself and
80973 + the GCC trampolines.
80974 +
80975 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
80976 + such programs will no longer work under your kernel.
80977 +
80978 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
80979 + utilities to enable trampoline emulation for the affected programs
80980 + yet still have the protection provided by the non-executable pages.
80981 +
80982 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
80983 + your system will not even boot.
80984 +
80985 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
80986 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
80987 + for the affected files.
80988 +
80989 + NOTE: enabling this feature *may* open up a loophole in the
80990 + protection provided by non-executable pages that an attacker
80991 + could abuse. Therefore the best solution is to not have any
80992 + files on your system that would require this option. This can
80993 + be achieved by not using libc5 (which relies on the kernel
80994 + signal handler return code) and not using or rewriting programs
80995 + that make use of the nested function implementation of GCC.
80996 + Skilled users can just fix GCC itself so that it implements
80997 + nested function calls in a way that does not interfere with PaX.
80998 +
80999 +config PAX_EMUSIGRT
81000 + bool "Automatically emulate sigreturn trampolines"
81001 + depends on PAX_EMUTRAMP && PARISC
81002 + default y
81003 + help
81004 + Enabling this option will have the kernel automatically detect
81005 + and emulate signal return trampolines executing on the stack
81006 + that would otherwise lead to task termination.
81007 +
81008 + This solution is intended as a temporary one for users with
81009 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
81010 + Modula-3 runtime, etc) or executables linked to such, basically
81011 + everything that does not specify its own SA_RESTORER function in
81012 + normal executable memory like glibc 2.1+ does.
81013 +
81014 + On parisc you MUST enable this option, otherwise your system will
81015 + not even boot.
81016 +
81017 + NOTE: this feature cannot be disabled on a per executable basis
81018 + and since it *does* open up a loophole in the protection provided
81019 + by non-executable pages, the best solution is to not have any
81020 + files on your system that would require this option.
81021 +
81022 +config PAX_MPROTECT
81023 + bool "Restrict mprotect()"
81024 + default y if GRKERNSEC_CONFIG_AUTO
81025 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
81026 + help
81027 + Enabling this option will prevent programs from
81028 + - changing the executable status of memory pages that were
81029 + not originally created as executable,
81030 + - making read-only executable pages writable again,
81031 + - creating executable pages from anonymous memory,
81032 + - making read-only-after-relocations (RELRO) data pages writable again.
81033 +
81034 + You should say Y here to complete the protection provided by
81035 + the enforcement of non-executable pages.
81036 +
81037 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81038 + this feature on a per file basis.
81039 +
81040 +config PAX_MPROTECT_COMPAT
81041 + bool "Use legacy/compat protection demoting (read help)"
81042 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81043 + depends on PAX_MPROTECT
81044 + help
81045 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
81046 + by sending the proper error code to the application. For some broken
81047 + userland, this can cause problems with Python or other applications. The
81048 + current implementation however allows for applications like clamav to
81049 + detect if JIT compilation/execution is allowed and to fall back gracefully
81050 + to an interpreter-based mode if it does not. While we encourage everyone
81051 + to use the current implementation as-is and push upstream to fix broken
81052 + userland (note that the RWX logging option can assist with this), in some
81053 + environments this may not be possible. Having to disable MPROTECT
81054 + completely on certain binaries reduces the security benefit of PaX,
81055 + so this option is provided for those environments to revert to the old
81056 + behavior.
81057 +
81058 +config PAX_ELFRELOCS
81059 + bool "Allow ELF text relocations (read help)"
81060 + depends on PAX_MPROTECT
81061 + default n
81062 + help
81063 + Non-executable pages and mprotect() restrictions are effective
81064 + in preventing the introduction of new executable code into an
81065 + attacked task's address space. There remain only two venues
81066 + for this kind of attack: if the attacker can execute already
81067 + existing code in the attacked task then he can either have it
81068 + create and mmap() a file containing his code or have it mmap()
81069 + an already existing ELF library that does not have position
81070 + independent code in it and use mprotect() on it to make it
81071 + writable and copy his code there. While protecting against
81072 + the former approach is beyond PaX, the latter can be prevented
81073 + by having only PIC ELF libraries on one's system (which do not
81074 + need to relocate their code). If you are sure this is your case,
81075 + as is the case with all modern Linux distributions, then leave
81076 + this option disabled. You should say 'n' here.
81077 +
81078 +config PAX_ETEXECRELOCS
81079 + bool "Allow ELF ET_EXEC text relocations"
81080 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
81081 + select PAX_ELFRELOCS
81082 + default y
81083 + help
81084 + On some architectures there are incorrectly created applications
81085 + that require text relocations and would not work without enabling
81086 + this option. If you are an alpha, ia64 or parisc user, you should
81087 + enable this option and disable it once you have made sure that
81088 + none of your applications need it.
81089 +
81090 +config PAX_EMUPLT
81091 + bool "Automatically emulate ELF PLT"
81092 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
81093 + default y
81094 + help
81095 + Enabling this option will have the kernel automatically detect
81096 + and emulate the Procedure Linkage Table entries in ELF files.
81097 + On some architectures such entries are in writable memory, and
81098 + become non-executable leading to task termination. Therefore
81099 + it is mandatory that you enable this option on alpha, parisc,
81100 + sparc and sparc64, otherwise your system would not even boot.
81101 +
81102 + NOTE: this feature *does* open up a loophole in the protection
81103 + provided by the non-executable pages, therefore the proper
81104 + solution is to modify the toolchain to produce a PLT that does
81105 + not need to be writable.
81106 +
81107 +config PAX_DLRESOLVE
81108 + bool 'Emulate old glibc resolver stub'
81109 + depends on PAX_EMUPLT && SPARC
81110 + default n
81111 + help
81112 + This option is needed if userland has an old glibc (before 2.4)
81113 + that puts a 'save' instruction into the runtime generated resolver
81114 + stub that needs special emulation.
81115 +
81116 +config PAX_KERNEXEC
81117 + bool "Enforce non-executable kernel pages"
81118 + 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))
81119 + depends on (PPC || X86) && (!X86_32 || X86_WP_WORKS_OK) && !XEN
81120 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
81121 + select PAX_KERNEXEC_PLUGIN if X86_64
81122 + help
81123 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
81124 + that is, enabling this option will make it harder to inject
81125 + and execute 'foreign' code in kernel memory itself.
81126 +
81127 +choice
81128 + prompt "Return Address Instrumentation Method"
81129 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
81130 + depends on PAX_KERNEXEC_PLUGIN
81131 + help
81132 + Select the method used to instrument function pointer dereferences.
81133 + Note that binary modules cannot be instrumented by this approach.
81134 +
81135 + Note that the implementation requires a gcc with plugin support,
81136 + i.e., gcc 4.5 or newer. You may need to install the supporting
81137 + headers explicitly in addition to the normal gcc package.
81138 +
81139 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
81140 + bool "bts"
81141 + help
81142 + This method is compatible with binary only modules but has
81143 + a higher runtime overhead.
81144 +
81145 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
81146 + bool "or"
81147 + depends on !PARAVIRT
81148 + help
81149 + This method is incompatible with binary only modules but has
81150 + a lower runtime overhead.
81151 +endchoice
81152 +
81153 +config PAX_KERNEXEC_PLUGIN_METHOD
81154 + string
81155 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
81156 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
81157 + default ""
81158 +
81159 +config PAX_KERNEXEC_MODULE_TEXT
81160 + int "Minimum amount of memory reserved for module code"
81161 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
81162 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
81163 + depends on PAX_KERNEXEC && X86_32 && MODULES
81164 + help
81165 + Due to implementation details the kernel must reserve a fixed
81166 + amount of memory for module code at compile time that cannot be
81167 + changed at runtime. Here you can specify the minimum amount
81168 + in MB that will be reserved. Due to the same implementation
81169 + details this size will always be rounded up to the next 2/4 MB
81170 + boundary (depends on PAE) so the actually available memory for
81171 + module code will usually be more than this minimum.
81172 +
81173 + The default 4 MB should be enough for most users but if you have
81174 + an excessive number of modules (e.g., most distribution configs
81175 + compile many drivers as modules) or use huge modules such as
81176 + nvidia's kernel driver, you will need to adjust this amount.
81177 + A good rule of thumb is to look at your currently loaded kernel
81178 + modules and add up their sizes.
81179 +
81180 +endmenu
81181 +
81182 +menu "Address Space Layout Randomization"
81183 + depends on PAX
81184 +
81185 +config PAX_ASLR
81186 + bool "Address Space Layout Randomization"
81187 + default y if GRKERNSEC_CONFIG_AUTO
81188 + help
81189 + Many if not most exploit techniques rely on the knowledge of
81190 + certain addresses in the attacked program. The following options
81191 + will allow the kernel to apply a certain amount of randomization
81192 + to specific parts of the program thereby forcing an attacker to
81193 + guess them in most cases. Any failed guess will most likely crash
81194 + the attacked program which allows the kernel to detect such attempts
81195 + and react on them. PaX itself provides no reaction mechanisms,
81196 + instead it is strongly encouraged that you make use of Nergal's
81197 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
81198 + (http://www.grsecurity.net/) built-in crash detection features or
81199 + develop one yourself.
81200 +
81201 + By saying Y here you can choose to randomize the following areas:
81202 + - top of the task's kernel stack
81203 + - top of the task's userland stack
81204 + - base address for mmap() requests that do not specify one
81205 + (this includes all libraries)
81206 + - base address of the main executable
81207 +
81208 + It is strongly recommended to say Y here as address space layout
81209 + randomization has negligible impact on performance yet it provides
81210 + a very effective protection.
81211 +
81212 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
81213 + this feature on a per file basis.
81214 +
81215 +config PAX_RANDKSTACK
81216 + bool "Randomize kernel stack base"
81217 + default y if GRKERNSEC_CONFIG_AUTO
81218 + depends on X86_TSC && X86
81219 + help
81220 + By saying Y here the kernel will randomize every task's kernel
81221 + stack on every system call. This will not only force an attacker
81222 + to guess it but also prevent him from making use of possible
81223 + leaked information about it.
81224 +
81225 + Since the kernel stack is a rather scarce resource, randomization
81226 + may cause unexpected stack overflows, therefore you should very
81227 + carefully test your system. Note that once enabled in the kernel
81228 + configuration, this feature cannot be disabled on a per file basis.
81229 +
81230 +config PAX_RANDUSTACK
81231 + bool "Randomize user stack base"
81232 + default y if GRKERNSEC_CONFIG_AUTO
81233 + depends on PAX_ASLR
81234 + help
81235 + By saying Y here the kernel will randomize every task's userland
81236 + stack. The randomization is done in two steps where the second
81237 + one may apply a big amount of shift to the top of the stack and
81238 + cause problems for programs that want to use lots of memory (more
81239 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
81240 + For this reason the second step can be controlled by 'chpax' or
81241 + 'paxctl' on a per file basis.
81242 +
81243 +config PAX_RANDMMAP
81244 + bool "Randomize mmap() base"
81245 + default y if GRKERNSEC_CONFIG_AUTO
81246 + depends on PAX_ASLR
81247 + help
81248 + By saying Y here the kernel will use a randomized base address for
81249 + mmap() requests that do not specify one themselves. As a result
81250 + all dynamically loaded libraries will appear at random addresses
81251 + and therefore be harder to exploit by a technique where an attacker
81252 + attempts to execute library code for his purposes (e.g. spawn a
81253 + shell from an exploited program that is running at an elevated
81254 + privilege level).
81255 +
81256 + Furthermore, if a program is relinked as a dynamic ELF file, its
81257 + base address will be randomized as well, completing the full
81258 + randomization of the address space layout. Attacking such programs
81259 + becomes a guess game. You can find an example of doing this at
81260 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
81261 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
81262 +
81263 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
81264 + feature on a per file basis.
81265 +
81266 +endmenu
81267 +
81268 +menu "Miscellaneous hardening features"
81269 +
81270 +config PAX_MEMORY_SANITIZE
81271 + bool "Sanitize all freed memory"
81272 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81273 + depends on !HIBERNATION
81274 + help
81275 + By saying Y here the kernel will erase memory pages as soon as they
81276 + are freed. This in turn reduces the lifetime of data stored in the
81277 + pages, making it less likely that sensitive information such as
81278 + passwords, cryptographic secrets, etc stay in memory for too long.
81279 +
81280 + This is especially useful for programs whose runtime is short, long
81281 + lived processes and the kernel itself benefit from this as long as
81282 + they operate on whole memory pages and ensure timely freeing of pages
81283 + that may hold sensitive information.
81284 +
81285 + The tradeoff is performance impact, on a single CPU system kernel
81286 + compilation sees a 3% slowdown, other systems and workloads may vary
81287 + and you are advised to test this feature on your expected workload
81288 + before deploying it.
81289 +
81290 + Note that this feature does not protect data stored in live pages,
81291 + e.g., process memory swapped to disk may stay there for a long time.
81292 +
81293 +config PAX_MEMORY_STACKLEAK
81294 + bool "Sanitize kernel stack"
81295 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
81296 + depends on X86
81297 + help
81298 + By saying Y here the kernel will erase the kernel stack before it
81299 + returns from a system call. This in turn reduces the information
81300 + that a kernel stack leak bug can reveal.
81301 +
81302 + Note that such a bug can still leak information that was put on
81303 + the stack by the current system call (the one eventually triggering
81304 + the bug) but traces of earlier system calls on the kernel stack
81305 + cannot leak anymore.
81306 +
81307 + The tradeoff is performance impact: on a single CPU system kernel
81308 + compilation sees a 1% slowdown, other systems and workloads may vary
81309 + and you are advised to test this feature on your expected workload
81310 + before deploying it.
81311 +
81312 + Note that the full feature requires a gcc with plugin support,
81313 + i.e., gcc 4.5 or newer. You may need to install the supporting
81314 + headers explicitly in addition to the normal gcc package. Using
81315 + older gcc versions means that functions with large enough stack
81316 + frames may leave uninitialized memory behind that may be exposed
81317 + to a later syscall leaking the stack.
81318 +
81319 +config PAX_MEMORY_UDEREF
81320 + bool "Prevent invalid userland pointer dereference"
81321 + default y if GRKERNSEC_CONFIG_AUTO && (X86_32 || (X86_64 && GRKERNSEC_CONFIG_PRIORITY_SECURITY)) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
81322 + depends on X86 && !UML_X86 && !XEN
81323 + select PAX_PER_CPU_PGD if X86_64
81324 + help
81325 + By saying Y here the kernel will be prevented from dereferencing
81326 + userland pointers in contexts where the kernel expects only kernel
81327 + pointers. This is both a useful runtime debugging feature and a
81328 + security measure that prevents exploiting a class of kernel bugs.
81329 +
81330 + The tradeoff is that some virtualization solutions may experience
81331 + a huge slowdown and therefore you should not enable this feature
81332 + for kernels meant to run in such environments. Whether a given VM
81333 + solution is affected or not is best determined by simply trying it
81334 + out, the performance impact will be obvious right on boot as this
81335 + mechanism engages from very early on. A good rule of thumb is that
81336 + VMs running on CPUs without hardware virtualization support (i.e.,
81337 + the majority of IA-32 CPUs) will likely experience the slowdown.
81338 +
81339 +config PAX_REFCOUNT
81340 + bool "Prevent various kernel object reference counter overflows"
81341 + default y if GRKERNSEC_CONFIG_AUTO
81342 + depends on GRKERNSEC && ((ARM && (CPU_32v6 || CPU_32v6K || CPU_32v7)) || SPARC64 || X86)
81343 + help
81344 + By saying Y here the kernel will detect and prevent overflowing
81345 + various (but not all) kinds of object reference counters. Such
81346 + overflows can normally occur due to bugs only and are often, if
81347 + not always, exploitable.
81348 +
81349 + The tradeoff is that data structures protected by an overflowed
81350 + refcount will never be freed and therefore will leak memory. Note
81351 + that this leak also happens even without this protection but in
81352 + that case the overflow can eventually trigger the freeing of the
81353 + data structure while it is still being used elsewhere, resulting
81354 + in the exploitable situation that this feature prevents.
81355 +
81356 + Since this has a negligible performance impact, you should enable
81357 + this feature.
81358 +
81359 +config PAX_USERCOPY
81360 + bool "Harden heap object copies between kernel and userland"
81361 + default y if GRKERNSEC_CONFIG_AUTO
81362 + depends on X86 || PPC || SPARC || ARM
81363 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
81364 + select PAX_USERCOPY_SLABS
81365 + help
81366 + By saying Y here the kernel will enforce the size of heap objects
81367 + when they are copied in either direction between the kernel and
81368 + userland, even if only a part of the heap object is copied.
81369 +
81370 + Specifically, this checking prevents information leaking from the
81371 + kernel heap during kernel to userland copies (if the kernel heap
81372 + object is otherwise fully initialized) and prevents kernel heap
81373 + overflows during userland to kernel copies.
81374 +
81375 + Note that the current implementation provides the strictest bounds
81376 + checks for the SLUB allocator.
81377 +
81378 + Enabling this option also enables per-slab cache protection against
81379 + data in a given cache being copied into/out of via userland
81380 + accessors. Though the whitelist of regions will be reduced over
81381 + time, it notably protects important data structures like task structs.
81382 +
81383 + If frame pointers are enabled on x86, this option will also restrict
81384 + copies into and out of the kernel stack to local variables within a
81385 + single frame.
81386 +
81387 + Since this has a negligible performance impact, you should enable
81388 + this feature.
81389 +
81390 +config PAX_SIZE_OVERFLOW
81391 + bool "Prevent various integer overflows in function size parameters"
81392 + default y if GRKERNSEC_CONFIG_AUTO
81393 + depends on X86
81394 + help
81395 + By saying Y here the kernel recomputes expressions of function
81396 + arguments marked by a size_overflow attribute with double integer
81397 + precision (DImode/TImode for 32/64 bit integer types).
81398 +
81399 + The recomputed argument is checked against TYPE_MAX and an event
81400 + is logged on overflow and the triggering process is killed.
81401 +
81402 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
81403 +
81404 + Note that the implementation requires a gcc with plugin support,
81405 + i.e., gcc 4.5 or newer. You may need to install the supporting
81406 + headers explicitly in addition to the normal gcc package.
81407 +
81408 +config PAX_LATENT_ENTROPY
81409 + bool "Generate some entropy during boot"
81410 + default y if GRKERNSEC_CONFIG_AUTO
81411 + help
81412 + By saying Y here the kernel will instrument early boot code to
81413 + extract some entropy from both original and artificially created
81414 + program state. This will help especially embedded systems where
81415 + there is little 'natural' source of entropy normally. The cost
81416 + is some slowdown of the boot process.
81417 +
81418 + Note that the implementation requires a gcc with plugin support,
81419 + i.e., gcc 4.5 or newer. You may need to install the supporting
81420 + headers explicitly in addition to the normal gcc package.
81421 +
81422 + Note that entropy extracted this way is not cryptographically
81423 + secure!
81424 +
81425 +endmenu
81426 +
81427 +endmenu
81428 +
81429 +source grsecurity/Kconfig
81430 +
81431 +endmenu
81432 +
81433 +endmenu
81434 +
81435 source security/keys/Kconfig
81436
81437 config SECURITY_DMESG_RESTRICT
81438 @@ -103,7 +993,7 @@ config INTEL_TXT
81439 config LSM_MMAP_MIN_ADDR
81440 int "Low address space for LSM to protect from user allocation"
81441 depends on SECURITY && SECURITY_SELINUX
81442 - default 32768 if ARM
81443 + default 32768 if ALPHA || ARM || PARISC || SPARC32
81444 default 65536
81445 help
81446 This is the portion of low virtual memory which should be protected
81447 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
81448 index 8ea39aa..8569ac5 100644
81449 --- a/security/apparmor/lsm.c
81450 +++ b/security/apparmor/lsm.c
81451 @@ -614,7 +614,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
81452 return error;
81453 }
81454
81455 -static struct security_operations apparmor_ops = {
81456 +static struct security_operations apparmor_ops __read_only = {
81457 .name = "apparmor",
81458
81459 .ptrace_access_check = apparmor_ptrace_access_check,
81460 diff --git a/security/commoncap.c b/security/commoncap.c
81461 index 6dbae46..d5611fd 100644
81462 --- a/security/commoncap.c
81463 +++ b/security/commoncap.c
81464 @@ -415,6 +415,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
81465 return 0;
81466 }
81467
81468 +/* returns:
81469 + 1 for suid privilege
81470 + 2 for sgid privilege
81471 + 3 for fscap privilege
81472 +*/
81473 +int is_privileged_binary(const struct dentry *dentry)
81474 +{
81475 + struct cpu_vfs_cap_data capdata;
81476 + struct inode *inode = dentry->d_inode;
81477 +
81478 + if (!inode || S_ISDIR(inode->i_mode))
81479 + return 0;
81480 +
81481 + if (inode->i_mode & S_ISUID)
81482 + return 1;
81483 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
81484 + return 2;
81485 +
81486 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
81487 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
81488 + return 3;
81489 + }
81490 +
81491 + return 0;
81492 +}
81493 +
81494 /*
81495 * Attempt to get the on-exec apply capability sets for an executable file from
81496 * its xattrs and, if present, apply them to the proposed credentials being
81497 @@ -583,6 +609,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
81498 const struct cred *cred = current_cred();
81499 kuid_t root_uid = make_kuid(cred->user_ns, 0);
81500
81501 + if (gr_acl_enable_at_secure())
81502 + return 1;
81503 +
81504 if (!uid_eq(cred->uid, root_uid)) {
81505 if (bprm->cap_effective)
81506 return 1;
81507 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
81508 index 3ccf7ac..d73ad64 100644
81509 --- a/security/integrity/ima/ima.h
81510 +++ b/security/integrity/ima/ima.h
81511 @@ -86,8 +86,8 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81512 extern spinlock_t ima_queue_lock;
81513
81514 struct ima_h_table {
81515 - atomic_long_t len; /* number of stored measurements in the list */
81516 - atomic_long_t violations;
81517 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
81518 + atomic_long_unchecked_t violations;
81519 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
81520 };
81521 extern struct ima_h_table ima_htable;
81522 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
81523 index 88a2788..581ab92 100644
81524 --- a/security/integrity/ima/ima_api.c
81525 +++ b/security/integrity/ima/ima_api.c
81526 @@ -75,7 +75,7 @@ void ima_add_violation(struct inode *inode, const unsigned char *filename,
81527 int result;
81528
81529 /* can overflow, only indicator */
81530 - atomic_long_inc(&ima_htable.violations);
81531 + atomic_long_inc_unchecked(&ima_htable.violations);
81532
81533 entry = kmalloc(sizeof(*entry), GFP_KERNEL);
81534 if (!entry) {
81535 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
81536 index e1aa2b4..52027bf 100644
81537 --- a/security/integrity/ima/ima_fs.c
81538 +++ b/security/integrity/ima/ima_fs.c
81539 @@ -28,12 +28,12 @@
81540 static int valid_policy = 1;
81541 #define TMPBUFLEN 12
81542 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
81543 - loff_t *ppos, atomic_long_t *val)
81544 + loff_t *ppos, atomic_long_unchecked_t *val)
81545 {
81546 char tmpbuf[TMPBUFLEN];
81547 ssize_t len;
81548
81549 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
81550 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
81551 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
81552 }
81553
81554 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
81555 index 55a6271..ad829c3 100644
81556 --- a/security/integrity/ima/ima_queue.c
81557 +++ b/security/integrity/ima/ima_queue.c
81558 @@ -81,7 +81,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
81559 INIT_LIST_HEAD(&qe->later);
81560 list_add_tail_rcu(&qe->later, &ima_measurements);
81561
81562 - atomic_long_inc(&ima_htable.len);
81563 + atomic_long_inc_unchecked(&ima_htable.len);
81564 key = ima_hash_key(entry->digest);
81565 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
81566 return 0;
81567 diff --git a/security/keys/compat.c b/security/keys/compat.c
81568 index c92d42b..341e7ea 100644
81569 --- a/security/keys/compat.c
81570 +++ b/security/keys/compat.c
81571 @@ -44,7 +44,7 @@ long compat_keyctl_instantiate_key_iov(
81572 if (ret == 0)
81573 goto no_payload_free;
81574
81575 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81576 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81577
81578 if (iov != iovstack)
81579 kfree(iov);
81580 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
81581 index 0f5b3f0..b8d47c1 100644
81582 --- a/security/keys/keyctl.c
81583 +++ b/security/keys/keyctl.c
81584 @@ -966,7 +966,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
81585 /*
81586 * Copy the iovec data from userspace
81587 */
81588 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81589 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
81590 unsigned ioc)
81591 {
81592 for (; ioc > 0; ioc--) {
81593 @@ -988,7 +988,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
81594 * If successful, 0 will be returned.
81595 */
81596 long keyctl_instantiate_key_common(key_serial_t id,
81597 - const struct iovec *payload_iov,
81598 + const struct iovec __user *payload_iov,
81599 unsigned ioc,
81600 size_t plen,
81601 key_serial_t ringid)
81602 @@ -1083,7 +1083,7 @@ long keyctl_instantiate_key(key_serial_t id,
81603 [0].iov_len = plen
81604 };
81605
81606 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
81607 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
81608 }
81609
81610 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
81611 @@ -1116,7 +1116,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
81612 if (ret == 0)
81613 goto no_payload_free;
81614
81615 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
81616 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
81617
81618 if (iov != iovstack)
81619 kfree(iov);
81620 diff --git a/security/keys/keyring.c b/security/keys/keyring.c
81621 index 7445875..262834f 100644
81622 --- a/security/keys/keyring.c
81623 +++ b/security/keys/keyring.c
81624 @@ -227,16 +227,16 @@ static long keyring_read(const struct key *keyring,
81625 ret = -EFAULT;
81626
81627 for (loop = 0; loop < klist->nkeys; loop++) {
81628 + key_serial_t serial;
81629 key = rcu_deref_link_locked(klist, loop,
81630 keyring);
81631 + serial = key->serial;
81632
81633 tmp = sizeof(key_serial_t);
81634 if (tmp > buflen)
81635 tmp = buflen;
81636
81637 - if (copy_to_user(buffer,
81638 - &key->serial,
81639 - tmp) != 0)
81640 + if (copy_to_user(buffer, &serial, tmp))
81641 goto error;
81642
81643 buflen -= tmp;
81644 diff --git a/security/min_addr.c b/security/min_addr.c
81645 index f728728..6457a0c 100644
81646 --- a/security/min_addr.c
81647 +++ b/security/min_addr.c
81648 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
81649 */
81650 static void update_mmap_min_addr(void)
81651 {
81652 +#ifndef SPARC
81653 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
81654 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
81655 mmap_min_addr = dac_mmap_min_addr;
81656 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
81657 #else
81658 mmap_min_addr = dac_mmap_min_addr;
81659 #endif
81660 +#endif
81661 }
81662
81663 /*
81664 diff --git a/security/security.c b/security/security.c
81665 index 860aeb3..45765c0 100644
81666 --- a/security/security.c
81667 +++ b/security/security.c
81668 @@ -20,6 +20,7 @@
81669 #include <linux/ima.h>
81670 #include <linux/evm.h>
81671 #include <linux/fsnotify.h>
81672 +#include <linux/mm.h>
81673 #include <linux/mman.h>
81674 #include <linux/mount.h>
81675 #include <linux/personality.h>
81676 @@ -32,8 +33,8 @@
81677 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
81678 CONFIG_DEFAULT_SECURITY;
81679
81680 -static struct security_operations *security_ops;
81681 -static struct security_operations default_security_ops = {
81682 +static struct security_operations *security_ops __read_only;
81683 +static struct security_operations default_security_ops __read_only = {
81684 .name = "default",
81685 };
81686
81687 @@ -74,7 +75,9 @@ int __init security_init(void)
81688
81689 void reset_security_ops(void)
81690 {
81691 + pax_open_kernel();
81692 security_ops = &default_security_ops;
81693 + pax_close_kernel();
81694 }
81695
81696 /* Save user chosen LSM */
81697 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
81698 index db10db2..99a640f 100644
81699 --- a/security/selinux/hooks.c
81700 +++ b/security/selinux/hooks.c
81701 @@ -95,8 +95,6 @@
81702
81703 #define NUM_SEL_MNT_OPTS 5
81704
81705 -extern struct security_operations *security_ops;
81706 -
81707 /* SECMARK reference count */
81708 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
81709
81710 @@ -5511,7 +5509,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
81711
81712 #endif
81713
81714 -static struct security_operations selinux_ops = {
81715 +static struct security_operations selinux_ops __read_only = {
81716 .name = "selinux",
81717
81718 .ptrace_access_check = selinux_ptrace_access_check,
81719 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
81720 index c220f31..89fab3f 100644
81721 --- a/security/selinux/include/xfrm.h
81722 +++ b/security/selinux/include/xfrm.h
81723 @@ -50,7 +50,7 @@ int selinux_xfrm_decode_session(struct sk_buff *skb, u32 *sid, int ckall);
81724
81725 static inline void selinux_xfrm_notify_policyload(void)
81726 {
81727 - atomic_inc(&flow_cache_genid);
81728 + atomic_inc_unchecked(&flow_cache_genid);
81729 }
81730 #else
81731 static inline int selinux_xfrm_enabled(void)
81732 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
81733 index ee0bb57..57fcd43 100644
81734 --- a/security/smack/smack_lsm.c
81735 +++ b/security/smack/smack_lsm.c
81736 @@ -3432,7 +3432,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
81737 return 0;
81738 }
81739
81740 -struct security_operations smack_ops = {
81741 +struct security_operations smack_ops __read_only = {
81742 .name = "smack",
81743
81744 .ptrace_access_check = smack_ptrace_access_check,
81745 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
81746 index c2d04a5..e6a1aeb 100644
81747 --- a/security/tomoyo/tomoyo.c
81748 +++ b/security/tomoyo/tomoyo.c
81749 @@ -501,7 +501,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
81750 * tomoyo_security_ops is a "struct security_operations" which is used for
81751 * registering TOMOYO.
81752 */
81753 -static struct security_operations tomoyo_security_ops = {
81754 +static struct security_operations tomoyo_security_ops __read_only = {
81755 .name = "tomoyo",
81756 .cred_alloc_blank = tomoyo_cred_alloc_blank,
81757 .cred_prepare = tomoyo_cred_prepare,
81758 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
81759 index 51d6709..1f3dbe2 100644
81760 --- a/security/yama/Kconfig
81761 +++ b/security/yama/Kconfig
81762 @@ -1,6 +1,6 @@
81763 config SECURITY_YAMA
81764 bool "Yama support"
81765 - depends on SECURITY
81766 + depends on SECURITY && !GRKERNSEC
81767 select SECURITYFS
81768 select SECURITY_PATH
81769 default n
81770 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
81771 index 4cedc69..e59d8a3 100644
81772 --- a/sound/aoa/codecs/onyx.c
81773 +++ b/sound/aoa/codecs/onyx.c
81774 @@ -54,7 +54,7 @@ struct onyx {
81775 spdif_locked:1,
81776 analog_locked:1,
81777 original_mute:2;
81778 - int open_count;
81779 + local_t open_count;
81780 struct codec_info *codec_info;
81781
81782 /* mutex serializes concurrent access to the device
81783 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
81784 struct onyx *onyx = cii->codec_data;
81785
81786 mutex_lock(&onyx->mutex);
81787 - onyx->open_count++;
81788 + local_inc(&onyx->open_count);
81789 mutex_unlock(&onyx->mutex);
81790
81791 return 0;
81792 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
81793 struct onyx *onyx = cii->codec_data;
81794
81795 mutex_lock(&onyx->mutex);
81796 - onyx->open_count--;
81797 - if (!onyx->open_count)
81798 + if (local_dec_and_test(&onyx->open_count))
81799 onyx->spdif_locked = onyx->analog_locked = 0;
81800 mutex_unlock(&onyx->mutex);
81801
81802 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
81803 index ffd2025..df062c9 100644
81804 --- a/sound/aoa/codecs/onyx.h
81805 +++ b/sound/aoa/codecs/onyx.h
81806 @@ -11,6 +11,7 @@
81807 #include <linux/i2c.h>
81808 #include <asm/pmac_low_i2c.h>
81809 #include <asm/prom.h>
81810 +#include <asm/local.h>
81811
81812 /* PCM3052 register definitions */
81813
81814 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
81815 index 08fde00..0bf641a 100644
81816 --- a/sound/core/oss/pcm_oss.c
81817 +++ b/sound/core/oss/pcm_oss.c
81818 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
81819 if (in_kernel) {
81820 mm_segment_t fs;
81821 fs = snd_enter_user();
81822 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81823 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81824 snd_leave_user(fs);
81825 } else {
81826 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
81827 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
81828 }
81829 if (ret != -EPIPE && ret != -ESTRPIPE)
81830 break;
81831 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
81832 if (in_kernel) {
81833 mm_segment_t fs;
81834 fs = snd_enter_user();
81835 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81836 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81837 snd_leave_user(fs);
81838 } else {
81839 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
81840 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
81841 }
81842 if (ret == -EPIPE) {
81843 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
81844 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
81845 struct snd_pcm_plugin_channel *channels;
81846 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
81847 if (!in_kernel) {
81848 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
81849 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
81850 return -EFAULT;
81851 buf = runtime->oss.buffer;
81852 }
81853 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
81854 }
81855 } else {
81856 tmp = snd_pcm_oss_write2(substream,
81857 - (const char __force *)buf,
81858 + (const char __force_kernel *)buf,
81859 runtime->oss.period_bytes, 0);
81860 if (tmp <= 0)
81861 goto err;
81862 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
81863 struct snd_pcm_runtime *runtime = substream->runtime;
81864 snd_pcm_sframes_t frames, frames1;
81865 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
81866 - char __user *final_dst = (char __force __user *)buf;
81867 + char __user *final_dst = (char __force_user *)buf;
81868 if (runtime->oss.plugin_first) {
81869 struct snd_pcm_plugin_channel *channels;
81870 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
81871 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
81872 xfer += tmp;
81873 runtime->oss.buffer_used -= tmp;
81874 } else {
81875 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
81876 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
81877 runtime->oss.period_bytes, 0);
81878 if (tmp <= 0)
81879 goto err;
81880 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
81881 size1);
81882 size1 /= runtime->channels; /* frames */
81883 fs = snd_enter_user();
81884 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
81885 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
81886 snd_leave_user(fs);
81887 }
81888 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
81889 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
81890 index 91cdf94..4085161 100644
81891 --- a/sound/core/pcm_compat.c
81892 +++ b/sound/core/pcm_compat.c
81893 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
81894 int err;
81895
81896 fs = snd_enter_user();
81897 - err = snd_pcm_delay(substream, &delay);
81898 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
81899 snd_leave_user(fs);
81900 if (err < 0)
81901 return err;
81902 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
81903 index 53b5ada..2db94c8 100644
81904 --- a/sound/core/pcm_native.c
81905 +++ b/sound/core/pcm_native.c
81906 @@ -2780,11 +2780,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
81907 switch (substream->stream) {
81908 case SNDRV_PCM_STREAM_PLAYBACK:
81909 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
81910 - (void __user *)arg);
81911 + (void __force_user *)arg);
81912 break;
81913 case SNDRV_PCM_STREAM_CAPTURE:
81914 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
81915 - (void __user *)arg);
81916 + (void __force_user *)arg);
81917 break;
81918 default:
81919 result = -EINVAL;
81920 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
81921 index 5cf8d65..912a79c 100644
81922 --- a/sound/core/seq/seq_device.c
81923 +++ b/sound/core/seq/seq_device.c
81924 @@ -64,7 +64,7 @@ struct ops_list {
81925 int argsize; /* argument size */
81926
81927 /* operators */
81928 - struct snd_seq_dev_ops ops;
81929 + struct snd_seq_dev_ops *ops;
81930
81931 /* registred devices */
81932 struct list_head dev_list; /* list of devices */
81933 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
81934
81935 mutex_lock(&ops->reg_mutex);
81936 /* copy driver operators */
81937 - ops->ops = *entry;
81938 + ops->ops = entry;
81939 ops->driver |= DRIVER_LOADED;
81940 ops->argsize = argsize;
81941
81942 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
81943 dev->name, ops->id, ops->argsize, dev->argsize);
81944 return -EINVAL;
81945 }
81946 - if (ops->ops.init_device(dev) >= 0) {
81947 + if (ops->ops->init_device(dev) >= 0) {
81948 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
81949 ops->num_init_devices++;
81950 } else {
81951 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
81952 dev->name, ops->id, ops->argsize, dev->argsize);
81953 return -EINVAL;
81954 }
81955 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
81956 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
81957 dev->status = SNDRV_SEQ_DEVICE_FREE;
81958 dev->driver_data = NULL;
81959 ops->num_init_devices--;
81960 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
81961 index 621e60e..f4543f5 100644
81962 --- a/sound/drivers/mts64.c
81963 +++ b/sound/drivers/mts64.c
81964 @@ -29,6 +29,7 @@
81965 #include <sound/initval.h>
81966 #include <sound/rawmidi.h>
81967 #include <sound/control.h>
81968 +#include <asm/local.h>
81969
81970 #define CARD_NAME "Miditerminal 4140"
81971 #define DRIVER_NAME "MTS64"
81972 @@ -67,7 +68,7 @@ struct mts64 {
81973 struct pardevice *pardev;
81974 int pardev_claimed;
81975
81976 - int open_count;
81977 + local_t open_count;
81978 int current_midi_output_port;
81979 int current_midi_input_port;
81980 u8 mode[MTS64_NUM_INPUT_PORTS];
81981 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81982 {
81983 struct mts64 *mts = substream->rmidi->private_data;
81984
81985 - if (mts->open_count == 0) {
81986 + if (local_read(&mts->open_count) == 0) {
81987 /* We don't need a spinlock here, because this is just called
81988 if the device has not been opened before.
81989 So there aren't any IRQs from the device */
81990 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
81991
81992 msleep(50);
81993 }
81994 - ++(mts->open_count);
81995 + local_inc(&mts->open_count);
81996
81997 return 0;
81998 }
81999 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82000 struct mts64 *mts = substream->rmidi->private_data;
82001 unsigned long flags;
82002
82003 - --(mts->open_count);
82004 - if (mts->open_count == 0) {
82005 + if (local_dec_return(&mts->open_count) == 0) {
82006 /* We need the spinlock_irqsave here because we can still
82007 have IRQs at this point */
82008 spin_lock_irqsave(&mts->lock, flags);
82009 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
82010
82011 msleep(500);
82012
82013 - } else if (mts->open_count < 0)
82014 - mts->open_count = 0;
82015 + } else if (local_read(&mts->open_count) < 0)
82016 + local_set(&mts->open_count, 0);
82017
82018 return 0;
82019 }
82020 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
82021 index b953fb4..1999c01 100644
82022 --- a/sound/drivers/opl4/opl4_lib.c
82023 +++ b/sound/drivers/opl4/opl4_lib.c
82024 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
82025 MODULE_DESCRIPTION("OPL4 driver");
82026 MODULE_LICENSE("GPL");
82027
82028 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
82029 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
82030 {
82031 int timeout = 10;
82032 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
82033 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
82034 index 3e32bd3..46fc152 100644
82035 --- a/sound/drivers/portman2x4.c
82036 +++ b/sound/drivers/portman2x4.c
82037 @@ -48,6 +48,7 @@
82038 #include <sound/initval.h>
82039 #include <sound/rawmidi.h>
82040 #include <sound/control.h>
82041 +#include <asm/local.h>
82042
82043 #define CARD_NAME "Portman 2x4"
82044 #define DRIVER_NAME "portman"
82045 @@ -85,7 +86,7 @@ struct portman {
82046 struct pardevice *pardev;
82047 int pardev_claimed;
82048
82049 - int open_count;
82050 + local_t open_count;
82051 int mode[PORTMAN_NUM_INPUT_PORTS];
82052 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
82053 };
82054 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
82055 index ea995af..f1bfa37 100644
82056 --- a/sound/firewire/amdtp.c
82057 +++ b/sound/firewire/amdtp.c
82058 @@ -389,7 +389,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
82059 ptr = s->pcm_buffer_pointer + data_blocks;
82060 if (ptr >= pcm->runtime->buffer_size)
82061 ptr -= pcm->runtime->buffer_size;
82062 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
82063 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
82064
82065 s->pcm_period_pointer += data_blocks;
82066 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
82067 @@ -557,7 +557,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
82068 */
82069 void amdtp_out_stream_update(struct amdtp_out_stream *s)
82070 {
82071 - ACCESS_ONCE(s->source_node_id_field) =
82072 + ACCESS_ONCE_RW(s->source_node_id_field) =
82073 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
82074 }
82075 EXPORT_SYMBOL(amdtp_out_stream_update);
82076 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
82077 index b680c5e..061b7a0 100644
82078 --- a/sound/firewire/amdtp.h
82079 +++ b/sound/firewire/amdtp.h
82080 @@ -139,7 +139,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
82081 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
82082 struct snd_pcm_substream *pcm)
82083 {
82084 - ACCESS_ONCE(s->pcm) = pcm;
82085 + ACCESS_ONCE_RW(s->pcm) = pcm;
82086 }
82087
82088 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
82089 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
82090 index d428ffe..751ef78 100644
82091 --- a/sound/firewire/isight.c
82092 +++ b/sound/firewire/isight.c
82093 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
82094 ptr += count;
82095 if (ptr >= runtime->buffer_size)
82096 ptr -= runtime->buffer_size;
82097 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
82098 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
82099
82100 isight->period_counter += count;
82101 if (isight->period_counter >= runtime->period_size) {
82102 @@ -307,7 +307,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
82103 if (err < 0)
82104 return err;
82105
82106 - ACCESS_ONCE(isight->pcm_active) = true;
82107 + ACCESS_ONCE_RW(isight->pcm_active) = true;
82108
82109 return 0;
82110 }
82111 @@ -340,7 +340,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
82112 {
82113 struct isight *isight = substream->private_data;
82114
82115 - ACCESS_ONCE(isight->pcm_active) = false;
82116 + ACCESS_ONCE_RW(isight->pcm_active) = false;
82117
82118 mutex_lock(&isight->mutex);
82119 isight_stop_streaming(isight);
82120 @@ -433,10 +433,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
82121
82122 switch (cmd) {
82123 case SNDRV_PCM_TRIGGER_START:
82124 - ACCESS_ONCE(isight->pcm_running) = true;
82125 + ACCESS_ONCE_RW(isight->pcm_running) = true;
82126 break;
82127 case SNDRV_PCM_TRIGGER_STOP:
82128 - ACCESS_ONCE(isight->pcm_running) = false;
82129 + ACCESS_ONCE_RW(isight->pcm_running) = false;
82130 break;
82131 default:
82132 return -EINVAL;
82133 diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
82134 index 7bd5e33..1fcab12 100644
82135 --- a/sound/isa/cmi8330.c
82136 +++ b/sound/isa/cmi8330.c
82137 @@ -172,7 +172,7 @@ struct snd_cmi8330 {
82138
82139 struct snd_pcm *pcm;
82140 struct snd_cmi8330_stream {
82141 - struct snd_pcm_ops ops;
82142 + snd_pcm_ops_no_const ops;
82143 snd_pcm_open_callback_t open;
82144 void *private_data; /* sb or wss */
82145 } streams[2];
82146 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
82147 index 733b014..56ce96f 100644
82148 --- a/sound/oss/sb_audio.c
82149 +++ b/sound/oss/sb_audio.c
82150 @@ -901,7 +901,7 @@ sb16_copy_from_user(int dev,
82151 buf16 = (signed short *)(localbuf + localoffs);
82152 while (c)
82153 {
82154 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82155 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
82156 if (copy_from_user(lbuf8,
82157 userbuf+useroffs + p,
82158 locallen))
82159 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
82160 index 09d4648..cf234c7 100644
82161 --- a/sound/oss/swarm_cs4297a.c
82162 +++ b/sound/oss/swarm_cs4297a.c
82163 @@ -2606,7 +2606,6 @@ static int __init cs4297a_init(void)
82164 {
82165 struct cs4297a_state *s;
82166 u32 pwr, id;
82167 - mm_segment_t fs;
82168 int rval;
82169 #ifndef CONFIG_BCM_CS4297A_CSWARM
82170 u64 cfg;
82171 @@ -2696,22 +2695,23 @@ static int __init cs4297a_init(void)
82172 if (!rval) {
82173 char *sb1250_duart_present;
82174
82175 +#if 0
82176 + mm_segment_t fs;
82177 fs = get_fs();
82178 set_fs(KERNEL_DS);
82179 -#if 0
82180 val = SOUND_MASK_LINE;
82181 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
82182 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
82183 val = initvol[i].vol;
82184 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
82185 }
82186 + set_fs(fs);
82187 // cs4297a_write_ac97(s, 0x18, 0x0808);
82188 #else
82189 // cs4297a_write_ac97(s, 0x5e, 0x180);
82190 cs4297a_write_ac97(s, 0x02, 0x0808);
82191 cs4297a_write_ac97(s, 0x18, 0x0808);
82192 #endif
82193 - set_fs(fs);
82194
82195 list_add(&s->list, &cs4297a_devs);
82196
82197 diff --git a/sound/pci/hda/hda_codec.h b/sound/pci/hda/hda_codec.h
82198 index 2fdaadb..7df8fc6 100644
82199 --- a/sound/pci/hda/hda_codec.h
82200 +++ b/sound/pci/hda/hda_codec.h
82201 @@ -611,7 +611,7 @@ struct hda_bus_ops {
82202 /* notify power-up/down from codec to controller */
82203 void (*pm_notify)(struct hda_bus *bus);
82204 #endif
82205 -};
82206 +} __no_const;
82207
82208 /* template to pass to the bus constructor */
82209 struct hda_bus_template {
82210 @@ -711,6 +711,7 @@ struct hda_codec_ops {
82211 #endif
82212 void (*reboot_notify)(struct hda_codec *codec);
82213 };
82214 +typedef struct hda_codec_ops __no_const hda_codec_ops_no_const;
82215
82216 /* record for amp information cache */
82217 struct hda_cache_head {
82218 @@ -741,7 +742,7 @@ struct hda_pcm_ops {
82219 struct snd_pcm_substream *substream);
82220 int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
82221 struct snd_pcm_substream *substream);
82222 -};
82223 +} __no_const;
82224
82225 /* PCM information for each substream */
82226 struct hda_pcm_stream {
82227 @@ -799,7 +800,7 @@ struct hda_codec {
82228 const char *modelname; /* model name for preset */
82229
82230 /* set by patch */
82231 - struct hda_codec_ops patch_ops;
82232 + hda_codec_ops_no_const patch_ops;
82233
82234 /* PCM to create, set by patch_ops.build_pcms callback */
82235 unsigned int num_pcms;
82236 diff --git a/sound/pci/ice1712/ice1712.h b/sound/pci/ice1712/ice1712.h
82237 index 0da778a..bc38b84 100644
82238 --- a/sound/pci/ice1712/ice1712.h
82239 +++ b/sound/pci/ice1712/ice1712.h
82240 @@ -269,7 +269,7 @@ struct snd_ak4xxx_private {
82241 unsigned int mask_flags; /* total mask bits */
82242 struct snd_akm4xxx_ops {
82243 void (*set_rate_val)(struct snd_akm4xxx *ak, unsigned int rate);
82244 - } ops;
82245 + } __no_const ops;
82246 };
82247
82248 struct snd_ice1712_spdif {
82249 @@ -285,7 +285,7 @@ struct snd_ice1712_spdif {
82250 int (*default_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82251 void (*stream_get)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82252 int (*stream_put)(struct snd_ice1712 *, struct snd_ctl_elem_value *ucontrol);
82253 - } ops;
82254 + } __no_const ops;
82255 };
82256
82257
82258 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
82259 index a8159b81..5f006a5 100644
82260 --- a/sound/pci/ymfpci/ymfpci_main.c
82261 +++ b/sound/pci/ymfpci/ymfpci_main.c
82262 @@ -203,8 +203,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
82263 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
82264 break;
82265 }
82266 - if (atomic_read(&chip->interrupt_sleep_count)) {
82267 - atomic_set(&chip->interrupt_sleep_count, 0);
82268 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82269 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82270 wake_up(&chip->interrupt_sleep);
82271 }
82272 __end:
82273 @@ -788,7 +788,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
82274 continue;
82275 init_waitqueue_entry(&wait, current);
82276 add_wait_queue(&chip->interrupt_sleep, &wait);
82277 - atomic_inc(&chip->interrupt_sleep_count);
82278 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
82279 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
82280 remove_wait_queue(&chip->interrupt_sleep, &wait);
82281 }
82282 @@ -826,8 +826,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
82283 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
82284 spin_unlock(&chip->reg_lock);
82285
82286 - if (atomic_read(&chip->interrupt_sleep_count)) {
82287 - atomic_set(&chip->interrupt_sleep_count, 0);
82288 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
82289 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82290 wake_up(&chip->interrupt_sleep);
82291 }
82292 }
82293 @@ -2398,7 +2398,7 @@ int __devinit snd_ymfpci_create(struct snd_card *card,
82294 spin_lock_init(&chip->reg_lock);
82295 spin_lock_init(&chip->voice_lock);
82296 init_waitqueue_head(&chip->interrupt_sleep);
82297 - atomic_set(&chip->interrupt_sleep_count, 0);
82298 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
82299 chip->card = card;
82300 chip->pci = pci;
82301 chip->irq = -1;
82302 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
82303 new file mode 100644
82304 index 0000000..50f2f2f
82305 --- /dev/null
82306 +++ b/tools/gcc/.gitignore
82307 @@ -0,0 +1 @@
82308 +size_overflow_hash.h
82309 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
82310 new file mode 100644
82311 index 0000000..1d09b7e
82312 --- /dev/null
82313 +++ b/tools/gcc/Makefile
82314 @@ -0,0 +1,43 @@
82315 +#CC := gcc
82316 +#PLUGIN_SOURCE_FILES := pax_plugin.c
82317 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
82318 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
82319 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
82320 +
82321 +ifeq ($(PLUGINCC),$(HOSTCC))
82322 +HOSTLIBS := hostlibs
82323 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu99 -ggdb
82324 +else
82325 +HOSTLIBS := hostcxxlibs
82326 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -I$(GCCPLUGINS_DIR)/include/c-family -std=gnu++98 -ggdb -Wno-unused-parameter
82327 +endif
82328 +
82329 +$(HOSTLIBS)-y := constify_plugin.so
82330 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
82331 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
82332 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
82333 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
82334 +$(HOSTLIBS)-y += colorize_plugin.so
82335 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
82336 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
82337 +
82338 +always := $($(HOSTLIBS)-y)
82339 +
82340 +constify_plugin-objs := constify_plugin.o
82341 +stackleak_plugin-objs := stackleak_plugin.o
82342 +kallocstat_plugin-objs := kallocstat_plugin.o
82343 +kernexec_plugin-objs := kernexec_plugin.o
82344 +checker_plugin-objs := checker_plugin.o
82345 +colorize_plugin-objs := colorize_plugin.o
82346 +size_overflow_plugin-objs := size_overflow_plugin.o
82347 +latent_entropy_plugin-objs := latent_entropy_plugin.o
82348 +
82349 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
82350 +
82351 +quiet_cmd_build_size_overflow_hash = GENHASH $@
82352 + cmd_build_size_overflow_hash = \
82353 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
82354 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
82355 + $(call if_changed,build_size_overflow_hash)
82356 +
82357 +targets += size_overflow_hash.h
82358 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
82359 new file mode 100644
82360 index 0000000..d41b5af
82361 --- /dev/null
82362 +++ b/tools/gcc/checker_plugin.c
82363 @@ -0,0 +1,171 @@
82364 +/*
82365 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
82366 + * Licensed under the GPL v2
82367 + *
82368 + * Note: the choice of the license means that the compilation process is
82369 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82370 + * but for the kernel it doesn't matter since it doesn't link against
82371 + * any of the gcc libraries
82372 + *
82373 + * gcc plugin to implement various sparse (source code checker) features
82374 + *
82375 + * TODO:
82376 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
82377 + *
82378 + * BUGS:
82379 + * - none known
82380 + */
82381 +#include "gcc-plugin.h"
82382 +#include "config.h"
82383 +#include "system.h"
82384 +#include "coretypes.h"
82385 +#include "tree.h"
82386 +#include "tree-pass.h"
82387 +#include "flags.h"
82388 +#include "intl.h"
82389 +#include "toplev.h"
82390 +#include "plugin.h"
82391 +//#include "expr.h" where are you...
82392 +#include "diagnostic.h"
82393 +#include "plugin-version.h"
82394 +#include "tm.h"
82395 +#include "function.h"
82396 +#include "basic-block.h"
82397 +#include "gimple.h"
82398 +#include "rtl.h"
82399 +#include "emit-rtl.h"
82400 +#include "tree-flow.h"
82401 +#include "target.h"
82402 +
82403 +extern void c_register_addr_space (const char *str, addr_space_t as);
82404 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
82405 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
82406 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
82407 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
82408 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
82409 +
82410 +extern void print_gimple_stmt(FILE *, gimple, int, int);
82411 +extern rtx emit_move_insn(rtx x, rtx y);
82412 +
82413 +int plugin_is_GPL_compatible;
82414 +
82415 +static struct plugin_info checker_plugin_info = {
82416 + .version = "201111150100",
82417 +};
82418 +
82419 +#define ADDR_SPACE_KERNEL 0
82420 +#define ADDR_SPACE_FORCE_KERNEL 1
82421 +#define ADDR_SPACE_USER 2
82422 +#define ADDR_SPACE_FORCE_USER 3
82423 +#define ADDR_SPACE_IOMEM 0
82424 +#define ADDR_SPACE_FORCE_IOMEM 0
82425 +#define ADDR_SPACE_PERCPU 0
82426 +#define ADDR_SPACE_FORCE_PERCPU 0
82427 +#define ADDR_SPACE_RCU 0
82428 +#define ADDR_SPACE_FORCE_RCU 0
82429 +
82430 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
82431 +{
82432 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
82433 +}
82434 +
82435 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
82436 +{
82437 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
82438 +}
82439 +
82440 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
82441 +{
82442 + return default_addr_space_valid_pointer_mode(mode, as);
82443 +}
82444 +
82445 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
82446 +{
82447 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
82448 +}
82449 +
82450 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
82451 +{
82452 + return default_addr_space_legitimize_address(x, oldx, mode, as);
82453 +}
82454 +
82455 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
82456 +{
82457 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
82458 + return true;
82459 +
82460 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
82461 + return true;
82462 +
82463 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
82464 + return true;
82465 +
82466 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
82467 + return true;
82468 +
82469 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
82470 + return true;
82471 +
82472 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
82473 + return true;
82474 +
82475 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
82476 + return true;
82477 +
82478 + return subset == superset;
82479 +}
82480 +
82481 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
82482 +{
82483 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
82484 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
82485 +
82486 + return op;
82487 +}
82488 +
82489 +static void register_checker_address_spaces(void *event_data, void *data)
82490 +{
82491 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
82492 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
82493 + c_register_addr_space("__user", ADDR_SPACE_USER);
82494 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
82495 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
82496 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
82497 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
82498 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
82499 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
82500 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
82501 +
82502 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
82503 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
82504 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
82505 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
82506 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
82507 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
82508 + targetm.addr_space.convert = checker_addr_space_convert;
82509 +}
82510 +
82511 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82512 +{
82513 + const char * const plugin_name = plugin_info->base_name;
82514 + const int argc = plugin_info->argc;
82515 + const struct plugin_argument * const argv = plugin_info->argv;
82516 + int i;
82517 +
82518 + if (!plugin_default_version_check(version, &gcc_version)) {
82519 + error(G_("incompatible gcc/plugin versions"));
82520 + return 1;
82521 + }
82522 +
82523 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
82524 +
82525 + for (i = 0; i < argc; ++i)
82526 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
82527 +
82528 + if (TARGET_64BIT == 0)
82529 + return 0;
82530 +
82531 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
82532 +
82533 + return 0;
82534 +}
82535 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
82536 new file mode 100644
82537 index 0000000..846aeb0
82538 --- /dev/null
82539 +++ b/tools/gcc/colorize_plugin.c
82540 @@ -0,0 +1,148 @@
82541 +/*
82542 + * Copyright 2012 by PaX Team <pageexec@freemail.hu>
82543 + * Licensed under the GPL v2
82544 + *
82545 + * Note: the choice of the license means that the compilation process is
82546 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
82547 + * but for the kernel it doesn't matter since it doesn't link against
82548 + * any of the gcc libraries
82549 + *
82550 + * gcc plugin to colorize diagnostic output
82551 + *
82552 + */
82553 +
82554 +#include "gcc-plugin.h"
82555 +#include "config.h"
82556 +#include "system.h"
82557 +#include "coretypes.h"
82558 +#include "tree.h"
82559 +#include "tree-pass.h"
82560 +#include "flags.h"
82561 +#include "intl.h"
82562 +#include "toplev.h"
82563 +#include "plugin.h"
82564 +#include "diagnostic.h"
82565 +#include "plugin-version.h"
82566 +#include "tm.h"
82567 +
82568 +int plugin_is_GPL_compatible;
82569 +
82570 +static struct plugin_info colorize_plugin_info = {
82571 + .version = "201203092200",
82572 + .help = NULL,
82573 +};
82574 +
82575 +#define GREEN "\033[32m\033[2m"
82576 +#define LIGHTGREEN "\033[32m\033[1m"
82577 +#define YELLOW "\033[33m\033[2m"
82578 +#define LIGHTYELLOW "\033[33m\033[1m"
82579 +#define RED "\033[31m\033[2m"
82580 +#define LIGHTRED "\033[31m\033[1m"
82581 +#define BLUE "\033[34m\033[2m"
82582 +#define LIGHTBLUE "\033[34m\033[1m"
82583 +#define BRIGHT "\033[m\033[1m"
82584 +#define NORMAL "\033[m"
82585 +
82586 +static diagnostic_starter_fn old_starter;
82587 +static diagnostic_finalizer_fn old_finalizer;
82588 +
82589 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82590 +{
82591 + const char *color;
82592 + char *newprefix;
82593 +
82594 + switch (diagnostic->kind) {
82595 + case DK_NOTE:
82596 + color = LIGHTBLUE;
82597 + break;
82598 +
82599 + case DK_PEDWARN:
82600 + case DK_WARNING:
82601 + color = LIGHTYELLOW;
82602 + break;
82603 +
82604 + case DK_ERROR:
82605 + case DK_FATAL:
82606 + case DK_ICE:
82607 + case DK_PERMERROR:
82608 + case DK_SORRY:
82609 + color = LIGHTRED;
82610 + break;
82611 +
82612 + default:
82613 + color = NORMAL;
82614 + }
82615 +
82616 + old_starter(context, diagnostic);
82617 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
82618 + return;
82619 + pp_destroy_prefix(context->printer);
82620 + pp_set_prefix(context->printer, newprefix);
82621 +}
82622 +
82623 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
82624 +{
82625 + old_finalizer(context, diagnostic);
82626 +}
82627 +
82628 +static void colorize_arm(void)
82629 +{
82630 + old_starter = diagnostic_starter(global_dc);
82631 + old_finalizer = diagnostic_finalizer(global_dc);
82632 +
82633 + diagnostic_starter(global_dc) = start_colorize;
82634 + diagnostic_finalizer(global_dc) = finalize_colorize;
82635 +}
82636 +
82637 +static unsigned int execute_colorize_rearm(void)
82638 +{
82639 + if (diagnostic_starter(global_dc) == start_colorize)
82640 + return 0;
82641 +
82642 + colorize_arm();
82643 + return 0;
82644 +}
82645 +
82646 +struct simple_ipa_opt_pass pass_ipa_colorize_rearm = {
82647 + .pass = {
82648 + .type = SIMPLE_IPA_PASS,
82649 + .name = "colorize_rearm",
82650 + .gate = NULL,
82651 + .execute = execute_colorize_rearm,
82652 + .sub = NULL,
82653 + .next = NULL,
82654 + .static_pass_number = 0,
82655 + .tv_id = TV_NONE,
82656 + .properties_required = 0,
82657 + .properties_provided = 0,
82658 + .properties_destroyed = 0,
82659 + .todo_flags_start = 0,
82660 + .todo_flags_finish = 0
82661 + }
82662 +};
82663 +
82664 +static void colorize_start_unit(void *gcc_data, void *user_data)
82665 +{
82666 + colorize_arm();
82667 +}
82668 +
82669 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82670 +{
82671 + const char * const plugin_name = plugin_info->base_name;
82672 + struct register_pass_info colorize_rearm_pass_info = {
82673 + .pass = &pass_ipa_colorize_rearm.pass,
82674 + .reference_pass_name = "*free_lang_data",
82675 + .ref_pass_instance_number = 1,
82676 + .pos_op = PASS_POS_INSERT_AFTER
82677 + };
82678 +
82679 + if (!plugin_default_version_check(version, &gcc_version)) {
82680 + error(G_("incompatible gcc/plugin versions"));
82681 + return 1;
82682 + }
82683 +
82684 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
82685 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
82686 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
82687 + return 0;
82688 +}
82689 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
82690 new file mode 100644
82691 index 0000000..92ed719
82692 --- /dev/null
82693 +++ b/tools/gcc/constify_plugin.c
82694 @@ -0,0 +1,331 @@
82695 +/*
82696 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
82697 + * Copyright 2011 by PaX Team <pageexec@freemail.hu>
82698 + * Licensed under the GPL v2, or (at your option) v3
82699 + *
82700 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
82701 + *
82702 + * Homepage:
82703 + * http://www.grsecurity.net/~ephox/const_plugin/
82704 + *
82705 + * Usage:
82706 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
82707 + * $ gcc -fplugin=constify_plugin.so test.c -O2
82708 + */
82709 +
82710 +#include "gcc-plugin.h"
82711 +#include "config.h"
82712 +#include "system.h"
82713 +#include "coretypes.h"
82714 +#include "tree.h"
82715 +#include "tree-pass.h"
82716 +#include "flags.h"
82717 +#include "intl.h"
82718 +#include "toplev.h"
82719 +#include "plugin.h"
82720 +#include "diagnostic.h"
82721 +#include "plugin-version.h"
82722 +#include "tm.h"
82723 +#include "function.h"
82724 +#include "basic-block.h"
82725 +#include "gimple.h"
82726 +#include "rtl.h"
82727 +#include "emit-rtl.h"
82728 +#include "tree-flow.h"
82729 +
82730 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
82731 +
82732 +int plugin_is_GPL_compatible;
82733 +
82734 +static struct plugin_info const_plugin_info = {
82735 + .version = "201205300030",
82736 + .help = "no-constify\tturn off constification\n",
82737 +};
82738 +
82739 +static void deconstify_tree(tree node);
82740 +
82741 +static void deconstify_type(tree type)
82742 +{
82743 + tree field;
82744 +
82745 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
82746 + tree type = TREE_TYPE(field);
82747 +
82748 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82749 + continue;
82750 + if (!TYPE_READONLY(type))
82751 + continue;
82752 +
82753 + deconstify_tree(field);
82754 + }
82755 + TYPE_READONLY(type) = 0;
82756 + C_TYPE_FIELDS_READONLY(type) = 0;
82757 +}
82758 +
82759 +static void deconstify_tree(tree node)
82760 +{
82761 + tree old_type, new_type, field;
82762 +
82763 + old_type = TREE_TYPE(node);
82764 +
82765 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
82766 +
82767 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
82768 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
82769 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
82770 + DECL_FIELD_CONTEXT(field) = new_type;
82771 +
82772 + deconstify_type(new_type);
82773 +
82774 + TREE_READONLY(node) = 0;
82775 + TREE_TYPE(node) = new_type;
82776 +}
82777 +
82778 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82779 +{
82780 + tree type;
82781 +
82782 + *no_add_attrs = true;
82783 + if (TREE_CODE(*node) == FUNCTION_DECL) {
82784 + error("%qE attribute does not apply to functions", name);
82785 + return NULL_TREE;
82786 + }
82787 +
82788 + if (TREE_CODE(*node) == VAR_DECL) {
82789 + error("%qE attribute does not apply to variables", name);
82790 + return NULL_TREE;
82791 + }
82792 +
82793 + if (TYPE_P(*node)) {
82794 + if (TREE_CODE(*node) == RECORD_TYPE || TREE_CODE(*node) == UNION_TYPE)
82795 + *no_add_attrs = false;
82796 + else
82797 + error("%qE attribute applies to struct and union types only", name);
82798 + return NULL_TREE;
82799 + }
82800 +
82801 + type = TREE_TYPE(*node);
82802 +
82803 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
82804 + error("%qE attribute applies to struct and union types only", name);
82805 + return NULL_TREE;
82806 + }
82807 +
82808 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
82809 + error("%qE attribute is already applied to the type", name);
82810 + return NULL_TREE;
82811 + }
82812 +
82813 + if (TREE_CODE(*node) == TYPE_DECL && !TYPE_READONLY(type)) {
82814 + error("%qE attribute used on type that is not constified", name);
82815 + return NULL_TREE;
82816 + }
82817 +
82818 + if (TREE_CODE(*node) == TYPE_DECL) {
82819 + deconstify_tree(*node);
82820 + return NULL_TREE;
82821 + }
82822 +
82823 + return NULL_TREE;
82824 +}
82825 +
82826 +static void constify_type(tree type)
82827 +{
82828 + TYPE_READONLY(type) = 1;
82829 + C_TYPE_FIELDS_READONLY(type) = 1;
82830 +}
82831 +
82832 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
82833 +{
82834 + *no_add_attrs = true;
82835 + if (!TYPE_P(*node)) {
82836 + error("%qE attribute applies to types only", name);
82837 + return NULL_TREE;
82838 + }
82839 +
82840 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
82841 + error("%qE attribute applies to struct and union types only", name);
82842 + return NULL_TREE;
82843 + }
82844 +
82845 + *no_add_attrs = false;
82846 + constify_type(*node);
82847 + return NULL_TREE;
82848 +}
82849 +
82850 +static struct attribute_spec no_const_attr = {
82851 + .name = "no_const",
82852 + .min_length = 0,
82853 + .max_length = 0,
82854 + .decl_required = false,
82855 + .type_required = false,
82856 + .function_type_required = false,
82857 + .handler = handle_no_const_attribute,
82858 +#if BUILDING_GCC_VERSION >= 4007
82859 + .affects_type_identity = true
82860 +#endif
82861 +};
82862 +
82863 +static struct attribute_spec do_const_attr = {
82864 + .name = "do_const",
82865 + .min_length = 0,
82866 + .max_length = 0,
82867 + .decl_required = false,
82868 + .type_required = false,
82869 + .function_type_required = false,
82870 + .handler = handle_do_const_attribute,
82871 +#if BUILDING_GCC_VERSION >= 4007
82872 + .affects_type_identity = true
82873 +#endif
82874 +};
82875 +
82876 +static void register_attributes(void *event_data, void *data)
82877 +{
82878 + register_attribute(&no_const_attr);
82879 + register_attribute(&do_const_attr);
82880 +}
82881 +
82882 +static bool is_fptr(tree field)
82883 +{
82884 + tree ptr = TREE_TYPE(field);
82885 +
82886 + if (TREE_CODE(ptr) != POINTER_TYPE)
82887 + return false;
82888 +
82889 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
82890 +}
82891 +
82892 +static bool walk_struct(tree node)
82893 +{
82894 + tree field;
82895 +
82896 + if (TYPE_FIELDS(node) == NULL_TREE)
82897 + return false;
82898 +
82899 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
82900 + gcc_assert(!TYPE_READONLY(node));
82901 + deconstify_type(node);
82902 + return false;
82903 + }
82904 +
82905 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
82906 + tree type = TREE_TYPE(field);
82907 + enum tree_code code = TREE_CODE(type);
82908 +
82909 + if (node == type)
82910 + return false;
82911 + if (code == RECORD_TYPE || code == UNION_TYPE) {
82912 + if (!(walk_struct(type)))
82913 + return false;
82914 + } else if (!is_fptr(field) && !TREE_READONLY(field))
82915 + return false;
82916 + }
82917 + return true;
82918 +}
82919 +
82920 +static void finish_type(void *event_data, void *data)
82921 +{
82922 + tree type = (tree)event_data;
82923 +
82924 + if (type == NULL_TREE || type == error_mark_node)
82925 + return;
82926 +
82927 + if (TYPE_READONLY(type))
82928 + return;
82929 +
82930 + if (walk_struct(type))
82931 + constify_type(type);
82932 +}
82933 +
82934 +static unsigned int check_local_variables(void);
82935 +
82936 +struct gimple_opt_pass pass_local_variable = {
82937 + {
82938 + .type = GIMPLE_PASS,
82939 + .name = "check_local_variables",
82940 + .gate = NULL,
82941 + .execute = check_local_variables,
82942 + .sub = NULL,
82943 + .next = NULL,
82944 + .static_pass_number = 0,
82945 + .tv_id = TV_NONE,
82946 + .properties_required = 0,
82947 + .properties_provided = 0,
82948 + .properties_destroyed = 0,
82949 + .todo_flags_start = 0,
82950 + .todo_flags_finish = 0
82951 + }
82952 +};
82953 +
82954 +static unsigned int check_local_variables(void)
82955 +{
82956 + tree var;
82957 + referenced_var_iterator rvi;
82958 +
82959 +#if BUILDING_GCC_VERSION == 4005
82960 + FOR_EACH_REFERENCED_VAR(var, rvi) {
82961 +#else
82962 + FOR_EACH_REFERENCED_VAR(cfun, var, rvi) {
82963 +#endif
82964 + tree type = TREE_TYPE(var);
82965 +
82966 + if (!DECL_P(var) || TREE_STATIC(var) || DECL_EXTERNAL(var))
82967 + continue;
82968 +
82969 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
82970 + continue;
82971 +
82972 + if (!TYPE_READONLY(type))
82973 + continue;
82974 +
82975 +// if (lookup_attribute("no_const", DECL_ATTRIBUTES(var)))
82976 +// continue;
82977 +
82978 +// if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
82979 +// continue;
82980 +
82981 + if (walk_struct(type)) {
82982 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
82983 + return 1;
82984 + }
82985 + }
82986 + return 0;
82987 +}
82988 +
82989 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
82990 +{
82991 + const char * const plugin_name = plugin_info->base_name;
82992 + const int argc = plugin_info->argc;
82993 + const struct plugin_argument * const argv = plugin_info->argv;
82994 + int i;
82995 + bool constify = true;
82996 +
82997 + struct register_pass_info local_variable_pass_info = {
82998 + .pass = &pass_local_variable.pass,
82999 + .reference_pass_name = "*referenced_vars",
83000 + .ref_pass_instance_number = 1,
83001 + .pos_op = PASS_POS_INSERT_AFTER
83002 + };
83003 +
83004 + if (!plugin_default_version_check(version, &gcc_version)) {
83005 + error(G_("incompatible gcc/plugin versions"));
83006 + return 1;
83007 + }
83008 +
83009 + for (i = 0; i < argc; ++i) {
83010 + if (!(strcmp(argv[i].key, "no-constify"))) {
83011 + constify = false;
83012 + continue;
83013 + }
83014 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83015 + }
83016 +
83017 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
83018 + if (constify) {
83019 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
83020 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &local_variable_pass_info);
83021 + }
83022 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
83023 +
83024 + return 0;
83025 +}
83026 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
83027 new file mode 100644
83028 index 0000000..02c6bec
83029 --- /dev/null
83030 +++ b/tools/gcc/generate_size_overflow_hash.sh
83031 @@ -0,0 +1,94 @@
83032 +#!/bin/bash
83033 +
83034 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
83035 +
83036 +header1="size_overflow_hash.h"
83037 +database="size_overflow_hash.data"
83038 +n=65536
83039 +
83040 +usage() {
83041 +cat <<EOF
83042 +usage: $0 options
83043 +OPTIONS:
83044 + -h|--help help
83045 + -o header file
83046 + -d database file
83047 + -n hash array size
83048 +EOF
83049 + return 0
83050 +}
83051 +
83052 +while true
83053 +do
83054 + case "$1" in
83055 + -h|--help) usage && exit 0;;
83056 + -n) n=$2; shift 2;;
83057 + -o) header1="$2"; shift 2;;
83058 + -d) database="$2"; shift 2;;
83059 + --) shift 1; break ;;
83060 + *) break ;;
83061 + esac
83062 +done
83063 +
83064 +create_defines() {
83065 + for i in `seq 1 32`
83066 + do
83067 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
83068 + done
83069 + echo >> "$header1"
83070 +}
83071 +
83072 +create_structs () {
83073 + rm -f "$header1"
83074 +
83075 + create_defines
83076 +
83077 + cat "$database" | while read data
83078 + do
83079 + data_array=($data)
83080 + struct_hash_name="${data_array[0]}"
83081 + funcn="${data_array[1]}"
83082 + params="${data_array[2]}"
83083 + next="${data_array[5]}"
83084 +
83085 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
83086 +
83087 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
83088 + echo -en "\t.param\t= " >> "$header1"
83089 + line=
83090 + for param_num in ${params//-/ };
83091 + do
83092 + line="${line}PARAM"$param_num"|"
83093 + done
83094 +
83095 + echo -e "${line%?},\n};\n" >> "$header1"
83096 + done
83097 +}
83098 +
83099 +create_headers () {
83100 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
83101 +}
83102 +
83103 +create_array_elements () {
83104 + index=0
83105 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
83106 + do
83107 + data_array=($data)
83108 + i="${data_array[3]}"
83109 + hash="${data_array[4]}"
83110 + while [[ $index -lt $i ]]
83111 + do
83112 + echo -e "\t["$index"]\t= NULL," >> "$header1"
83113 + index=$(($index + 1))
83114 + done
83115 + index=$(($index + 1))
83116 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
83117 + done
83118 + echo '};' >> $header1
83119 +}
83120 +
83121 +create_structs
83122 +create_headers
83123 +create_array_elements
83124 +
83125 +exit 0
83126 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
83127 new file mode 100644
83128 index 0000000..a86e422
83129 --- /dev/null
83130 +++ b/tools/gcc/kallocstat_plugin.c
83131 @@ -0,0 +1,167 @@
83132 +/*
83133 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83134 + * Licensed under the GPL v2
83135 + *
83136 + * Note: the choice of the license means that the compilation process is
83137 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83138 + * but for the kernel it doesn't matter since it doesn't link against
83139 + * any of the gcc libraries
83140 + *
83141 + * gcc plugin to find the distribution of k*alloc sizes
83142 + *
83143 + * TODO:
83144 + *
83145 + * BUGS:
83146 + * - none known
83147 + */
83148 +#include "gcc-plugin.h"
83149 +#include "config.h"
83150 +#include "system.h"
83151 +#include "coretypes.h"
83152 +#include "tree.h"
83153 +#include "tree-pass.h"
83154 +#include "flags.h"
83155 +#include "intl.h"
83156 +#include "toplev.h"
83157 +#include "plugin.h"
83158 +//#include "expr.h" where are you...
83159 +#include "diagnostic.h"
83160 +#include "plugin-version.h"
83161 +#include "tm.h"
83162 +#include "function.h"
83163 +#include "basic-block.h"
83164 +#include "gimple.h"
83165 +#include "rtl.h"
83166 +#include "emit-rtl.h"
83167 +
83168 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83169 +
83170 +int plugin_is_GPL_compatible;
83171 +
83172 +static const char * const kalloc_functions[] = {
83173 + "__kmalloc",
83174 + "kmalloc",
83175 + "kmalloc_large",
83176 + "kmalloc_node",
83177 + "kmalloc_order",
83178 + "kmalloc_order_trace",
83179 + "kmalloc_slab",
83180 + "kzalloc",
83181 + "kzalloc_node",
83182 +};
83183 +
83184 +static struct plugin_info kallocstat_plugin_info = {
83185 + .version = "201111150100",
83186 +};
83187 +
83188 +static unsigned int execute_kallocstat(void);
83189 +
83190 +static struct gimple_opt_pass kallocstat_pass = {
83191 + .pass = {
83192 + .type = GIMPLE_PASS,
83193 + .name = "kallocstat",
83194 + .gate = NULL,
83195 + .execute = execute_kallocstat,
83196 + .sub = NULL,
83197 + .next = NULL,
83198 + .static_pass_number = 0,
83199 + .tv_id = TV_NONE,
83200 + .properties_required = 0,
83201 + .properties_provided = 0,
83202 + .properties_destroyed = 0,
83203 + .todo_flags_start = 0,
83204 + .todo_flags_finish = 0
83205 + }
83206 +};
83207 +
83208 +static bool is_kalloc(const char *fnname)
83209 +{
83210 + size_t i;
83211 +
83212 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
83213 + if (!strcmp(fnname, kalloc_functions[i]))
83214 + return true;
83215 + return false;
83216 +}
83217 +
83218 +static unsigned int execute_kallocstat(void)
83219 +{
83220 + basic_block bb;
83221 +
83222 + // 1. loop through BBs and GIMPLE statements
83223 + FOR_EACH_BB(bb) {
83224 + gimple_stmt_iterator gsi;
83225 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83226 + // gimple match:
83227 + tree fndecl, size;
83228 + gimple call_stmt;
83229 + const char *fnname;
83230 +
83231 + // is it a call
83232 + call_stmt = gsi_stmt(gsi);
83233 + if (!is_gimple_call(call_stmt))
83234 + continue;
83235 + fndecl = gimple_call_fndecl(call_stmt);
83236 + if (fndecl == NULL_TREE)
83237 + continue;
83238 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
83239 + continue;
83240 +
83241 + // is it a call to k*alloc
83242 + fnname = IDENTIFIER_POINTER(DECL_NAME(fndecl));
83243 + if (!is_kalloc(fnname))
83244 + continue;
83245 +
83246 + // is the size arg the result of a simple const assignment
83247 + size = gimple_call_arg(call_stmt, 0);
83248 + while (true) {
83249 + gimple def_stmt;
83250 + expanded_location xloc;
83251 + size_t size_val;
83252 +
83253 + if (TREE_CODE(size) != SSA_NAME)
83254 + break;
83255 + def_stmt = SSA_NAME_DEF_STMT(size);
83256 + if (!def_stmt || !is_gimple_assign(def_stmt))
83257 + break;
83258 + if (gimple_num_ops(def_stmt) != 2)
83259 + break;
83260 + size = gimple_assign_rhs1(def_stmt);
83261 + if (!TREE_CONSTANT(size))
83262 + continue;
83263 + xloc = expand_location(gimple_location(def_stmt));
83264 + if (!xloc.file)
83265 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
83266 + size_val = TREE_INT_CST_LOW(size);
83267 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
83268 + break;
83269 + }
83270 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83271 +//debug_tree(gimple_call_fn(call_stmt));
83272 +//print_node(stderr, "pax", fndecl, 4);
83273 + }
83274 + }
83275 +
83276 + return 0;
83277 +}
83278 +
83279 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83280 +{
83281 + const char * const plugin_name = plugin_info->base_name;
83282 + struct register_pass_info kallocstat_pass_info = {
83283 + .pass = &kallocstat_pass.pass,
83284 + .reference_pass_name = "ssa",
83285 + .ref_pass_instance_number = 1,
83286 + .pos_op = PASS_POS_INSERT_AFTER
83287 + };
83288 +
83289 + if (!plugin_default_version_check(version, &gcc_version)) {
83290 + error(G_("incompatible gcc/plugin versions"));
83291 + return 1;
83292 + }
83293 +
83294 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
83295 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
83296 +
83297 + return 0;
83298 +}
83299 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
83300 new file mode 100644
83301 index 0000000..98011fa
83302 --- /dev/null
83303 +++ b/tools/gcc/kernexec_plugin.c
83304 @@ -0,0 +1,427 @@
83305 +/*
83306 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
83307 + * Licensed under the GPL v2
83308 + *
83309 + * Note: the choice of the license means that the compilation process is
83310 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83311 + * but for the kernel it doesn't matter since it doesn't link against
83312 + * any of the gcc libraries
83313 + *
83314 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
83315 + *
83316 + * TODO:
83317 + *
83318 + * BUGS:
83319 + * - none known
83320 + */
83321 +#include "gcc-plugin.h"
83322 +#include "config.h"
83323 +#include "system.h"
83324 +#include "coretypes.h"
83325 +#include "tree.h"
83326 +#include "tree-pass.h"
83327 +#include "flags.h"
83328 +#include "intl.h"
83329 +#include "toplev.h"
83330 +#include "plugin.h"
83331 +//#include "expr.h" where are you...
83332 +#include "diagnostic.h"
83333 +#include "plugin-version.h"
83334 +#include "tm.h"
83335 +#include "function.h"
83336 +#include "basic-block.h"
83337 +#include "gimple.h"
83338 +#include "rtl.h"
83339 +#include "emit-rtl.h"
83340 +#include "tree-flow.h"
83341 +
83342 +extern void print_gimple_stmt(FILE *, gimple, int, int);
83343 +extern rtx emit_move_insn(rtx x, rtx y);
83344 +
83345 +int plugin_is_GPL_compatible;
83346 +
83347 +static struct plugin_info kernexec_plugin_info = {
83348 + .version = "201111291120",
83349 + .help = "method=[bts|or]\tinstrumentation method\n"
83350 +};
83351 +
83352 +static unsigned int execute_kernexec_reload(void);
83353 +static unsigned int execute_kernexec_fptr(void);
83354 +static unsigned int execute_kernexec_retaddr(void);
83355 +static bool kernexec_cmodel_check(void);
83356 +
83357 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
83358 +static void (*kernexec_instrument_retaddr)(rtx);
83359 +
83360 +static struct gimple_opt_pass kernexec_reload_pass = {
83361 + .pass = {
83362 + .type = GIMPLE_PASS,
83363 + .name = "kernexec_reload",
83364 + .gate = kernexec_cmodel_check,
83365 + .execute = execute_kernexec_reload,
83366 + .sub = NULL,
83367 + .next = NULL,
83368 + .static_pass_number = 0,
83369 + .tv_id = TV_NONE,
83370 + .properties_required = 0,
83371 + .properties_provided = 0,
83372 + .properties_destroyed = 0,
83373 + .todo_flags_start = 0,
83374 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83375 + }
83376 +};
83377 +
83378 +static struct gimple_opt_pass kernexec_fptr_pass = {
83379 + .pass = {
83380 + .type = GIMPLE_PASS,
83381 + .name = "kernexec_fptr",
83382 + .gate = kernexec_cmodel_check,
83383 + .execute = execute_kernexec_fptr,
83384 + .sub = NULL,
83385 + .next = NULL,
83386 + .static_pass_number = 0,
83387 + .tv_id = TV_NONE,
83388 + .properties_required = 0,
83389 + .properties_provided = 0,
83390 + .properties_destroyed = 0,
83391 + .todo_flags_start = 0,
83392 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
83393 + }
83394 +};
83395 +
83396 +static struct rtl_opt_pass kernexec_retaddr_pass = {
83397 + .pass = {
83398 + .type = RTL_PASS,
83399 + .name = "kernexec_retaddr",
83400 + .gate = kernexec_cmodel_check,
83401 + .execute = execute_kernexec_retaddr,
83402 + .sub = NULL,
83403 + .next = NULL,
83404 + .static_pass_number = 0,
83405 + .tv_id = TV_NONE,
83406 + .properties_required = 0,
83407 + .properties_provided = 0,
83408 + .properties_destroyed = 0,
83409 + .todo_flags_start = 0,
83410 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
83411 + }
83412 +};
83413 +
83414 +static bool kernexec_cmodel_check(void)
83415 +{
83416 + tree section;
83417 +
83418 + if (ix86_cmodel != CM_KERNEL)
83419 + return false;
83420 +
83421 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
83422 + if (!section || !TREE_VALUE(section))
83423 + return true;
83424 +
83425 + section = TREE_VALUE(TREE_VALUE(section));
83426 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
83427 + return true;
83428 +
83429 + return false;
83430 +}
83431 +
83432 +/*
83433 + * add special KERNEXEC instrumentation: reload %r10 after it has been clobbered
83434 + */
83435 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
83436 +{
83437 + gimple asm_movabs_stmt;
83438 +
83439 + // build asm volatile("movabs $0x8000000000000000, %%r10\n\t" : : : );
83440 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r10\n\t", NULL, NULL, NULL, NULL);
83441 + gimple_asm_set_volatile(asm_movabs_stmt, true);
83442 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
83443 + update_stmt(asm_movabs_stmt);
83444 +}
83445 +
83446 +/*
83447 + * find all asm() stmts that clobber r10 and add a reload of r10
83448 + */
83449 +static unsigned int execute_kernexec_reload(void)
83450 +{
83451 + basic_block bb;
83452 +
83453 + // 1. loop through BBs and GIMPLE statements
83454 + FOR_EACH_BB(bb) {
83455 + gimple_stmt_iterator gsi;
83456 +
83457 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83458 + // gimple match: __asm__ ("" : : : "r10");
83459 + gimple asm_stmt;
83460 + size_t nclobbers;
83461 +
83462 + // is it an asm ...
83463 + asm_stmt = gsi_stmt(gsi);
83464 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
83465 + continue;
83466 +
83467 + // ... clobbering r10
83468 + nclobbers = gimple_asm_nclobbers(asm_stmt);
83469 + while (nclobbers--) {
83470 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
83471 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r10"))
83472 + continue;
83473 + kernexec_reload_fptr_mask(&gsi);
83474 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
83475 + break;
83476 + }
83477 + }
83478 + }
83479 +
83480 + return 0;
83481 +}
83482 +
83483 +/*
83484 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
83485 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
83486 + */
83487 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
83488 +{
83489 + gimple assign_intptr, assign_new_fptr, call_stmt;
83490 + tree intptr, old_fptr, new_fptr, kernexec_mask;
83491 +
83492 + call_stmt = gsi_stmt(*gsi);
83493 + old_fptr = gimple_call_fn(call_stmt);
83494 +
83495 + // create temporary unsigned long variable used for bitops and cast fptr to it
83496 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
83497 + add_referenced_var(intptr);
83498 + mark_sym_for_renaming(intptr);
83499 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
83500 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83501 + update_stmt(assign_intptr);
83502 +
83503 + // apply logical or to temporary unsigned long and bitmask
83504 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
83505 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
83506 + assign_intptr = gimple_build_assign(intptr, fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask));
83507 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
83508 + update_stmt(assign_intptr);
83509 +
83510 + // cast temporary unsigned long back to a temporary fptr variable
83511 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
83512 + add_referenced_var(new_fptr);
83513 + mark_sym_for_renaming(new_fptr);
83514 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
83515 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
83516 + update_stmt(assign_new_fptr);
83517 +
83518 + // replace call stmt fn with the new fptr
83519 + gimple_call_set_fn(call_stmt, new_fptr);
83520 + update_stmt(call_stmt);
83521 +}
83522 +
83523 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
83524 +{
83525 + gimple asm_or_stmt, call_stmt;
83526 + tree old_fptr, new_fptr, input, output;
83527 + VEC(tree, gc) *inputs = NULL;
83528 + VEC(tree, gc) *outputs = NULL;
83529 +
83530 + call_stmt = gsi_stmt(*gsi);
83531 + old_fptr = gimple_call_fn(call_stmt);
83532 +
83533 + // create temporary fptr variable
83534 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
83535 + add_referenced_var(new_fptr);
83536 + mark_sym_for_renaming(new_fptr);
83537 +
83538 + // build asm volatile("orq %%r10, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
83539 + input = build_tree_list(NULL_TREE, build_string(2, "0"));
83540 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
83541 + output = build_tree_list(NULL_TREE, build_string(3, "=r"));
83542 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
83543 + VEC_safe_push(tree, gc, inputs, input);
83544 + VEC_safe_push(tree, gc, outputs, output);
83545 + asm_or_stmt = gimple_build_asm_vec("orq %%r10, %0\n\t", inputs, outputs, NULL, NULL);
83546 + gimple_asm_set_volatile(asm_or_stmt, true);
83547 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
83548 + update_stmt(asm_or_stmt);
83549 +
83550 + // replace call stmt fn with the new fptr
83551 + gimple_call_set_fn(call_stmt, new_fptr);
83552 + update_stmt(call_stmt);
83553 +}
83554 +
83555 +/*
83556 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
83557 + */
83558 +static unsigned int execute_kernexec_fptr(void)
83559 +{
83560 + basic_block bb;
83561 +
83562 + // 1. loop through BBs and GIMPLE statements
83563 + FOR_EACH_BB(bb) {
83564 + gimple_stmt_iterator gsi;
83565 +
83566 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
83567 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
83568 + tree fn;
83569 + gimple call_stmt;
83570 +
83571 + // is it a call ...
83572 + call_stmt = gsi_stmt(gsi);
83573 + if (!is_gimple_call(call_stmt))
83574 + continue;
83575 + fn = gimple_call_fn(call_stmt);
83576 + if (TREE_CODE(fn) == ADDR_EXPR)
83577 + continue;
83578 + if (TREE_CODE(fn) != SSA_NAME)
83579 + gcc_unreachable();
83580 +
83581 + // ... through a function pointer
83582 + fn = SSA_NAME_VAR(fn);
83583 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL)
83584 + continue;
83585 + fn = TREE_TYPE(fn);
83586 + if (TREE_CODE(fn) != POINTER_TYPE)
83587 + continue;
83588 + fn = TREE_TYPE(fn);
83589 + if (TREE_CODE(fn) != FUNCTION_TYPE)
83590 + continue;
83591 +
83592 + kernexec_instrument_fptr(&gsi);
83593 +
83594 +//debug_tree(gimple_call_fn(call_stmt));
83595 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
83596 + }
83597 + }
83598 +
83599 + return 0;
83600 +}
83601 +
83602 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
83603 +static void kernexec_instrument_retaddr_bts(rtx insn)
83604 +{
83605 + rtx btsq;
83606 + rtvec argvec, constraintvec, labelvec;
83607 + int line;
83608 +
83609 + // create asm volatile("btsq $63,(%%rsp)":::)
83610 + argvec = rtvec_alloc(0);
83611 + constraintvec = rtvec_alloc(0);
83612 + labelvec = rtvec_alloc(0);
83613 + line = expand_location(RTL_LOCATION(insn)).line;
83614 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83615 + MEM_VOLATILE_P(btsq) = 1;
83616 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
83617 + emit_insn_before(btsq, insn);
83618 +}
83619 +
83620 +// add special KERNEXEC instrumentation: orq %r10,(%rsp) just before retn
83621 +static void kernexec_instrument_retaddr_or(rtx insn)
83622 +{
83623 + rtx orq;
83624 + rtvec argvec, constraintvec, labelvec;
83625 + int line;
83626 +
83627 + // create asm volatile("orq %%r10,(%%rsp)":::)
83628 + argvec = rtvec_alloc(0);
83629 + constraintvec = rtvec_alloc(0);
83630 + labelvec = rtvec_alloc(0);
83631 + line = expand_location(RTL_LOCATION(insn)).line;
83632 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r10,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
83633 + MEM_VOLATILE_P(orq) = 1;
83634 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
83635 + emit_insn_before(orq, insn);
83636 +}
83637 +
83638 +/*
83639 + * find all asm level function returns and forcibly set the highest bit of the return address
83640 + */
83641 +static unsigned int execute_kernexec_retaddr(void)
83642 +{
83643 + rtx insn;
83644 +
83645 + // 1. find function returns
83646 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
83647 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
83648 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
83649 + rtx body;
83650 +
83651 + // is it a retn
83652 + if (!JUMP_P(insn))
83653 + continue;
83654 + body = PATTERN(insn);
83655 + if (GET_CODE(body) == PARALLEL)
83656 + body = XVECEXP(body, 0, 0);
83657 + if (GET_CODE(body) != RETURN)
83658 + continue;
83659 + kernexec_instrument_retaddr(insn);
83660 + }
83661 +
83662 +// print_simple_rtl(stderr, get_insns());
83663 +// print_rtl(stderr, get_insns());
83664 +
83665 + return 0;
83666 +}
83667 +
83668 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
83669 +{
83670 + const char * const plugin_name = plugin_info->base_name;
83671 + const int argc = plugin_info->argc;
83672 + const struct plugin_argument * const argv = plugin_info->argv;
83673 + int i;
83674 + struct register_pass_info kernexec_reload_pass_info = {
83675 + .pass = &kernexec_reload_pass.pass,
83676 + .reference_pass_name = "ssa",
83677 + .ref_pass_instance_number = 1,
83678 + .pos_op = PASS_POS_INSERT_AFTER
83679 + };
83680 + struct register_pass_info kernexec_fptr_pass_info = {
83681 + .pass = &kernexec_fptr_pass.pass,
83682 + .reference_pass_name = "ssa",
83683 + .ref_pass_instance_number = 1,
83684 + .pos_op = PASS_POS_INSERT_AFTER
83685 + };
83686 + struct register_pass_info kernexec_retaddr_pass_info = {
83687 + .pass = &kernexec_retaddr_pass.pass,
83688 + .reference_pass_name = "pro_and_epilogue",
83689 + .ref_pass_instance_number = 1,
83690 + .pos_op = PASS_POS_INSERT_AFTER
83691 + };
83692 +
83693 + if (!plugin_default_version_check(version, &gcc_version)) {
83694 + error(G_("incompatible gcc/plugin versions"));
83695 + return 1;
83696 + }
83697 +
83698 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
83699 +
83700 + if (TARGET_64BIT == 0)
83701 + return 0;
83702 +
83703 + for (i = 0; i < argc; ++i) {
83704 + if (!strcmp(argv[i].key, "method")) {
83705 + if (!argv[i].value) {
83706 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83707 + continue;
83708 + }
83709 + if (!strcmp(argv[i].value, "bts")) {
83710 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
83711 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
83712 + } else if (!strcmp(argv[i].value, "or")) {
83713 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
83714 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
83715 + fix_register("r10", 1, 1);
83716 + } else
83717 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
83718 + continue;
83719 + }
83720 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
83721 + }
83722 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
83723 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
83724 +
83725 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
83726 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
83727 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
83728 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
83729 +
83730 + return 0;
83731 +}
83732 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
83733 new file mode 100644
83734 index 0000000..b8008f7
83735 --- /dev/null
83736 +++ b/tools/gcc/latent_entropy_plugin.c
83737 @@ -0,0 +1,295 @@
83738 +/*
83739 + * Copyright 2012 by the PaX Team <pageexec@freemail.hu>
83740 + * Licensed under the GPL v2
83741 + *
83742 + * Note: the choice of the license means that the compilation process is
83743 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
83744 + * but for the kernel it doesn't matter since it doesn't link against
83745 + * any of the gcc libraries
83746 + *
83747 + * gcc plugin to help generate a little bit of entropy from program state,
83748 + * used during boot in the kernel
83749 + *
83750 + * TODO:
83751 + * - add ipa pass to identify not explicitly marked candidate functions
83752 + * - mix in more program state (function arguments/return values, loop variables, etc)
83753 + * - more instrumentation control via attribute parameters
83754 + *
83755 + * BUGS:
83756 + * - LTO needs -flto-partition=none for now
83757 + */
83758 +#include "gcc-plugin.h"
83759 +#include "config.h"
83760 +#include "system.h"
83761 +#include "coretypes.h"
83762 +#include "tree.h"
83763 +#include "tree-pass.h"
83764 +#include "flags.h"
83765 +#include "intl.h"
83766 +#include "toplev.h"
83767 +#include "plugin.h"
83768 +//#include "expr.h" where are you...
83769 +#include "diagnostic.h"
83770 +#include "plugin-version.h"
83771 +#include "tm.h"
83772 +#include "function.h"
83773 +#include "basic-block.h"
83774 +#include "gimple.h"
83775 +#include "rtl.h"
83776 +#include "emit-rtl.h"
83777 +#include "tree-flow.h"
83778 +
83779 +int plugin_is_GPL_compatible;
83780 +
83781 +static tree latent_entropy_decl;
83782 +
83783 +static struct plugin_info latent_entropy_plugin_info = {
83784 + .version = "201207271820",
83785 + .help = NULL
83786 +};
83787 +
83788 +static unsigned int execute_latent_entropy(void);
83789 +static bool gate_latent_entropy(void);
83790 +
83791 +static struct gimple_opt_pass latent_entropy_pass = {
83792 + .pass = {
83793 + .type = GIMPLE_PASS,
83794 + .name = "latent_entropy",
83795 + .gate = gate_latent_entropy,
83796 + .execute = execute_latent_entropy,
83797 + .sub = NULL,
83798 + .next = NULL,
83799 + .static_pass_number = 0,
83800 + .tv_id = TV_NONE,
83801 + .properties_required = PROP_gimple_leh | PROP_cfg,
83802 + .properties_provided = 0,
83803 + .properties_destroyed = 0,
83804 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
83805 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
83806 + }
83807 +};
83808 +
83809 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
83810 +{
83811 + if (TREE_CODE(*node) != FUNCTION_DECL) {
83812 + *no_add_attrs = true;
83813 + error("%qE attribute only applies to functions", name);
83814 + }
83815 + return NULL_TREE;
83816 +}
83817 +
83818 +static struct attribute_spec latent_entropy_attr = {
83819 + .name = "latent_entropy",
83820 + .min_length = 0,
83821 + .max_length = 0,
83822 + .decl_required = true,
83823 + .type_required = false,
83824 + .function_type_required = false,
83825 + .handler = handle_latent_entropy_attribute,
83826 +#if BUILDING_GCC_VERSION >= 4007
83827 + .affects_type_identity = false
83828 +#endif
83829 +};
83830 +
83831 +static void register_attributes(void *event_data, void *data)
83832 +{
83833 + register_attribute(&latent_entropy_attr);
83834 +}
83835 +
83836 +static bool gate_latent_entropy(void)
83837 +{
83838 + tree latent_entropy_attr;
83839 +
83840 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
83841 + return latent_entropy_attr != NULL_TREE;
83842 +}
83843 +
83844 +static unsigned HOST_WIDE_INT seed;
83845 +static unsigned HOST_WIDE_INT get_random_const(void)
83846 +{
83847 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
83848 + return seed;
83849 +}
83850 +
83851 +static enum tree_code get_op(tree *rhs)
83852 +{
83853 + static enum tree_code op;
83854 + unsigned HOST_WIDE_INT random_const;
83855 +
83856 + random_const = get_random_const();
83857 +
83858 + switch (op) {
83859 + case BIT_XOR_EXPR:
83860 + op = PLUS_EXPR;
83861 + break;
83862 +
83863 + case PLUS_EXPR:
83864 + if (rhs) {
83865 + op = LROTATE_EXPR;
83866 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
83867 + break;
83868 + }
83869 +
83870 + case LROTATE_EXPR:
83871 + default:
83872 + op = BIT_XOR_EXPR;
83873 + break;
83874 + }
83875 + if (rhs)
83876 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
83877 + return op;
83878 +}
83879 +
83880 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
83881 +{
83882 + gimple_stmt_iterator gsi;
83883 + gimple assign;
83884 + tree addxorrol, rhs;
83885 + enum tree_code op;
83886 +
83887 + op = get_op(&rhs);
83888 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
83889 + assign = gimple_build_assign(local_entropy, addxorrol);
83890 + find_referenced_vars_in(assign);
83891 +//debug_bb(bb);
83892 + gsi = gsi_after_labels(bb);
83893 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
83894 + update_stmt(assign);
83895 +}
83896 +
83897 +static void perturb_latent_entropy(basic_block bb, tree rhs)
83898 +{
83899 + gimple_stmt_iterator gsi;
83900 + gimple assign;
83901 + tree addxorrol, temp;
83902 +
83903 + // 1. create temporary copy of latent_entropy
83904 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
83905 + add_referenced_var(temp);
83906 + mark_sym_for_renaming(temp);
83907 +
83908 + // 2. read...
83909 + assign = gimple_build_assign(temp, latent_entropy_decl);
83910 + find_referenced_vars_in(assign);
83911 + gsi = gsi_after_labels(bb);
83912 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83913 + update_stmt(assign);
83914 +
83915 + // 3. ...modify...
83916 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
83917 + assign = gimple_build_assign(temp, addxorrol);
83918 + find_referenced_vars_in(assign);
83919 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83920 + update_stmt(assign);
83921 +
83922 + // 4. ...write latent_entropy
83923 + assign = gimple_build_assign(latent_entropy_decl, temp);
83924 + find_referenced_vars_in(assign);
83925 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83926 + update_stmt(assign);
83927 +}
83928 +
83929 +static unsigned int execute_latent_entropy(void)
83930 +{
83931 + basic_block bb;
83932 + gimple assign;
83933 + gimple_stmt_iterator gsi;
83934 + tree local_entropy;
83935 +
83936 + if (!latent_entropy_decl) {
83937 + struct varpool_node *node;
83938 +
83939 + for (node = varpool_nodes; node; node = node->next) {
83940 + tree var = node->decl;
83941 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
83942 + continue;
83943 + latent_entropy_decl = var;
83944 +// debug_tree(var);
83945 + break;
83946 + }
83947 + if (!latent_entropy_decl) {
83948 +// debug_tree(current_function_decl);
83949 + return 0;
83950 + }
83951 + }
83952 +
83953 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
83954 +
83955 + // 1. create local entropy variable
83956 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
83957 + add_referenced_var(local_entropy);
83958 + mark_sym_for_renaming(local_entropy);
83959 +
83960 + // 2. initialize local entropy variable
83961 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
83962 + if (dom_info_available_p(CDI_DOMINATORS))
83963 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
83964 + gsi = gsi_start_bb(bb);
83965 +
83966 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
83967 +// gimple_set_location(assign, loc);
83968 + find_referenced_vars_in(assign);
83969 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
83970 + update_stmt(assign);
83971 + bb = bb->next_bb;
83972 +
83973 + // 3. instrument each BB with an operation on the local entropy variable
83974 + while (bb != EXIT_BLOCK_PTR) {
83975 + perturb_local_entropy(bb, local_entropy);
83976 + bb = bb->next_bb;
83977 + };
83978 +
83979 + // 4. mix local entropy into the global entropy variable
83980 + perturb_latent_entropy(EXIT_BLOCK_PTR->prev_bb, local_entropy);
83981 + return 0;
83982 +}
83983 +
83984 +static void start_unit_callback(void *gcc_data, void *user_data)
83985 +{
83986 +#if BUILDING_GCC_VERSION >= 4007
83987 + seed = get_random_seed(false);
83988 +#else
83989 + sscanf(get_random_seed(false), "%" HOST_WIDE_INT_PRINT "x", &seed);
83990 + seed *= seed;
83991 +#endif
83992 +
83993 + if (in_lto_p)
83994 + return;
83995 +
83996 + // extern u64 latent_entropy
83997 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), unsigned_intDI_type_node);
83998 +
83999 + TREE_STATIC(latent_entropy_decl) = 1;
84000 + TREE_PUBLIC(latent_entropy_decl) = 1;
84001 + TREE_USED(latent_entropy_decl) = 1;
84002 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
84003 + DECL_EXTERNAL(latent_entropy_decl) = 1;
84004 + DECL_ARTIFICIAL(latent_entropy_decl) = 0;
84005 + DECL_INITIAL(latent_entropy_decl) = NULL;
84006 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
84007 +// varpool_finalize_decl(latent_entropy_decl);
84008 +// varpool_mark_needed_node(latent_entropy_decl);
84009 +}
84010 +
84011 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
84012 +{
84013 + const char * const plugin_name = plugin_info->base_name;
84014 + struct register_pass_info latent_entropy_pass_info = {
84015 + .pass = &latent_entropy_pass.pass,
84016 + .reference_pass_name = "optimized",
84017 + .ref_pass_instance_number = 1,
84018 + .pos_op = PASS_POS_INSERT_BEFORE
84019 + };
84020 +
84021 + if (!plugin_default_version_check(version, &gcc_version)) {
84022 + error(G_("incompatible gcc/plugin versions"));
84023 + return 1;
84024 + }
84025 +
84026 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
84027 + register_callback ("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
84028 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
84029 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
84030 +
84031 + return 0;
84032 +}
84033 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
84034 new file mode 100644
84035 index 0000000..1ff52ad
84036 --- /dev/null
84037 +++ b/tools/gcc/size_overflow_hash.data
84038 @@ -0,0 +1,3633 @@
84039 +_000001_hash alloc_dr 2 65495 _000001_hash NULL
84040 +_000002_hash __copy_from_user 3 10918 _000002_hash NULL
84041 +_000003_hash copy_from_user 3 17559 _000003_hash NULL
84042 +_000004_hash __copy_from_user_inatomic 3 4365 _000004_hash NULL
84043 +_000005_hash __copy_from_user_nocache 3 39351 _000005_hash NULL
84044 +_000006_hash __copy_to_user_inatomic 3 19214 _000006_hash NULL
84045 +_000007_hash do_xip_mapping_read 5 60297 _000007_hash NULL
84046 +_000008_hash hugetlbfs_read 3 11268 _000008_hash NULL
84047 +_000009_hash kmalloc 1 60432 _002597_hash NULL nohasharray
84048 +_000010_hash kmalloc_array 1-2 9444 _000010_hash NULL
84049 +_000012_hash kmalloc_slab 1 11917 _000012_hash NULL
84050 +_000013_hash kmemdup 2 64015 _000013_hash NULL
84051 +_000014_hash __krealloc 2 14857 _000331_hash NULL nohasharray
84052 +_000015_hash memdup_user 2 59590 _000015_hash NULL
84053 +_000016_hash module_alloc 1 63630 _000016_hash NULL
84054 +_000017_hash read_default_ldt 2 14302 _000017_hash NULL
84055 +_000018_hash read_kcore 3 63488 _000018_hash NULL
84056 +_000019_hash read_ldt 2 47570 _000019_hash NULL
84057 +_000020_hash read_zero 3 19366 _000020_hash NULL
84058 +_000021_hash __vmalloc_node 1 39308 _000021_hash NULL
84059 +_000022_hash vm_map_ram 2 23078 _001054_hash NULL nohasharray
84060 +_000023_hash aa_simple_write_to_buffer 4-3 49683 _000023_hash NULL
84061 +_000024_hash ablkcipher_copy_iv 3 64140 _000024_hash NULL
84062 +_000025_hash ablkcipher_next_slow 4-3 47274 _000025_hash NULL
84063 +_000026_hash acpi_battery_write_alarm 3 1240 _000026_hash NULL
84064 +_000027_hash acpi_os_allocate 1 14892 _000027_hash NULL
84065 +_000028_hash acpi_system_write_wakeup_device 3 34853 _000028_hash NULL
84066 +_000029_hash adu_write 3 30487 _000029_hash NULL
84067 +_000030_hash aer_inject_write 3 52399 _000030_hash NULL
84068 +_000031_hash afs_alloc_flat_call 2-3 36399 _000031_hash NULL
84069 +_000033_hash afs_proc_cells_write 3 61139 _000033_hash NULL
84070 +_000034_hash afs_proc_rootcell_write 3 15822 _000034_hash NULL
84071 +_000035_hash agp_3_5_isochronous_node_enable 3 49465 _000035_hash NULL
84072 +_000036_hash agp_alloc_page_array 1 22554 _000036_hash NULL
84073 +_000037_hash ah_alloc_tmp 2-3 54378 _000037_hash NULL
84074 +_000038_hash ahash_setkey_unaligned 3 33521 _000038_hash NULL
84075 +_000039_hash alg_setkey 3 31485 _000039_hash NULL
84076 +_000040_hash aligned_kmalloc 1 3628 _000040_hash NULL
84077 +_000041_hash alloc_context 1 3194 _000041_hash NULL
84078 +_000042_hash alloc_ep_req 2 54860 _000042_hash NULL
84079 +_000043_hash alloc_fdmem 1 27083 _000043_hash NULL
84080 +_000044_hash alloc_flex_gd 1 57259 _000044_hash NULL
84081 +_000045_hash alloc_sglist 1-3-2 22960 _000045_hash NULL
84082 +_000046_hash aoedev_flush 2 44398 _000046_hash NULL
84083 +_000047_hash append_to_buffer 3 63550 _000047_hash NULL
84084 +_000048_hash asix_read_cmd 5 13245 _000048_hash NULL
84085 +_000049_hash asix_write_cmd 5 58192 _000049_hash NULL
84086 +_000050_hash asn1_octets_decode 2 9991 _000050_hash NULL
84087 +_000051_hash asn1_oid_decode 2 4999 _000051_hash NULL
84088 +_000052_hash at76_set_card_command 4 4471 _000052_hash NULL
84089 +_000053_hash ath6kl_add_bss_if_needed 6 24317 _000053_hash NULL
84090 +_000054_hash ath6kl_debug_roam_tbl_event 3 5224 _000054_hash NULL
84091 +_000055_hash ath6kl_mgmt_powersave_ap 6 13791 _000055_hash NULL
84092 +_000056_hash ath6kl_send_go_probe_resp 3 21113 _000056_hash NULL
84093 +_000057_hash ath6kl_set_ap_probe_resp_ies 3 50539 _000057_hash NULL
84094 +_000058_hash ath6kl_set_assoc_req_ies 3 43185 _000058_hash NULL
84095 +_000059_hash ath6kl_wmi_bssinfo_event_rx 3 2275 _000059_hash NULL
84096 +_000060_hash ath6kl_wmi_send_action_cmd 7 58860 _000060_hash NULL
84097 +_000061_hash __ath6kl_wmi_send_mgmt_cmd 7 38971 _000061_hash NULL
84098 +_000062_hash attach_hdlc_protocol 3 19986 _000062_hash NULL
84099 +_000063_hash audio_write 4 54261 _001597_hash NULL nohasharray
84100 +_000064_hash audit_unpack_string 3 13748 _000064_hash NULL
84101 +_000065_hash av7110_vbi_write 3 34384 _000065_hash NULL
84102 +_000066_hash ax25_setsockopt 5 42740 _000066_hash NULL
84103 +_000067_hash b43_debugfs_write 3 34838 _000067_hash NULL
84104 +_000068_hash b43legacy_debugfs_write 3 28556 _000068_hash NULL
84105 +_000069_hash bch_alloc 1 4593 _000069_hash NULL
84106 +_000070_hash befs_nls2utf 3 17163 _000070_hash NULL
84107 +_000071_hash befs_utf2nls 3 25628 _000071_hash NULL
84108 +_000072_hash bfad_debugfs_write_regrd 3 15218 _000072_hash NULL
84109 +_000073_hash bfad_debugfs_write_regwr 3 61841 _000073_hash NULL
84110 +_000074_hash bio_alloc_map_data 1-2 50782 _000074_hash NULL
84111 +_000076_hash bio_kmalloc 2 54672 _000076_hash NULL
84112 +_000077_hash blkcipher_copy_iv 3 24075 _000077_hash NULL
84113 +_000078_hash blkcipher_next_slow 4-3 52733 _000078_hash NULL
84114 +_000079_hash bl_pipe_downcall 3 34264 _000079_hash NULL
84115 +_000080_hash bnad_debugfs_write_regrd 3 6706 _000080_hash NULL
84116 +_000081_hash bnad_debugfs_write_regwr 3 57500 _000081_hash NULL
84117 +_000082_hash bnx2fc_cmd_mgr_alloc 2-3 24873 _000082_hash NULL
84118 +_000084_hash bnx2_nvram_write 4-2 7790 _000084_hash NULL
84119 +_000085_hash brcmf_sdbrcm_downloadvars 3 42064 _000085_hash NULL
84120 +_000086_hash btmrvl_gpiogap_write 3 35053 _000086_hash NULL
84121 +_000087_hash btmrvl_hscfgcmd_write 3 27143 _000087_hash NULL
84122 +_000088_hash btmrvl_hscmd_write 3 27089 _000088_hash NULL
84123 +_000089_hash btmrvl_hsmode_write 3 42252 _000089_hash NULL
84124 +_000090_hash btmrvl_pscmd_write 3 29504 _000090_hash NULL
84125 +_000091_hash btmrvl_psmode_write 3 3703 _000091_hash NULL
84126 +_000092_hash btrfs_alloc_delayed_item 1 11678 _000092_hash NULL
84127 +_000093_hash cache_do_downcall 3 6926 _000093_hash NULL
84128 +_000094_hash cachefiles_cook_key 2 33274 _000094_hash NULL
84129 +_000095_hash cachefiles_daemon_write 3 43535 _000095_hash NULL
84130 +_000096_hash capi_write 3 35104 _000096_hash NULL
84131 +_000097_hash carl9170_debugfs_write 3 50857 _000097_hash NULL
84132 +_000098_hash cciss_allocate_sg_chain_blocks 2-3 5368 _000098_hash NULL
84133 +_000100_hash cciss_proc_write 3 10259 _000100_hash NULL
84134 +_000101_hash cdrom_read_cdda_old 4 27664 _000101_hash NULL
84135 +_000102_hash ceph_alloc_page_vector 1 18710 _000102_hash NULL
84136 +_000103_hash ceph_buffer_new 1 35974 _000103_hash NULL
84137 +_000104_hash ceph_copy_user_to_page_vector 4-3 656 _000104_hash NULL
84138 +_000105_hash ceph_get_direct_page_vector 2 41917 _000105_hash NULL
84139 +_000106_hash ceph_msg_new 2 5846 _000106_hash NULL
84140 +_000107_hash ceph_setxattr 4 18913 _000107_hash NULL
84141 +_000108_hash cfi_read_pri 3 24366 _000108_hash NULL
84142 +_000109_hash cgroup_write_string 5 10900 _000109_hash NULL
84143 +_000110_hash cgroup_write_X64 5 54514 _000110_hash NULL
84144 +_000111_hash change_xattr 5 61390 _000111_hash NULL
84145 +_000112_hash check_load_and_stores 2 2143 _000112_hash NULL
84146 +_000113_hash cifs_idmap_key_instantiate 3 54503 _000113_hash NULL
84147 +_000114_hash cifs_security_flags_proc_write 3 5484 _000114_hash NULL
84148 +_000115_hash cifs_setxattr 4 23957 _000115_hash NULL
84149 +_000116_hash cifs_spnego_key_instantiate 3 23588 _000116_hash NULL
84150 +_000117_hash ci_ll_write 4 3740 _000117_hash NULL
84151 +_000118_hash cld_pipe_downcall 3 15058 _000118_hash NULL
84152 +_000119_hash clear_refs_write 3 61904 _000119_hash NULL
84153 +_000120_hash clusterip_proc_write 3 44729 _000120_hash NULL
84154 +_000121_hash cm4040_write 3 58079 _000121_hash NULL
84155 +_000122_hash cm_copy_private_data 2 3649 _000122_hash NULL
84156 +_000123_hash cmm_write 3 2896 _000123_hash NULL
84157 +_000124_hash cm_write 3 36858 _000124_hash NULL
84158 +_000125_hash coda_psdev_write 3 1711 _000125_hash NULL
84159 +_000126_hash codec_reg_read_file 3 36280 _000126_hash NULL
84160 +_000127_hash command_file_write 3 31318 _000127_hash NULL
84161 +_000128_hash command_write 3 58841 _000128_hash NULL
84162 +_000129_hash comm_write 3 44537 _001532_hash NULL nohasharray
84163 +_000130_hash concat_writev 3 21451 _000130_hash NULL
84164 +_000131_hash copy_and_check 3 19089 _000131_hash NULL
84165 +_000132_hash copy_from_user_toio 3 31966 _000132_hash NULL
84166 +_000133_hash copy_items 6 50140 _000133_hash NULL
84167 +_000134_hash copy_macs 4 45534 _000134_hash NULL
84168 +_000135_hash __copy_to_user 3 17551 _000135_hash NULL
84169 +_000136_hash copy_vm86_regs_from_user 3 45340 _000136_hash NULL
84170 +_000137_hash cosa_write 3 1774 _000137_hash NULL
84171 +_000138_hash create_entry 2 33479 _000138_hash NULL
84172 +_000139_hash create_queues 2-3 9088 _000139_hash NULL
84173 +_000141_hash create_xattr 5 54106 _000141_hash NULL
84174 +_000142_hash create_xattr_datum 5 33356 _000142_hash NULL
84175 +_000143_hash csum_partial_copy_fromiovecend 3-4 9957 _000143_hash NULL
84176 +_000145_hash ctrl_out 3-5 8712 _000145_hash NULL
84177 +_000147_hash cx24116_writeregN 4 41975 _000147_hash NULL
84178 +_000148_hash cxacru_cm_get_array 4 4412 _000148_hash NULL
84179 +_000149_hash cxgbi_alloc_big_mem 1 4707 _000149_hash NULL
84180 +_000150_hash dac960_user_command_proc_write 3 3071 _000150_hash NULL
84181 +_000151_hash datablob_format 2 39571 _002156_hash NULL nohasharray
84182 +_000152_hash dccp_feat_clone_sp_val 3 11942 _000152_hash NULL
84183 +_000153_hash dccp_setsockopt_ccid 4 30701 _000153_hash NULL
84184 +_000154_hash dccp_setsockopt_cscov 2 37766 _000154_hash NULL
84185 +_000155_hash dccp_setsockopt_service 4 65336 _000155_hash NULL
84186 +_000156_hash ddb_output_write 3 31902 _000156_hash NULL
84187 +_000157_hash ddebug_proc_write 3 18055 _000157_hash NULL
84188 +_000158_hash dev_config 3 8506 _000158_hash NULL
84189 +_000159_hash device_write 3 45156 _000159_hash NULL
84190 +_000160_hash devm_kzalloc 2 4966 _000160_hash NULL
84191 +_000161_hash devres_alloc 2 551 _000161_hash NULL
84192 +_000162_hash dfs_file_write 3 41196 _000162_hash NULL
84193 +_000163_hash direct_entry 3 38836 _000163_hash NULL
84194 +_000164_hash dispatch_proc_write 3 44320 _000164_hash NULL
84195 +_000165_hash diva_os_copy_from_user 4 7792 _000165_hash NULL
84196 +_000166_hash dlm_alloc_pagevec 1 54296 _000166_hash NULL
84197 +_000167_hash dlmfs_file_read 3 28385 _000167_hash NULL
84198 +_000168_hash dlmfs_file_write 3 6892 _000168_hash NULL
84199 +_000169_hash dm_read 3 15674 _000169_hash NULL
84200 +_000170_hash dm_write 3 2513 _000170_hash NULL
84201 +_000171_hash __dn_setsockopt 5 13060 _000171_hash NULL
84202 +_000172_hash dns_query 3 9676 _000172_hash NULL
84203 +_000173_hash dns_resolver_instantiate 3 63314 _000173_hash NULL
84204 +_000174_hash do_add_counters 3 3992 _000174_hash NULL
84205 +_000175_hash __do_config_autodelink 3 58763 _000175_hash NULL
84206 +_000176_hash do_ip_setsockopt 5 41852 _000176_hash NULL
84207 +_000177_hash do_ipv6_setsockopt 5 18215 _000177_hash NULL
84208 +_000178_hash do_ip_vs_set_ctl 4 48641 _000178_hash NULL
84209 +_000179_hash do_kimage_alloc 3 64827 _000179_hash NULL
84210 +_000180_hash do_register_entry 4 29478 _000180_hash NULL
84211 +_000181_hash do_tty_write 5 44896 _000181_hash NULL
84212 +_000182_hash do_update_counters 4 2259 _000182_hash NULL
84213 +_000183_hash dsp_write 2 46218 _000183_hash NULL
84214 +_000184_hash dup_to_netobj 3 26363 _000184_hash NULL
84215 +_000185_hash dvb_aplay 3 56296 _000185_hash NULL
84216 +_000186_hash dvb_ca_en50221_io_write 3 43533 _000186_hash NULL
84217 +_000187_hash dvbdmx_write 3 19423 _000187_hash NULL
84218 +_000188_hash dvb_play 3 50814 _000188_hash NULL
84219 +_000189_hash dw210x_op_rw 6 39915 _000189_hash NULL
84220 +_000190_hash dwc3_link_state_write 3 12641 _000190_hash NULL
84221 +_000191_hash dwc3_mode_write 3 51997 _000191_hash NULL
84222 +_000192_hash dwc3_testmode_write 3 30516 _000192_hash NULL
84223 +_000193_hash ecryptfs_copy_filename 4 11868 _000193_hash NULL
84224 +_000194_hash ecryptfs_miscdev_write 3 26847 _000194_hash NULL
84225 +_000195_hash ecryptfs_send_miscdev 2 64816 _000195_hash NULL
84226 +_000196_hash efx_tsoh_heap_alloc 2 58545 _000196_hash NULL
84227 +_000197_hash emi26_writememory 4 57908 _000197_hash NULL
84228 +_000198_hash emi62_writememory 4 29731 _000198_hash NULL
84229 +_000199_hash encrypted_instantiate 3 3168 _000199_hash NULL
84230 +_000200_hash encrypted_update 3 13414 _000200_hash NULL
84231 +_000201_hash ep0_write 3 14536 _001328_hash NULL nohasharray
84232 +_000202_hash ep_read 3 58813 _000202_hash NULL
84233 +_000203_hash ep_write 3 59008 _000203_hash NULL
84234 +_000204_hash erst_dbg_write 3 46715 _000204_hash NULL
84235 +_000205_hash esp_alloc_tmp 2-3 40558 _000205_hash NULL
84236 +_000206_hash exofs_read_lookup_dev_table 3 17733 _000206_hash NULL
84237 +_000207_hash ext4_kvmalloc 1 14796 _000207_hash NULL
84238 +_000208_hash ezusb_writememory 4 45976 _000208_hash NULL
84239 +_000209_hash fanotify_write 3 64623 _000209_hash NULL
84240 +_000210_hash fd_copyin 3 56247 _000210_hash NULL
84241 +_000211_hash ffs_epfile_io 3 64886 _000211_hash NULL
84242 +_000212_hash ffs_prepare_buffer 2 59892 _000212_hash NULL
84243 +_000213_hash f_hidg_write 3 7932 _000213_hash NULL
84244 +_000214_hash file_read_actor 4 1401 _000214_hash NULL
84245 +_000215_hash fill_write_buffer 3 3142 _000215_hash NULL
84246 +_000216_hash fl_create 5 56435 _000216_hash NULL
84247 +_000217_hash ftdi_elan_write 3 57309 _000217_hash NULL
84248 +_000218_hash fuse_conn_limit_write 3 30777 _003837_hash NULL nohasharray
84249 +_000219_hash fw_iso_buffer_init 3 54582 _000219_hash NULL
84250 +_000220_hash garmin_write_bulk 3 58191 _000220_hash NULL
84251 +_000221_hash garp_attr_create 3 3883 _000221_hash NULL
84252 +_000222_hash get_arg 3 5694 _000222_hash NULL
84253 +_000223_hash getdqbuf 1 62908 _000223_hash NULL
84254 +_000224_hash get_fdb_entries 3 41916 _000224_hash NULL
84255 +_000225_hash get_indirect_ea 4 51869 _000225_hash NULL
84256 +_000226_hash get_registers 3 26187 _000226_hash NULL
84257 +_000227_hash get_scq 2 10897 _000227_hash NULL
84258 +_000228_hash get_server_iovec 2 16804 _000228_hash NULL
84259 +_000229_hash get_ucode_user 3 38202 _000229_hash NULL
84260 +_000230_hash get_user_cpu_mask 2 14861 _000230_hash NULL
84261 +_000231_hash gfs2_alloc_sort_buffer 1 18275 _000231_hash NULL
84262 +_000232_hash gfs2_glock_nq_m 1 20347 _000232_hash NULL
84263 +_000233_hash gigaset_initcs 2 43753 _000233_hash NULL
84264 +_000234_hash gigaset_initdriver 2 1060 _000234_hash NULL
84265 +_000235_hash gs_alloc_req 2 58883 _000235_hash NULL
84266 +_000236_hash gs_buf_alloc 2 25067 _000236_hash NULL
84267 +_000237_hash gsm_data_alloc 3 42437 _000237_hash NULL
84268 +_000238_hash gss_pipe_downcall 3 23182 _000238_hash NULL
84269 +_000239_hash handle_request 9 10024 _000239_hash NULL
84270 +_000240_hash hash_new 1 62224 _000240_hash NULL
84271 +_000241_hash hashtab_create 3 33769 _000241_hash NULL
84272 +_000242_hash hcd_buffer_alloc 2 27495 _000242_hash NULL
84273 +_000243_hash hci_sock_setsockopt 5 28993 _000243_hash NULL
84274 +_000244_hash heap_init 2 49617 _000244_hash NULL
84275 +_000245_hash hest_ghes_dev_register 1 46766 _000245_hash NULL
84276 +_000246_hash hidraw_get_report 3 45609 _000246_hash NULL
84277 +_000247_hash hidraw_report_event 3 49578 _000509_hash NULL nohasharray
84278 +_000248_hash hidraw_send_report 3 23449 _000248_hash NULL
84279 +_000249_hash hpfs_translate_name 3 41497 _000249_hash NULL
84280 +_000250_hash hysdn_conf_write 3 52145 _000250_hash NULL
84281 +_000251_hash hysdn_log_write 3 48694 _000251_hash NULL
84282 +_000252_hash __i2400mu_send_barker 3 23652 _000252_hash NULL
84283 +_000253_hash i2cdev_read 3 1206 _000253_hash NULL
84284 +_000254_hash i2cdev_write 3 23310 _000254_hash NULL
84285 +_000255_hash i2o_parm_field_get 5 34477 _000255_hash NULL
84286 +_000256_hash i2o_parm_table_get 6 61635 _000256_hash NULL
84287 +_000257_hash ib_copy_from_udata 3 59502 _000257_hash NULL
84288 +_000258_hash ib_ucm_alloc_data 3 36885 _000258_hash NULL
84289 +_000259_hash ib_umad_write 3 47993 _000259_hash NULL
84290 +_000260_hash ib_uverbs_unmarshall_recv 5 12251 _000260_hash NULL
84291 +_000261_hash icn_writecmd 2 38629 _000261_hash NULL
84292 +_000262_hash ide_driver_proc_write 3 32493 _000262_hash NULL
84293 +_000263_hash ide_settings_proc_write 3 35110 _000263_hash NULL
84294 +_000264_hash idetape_chrdev_write 3 53976 _000264_hash NULL
84295 +_000265_hash idmap_pipe_downcall 3 14591 _000265_hash NULL
84296 +_000266_hash ieee80211_build_probe_req 7-5 27660 _000266_hash NULL
84297 +_000267_hash ieee80211_if_write 3 34894 _000267_hash NULL
84298 +_000268_hash if_write 3 51756 _000268_hash NULL
84299 +_000269_hash ilo_write 3 64378 _000269_hash NULL
84300 +_000270_hash ima_write_policy 3 40548 _000270_hash NULL
84301 +_000271_hash init_data_container 1 60709 _000271_hash NULL
84302 +_000272_hash init_send_hfcd 1 34586 _000272_hash NULL
84303 +_000273_hash insert_dent 7 65034 _000273_hash NULL
84304 +_000274_hash interpret_user_input 2 19393 _000274_hash NULL
84305 +_000275_hash int_proc_write 3 39542 _000275_hash NULL
84306 +_000276_hash ioctl_private_iw_point 7 1273 _000276_hash NULL
84307 +_000277_hash iov_iter_copy_from_user 4 31942 _000277_hash NULL
84308 +_000278_hash iov_iter_copy_from_user_atomic 4 56368 _000278_hash NULL
84309 +_000279_hash iowarrior_write 3 18604 _000279_hash NULL
84310 +_000280_hash ipc_alloc 1 1192 _000280_hash NULL
84311 +_000281_hash ipc_rcu_alloc 1 21208 _000281_hash NULL
84312 +_000282_hash ip_options_get_from_user 4 64958 _000282_hash NULL
84313 +_000283_hash ipv6_renew_option 3 38813 _000283_hash NULL
84314 +_000284_hash ip_vs_conn_fill_param_sync 6 29771 _002404_hash NULL nohasharray
84315 +_000285_hash ip_vs_create_timeout_table 2 64478 _000285_hash NULL
84316 +_000286_hash ipw_queue_tx_init 3 49161 _000286_hash NULL
84317 +_000287_hash irda_setsockopt 5 19824 _000287_hash NULL
84318 +_000288_hash irias_new_octseq_value 2 13596 _003296_hash NULL nohasharray
84319 +_000289_hash ir_lirc_transmit_ir 3 64403 _000289_hash NULL
84320 +_000290_hash irnet_ctrl_write 3 24139 _000290_hash NULL
84321 +_000291_hash isdn_add_channels 3 40905 _000291_hash NULL
84322 +_000292_hash isdn_ppp_fill_rq 2 41428 _000292_hash NULL
84323 +_000293_hash isdn_ppp_write 4 29109 _000293_hash NULL
84324 +_000294_hash isdn_read 3 50021 _000294_hash NULL
84325 +_000295_hash isdn_v110_open 3 2418 _000295_hash NULL
84326 +_000296_hash isdn_writebuf_stub 4 52383 _000296_hash NULL
84327 +_000297_hash islpci_mgt_transmit 5 34133 _000297_hash NULL
84328 +_000298_hash iso_callback 3 43208 _000298_hash NULL
84329 +_000299_hash iso_packets_buffer_init 3-4 29061 _000299_hash NULL
84330 +_000300_hash it821x_firmware_command 3 8628 _000300_hash NULL
84331 +_000301_hash ivtv_buf_copy_from_user 4 25502 _000301_hash NULL
84332 +_000302_hash iwch_alloc_fastreg_pbl 2 40153 _000302_hash NULL
84333 +_000303_hash iwl_calib_set 3 34400 _002188_hash NULL nohasharray
84334 +_000304_hash jbd2_journal_init_revoke_table 1 36336 _000304_hash NULL
84335 +_000305_hash jffs2_alloc_full_dirent 1 60179 _001111_hash NULL nohasharray
84336 +_000306_hash journal_init_revoke_table 1 56331 _000306_hash NULL
84337 +_000307_hash kcalloc 1-2 27770 _000307_hash NULL
84338 +_000309_hash keyctl_instantiate_key_common 4 47889 _000309_hash NULL
84339 +_000310_hash keyctl_update_key 3 26061 _000310_hash NULL
84340 +_000311_hash __kfifo_alloc 2-3 22173 _000311_hash NULL
84341 +_000313_hash kfifo_copy_from_user 3 5091 _000313_hash NULL
84342 +_000314_hash kmalloc_node 1 50163 _003293_hash NULL nohasharray
84343 +_000315_hash kmalloc_parameter 1 65279 _000315_hash NULL
84344 +_000316_hash kmem_alloc 1 31920 _000316_hash NULL
84345 +_000317_hash kobj_map 2-3 9566 _000317_hash NULL
84346 +_000319_hash kone_receive 4 4690 _000319_hash NULL
84347 +_000320_hash kone_send 4 63435 _000320_hash NULL
84348 +_000321_hash krealloc 2 14908 _000321_hash NULL
84349 +_000322_hash kvmalloc 1 32646 _000322_hash NULL
84350 +_000323_hash kvm_read_guest_atomic 4 10765 _000323_hash NULL
84351 +_000324_hash kvm_read_guest_cached 4 39666 _000324_hash NULL
84352 +_000325_hash kvm_read_guest_page 5 18074 _000325_hash NULL
84353 +_000326_hash kzalloc 1 54740 _000326_hash NULL
84354 +_000327_hash l2cap_sock_setsockopt 5 50207 _000327_hash NULL
84355 +_000328_hash l2cap_sock_setsockopt_old 4 29346 _000328_hash NULL
84356 +_000329_hash lane2_associate_req 4 45398 _000329_hash NULL
84357 +_000330_hash lbs_debugfs_write 3 48413 _000330_hash NULL
84358 +_000331_hash lcd_write 3 14857 _000331_hash &_000014_hash
84359 +_000332_hash ldm_frag_add 2 5611 _000332_hash NULL
84360 +_000333_hash __lgread 4 31668 _000333_hash NULL
84361 +_000334_hash libipw_alloc_txb 1-3-2 27579 _000334_hash NULL
84362 +_000335_hash link_send_sections_long 4 46556 _000335_hash NULL
84363 +_000336_hash listxattr 3 12769 _000336_hash NULL
84364 +_000337_hash LoadBitmap 2 19658 _000337_hash NULL
84365 +_000338_hash load_msg 2 95 _000338_hash NULL
84366 +_000339_hash lpfc_debugfs_dif_err_write 3 17424 _000339_hash NULL
84367 +_000340_hash lp_write 3 9511 _000340_hash NULL
84368 +_000341_hash mb_cache_create 2 17307 _000341_hash NULL
84369 +_000342_hash mce_write 3 26201 _000342_hash NULL
84370 +_000343_hash mcs7830_get_reg 3 33308 _000343_hash NULL
84371 +_000344_hash mcs7830_set_reg 3 31413 _000344_hash NULL
84372 +_000345_hash memcpy_fromiovec 3 55247 _000345_hash NULL
84373 +_000346_hash memcpy_fromiovecend 3-4 2707 _000346_hash NULL
84374 +_000348_hash mempool_kmalloc 2 53831 _000348_hash NULL
84375 +_000349_hash mempool_resize 2 47983 _001821_hash NULL nohasharray
84376 +_000350_hash mem_rw 3 22085 _000350_hash NULL
84377 +_000351_hash mgmt_control 3 7349 _000351_hash NULL
84378 +_000352_hash mgmt_pending_add 5 46976 _000352_hash NULL
84379 +_000353_hash mlx4_ib_alloc_fast_reg_page_list 2 46119 _000353_hash NULL
84380 +_000354_hash mmc_alloc_sg 1 21504 _000354_hash NULL
84381 +_000355_hash mmc_send_bus_test 4 18285 _000355_hash NULL
84382 +_000356_hash mmc_send_cxd_data 5 38655 _000356_hash NULL
84383 +_000357_hash module_alloc_update_bounds 1 47205 _000357_hash NULL
84384 +_000358_hash move_addr_to_kernel 2 32673 _000358_hash NULL
84385 +_000359_hash mpi_alloc_limb_space 1 23190 _000359_hash NULL
84386 +_000360_hash mpi_resize 2 44674 _000360_hash NULL
84387 +_000361_hash mptctl_getiocinfo 2 28545 _000361_hash NULL
84388 +_000362_hash mtdchar_readoob 4 31200 _000362_hash NULL
84389 +_000363_hash mtdchar_write 3 56831 _002688_hash NULL nohasharray
84390 +_000364_hash mtdchar_writeoob 4 3393 _000364_hash NULL
84391 +_000365_hash mtd_device_parse_register 5 5024 _000365_hash NULL
84392 +_000366_hash mtf_test_write 3 18844 _000366_hash NULL
84393 +_000367_hash mtrr_write 3 59622 _000367_hash NULL
84394 +_000368_hash musb_test_mode_write 3 33518 _000368_hash NULL
84395 +_000369_hash mwifiex_get_common_rates 3 17131 _000369_hash NULL
84396 +_000370_hash mwifiex_update_curr_bss_params 5 16908 _000370_hash NULL
84397 +_000371_hash nand_bch_init 2-3 16280 _001341_hash NULL nohasharray
84398 +_000373_hash ncp_file_write 3 3813 _000373_hash NULL
84399 +_000374_hash ncp__vol2io 5 4804 _000374_hash NULL
84400 +_000375_hash nes_alloc_fast_reg_page_list 2 33523 _000375_hash NULL
84401 +_000376_hash nfc_targets_found 3 29886 _000376_hash NULL
84402 +_000377_hash nfs4_acl_new 1 49806 _000377_hash NULL
84403 +_000378_hash nfs4_write_cached_acl 4 15070 _000378_hash NULL
84404 +_000379_hash nfsd_cache_update 3 59574 _000379_hash NULL
84405 +_000380_hash nfsd_symlink 6 63442 _000380_hash NULL
84406 +_000381_hash nfs_idmap_get_desc 2-4 42990 _000381_hash NULL
84407 +_000383_hash nfs_readdir_make_qstr 3 12509 _000383_hash NULL
84408 +_000384_hash note_last_dentry 3 12285 _000384_hash NULL
84409 +_000385_hash ntfs_copy_from_user 3-5 15072 _000385_hash NULL
84410 +_000387_hash __ntfs_copy_from_user_iovec_inatomic 3-4 38153 _000387_hash NULL
84411 +_000389_hash ntfs_ucstonls 3-5 23097 _000389_hash NULL
84412 +_000390_hash nvme_alloc_iod 1 56027 _000390_hash NULL
84413 +_000391_hash nvram_write 3 3894 _000391_hash NULL
84414 +_000392_hash o2hb_debug_create 4 18744 _000392_hash NULL
84415 +_000393_hash o2net_send_message_vec 4 879 _001792_hash NULL nohasharray
84416 +_000394_hash ocfs2_control_cfu 2 37750 _000394_hash NULL
84417 +_000395_hash oom_adjust_write 3 41116 _000395_hash NULL
84418 +_000396_hash oom_score_adj_write 3 42594 _000396_hash NULL
84419 +_000397_hash opera1_xilinx_rw 5 31453 _000397_hash NULL
84420 +_000398_hash oprofilefs_ulong_from_user 3 57251 _000398_hash NULL
84421 +_000399_hash opticon_write 4 60775 _000399_hash NULL
84422 +_000400_hash orig_node_add_if 2 32833 _000400_hash NULL
84423 +_000401_hash orig_node_del_if 2 28371 _000401_hash NULL
84424 +_000402_hash p9_check_zc_errors 4 15534 _000402_hash NULL
84425 +_000403_hash packet_buffer_init 2 1607 _000403_hash NULL
84426 +_000404_hash packet_setsockopt 5 17662 _000404_hash NULL
84427 +_000405_hash parse_command 2 37079 _000405_hash NULL
84428 +_000406_hash pcbit_writecmd 2 12332 _000406_hash NULL
84429 +_000407_hash pcmcia_replace_cis 3 57066 _000407_hash NULL
84430 +_000408_hash pgctrl_write 3 50453 _000408_hash NULL
84431 +_000409_hash pg_write 3 40766 _000409_hash NULL
84432 +_000410_hash pidlist_allocate 1 64404 _000410_hash NULL
84433 +_000411_hash pipe_iov_copy_from_user 3 23102 _000411_hash NULL
84434 +_000412_hash pipe_iov_copy_to_user 3 3447 _000412_hash NULL
84435 +_000413_hash pkt_add 3 39897 _000413_hash NULL
84436 +_000414_hash pktgen_if_write 3 55628 _000414_hash NULL
84437 +_000415_hash platform_device_add_data 3 310 _000415_hash NULL
84438 +_000416_hash platform_device_add_resources 3 13289 _000416_hash NULL
84439 +_000417_hash pm_qos_power_write 3 52513 _000417_hash NULL
84440 +_000418_hash pnpbios_proc_write 3 19758 _000418_hash NULL
84441 +_000419_hash pool_allocate 3 42012 _000419_hash NULL
84442 +_000420_hash posix_acl_alloc 1 48063 _000420_hash NULL
84443 +_000421_hash ppp_cp_parse_cr 4 5214 _000421_hash NULL
84444 +_000422_hash ppp_write 3 34034 _000422_hash NULL
84445 +_000423_hash pp_read 3 33210 _000423_hash NULL
84446 +_000424_hash pp_write 3 39554 _000424_hash NULL
84447 +_000425_hash printer_req_alloc 2 62687 _001807_hash NULL nohasharray
84448 +_000426_hash printer_write 3 60276 _000426_hash NULL
84449 +_000427_hash prism2_set_genericelement 3 29277 _000427_hash NULL
84450 +_000428_hash __probe_kernel_read 3 61119 _000428_hash NULL
84451 +_000429_hash __probe_kernel_write 3 29842 _000429_hash NULL
84452 +_000430_hash proc_coredump_filter_write 3 25625 _000430_hash NULL
84453 +_000431_hash _proc_do_string 2 6376 _000431_hash NULL
84454 +_000432_hash process_vm_rw_pages 5-6 15954 _000432_hash NULL
84455 +_000434_hash proc_loginuid_write 3 63648 _000434_hash NULL
84456 +_000435_hash proc_pid_attr_write 3 63845 _000435_hash NULL
84457 +_000436_hash proc_scsi_devinfo_write 3 32064 _000436_hash NULL
84458 +_000437_hash proc_scsi_write 3 29142 _000437_hash NULL
84459 +_000438_hash proc_scsi_write_proc 3 267 _000438_hash NULL
84460 +_000439_hash pstore_mkfile 5 50830 _000439_hash NULL
84461 +_000440_hash pti_char_write 3 60960 _000440_hash NULL
84462 +_000441_hash ptrace_writedata 4 45021 _000441_hash NULL
84463 +_000442_hash pt_write 3 40159 _000442_hash NULL
84464 +_000443_hash pvr2_ioread_set_sync_key 3 59882 _000443_hash NULL
84465 +_000444_hash pvr2_stream_buffer_count 2 33719 _000444_hash NULL
84466 +_000445_hash qdisc_class_hash_alloc 1 18262 _000445_hash NULL
84467 +_000446_hash r3964_write 4 57662 _000446_hash NULL
84468 +_000447_hash raw_seticmpfilter 3 6888 _000447_hash NULL
84469 +_000448_hash raw_setsockopt 5 45800 _000448_hash NULL
84470 +_000449_hash rawv6_seticmpfilter 5 12137 _000449_hash NULL
84471 +_000450_hash ray_cs_essid_proc_write 3 17875 _000450_hash NULL
84472 +_000451_hash rbd_add 3 16366 _000451_hash NULL
84473 +_000452_hash rbd_snap_add 4 19678 _000452_hash NULL
84474 +_000453_hash rdma_set_ib_paths 3 45592 _000453_hash NULL
84475 +_000454_hash rds_page_copy_user 4 35691 _000454_hash NULL
84476 +_000455_hash read 3 9397 _000455_hash NULL
84477 +_000456_hash read_buf 2 20469 _000456_hash NULL
84478 +_000457_hash read_cis_cache 4 29735 _000457_hash NULL
84479 +_000458_hash realloc_buffer 2 25816 _000458_hash NULL
84480 +_000459_hash realloc_packet_buffer 2 25569 _000459_hash NULL
84481 +_000460_hash receive_DataRequest 3 9904 _000460_hash NULL
84482 +_000461_hash recent_mt_proc_write 3 8206 _000461_hash NULL
84483 +_000462_hash regmap_access_read_file 3 37223 _000462_hash NULL
84484 +_000463_hash regmap_bulk_write 4 59049 _000463_hash NULL
84485 +_000464_hash regmap_map_read_file 3 37685 _000464_hash NULL
84486 +_000465_hash regset_tls_set 4 18459 _000465_hash NULL
84487 +_000466_hash reg_w_buf 3 27724 _000466_hash NULL
84488 +_000467_hash reg_w_ixbuf 4 34736 _000467_hash NULL
84489 +_000468_hash remote_settings_file_write 3 22987 _000468_hash NULL
84490 +_000469_hash request_key_auth_new 3 38092 _000469_hash NULL
84491 +_000470_hash restore_i387_fxsave 2 17528 _000470_hash NULL
84492 +_000471_hash revalidate 2 19043 _000471_hash NULL
84493 +_000472_hash rfcomm_sock_setsockopt 5 18254 _000472_hash NULL
84494 +_000473_hash rndis_add_response 2 58544 _000473_hash NULL
84495 +_000474_hash rndis_set_oid 4 6547 _000474_hash NULL
84496 +_000475_hash rngapi_reset 3 34366 _002911_hash NULL nohasharray
84497 +_000476_hash roccat_common_receive 4 53407 _000476_hash NULL
84498 +_000477_hash roccat_common_send 4 12284 _000477_hash NULL
84499 +_000478_hash rpc_malloc 2 43573 _000478_hash NULL
84500 +_000479_hash rt2x00debug_write_bbp 3 8212 _000479_hash NULL
84501 +_000480_hash rt2x00debug_write_csr 3 64753 _000480_hash NULL
84502 +_000481_hash rt2x00debug_write_eeprom 3 23091 _000481_hash NULL
84503 +_000482_hash rt2x00debug_write_rf 3 38195 _000482_hash NULL
84504 +_000483_hash rts51x_read_mem 4 26577 _000483_hash NULL
84505 +_000484_hash rts51x_read_status 4 11830 _000484_hash NULL
84506 +_000485_hash rts51x_write_mem 4 17598 _000485_hash NULL
84507 +_000486_hash rw_copy_check_uvector 3 34271 _000486_hash NULL
84508 +_000487_hash rxrpc_request_key 3 27235 _000487_hash NULL
84509 +_000488_hash rxrpc_server_keyring 3 16431 _000488_hash NULL
84510 +_000489_hash savemem 3 58129 _000489_hash NULL
84511 +_000490_hash sb16_copy_from_user 10-7-6 55836 _000490_hash NULL
84512 +_000493_hash sched_autogroup_write 3 10984 _000493_hash NULL
84513 +_000494_hash scsi_mode_select 6 37330 _000494_hash NULL
84514 +_000495_hash scsi_tgt_copy_sense 3 26933 _000495_hash NULL
84515 +_000496_hash sctp_auth_create_key 1 51641 _000496_hash NULL
84516 +_000497_hash sctp_getsockopt_delayed_ack 2 9232 _000497_hash NULL
84517 +_000498_hash sctp_getsockopt_local_addrs 2 25178 _000498_hash NULL
84518 +_000499_hash sctp_make_abort_user 3 29654 _000499_hash NULL
84519 +_000500_hash sctp_setsockopt_active_key 3 43755 _000500_hash NULL
84520 +_000501_hash sctp_setsockopt_adaptation_layer 3 26935 _001925_hash NULL nohasharray
84521 +_000502_hash sctp_setsockopt_associnfo 3 51684 _000502_hash NULL
84522 +_000503_hash sctp_setsockopt_auth_chunk 3 30843 _000503_hash NULL
84523 +_000504_hash sctp_setsockopt_auth_key 3 3793 _000504_hash NULL
84524 +_000505_hash sctp_setsockopt_autoclose 3 5775 _000505_hash NULL
84525 +_000506_hash sctp_setsockopt_bindx 3 49870 _000506_hash NULL
84526 +_000507_hash __sctp_setsockopt_connectx 3 46949 _000507_hash NULL
84527 +_000508_hash sctp_setsockopt_context 3 31091 _000508_hash NULL
84528 +_000509_hash sctp_setsockopt_default_send_param 3 49578 _000509_hash &_000247_hash
84529 +_000510_hash sctp_setsockopt_delayed_ack 3 40129 _000510_hash NULL
84530 +_000511_hash sctp_setsockopt_del_key 3 42304 _002281_hash NULL nohasharray
84531 +_000512_hash sctp_setsockopt_events 3 18862 _000512_hash NULL
84532 +_000513_hash sctp_setsockopt_hmac_ident 3 11687 _000513_hash NULL
84533 +_000514_hash sctp_setsockopt_initmsg 3 1383 _000514_hash NULL
84534 +_000515_hash sctp_setsockopt_maxburst 3 28041 _000515_hash NULL
84535 +_000516_hash sctp_setsockopt_maxseg 3 11829 _000516_hash NULL
84536 +_000517_hash sctp_setsockopt_peer_addr_params 3 734 _000517_hash NULL
84537 +_000518_hash sctp_setsockopt_peer_primary_addr 3 13440 _000518_hash NULL
84538 +_000519_hash sctp_setsockopt_rtoinfo 3 30941 _000519_hash NULL
84539 +_000520_hash security_context_to_sid_core 2 29248 _000520_hash NULL
84540 +_000521_hash sel_commit_bools_write 3 46077 _000521_hash NULL
84541 +_000522_hash sel_write_avc_cache_threshold 3 2256 _000522_hash NULL
84542 +_000523_hash sel_write_bool 3 46996 _000523_hash NULL
84543 +_000524_hash sel_write_checkreqprot 3 60774 _000524_hash NULL
84544 +_000525_hash sel_write_disable 3 10511 _000525_hash NULL
84545 +_000526_hash sel_write_enforce 3 48998 _000526_hash NULL
84546 +_000527_hash sel_write_load 3 63830 _000527_hash NULL
84547 +_000528_hash send_bulk_static_data 3 61932 _000528_hash NULL
84548 +_000529_hash send_control_msg 6 48498 _000529_hash NULL
84549 +_000530_hash set_aoe_iflist 2 42737 _000530_hash NULL
84550 +_000531_hash setkey_unaligned 3 39474 _000531_hash NULL
84551 +_000532_hash set_registers 3 53582 _000532_hash NULL
84552 +_000533_hash setsockopt 5 54539 _000533_hash NULL
84553 +_000534_hash setup_req 3 5848 _000534_hash NULL
84554 +_000535_hash setup_window 7-5-4-2 59178 _000535_hash NULL
84555 +_000536_hash setxattr 4 37006 _000536_hash NULL
84556 +_000537_hash sfq_alloc 1 2861 _000537_hash NULL
84557 +_000538_hash sg_kmalloc 1 50240 _000538_hash NULL
84558 +_000539_hash sgl_map_user_pages 2 30610 _000539_hash NULL
84559 +_000540_hash shash_setkey_unaligned 3 8620 _000540_hash NULL
84560 +_000541_hash shmem_xattr_alloc 2 61190 _000541_hash NULL
84561 +_000542_hash sierra_setup_urb 5 46029 _000542_hash NULL
84562 +_000543_hash simple_transaction_get 3 50633 _000543_hash NULL
84563 +_000544_hash simple_write_to_buffer 2-5 3122 _000544_hash NULL
84564 +_000546_hash sisusb_send_bulk_msg 3 17864 _000546_hash NULL
84565 +_000547_hash skb_add_data 3 48363 _000547_hash NULL
84566 +_000548_hash skb_do_copy_data_nocache 5 12465 _000548_hash NULL
84567 +_000549_hash sl_alloc_bufs 2 50380 _000549_hash NULL
84568 +_000550_hash sl_realloc_bufs 2 64086 _000550_hash NULL
84569 +_000551_hash smk_write_ambient 3 45691 _000551_hash NULL
84570 +_000552_hash smk_write_cipso 3 17989 _000552_hash NULL
84571 +_000553_hash smk_write_direct 3 46363 _000553_hash NULL
84572 +_000554_hash smk_write_doi 3 49621 _000554_hash NULL
84573 +_000555_hash smk_write_load_list 3 52280 _000555_hash NULL
84574 +_000556_hash smk_write_logging 3 2618 _000556_hash NULL
84575 +_000557_hash smk_write_netlbladdr 3 42525 _000557_hash NULL
84576 +_000558_hash smk_write_onlycap 3 14400 _000558_hash NULL
84577 +_000559_hash snd_ctl_elem_user_tlv 3 11695 _000559_hash NULL
84578 +_000560_hash snd_emu10k1_fx8010_read 5 9605 _000560_hash NULL
84579 +_000561_hash snd_emu10k1_synth_copy_from_user 3-5 9061 _000561_hash NULL
84580 +_000563_hash snd_gus_dram_poke 4 18525 _000563_hash NULL
84581 +_000564_hash snd_hdsp_playback_copy 5 20676 _000564_hash NULL
84582 +_000565_hash snd_info_entry_write 3 63474 _000565_hash NULL
84583 +_000566_hash snd_korg1212_copy_from 6 36169 _000566_hash NULL
84584 +_000567_hash snd_mem_proc_write 3 9786 _000567_hash NULL
84585 +_000568_hash snd_midi_channel_init_set 1 30092 _000568_hash NULL
84586 +_000569_hash snd_midi_event_new 1 9893 _000750_hash NULL nohasharray
84587 +_000570_hash snd_opl4_mem_proc_write 5 9670 _000570_hash NULL
84588 +_000571_hash snd_pcm_aio_read 3 13900 _000571_hash NULL
84589 +_000572_hash snd_pcm_aio_write 3 28738 _000572_hash NULL
84590 +_000573_hash snd_pcm_oss_write1 3 10872 _000573_hash NULL
84591 +_000574_hash snd_pcm_oss_write2 3 27332 _000574_hash NULL
84592 +_000575_hash snd_rawmidi_kernel_write1 4 56847 _000575_hash NULL
84593 +_000576_hash snd_rme9652_playback_copy 5 20970 _000576_hash NULL
84594 +_000577_hash snd_sb_csp_load_user 3 45190 _000577_hash NULL
84595 +_000578_hash snd_usb_ctl_msg 8 8436 _000578_hash NULL
84596 +_000579_hash sock_bindtodevice 3 50942 _000579_hash NULL
84597 +_000580_hash sock_kmalloc 2 62205 _000580_hash NULL
84598 +_000581_hash spidev_write 3 44510 _000581_hash NULL
84599 +_000582_hash squashfs_read_table 3 16945 _000582_hash NULL
84600 +_000583_hash srpt_alloc_ioctx 2-3 51042 _000583_hash NULL
84601 +_000585_hash srpt_alloc_ioctx_ring 2-4-3 49330 _000585_hash NULL
84602 +_000586_hash st5481_setup_isocpipes 6-4 61340 _000586_hash NULL
84603 +_000587_hash sta_agg_status_write 3 45164 _000587_hash NULL
84604 +_000588_hash svc_setsockopt 5 36876 _000588_hash NULL
84605 +_000589_hash sys_add_key 4 61288 _000589_hash NULL
84606 +_000590_hash sys_modify_ldt 3 18824 _000590_hash NULL
84607 +_000591_hash sys_semtimedop 3 4486 _000591_hash NULL
84608 +_000592_hash sys_setdomainname 2 4373 _000592_hash NULL
84609 +_000593_hash sys_sethostname 2 42962 _000593_hash NULL
84610 +_000594_hash tda10048_writeregbulk 4 11050 _000594_hash NULL
84611 +_000595_hash tipc_log_resize 1 34803 _000595_hash NULL
84612 +_000596_hash tomoyo_write_self 3 45161 _000596_hash NULL
84613 +_000597_hash tower_write 3 8580 _000597_hash NULL
84614 +_000598_hash tpm_write 3 50798 _000598_hash NULL
84615 +_000599_hash trusted_instantiate 3 4710 _000599_hash NULL
84616 +_000600_hash trusted_update 3 12664 _000600_hash NULL
84617 +_000601_hash tt_changes_fill_buffer 3 62649 _000601_hash NULL
84618 +_000602_hash tty_buffer_alloc 2 45437 _000602_hash NULL
84619 +_000603_hash __tun_chr_ioctl 4 22300 _000603_hash NULL
84620 +_000604_hash ubi_more_leb_change_data 4 63534 _000604_hash NULL
84621 +_000605_hash ubi_more_update_data 4 39189 _000605_hash NULL
84622 +_000606_hash ubi_resize_volume 2 50172 _000606_hash NULL
84623 +_000607_hash udf_alloc_i_data 2 35786 _000607_hash NULL
84624 +_000608_hash uea_idma_write 3 64139 _000608_hash NULL
84625 +_000609_hash uea_request 4 47613 _000609_hash NULL
84626 +_000610_hash uea_send_modem_cmd 3 3888 _000610_hash NULL
84627 +_000611_hash uio_write 3 43202 _000611_hash NULL
84628 +_000612_hash um_idi_write 3 18293 _000612_hash NULL
84629 +_000613_hash us122l_ctl_msg 8 13330 _000613_hash NULL
84630 +_000614_hash usb_alloc_urb 1 43436 _000614_hash NULL
84631 +_000615_hash usblp_new_writeurb 2 22894 _000615_hash NULL
84632 +_000616_hash usblp_write 3 23178 _000616_hash NULL
84633 +_000617_hash usbtest_alloc_urb 3-5 34446 _000617_hash NULL
84634 +_000619_hash usbtmc_write 3 64340 _000619_hash NULL
84635 +_000620_hash user_instantiate 3 26131 _000620_hash NULL
84636 +_000621_hash user_update 3 41332 _000621_hash NULL
84637 +_000622_hash uvc_simplify_fraction 3 31303 _000622_hash NULL
84638 +_000623_hash uwb_rc_cmd_done 4 35892 _000623_hash NULL
84639 +_000624_hash uwb_rc_neh_grok_event 3 55799 _000624_hash NULL
84640 +_000625_hash v9fs_alloc_rdir_buf 2 42150 _000625_hash NULL
84641 +_000626_hash __vb2_perform_fileio 3 63033 _000626_hash NULL
84642 +_000627_hash vc_do_resize 3-4 48842 _000627_hash NULL
84643 +_000629_hash vcs_write 3 3910 _000629_hash NULL
84644 +_000630_hash vfd_write 3 14717 _000630_hash NULL
84645 +_000631_hash vga_arb_write 3 36112 _000631_hash NULL
84646 +_000632_hash vga_switcheroo_debugfs_write 3 33984 _000632_hash NULL
84647 +_000633_hash vhci_get_user 3 45039 _000633_hash NULL
84648 +_000634_hash video_proc_write 3 6724 _000634_hash NULL
84649 +_000635_hash vlsi_alloc_ring 3-4 57003 _000635_hash NULL
84650 +_000637_hash __vmalloc 1 61168 _000637_hash NULL
84651 +_000638_hash vmalloc_32 1 1135 _000638_hash NULL
84652 +_000639_hash vmalloc_32_user 1 37519 _000639_hash NULL
84653 +_000640_hash vmalloc_exec 1 36132 _000640_hash NULL
84654 +_000641_hash vmalloc_node 1 58700 _000641_hash NULL
84655 +_000642_hash __vmalloc_node_flags 1 30352 _000642_hash NULL
84656 +_000643_hash vmalloc_user 1 32308 _000643_hash NULL
84657 +_000644_hash vol_cdev_direct_write 3 20751 _000644_hash NULL
84658 +_000645_hash vp_request_msix_vectors 2 28849 _000645_hash NULL
84659 +_000646_hash vring_add_indirect 3-4 20737 _000646_hash NULL
84660 +_000648_hash vring_new_virtqueue 1 9671 _000648_hash NULL
84661 +_000649_hash vxge_os_dma_malloc 2 46184 _000649_hash NULL
84662 +_000650_hash vxge_os_dma_malloc_async 3 56348 _000650_hash NULL
84663 +_000651_hash wdm_write 3 53735 _000651_hash NULL
84664 +_000652_hash wiimote_hid_send 3 48528 _000652_hash NULL
84665 +_000653_hash wl1273_fm_fops_write 3 60621 _000653_hash NULL
84666 +_000654_hash wlc_phy_loadsampletable_nphy 3 64367 _000654_hash NULL
84667 +_000655_hash write 3 62671 _000655_hash NULL
84668 +_000656_hash write_flush 3 50803 _000656_hash NULL
84669 +_000657_hash write_rio 3 54837 _000657_hash NULL
84670 +_000658_hash x25_asy_change_mtu 2 26928 _000658_hash NULL
84671 +_000659_hash xdi_copy_from_user 4 8395 _000659_hash NULL
84672 +_000660_hash xfrm_dst_alloc_copy 3 3034 _000660_hash NULL
84673 +_000661_hash xfrm_user_policy 4 62573 _000661_hash NULL
84674 +_000662_hash xfs_attrmulti_attr_set 4 59346 _000662_hash NULL
84675 +_000663_hash xfs_handle_to_dentry 3 12135 _000663_hash NULL
84676 +_000664_hash __xip_file_write 3-4 2733 _000664_hash NULL
84677 +_000665_hash xprt_rdma_allocate 2 31372 _000665_hash NULL
84678 +_000666_hash zd_usb_iowrite16v_async 3 23984 _000666_hash NULL
84679 +_000667_hash zd_usb_read_fw 4 22049 _000667_hash NULL
84680 +_000668_hash zerocopy_sg_from_iovec 3 11828 _000668_hash NULL
84681 +_000669_hash zoran_write 3 22404 _000669_hash NULL
84682 +_000671_hash acpi_ex_allocate_name_string 2-1 7685 _002855_hash NULL nohasharray
84683 +_000672_hash acpi_os_allocate_zeroed 1 37422 _000672_hash NULL
84684 +_000673_hash acpi_ut_initialize_buffer 2 47143 _002314_hash NULL nohasharray
84685 +_000674_hash ad7879_spi_xfer 3 36311 _000674_hash NULL
84686 +_000675_hash add_new_gdb 3 27643 _000675_hash NULL
84687 +_000676_hash add_numbered_child 5 14273 _000676_hash NULL
84688 +_000677_hash add_res_range 4 21310 _000677_hash NULL
84689 +_000678_hash addtgt 3 54703 _000678_hash NULL
84690 +_000679_hash add_uuid 4 49831 _000679_hash NULL
84691 +_000680_hash afs_cell_alloc 2 24052 _000680_hash NULL
84692 +_000681_hash aggr_recv_addba_req_evt 4 38037 _000681_hash NULL
84693 +_000682_hash agp_create_memory 1 1075 _000682_hash NULL
84694 +_000683_hash agp_create_user_memory 1 62955 _000683_hash NULL
84695 +_000684_hash alg_setsockopt 5 20985 _000684_hash NULL
84696 +_000685_hash alloc_async 1 14208 _000685_hash NULL
84697 +_000686_hash ___alloc_bootmem_nopanic 1 53626 _000686_hash NULL
84698 +_000687_hash alloc_buf 1 34532 _000687_hash NULL
84699 +_000688_hash alloc_chunk 1 49575 _000688_hash NULL
84700 +_000689_hash alloc_context 1 41283 _000689_hash NULL
84701 +_000690_hash alloc_ctrl_packet 1 44667 _000690_hash NULL
84702 +_000691_hash alloc_data_packet 1 46698 _000691_hash NULL
84703 +_000692_hash alloc_dca_provider 2 59670 _000692_hash NULL
84704 +_000693_hash __alloc_dev_table 2 54343 _000693_hash NULL
84705 +_000694_hash alloc_ep 1 17269 _000694_hash NULL
84706 +_000695_hash __alloc_extent_buffer 3 15093 _000695_hash NULL
84707 +_000696_hash alloc_group_attrs 2 9194 _000719_hash NULL nohasharray
84708 +_000697_hash alloc_large_system_hash 2 64490 _000697_hash NULL
84709 +_000698_hash alloc_netdev_mqs 1 30030 _000698_hash NULL
84710 +_000699_hash __alloc_objio_seg 1 7203 _000699_hash NULL
84711 +_000700_hash alloc_ring 2-4 15345 _000700_hash NULL
84712 +_000701_hash alloc_ring 2-4 39151 _000701_hash NULL
84713 +_000704_hash alloc_session 1-2 64171 _000704_hash NULL
84714 +_000708_hash alloc_smp_req 1 51337 _000708_hash NULL
84715 +_000709_hash alloc_smp_resp 1 3566 _000709_hash NULL
84716 +_000710_hash alloc_ts_config 1 45775 _000710_hash NULL
84717 +_000711_hash alloc_upcall 2 62186 _000711_hash NULL
84718 +_000712_hash altera_drscan 2 48698 _000712_hash NULL
84719 +_000713_hash altera_irscan 2 62396 _000713_hash NULL
84720 +_000714_hash altera_set_dr_post 2 54291 _000714_hash NULL
84721 +_000715_hash altera_set_dr_pre 2 64862 _000715_hash NULL
84722 +_000716_hash altera_set_ir_post 2 20948 _000716_hash NULL
84723 +_000717_hash altera_set_ir_pre 2 54103 _000717_hash NULL
84724 +_000718_hash altera_swap_dr 2 50090 _000718_hash NULL
84725 +_000719_hash altera_swap_ir 2 9194 _000719_hash &_000696_hash
84726 +_000720_hash amd_create_gatt_pages 1 20537 _000720_hash NULL
84727 +_000721_hash aoechr_write 3 62883 _001352_hash NULL nohasharray
84728 +_000722_hash applesmc_create_nodes 2 49392 _000722_hash NULL
84729 +_000723_hash array_zalloc 1-2 7519 _000723_hash NULL
84730 +_000725_hash arvo_sysfs_read 6 31617 _000725_hash NULL
84731 +_000726_hash arvo_sysfs_write 6 3311 _000726_hash NULL
84732 +_000727_hash asd_store_update_bios 4 10165 _000727_hash NULL
84733 +_000728_hash ata_host_alloc 2 46094 _000728_hash NULL
84734 +_000729_hash atalk_sendmsg 4 21677 _000729_hash NULL
84735 +_000730_hash ath6kl_cfg80211_connect_event 7-9-8 13443 _000730_hash NULL
84736 +_000731_hash ath6kl_mgmt_tx 9 21153 _000731_hash NULL
84737 +_000732_hash ath6kl_wmi_roam_tbl_event_rx 3 43440 _000732_hash NULL
84738 +_000733_hash ath6kl_wmi_send_mgmt_cmd 7 17347 _000733_hash NULL
84739 +_000734_hash ath_descdma_setup 5 12257 _000734_hash NULL
84740 +_000735_hash ath_rx_edma_init 2 65483 _000735_hash NULL
84741 +_000736_hash ati_create_gatt_pages 1 4722 _003185_hash NULL nohasharray
84742 +_000737_hash au0828_init_isoc 2-3 61917 _000737_hash NULL
84743 +_000739_hash audit_init_entry 1 38644 _000739_hash NULL
84744 +_000740_hash ax25_sendmsg 4 62770 _000740_hash NULL
84745 +_000741_hash b1_alloc_card 1 36155 _000741_hash NULL
84746 +_000742_hash b43_nphy_load_samples 3 36481 _000742_hash NULL
84747 +_000743_hash bio_copy_user_iov 4 37660 _000743_hash NULL
84748 +_000744_hash __bio_map_kern 2-3 47379 _000744_hash NULL
84749 +_000746_hash blk_register_region 1-2 51424 _000746_hash NULL
84750 +_000748_hash bm_entry_write 3 28338 _000748_hash NULL
84751 +_000749_hash bm_realloc_pages 2 9431 _000749_hash NULL
84752 +_000750_hash bm_register_write 3 9893 _000750_hash &_000569_hash
84753 +_000751_hash bm_status_write 3 12964 _000751_hash NULL
84754 +_000752_hash br_mdb_rehash 2 42643 _000752_hash NULL
84755 +_000753_hash btrfs_copy_from_user 3-1 43806 _000753_hash NULL
84756 +_000754_hash btrfs_insert_delayed_dir_index 4 63720 _000754_hash NULL
84757 +_000755_hash __btrfs_map_block 3 49839 _000755_hash NULL
84758 +_000756_hash __c4iw_init_resource_fifo 3 8334 _000756_hash NULL
84759 +_000757_hash cache_downcall 3 13666 _000757_hash NULL
84760 +_000758_hash cache_slow_downcall 2 8570 _000758_hash NULL
84761 +_000759_hash ca_extend 2 64541 _000759_hash NULL
84762 +_000760_hash caif_seqpkt_sendmsg 4 22961 _000760_hash NULL
84763 +_000761_hash caif_stream_sendmsg 4 9110 _000761_hash NULL
84764 +_000762_hash carl9170_cmd_buf 3 950 _000762_hash NULL
84765 +_000763_hash cdev_add 2-3 38176 _000763_hash NULL
84766 +_000765_hash cdrom_read_cdda 4 50478 _000765_hash NULL
84767 +_000766_hash ceph_dns_resolve_name 1-2 62488 _000766_hash NULL
84768 +_000767_hash ceph_msgpool_get 2 54258 _000767_hash NULL
84769 +_000768_hash cfg80211_connect_result 4-6 56515 _000768_hash NULL
84770 +_000770_hash cfg80211_disconnected 4 57 _000770_hash NULL
84771 +_000771_hash cfg80211_inform_bss 8 19332 _000771_hash NULL
84772 +_000772_hash cfg80211_inform_bss_frame 4 41078 _000772_hash NULL
84773 +_000773_hash cfg80211_mlme_register_mgmt 5 19852 _000773_hash NULL
84774 +_000774_hash cfg80211_roamed_bss 4-6 50198 _000774_hash NULL
84775 +_000776_hash cifs_readdata_alloc 1 50318 _000776_hash NULL
84776 +_000777_hash cifs_readv_from_socket 3 19109 _000777_hash NULL
84777 +_000778_hash cifs_writedata_alloc 1 32880 _003119_hash NULL nohasharray
84778 +_000779_hash cnic_alloc_dma 3 34641 _000779_hash NULL
84779 +_000780_hash configfs_write_file 3 61621 _000780_hash NULL
84780 +_000781_hash construct_key 3 11329 _000781_hash NULL
84781 +_000782_hash context_alloc 3 24645 _000782_hash NULL
84782 +_000783_hash copy_to_user 3 57835 _000783_hash NULL
84783 +_000784_hash create_attr_set 1 22861 _000784_hash NULL
84784 +_000785_hash create_bounce_buffer 3 39155 _000785_hash NULL
84785 +_000786_hash create_gpadl_header 2 19064 _000786_hash NULL
84786 +_000787_hash _create_sg_bios 4 31244 _000787_hash NULL
84787 +_000788_hash cryptd_alloc_instance 2-3 18048 _000788_hash NULL
84788 +_000790_hash crypto_ahash_setkey 3 55134 _000790_hash NULL
84789 +_000791_hash crypto_alloc_instance2 3 25277 _000791_hash NULL
84790 +_000792_hash crypto_shash_setkey 3 60483 _000792_hash NULL
84791 +_000793_hash cx231xx_init_bulk 3-2 47024 _000793_hash NULL
84792 +_000794_hash cx231xx_init_isoc 2-3 56453 _000794_hash NULL
84793 +_000796_hash cx231xx_init_vbi_isoc 2-3 28053 _000796_hash NULL
84794 +_000798_hash cxgb_alloc_mem 1 24007 _000798_hash NULL
84795 +_000799_hash cxgbi_device_portmap_create 3 25747 _000799_hash NULL
84796 +_000800_hash cxgbi_device_register 1-2 36746 _000800_hash NULL
84797 +_000802_hash __cxio_init_resource_fifo 3 23447 _000802_hash NULL
84798 +_000803_hash dccp_sendmsg 4 56058 _000803_hash NULL
84799 +_000804_hash ddp_make_gl 1 12179 _000804_hash NULL
84800 +_000805_hash depth_write 3 3021 _000805_hash NULL
84801 +_000806_hash dev_irnet_write 3 11398 _000806_hash NULL
84802 +_000807_hash dev_set_alias 3 50084 _000807_hash NULL
84803 +_000808_hash dev_write 3 7708 _000808_hash NULL
84804 +_000809_hash dfs_global_file_write 3 6112 _000809_hash NULL
84805 +_000810_hash dgram_sendmsg 4 45679 _000810_hash NULL
84806 +_000811_hash disconnect 4 32521 _000811_hash NULL
84807 +_000812_hash dma_attach 6-7 50831 _000812_hash NULL
84808 +_000814_hash dn_sendmsg 4 38390 _000814_hash NULL
84809 +_000815_hash do_dccp_setsockopt 5 54377 _003160_hash NULL nohasharray
84810 +_000816_hash do_jffs2_setxattr 5 25910 _000816_hash NULL
84811 +_000817_hash do_msgsnd 4 1387 _000817_hash NULL
84812 +_000818_hash do_raw_setsockopt 5 55215 _000818_hash NULL
84813 +_000819_hash do_readv_writev 4 51849 _000819_hash NULL
84814 +_000820_hash do_sync 1 9604 _000820_hash NULL
84815 +_000821_hash dup_array 3 33551 _000821_hash NULL
84816 +_000822_hash dvb_audio_write 3 51275 _000822_hash NULL
84817 +_000823_hash dvb_ca_en50221_init 4 45718 _000823_hash NULL
84818 +_000824_hash dvb_video_write 3 754 _000824_hash NULL
84819 +_000825_hash econet_sendmsg 4 51430 _000825_hash NULL
84820 +_000826_hash ecryptfs_decode_and_decrypt_filename 5 10379 _000826_hash NULL
84821 +_000827_hash ecryptfs_encrypt_and_encode_filename 6 2109 _000827_hash NULL
84822 +_000828_hash ecryptfs_send_message_locked 2 31801 _000828_hash NULL
84823 +_000829_hash edac_device_alloc_ctl_info 1 5941 _000829_hash NULL
84824 +_000830_hash edac_mc_alloc 1 54846 _000830_hash NULL
84825 +_000831_hash edac_pci_alloc_ctl_info 1 63388 _000831_hash NULL
84826 +_000832_hash efivar_create_sysfs_entry 2 19485 _000832_hash NULL
84827 +_000833_hash em28xx_alloc_isoc 4 46892 _000833_hash NULL
84828 +_000834_hash enable_write 3 30456 _000834_hash NULL
84829 +_000835_hash enclosure_register 3 57412 _000835_hash NULL
84830 +_000836_hash ext4_kvzalloc 1 47605 _000836_hash NULL
84831 +_000837_hash extend_netdev_table 2 31680 _000837_hash NULL
84832 +_000838_hash __feat_register_sp 6 64712 _000838_hash NULL
84833 +_000839_hash __ffs_ep0_read_events 3 48868 _000839_hash NULL
84834 +_000840_hash ffs_ep0_write 3 9438 _000840_hash NULL
84835 +_000841_hash ffs_epfile_read 3 18775 _000841_hash NULL
84836 +_000842_hash ffs_epfile_write 3 48014 _000842_hash NULL
84837 +_000843_hash fib_info_hash_alloc 1 9075 _000843_hash NULL
84838 +_000844_hash fillonedir 3 41746 _000844_hash NULL
84839 +_000845_hash flexcop_device_kmalloc 1 54793 _000845_hash NULL
84840 +_000846_hash frame_alloc 4 15981 _000846_hash NULL
84841 +_000847_hash fw_node_create 2 9559 _000847_hash NULL
84842 +_000848_hash garmin_read_process 3 27509 _000848_hash NULL
84843 +_000849_hash garp_request_join 4 7471 _000849_hash NULL
84844 +_000850_hash get_derived_key 4 61100 _000850_hash NULL
84845 +_000851_hash get_entry 4 16003 _000851_hash NULL
84846 +_000852_hash get_free_de 2 33714 _000852_hash NULL
84847 +_000853_hash get_new_cssid 2 51665 _000853_hash NULL
84848 +_000854_hash getxattr 4 24398 _003728_hash NULL nohasharray
84849 +_000855_hash gspca_dev_probe2 4 59833 _000855_hash NULL
84850 +_000856_hash hcd_alloc_coherent 5 55862 _000856_hash NULL
84851 +_000857_hash hci_sock_sendmsg 4 37420 _000857_hash NULL
84852 +_000858_hash hid_register_field 2-3 4874 _000858_hash NULL
84853 +_000860_hash hid_report_raw_event 4 7024 _000860_hash NULL
84854 +_000861_hash hpi_alloc_control_cache 1 35351 _000861_hash NULL
84855 +_000862_hash hugetlbfs_read_actor 2-5-4 34547 _000862_hash NULL
84856 +_000865_hash hvc_alloc 4 12579 _000865_hash NULL
84857 +_000866_hash __hwahc_dev_set_key 5 46328 _000866_hash NULL
84858 +_000867_hash i2400m_zrealloc_2x 3 54166 _001430_hash NULL nohasharray
84859 +_000868_hash ib_alloc_device 1 26483 _000868_hash NULL
84860 +_000869_hash ib_create_send_mad 5 1196 _000869_hash NULL
84861 +_000870_hash ibmasm_new_command 2 25714 _000870_hash NULL
84862 +_000871_hash ib_send_cm_drep 3 50186 _000871_hash NULL
84863 +_000872_hash ib_send_cm_mra 4 60202 _003875_hash NULL nohasharray
84864 +_000873_hash ib_send_cm_rtu 3 63138 _000873_hash NULL
84865 +_000874_hash ieee80211_key_alloc 3 19065 _000874_hash NULL
84866 +_000875_hash ieee80211_mgmt_tx 9 46860 _000875_hash NULL
84867 +_000876_hash ieee80211_send_probe_req 6-4 6924 _000876_hash NULL
84868 +_000877_hash if_writecmd 2 815 _000877_hash NULL
84869 +_000878_hash init_bch 1-2 64130 _000878_hash NULL
84870 +_000880_hash init_ipath 1 48187 _000880_hash NULL
84871 +_000881_hash init_list_set 2-3 39188 _000881_hash NULL
84872 +_000883_hash init_q 4 132 _000883_hash NULL
84873 +_000884_hash init_state 2 60165 _000884_hash NULL
84874 +_000885_hash init_tag_map 3 57515 _000885_hash NULL
84875 +_000886_hash input_ff_create 2 21240 _000886_hash NULL
84876 +_000887_hash input_mt_init_slots 2 31183 _000887_hash NULL
84877 +_000888_hash interfaces 2 38859 _000888_hash NULL
84878 +_000889_hash ioat2_alloc_ring 2 11172 _000889_hash NULL
84879 +_000890_hash ip_generic_getfrag 3-4 12187 _000890_hash NULL
84880 +_000892_hash ipr_alloc_ucode_buffer 1 40199 _000892_hash NULL
84881 +_000893_hash ip_set_alloc 1 57953 _000893_hash NULL
84882 +_000894_hash ipv6_flowlabel_opt 3 58135 _001125_hash NULL nohasharray
84883 +_000895_hash ipv6_renew_options 5 28867 _000895_hash NULL
84884 +_000896_hash ipxrtr_route_packet 4 54036 _000896_hash NULL
84885 +_000897_hash irda_sendmsg 4 4388 _000897_hash NULL
84886 +_000898_hash irda_sendmsg_dgram 4 38563 _000898_hash NULL
84887 +_000899_hash irda_sendmsg_ultra 4 42047 _000899_hash NULL
84888 +_000900_hash irias_add_octseq_attrib 4 29983 _000900_hash NULL
84889 +_000901_hash irq_alloc_generic_chip 2 26650 _000901_hash NULL
84890 +_000902_hash irq_domain_add_linear 2 29236 _000902_hash NULL
84891 +_000903_hash iscsi_alloc_session 3 49390 _000903_hash NULL
84892 +_000904_hash iscsi_create_conn 2 50425 _000904_hash NULL
84893 +_000905_hash iscsi_create_endpoint 1 15193 _000905_hash NULL
84894 +_000906_hash iscsi_create_iface 5 38510 _000906_hash NULL
84895 +_000907_hash iscsi_decode_text_input 4 58292 _000907_hash NULL
84896 +_000908_hash iscsi_pool_init 2-4 54913 _000908_hash NULL
84897 +_000910_hash iscsit_dump_data_payload 2 38683 _000910_hash NULL
84898 +_000911_hash isdn_write 3 45863 _000911_hash NULL
84899 +_000912_hash isku_receive 4 54130 _000912_hash NULL
84900 +_000913_hash isku_send 4 41542 _000913_hash NULL
84901 +_000914_hash islpci_mgt_transaction 5 23610 _000914_hash NULL
84902 +_000915_hash iso_sched_alloc 1 13377 _002079_hash NULL nohasharray
84903 +_000916_hash ivtv_v4l2_write 3 39226 _000916_hash NULL
84904 +_000917_hash iwl_trans_txq_alloc 3 36147 _000917_hash NULL
84905 +_000918_hash iwmct_fw_parser_init 4 37876 _000918_hash NULL
84906 +_000919_hash iwm_notif_send 6 12295 _000919_hash NULL
84907 +_000920_hash iwm_ntf_calib_res 3 11686 _000920_hash NULL
84908 +_000921_hash iwm_umac_set_config_var 4 17320 _000921_hash NULL
84909 +_000922_hash ixgbe_alloc_q_vector 3-5 45428 _000922_hash NULL
84910 +_000924_hash jbd2_journal_init_revoke 2 51088 _000924_hash NULL
84911 +_000925_hash jffs2_write_dirent 5 37311 _000925_hash NULL
84912 +_000926_hash journal_init_revoke 2 56933 _000926_hash NULL
84913 +_000927_hash keyctl_instantiate_key 3 41855 _000927_hash NULL
84914 +_000928_hash keyctl_instantiate_key_iov 3 16969 _000928_hash NULL
84915 +_000929_hash __kfifo_from_user 3 20399 _000929_hash NULL
84916 +_000930_hash kimage_crash_alloc 3 3233 _000930_hash NULL
84917 +_000931_hash kimage_normal_alloc 3 31140 _000931_hash NULL
84918 +_000932_hash kmem_realloc 2 37489 _000932_hash NULL
84919 +_000933_hash kmem_zalloc 1 11510 _000933_hash NULL
84920 +_000934_hash koneplus_send 4 18226 _000934_hash NULL
84921 +_000935_hash koneplus_sysfs_read 6 42792 _000935_hash NULL
84922 +_000936_hash kovaplus_send 4 10009 _000936_hash NULL
84923 +_000937_hash kvm_read_guest_page_mmu 6 37611 _000937_hash NULL
84924 +_000938_hash kvm_set_irq_routing 3 48704 _000938_hash NULL
84925 +_000939_hash kvm_write_guest_cached 4 11106 _000939_hash NULL
84926 +_000940_hash kvm_write_guest_page 5 63555 _002809_hash NULL nohasharray
84927 +_000941_hash l2cap_skbuff_fromiovec 3-4 35003 _000941_hash NULL
84928 +_000943_hash l2tp_ip_sendmsg 4 50411 _000943_hash NULL
84929 +_000944_hash l2tp_session_create 1 25286 _000944_hash NULL
84930 +_000945_hash lc_create 3 48662 _000945_hash NULL
84931 +_000946_hash leaf_dealloc 3 29566 _000946_hash NULL
84932 +_000947_hash linear_conf 2 23485 _003314_hash NULL nohasharray
84933 +_000948_hash lirc_buffer_init 2-3 53282 _000948_hash NULL
84934 +_000950_hash llc_ui_sendmsg 4 24987 _000950_hash NULL
84935 +_000951_hash lpfc_sli4_queue_alloc 3 62646 _000951_hash NULL
84936 +_000952_hash mce_request_packet 3 1073 _000952_hash NULL
84937 +_000953_hash mdiobus_alloc_size 1 52259 _000953_hash NULL
84938 +_000954_hash media_entity_init 2-4 15870 _001556_hash NULL nohasharray
84939 +_000956_hash memstick_alloc_host 1 142 _000956_hash NULL
84940 +_000957_hash mesh_table_alloc 1 22305 _000957_hash NULL
84941 +_000958_hash mfd_add_devices 4 56753 _000958_hash NULL
84942 +_000959_hash mISDN_sock_sendmsg 4 41035 _000959_hash NULL
84943 +_000960_hash mmc_alloc_host 1 48097 _000960_hash NULL
84944 +_000961_hash mmc_test_alloc_mem 3-2 28102 _000961_hash NULL
84945 +_000962_hash mpi_alloc 1 18094 _000962_hash NULL
84946 +_000963_hash mpihelp_mul_karatsuba_case 5-3 23918 _003873_hash NULL nohasharray
84947 +_000964_hash mpihelp_mul_n 4 16405 _000964_hash NULL
84948 +_000965_hash mpi_set_bit 2 15104 _000965_hash NULL
84949 +_000966_hash mpi_set_highbit 2 37327 _001420_hash NULL nohasharray
84950 +_000967_hash mtd_concat_create 2 14416 _000967_hash NULL
84951 +_000968_hash mvumi_alloc_mem_resource 3 47750 _000968_hash NULL
84952 +_000969_hash mwifiex_11n_create_rx_reorder_tbl 4 63806 _000969_hash NULL
84953 +_000970_hash mwifiex_alloc_sdio_mpa_buffers 2-3 60961 _000970_hash NULL
84954 +_000972_hash mwl8k_cmd_set_beacon 4 23110 _000972_hash NULL
84955 +_000973_hash neigh_hash_alloc 1 17595 _000973_hash NULL
84956 +_000974_hash netlink_sendmsg 4 33708 _001172_hash NULL nohasharray
84957 +_000975_hash netxen_alloc_sds_rings 2 13417 _000975_hash NULL
84958 +_000976_hash new_bind_ctl 2 35324 _000976_hash NULL
84959 +_000977_hash new_dir 3 31919 _000977_hash NULL
84960 +_000978_hash new_tape_buffer 2 32866 _000978_hash NULL
84961 +_000979_hash nfc_llcp_build_tlv 3 19536 _000979_hash NULL
84962 +_000980_hash nfc_llcp_send_i_frame 3 59130 _000980_hash NULL
84963 +_000981_hash nfs4_alloc_slots 1 2454 _003914_hash NULL nohasharray
84964 +_000982_hash nfsctl_transaction_write 3 64800 _000982_hash NULL
84965 +_000983_hash nfs_idmap_request_key 3 30208 _000983_hash NULL
84966 +_000984_hash nfs_readdata_alloc 1 9990 _000984_hash NULL
84967 +_000985_hash nfs_writedata_alloc 1 62868 _000985_hash NULL
84968 +_000986_hash nl_pid_hash_zalloc 1 23314 _000986_hash NULL
84969 +_000987_hash nr_sendmsg 4 53656 _000987_hash NULL
84970 +_000988_hash nsm_create_handle 4 38060 _000988_hash NULL
84971 +_000989_hash ntfs_copy_from_user_iovec 3-6 49829 _000989_hash NULL
84972 +_000991_hash ntfs_file_buffered_write 4-6 41442 _000991_hash NULL
84973 +_000993_hash __ntfs_malloc 1 34022 _000993_hash NULL
84974 +_000994_hash nvme_alloc_queue 3 46865 _000994_hash NULL
84975 +_000995_hash ocfs2_acl_from_xattr 2 21604 _000995_hash NULL
84976 +_000996_hash ocfs2_control_message 3 19564 _000996_hash NULL
84977 +_000997_hash opera1_usb_i2c_msgxfer 4 64521 _000997_hash NULL
84978 +_000998_hash _ore_get_io_state 3-5-4 2166 _000998_hash NULL
84979 +_000999_hash orig_hash_add_if 2 53676 _000999_hash NULL
84980 +_001000_hash orig_hash_del_if 2 45080 _001000_hash NULL
84981 +_001001_hash orinoco_set_key 5-7 17878 _001001_hash NULL
84982 +_001003_hash osdmap_set_max_osd 2 57630 _003740_hash NULL nohasharray
84983 +_001004_hash _osd_realloc_seg 3 54352 _001004_hash NULL
84984 +_001005_hash OSDSetBlock 2-4 38986 _001005_hash NULL
84985 +_001007_hash osst_execute 7-6 17607 _001007_hash NULL
84986 +_001008_hash osst_write 3 31581 _001008_hash NULL
84987 +_001009_hash otp_read 2-5-4 10594 _001009_hash NULL
84988 +_001012_hash ovs_vport_alloc 1 33475 _001012_hash NULL
84989 +_001013_hash packet_sendmsg_spkt 4 28885 _001013_hash NULL
84990 +_001014_hash pair_device 4 61175 _001708_hash NULL nohasharray
84991 +_001015_hash pccard_store_cis 6 18176 _001015_hash NULL
84992 +_001016_hash pci_add_cap_save_buffer 3 3426 _001016_hash NULL
84993 +_001017_hash pcnet32_realloc_rx_ring 3 36598 _001017_hash NULL
84994 +_001018_hash pcnet32_realloc_tx_ring 3 38428 _001018_hash NULL
84995 +_001019_hash pcpu_mem_zalloc 1 22948 _001019_hash NULL
84996 +_001020_hash pep_sendmsg 4 62524 _001020_hash NULL
84997 +_001021_hash pfkey_sendmsg 4 47394 _001021_hash NULL
84998 +_001022_hash pidlist_resize 2 496 _001022_hash NULL
84999 +_001023_hash pin_code_reply 4 46510 _001023_hash NULL
85000 +_001024_hash ping_getfrag 3-4 8360 _001024_hash NULL
85001 +_001026_hash pipe_set_size 2 5204 _001026_hash NULL
85002 +_001027_hash pkt_bio_alloc 1 48284 _001027_hash NULL
85003 +_001028_hash platform_create_bundle 4-6 12785 _001028_hash NULL
85004 +_001030_hash play_iframe 3 8219 _001030_hash NULL
85005 +_001031_hash pm8001_store_update_fw 4 55716 _001031_hash NULL
85006 +_001032_hash pmcraid_alloc_sglist 1 9864 _001032_hash NULL
85007 +_001033_hash pn533_dep_link_up 5 7659 _001033_hash NULL
85008 +_001034_hash pnp_alloc 1 24869 _001419_hash NULL nohasharray
85009 +_001035_hash pn_sendmsg 4 12640 _001035_hash NULL
85010 +_001036_hash pppoe_sendmsg 4 48039 _001036_hash NULL
85011 +_001037_hash pppol2tp_sendmsg 4 56420 _001037_hash NULL
85012 +_001038_hash process_vm_rw 3-5 47533 _001038_hash NULL
85013 +_001040_hash process_vm_rw_single_vec 1-2 26213 _001040_hash NULL
85014 +_001042_hash proc_write 3 51003 _001042_hash NULL
85015 +_001043_hash profile_load 3 58267 _001043_hash NULL
85016 +_001044_hash profile_remove 3 8556 _001044_hash NULL
85017 +_001045_hash profile_replace 3 14652 _001045_hash NULL
85018 +_001046_hash pscsi_get_bio 1 56103 _001046_hash NULL
85019 +_001047_hash pyra_send 4 12061 _001047_hash NULL
85020 +_001048_hash qc_capture 3 19298 _001048_hash NULL
85021 +_001049_hash qla4xxx_alloc_work 2 44813 _001049_hash NULL
85022 +_001050_hash qlcnic_alloc_msix_entries 2 46160 _001050_hash NULL
85023 +_001051_hash qlcnic_alloc_sds_rings 2 26795 _001051_hash NULL
85024 +_001052_hash queue_received_packet 5 9657 _001052_hash NULL
85025 +_001053_hash raw_send_hdrinc 4 58803 _001053_hash NULL
85026 +_001054_hash raw_sendmsg 4 23078 _001054_hash &_000022_hash
85027 +_001055_hash rawsock_sendmsg 4 60010 _001055_hash NULL
85028 +_001056_hash rawv6_send_hdrinc 3 35425 _001056_hash NULL
85029 +_001057_hash rb_alloc 1 3102 _001057_hash NULL
85030 +_001058_hash rbd_alloc_coll 1 33678 _001058_hash NULL
85031 +_001059_hash rbd_create_rw_ops 2 4605 _001059_hash NULL
85032 +_001060_hash rds_ib_inc_copy_to_user 3 55007 _001060_hash NULL
85033 +_001061_hash rds_iw_inc_copy_to_user 3 29214 _001061_hash NULL
85034 +_001062_hash rds_message_alloc 1 10517 _001062_hash NULL
85035 +_001063_hash rds_message_copy_from_user 3 45510 _001063_hash NULL
85036 +_001064_hash rds_message_inc_copy_to_user 3 26540 _001064_hash NULL
85037 +_001065_hash redrat3_transmit_ir 3 64244 _001065_hash NULL
85038 +_001066_hash regcache_rbtree_insert_to_block 5 58009 _001066_hash NULL
85039 +_001067_hash _regmap_raw_write 4 42652 _001067_hash NULL
85040 +_001068_hash regmap_register_patch 3 21681 _001068_hash NULL
85041 +_001069_hash relay_alloc_page_array 1 52735 _001069_hash NULL
85042 +_001070_hash remove_uuid 4 64505 _001070_hash NULL
85043 +_001071_hash reshape_ring 2 29147 _001071_hash NULL
85044 +_001072_hash RESIZE_IF_NEEDED 2 56286 _001072_hash NULL
85045 +_001073_hash resize_stripes 2 61650 _001073_hash NULL
85046 +_001074_hash rfcomm_sock_sendmsg 4 37661 _003927_hash NULL nohasharray
85047 +_001075_hash rose_sendmsg 4 20249 _001075_hash NULL
85048 +_001076_hash rxrpc_send_data 5 21553 _001076_hash NULL
85049 +_001077_hash rxrpc_setsockopt 5 50286 _001077_hash NULL
85050 +_001078_hash saa7146_vmalloc_build_pgtable 2 19780 _001078_hash NULL
85051 +_001079_hash saa7164_buffer_alloc_user 2 9627 _001079_hash NULL
85052 +_001081_hash sco_send_frame 3 41815 _001081_hash NULL
85053 +_001082_hash scsi_host_alloc 2 63041 _001082_hash NULL
85054 +_001083_hash scsi_tgt_kspace_exec 8 9522 _001083_hash NULL
85055 +_001084_hash sctp_sendmsg 4 61919 _001084_hash NULL
85056 +_001085_hash sctp_setsockopt 5 44788 _001085_hash NULL
85057 +_001086_hash sctp_setsockopt_connectx 3 6073 _001086_hash NULL
85058 +_001087_hash sctp_setsockopt_connectx_old 3 22631 _001087_hash NULL
85059 +_001088_hash sctp_tsnmap_init 2 36446 _001088_hash NULL
85060 +_001089_hash sctp_user_addto_chunk 2-3 62047 _001089_hash NULL
85061 +_001091_hash security_context_to_sid 2 19839 _001091_hash NULL
85062 +_001092_hash security_context_to_sid_default 2 3492 _003366_hash NULL nohasharray
85063 +_001093_hash security_context_to_sid_force 2 20724 _001093_hash NULL
85064 +_001094_hash selinux_transaction_write 3 59038 _001094_hash NULL
85065 +_001095_hash sel_write_access 3 51704 _001095_hash NULL
85066 +_001096_hash sel_write_create 3 11353 _001096_hash NULL
85067 +_001097_hash sel_write_member 3 28800 _001097_hash NULL
85068 +_001098_hash sel_write_relabel 3 55195 _001098_hash NULL
85069 +_001099_hash sel_write_user 3 45060 _001099_hash NULL
85070 +_001100_hash __seq_open_private 3 40715 _001100_hash NULL
85071 +_001101_hash serverworks_create_gatt_pages 1 46582 _001101_hash NULL
85072 +_001102_hash set_connectable 4 56458 _001102_hash NULL
85073 +_001103_hash set_dev_class 4 39645 _001697_hash NULL nohasharray
85074 +_001104_hash set_discoverable 4 48141 _001104_hash NULL
85075 +_001105_hash setkey 3 14987 _001105_hash NULL
85076 +_001106_hash set_le 4 30581 _001106_hash NULL
85077 +_001107_hash set_link_security 4 4502 _001107_hash NULL
85078 +_001108_hash set_local_name 4 55757 _001108_hash NULL
85079 +_001109_hash set_powered 4 12129 _001109_hash NULL
85080 +_001110_hash set_ssp 4 62411 _001110_hash NULL
85081 +_001111_hash sg_build_sgat 3 60179 _001111_hash &_000305_hash
85082 +_001112_hash sg_read_oxfer 3 51724 _001112_hash NULL
85083 +_001113_hash shmem_xattr_set 4 11843 _001113_hash NULL
85084 +_001114_hash simple_alloc_urb 3 60420 _001114_hash NULL
85085 +_001115_hash sisusb_send_bridge_packet 2 11649 _001115_hash NULL
85086 +_001116_hash sisusb_send_packet 2 20891 _001116_hash NULL
85087 +_001117_hash skb_add_data_nocache 4 4682 _001117_hash NULL
85088 +_001118_hash skb_copy_datagram_from_iovec 2-5-4 52014 _001118_hash NULL
85089 +_001121_hash skb_copy_to_page_nocache 6 58624 _001121_hash NULL
85090 +_001122_hash sk_chk_filter 2 42095 _001122_hash NULL
85091 +_001123_hash skcipher_sendmsg 4 30290 _001123_hash NULL
85092 +_001124_hash sl_change_mtu 2 7396 _001124_hash NULL
85093 +_001125_hash slhc_init 1-2 58135 _001125_hash &_000894_hash
85094 +_001127_hash sm501_create_subdev 3-4 48668 _003678_hash NULL nohasharray
85095 +_001129_hash smk_write_access 3 49561 _001129_hash NULL
85096 +_001130_hash snapshot_write 3 28351 _001130_hash NULL
85097 +_001131_hash snd_ac97_pcm_assign 2 30218 _001131_hash NULL
85098 +_001132_hash snd_card_create 4 64418 _001411_hash NULL nohasharray
85099 +_001133_hash snd_emux_create_port 3 42533 _001133_hash NULL
85100 +_001134_hash snd_gus_dram_write 4 38784 _001134_hash NULL
85101 +_001135_hash snd_midi_channel_alloc_set 1 28153 _001135_hash NULL
85102 +_001136_hash _snd_pcm_lib_alloc_vmalloc_buffer 2 17820 _001136_hash NULL
85103 +_001137_hash snd_pcm_oss_sync1 2 45298 _001137_hash NULL
85104 +_001138_hash snd_pcm_oss_write 3 38108 _001138_hash NULL
85105 +_001139_hash snd_pcm_plugin_build 5 25505 _001139_hash NULL
85106 +_001140_hash snd_rawmidi_kernel_write 3 25106 _001140_hash NULL
85107 +_001141_hash snd_rawmidi_write 3 28008 _001141_hash NULL
85108 +_001142_hash snd_rme32_playback_copy 5 43732 _001142_hash NULL
85109 +_001143_hash snd_rme96_playback_copy 5 13111 _001143_hash NULL
85110 +_001144_hash snd_seq_device_new 4 31753 _001144_hash NULL
85111 +_001145_hash snd_seq_oss_readq_new 2 14283 _001145_hash NULL
85112 +_001146_hash snd_vx_create 4 40948 _001146_hash NULL
85113 +_001147_hash sock_setsockopt 5 50088 _001147_hash NULL
85114 +_001148_hash sound_write 3 5102 _001148_hash NULL
85115 +_001149_hash _sp2d_alloc 1-3-2 16944 _001149_hash NULL
85116 +_001150_hash spi_alloc_master 2 45223 _001150_hash NULL
85117 +_001151_hash spidev_message 3 5518 _001151_hash NULL
85118 +_001152_hash spi_register_board_info 2 35651 _001152_hash NULL
85119 +_001153_hash squashfs_cache_init 2 41656 _001153_hash NULL
85120 +_001154_hash squashfs_read_data 6 59440 _001154_hash NULL
85121 +_001155_hash srp_alloc_iu 2 44227 _001155_hash NULL
85122 +_001156_hash srp_iu_pool_alloc 2 17920 _001156_hash NULL
85123 +_001157_hash srp_ring_alloc 2 26760 _001157_hash NULL
85124 +_001159_hash start_isoc_chain 2 565 _001159_hash NULL
85125 +_001160_hash stk_prepare_sio_buffers 2 57168 _001160_hash NULL
85126 +_001161_hash store_iwmct_log_level 4 60209 _001161_hash NULL
85127 +_001162_hash store_iwmct_log_level_fw 4 1974 _001162_hash NULL
85128 +_001163_hash st_write 3 16874 _001163_hash NULL
85129 +_001164_hash svc_pool_map_alloc_arrays 2 47181 _001164_hash NULL
85130 +_001165_hash symtab_init 2 61050 _001165_hash NULL
85131 +_001166_hash sys_bind 3 10799 _001166_hash NULL
85132 +_001167_hash sys_connect 3 15291 _003291_hash NULL nohasharray
85133 +_001168_hash sys_flistxattr 3 41407 _001168_hash NULL
85134 +_001169_hash sys_fsetxattr 4 49736 _001169_hash NULL
85135 +_001170_hash sysfs_write_file 3 57116 _001170_hash NULL
85136 +_001171_hash sys_ipc 3 4889 _001171_hash NULL
85137 +_001172_hash sys_keyctl 4 33708 _001172_hash &_000974_hash
85138 +_001173_hash sys_listxattr 3 27833 _001173_hash NULL
85139 +_001174_hash sys_llistxattr 3 4532 _001174_hash NULL
85140 +_001175_hash sys_lsetxattr 4 61177 _001175_hash NULL
85141 +_001176_hash sys_mq_timedsend 3 57661 _001176_hash NULL
85142 +_001177_hash sys_sched_setaffinity 2 32046 _001177_hash NULL
85143 +_001178_hash sys_semop 3 39457 _001178_hash NULL
85144 +_001179_hash sys_sendto 6 20809 _001179_hash NULL
85145 +_001180_hash sys_setxattr 4 37880 _001180_hash NULL
85146 +_001181_hash t4_alloc_mem 1 32342 _001181_hash NULL
85147 +_001182_hash tcf_hash_create 4 54360 _001182_hash NULL
85148 +_001183_hash __team_options_register 3 63941 _001183_hash NULL
85149 +_001184_hash test_unaligned_bulk 3 52333 _001184_hash NULL
85150 +_001185_hash tifm_alloc_adapter 1 10903 _001185_hash NULL
85151 +_001186_hash timeout_write 3 50991 _001186_hash NULL
85152 +_001187_hash tipc_link_send_sections_fast 4 37920 _001187_hash NULL
85153 +_001188_hash tipc_subseq_alloc 1 5957 _001188_hash NULL
85154 +_001189_hash tm6000_read_write_usb 7 50774 _002917_hash NULL nohasharray
85155 +_001190_hash tnode_alloc 1 49407 _001190_hash NULL
85156 +_001191_hash tomoyo_commit_ok 2 20167 _001191_hash NULL
85157 +_001192_hash tomoyo_scan_bprm 2-4 15642 _001192_hash NULL
85158 +_001194_hash tps65910_i2c_write 3 39531 _001194_hash NULL
85159 +_001195_hash ts_write 3 64336 _001195_hash NULL
85160 +_001196_hash ttusb2_msg 4 3100 _001196_hash NULL
85161 +_001197_hash tty_write 3 5494 _001197_hash NULL
85162 +_001198_hash ubi_dbg_check_all_ff 4 59810 _001198_hash NULL
85163 +_001199_hash ubi_dbg_check_write 5 48525 _001199_hash NULL
85164 +_001200_hash ubifs_setxattr 4 59650 _001370_hash NULL nohasharray
85165 +_001201_hash udf_sb_alloc_partition_maps 2 62313 _001201_hash NULL
85166 +_001202_hash udplite_getfrag 3-4 14479 _001202_hash NULL
85167 +_001204_hash ulong_write_file 3 26485 _001204_hash NULL
85168 +_001205_hash unix_dgram_sendmsg 4 45699 _001205_hash NULL
85169 +_001206_hash unix_stream_sendmsg 4 61455 _001206_hash NULL
85170 +_001207_hash unlink_queued 3-4 645 _001207_hash NULL
85171 +_001208_hash update_pmkid 4 2481 _001208_hash NULL
85172 +_001209_hash usb_alloc_coherent 2 65444 _001209_hash NULL
85173 +_001210_hash uvc_alloc_buffers 2-3 9656 _001210_hash NULL
85174 +_001211_hash uvc_alloc_entity 3-4 20836 _001211_hash NULL
85175 +_001212_hash v4l2_ctrl_new 7 38725 _001212_hash NULL
85176 +_001213_hash v4l2_event_subscribe 3 19510 _001213_hash NULL
85177 +_001214_hash vb2_read 3 42703 _001214_hash NULL
85178 +_001215_hash vb2_write 3 31948 _001215_hash NULL
85179 +_001216_hash vc_resize 2-3 3585 _001216_hash NULL
85180 +_001218_hash __vhost_add_used_n 3 26554 _001218_hash NULL
85181 +_001219_hash __videobuf_alloc_vb 1 27062 _001219_hash NULL
85182 +_001220_hash videobuf_dma_init_kernel 3 6963 _001220_hash NULL
85183 +_001221_hash virtqueue_add_buf 3-4 59470 _001221_hash NULL
85184 +_001223_hash vmalloc 1 15464 _001223_hash NULL
85185 +_001224_hash vmalloc_to_sg 2 58354 _001224_hash NULL
85186 +_001225_hash vol_cdev_write 3 40915 _001225_hash NULL
85187 +_001226_hash vxge_device_register 4 7752 _001226_hash NULL
85188 +_001227_hash __vxge_hw_channel_allocate 3 55462 _001227_hash NULL
85189 +_001228_hash vzalloc 1 47421 _001228_hash NULL
85190 +_001229_hash vzalloc_node 1 23424 _001229_hash NULL
85191 +_001230_hash wa_nep_queue 2 8858 _001230_hash NULL
85192 +_001231_hash __wa_xfer_setup_segs 2 56725 _001231_hash NULL
85193 +_001232_hash wiphy_new 2 2482 _001232_hash NULL
85194 +_001233_hash wpan_phy_alloc 1 48056 _001233_hash NULL
85195 +_001234_hash wusb_ccm_mac 7 32199 _001234_hash NULL
85196 +_001235_hash x25_sendmsg 4 12487 _001235_hash NULL
85197 +_001236_hash xfrm_hash_alloc 1 10997 _001236_hash NULL
85198 +_001237_hash _xfs_buf_get_pages 2 46811 _001237_hash NULL
85199 +_001238_hash xfs_da_buf_make 1 55845 _001238_hash NULL
85200 +_001239_hash xfs_da_grow_inode_int 3 21785 _001239_hash NULL
85201 +_001240_hash xfs_dir_cilookup_result 3 64288 _003139_hash NULL nohasharray
85202 +_001241_hash xfs_iext_add_indirect_multi 3 32400 _001241_hash NULL
85203 +_001242_hash xfs_iext_inline_to_direct 2 12384 _001242_hash NULL
85204 +_001243_hash xfs_iroot_realloc 2 46826 _001243_hash NULL
85205 +_001244_hash xhci_alloc_stream_info 3 63902 _001244_hash NULL
85206 +_001245_hash xlog_recover_add_to_trans 4 62839 _001245_hash NULL
85207 +_001246_hash xprt_alloc 2 1475 _001246_hash NULL
85208 +_001247_hash xt_alloc_table_info 1 57903 _001247_hash NULL
85209 +_001248_hash _zd_iowrite32v_async_locked 3 39034 _001248_hash NULL
85210 +_001249_hash zd_usb_iowrite16v 3 49744 _001249_hash NULL
85211 +_001250_hash acpi_ds_build_internal_package_obj 3 58271 _001250_hash NULL
85212 +_001251_hash acpi_system_read_event 3 55362 _001251_hash NULL
85213 +_001252_hash acpi_ut_create_buffer_object 1 42030 _001252_hash NULL
85214 +_001253_hash acpi_ut_create_package_object 1 17594 _001253_hash NULL
85215 +_001254_hash acpi_ut_create_string_object 1 15360 _001254_hash NULL
85216 +_001255_hash ad7879_spi_multi_read 3 8218 _001255_hash NULL
85217 +_001256_hash add_child 4 45201 _001256_hash NULL
85218 +_001257_hash add_port 2 54941 _001257_hash NULL
85219 +_001258_hash adu_read 3 24177 _001258_hash NULL
85220 +_001259_hash afs_cell_create 2 27346 _001259_hash NULL
85221 +_001260_hash agp_generic_alloc_user 1 9470 _001260_hash NULL
85222 +_001261_hash alloc_agpphysmem_i8xx 1 39427 _001261_hash NULL
85223 +_001262_hash allocate_cnodes 1 5329 _001262_hash NULL
85224 +_001263_hash ___alloc_bootmem 1 11410 _001263_hash NULL
85225 +_001264_hash __alloc_bootmem_nopanic 1 65397 _001264_hash NULL
85226 +_001265_hash alloc_bulk_urbs_generic 5 12127 _001265_hash NULL
85227 +_001266_hash alloc_candev 1-2 7776 _001266_hash NULL
85228 +_001268_hash ____alloc_ei_netdev 1 51475 _001268_hash NULL
85229 +_001269_hash alloc_etherdev_mqs 1 36450 _001269_hash NULL
85230 +_001270_hash alloc_extent_buffer 3 52824 _001270_hash NULL
85231 +_001271_hash alloc_fcdev 1 18780 _001271_hash NULL
85232 +_001272_hash alloc_fddidev 1 15382 _001272_hash NULL
85233 +_001273_hash alloc_hippi_dev 1 51320 _001273_hash NULL
85234 +_001274_hash alloc_irdadev 1 19140 _001274_hash NULL
85235 +_001275_hash alloc_ltalkdev 1 38071 _001275_hash NULL
85236 +_001276_hash alloc_one_pg_vec_page 1 10747 _001276_hash NULL
85237 +_001277_hash alloc_orinocodev 1 21371 _001277_hash NULL
85238 +_001279_hash alloc_trdev 1 16399 _001279_hash NULL
85239 +_001280_hash async_setkey 3 35521 _001280_hash NULL
85240 +_001281_hash ata_host_alloc_pinfo 3 17325 _001281_hash NULL
85241 +_001284_hash ath6kl_connect_event 7-9-8 14267 _001284_hash NULL
85242 +_001285_hash ath6kl_fwlog_block_read 3 49836 _001285_hash NULL
85243 +_001286_hash ath6kl_fwlog_read 3 32101 _001286_hash NULL
85244 +_001287_hash ath_rx_init 2 43564 _001287_hash NULL
85245 +_001288_hash ath_tx_init 2 60515 _001288_hash NULL
85246 +_001289_hash atm_get_addr 3 31221 _001289_hash NULL
85247 +_001290_hash av7110_ipack_init 2 46655 _001290_hash NULL
85248 +_001291_hash bdx_rxdb_create 1 46525 _001291_hash NULL
85249 +_001292_hash bdx_tx_db_init 2 41719 _001292_hash NULL
85250 +_001293_hash bio_map_kern 3 64751 _001293_hash NULL
85251 +_001294_hash bits_to_user 3-2 47733 _001294_hash NULL
85252 +_001295_hash __blk_queue_init_tags 2 9778 _001295_hash NULL
85253 +_001296_hash blk_queue_resize_tags 2 28670 _001296_hash NULL
85254 +_001297_hash blk_rq_map_user_iov 5 16772 _001297_hash NULL
85255 +_001298_hash bm_init 2 13529 _001298_hash NULL
85256 +_001299_hash brcmf_alloc_wdev 1 60347 _001299_hash NULL
85257 +_001300_hash btrfs_insert_dir_item 4 59304 _001300_hash NULL
85258 +_001301_hash btrfs_map_block 3 64379 _001301_hash NULL
85259 +_001302_hash c4_add_card 3 54968 _001302_hash NULL
85260 +_001303_hash cache_read 3 24790 _001303_hash NULL
85261 +_001304_hash cache_write 3 13589 _001304_hash NULL
85262 +_001305_hash calc_hmac 3 32010 _001305_hash NULL
85263 +_001306_hash ccid_getsockopt_builtin_ccids 2 53634 _001306_hash NULL
85264 +_001307_hash ceph_copy_page_vector_to_user 4-3 31270 _001307_hash NULL
85265 +_001308_hash ceph_read_dir 3 17005 _001308_hash NULL
85266 +_001309_hash cfg80211_roamed 5-7 32632 _001309_hash NULL
85267 +_001311_hash ci_ll_init 3 12930 _001311_hash NULL
85268 +_001312_hash coda_psdev_read 3 35029 _001312_hash NULL
85269 +_001313_hash construct_key_and_link 4 8321 _001313_hash NULL
85270 +_001314_hash copy_counters_to_user 5 17027 _001824_hash NULL nohasharray
85271 +_001315_hash copy_entries_to_user 1 52367 _001315_hash NULL
85272 +_001316_hash copy_from_buf 4-2 27308 _001316_hash NULL
85273 +_001317_hash copy_oldmem_page 3-1 26164 _001317_hash NULL
85274 +_001318_hash copy_to_user_fromio 3 57432 _001318_hash NULL
85275 +_001319_hash cryptd_hash_setkey 3 42781 _001319_hash NULL
85276 +_001320_hash crypto_authenc_esn_setkey 3 6985 _001320_hash NULL
85277 +_001321_hash crypto_authenc_setkey 3 80 _003311_hash NULL nohasharray
85278 +_001322_hash cx18_copy_buf_to_user 4 22735 _001322_hash NULL
85279 +_001324_hash cxgbi_ddp_reserve 4 30091 _001324_hash NULL
85280 +_001325_hash datablob_hmac_append 3 40038 _001325_hash NULL
85281 +_001326_hash datablob_hmac_verify 4 24786 _001326_hash NULL
85282 +_001327_hash dataflash_read_fact_otp 3-2 33204 _001327_hash NULL
85283 +_001328_hash dataflash_read_user_otp 3-2 14536 _001328_hash &_000201_hash
85284 +_001329_hash dccp_feat_register_sp 5 17914 _001329_hash NULL
85285 +_001330_hash ddb_input_read 3 9743 _001330_hash NULL
85286 +_001331_hash dev_read 3 56369 _001331_hash NULL
85287 +_001332_hash diva_os_copy_to_user 4 48508 _001332_hash NULL
85288 +_001333_hash diva_os_malloc 2 16406 _001333_hash NULL
85289 +_001334_hash dlm_dir_lookup 4 56662 _001334_hash NULL
85290 +_001335_hash dm_vcalloc 1-2 16814 _001335_hash NULL
85291 +_001337_hash do_proc_readlink 3 14096 _001337_hash NULL
85292 +_001338_hash do_readlink 2 43518 _001338_hash NULL
85293 +_001339_hash __do_replace 5 37227 _001339_hash NULL
85294 +_001340_hash do_sigpending 2 9766 _001340_hash NULL
85295 +_001341_hash drbd_setsockopt 5 16280 _001341_hash &_000371_hash
85296 +_001342_hash dsp_buffer_alloc 2 11684 _001342_hash NULL
85297 +_001343_hash dump_midi 3 51040 _001343_hash NULL
85298 +_001344_hash dvb_dmxdev_set_buffer_size 2 55643 _001344_hash NULL
85299 +_001345_hash dvb_dvr_set_buffer_size 2 9840 _001345_hash NULL
85300 +_001346_hash dvb_ringbuffer_pkt_read_user 3-5-2 4303 _001346_hash NULL
85301 +_001348_hash dvb_ringbuffer_read_user 3 56702 _001348_hash NULL
85302 +_001349_hash ecryptfs_filldir 3 6622 _001349_hash NULL
85303 +_001350_hash ecryptfs_readlink 3 40775 _001350_hash NULL
85304 +_001351_hash ecryptfs_send_message 2 18322 _001351_hash NULL
85305 +_001352_hash em28xx_init_isoc 4 62883 _001352_hash &_000721_hash
85306 +_001353_hash et61x251_read 3 25420 _001353_hash NULL
85307 +_001354_hash ext4_add_new_descs 3 19509 _001354_hash NULL
85308 +_001355_hash fat_ioctl_filldir 3 36621 _001355_hash NULL
85309 +_001356_hash fd_copyout 3 59323 _001356_hash NULL
85310 +_001357_hash f_hidg_read 3 6238 _001357_hash NULL
85311 +_001358_hash filldir 3 55137 _001358_hash NULL
85312 +_001359_hash filldir64 3 46469 _001359_hash NULL
85313 +_001360_hash fops_read 3 40672 _001360_hash NULL
85314 +_001361_hash from_buffer 3 18625 _001361_hash NULL
85315 +_001362_hash fsm_init 2 16134 _001362_hash NULL
85316 +_001363_hash get_subdir 3 62581 _001363_hash NULL
85317 +_001364_hash gspca_dev_probe 4 2570 _001364_hash NULL
85318 +_001365_hash handle_received_packet 3 22457 _001365_hash NULL
85319 +_001366_hash hash_setkey 3 48310 _001366_hash NULL
85320 +_001367_hash hdlcdrv_register 2 6792 _001367_hash NULL
85321 +_001368_hash hdpvr_read 3 9273 _001368_hash NULL
85322 +_001369_hash hid_input_report 4 32458 _001369_hash NULL
85323 +_001370_hash hidraw_read 3 59650 _001370_hash &_001200_hash
85324 +_001371_hash HiSax_readstatus 2 15752 _001371_hash NULL
85325 +_001373_hash __hwahc_op_set_gtk 4 42038 _001373_hash NULL
85326 +_001374_hash __hwahc_op_set_ptk 5 36510 _001374_hash NULL
85327 +_001375_hash ib_copy_to_udata 3 27525 _001375_hash NULL
85328 +_001376_hash idetape_chrdev_read 3 2097 _001376_hash NULL
85329 +_001377_hash ieee80211_alloc_hw 1 43829 _001377_hash NULL
85330 +_001378_hash ieee80211_bss_info_update 4 13991 _001378_hash NULL
85331 +_001379_hash ilo_read 3 32531 _001379_hash NULL
85332 +_001380_hash init_map_ipmac 3-4 63896 _001380_hash NULL
85333 +_001382_hash init_tid_tabs 2-4-3 13252 _001382_hash NULL
85334 +_001385_hash iowarrior_read 3 53483 _001385_hash NULL
85335 +_001386_hash ipv6_getsockopt_sticky 5 56711 _001386_hash NULL
85336 +_001387_hash ipwireless_send_packet 4 8328 _001387_hash NULL
85337 +_001388_hash ipx_sendmsg 4 1362 _001388_hash NULL
85338 +_001389_hash iscsi_conn_setup 2 35159 _001389_hash NULL
85339 +_001390_hash iscsi_create_session 3 51647 _001390_hash NULL
85340 +_001391_hash iscsi_host_alloc 2 36671 _001391_hash NULL
85341 +_001392_hash iscsi_session_setup 4-5 196 _001392_hash NULL
85342 +_001394_hash iscsit_find_cmd_from_itt_or_dump 3 17194 _001701_hash NULL nohasharray
85343 +_001395_hash isdn_ppp_read 4 50356 _001395_hash NULL
85344 +_001396_hash isku_sysfs_read 6 58806 _001396_hash NULL
85345 +_001397_hash isku_sysfs_write 6 49767 _001397_hash NULL
85346 +_001398_hash iso_alloc_urb 4-5 45206 _001398_hash NULL
85347 +_001400_hash ivtv_copy_buf_to_user 4 6159 _001400_hash NULL
85348 +_001401_hash iwm_rx_handle 3 24899 _001401_hash NULL
85349 +_001402_hash iwm_wdev_alloc 1 38415 _001402_hash NULL
85350 +_001403_hash jbd2_alloc 1 41359 _001403_hash NULL
85351 +_001404_hash jffs2_do_link 6 42048 _001404_hash NULL
85352 +_001405_hash jffs2_do_unlink 4 62020 _001405_hash NULL
85353 +_001406_hash jffs2_security_setxattr 4 62107 _001406_hash NULL
85354 +_001407_hash jffs2_trusted_setxattr 4 17048 _001407_hash NULL
85355 +_001408_hash jffs2_user_setxattr 4 10182 _001408_hash NULL
85356 +_001409_hash kernel_setsockopt 5 35913 _001409_hash NULL
85357 +_001410_hash keyctl_describe_key 3 36853 _001410_hash NULL
85358 +_001411_hash keyctl_get_security 3 64418 _001411_hash &_001132_hash
85359 +_001412_hash keyring_read 3 13438 _001412_hash NULL
85360 +_001413_hash kfifo_copy_to_user 3 20646 _001413_hash NULL
85361 +_001414_hash kmem_zalloc_large 1 56128 _001414_hash NULL
85362 +_001415_hash kmp_init 2 41373 _001415_hash NULL
85363 +_001416_hash koneplus_sysfs_write 6 35993 _001416_hash NULL
85364 +_001417_hash kvm_clear_guest_page 4 2308 _001417_hash NULL
85365 +_001418_hash kvm_read_nested_guest_page 5 13337 _001418_hash NULL
85366 +_001419_hash l2cap_create_basic_pdu 3 24869 _003830_hash &_001034_hash nohasharray
85367 +_001420_hash l2cap_create_connless_pdu 3 37327 _001420_hash &_000966_hash
85368 +_001421_hash l2cap_create_iframe_pdu 3 51801 _001421_hash NULL
85369 +_001422_hash __lgwrite 4 57669 _001422_hash NULL
85370 +_001423_hash libfc_host_alloc 2 7917 _001423_hash NULL
85371 +_001424_hash llcp_sock_sendmsg 4 1092 _001424_hash NULL
85372 +_001425_hash macvtap_get_user 4 28185 _001425_hash NULL
85373 +_001426_hash mcam_v4l_read 3 36513 _001426_hash NULL
85374 +_001427_hash mce_async_out 3 58056 _001427_hash NULL
85375 +_001428_hash mce_flush_rx_buffer 2 14976 _001428_hash NULL
85376 +_001429_hash mdc800_device_read 3 22896 _001429_hash NULL
85377 +_001430_hash memcpy_toiovec 3 54166 _001430_hash &_000867_hash
85378 +_001431_hash memcpy_toiovecend 3-4 19736 _001431_hash NULL
85379 +_001433_hash mgt_set_varlen 4 60916 _001433_hash NULL
85380 +_001434_hash mlx4_en_create_rx_ring 3 62498 _001434_hash NULL
85381 +_001435_hash mlx4_en_create_tx_ring 4 48501 _001435_hash NULL
85382 +_001436_hash mon_bin_get_event 4 52863 _001436_hash NULL
85383 +_001437_hash mousedev_read 3 47123 _001437_hash NULL
85384 +_001438_hash move_addr_to_user 2 2868 _001438_hash NULL
85385 +_001439_hash mpihelp_mul 5-3 27805 _001439_hash NULL
85386 +_001441_hash mpi_lshift_limbs 2 9337 _001441_hash NULL
85387 +_001442_hash msnd_fifo_alloc 2 23179 _001442_hash NULL
85388 +_001443_hash mtdswap_init 2 55719 _001443_hash NULL
85389 +_001444_hash neigh_hash_grow 2 17283 _001444_hash NULL
85390 +_001445_hash nfs4_realloc_slot_table 2 22859 _001445_hash NULL
85391 +_001446_hash nfs_idmap_get_key 2 39616 _001446_hash NULL
85392 +_001447_hash nsm_get_handle 4 52089 _001447_hash NULL
85393 +_001448_hash ntfs_malloc_nofs 1 49572 _001448_hash NULL
85394 +_001449_hash ntfs_malloc_nofs_nofail 1 63631 _001449_hash NULL
85395 +_001450_hash nvme_create_queue 3 170 _001450_hash NULL
85396 +_001451_hash ocfs2_control_write 3 54737 _001451_hash NULL
85397 +_001452_hash orinoco_add_extscan_result 3 18207 _001452_hash NULL
85398 +_001454_hash override_release 2 52032 _001454_hash NULL
85399 +_001455_hash packet_snd 3 13634 _001455_hash NULL
85400 +_001456_hash pcbit_stat 2 27364 _001456_hash NULL
85401 +_001457_hash pcpu_extend_area_map 2 12589 _001457_hash NULL
85402 +_001458_hash pg_read 3 17276 _001458_hash NULL
85403 +_001459_hash picolcd_debug_eeprom_read 3 14549 _001459_hash NULL
85404 +_001460_hash pkt_alloc_packet_data 1 37928 _001460_hash NULL
85405 +_001461_hash pmcraid_build_passthrough_ioadls 2 62034 _001461_hash NULL
85406 +_001462_hash pms_capture 4 27142 _001462_hash NULL
85407 +_001463_hash posix_clock_register 2 5662 _001463_hash NULL
85408 +_001464_hash printer_read 3 54851 _001464_hash NULL
85409 +_001465_hash __proc_file_read 3 54978 _001465_hash NULL
85410 +_001466_hash pt_read 3 49136 _001466_hash NULL
85411 +_001467_hash put_cmsg 4 36589 _001467_hash NULL
85412 +_001468_hash pvr2_ioread_read 3 10720 _001505_hash NULL nohasharray
85413 +_001469_hash pwc_video_read 3 51735 _001469_hash NULL
85414 +_001470_hash px_raw_event 4 49371 _001470_hash NULL
85415 +_001471_hash qcam_read 3 13977 _001471_hash NULL
85416 +_001472_hash rawv6_sendmsg 4 20080 _001472_hash NULL
85417 +_001473_hash rds_sendmsg 4 40976 _001473_hash NULL
85418 +_001474_hash read_flush 3 43851 _001474_hash NULL
85419 +_001475_hash read_profile 3 27859 _001475_hash NULL
85420 +_001476_hash read_vmcore 3 26501 _001476_hash NULL
85421 +_001477_hash redirected_tty_write 3 65297 _001477_hash NULL
85422 +_001478_hash __register_chrdev 2-3 54223 _001478_hash NULL
85423 +_001480_hash regmap_raw_write 4 53803 _001480_hash NULL
85424 +_001481_hash reiserfs_allocate_list_bitmaps 3 21732 _001481_hash NULL
85425 +_001482_hash reiserfs_resize 2 34377 _001482_hash NULL
85426 +_001483_hash request_key_auth_read 3 24109 _001483_hash NULL
85427 +_001484_hash rfkill_fop_read 3 54711 _001484_hash NULL
85428 +_001485_hash rng_dev_read 3 41581 _001485_hash NULL
85429 +_001486_hash roccat_read 3 41093 _003519_hash NULL nohasharray
85430 +_001487_hash sco_sock_sendmsg 4 62542 _001487_hash NULL
85431 +_001488_hash scsi_register 2 49094 _001488_hash NULL
85432 +_001489_hash sctp_getsockopt_events 2 3607 _001489_hash NULL
85433 +_001490_hash sctp_getsockopt_maxburst 2 42941 _001490_hash NULL
85434 +_001491_hash sctp_getsockopt_maxseg 2 10737 _001491_hash NULL
85435 +_001492_hash sctpprobe_read 3 17741 _001492_hash NULL
85436 +_001493_hash sdhci_alloc_host 2 7509 _001493_hash NULL
85437 +_001494_hash selinux_inode_post_setxattr 4 26037 _001494_hash NULL
85438 +_001495_hash selinux_inode_setsecurity 4 18148 _001495_hash NULL
85439 +_001496_hash selinux_inode_setxattr 4 10708 _001496_hash NULL
85440 +_001497_hash selinux_secctx_to_secid 2 63744 _001497_hash NULL
85441 +_001498_hash selinux_setprocattr 4 55611 _001498_hash NULL
85442 +_001499_hash sel_write_context 3 25726 _002397_hash NULL nohasharray
85443 +_001500_hash seq_copy_in_user 3 18543 _001500_hash NULL
85444 +_001501_hash seq_open_net 4 8968 _001594_hash NULL nohasharray
85445 +_001502_hash seq_open_private 3 61589 _001502_hash NULL
85446 +_001503_hash set_arg 3 42824 _001503_hash NULL
85447 +_001504_hash sg_read 3 25799 _001504_hash NULL
85448 +_001505_hash shash_async_setkey 3 10720 _001505_hash &_001468_hash
85449 +_001506_hash shash_compat_setkey 3 12267 _001506_hash NULL
85450 +_001507_hash shmem_setxattr 4 55867 _001507_hash NULL
85451 +_001508_hash simple_read_from_buffer 2-5 55957 _001508_hash NULL
85452 +_001511_hash sm_checker_extend 2 23615 _001511_hash NULL
85453 +_001512_hash sn9c102_read 3 29305 _001512_hash NULL
85454 +_001513_hash snd_es1938_capture_copy 5 25930 _001513_hash NULL
85455 +_001514_hash snd_gus_dram_peek 4 9062 _001514_hash NULL
85456 +_001515_hash snd_hdsp_capture_copy 5 4011 _001515_hash NULL
85457 +_001516_hash snd_korg1212_copy_to 6 92 _001516_hash NULL
85458 +_001517_hash snd_opl4_mem_proc_read 5 63774 _001517_hash NULL
85459 +_001518_hash snd_pcm_alloc_vmalloc_buffer 2 44595 _001518_hash NULL
85460 +_001519_hash snd_pcm_oss_read1 3 63771 _001519_hash NULL
85461 +_001520_hash snd_rawmidi_kernel_read1 4 36740 _001520_hash NULL
85462 +_001521_hash snd_rme9652_capture_copy 5 10287 _001521_hash NULL
85463 +_001522_hash srp_target_alloc 3 37288 _001522_hash NULL
85464 +_001523_hash stk_allocate_buffers 2 16291 _001523_hash NULL
85465 +_001524_hash store_ifalias 4 35088 _001524_hash NULL
85466 +_001525_hash store_msg 3 56417 _001525_hash NULL
85467 +_001526_hash str_to_user 2 11411 _001526_hash NULL
85468 +_001527_hash subbuf_read_actor 3 2071 _001527_hash NULL
85469 +_001528_hash sys_fgetxattr 4 25166 _001528_hash NULL
85470 +_001529_hash sys_gethostname 2 49698 _001529_hash NULL
85471 +_001530_hash sys_getxattr 4 37418 _001530_hash NULL
85472 +_001531_hash sys_kexec_load 2 14222 _001531_hash NULL
85473 +_001532_hash sys_msgsnd 3 44537 _001532_hash &_000129_hash
85474 +_001533_hash sys_process_vm_readv 3-5 19090 _003125_hash NULL nohasharray
85475 +_001535_hash sys_process_vm_writev 3-5 4928 _001535_hash NULL
85476 +_001537_hash sys_sched_getaffinity 2 60033 _001537_hash NULL
85477 +_001538_hash sys_setsockopt 5 35320 _001538_hash NULL
85478 +_001539_hash t3_init_l2t 1 8261 _001539_hash NULL
85479 +_001540_hash team_options_register 3 20091 _001540_hash NULL
85480 +_001541_hash tipc_send2name 6 16809 _001541_hash NULL
85481 +_001542_hash tipc_send2port 5 63935 _001542_hash NULL
85482 +_001543_hash tipc_send 4 51238 _001543_hash NULL
85483 +_001544_hash tm6000_i2c_recv_regs16 5 2949 _001544_hash NULL
85484 +_001545_hash tm6000_i2c_recv_regs 5 46215 _001545_hash NULL
85485 +_001546_hash tm6000_i2c_send_regs 5 20250 _001546_hash NULL
85486 +_001547_hash tnode_new 3 44757 _003828_hash NULL nohasharray
85487 +_001548_hash tomoyo_read_self 3 33539 _001548_hash NULL
85488 +_001549_hash tomoyo_update_domain 2 5498 _001549_hash NULL
85489 +_001550_hash tomoyo_update_policy 2 40458 _001550_hash NULL
85490 +_001551_hash tpm_read 3 50344 _001551_hash NULL
85491 +_001552_hash TSS_rawhmac 3 17486 _001552_hash NULL
85492 +_001553_hash tt3650_ci_msg 4 57219 _001553_hash NULL
85493 +_001554_hash tun_get_user 3 33178 _001554_hash NULL
85494 +_001555_hash ubi_dbg_dump_flash 4 3870 _001555_hash NULL
85495 +_001556_hash ubi_io_write 4-5 15870 _001556_hash &_000954_hash
85496 +_001558_hash uio_read 3 49300 _001558_hash NULL
85497 +_001559_hash unix_seqpacket_sendmsg 4 27893 _001559_hash NULL
85498 +_001560_hash unlink1 3 63059 _001560_hash NULL
85499 +_001562_hash usb_allocate_stream_buffers 3 8964 _001562_hash NULL
85500 +_001563_hash usbdev_read 3 45114 _001563_hash NULL
85501 +_001564_hash usblp_read 3 57342 _003306_hash NULL nohasharray
85502 +_001565_hash usbtmc_read 3 32377 _001565_hash NULL
85503 +_001566_hash usbvision_v4l2_read 3 34386 _001566_hash NULL
85504 +_001567_hash _usb_writeN_sync 4 31682 _001567_hash NULL
85505 +_001568_hash user_read 3 51881 _001568_hash NULL
85506 +_001569_hash v4l_stk_read 3 39672 _001569_hash NULL
85507 +_001570_hash vcs_read 3 8017 _001570_hash NULL
85508 +_001571_hash vdma_mem_alloc 1 6171 _001571_hash NULL
85509 +_001572_hash venus_create 4 20555 _001572_hash NULL
85510 +_001573_hash venus_link 5 32165 _001573_hash NULL
85511 +_001574_hash venus_lookup 4 8121 _001574_hash NULL
85512 +_001575_hash venus_mkdir 4 8967 _001575_hash NULL
85513 +_001576_hash venus_remove 4 59781 _001576_hash NULL
85514 +_001577_hash venus_rename 4-5 17707 _003279_hash NULL nohasharray
85515 +_001579_hash venus_rmdir 4 45564 _001579_hash NULL
85516 +_001580_hash venus_symlink 4-6 23570 _001580_hash NULL
85517 +_001582_hash vfs_readlink 3 54368 _001582_hash NULL
85518 +_001583_hash vfs_readv 3 38011 _001583_hash NULL
85519 +_001584_hash vfs_writev 3 25278 _001584_hash NULL
85520 +_001585_hash vga_arb_read 3 4886 _001585_hash NULL
85521 +_001586_hash vhci_put_user 4 12604 _001586_hash NULL
85522 +_001587_hash vhost_add_used_n 3 10760 _001587_hash NULL
85523 +_001588_hash __videobuf_copy_to_user 4 15423 _001588_hash NULL
85524 +_001589_hash videobuf_pages_to_sg 2 3708 _001589_hash NULL
85525 +_001590_hash videobuf_vmalloc_to_sg 2 4548 _001590_hash NULL
85526 +_001591_hash virtnet_send_command 5-6 61993 _001591_hash NULL
85527 +_001593_hash vmbus_establish_gpadl 3 4495 _001593_hash NULL
85528 +_001594_hash vol_cdev_read 3 8968 _001594_hash &_001501_hash
85529 +_001595_hash w9966_v4l_read 3 31148 _001595_hash NULL
85530 +_001596_hash wdm_read 3 6549 _001596_hash NULL
85531 +_001597_hash wusb_prf 7 54261 _001597_hash &_000063_hash
85532 +_001598_hash xdi_copy_to_user 4 48900 _001598_hash NULL
85533 +_001599_hash xfs_buf_get_uncached 2 51477 _001599_hash NULL
85534 +_001600_hash xfs_efd_init 3 5463 _001600_hash NULL
85535 +_001601_hash xfs_efi_init 2 5476 _001601_hash NULL
85536 +_001602_hash xfs_iext_realloc_direct 2 20521 _001602_hash NULL
85537 +_001603_hash xfs_iext_realloc_indirect 2 59211 _001603_hash NULL
85538 +_001604_hash xfs_inumbers_fmt 3 12817 _001604_hash NULL
85539 +_001605_hash xlog_recover_add_to_cont_trans 4 44102 _001605_hash NULL
85540 +_001606_hash xz_dec_lzma2_create 2 36353 _002745_hash NULL nohasharray
85541 +_001607_hash _zd_iowrite32v_locked 3 44725 _001607_hash NULL
85542 +_001608_hash aat2870_reg_read_file 3 12221 _001608_hash NULL
85543 +_001609_hash add_sctp_bind_addr 3 12269 _001609_hash NULL
85544 +_001610_hash aes_decrypt_fail_read 3 54815 _001610_hash NULL
85545 +_001611_hash aes_decrypt_interrupt_read 3 19910 _001611_hash NULL
85546 +_001612_hash aes_decrypt_packets_read 3 10155 _001612_hash NULL
85547 +_001613_hash aes_encrypt_fail_read 3 32562 _001613_hash NULL
85548 +_001614_hash aes_encrypt_interrupt_read 3 39919 _001614_hash NULL
85549 +_001615_hash aes_encrypt_packets_read 3 48666 _001615_hash NULL
85550 +_001616_hash afs_cell_lookup 2 8482 _001616_hash NULL
85551 +_001617_hash agp_allocate_memory 2 58761 _001617_hash NULL
85552 +_001618_hash __alloc_bootmem 1 31498 _001618_hash NULL
85553 +_001619_hash __alloc_bootmem_low 1 43423 _003150_hash NULL nohasharray
85554 +_001620_hash __alloc_bootmem_node_nopanic 2 6432 _001620_hash NULL
85555 +_001621_hash alloc_cc770dev 1 48186 _001621_hash NULL
85556 +_001622_hash __alloc_ei_netdev 1 29338 _001622_hash NULL
85557 +_001623_hash __alloc_eip_netdev 1 51549 _001623_hash NULL
85558 +_001624_hash alloc_libipw 1 22708 _001624_hash NULL
85559 +_001625_hash alloc_pg_vec 2 8533 _001625_hash NULL
85560 +_001626_hash alloc_sja1000dev 1 17868 _001626_hash NULL
85561 +_001627_hash alloc_targets 2 8074 _003536_hash NULL nohasharray
85562 +_001630_hash ath6kl_disconnect_timeout_read 3 3650 _001630_hash NULL
85563 +_001631_hash ath6kl_endpoint_stats_read 3 41554 _001631_hash NULL
85564 +_001632_hash ath6kl_fwlog_mask_read 3 2050 _001632_hash NULL
85565 +_001633_hash ath6kl_keepalive_read 3 44303 _001633_hash NULL
85566 +_001634_hash ath6kl_listen_int_read 3 10355 _001634_hash NULL
85567 +_001635_hash ath6kl_lrssi_roam_read 3 61022 _001635_hash NULL
85568 +_001636_hash ath6kl_regdump_read 3 14393 _001636_hash NULL
85569 +_001637_hash ath6kl_regread_read 3 25884 _001637_hash NULL
85570 +_001638_hash ath6kl_regwrite_read 3 48747 _001638_hash NULL
85571 +_001639_hash ath6kl_roam_table_read 3 26166 _001639_hash NULL
85572 +_001640_hash ath9k_debugfs_read_buf 3 25316 _001640_hash NULL
85573 +_001641_hash atk_debugfs_ggrp_read 3 29522 _001641_hash NULL
85574 +_001642_hash b43_debugfs_read 3 24425 _001642_hash NULL
85575 +_001643_hash b43legacy_debugfs_read 3 2473 _001643_hash NULL
85576 +_001644_hash bcm_recvmsg 4 43992 _001644_hash NULL
85577 +_001645_hash bfad_debugfs_read 3 13119 _001645_hash NULL
85578 +_001646_hash bfad_debugfs_read_regrd 3 57830 _001646_hash NULL
85579 +_001647_hash blk_init_tags 1 30592 _001647_hash NULL
85580 +_001648_hash blk_queue_init_tags 2 44355 _002686_hash NULL nohasharray
85581 +_001649_hash blk_rq_map_kern 4 47004 _001649_hash NULL
85582 +_001650_hash bm_entry_read 3 10976 _001650_hash NULL
85583 +_001651_hash bm_status_read 3 19583 _001651_hash NULL
85584 +_001652_hash bnad_debugfs_read 3 50665 _001652_hash NULL
85585 +_001653_hash bnad_debugfs_read_regrd 3 51308 _001653_hash NULL
85586 +_001654_hash btmrvl_curpsmode_read 3 46939 _001654_hash NULL
85587 +_001655_hash btmrvl_gpiogap_read 3 4718 _001655_hash NULL
85588 +_001656_hash btmrvl_hscfgcmd_read 3 56303 _001656_hash NULL
85589 +_001657_hash btmrvl_hscmd_read 3 1614 _001657_hash NULL
85590 +_001658_hash btmrvl_hsmode_read 3 1647 _001658_hash NULL
85591 +_001659_hash btmrvl_hsstate_read 3 920 _001659_hash NULL
85592 +_001660_hash btmrvl_pscmd_read 3 24308 _001660_hash NULL
85593 +_001661_hash btmrvl_psmode_read 3 22395 _001661_hash NULL
85594 +_001662_hash btmrvl_psstate_read 3 50683 _001662_hash NULL
85595 +_001663_hash btmrvl_txdnldready_read 3 413 _001663_hash NULL
85596 +_001664_hash btrfs_add_link 5 9973 _001664_hash NULL
85597 +_001665_hash btrfs_discard_extent 2 38547 _001665_hash NULL
85598 +_001666_hash btrfs_find_create_tree_block 3 55812 _001666_hash NULL
85599 +_001667_hash btrfsic_map_block 2 56751 _001667_hash NULL
85600 +_001668_hash caif_stream_recvmsg 4 13173 _001668_hash NULL
85601 +_001669_hash carl9170_alloc 1 27 _001669_hash NULL
85602 +_001670_hash carl9170_debugfs_read 3 47738 _001670_hash NULL
85603 +_001671_hash cgroup_read_s64 5 19570 _001671_hash NULL
85604 +_001672_hash cgroup_read_u64 5 45532 _001672_hash NULL
85605 +_001673_hash channel_type_read 3 47308 _001673_hash NULL
85606 +_001674_hash codec_list_read_file 3 24910 _001674_hash NULL
85607 +_001675_hash configfs_read_file 3 1683 _001675_hash NULL
85608 +_001676_hash cpuset_common_file_read 5 8800 _001676_hash NULL
85609 +_001677_hash create_subvol 4 2347 _001677_hash NULL
85610 +_001678_hash cx18_copy_mdl_to_user 4 45549 _001678_hash NULL
85611 +_001679_hash dai_list_read_file 3 25421 _001679_hash NULL
85612 +_001680_hash dapm_bias_read_file 3 64715 _001680_hash NULL
85613 +_001681_hash dapm_widget_power_read_file 3 59950 _001754_hash NULL nohasharray
85614 +_001684_hash dbgfs_frame 3 45917 _001684_hash NULL
85615 +_001685_hash dbgfs_state 3 38894 _001685_hash NULL
85616 +_001686_hash debugfs_read 3 62535 _001686_hash NULL
85617 +_001687_hash debug_output 3 18575 _001687_hash NULL
85618 +_001688_hash debug_read 3 19322 _001688_hash NULL
85619 +_001689_hash dfs_file_read 3 18116 _001689_hash NULL
85620 +_001690_hash dma_memcpy_pg_to_iovec 6 1725 _001690_hash NULL
85621 +_001691_hash dma_memcpy_to_iovec 5 12173 _001691_hash NULL
85622 +_001692_hash dma_rx_errors_read 3 52045 _001692_hash NULL
85623 +_001693_hash dma_rx_requested_read 3 65354 _001693_hash NULL
85624 +_001694_hash dma_show_regs 3 35266 _001694_hash NULL
85625 +_001695_hash dma_tx_errors_read 3 46060 _001695_hash NULL
85626 +_001696_hash dma_tx_requested_read 3 16110 _001775_hash NULL nohasharray
85627 +_001697_hash dm_exception_table_init 2 39645 _001697_hash &_001103_hash
85628 +_001698_hash dn_recvmsg 4 17213 _001698_hash NULL
85629 +_001699_hash dns_resolver_read 3 54658 _001699_hash NULL
85630 +_001700_hash do_msgrcv 4 5590 _001700_hash NULL
85631 +_001701_hash driver_state_read 3 17194 _001701_hash &_001394_hash
85632 +_001702_hash dvb_demux_do_ioctl 3 34871 _001702_hash NULL
85633 +_001703_hash dvb_dmxdev_buffer_read 4 20682 _001703_hash NULL
85634 +_001704_hash dvb_dvr_do_ioctl 3 43355 _001704_hash NULL
85635 +_001705_hash econet_recvmsg 4 40978 _001705_hash NULL
85636 +_001706_hash event_calibration_read 3 21083 _001706_hash NULL
85637 +_001707_hash event_heart_beat_read 3 48961 _001707_hash NULL
85638 +_001708_hash event_oom_late_read 3 61175 _001708_hash &_001014_hash
85639 +_001709_hash event_phy_transmit_error_read 3 10471 _001709_hash NULL
85640 +_001710_hash event_rx_mem_empty_read 3 40363 _001710_hash NULL
85641 +_001711_hash event_rx_mismatch_read 3 38518 _001711_hash NULL
85642 +_001712_hash event_rx_pool_read 3 25792 _001712_hash NULL
85643 +_001713_hash event_tx_stuck_read 3 19305 _001713_hash NULL
85644 +_001714_hash excessive_retries_read 3 60425 _001714_hash NULL
85645 +_001715_hash fallback_on_nodma_alloc 2 35332 _001715_hash NULL
85646 +_001716_hash filter_read 3 61692 _001716_hash NULL
85647 +_001717_hash format_devstat_counter 3 32550 _001717_hash NULL
85648 +_001718_hash fragmentation_threshold_read 3 61718 _001718_hash NULL
85649 +_001719_hash fuse_conn_limit_read 3 20084 _001719_hash NULL
85650 +_001720_hash fuse_conn_waiting_read 3 49762 _001720_hash NULL
85651 +_001721_hash generic_readlink 3 32654 _001721_hash NULL
85652 +_001722_hash gpio_power_read 3 36059 _001722_hash NULL
85653 +_001723_hash hash_recvmsg 4 50924 _001723_hash NULL
85654 +_001724_hash ht40allow_map_read 3 55209 _002830_hash NULL nohasharray
85655 +_001725_hash hwflags_read 3 52318 _001725_hash NULL
85656 +_001726_hash hysdn_conf_read 3 42324 _003205_hash NULL nohasharray
85657 +_001727_hash i2400m_rx_stats_read 3 57706 _001727_hash NULL
85658 +_001728_hash i2400m_tx_stats_read 3 28527 _001728_hash NULL
85659 +_001729_hash idmouse_read 3 63374 _001729_hash NULL
85660 +_001730_hash ieee80211_if_read 3 6785 _001730_hash NULL
85661 +_001731_hash ieee80211_rx_bss_info 3 61630 _001731_hash NULL
85662 +_001732_hash ikconfig_read_current 3 1658 _001732_hash NULL
85663 +_001733_hash il3945_sta_dbgfs_stats_table_read 3 48802 _001733_hash NULL
85664 +_001734_hash il3945_ucode_general_stats_read 3 46111 _001734_hash NULL
85665 +_001735_hash il3945_ucode_rx_stats_read 3 3048 _001735_hash NULL
85666 +_001736_hash il3945_ucode_tx_stats_read 3 36016 _001736_hash NULL
85667 +_001737_hash il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 _001737_hash NULL
85668 +_001738_hash il4965_rs_sta_dbgfs_scale_table_read 3 38564 _001738_hash NULL
85669 +_001739_hash il4965_rs_sta_dbgfs_stats_table_read 3 49206 _001739_hash NULL
85670 +_001740_hash il4965_ucode_general_stats_read 3 56277 _001740_hash NULL
85671 +_001741_hash il4965_ucode_rx_stats_read 3 61948 _001741_hash NULL
85672 +_001742_hash il4965_ucode_tx_stats_read 3 12064 _001742_hash NULL
85673 +_001743_hash il_dbgfs_chain_noise_read 3 38044 _001743_hash NULL
85674 +_001744_hash il_dbgfs_channels_read 3 25005 _001744_hash NULL
85675 +_001745_hash il_dbgfs_disable_ht40_read 3 42386 _001745_hash NULL
85676 +_001746_hash il_dbgfs_fh_reg_read 3 40993 _001746_hash NULL
85677 +_001747_hash il_dbgfs_force_reset_read 3 57517 _001747_hash NULL
85678 +_001748_hash il_dbgfs_interrupt_read 3 3351 _001748_hash NULL
85679 +_001749_hash il_dbgfs_missed_beacon_read 3 59956 _001749_hash NULL
85680 +_001750_hash il_dbgfs_nvm_read 3 12288 _001750_hash NULL
85681 +_001751_hash il_dbgfs_power_save_status_read 3 43165 _001751_hash NULL
85682 +_001752_hash il_dbgfs_qos_read 3 33615 _001752_hash NULL
85683 +_001753_hash il_dbgfs_rxon_filter_flags_read 3 19281 _001753_hash NULL
85684 +_001754_hash il_dbgfs_rxon_flags_read 3 59950 _001754_hash &_001681_hash
85685 +_001755_hash il_dbgfs_rx_queue_read 3 11221 _001755_hash NULL
85686 +_001756_hash il_dbgfs_rx_stats_read 3 15243 _001756_hash NULL
85687 +_001757_hash il_dbgfs_sensitivity_read 3 2370 _001757_hash NULL
85688 +_001758_hash il_dbgfs_sram_read 3 62296 _001758_hash NULL
85689 +_001759_hash il_dbgfs_stations_read 3 21532 _001759_hash NULL
85690 +_001760_hash il_dbgfs_status_read 3 58388 _001760_hash NULL
85691 +_001761_hash il_dbgfs_tx_queue_read 3 55668 _001761_hash NULL
85692 +_001762_hash il_dbgfs_tx_stats_read 3 32913 _001762_hash NULL
85693 +_001763_hash ima_show_htable_value 2 57136 _001763_hash NULL
85694 +_001765_hash ipw_write 3 59807 _001765_hash NULL
85695 +_001766_hash irda_recvmsg_stream 4 35280 _001766_hash NULL
85696 +_001767_hash iscsi_tcp_conn_setup 2 16376 _001767_hash NULL
85697 +_001768_hash isr_cmd_cmplt_read 3 53439 _001768_hash NULL
85698 +_001769_hash isr_commands_read 3 41398 _001769_hash NULL
85699 +_001770_hash isr_decrypt_done_read 3 49490 _001770_hash NULL
85700 +_001771_hash isr_dma0_done_read 3 8574 _001771_hash NULL
85701 +_001772_hash isr_dma1_done_read 3 48159 _001772_hash NULL
85702 +_001773_hash isr_fiqs_read 3 34687 _001773_hash NULL
85703 +_001774_hash isr_host_acknowledges_read 3 54136 _001774_hash NULL
85704 +_001775_hash isr_hw_pm_mode_changes_read 3 16110 _001775_hash &_001696_hash
85705 +_001776_hash isr_irqs_read 3 9181 _001776_hash NULL
85706 +_001777_hash isr_low_rssi_read 3 64789 _001777_hash NULL
85707 +_001778_hash isr_pci_pm_read 3 30271 _001778_hash NULL
85708 +_001779_hash isr_rx_headers_read 3 38325 _001779_hash NULL
85709 +_001780_hash isr_rx_mem_overflow_read 3 43025 _001780_hash NULL
85710 +_001781_hash isr_rx_procs_read 3 31804 _001781_hash NULL
85711 +_001782_hash isr_rx_rdys_read 3 35283 _001782_hash NULL
85712 +_001783_hash isr_tx_exch_complete_read 3 16103 _001783_hash NULL
85713 +_001784_hash isr_tx_procs_read 3 23084 _001784_hash NULL
85714 +_001785_hash isr_wakeups_read 3 49607 _001785_hash NULL
85715 +_001786_hash ivtv_read 3 57796 _001786_hash NULL
85716 +_001787_hash iwl_dbgfs_bt_traffic_read 3 35534 _001787_hash NULL
85717 +_001788_hash iwl_dbgfs_chain_noise_read 3 46355 _001788_hash NULL
85718 +_001789_hash iwl_dbgfs_channels_read 3 6784 _001789_hash NULL
85719 +_001790_hash iwl_dbgfs_current_sleep_command_read 3 2081 _001790_hash NULL
85720 +_001791_hash iwl_dbgfs_disable_ht40_read 3 35761 _001791_hash NULL
85721 +_001792_hash iwl_dbgfs_fh_reg_read 3 879 _001792_hash &_000393_hash
85722 +_001793_hash iwl_dbgfs_force_reset_read 3 62628 _001793_hash NULL
85723 +_001794_hash iwl_dbgfs_interrupt_read 3 23574 _001794_hash NULL
85724 +_001795_hash iwl_dbgfs_log_event_read 3 2107 _001795_hash NULL
85725 +_001796_hash iwl_dbgfs_missed_beacon_read 3 50584 _001796_hash NULL
85726 +_001797_hash iwl_dbgfs_nvm_read 3 23845 _001797_hash NULL
85727 +_001798_hash iwl_dbgfs_plcp_delta_read 3 55407 _001798_hash NULL
85728 +_001799_hash iwl_dbgfs_power_save_status_read 3 54392 _001799_hash NULL
85729 +_001800_hash iwl_dbgfs_protection_mode_read 3 13943 _001800_hash NULL
85730 +_001801_hash iwl_dbgfs_qos_read 3 11753 _001801_hash NULL
85731 +_001802_hash iwl_dbgfs_reply_tx_error_read 3 19205 _001802_hash NULL
85732 +_001803_hash iwl_dbgfs_rx_handlers_read 3 18708 _001803_hash NULL
85733 +_001804_hash iwl_dbgfs_rxon_filter_flags_read 3 28832 _001804_hash NULL
85734 +_001805_hash iwl_dbgfs_rxon_flags_read 3 20795 _001805_hash NULL
85735 +_001806_hash iwl_dbgfs_rx_queue_read 3 19943 _001806_hash NULL
85736 +_001807_hash iwl_dbgfs_rx_statistics_read 3 62687 _001807_hash &_000425_hash
85737 +_001808_hash iwl_dbgfs_sensitivity_read 3 63116 _003026_hash NULL nohasharray
85738 +_001809_hash iwl_dbgfs_sleep_level_override_read 3 3038 _001809_hash NULL
85739 +_001810_hash iwl_dbgfs_sram_read 3 44505 _001810_hash NULL
85740 +_001811_hash iwl_dbgfs_stations_read 3 9309 _001811_hash NULL
85741 +_001812_hash iwl_dbgfs_status_read 3 5171 _001812_hash NULL
85742 +_001813_hash iwl_dbgfs_temperature_read 3 29224 _001813_hash NULL
85743 +_001814_hash iwl_dbgfs_thermal_throttling_read 3 38779 _001814_hash NULL
85744 +_001815_hash iwl_dbgfs_traffic_log_read 3 58870 _001815_hash NULL
85745 +_001816_hash iwl_dbgfs_tx_queue_read 3 4635 _001816_hash NULL
85746 +_001817_hash iwl_dbgfs_tx_statistics_read 3 314 _003437_hash NULL nohasharray
85747 +_001818_hash iwl_dbgfs_ucode_bt_stats_read 3 42820 _001818_hash NULL
85748 +_001819_hash iwl_dbgfs_ucode_general_stats_read 3 49199 _001819_hash NULL
85749 +_001820_hash iwl_dbgfs_ucode_rx_stats_read 3 58023 _001820_hash NULL
85750 +_001821_hash iwl_dbgfs_ucode_tracing_read 3 47983 _001821_hash &_000349_hash
85751 +_001822_hash iwl_dbgfs_ucode_tx_stats_read 3 31611 _001822_hash NULL
85752 +_001823_hash iwl_dbgfs_wowlan_sram_read 3 540 _001823_hash NULL
85753 +_001824_hash iwm_if_alloc 1 17027 _001824_hash &_001314_hash
85754 +_001825_hash kernel_readv 3 35617 _001825_hash NULL
85755 +_001826_hash key_algorithm_read 3 57946 _001826_hash NULL
85756 +_001827_hash key_icverrors_read 3 20895 _001827_hash NULL
85757 +_001828_hash key_key_read 3 3241 _001828_hash NULL
85758 +_001829_hash key_replays_read 3 62746 _001829_hash NULL
85759 +_001830_hash key_rx_spec_read 3 12736 _001830_hash NULL
85760 +_001831_hash key_tx_spec_read 3 4862 _001831_hash NULL
85761 +_001832_hash __kfifo_to_user 3 36555 _002199_hash NULL nohasharray
85762 +_001833_hash __kfifo_to_user_r 3 39123 _001833_hash NULL
85763 +_001834_hash kmem_zalloc_greedy 2-3 65268 _001834_hash NULL
85764 +_001836_hash l2cap_chan_send 3 49995 _001836_hash NULL
85765 +_001837_hash l2cap_sar_segment_sdu 3 27701 _001837_hash NULL
85766 +_001838_hash lbs_debugfs_read 3 30721 _001838_hash NULL
85767 +_001839_hash lbs_dev_info 3 51023 _001839_hash NULL
85768 +_001840_hash lbs_host_sleep_read 3 31013 _001840_hash NULL
85769 +_001841_hash lbs_rdbbp_read 3 45805 _001841_hash NULL
85770 +_001842_hash lbs_rdmac_read 3 418 _001842_hash NULL
85771 +_001843_hash lbs_rdrf_read 3 41431 _001843_hash NULL
85772 +_001844_hash lbs_sleepparams_read 3 10840 _001844_hash NULL
85773 +_001845_hash lbs_threshold_read 5 21046 _001845_hash NULL
85774 +_001846_hash libfc_vport_create 2 4415 _001846_hash NULL
85775 +_001847_hash lkdtm_debugfs_read 3 45752 _001847_hash NULL
85776 +_001848_hash llcp_sock_recvmsg 4 13556 _001848_hash NULL
85777 +_001849_hash long_retry_limit_read 3 59766 _001849_hash NULL
85778 +_001850_hash lpfc_debugfs_dif_err_read 3 36303 _001850_hash NULL
85779 +_001851_hash lpfc_debugfs_read 3 16566 _001851_hash NULL
85780 +_001852_hash lpfc_idiag_baracc_read 3 58466 _002447_hash NULL nohasharray
85781 +_001853_hash lpfc_idiag_ctlacc_read 3 33943 _001853_hash NULL
85782 +_001854_hash lpfc_idiag_drbacc_read 3 15948 _001854_hash NULL
85783 +_001855_hash lpfc_idiag_extacc_read 3 48301 _001855_hash NULL
85784 +_001856_hash lpfc_idiag_mbxacc_read 3 28061 _001856_hash NULL
85785 +_001857_hash lpfc_idiag_pcicfg_read 3 50334 _001857_hash NULL
85786 +_001858_hash lpfc_idiag_queacc_read 3 13950 _001858_hash NULL
85787 +_001859_hash lpfc_idiag_queinfo_read 3 55662 _001859_hash NULL
85788 +_001860_hash mac80211_format_buffer 2 41010 _001860_hash NULL
85789 +_001861_hash macvtap_put_user 4 55609 _001861_hash NULL
85790 +_001862_hash macvtap_sendmsg 4 30629 _001862_hash NULL
85791 +_001863_hash mic_calc_failure_read 3 59700 _001863_hash NULL
85792 +_001864_hash mic_rx_pkts_read 3 27972 _001864_hash NULL
85793 +_001865_hash minstrel_stats_read 3 17290 _001865_hash NULL
85794 +_001866_hash mmc_ext_csd_read 3 13205 _001866_hash NULL
85795 +_001867_hash mon_bin_read 3 6841 _001867_hash NULL
85796 +_001868_hash mon_stat_read 3 25238 _001868_hash NULL
85797 +_001870_hash mqueue_read_file 3 6228 _001870_hash NULL
85798 +_001871_hash mwifiex_debug_read 3 53074 _001871_hash NULL
85799 +_001872_hash mwifiex_getlog_read 3 54269 _001872_hash NULL
85800 +_001873_hash mwifiex_info_read 3 53447 _001873_hash NULL
85801 +_001874_hash mwifiex_rdeeprom_read 3 51429 _001874_hash NULL
85802 +_001875_hash mwifiex_regrdwr_read 3 34472 _001875_hash NULL
85803 +_001876_hash nfsd_vfs_read 6 62605 _003003_hash NULL nohasharray
85804 +_001877_hash nfsd_vfs_write 6 54577 _001877_hash NULL
85805 +_001878_hash nfs_idmap_lookup_id 2 10660 _001878_hash NULL
85806 +_001879_hash o2hb_debug_read 3 37851 _001879_hash NULL
85807 +_001880_hash o2net_debug_read 3 52105 _001880_hash NULL
85808 +_001881_hash ocfs2_control_read 3 56405 _001881_hash NULL
85809 +_001882_hash ocfs2_debug_read 3 14507 _001882_hash NULL
85810 +_001883_hash ocfs2_readlink 3 50656 _001883_hash NULL
85811 +_001884_hash oom_adjust_read 3 25127 _001884_hash NULL
85812 +_001885_hash oom_score_adj_read 3 39921 _002116_hash NULL nohasharray
85813 +_001886_hash oprofilefs_str_to_user 3 42182 _001886_hash NULL
85814 +_001887_hash oprofilefs_ulong_to_user 3 11582 _001887_hash NULL
85815 +_001888_hash _osd_req_list_objects 6 4204 _001888_hash NULL
85816 +_001889_hash osd_req_read_kern 5 59990 _001889_hash NULL
85817 +_001890_hash osd_req_write_kern 5 53486 _001890_hash NULL
85818 +_001891_hash p54_init_common 1 23850 _001891_hash NULL
85819 +_001892_hash packet_sendmsg 4 24954 _001892_hash NULL
85820 +_001893_hash page_readlink 3 23346 _001893_hash NULL
85821 +_001894_hash pcf50633_write_block 3 2124 _001894_hash NULL
85822 +_001895_hash platform_list_read_file 3 34734 _001895_hash NULL
85823 +_001896_hash pm860x_bulk_write 3 43875 _001896_hash NULL
85824 +_001897_hash pm_qos_power_read 3 55891 _001897_hash NULL
85825 +_001898_hash pms_read 3 53873 _001898_hash NULL
85826 +_001899_hash port_show_regs 3 5904 _001899_hash NULL
85827 +_001900_hash proc_coredump_filter_read 3 39153 _001900_hash NULL
85828 +_001901_hash proc_fdinfo_read 3 62043 _001901_hash NULL
85829 +_001902_hash proc_info_read 3 63344 _001902_hash NULL
85830 +_001903_hash proc_loginuid_read 3 15631 _001903_hash NULL
85831 +_001904_hash proc_pid_attr_read 3 10173 _001904_hash NULL
85832 +_001905_hash proc_pid_readlink 3 52186 _001905_hash NULL
85833 +_001906_hash proc_read 3 43614 _001906_hash NULL
85834 +_001907_hash proc_self_readlink 3 38094 _001907_hash NULL
85835 +_001908_hash proc_sessionid_read 3 6911 _002038_hash NULL nohasharray
85836 +_001909_hash provide_user_output 3 41105 _001909_hash NULL
85837 +_001910_hash ps_pspoll_max_apturn_read 3 6699 _001910_hash NULL
85838 +_001911_hash ps_pspoll_timeouts_read 3 11776 _001911_hash NULL
85839 +_001912_hash ps_pspoll_utilization_read 3 5361 _001912_hash NULL
85840 +_001913_hash pstore_file_read 3 57288 _001913_hash NULL
85841 +_001914_hash ps_upsd_max_apturn_read 3 19918 _001914_hash NULL
85842 +_001915_hash ps_upsd_max_sptime_read 3 63362 _001915_hash NULL
85843 +_001916_hash ps_upsd_timeouts_read 3 28924 _001916_hash NULL
85844 +_001917_hash ps_upsd_utilization_read 3 51669 _001917_hash NULL
85845 +_001918_hash pvr2_v4l2_read 3 18006 _001918_hash NULL
85846 +_001919_hash pwr_disable_ps_read 3 13176 _001919_hash NULL
85847 +_001920_hash pwr_elp_enter_read 3 5324 _001920_hash NULL
85848 +_001921_hash pwr_enable_ps_read 3 17686 _001921_hash NULL
85849 +_001922_hash pwr_fix_tsf_ps_read 3 26627 _001922_hash NULL
85850 +_001923_hash pwr_missing_bcns_read 3 25824 _001923_hash NULL
85851 +_001924_hash pwr_power_save_off_read 3 18355 _001924_hash NULL
85852 +_001925_hash pwr_ps_enter_read 3 26935 _001925_hash &_000501_hash
85853 +_001926_hash pwr_rcvd_awake_beacons_read 3 50505 _001926_hash NULL
85854 +_001927_hash pwr_rcvd_beacons_read 3 52836 _001927_hash NULL
85855 +_001928_hash pwr_tx_without_ps_read 3 48423 _001928_hash NULL
85856 +_001929_hash pwr_tx_with_ps_read 3 60851 _001929_hash NULL
85857 +_001930_hash pwr_wake_on_host_read 3 26321 _001930_hash NULL
85858 +_001931_hash pwr_wake_on_timer_exp_read 3 22640 _001931_hash NULL
85859 +_001932_hash queues_read 3 24877 _001932_hash NULL
85860 +_001933_hash raw_recvmsg 4 17277 _001933_hash NULL
85861 +_001934_hash rcname_read 3 25919 _001934_hash NULL
85862 +_001935_hash read_4k_modal_eeprom 3 30212 _001935_hash NULL
85863 +_001936_hash read_9287_modal_eeprom 3 59327 _001936_hash NULL
85864 +_001937_hash reada_find_extent 2 63486 _001937_hash NULL
85865 +_001938_hash read_def_modal_eeprom 3 14041 _001938_hash NULL
85866 +_001939_hash read_enabled_file_bool 3 37744 _001939_hash NULL
85867 +_001940_hash read_file_ani 3 23161 _001940_hash NULL
85868 +_001941_hash read_file_antenna 3 13574 _001941_hash NULL
85869 +_001942_hash read_file_base_eeprom 3 42168 _001942_hash NULL
85870 +_001943_hash read_file_beacon 3 32595 _001943_hash NULL
85871 +_001944_hash read_file_blob 3 57406 _001944_hash NULL
85872 +_001945_hash read_file_bool 3 4180 _001945_hash NULL
85873 +_001946_hash read_file_credit_dist_stats 3 54367 _001946_hash NULL
85874 +_001947_hash read_file_debug 3 58256 _001947_hash NULL
85875 +_001948_hash read_file_disable_ani 3 6536 _001948_hash NULL
85876 +_001949_hash read_file_dma 3 9530 _001949_hash NULL
85877 +_001950_hash read_file_dump_nfcal 3 18766 _001950_hash NULL
85878 +_001951_hash read_file_frameerrors 3 64001 _001951_hash NULL
85879 +_001952_hash read_file_interrupt 3 61742 _001959_hash NULL nohasharray
85880 +_001953_hash read_file_misc 3 9948 _001953_hash NULL
85881 +_001954_hash read_file_modal_eeprom 3 39909 _001954_hash NULL
85882 +_001955_hash read_file_queue 3 40895 _001955_hash NULL
85883 +_001956_hash read_file_rcstat 3 22854 _001956_hash NULL
85884 +_001957_hash read_file_recv 3 48232 _001957_hash NULL
85885 +_001958_hash read_file_regidx 3 33370 _001958_hash NULL
85886 +_001959_hash read_file_regval 3 61742 _001959_hash &_001952_hash
85887 +_001960_hash read_file_reset 3 52310 _001960_hash NULL
85888 +_001961_hash read_file_rx_chainmask 3 41605 _001961_hash NULL
85889 +_001962_hash read_file_slot 3 50111 _001962_hash NULL
85890 +_001963_hash read_file_stations 3 35795 _001963_hash NULL
85891 +_001964_hash read_file_tgt_int_stats 3 20697 _001964_hash NULL
85892 +_001965_hash read_file_tgt_rx_stats 3 33944 _001965_hash NULL
85893 +_001966_hash read_file_tgt_stats 3 8959 _001966_hash NULL
85894 +_001967_hash read_file_tgt_tx_stats 3 51847 _001967_hash NULL
85895 +_001968_hash read_file_tx_chainmask 3 3829 _001968_hash NULL
85896 +_001969_hash read_file_war_stats 3 292 _001969_hash NULL
85897 +_001970_hash read_file_xmit 3 21487 _001970_hash NULL
85898 +_001971_hash read_from_oldmem 2 3337 _001971_hash NULL
85899 +_001972_hash read_oldmem 3 55658 _001972_hash NULL
85900 +_001973_hash regmap_name_read_file 3 39379 _001973_hash NULL
85901 +_001974_hash repair_io_failure 4 4815 _001974_hash NULL
85902 +_001975_hash request_key_and_link 4 42693 _001975_hash NULL
85903 +_001976_hash res_counter_read 4 33499 _001976_hash NULL
85904 +_001977_hash retry_count_read 3 52129 _001977_hash NULL
85905 +_001978_hash rs_sta_dbgfs_rate_scale_data_read 3 47165 _001978_hash NULL
85906 +_001979_hash rs_sta_dbgfs_scale_table_read 3 40262 _001979_hash NULL
85907 +_001980_hash rs_sta_dbgfs_stats_table_read 3 56573 _001980_hash NULL
85908 +_001981_hash rts_threshold_read 3 44384 _001981_hash NULL
85909 +_001982_hash rx_dropped_read 3 44799 _001982_hash NULL
85910 +_001983_hash rx_fcs_err_read 3 62844 _001983_hash NULL
85911 +_001984_hash rx_hdr_overflow_read 3 64407 _001984_hash NULL
85912 +_001985_hash rx_hw_stuck_read 3 57179 _001985_hash NULL
85913 +_001986_hash rx_out_of_mem_read 3 10157 _001986_hash NULL
85914 +_001987_hash rx_path_reset_read 3 23801 _001987_hash NULL
85915 +_001988_hash rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 _001988_hash NULL
85916 +_001989_hash rxpipe_descr_host_int_trig_rx_data_read 3 22001 _003089_hash NULL nohasharray
85917 +_001990_hash rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 _001990_hash NULL
85918 +_001991_hash rxpipe_rx_prep_beacon_drop_read 3 2403 _001991_hash NULL
85919 +_001992_hash rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 _001992_hash NULL
85920 +_001993_hash rx_reset_counter_read 3 58001 _001993_hash NULL
85921 +_001994_hash rx_xfr_hint_trig_read 3 40283 _001994_hash NULL
85922 +_001995_hash s5m_bulk_write 3 4833 _001995_hash NULL
85923 +_001996_hash scrub_setup_recheck_block 3-4 56245 _001996_hash NULL
85924 +_001998_hash scsi_adjust_queue_depth 3 12802 _001998_hash NULL
85925 +_001999_hash selinux_inode_notifysecctx 3 36896 _001999_hash NULL
85926 +_002000_hash sel_read_avc_cache_threshold 3 33942 _002000_hash NULL
85927 +_002001_hash sel_read_avc_hash_stats 3 1984 _002001_hash NULL
85928 +_002002_hash sel_read_bool 3 24236 _002002_hash NULL
85929 +_002003_hash sel_read_checkreqprot 3 33068 _002003_hash NULL
85930 +_002004_hash sel_read_class 3 12669 _002541_hash NULL nohasharray
85931 +_002005_hash sel_read_enforce 3 2828 _002005_hash NULL
85932 +_002006_hash sel_read_handle_status 3 56139 _002006_hash NULL
85933 +_002007_hash sel_read_handle_unknown 3 57933 _002007_hash NULL
85934 +_002008_hash sel_read_initcon 3 32362 _002008_hash NULL
85935 +_002009_hash sel_read_mls 3 25369 _002009_hash NULL
85936 +_002010_hash sel_read_perm 3 42302 _002010_hash NULL
85937 +_002011_hash sel_read_policy 3 55947 _002011_hash NULL
85938 +_002012_hash sel_read_policycap 3 28544 _002012_hash NULL
85939 +_002013_hash sel_read_policyvers 3 55 _003257_hash NULL nohasharray
85940 +_002014_hash send_msg 4 37323 _002014_hash NULL
85941 +_002015_hash send_packet 4 52960 _002015_hash NULL
85942 +_002016_hash short_retry_limit_read 3 4687 _002016_hash NULL
85943 +_002017_hash simple_attr_read 3 24738 _002017_hash NULL
85944 +_002018_hash simple_transaction_read 3 17076 _002018_hash NULL
85945 +_002019_hash skb_copy_datagram_const_iovec 2-5-4 48102 _002019_hash NULL
85946 +_002022_hash skb_copy_datagram_iovec 2-4 5806 _002022_hash NULL
85947 +_002024_hash smk_read_ambient 3 61220 _002024_hash NULL
85948 +_002025_hash smk_read_direct 3 15803 _002025_hash NULL
85949 +_002026_hash smk_read_doi 3 30813 _002026_hash NULL
85950 +_002027_hash smk_read_logging 3 37804 _002027_hash NULL
85951 +_002028_hash smk_read_onlycap 3 3855 _002028_hash NULL
85952 +_002029_hash snapshot_read 3 22601 _002029_hash NULL
85953 +_002030_hash snd_cs4281_BA0_read 5 6847 _002030_hash NULL
85954 +_002031_hash snd_cs4281_BA1_read 5 20323 _002031_hash NULL
85955 +_002032_hash snd_cs46xx_io_read 5 45734 _002032_hash NULL
85956 +_002033_hash snd_gus_dram_read 4 56686 _002033_hash NULL
85957 +_002034_hash snd_pcm_oss_read 3 28317 _002034_hash NULL
85958 +_002035_hash snd_rme32_capture_copy 5 39653 _002035_hash NULL
85959 +_002036_hash snd_rme96_capture_copy 5 58484 _002036_hash NULL
85960 +_002037_hash snd_soc_hw_bulk_write_raw 4 14245 _002037_hash NULL
85961 +_002038_hash spi_show_regs 3 6911 _002038_hash &_001908_hash
85962 +_002039_hash sta_agg_status_read 3 14058 _002039_hash NULL
85963 +_002040_hash sta_connected_time_read 3 17435 _002040_hash NULL
85964 +_002041_hash sta_flags_read 3 56710 _002041_hash NULL
85965 +_002042_hash sta_ht_capa_read 3 10366 _002042_hash NULL
85966 +_002043_hash sta_last_seq_ctrl_read 3 19106 _002043_hash NULL
85967 +_002044_hash sta_num_ps_buf_frames_read 3 1488 _002044_hash NULL
85968 +_002045_hash st_read 3 51251 _002045_hash NULL
85969 +_002046_hash supply_map_read_file 3 10608 _002046_hash NULL
85970 +_002047_hash sysfs_read_file 3 42113 _002047_hash NULL
85971 +_002048_hash sys_lgetxattr 4 45531 _002048_hash NULL
85972 +_002049_hash sys_preadv 3 17100 _002049_hash NULL
85973 +_002050_hash sys_pwritev 3 41722 _002050_hash NULL
85974 +_002051_hash sys_readv 3 50664 _002051_hash NULL
85975 +_002052_hash sys_rt_sigpending 2 24961 _002052_hash NULL
85976 +_002053_hash sys_writev 3 28384 _002053_hash NULL
85977 +_002054_hash test_iso_queue 5 62534 _002054_hash NULL
85978 +_002055_hash ts_read 3 44687 _002055_hash NULL
85979 +_002056_hash TSS_authhmac 3 12839 _002056_hash NULL
85980 +_002057_hash TSS_checkhmac1 5 31429 _002057_hash NULL
85981 +_002058_hash TSS_checkhmac2 5-7 40520 _002058_hash NULL
85982 +_002060_hash tt3650_ci_msg_locked 4 8013 _002060_hash NULL
85983 +_002061_hash tun_sendmsg 4 10337 _002061_hash NULL
85984 +_002062_hash tx_internal_desc_overflow_read 3 47300 _002062_hash NULL
85985 +_002063_hash tx_queue_len_read 3 1463 _002063_hash NULL
85986 +_002064_hash tx_queue_status_read 3 44978 _002064_hash NULL
85987 +_002065_hash ubi_io_write_data 4-5 40305 _002065_hash NULL
85988 +_002067_hash uhci_debug_read 3 5911 _002067_hash NULL
85989 +_002068_hash unix_stream_recvmsg 4 35210 _002068_hash NULL
85990 +_002069_hash uvc_debugfs_stats_read 3 56651 _002069_hash NULL
85991 +_002070_hash vhost_add_used_and_signal_n 4 8038 _002070_hash NULL
85992 +_002071_hash vifs_state_read 3 33762 _002071_hash NULL
85993 +_002072_hash vmbus_open 2-3 12154 _002072_hash NULL
85994 +_002074_hash waiters_read 3 40902 _002074_hash NULL
85995 +_002075_hash wep_addr_key_count_read 3 20174 _002075_hash NULL
85996 +_002076_hash wep_decrypt_fail_read 3 58567 _002076_hash NULL
85997 +_002077_hash wep_default_key_count_read 3 43035 _002077_hash NULL
85998 +_002078_hash wep_interrupt_read 3 41492 _002078_hash NULL
85999 +_002079_hash wep_key_not_found_read 3 13377 _002079_hash &_000915_hash
86000 +_002080_hash wep_packets_read 3 18751 _002080_hash NULL
86001 +_002081_hash wl1271_format_buffer 2 20834 _002081_hash NULL
86002 +_002082_hash wm8994_bulk_write 3 13615 _002082_hash NULL
86003 +_002083_hash wusb_prf_256 7 29203 _002083_hash NULL
86004 +_002084_hash wusb_prf_64 7 51065 _002084_hash NULL
86005 +_002085_hash xfs_buf_read_uncached 4 27519 _002085_hash NULL
86006 +_002086_hash xfs_iext_add 3 41422 _002086_hash NULL
86007 +_002087_hash xfs_iext_remove_direct 3 40744 _002087_hash NULL
86008 +_002088_hash xfs_trans_get_efd 3 51148 _002088_hash NULL
86009 +_002089_hash xfs_trans_get_efi 2 7898 _002089_hash NULL
86010 +_002090_hash xlog_get_bp 2 23229 _002090_hash NULL
86011 +_002091_hash xz_dec_init 2 29029 _002091_hash NULL
86012 +_002092_hash aac_change_queue_depth 2 825 _002092_hash NULL
86013 +_002093_hash agp_allocate_memory_wrap 1 16576 _002093_hash NULL
86014 +_002094_hash arcmsr_adjust_disk_queue_depth 2 16756 _002094_hash NULL
86015 +_002095_hash atalk_recvmsg 4 22053 _002095_hash NULL
86016 +_002097_hash atomic_read_file 3 16227 _002097_hash NULL
86017 +_002098_hash ax25_recvmsg 4 64441 _002098_hash NULL
86018 +_002099_hash beacon_interval_read 3 7091 _002099_hash NULL
86019 +_002100_hash btrfs_init_new_buffer 4 55761 _002100_hash NULL
86020 +_002101_hash btrfs_mksubvol 3 39479 _002101_hash NULL
86021 +_002102_hash bt_sock_recvmsg 4 12316 _002102_hash NULL
86022 +_002103_hash bt_sock_stream_recvmsg 4 52518 _002103_hash NULL
86023 +_002104_hash caif_seqpkt_recvmsg 4 32241 _002104_hash NULL
86024 +_002105_hash cpu_type_read 3 36540 _002105_hash NULL
86025 +_002106_hash cx18_read 3 23699 _002106_hash NULL
86026 +_002107_hash dccp_recvmsg 4 16056 _002107_hash NULL
86027 +_002108_hash depth_read 3 31112 _002108_hash NULL
86028 +_002109_hash dfs_global_file_read 3 7787 _002109_hash NULL
86029 +_002110_hash dgram_recvmsg 4 23104 _002110_hash NULL
86030 +_002111_hash dma_skb_copy_datagram_iovec 3-5 21516 _002111_hash NULL
86031 +_002113_hash dtim_interval_read 3 654 _002113_hash NULL
86032 +_002114_hash dynamic_ps_timeout_read 3 10110 _002114_hash NULL
86033 +_002115_hash enable_read 3 2117 _002115_hash NULL
86034 +_002116_hash exofs_read_kern 6 39921 _002116_hash &_001885_hash
86035 +_002117_hash fc_change_queue_depth 2 36841 _002117_hash NULL
86036 +_002118_hash forced_ps_read 3 31685 _002118_hash NULL
86037 +_002119_hash frequency_read 3 64031 _003106_hash NULL nohasharray
86038 +_002120_hash get_alua_req 3 4166 _002120_hash NULL
86039 +_002121_hash get_rdac_req 3 45882 _002121_hash NULL
86040 +_002122_hash hci_sock_recvmsg 4 7072 _002122_hash NULL
86041 +_002123_hash hpsa_change_queue_depth 2 15449 _002123_hash NULL
86042 +_002124_hash hptiop_adjust_disk_queue_depth 2 20122 _002124_hash NULL
86043 +_002125_hash ide_queue_pc_tail 5 11673 _002125_hash NULL
86044 +_002126_hash ide_raw_taskfile 4 42355 _002126_hash NULL
86045 +_002127_hash idetape_queue_rw_tail 3 29562 _002127_hash NULL
86046 +_002128_hash ieee80211_if_read_aid 3 9705 _002128_hash NULL
86047 +_002129_hash ieee80211_if_read_auto_open_plinks 3 38268 _003504_hash NULL nohasharray
86048 +_002130_hash ieee80211_if_read_ave_beacon 3 64924 _002130_hash NULL
86049 +_002131_hash ieee80211_if_read_bssid 3 35161 _002131_hash NULL
86050 +_002132_hash ieee80211_if_read_channel_type 3 23884 _002132_hash NULL
86051 +_002133_hash ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 _002133_hash NULL
86052 +_002134_hash ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 _002134_hash NULL
86053 +_002135_hash ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 _002135_hash NULL
86054 +_002136_hash ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 _002136_hash NULL
86055 +_002137_hash ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 _002137_hash NULL
86056 +_002138_hash ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 _002138_hash NULL
86057 +_002139_hash ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 _002139_hash NULL
86058 +_002140_hash ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 _002140_hash NULL
86059 +_002141_hash ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 _002141_hash NULL
86060 +_002142_hash ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 _002142_hash NULL
86061 +_002143_hash ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 _002143_hash NULL
86062 +_002144_hash ieee80211_if_read_dot11MeshMaxRetries 3 12756 _002144_hash NULL
86063 +_002145_hash ieee80211_if_read_dot11MeshRetryTimeout 3 52168 _002145_hash NULL
86064 +_002146_hash ieee80211_if_read_dot11MeshTTL 3 58307 _002146_hash NULL
86065 +_002147_hash ieee80211_if_read_dropped_frames_congestion 3 32603 _002147_hash NULL
86066 +_002148_hash ieee80211_if_read_dropped_frames_no_route 3 33383 _002148_hash NULL
86067 +_002149_hash ieee80211_if_read_dropped_frames_ttl 3 44500 _002149_hash NULL
86068 +_002150_hash ieee80211_if_read_drop_unencrypted 3 37053 _002150_hash NULL
86069 +_002151_hash ieee80211_if_read_dtim_count 3 38419 _002151_hash NULL
86070 +_002152_hash ieee80211_if_read_element_ttl 3 18869 _002152_hash NULL
86071 +_002153_hash ieee80211_if_read_estab_plinks 3 32533 _002153_hash NULL
86072 +_002154_hash ieee80211_if_read_flags 3 57470 _002389_hash NULL nohasharray
86073 +_002155_hash ieee80211_if_read_fwded_frames 3 36520 _002155_hash NULL
86074 +_002156_hash ieee80211_if_read_fwded_mcast 3 39571 _002156_hash &_000151_hash
86075 +_002157_hash ieee80211_if_read_fwded_unicast 3 59740 _002859_hash NULL nohasharray
86076 +_002158_hash ieee80211_if_read_last_beacon 3 31257 _002158_hash NULL
86077 +_002159_hash ieee80211_if_read_min_discovery_timeout 3 13946 _002159_hash NULL
86078 +_002160_hash ieee80211_if_read_num_buffered_multicast 3 12716 _002160_hash NULL
86079 +_002161_hash ieee80211_if_read_num_sta_authorized 3 56177 _002161_hash NULL
86080 +_002162_hash ieee80211_if_read_num_sta_ps 3 34722 _002162_hash NULL
86081 +_002163_hash ieee80211_if_read_path_refresh_time 3 25545 _002163_hash NULL
86082 +_002164_hash ieee80211_if_read_peer 3 45233 _002164_hash NULL
86083 +_002165_hash ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 _002165_hash NULL
86084 +_002166_hash ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 _002166_hash NULL
86085 +_002167_hash ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 _002167_hash NULL
86086 +_002168_hash ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 _002168_hash NULL
86087 +_002169_hash ieee80211_if_read_rssi_threshold 3 49260 _002169_hash NULL
86088 +_002170_hash ieee80211_if_read_smps 3 27416 _002170_hash NULL
86089 +_002171_hash ieee80211_if_read_state 3 9813 _002280_hash NULL nohasharray
86090 +_002172_hash ieee80211_if_read_tkip_mic_test 3 19565 _002172_hash NULL
86091 +_002173_hash ieee80211_if_read_tsf 3 16420 _002173_hash NULL
86092 +_002174_hash ieee80211_if_read_uapsd_max_sp_len 3 15067 _002174_hash NULL
86093 +_002175_hash ieee80211_if_read_uapsd_queues 3 55150 _002175_hash NULL
86094 +_002176_hash ieee80211_rx_mgmt_beacon 3 24430 _002176_hash NULL
86095 +_002177_hash ieee80211_rx_mgmt_probe_resp 3 6918 _002177_hash NULL
86096 +_002178_hash ima_show_htable_violations 3 10619 _002178_hash NULL
86097 +_002179_hash ima_show_measurements_count 3 23536 _002179_hash NULL
86098 +_002180_hash insert_one_name 7 61668 _002180_hash NULL
86099 +_002181_hash ipr_change_queue_depth 2 6431 _002181_hash NULL
86100 +_002182_hash ip_recv_error 3 23109 _002182_hash NULL
86101 +_002183_hash ipv6_recv_error 3 56347 _002183_hash NULL
86102 +_002184_hash ipv6_recv_rxpmtu 3 7142 _002184_hash NULL
86103 +_002185_hash ipx_recvmsg 4 44366 _002185_hash NULL
86104 +_002186_hash irda_recvmsg_dgram 4 32631 _002186_hash NULL
86105 +_002187_hash iscsi_change_queue_depth 2 23416 _002187_hash NULL
86106 +_002188_hash ivtv_read_pos 3 34400 _002188_hash &_000303_hash
86107 +_002189_hash key_conf_hw_key_idx_read 3 25003 _002189_hash NULL
86108 +_002190_hash key_conf_keyidx_read 3 42443 _002190_hash NULL
86109 +_002191_hash key_conf_keylen_read 3 49758 _002191_hash NULL
86110 +_002192_hash key_flags_read 3 25931 _002192_hash NULL
86111 +_002193_hash key_ifindex_read 3 31411 _002193_hash NULL
86112 +_002194_hash key_tx_rx_count_read 3 44742 _002194_hash NULL
86113 +_002195_hash l2cap_sock_sendmsg 4 63427 _002195_hash NULL
86114 +_002196_hash l2tp_ip_recvmsg 4 22681 _002196_hash NULL
86115 +_002197_hash llc_ui_recvmsg 4 3826 _002197_hash NULL
86116 +_002198_hash lpfc_change_queue_depth 2 25905 _002198_hash NULL
86117 +_002199_hash macvtap_do_read 4 36555 _002199_hash &_001832_hash
86118 +_002200_hash megaraid_change_queue_depth 2 64815 _002200_hash NULL
86119 +_002201_hash megasas_change_queue_depth 2 32747 _002201_hash NULL
86120 +_002202_hash mptscsih_change_queue_depth 2 26036 _002202_hash NULL
86121 +_002203_hash NCR_700_change_queue_depth 2 31742 _002203_hash NULL
86122 +_002204_hash netlink_recvmsg 4 61600 _002204_hash NULL
86123 +_002205_hash nfsctl_transaction_read 3 48250 _002205_hash NULL
86124 +_002206_hash nfs_map_group_to_gid 3 15892 _002206_hash NULL
86125 +_002207_hash nfs_map_name_to_uid 3 51132 _002207_hash NULL
86126 +_002208_hash nr_recvmsg 4 12649 _002208_hash NULL
86127 +_002209_hash osd_req_list_collection_objects 5 36664 _002209_hash NULL
86128 +_002210_hash osd_req_list_partition_objects 5 56464 _002210_hash NULL
86129 +_002212_hash packet_recv_error 3 16669 _002212_hash NULL
86130 +_002213_hash packet_recvmsg 4 47700 _002213_hash NULL
86131 +_002214_hash pep_recvmsg 4 19402 _002214_hash NULL
86132 +_002215_hash pfkey_recvmsg 4 53604 _002215_hash NULL
86133 +_002216_hash ping_recvmsg 4 25597 _002216_hash NULL
86134 +_002217_hash pmcraid_change_queue_depth 2 9116 _002217_hash NULL
86135 +_002218_hash pn_recvmsg 4 30887 _002218_hash NULL
86136 +_002219_hash pointer_size_read 3 51863 _002219_hash NULL
86137 +_002220_hash power_read 3 15939 _002220_hash NULL
86138 +_002221_hash pppoe_recvmsg 4 15073 _002221_hash NULL
86139 +_002222_hash pppol2tp_recvmsg 4 57742 _003858_hash NULL nohasharray
86140 +_002223_hash qla2x00_adjust_sdev_qdepth_up 2 20097 _002223_hash NULL
86141 +_002224_hash qla2x00_change_queue_depth 2 24742 _002224_hash NULL
86142 +_002225_hash raw_recvmsg 4 52529 _002225_hash NULL
86143 +_002226_hash rawsock_recvmsg 4 12144 _002226_hash NULL
86144 +_002227_hash rawv6_recvmsg 4 30265 _002227_hash NULL
86145 +_002228_hash reada_add_block 2 54247 _002228_hash NULL
86146 +_002229_hash readahead_tree_block 3 36285 _002229_hash NULL
86147 +_002230_hash reada_tree_block_flagged 3 18402 _002230_hash NULL
86148 +_002231_hash read_tree_block 3 841 _002231_hash NULL
86149 +_002232_hash recover_peb 6-7 29238 _002232_hash NULL
86150 +_002234_hash recv_msg 4 48709 _002234_hash NULL
86151 +_002235_hash recv_stream 4 30138 _002235_hash NULL
86152 +_002236_hash _req_append_segment 2 41031 _002236_hash NULL
86153 +_002237_hash request_key_async 4 6990 _002237_hash NULL
86154 +_002238_hash request_key_async_with_auxdata 4 46624 _002238_hash NULL
86155 +_002239_hash request_key_with_auxdata 4 24515 _002239_hash NULL
86156 +_002240_hash rose_recvmsg 4 2368 _002240_hash NULL
86157 +_002241_hash rxrpc_recvmsg 4 26233 _002241_hash NULL
86158 +_002242_hash rx_streaming_always_read 3 49401 _002242_hash NULL
86159 +_002243_hash rx_streaming_interval_read 3 55291 _002243_hash NULL
86160 +_002244_hash sas_change_queue_depth 2 18555 _002244_hash NULL
86161 +_002245_hash scsi_activate_tcq 2 42640 _002245_hash NULL
86162 +_002246_hash scsi_deactivate_tcq 2 47086 _002246_hash NULL
86163 +_002247_hash scsi_execute 5 33596 _002247_hash NULL
86164 +_002248_hash _scsih_adjust_queue_depth 2 1083 _002248_hash NULL
86165 +_002249_hash scsi_init_shared_tag_map 2 59812 _002249_hash NULL
86166 +_002250_hash scsi_track_queue_full 2 44239 _002250_hash NULL
86167 +_002251_hash sctp_recvmsg 4 23265 _002251_hash NULL
86168 +_002252_hash send_stream 4 3397 _002252_hash NULL
86169 +_002253_hash skb_copy_and_csum_datagram_iovec 2 24466 _002253_hash NULL
86170 +_002255_hash snd_gf1_mem_proc_dump 5 16926 _003922_hash NULL nohasharray
86171 +_002256_hash split_scan_timeout_read 3 20029 _002256_hash NULL
86172 +_002257_hash sta_dev_read 3 14782 _002257_hash NULL
86173 +_002258_hash sta_inactive_ms_read 3 25690 _002258_hash NULL
86174 +_002259_hash sta_last_signal_read 3 31818 _002259_hash NULL
86175 +_002260_hash stats_dot11ACKFailureCount_read 3 45558 _002260_hash NULL
86176 +_002261_hash stats_dot11FCSErrorCount_read 3 28154 _002261_hash NULL
86177 +_002262_hash stats_dot11RTSFailureCount_read 3 43948 _002262_hash NULL
86178 +_002263_hash stats_dot11RTSSuccessCount_read 3 33065 _002263_hash NULL
86179 +_002264_hash storvsc_connect_to_vsp 2 22 _002264_hash NULL
86180 +_002265_hash suspend_dtim_interval_read 3 64971 _002265_hash NULL
86181 +_002266_hash sys_msgrcv 3 959 _002266_hash NULL
86182 +_002267_hash tcm_loop_change_queue_depth 2 42454 _002267_hash NULL
86183 +_002268_hash tcp_copy_to_iovec 3 28344 _002268_hash NULL
86184 +_002269_hash tcp_recvmsg 4 31238 _002269_hash NULL
86185 +_002270_hash timeout_read 3 47915 _002270_hash NULL
86186 +_002271_hash total_ps_buffered_read 3 16365 _002271_hash NULL
86187 +_002272_hash tun_put_user 4 59849 _002272_hash NULL
86188 +_002273_hash twa_change_queue_depth 2 48808 _002273_hash NULL
86189 +_002274_hash tw_change_queue_depth 2 11116 _002274_hash NULL
86190 +_002275_hash twl_change_queue_depth 2 41342 _002275_hash NULL
86191 +_002276_hash ubi_eba_write_leb 5-6 19826 _002276_hash NULL
86192 +_002278_hash ubi_eba_write_leb_st 5 27896 _002278_hash NULL
86193 +_002279_hash udp_recvmsg 4 42558 _002279_hash NULL
86194 +_002280_hash udpv6_recvmsg 4 9813 _002280_hash &_002171_hash
86195 +_002281_hash ulong_read_file 3 42304 _002281_hash &_000511_hash
86196 +_002282_hash unix_dgram_recvmsg 4 14952 _002282_hash NULL
86197 +_002283_hash user_power_read 3 39414 _002283_hash NULL
86198 +_002284_hash vcc_recvmsg 4 37198 _002284_hash NULL
86199 +_002285_hash wep_iv_read 3 54744 _002285_hash NULL
86200 +_002286_hash x25_recvmsg 4 42777 _002286_hash NULL
86201 +_002287_hash xfs_iext_insert 3 18667 _003817_hash NULL nohasharray
86202 +_002288_hash xfs_iext_remove 3 50909 _002288_hash NULL
86203 +_002289_hash xlog_find_verify_log_record 2 18870 _002289_hash NULL
86204 +_002290_hash btrfs_alloc_free_block 3 29982 _002290_hash NULL
86205 +_002291_hash cx18_read_pos 3 4683 _002291_hash NULL
86206 +_002292_hash l2cap_sock_recvmsg 4 59886 _002292_hash NULL
86207 +_002293_hash osd_req_list_dev_partitions 4 60027 _002293_hash NULL
86208 +_002294_hash osd_req_list_partition_collections 5 38223 _002294_hash NULL
86209 +_002295_hash osst_do_scsi 4 44410 _002295_hash NULL
86210 +_002296_hash qla2x00_handle_queue_full 2 24365 _002296_hash NULL
86211 +_002297_hash rfcomm_sock_recvmsg 4 22227 _002297_hash NULL
86212 +_002298_hash scsi_execute_req 5 42088 _002298_hash NULL
86213 +_002299_hash _scsih_change_queue_depth 2 26230 _002299_hash NULL
86214 +_002300_hash spi_execute 5 28736 _002300_hash NULL
86215 +_002301_hash submit_inquiry 3 42108 _002301_hash NULL
86216 +_002302_hash tcp_dma_try_early_copy 3 37651 _002302_hash NULL
86217 +_002303_hash tun_do_read 4 50800 _002303_hash NULL
86218 +_002304_hash ubi_eba_atomic_leb_change 5 13041 _002304_hash NULL
86219 +_002305_hash ubi_leb_write 4-5 41691 _002305_hash NULL
86220 +_002307_hash unix_seqpacket_recvmsg 4 23062 _003542_hash NULL nohasharray
86221 +_002308_hash write_leb 5 36957 _002308_hash NULL
86222 +_002309_hash ch_do_scsi 4 31171 _002309_hash NULL
86223 +_002310_hash dbg_leb_write 4-5 20478 _002310_hash NULL
86224 +_002312_hash scsi_mode_sense 5 16835 _002312_hash NULL
86225 +_002313_hash scsi_vpd_inquiry 4 30040 _002313_hash NULL
86226 +_002314_hash ses_recv_diag 4 47143 _002314_hash &_000673_hash
86227 +_002315_hash ses_send_diag 4 64527 _002315_hash NULL
86228 +_002316_hash spi_dv_device_echo_buffer 2-3 39846 _002316_hash NULL
86229 +_002318_hash ubifs_leb_write 4-5 61226 _002318_hash NULL
86230 +_002320_hash ubi_leb_change 4 14899 _002320_hash NULL
86231 +_002321_hash ubi_write 4-5 30809 _002321_hash NULL
86232 +_002322_hash dbg_leb_change 4 19969 _002322_hash NULL
86233 +_002323_hash gluebi_write 3 27905 _002323_hash NULL
86234 +_002324_hash scsi_get_vpd_page 4 51951 _002324_hash NULL
86235 +_002325_hash sd_do_mode_sense 5 11507 _002325_hash NULL
86236 +_002326_hash ubifs_leb_change 4 22399 _002436_hash NULL nohasharray
86237 +_002327_hash ubifs_write_node 5 15088 _002327_hash NULL
86238 +_002328_hash fixup_leb 3 43256 _002328_hash NULL
86239 +_002329_hash recover_head 3 17904 _002329_hash NULL
86240 +_002330_hash alloc_cpu_rmap 1 65363 _002330_hash NULL
86241 +_002331_hash alloc_ebda_hpc 1-2 50046 _002331_hash NULL
86242 +_002333_hash alloc_sched_domains 1 28972 _002333_hash NULL
86243 +_002334_hash amthi_read 4 45831 _002334_hash NULL
86244 +_002335_hash bcm_char_read 3 31750 _002335_hash NULL
86245 +_002336_hash BcmCopySection 5 2035 _002336_hash NULL
86246 +_002337_hash buffer_from_user 3 51826 _002337_hash NULL
86247 +_002338_hash buffer_to_user 3 35439 _002338_hash NULL
86248 +_002339_hash c4iw_init_resource_fifo 3 48090 _002339_hash NULL
86249 +_002340_hash c4iw_init_resource_fifo_random 3 25547 _002340_hash NULL
86250 +_002341_hash card_send_command 3 40757 _002341_hash NULL
86251 +_002342_hash chd_dec_fetch_cdata 3 50926 _002342_hash NULL
86252 +_002343_hash crystalhd_create_dio_pool 2 3427 _002343_hash NULL
86253 +_002344_hash crystalhd_user_data 3 18407 _002344_hash NULL
86254 +_002345_hash cxio_init_resource_fifo 3 28764 _002345_hash NULL
86255 +_002346_hash cxio_init_resource_fifo_random 3 47151 _002346_hash NULL
86256 +_002347_hash do_pages_stat 2 4437 _002347_hash NULL
86257 +_002348_hash do_read_log_to_user 4 3236 _002348_hash NULL
86258 +_002349_hash do_write_log_from_user 3 39362 _002349_hash NULL
86259 +_002350_hash dt3155_read 3 59226 _002350_hash NULL
86260 +_002351_hash easycap_alsa_vmalloc 2 14426 _002351_hash NULL
86261 +_002352_hash evm_read_key 3 54674 _002352_hash NULL
86262 +_002353_hash evm_write_key 3 27715 _002353_hash NULL
86263 +_002354_hash fir16_create 3 5574 _002354_hash NULL
86264 +_002355_hash iio_allocate_device 1 18821 _002355_hash NULL
86265 +_002356_hash __iio_allocate_kfifo 2-3 55738 _002356_hash NULL
86266 +_002358_hash __iio_allocate_sw_ring_buffer 3 4843 _002358_hash NULL
86267 +_002359_hash iio_debugfs_read_reg 3 60908 _002359_hash NULL
86268 +_002360_hash iio_debugfs_write_reg 3 22742 _002360_hash NULL
86269 +_002361_hash iio_event_chrdev_read 3 54757 _002361_hash NULL
86270 +_002362_hash iio_read_first_n_kfifo 2 57910 _002362_hash NULL
86271 +_002363_hash iio_read_first_n_sw_rb 2 51911 _002363_hash NULL
86272 +_002364_hash ioapic_setup_resources 1 35255 _002364_hash NULL
86273 +_002365_hash keymap_store 4 45406 _002365_hash NULL
86274 +_002366_hash kzalloc_node 1 24352 _002366_hash NULL
86275 +_002367_hash line6_alloc_sysex_buffer 4 28225 _002367_hash NULL
86276 +_002368_hash line6_dumpreq_initbuf 3 53123 _002368_hash NULL
86277 +_002369_hash line6_midibuf_init 2 52425 _002369_hash NULL
86278 +_002370_hash lirc_write 3 20604 _002370_hash NULL
86279 +_002371_hash _malloc 1 54077 _002371_hash NULL
86280 +_002372_hash mei_read 3 6507 _002372_hash NULL
86281 +_002373_hash mei_write 3 4005 _002373_hash NULL
86282 +_002374_hash mempool_create_node 1 44715 _002374_hash NULL
86283 +_002375_hash msg_set 3 51725 _002375_hash NULL
86284 +_002376_hash newpart 6 47485 _002376_hash NULL
86285 +_002377_hash OS_kmalloc 1 36909 _002377_hash NULL
86286 +_002378_hash pcpu_alloc_bootmem 2 62074 _002378_hash NULL
86287 +_002379_hash pcpu_get_vm_areas 3 50085 _002379_hash NULL
86288 +_002380_hash resource_from_user 3 30341 _002380_hash NULL
86289 +_002381_hash sca3000_read_data 4 57064 _002381_hash NULL
86290 +_002382_hash sca3000_read_first_n_hw_rb 2 11479 _002382_hash NULL
86291 +_002383_hash send_midi_async 3 57463 _002383_hash NULL
86292 +_002384_hash sep_create_dcb_dmatables_context 6 37551 _002384_hash NULL
86293 +_002385_hash sep_create_dcb_dmatables_context_kernel 6 49728 _002385_hash NULL
86294 +_002386_hash sep_create_msgarea_context 4 33829 _002386_hash NULL
86295 +_002387_hash sep_lli_table_secure_dma 2-3 64042 _002387_hash NULL
86296 +_002389_hash sep_lock_user_pages 2-3 57470 _002389_hash &_002154_hash
86297 +_002391_hash sep_prepare_input_output_dma_table_in_dcb 4-5-2-3 63087 _002391_hash NULL
86298 +_002393_hash sep_read 3 17161 _002393_hash NULL
86299 +_002394_hash TransmitTcb 4 12989 _002394_hash NULL
86300 +_002395_hash ValidateDSDParamsChecksum 3 63654 _002395_hash NULL
86301 +_002396_hash Wb35Reg_BurstWrite 4 62327 _002396_hash NULL
86302 +_002397_hash __alloc_bootmem_low_node 2 25726 _002397_hash &_001499_hash
86303 +_002398_hash __alloc_bootmem_node 2 1992 _002398_hash NULL
86304 +_002399_hash alloc_irq_cpu_rmap 1 28459 _002399_hash NULL
86305 +_002400_hash alloc_ring 2-4 18278 _002400_hash NULL
86306 +_002402_hash c4iw_init_resource 2-3 30393 _002402_hash NULL
86307 +_002404_hash cxio_hal_init_resource 2-7-6 29771 _002404_hash &_000284_hash
86308 +_002407_hash cxio_hal_init_rhdl_resource 1 25104 _002407_hash NULL
86309 +_002408_hash disk_expand_part_tbl 2 30561 _002408_hash NULL
86310 +_002409_hash InterfaceTransmitPacket 3 42058 _002409_hash NULL
86311 +_002410_hash line6_dumpreq_init 3 34473 _002410_hash NULL
86312 +_002411_hash mempool_create 1 29437 _002411_hash NULL
86313 +_002412_hash pcpu_fc_alloc 2 11818 _002412_hash NULL
86314 +_002413_hash pod_alloc_sysex_buffer 3 31651 _002413_hash NULL
86315 +_002414_hash r8712_usbctrl_vendorreq 6 48489 _002414_hash NULL
86316 +_002415_hash r871x_set_wpa_ie 3 7000 _002415_hash NULL
86317 +_002416_hash sys_move_pages 2 42626 _002416_hash NULL
86318 +_002417_hash variax_alloc_sysex_buffer 3 15237 _002417_hash NULL
86319 +_002418_hash vme_user_write 3 15587 _002418_hash NULL
86320 +_002419_hash add_partition 2 55588 _002419_hash NULL
86321 +_002420_hash __alloc_bootmem_node_high 2 65076 _002420_hash NULL
86322 +_002421_hash ceph_msgpool_init 3 33312 _002421_hash NULL
86323 +_002423_hash mempool_create_kmalloc_pool 1 41650 _002423_hash NULL
86324 +_002424_hash mempool_create_page_pool 1 30189 _002424_hash NULL
86325 +_002425_hash mempool_create_slab_pool 1 62907 _002425_hash NULL
86326 +_002426_hash variax_set_raw2 4 32374 _002426_hash NULL
86327 +_002427_hash bioset_create 1 5580 _002427_hash NULL
86328 +_002428_hash bioset_integrity_create 2 62708 _002428_hash NULL
86329 +_002429_hash biovec_create_pools 2 9575 _002429_hash NULL
86330 +_002430_hash i2o_pool_alloc 4 55485 _002430_hash NULL
86331 +_002431_hash prison_create 1 43623 _002431_hash NULL
86332 +_002432_hash unlink_simple 3 47506 _002432_hash NULL
86333 +_002433_hash alloc_ieee80211 1 20063 _002433_hash NULL
86334 +_002434_hash alloc_ieee80211_rsl 1 34564 _002434_hash NULL
86335 +_002435_hash alloc_page_cgroup 1 2919 _002435_hash NULL
86336 +_002436_hash alloc_private 2 22399 _002436_hash &_002326_hash
86337 +_002437_hash alloc_rtllib 1 51136 _002437_hash NULL
86338 +_002438_hash alloc_rx_desc_ring 2 18016 _002438_hash NULL
86339 +_002439_hash alloc_subdevices 2 43300 _002439_hash NULL
86340 +_002440_hash atomic_counters_read 3 48827 _002440_hash NULL
86341 +_002441_hash atomic_stats_read 3 36228 _002441_hash NULL
86342 +_002442_hash capabilities_read 3 58457 _002442_hash NULL
86343 +_002443_hash comedi_read 3 13199 _002443_hash NULL
86344 +_002444_hash comedi_write 3 47926 _002444_hash NULL
86345 +_002445_hash compat_do_arpt_set_ctl 4 12184 _002445_hash NULL
86346 +_002446_hash compat_do_ip6t_set_ctl 4 3184 _002446_hash NULL
86347 +_002447_hash compat_do_ipt_set_ctl 4 58466 _002447_hash &_001852_hash
86348 +_002448_hash compat_filldir 3 32999 _002448_hash NULL
86349 +_002449_hash compat_filldir64 3 35354 _002449_hash NULL
86350 +_002450_hash compat_fillonedir 3 15620 _002450_hash NULL
86351 +_002451_hash compat_rw_copy_check_uvector 3 25242 _002451_hash NULL
86352 +_002452_hash compat_sock_setsockopt 5 23 _002452_hash NULL
86353 +_002453_hash compat_sys_kexec_load 2 35674 _002453_hash NULL
86354 +_002454_hash compat_sys_keyctl 4 9639 _002454_hash NULL
86355 +_002455_hash compat_sys_move_pages 2 5861 _002455_hash NULL
86356 +_002456_hash compat_sys_mq_timedsend 3 31060 _002456_hash NULL
86357 +_002457_hash compat_sys_msgrcv 2 7482 _002457_hash NULL
86358 +_002458_hash compat_sys_msgsnd 2 10738 _002458_hash NULL
86359 +_002459_hash compat_sys_semtimedop 3 3606 _002459_hash NULL
86360 +_002460_hash __copy_in_user 3 34790 _002460_hash NULL
86361 +_002461_hash copy_in_user 3 57502 _002461_hash NULL
86362 +_002462_hash dev_counters_read 3 19216 _002462_hash NULL
86363 +_002463_hash dev_names_read 3 38509 _002463_hash NULL
86364 +_002464_hash do_arpt_set_ctl 4 51053 _002464_hash NULL
86365 +_002465_hash do_ip6t_set_ctl 4 60040 _002465_hash NULL
86366 +_002466_hash do_ipt_set_ctl 4 56238 _002466_hash NULL
86367 +_002467_hash drbd_bm_resize 2 20522 _002467_hash NULL
86368 +_002468_hash driver_names_read 3 60399 _002468_hash NULL
86369 +_002469_hash driver_stats_read 3 8944 _002469_hash NULL
86370 +_002470_hash __earlyonly_bootmem_alloc 2 23824 _002470_hash NULL
86371 +_002471_hash evtchn_read 3 3569 _002471_hash NULL
86372 +_002472_hash ext_sd_execute_read_data 9 48589 _002472_hash NULL
86373 +_002473_hash ext_sd_execute_write_data 9 8175 _002473_hash NULL
86374 +_002474_hash fat_compat_ioctl_filldir 3 36328 _002474_hash NULL
86375 +_002475_hash firmwareUpload 3 32794 _002475_hash NULL
86376 +_002476_hash flash_read 3 57843 _002476_hash NULL
86377 +_002477_hash flash_write 3 62354 _002477_hash NULL
86378 +_002478_hash gather_array 3 56641 _002478_hash NULL
86379 +_002479_hash ghash_async_setkey 3 60001 _002479_hash NULL
86380 +_002480_hash gntdev_alloc_map 2 35145 _002480_hash NULL
86381 +_002481_hash gnttab_map 2 56439 _002481_hash NULL
86382 +_002482_hash gru_alloc_gts 2-3 60056 _003495_hash NULL nohasharray
86383 +_002484_hash handle_eviocgbit 3 44193 _002484_hash NULL
86384 +_002485_hash hid_parse_report 3 51737 _002485_hash NULL
86385 +_002486_hash ieee80211_alloc_txb 1-2 52477 _002486_hash NULL
86386 +_002487_hash ieee80211_wx_set_gen_ie 3 51399 _002487_hash NULL
86387 +_002488_hash ieee80211_wx_set_gen_ie_rsl 3 3521 _002488_hash NULL
86388 +_002489_hash init_cdev 1 8274 _002489_hash NULL
86389 +_002490_hash init_per_cpu 1 17880 _002490_hash NULL
86390 +_002491_hash ipath_create_cq 2 45586 _002491_hash NULL
86391 +_002492_hash ipath_get_base_info 3 7043 _002492_hash NULL
86392 +_002493_hash ipath_init_qp_table 2 25167 _002493_hash NULL
86393 +_002494_hash ipath_resize_cq 2 712 _002494_hash NULL
86394 +_002495_hash ni_gpct_device_construct 5 610 _002495_hash NULL
86395 +_002496_hash options_write 3 47243 _002496_hash NULL
86396 +_002497_hash portcntrs_1_read 3 47253 _002497_hash NULL
86397 +_002498_hash portcntrs_2_read 3 56586 _002498_hash NULL
86398 +_002499_hash portnames_read 3 41958 _002499_hash NULL
86399 +_002500_hash ptc_proc_write 3 12076 _002500_hash NULL
86400 +_002501_hash put_cmsg_compat 4 35937 _002501_hash NULL
86401 +_002502_hash qib_alloc_devdata 2 51819 _002502_hash NULL
86402 +_002503_hash qib_alloc_fast_reg_page_list 2 10507 _002503_hash NULL
86403 +_002504_hash qib_cdev_init 1 34778 _002504_hash NULL
86404 +_002505_hash qib_create_cq 2 27497 _002505_hash NULL
86405 +_002506_hash qib_diag_write 3 62133 _002506_hash NULL
86406 +_002507_hash qib_get_base_info 3 11369 _002507_hash NULL
86407 +_002508_hash qib_resize_cq 2 53090 _002508_hash NULL
86408 +_002509_hash qsfp_1_read 3 21915 _002509_hash NULL
86409 +_002510_hash qsfp_2_read 3 31491 _002510_hash NULL
86410 +_002511_hash queue_reply 3 22416 _002511_hash NULL
86411 +_002512_hash Realloc 2 34961 _002512_hash NULL
86412 +_002513_hash rfc4106_set_key 3 54519 _002513_hash NULL
86413 +_002514_hash rtllib_alloc_txb 1-2 21687 _002514_hash NULL
86414 +_002515_hash rtllib_wx_set_gen_ie 3 59808 _002515_hash NULL
86415 +_002516_hash rts51x_transfer_data_partial 6 5735 _002516_hash NULL
86416 +_002517_hash sparse_early_usemaps_alloc_node 4 9269 _002517_hash NULL
86417 +_002518_hash split 2 11691 _002518_hash NULL
86418 +_002519_hash stats_read_ul 3 32751 _002519_hash NULL
86419 +_002520_hash store_debug_level 3 35652 _002520_hash NULL
86420 +_002521_hash sys32_ipc 3 7238 _002521_hash NULL
86421 +_002522_hash sys32_rt_sigpending 2 25814 _002522_hash NULL
86422 +_002523_hash tunables_read 3 36385 _002523_hash NULL
86423 +_002524_hash tunables_write 3 59563 _002524_hash NULL
86424 +_002525_hash u32_array_read 3 2219 _002525_hash NULL
86425 +_002526_hash usb_buffer_alloc 2 36276 _002526_hash NULL
86426 +_002527_hash xenbus_file_write 3 6282 _002527_hash NULL
86427 +_002528_hash xpc_kmalloc_cacheline_aligned 1 42895 _002528_hash NULL
86428 +_002529_hash xpc_kzalloc_cacheline_aligned 1 65433 _002529_hash NULL
86429 +_002530_hash xsd_read 3 15653 _002530_hash NULL
86430 +_002531_hash compat_do_readv_writev 4 49102 _002531_hash NULL
86431 +_002532_hash compat_keyctl_instantiate_key_iov 3 57431 _003110_hash NULL nohasharray
86432 +_002533_hash compat_process_vm_rw 3-5 22254 _002533_hash NULL
86433 +_002535_hash compat_sys_setsockopt 5 3326 _002535_hash NULL
86434 +_002536_hash ipath_cdev_init 1 37752 _002536_hash NULL
86435 +_002537_hash ms_read_multiple_pages 4-5 8052 _002537_hash NULL
86436 +_002539_hash ms_write_multiple_pages 5-6 10362 _002539_hash NULL
86437 +_002541_hash sparse_mem_maps_populate_node 4 12669 _002541_hash &_002004_hash
86438 +_002542_hash vmemmap_alloc_block 1 43245 _002542_hash NULL
86439 +_002543_hash xd_read_multiple_pages 4-5 11422 _002543_hash NULL
86440 +_002545_hash xd_write_multiple_pages 5-6 53633 _002545_hash NULL
86441 +_002546_hash compat_readv 3 30273 _002546_hash NULL
86442 +_002547_hash compat_sys_process_vm_readv 3-5 15374 _002547_hash NULL
86443 +_002549_hash compat_sys_process_vm_writev 3-5 41194 _002549_hash NULL
86444 +_002551_hash compat_writev 3 60063 _002551_hash NULL
86445 +_002552_hash ms_rw_multi_sector 4-3 7459 _002552_hash NULL
86446 +_002553_hash sparse_early_mem_maps_alloc_node 4 36971 _002553_hash NULL
86447 +_002554_hash vmemmap_alloc_block_buf 1 61126 _002554_hash NULL
86448 +_002555_hash xd_rw 4-3 49020 _002555_hash NULL
86449 +_002556_hash compat_sys_preadv64 3 24283 _002556_hash NULL
86450 +_002557_hash compat_sys_pwritev64 3 51151 _002557_hash NULL
86451 +_002558_hash compat_sys_readv 3 20911 _002558_hash NULL
86452 +_002559_hash compat_sys_writev 3 5784 _002559_hash NULL
86453 +_002560_hash ms_rw 4 17220 _002560_hash NULL
86454 +_002561_hash compat_sys_preadv 3 583 _002561_hash NULL
86455 +_002562_hash compat_sys_pwritev 3 17886 _002562_hash NULL
86456 +_002563_hash alloc_apertures 1 56561 _002563_hash NULL
86457 +_002564_hash bin_uuid 3 28999 _002564_hash NULL
86458 +_002565_hash __copy_from_user_inatomic_nocache 3 49921 _002565_hash NULL
86459 +_002566_hash do_dmabuf_dirty_sou 7 3017 _002566_hash NULL
86460 +_002567_hash do_surface_dirty_sou 7 39678 _002567_hash NULL
86461 +_002568_hash drm_agp_bind_pages 3 56748 _002568_hash NULL
86462 +_002569_hash drm_calloc_large 1-2 65421 _002569_hash NULL
86463 +_002571_hash drm_fb_helper_init 3-4 19044 _002571_hash NULL
86464 +_002573_hash drm_ht_create 2 18853 _002573_hash NULL
86465 +_002574_hash drm_malloc_ab 1-2 16831 _002574_hash NULL
86466 +_002576_hash drm_mode_crtc_set_gamma_size 2 31881 _002576_hash NULL
86467 +_002577_hash drm_plane_init 6 28731 _002577_hash NULL
86468 +_002578_hash drm_property_create 4 51239 _002578_hash NULL
86469 +_002579_hash drm_property_create_blob 2 7414 _002579_hash NULL
86470 +_002580_hash drm_vblank_init 2 11362 _002580_hash NULL
86471 +_002581_hash drm_vmalloc_dma 1 14550 _002581_hash NULL
86472 +_002582_hash fb_alloc_cmap_gfp 2 20792 _002582_hash NULL
86473 +_002583_hash fbcon_prepare_logo 5 6246 _002583_hash NULL
86474 +_002584_hash fb_read 3 33506 _002584_hash NULL
86475 +_002585_hash fb_write 3 46924 _002585_hash NULL
86476 +_002586_hash framebuffer_alloc 1 59145 _002586_hash NULL
86477 +_002587_hash i915_cache_sharing_read 3 24775 _002587_hash NULL
86478 +_002588_hash i915_cache_sharing_write 3 57961 _002588_hash NULL
86479 +_002589_hash i915_max_freq_read 3 20581 _002589_hash NULL
86480 +_002590_hash i915_max_freq_write 3 11350 _002590_hash NULL
86481 +_002591_hash i915_wedged_read 3 35474 _002591_hash NULL
86482 +_002592_hash i915_wedged_write 3 47771 _002592_hash NULL
86483 +_002593_hash p9_client_read 5 19750 _002593_hash NULL
86484 +_002594_hash probe_kernel_write 3 17481 _002594_hash NULL
86485 +_002595_hash sched_feat_write 3 55202 _002595_hash NULL
86486 +_002596_hash sd_alloc_ctl_entry 1 29708 _002596_hash NULL
86487 +_002597_hash tstats_write 3 60432 _002597_hash &_000009_hash
86488 +_002598_hash ttm_bo_fbdev_io 4 9805 _002598_hash NULL
86489 +_002599_hash ttm_bo_io 5 47000 _002599_hash NULL
86490 +_002600_hash ttm_dma_page_pool_free 2 34135 _002600_hash NULL
86491 +_002601_hash ttm_page_pool_free 2 61661 _002601_hash NULL
86492 +_002602_hash vmw_execbuf_process 5 22885 _002602_hash NULL
86493 +_002603_hash vmw_fifo_reserve 2 12141 _002603_hash NULL
86494 +_002604_hash vmw_kms_present 9 38130 _002604_hash NULL
86495 +_002605_hash vmw_kms_readback 6 5727 _002605_hash NULL
86496 +_002606_hash do_dmabuf_dirty_ldu 6 52241 _002606_hash NULL
86497 +_002607_hash drm_mode_create_tv_properties 2 23122 _002607_hash NULL
86498 +_002608_hash drm_property_create_enum 5 29201 _002608_hash NULL
86499 +_002609_hash fast_user_write 5 20494 _002609_hash NULL
86500 +_002610_hash fb_alloc_cmap 2 6554 _002610_hash NULL
86501 +_002611_hash i915_gem_execbuffer_relocate_slow 7 25355 _002611_hash NULL
86502 +_002612_hash kgdb_hex2mem 3 24755 _002612_hash NULL
86503 +_002613_hash ttm_object_device_init 2 10321 _002613_hash NULL
86504 +_002614_hash ttm_object_file_init 2 27804 _002614_hash NULL
86505 +_002615_hash vmw_cursor_update_image 3-4 16332 _002615_hash NULL
86506 +_002617_hash vmw_gmr2_bind 3 21305 _002617_hash NULL
86507 +_002618_hash vmw_cursor_update_dmabuf 3-4 32045 _002618_hash NULL
86508 +_002620_hash vmw_gmr_bind 3 44130 _002620_hash NULL
86509 +_002621_hash vmw_du_crtc_cursor_set 4-5 28479 _002621_hash NULL
86510 +_002622_hash __module_alloc 1 50004 _002622_hash NULL
86511 +_002623_hash module_alloc_update_bounds_rw 1 63233 _002623_hash NULL
86512 +_002624_hash module_alloc_update_bounds_rx 1 58634 _002624_hash NULL
86513 +_002625_hash acpi_system_write_alarm 3 40205 _002625_hash NULL
86514 +_002626_hash create_table 2 16213 _002626_hash NULL
86515 +_002627_hash mem_read 3 57631 _002627_hash NULL
86516 +_002628_hash mem_write 3 22232 _002628_hash NULL
86517 +_002629_hash proc_fault_inject_read 3 36802 _002629_hash NULL
86518 +_002630_hash proc_fault_inject_write 3 21058 _002630_hash NULL
86519 +_002631_hash v9fs_fid_readn 4 60544 _002631_hash NULL
86520 +_002632_hash v9fs_file_read 3 40858 _002632_hash NULL
86521 +_002633_hash __devres_alloc 2 25598 _002633_hash NULL
86522 +_002634_hash alloc_dummy_extent_buffer 2 56374 _002634_hash NULL
86523 +_002635_hash alloc_fdtable 1 17389 _002635_hash NULL
86524 +_002636_hash alloc_large_system_hash 2 22391 _002636_hash NULL
86525 +_002637_hash alloc_ldt 2 21972 _002637_hash NULL
86526 +_002638_hash __alloc_skb 1 23940 _002638_hash NULL
86527 +_002639_hash __ata_change_queue_depth 3 23484 _002639_hash NULL
86528 +_002640_hash btrfs_alloc_free_block 3 8986 _002640_hash NULL
86529 +_002641_hash btrfs_find_device_for_logical 2 44993 _002641_hash NULL
86530 +_002642_hash ccid3_hc_rx_getsockopt 3 62331 _002642_hash NULL
86531 +_002643_hash ccid3_hc_tx_getsockopt 3 16314 _002643_hash NULL
86532 +_002644_hash cifs_readdata_alloc 1 26360 _002644_hash NULL
86533 +_002645_hash cistpl_vers_1 4 15023 _002645_hash NULL
86534 +_002646_hash cmm_read 3 57520 _002646_hash NULL
86535 +_002647_hash cosa_read 3 25966 _002647_hash NULL
86536 +_002648_hash dm_table_create 3 35687 _002648_hash NULL
86537 +_002649_hash dpcm_state_read_file 3 65489 _002649_hash NULL
86538 +_002651_hash edac_mc_alloc 4 3611 _002651_hash NULL
86539 +_002652_hash ep0_read 3 38095 _002652_hash NULL
86540 +_002653_hash event_buffer_read 3 48772 _002765_hash NULL nohasharray
86541 +_002654_hash extend_netdev_table 2 21453 _002654_hash NULL
86542 +_002655_hash extract_entropy_user 3 26952 _003616_hash NULL nohasharray
86543 +_002656_hash fcoe_ctlr_device_add 3 1793 _002656_hash NULL
86544 +_002657_hash fd_do_readv 3 51297 _002657_hash NULL
86545 +_002658_hash fd_do_writev 3 29329 _002658_hash NULL
86546 +_002659_hash ffs_ep0_read 3 2672 _002659_hash NULL
86547 +_002660_hash fill_readbuf 3 32464 _002660_hash NULL
86548 +_002661_hash fw_iso_buffer_alloc 2 13704 _002661_hash NULL
86549 +_002662_hash get_fd_set 1 3866 _002662_hash NULL
86550 +_002663_hash hidraw_report_event 3 20503 _002663_hash NULL
86551 +_002664_hash ieee80211_if_read_ht_opmode 3 29044 _002664_hash NULL
86552 +_002665_hash ieee80211_if_read_num_mcast_sta 3 12419 _002665_hash NULL
86553 +_002666_hash iwl_dbgfs_calib_disabled_read 3 22649 _002666_hash NULL
86554 +_002667_hash iwl_dbgfs_rf_reset_read 3 26512 _002667_hash NULL
86555 +_002668_hash ixgbe_alloc_q_vector 4-6 24439 _002668_hash NULL
86556 +_002670_hash joydev_handle_JSIOCSAXMAP 3 48898 _002836_hash NULL nohasharray
86557 +_002671_hash joydev_handle_JSIOCSBTNMAP 3 15643 _002671_hash NULL
86558 +_002672_hash __kfifo_from_user_r 3 60345 _002672_hash NULL
86559 +_002673_hash kstrtoint_from_user 2 8778 _002673_hash NULL
86560 +_002674_hash kstrtol_from_user 2 10168 _002674_hash NULL
86561 +_002675_hash kstrtoll_from_user 2 19500 _002675_hash NULL
86562 +_002676_hash kstrtos16_from_user 2 28300 _002676_hash NULL
86563 +_002677_hash kstrtos8_from_user 2 58268 _002677_hash NULL
86564 +_002678_hash kstrtou16_from_user 2 54274 _002678_hash NULL
86565 +_002679_hash kstrtou8_from_user 2 55599 _002679_hash NULL
86566 +_002680_hash kstrtouint_from_user 2 10536 _002680_hash NULL
86567 +_002681_hash kstrtoul_from_user 2 64569 _002681_hash NULL
86568 +_002682_hash kstrtoull_from_user 2 63026 _002682_hash NULL
86569 +_002683_hash l2cap_create_iframe_pdu 3 40055 _002683_hash NULL
86570 +_002684_hash l2tp_ip6_recvmsg 4 62874 _002684_hash NULL
86571 +_002685_hash mem_cgroup_read 5 22461 _002685_hash NULL
86572 +_002686_hash nfs_fscache_get_super_cookie 3 44355 _002686_hash &_001648_hash
86573 +_002687_hash nfs_pgarray_set 2 1085 _002687_hash NULL
86574 +_002688_hash ntfs_rl_realloc 3 56831 _002688_hash &_000363_hash
86575 +_002689_hash ntfs_rl_realloc_nofail 3 32173 _002689_hash NULL
86576 +_002690_hash pn533_dep_link_up 5 22154 _002690_hash NULL
86577 +_002691_hash port_fops_write 3 54627 _002691_hash NULL
86578 +_002692_hash ptp_read 4 63251 _002692_hash NULL
86579 +_002693_hash qla4xxx_change_queue_depth 2 1268 _002693_hash NULL
86580 +_002694_hash reqsk_queue_alloc 2 40272 _002694_hash NULL
86581 +_002695_hash resize_info_buffer 2 62889 _002695_hash NULL
86582 +_002696_hash rfkill_fop_write 3 64808 _002696_hash NULL
86583 +_002697_hash rt2x00debug_write_rfcsr 3 41473 _002697_hash NULL
86584 +_002698_hash rvmalloc 1 46873 _002698_hash NULL
86585 +_002699_hash rw_copy_check_uvector 3 45748 _003398_hash NULL nohasharray
86586 +_002700_hash sctp_getsockopt_active_key 2 45483 _002700_hash NULL
86587 +_002701_hash sctp_getsockopt_adaptation_layer 2 45375 _002701_hash NULL
86588 +_002702_hash sctp_getsockopt_assoc_ids 2 9043 _002702_hash NULL
86589 +_002703_hash sctp_getsockopt_associnfo 2 58169 _002703_hash NULL
86590 +_002704_hash sctp_getsockopt_assoc_number 2 6384 _002704_hash NULL
86591 +_002705_hash sctp_getsockopt_auto_asconf 2 46584 _002705_hash NULL
86592 +_002706_hash sctp_getsockopt_context 2 52490 _002706_hash NULL
86593 +_002707_hash sctp_getsockopt_default_send_param 2 63056 _002707_hash NULL
86594 +_002708_hash sctp_getsockopt_disable_fragments 2 12330 _002708_hash NULL
86595 +_002709_hash sctp_getsockopt_fragment_interleave 2 51215 _002709_hash NULL
86596 +_002710_hash sctp_getsockopt_initmsg 2 26042 _002710_hash NULL
86597 +_002711_hash sctp_getsockopt_mappedv4 2 20044 _002711_hash NULL
86598 +_002712_hash sctp_getsockopt_nodelay 2 9560 _002712_hash NULL
86599 +_002713_hash sctp_getsockopt_partial_delivery_point 2 60952 _002713_hash NULL
86600 +_002714_hash sctp_getsockopt_peeloff 2 59190 _002714_hash NULL
86601 +_002715_hash sctp_getsockopt_peer_addr_info 2 6024 _002715_hash NULL
86602 +_002716_hash sctp_getsockopt_peer_addr_params 2 53645 _002716_hash NULL
86603 +_002717_hash sctp_getsockopt_primary_addr 2 24639 _002717_hash NULL
86604 +_002718_hash sctp_getsockopt_rtoinfo 2 62027 _002718_hash NULL
86605 +_002719_hash sctp_getsockopt_sctp_status 2 56540 _002719_hash NULL
86606 +_002720_hash self_check_write 5 50856 _002720_hash NULL
86607 +_002721_hash smk_read_mapped 3 7562 _002721_hash NULL
86608 +_002722_hash smk_set_cipso 3 20379 _002722_hash NULL
86609 +_002723_hash smk_user_access 3 24440 _002723_hash NULL
86610 +_002724_hash smk_write_mapped 3 13519 _002724_hash NULL
86611 +_002725_hash smk_write_rules_list 3 18565 _002725_hash NULL
86612 +_002726_hash snd_mixart_BA0_read 5 45069 _002726_hash NULL
86613 +_002727_hash snd_mixart_BA1_read 5 5082 _002727_hash NULL
86614 +_002728_hash snd_pcm_oss_read2 3 54387 _002728_hash NULL
86615 +_002729_hash syslog_print 2 307 _002729_hash NULL
86616 +_002730_hash tcp_dma_try_early_copy 3 4457 _002730_hash NULL
86617 +_002731_hash tcp_send_rcvq 3 11316 _002731_hash NULL
86618 +_002732_hash tomoyo_init_log 2 61526 _002732_hash NULL
86619 +_002733_hash ubi_dump_flash 4 46381 _002733_hash NULL
86620 +_002734_hash ubi_eba_atomic_leb_change 5 60379 _002734_hash NULL
86621 +_002735_hash ubi_eba_write_leb 5-6 36029 _002735_hash NULL
86622 +_002737_hash ubi_eba_write_leb_st 5 44343 _002737_hash NULL
86623 +_002738_hash ubi_self_check_all_ff 4 41959 _002738_hash NULL
86624 +_002739_hash unix_bind 3 15668 _002739_hash NULL
86625 +_002740_hash usbvision_rvmalloc 1 19655 _002740_hash NULL
86626 +_002742_hash v4l2_ctrl_new 7 24927 _002742_hash NULL
86627 +_002743_hash v4l2_event_subscribe 3 53687 _002743_hash NULL
86628 +_002744_hash v9fs_direct_read 3 45546 _002744_hash NULL
86629 +_002745_hash v9fs_file_readn 4 36353 _002745_hash &_001606_hash
86630 +_002746_hash __videobuf_alloc_vb 1 5665 _002746_hash NULL
86631 +_002747_hash wm8350_write 3 24480 _002747_hash NULL
86632 +_002748_hash xfs_buf_read_uncached 3 42844 _002748_hash NULL
86633 +_002749_hash yurex_write 3 8761 _002749_hash NULL
86634 +_002750_hash alloc_skb 1 55439 _002750_hash NULL
86635 +_002751_hash alloc_skb_fclone 1 3467 _002751_hash NULL
86636 +_002752_hash ata_scsi_change_queue_depth 2 23126 _002752_hash NULL
86637 +_002753_hash ath6kl_disconnect_timeout_write 3 794 _002753_hash NULL
86638 +_002754_hash ath6kl_keepalive_write 3 45600 _002754_hash NULL
86639 +_002755_hash ath6kl_lrssi_roam_write 3 8362 _002755_hash NULL
86640 +_002756_hash ath6kl_regread_write 3 14220 _002756_hash NULL
86641 +_002757_hash core_sys_select 1 47494 _002757_hash NULL
86642 +_002758_hash do_syslog 3 56807 _002758_hash NULL
86643 +_002759_hash expand_fdtable 2 39273 _002759_hash NULL
86644 +_002760_hash fd_execute_cmd 3 1132 _002760_hash NULL
86645 +_002761_hash get_chars 3 40373 _002761_hash NULL
86646 +_002762_hash hid_report_raw_event 4 2762 _002762_hash NULL
86647 +_002763_hash inet_csk_listen_start 2 38233 _002763_hash NULL
86648 +_002764_hash kstrtou32_from_user 2 30361 _002764_hash NULL
86649 +_002765_hash l2cap_segment_sdu 4 48772 _002765_hash &_002653_hash
86650 +_002766_hash __netdev_alloc_skb 2 18595 _002766_hash NULL
86651 +_002767_hash nfs_readdata_alloc 2 65015 _002767_hash NULL
86652 +_002768_hash nfs_writedata_alloc 2 12133 _002768_hash NULL
86653 +_002769_hash ntfs_rl_append 2-4 6037 _002769_hash NULL
86654 +_002771_hash ntfs_rl_insert 2-4 4931 _002771_hash NULL
86655 +_002773_hash ntfs_rl_replace 2-4 14136 _002773_hash NULL
86656 +_002775_hash ntfs_rl_split 2-4 52328 _002775_hash NULL
86657 +_002777_hash port_fops_read 3 49626 _002777_hash NULL
86658 +_002778_hash random_read 3 13815 _002778_hash NULL
86659 +_002779_hash sg_proc_write_adio 3 45704 _002779_hash NULL
86660 +_002780_hash sg_proc_write_dressz 3 46316 _002780_hash NULL
86661 +_002781_hash tcp_sendmsg 4 30296 _002781_hash NULL
86662 +_002782_hash tomoyo_write_log2 2 34318 _002782_hash NULL
86663 +_002783_hash ubi_leb_change 4 10289 _002783_hash NULL
86664 +_002784_hash ubi_leb_write 4-5 5478 _002784_hash NULL
86665 +_002786_hash urandom_read 3 30462 _002786_hash NULL
86666 +_002787_hash v9fs_cached_file_read 3 2514 _002787_hash NULL
86667 +_002788_hash __videobuf_alloc_cached 1 12740 _002788_hash NULL
86668 +_002789_hash __videobuf_alloc_uncached 1 55711 _002789_hash NULL
86669 +_002790_hash wm8350_block_write 3 19727 _002790_hash NULL
86670 +_002791_hash alloc_tx 2 32143 _002791_hash NULL
86671 +_002792_hash alloc_wr 1-2 24635 _002792_hash NULL
86672 +_002794_hash ath6kl_endpoint_stats_write 3 59621 _002794_hash NULL
86673 +_002795_hash ath6kl_fwlog_mask_write 3 24810 _002795_hash NULL
86674 +_002796_hash ath9k_wmi_cmd 4 327 _002796_hash NULL
86675 +_002797_hash atm_alloc_charge 2 19517 _002879_hash NULL nohasharray
86676 +_002798_hash ax25_output 2 22736 _002798_hash NULL
86677 +_002799_hash bcsp_prepare_pkt 3 12961 _002799_hash NULL
86678 +_002800_hash bt_skb_alloc 1 6404 _002800_hash NULL
86679 +_002801_hash capinc_tty_write 3 28539 _002801_hash NULL
86680 +_002802_hash cfpkt_create_pfx 1-2 23594 _002802_hash NULL
86681 +_002804_hash cmd_complete 6 51629 _002804_hash NULL
86682 +_002805_hash cmtp_add_msgpart 4 9252 _002805_hash NULL
86683 +_002806_hash cmtp_send_interopmsg 7 376 _002806_hash NULL
86684 +_002807_hash cxgb3_get_cpl_reply_skb 2 10620 _002807_hash NULL
86685 +_002808_hash dbg_leb_change 4 23555 _002808_hash NULL
86686 +_002809_hash dbg_leb_write 4-5 63555 _002809_hash &_000940_hash
86687 +_002811_hash dccp_listen_start 2 35918 _002811_hash NULL
86688 +_002812_hash __dev_alloc_skb 1 28681 _002812_hash NULL
86689 +_002813_hash diva_os_alloc_message_buffer 1 64568 _002813_hash NULL
86690 +_002814_hash dn_alloc_skb 2 6631 _002814_hash NULL
86691 +_002815_hash do_pselect 1 62061 _002815_hash NULL
86692 +_002816_hash _fc_frame_alloc 1 43568 _002816_hash NULL
86693 +_002817_hash find_skb 2 20431 _002817_hash NULL
86694 +_002818_hash fm_send_cmd 5 39639 _002818_hash NULL
86695 +_002819_hash gem_alloc_skb 2 51715 _002819_hash NULL
86696 +_002820_hash get_packet 3 41914 _002820_hash NULL
86697 +_002821_hash get_packet 3 5747 _002821_hash NULL
86698 +_002822_hash get_packet_pg 4 28023 _002822_hash NULL
86699 +_002823_hash get_skb 2 63008 _002823_hash NULL
86700 +_002824_hash hidp_queue_report 3 1881 _002824_hash NULL
86701 +_002825_hash __hidp_send_ctrl_message 4 28303 _002825_hash NULL
86702 +_002826_hash hycapi_rx_capipkt 3 11602 _002826_hash NULL
86703 +_002827_hash i2400m_net_rx 5 27170 _002827_hash NULL
86704 +_002828_hash igmpv3_newpack 2 35912 _002828_hash NULL
86705 +_002829_hash inet_listen 2 14723 _002829_hash NULL
86706 +_002830_hash isdn_net_ciscohdlck_alloc_skb 2 55209 _002830_hash &_001724_hash
86707 +_002831_hash isdn_ppp_ccp_xmit_reset 6 63297 _002831_hash NULL
86708 +_002832_hash kmsg_read 3 46514 _002832_hash NULL
86709 +_002833_hash _l2_alloc_skb 1 11883 _002833_hash NULL
86710 +_002834_hash l3_alloc_skb 1 32289 _002834_hash NULL
86711 +_002835_hash llc_alloc_frame 4 64366 _002835_hash NULL
86712 +_002836_hash mac_drv_rx_init 2 48898 _002836_hash &_002670_hash
86713 +_002837_hash mgmt_event 4 12810 _002837_hash NULL
86714 +_002838_hash mI_alloc_skb 1 24770 _002838_hash NULL
86715 +_002839_hash nci_skb_alloc 2 49757 _002839_hash NULL
86716 +_002840_hash netdev_alloc_skb 2 62437 _002840_hash NULL
86717 +_002841_hash __netdev_alloc_skb_ip_align 2 55067 _002841_hash NULL
86718 +_002842_hash new_skb 1 21148 _002842_hash NULL
86719 +_002843_hash nfc_alloc_recv_skb 1 10244 _002843_hash NULL
86720 +_002844_hash nfcwilink_skb_alloc 1 16167 _002844_hash NULL
86721 +_002845_hash nfulnl_alloc_skb 2 65207 _002845_hash NULL
86722 +_002846_hash ni65_alloc_mem 3 10664 _002846_hash NULL
86723 +_002847_hash pep_alloc_skb 3 46303 _002847_hash NULL
86724 +_002848_hash pn_raw_send 2 54330 _002848_hash NULL
86725 +_002849_hash __pskb_copy 2 9038 _002849_hash NULL
86726 +_002850_hash refill_pool 2 19477 _002850_hash NULL
86727 +_002851_hash rfcomm_wmalloc 2 58090 _002851_hash NULL
86728 +_002852_hash rx 4 57944 _002852_hash NULL
86729 +_002853_hash sctp_ulpevent_new 1 33377 _002853_hash NULL
86730 +_002854_hash send_command 4 10832 _002854_hash NULL
86731 +_002855_hash skb_copy_expand 2-3 7685 _002855_hash &_000671_hash
86732 +_002857_hash sk_stream_alloc_skb 2 57622 _002857_hash NULL
86733 +_002858_hash sock_alloc_send_pskb 2 21246 _002858_hash NULL
86734 +_002859_hash sock_rmalloc 2 59740 _002859_hash &_002157_hash
86735 +_002860_hash sock_wmalloc 2 16472 _002860_hash NULL
86736 +_002861_hash solos_param_store 4 34755 _002861_hash NULL
86737 +_002862_hash sys_select 1 38827 _002862_hash NULL
86738 +_002863_hash sys_syslog 3 10746 _002863_hash NULL
86739 +_002864_hash t4vf_pktgl_to_skb 2 39005 _002864_hash NULL
86740 +_002865_hash tcp_collapse 5-6 63294 _002865_hash NULL
86741 +_002867_hash tipc_cfg_reply_alloc 1 27606 _002867_hash NULL
86742 +_002868_hash ubifs_leb_change 4 17789 _002868_hash NULL
86743 +_002869_hash ubifs_leb_write 4-5 22679 _002869_hash NULL
86744 +_002871_hash ulog_alloc_skb 1 23427 _002871_hash NULL
86745 +_002872_hash _alloc_mISDN_skb 3 52232 _002872_hash NULL
86746 +_002873_hash ath9k_multi_regread 4 65056 _002873_hash NULL
86747 +_002874_hash ath_rxbuf_alloc 2 24745 _002874_hash NULL
86748 +_002875_hash ax25_send_frame 2 19964 _002875_hash NULL
86749 +_002876_hash bchannel_get_rxbuf 2 37213 _002876_hash NULL
86750 +_002877_hash cfpkt_create 1 18197 _002877_hash NULL
86751 +_002878_hash console_store 4 36007 _002878_hash NULL
86752 +_002879_hash dev_alloc_skb 1 19517 _002879_hash &_002797_hash
86753 +_002880_hash dn_nsp_do_disc 2-6 49474 _002880_hash NULL
86754 +_002882_hash do_write_orph_node 2 64343 _002882_hash NULL
86755 +_002883_hash dsp_cmx_send_member 2 15625 _002883_hash NULL
86756 +_002884_hash fc_frame_alloc 2 1596 _002884_hash NULL
86757 +_002885_hash fc_frame_alloc_fill 2 59394 _002885_hash NULL
86758 +_002886_hash fmc_send_cmd 5 20435 _002886_hash NULL
86759 +_002887_hash hci_send_cmd 3 43810 _002887_hash NULL
86760 +_002888_hash hci_si_event 3 1404 _002888_hash NULL
86761 +_002889_hash hfcpci_empty_bfifo 4 62323 _002889_hash NULL
86762 +_002890_hash hidp_send_ctrl_message 4 43702 _002890_hash NULL
86763 +_002891_hash hysdn_sched_rx 3 60533 _002891_hash NULL
86764 +_002892_hash inet_dccp_listen 2 28565 _002892_hash NULL
86765 +_002893_hash ip6_append_data 4-5 36490 _002893_hash NULL
86766 +_002894_hash __ip_append_data 7-8 36191 _002894_hash NULL
86767 +_002895_hash l1oip_socket_recv 6 56537 _002895_hash NULL
86768 +_002896_hash l2cap_build_cmd 4 48676 _002896_hash NULL
86769 +_002897_hash l2down_create 4 21755 _002897_hash NULL
86770 +_002898_hash l2up_create 3 6430 _002898_hash NULL
86771 +_002899_hash ldisc_receive 4 41516 _002899_hash NULL
86772 +_002902_hash lro_gen_skb 6 2644 _002902_hash NULL
86773 +_002903_hash macvtap_alloc_skb 2-4-3 50629 _002903_hash NULL
86774 +_002906_hash mgmt_device_found 10 14146 _002906_hash NULL
86775 +_002907_hash nci_send_cmd 3 58206 _002907_hash NULL
86776 +_002908_hash netdev_alloc_skb_ip_align 2 40811 _002908_hash NULL
86777 +_002909_hash nfcwilink_send_bts_cmd 3 10802 _002909_hash NULL
86778 +_002910_hash nfqnl_mangle 2 14583 _002910_hash NULL
86779 +_002911_hash p54_alloc_skb 3 34366 _002911_hash &_000475_hash
86780 +_002912_hash packet_alloc_skb 2-5-4 62602 _002912_hash NULL
86781 +_002915_hash pep_indicate 5 38611 _002915_hash NULL
86782 +_002916_hash pep_reply 5 50582 _002916_hash NULL
86783 +_002917_hash pipe_handler_request 5 50774 _002917_hash &_001189_hash
86784 +_002918_hash ql_process_mac_rx_page 4 15543 _002918_hash NULL
86785 +_002919_hash ql_process_mac_rx_skb 4 6689 _002919_hash NULL
86786 +_002920_hash rfcomm_tty_write 3 51603 _002920_hash NULL
86787 +_002921_hash send_mpa_reject 3 7135 _002921_hash NULL
86788 +_002922_hash send_mpa_reply 3 32372 _002922_hash NULL
86789 +_002923_hash set_rxd_buffer_pointer 8 9950 _002923_hash NULL
86790 +_002924_hash sge_rx 3 50594 _002924_hash NULL
86791 +_002925_hash skb_cow_data 2 11565 _002925_hash NULL
86792 +_002926_hash smp_build_cmd 3 45853 _002926_hash NULL
86793 +_002927_hash sock_alloc_send_skb 2 23720 _002927_hash NULL
86794 +_002928_hash sys_pselect6 1 57449 _002928_hash NULL
86795 +_002929_hash tcp_fragment 3 20436 _002929_hash NULL
86796 +_002930_hash teiup_create 3 43201 _002930_hash NULL
86797 +_002931_hash tg3_run_loopback 2 30093 _002931_hash NULL
86798 +_002932_hash tun_alloc_skb 2-4-3 41216 _002932_hash NULL
86799 +_002935_hash ubifs_write_node 5-3 11258 _002935_hash NULL
86800 +_002936_hash use_pool 2 64607 _002936_hash NULL
86801 +_002937_hash vxge_rx_alloc 3 52024 _002937_hash NULL
86802 +_002938_hash add_packet 3 54433 _002938_hash NULL
86803 +_002939_hash add_rx_skb 3 8257 _002939_hash NULL
86804 +_002940_hash ath6kl_buf_alloc 1 57304 _002940_hash NULL
86805 +_002941_hash bat_iv_ogm_aggregate_new 2 2620 _002941_hash NULL
86806 +_002942_hash bnx2fc_process_l2_frame_compl 3 65072 _002942_hash NULL
86807 +_002943_hash brcmu_pkt_buf_get_skb 1 5556 _002943_hash NULL
86808 +_002944_hash br_send_bpdu 3 29669 _002944_hash NULL
86809 +_002945_hash bt_skb_send_alloc 2 6581 _002945_hash NULL
86810 +_002946_hash c4iw_reject_cr 3 28174 _002946_hash NULL
86811 +_002947_hash carl9170_rx_copy_data 2 21656 _002947_hash NULL
86812 +_002948_hash cfpkt_add_body 3 44630 _002948_hash NULL
86813 +_002949_hash cfpkt_append 3 61206 _002949_hash NULL
86814 +_002950_hash cosa_net_setup_rx 2 38594 _002950_hash NULL
86815 +_002951_hash cxgb4_pktgl_to_skb 2 61899 _002951_hash NULL
86816 +_002952_hash dn_alloc_send_pskb 2 4465 _002952_hash NULL
86817 +_002953_hash dn_nsp_return_disc 2 60296 _002953_hash NULL
86818 +_002954_hash dn_nsp_send_disc 2 23469 _002954_hash NULL
86819 +_002955_hash dsp_tone_hw_message 3 17678 _002955_hash NULL
86820 +_002956_hash dvb_net_sec 3 37884 _002956_hash NULL
86821 +_002957_hash e1000_check_copybreak 3 62448 _002957_hash NULL
86822 +_002958_hash fast_rx_path 3 59214 _002958_hash NULL
86823 +_002959_hash fc_fcp_frame_alloc 2 12624 _002959_hash NULL
86824 +_002960_hash fcoe_ctlr_send_keep_alive 3 15308 _002960_hash NULL
86825 +_002961_hash fwnet_incoming_packet 3 40380 _002961_hash NULL
86826 +_002962_hash fwnet_pd_new 4 39947 _002962_hash NULL
86827 +_002963_hash got_frame 2 16028 _002963_hash NULL
86828 +_002964_hash gsm_mux_rx_netchar 3 33336 _002964_hash NULL
86829 +_002965_hash hdlcdev_rx 3 997 _002965_hash NULL
86830 +_002966_hash hdlc_empty_fifo 2 18397 _002966_hash NULL
86831 +_002967_hash hfc_empty_fifo 2 57972 _002967_hash NULL
86832 +_002968_hash hfcpci_empty_fifo 4 2427 _002968_hash NULL
86833 +_002969_hash hfcsusb_rx_frame 3 52745 _002969_hash NULL
86834 +_002970_hash hidp_output_raw_report 3 5629 _002970_hash NULL
86835 +_002971_hash hscx_empty_fifo 2 13360 _002971_hash NULL
86836 +_002972_hash hysdn_rx_netpkt 3 16136 _002972_hash NULL
86837 +_002973_hash ieee80211_fragment 4 33112 _002973_hash NULL
86838 +_002974_hash ieee80211_probereq_get 4-6 29069 _002974_hash NULL
86839 +_002976_hash ieee80211_send_auth 5 24121 _002976_hash NULL
86840 +_002977_hash ieee80211_set_probe_resp 3 10077 _002977_hash NULL
86841 +_002978_hash ieee80211_tdls_mgmt 8 9581 _002978_hash NULL
86842 +_002979_hash ip6_ufo_append_data 5-7-6 4780 _002979_hash NULL
86843 +_002982_hash ip_ufo_append_data 6-8-7 12775 _002982_hash NULL
86844 +_002985_hash ipw_packet_received_skb 2 1230 _002985_hash NULL
86845 +_002986_hash iwch_reject_cr 3 23901 _002986_hash NULL
86846 +_002987_hash iwm_rx_packet_alloc 3 9898 _002987_hash NULL
86847 +_002988_hash ixgb_check_copybreak 3 5847 _002988_hash NULL
86848 +_002989_hash l1oip_socket_parse 4 4507 _002989_hash NULL
86849 +_002990_hash l2cap_send_cmd 4 14548 _002990_hash NULL
86850 +_002991_hash l2tp_ip6_sendmsg 4 7461 _002991_hash NULL
86851 +_002993_hash lowpan_fragment_xmit 3-4 22095 _002993_hash NULL
86852 +_002996_hash mcs_unwrap_fir 3 25733 _002996_hash NULL
86853 +_002997_hash mcs_unwrap_mir 3 9455 _002997_hash NULL
86854 +_002998_hash mld_newpack 2 50950 _002998_hash NULL
86855 +_002999_hash nfc_alloc_send_skb 4 3167 _002999_hash NULL
86856 +_003000_hash p54_download_eeprom 4 43842 _003000_hash NULL
86857 +_003002_hash ppp_tx_cp 5 62044 _003002_hash NULL
86858 +_003003_hash prism2_send_mgmt 4 62605 _003003_hash &_001876_hash
86859 +_003004_hash prism2_sta_send_mgmt 5 43916 _003004_hash NULL
86860 +_003005_hash _queue_data 4 54983 _003005_hash NULL
86861 +_003006_hash read_dma 3 55086 _003006_hash NULL
86862 +_003007_hash read_fifo 3 826 _003007_hash NULL
86863 +_003008_hash receive_copy 3 12216 _003008_hash NULL
86864 +_003009_hash rtl8169_try_rx_copy 3 705 _003009_hash NULL
86865 +_003010_hash _rtl92s_firmware_downloadcode 3 14021 _003010_hash NULL
86866 +_003011_hash rx_data 4 60442 _003011_hash NULL
86867 +_003012_hash sis190_try_rx_copy 3 57069 _003012_hash NULL
86868 +_003013_hash skge_rx_get 3 40598 _003013_hash NULL
86869 +_003014_hash tcp_mark_head_lost 2 35895 _003014_hash NULL
86870 +_003015_hash tcp_match_skb_to_sack 3-4 23568 _003015_hash NULL
86871 +_003017_hash tso_fragment 3 29050 _003017_hash NULL
86872 +_003018_hash tt_response_fill_table 1 57902 _003018_hash NULL
86873 +_003020_hash udpv6_sendmsg 4 22316 _003020_hash NULL
86874 +_003021_hash velocity_rx_copy 2 34583 _003021_hash NULL
86875 +_003022_hash W6692_empty_Bfifo 2 47804 _003022_hash NULL
86876 +_003023_hash zd_mac_rx 3 38296 _003023_hash NULL
86877 +_003024_hash ath6kl_wmi_get_new_buf 1 52304 _003024_hash NULL
86878 +_003025_hash bat_iv_ogm_queue_add 3 30870 _003025_hash NULL
86879 +_003026_hash brcmf_alloc_pkt_and_read 2 63116 _003026_hash &_001808_hash
86880 +_003027_hash brcmf_sdcard_recv_buf 6 38179 _003027_hash NULL
86881 +_003028_hash brcmf_sdcard_rwdata 5 65041 _003028_hash NULL
86882 +_003029_hash brcmf_sdcard_send_buf 6 7713 _003029_hash NULL
86883 +_003030_hash carl9170_handle_mpdu 3 11056 _003030_hash NULL
86884 +_003031_hash cfpkt_add_trail 3 27260 _003031_hash NULL
86885 +_003032_hash cfpkt_pad_trail 2 55511 _003032_hash NULL
86886 +_003033_hash dvb_net_sec_callback 2 28786 _003033_hash NULL
86887 +_003034_hash fwnet_receive_packet 9 50537 _003034_hash NULL
86888 +_003035_hash handle_rx_packet 3 58993 _003035_hash NULL
86889 +_003036_hash HDLC_irq 2 8709 _003036_hash NULL
86890 +_003037_hash hdlc_rpr_irq 2 10240 _003037_hash NULL
86891 +_003043_hash ipwireless_network_packet_received 4 51277 _003043_hash NULL
86892 +_003044_hash l2cap_bredr_sig_cmd 3 49065 _003044_hash NULL
86893 +_003045_hash l2cap_sock_alloc_skb_cb 2 33532 _003045_hash NULL
86894 +_003046_hash llcp_allocate_pdu 3 19866 _003046_hash NULL
86895 +_003047_hash ppp_cp_event 6 2965 _003047_hash NULL
86896 +_003048_hash receive_client_update_packet 3 49104 _003048_hash NULL
86897 +_003049_hash receive_server_sync_packet 3 59021 _003049_hash NULL
86898 +_003050_hash sky2_receive 2 13407 _003050_hash NULL
86899 +_003051_hash tcp_sacktag_walk 5-6 49703 _003051_hash NULL
86900 +_003053_hash tcp_write_xmit 2 64602 _003053_hash NULL
86901 +_003054_hash ath6kl_wmi_add_wow_pattern_cmd 4 12842 _003054_hash NULL
86902 +_003055_hash ath6kl_wmi_beginscan_cmd 8 25462 _003055_hash NULL
86903 +_003056_hash ath6kl_wmi_send_probe_response_cmd 6 31728 _003056_hash NULL
86904 +_003057_hash ath6kl_wmi_set_appie_cmd 5 39266 _003057_hash NULL
86905 +_003058_hash ath6kl_wmi_set_ie_cmd 6 37260 _003058_hash NULL
86906 +_003059_hash ath6kl_wmi_startscan_cmd 8 33674 _003059_hash NULL
86907 +_003060_hash ath6kl_wmi_test_cmd 3 27312 _003060_hash NULL
86908 +_003061_hash brcmf_sdbrcm_membytes 3-5 37324 _003061_hash NULL
86909 +_003063_hash brcmf_sdbrcm_read_control 3 22721 _003063_hash NULL
86910 +_003064_hash brcmf_tx_frame 3 20978 _003064_hash NULL
86911 +_003065_hash __carl9170_rx 3 56784 _003065_hash NULL
86912 +_003066_hash cfpkt_setlen 2 49343 _003066_hash NULL
86913 +_003067_hash hdlc_irq_one 2 3944 _003067_hash NULL
86914 +_003069_hash tcp_push_one 2 48816 _003069_hash NULL
86915 +_003070_hash __tcp_push_pending_frames 2 48148 _003070_hash NULL
86916 +_003071_hash brcmf_sdbrcm_bus_txctl 3 42492 _003071_hash NULL
86917 +_003072_hash carl9170_rx 3 13272 _003072_hash NULL
86918 +_003073_hash carl9170_rx_stream 3 1334 _003073_hash NULL
86919 +_003074_hash tcp_push 3 10680 _003074_hash NULL
86920 +_003075_hash create_log 2 8225 _003075_hash NULL
86921 +_003076_hash expand_files 2 17080 _003076_hash NULL
86922 +_003077_hash iio_device_alloc 1 41440 _003077_hash NULL
86923 +_003078_hash OS_mem_token_alloc 1 14276 _003078_hash NULL
86924 +_003079_hash packet_came 3 18072 _003079_hash NULL
86925 +_003080_hash softsynth_write 3 3455 _003080_hash NULL
86926 +_003081_hash alloc_fd 1 37637 _003081_hash NULL
86927 +_003082_hash sys_dup3 2 33421 _003082_hash NULL
86928 +_003083_hash do_fcntl 3 31468 _003083_hash NULL
86929 +_003084_hash sys_dup2 2 25284 _003084_hash NULL
86930 +_003085_hash sys_fcntl 3 19267 _003085_hash NULL
86931 +_003086_hash sys_fcntl64 3 29031 _003086_hash NULL
86932 +_003087_hash cmpk_message_handle_tx 4 54024 _003087_hash NULL
86933 +_003088_hash comedi_buf_alloc 3 24822 _003088_hash NULL
86934 +_003089_hash compat_rw_copy_check_uvector 3 22001 _003089_hash &_001989_hash
86935 +_003090_hash compat_sys_fcntl64 3 60256 _003090_hash NULL
86936 +_003091_hash evtchn_write 3 43278 _003091_hash NULL
86937 +_003092_hash fw_download_code 3 13249 _003092_hash NULL
86938 +_003093_hash fwSendNullPacket 2 54618 _003093_hash NULL
86939 +_003095_hash ieee80211_authentication_req 3 63973 _003095_hash NULL
86940 +_003097_hash rtllib_authentication_req 3 26713 _003097_hash NULL
86941 +_003098_hash SendTxCommandPacket 3 42901 _003098_hash NULL
86942 +_003099_hash snd_nm256_capture_copy 5 28622 _003099_hash NULL
86943 +_003100_hash snd_nm256_playback_copy 5 38567 _003100_hash NULL
86944 +_003101_hash tomoyo_init_log 2 14806 _003101_hash NULL
86945 +_003102_hash usbdux_attach_common 4 51764 _003271_hash NULL nohasharray
86946 +_003103_hash compat_sys_fcntl 3 15654 _003103_hash NULL
86947 +_003104_hash ieee80211_auth_challenge 3 18810 _003104_hash NULL
86948 +_003105_hash ieee80211_rtl_auth_challenge 3 61897 _003105_hash NULL
86949 +_003106_hash resize_async_buffer 4 64031 _003106_hash &_002119_hash
86950 +_003107_hash rtllib_auth_challenge 3 12493 _003107_hash NULL
86951 +_003108_hash tomoyo_write_log2 2 11732 _003108_hash NULL
86952 +_003109_hash allocate_probes 1 40204 _003109_hash NULL
86953 +_003110_hash alloc_ftrace_hash 1 57431 _003110_hash &_002532_hash
86954 +_003111_hash __alloc_preds 2 9492 _003111_hash NULL
86955 +_003112_hash __alloc_pred_stack 2 26687 _003112_hash NULL
86956 +_003113_hash alloc_sched_domains 1 47756 _003113_hash NULL
86957 +_003114_hash alloc_trace_probe 6 38720 _003114_hash NULL
86958 +_003115_hash alloc_trace_uprobe 3 13870 _003850_hash NULL nohasharray
86959 +_003116_hash arcfb_write 3 8702 _003116_hash NULL
86960 +_003117_hash ath6kl_sdio_alloc_prep_scat_req 2 51986 _003117_hash NULL
86961 +_003118_hash ath6kl_usb_post_recv_transfers 2 32892 _003118_hash NULL
86962 +_003119_hash ath6kl_usb_submit_ctrl_in 6 32880 _003119_hash &_000778_hash
86963 +_003120_hash ath6kl_usb_submit_ctrl_out 6 9978 _003120_hash NULL
86964 +_003121_hash auok190xfb_write 3 37001 _003121_hash NULL
86965 +_003122_hash beacon_interval_write 3 17952 _003122_hash NULL
86966 +_003123_hash blk_dropped_read 3 4168 _003123_hash NULL
86967 +_003124_hash blk_msg_write 3 13655 _003124_hash NULL
86968 +_003125_hash brcmf_usbdev_qinit 2 19090 _003125_hash &_001533_hash
86969 +_003126_hash brcmf_usb_dl_cmd 4 53130 _003126_hash NULL
86970 +_003127_hash broadsheetfb_write 3 39976 _003127_hash NULL
86971 +_003128_hash broadsheet_spiflash_rewrite_sector 2 54864 _003128_hash NULL
86972 +_003129_hash cyttsp_probe 4 1940 _003129_hash NULL
86973 +_003130_hash da9052_group_write 3 4534 _003130_hash NULL
86974 +_003131_hash dccpprobe_read 3 52549 _003131_hash NULL
86975 +_003132_hash drm_property_create_bitmask 5 30195 _003132_hash NULL
86976 +_003133_hash dtim_interval_write 3 30489 _003133_hash NULL
86977 +_003134_hash dynamic_ps_timeout_write 3 37713 _003134_hash NULL
86978 +_003135_hash event_enable_read 3 7074 _003135_hash NULL
86979 +_003136_hash event_enable_write 3 45238 _003136_hash NULL
86980 +_003137_hash event_filter_read 3 23494 _003137_hash NULL
86981 +_003138_hash event_filter_write 3 56609 _003138_hash NULL
86982 +_003139_hash event_id_read 3 64288 _003139_hash &_001240_hash
86983 +_003140_hash f_audio_buffer_alloc 1 41110 _003140_hash NULL
86984 +_003141_hash fb_sys_read 3 13778 _003141_hash NULL
86985 +_003142_hash fb_sys_write 3 33130 _003142_hash NULL
86986 +_003143_hash forced_ps_write 3 37209 _003143_hash NULL
86987 +_003144_hash __fprog_create 2 41263 _003144_hash NULL
86988 +_003145_hash fq_codel_zalloc 1 15378 _003145_hash NULL
86989 +_003146_hash ftrace_pid_write 3 39710 _003146_hash NULL
86990 +_003147_hash ftrace_profile_read 3 21327 _003147_hash NULL
86991 +_003148_hash ftrace_profile_write 3 53327 _003148_hash NULL
86992 +_003149_hash ftrace_write 3 29551 _003149_hash NULL
86993 +_003150_hash gdm_wimax_netif_rx 3 43423 _003150_hash &_001619_hash
86994 +_003151_hash gpio_power_write 3 1991 _003151_hash NULL
86995 +_003152_hash hecubafb_write 3 26942 _003152_hash NULL
86996 +_003153_hash hsc_msg_alloc 1 60990 _003153_hash NULL
86997 +_003154_hash hsc_write 3 55875 _003154_hash NULL
86998 +_003155_hash hsi_alloc_controller 1 41802 _003155_hash NULL
86999 +_003156_hash hsi_register_board_info 2 13820 _003156_hash NULL
87000 +_003157_hash i915_ring_stop_read 3 42549 _003406_hash NULL nohasharray
87001 +_003158_hash i915_ring_stop_write 3 59010 _003158_hash NULL
87002 +_003159_hash ieee802154_alloc_device 1 13767 _003159_hash NULL
87003 +_003160_hash intel_sdvo_write_cmd 4 54377 _003160_hash &_000815_hash
87004 +_003161_hash ivtvfb_write 3 40023 _003161_hash NULL
87005 +_003162_hash metronomefb_write 3 8823 _003162_hash NULL
87006 +_003163_hash mwifiex_usb_submit_rx_urb 2 54558 _003163_hash NULL
87007 +_003164_hash nfc_hci_hcp_message_tx 6 14534 _003164_hash NULL
87008 +_003165_hash nfc_hci_set_param 5 40697 _003165_hash NULL
87009 +_003166_hash nfc_shdlc_alloc_skb 2 12741 _003166_hash NULL
87010 +_003167_hash odev_update 2 50169 _003167_hash NULL
87011 +_003168_hash oz_add_farewell 5 20652 _003168_hash NULL
87012 +_003169_hash oz_cdev_read 3 20659 _003169_hash NULL
87013 +_003170_hash oz_cdev_write 3 33852 _003170_hash NULL
87014 +_003171_hash oz_ep_alloc 2 5587 _003171_hash NULL
87015 +_003172_hash oz_events_read 3 47535 _003172_hash NULL
87016 +_003173_hash pmcraid_copy_sglist 3 38431 _003173_hash NULL
87017 +_003174_hash prctl_set_mm 3 64538 _003174_hash NULL
87018 +_003175_hash ptp_filter_init 2 36780 _003175_hash NULL
87019 +_003176_hash rb_simple_read 3 45972 _003176_hash NULL
87020 +_003177_hash rb_simple_write 3 20890 _003177_hash NULL
87021 +_003178_hash read_file_dfs 3 43145 _003178_hash NULL
87022 +_003179_hash rx_streaming_always_write 3 32357 _003436_hash NULL nohasharray
87023 +_003180_hash rx_streaming_interval_write 3 50120 _003180_hash NULL
87024 +_003181_hash shmem_pread_fast 3 34147 _003181_hash NULL
87025 +_003182_hash shmem_pread_slow 3 3198 _003182_hash NULL
87026 +_003183_hash shmem_pwrite_fast 3 46842 _003183_hash NULL
87027 +_003184_hash shmem_pwrite_slow 3 31741 _003184_hash NULL
87028 +_003185_hash show_header 3 4722 _003185_hash &_000736_hash
87029 +_003186_hash split_scan_timeout_write 3 52128 _003186_hash NULL
87030 +_003187_hash stack_max_size_read 3 1445 _003187_hash NULL
87031 +_003188_hash stack_max_size_write 3 36068 _003188_hash NULL
87032 +_003189_hash subsystem_filter_read 3 62310 _003189_hash NULL
87033 +_003190_hash subsystem_filter_write 3 13022 _003190_hash NULL
87034 +_003191_hash suspend_dtim_interval_write 3 48854 _003191_hash NULL
87035 +_003192_hash system_enable_read 3 25815 _003192_hash NULL
87036 +_003193_hash system_enable_write 3 61396 _003193_hash NULL
87037 +_003194_hash trace_options_core_read 3 47390 _003194_hash NULL
87038 +_003195_hash trace_options_core_write 3 61551 _003195_hash NULL
87039 +_003196_hash trace_options_read 3 11419 _003196_hash NULL
87040 +_003197_hash trace_options_write 3 48275 _003197_hash NULL
87041 +_003198_hash trace_parser_get_init 2 31379 _003198_hash NULL
87042 +_003199_hash traceprobe_probes_write 3 64969 _003199_hash NULL
87043 +_003200_hash trace_seq_to_user 3 65398 _003200_hash NULL
87044 +_003201_hash tracing_buffers_read 3 11124 _003201_hash NULL
87045 +_003202_hash tracing_clock_write 3 27961 _003202_hash NULL
87046 +_003203_hash tracing_cpumask_read 3 7010 _003203_hash NULL
87047 +_003204_hash tracing_ctrl_read 3 46922 _003204_hash NULL
87048 +_003205_hash tracing_ctrl_write 3 42324 _003205_hash &_001726_hash
87049 +_003206_hash tracing_entries_read 3 8345 _003206_hash NULL
87050 +_003207_hash tracing_entries_write 3 60563 _003207_hash NULL
87051 +_003208_hash tracing_max_lat_read 3 8890 _003208_hash NULL
87052 +_003209_hash tracing_max_lat_write 3 8728 _003209_hash NULL
87053 +_003210_hash tracing_read_dyn_info 3 45468 _003210_hash NULL
87054 +_003211_hash tracing_readme_read 3 16493 _003211_hash NULL
87055 +_003212_hash tracing_saved_cmdlines_read 3 21434 _003212_hash NULL
87056 +_003213_hash tracing_set_trace_read 3 44122 _003213_hash NULL
87057 +_003214_hash tracing_set_trace_write 3 57096 _003214_hash NULL
87058 +_003215_hash tracing_stats_read 3 34537 _003215_hash NULL
87059 +_003216_hash tracing_total_entries_read 3 62817 _003216_hash NULL
87060 +_003217_hash tracing_trace_options_write 3 153 _003217_hash NULL
87061 +_003218_hash ttm_put_pages 2 9179 _003218_hash NULL
87062 +_003219_hash udl_prime_create 2 57159 _003219_hash NULL
87063 +_003220_hash ufx_alloc_urb_list 3 10349 _003220_hash NULL
87064 +_003221_hash u_memcpya 2-3 30139 _003221_hash NULL
87065 +_003223_hash viafb_dfph_proc_write 3 49288 _003223_hash NULL
87066 +_003224_hash viafb_dfpl_proc_write 3 627 _003224_hash NULL
87067 +_003225_hash viafb_dvp0_proc_write 3 23023 _003225_hash NULL
87068 +_003226_hash viafb_dvp1_proc_write 3 48864 _003226_hash NULL
87069 +_003227_hash viafb_vt1636_proc_write 3 16018 _003227_hash NULL
87070 +_003228_hash vivi_read 3 23073 _003228_hash NULL
87071 +_003229_hash wl1271_rx_filter_alloc_field 5 46721 _003229_hash NULL
87072 +_003230_hash wl12xx_cmd_build_probe_req 6-8 3098 _003230_hash NULL
87073 +_003232_hash wlcore_alloc_hw 1 7785 _003232_hash NULL
87074 +_003233_hash alloc_and_copy_ftrace_hash 1 29368 _003233_hash NULL
87075 +_003234_hash create_trace_probe 1 20175 _003234_hash NULL
87076 +_003235_hash create_trace_uprobe 1 13184 _003235_hash NULL
87077 +_003236_hash intel_sdvo_set_value 4 2311 _003236_hash NULL
87078 +_003237_hash mmio_read 4 40348 _003237_hash NULL
87079 +_003238_hash nfc_hci_execute_cmd 5 43882 _003238_hash NULL
87080 +_003239_hash nfc_hci_send_event 5 21452 _003239_hash NULL
87081 +_003240_hash nfc_hci_send_response 5 56462 _003240_hash NULL
87082 +_003241_hash picolcd_fb_write 3 2318 _003241_hash NULL
87083 +_003242_hash probes_write 3 29711 _003242_hash NULL
87084 +_003243_hash sys_prctl 4 8766 _003243_hash NULL
87085 +_003244_hash tracing_read_pipe 3 35312 _003244_hash NULL
87086 +_003245_hash brcmf_usb_attach 1-2 44656 _003245_hash NULL
87087 +_003247_hash dlfb_ops_write 3 64150 _003247_hash NULL
87088 +_003248_hash nfc_hci_send_cmd 5 55714 _003248_hash NULL
87089 +_003249_hash ufx_ops_write 3 54848 _003249_hash NULL
87090 +_003250_hash viafb_iga1_odev_proc_write 3 36241 _003250_hash NULL
87091 +_003251_hash viafb_iga2_odev_proc_write 3 2363 _003251_hash NULL
87092 +_003252_hash xenfb_write 3 43412 _003252_hash NULL
87093 +_003253_hash acl_alloc 1 35979 _003253_hash NULL
87094 +_003254_hash acl_alloc_stack_init 1 60630 _003254_hash NULL
87095 +_003255_hash acl_alloc_num 1-2 60778 _003255_hash NULL
87096 +_003257_hash padzero 1 55 _003257_hash &_002013_hash
87097 +_003258_hash __get_vm_area_node 1 55305 _003258_hash NULL
87098 +_003259_hash get_vm_area 1 18080 _003259_hash NULL
87099 +_003260_hash __get_vm_area 1 61599 _003260_hash NULL
87100 +_003261_hash get_vm_area_caller 1 10527 _003261_hash NULL
87101 +_003262_hash __get_vm_area_caller 1 56416 _003302_hash NULL nohasharray
87102 +_003263_hash alloc_vm_area 1 36149 _003263_hash NULL
87103 +_003264_hash __ioremap_caller 1-2 21800 _003264_hash NULL
87104 +_003266_hash vmap 2 15025 _003266_hash NULL
87105 +_003267_hash ioremap_cache 1-2 47189 _003267_hash NULL
87106 +_003269_hash ioremap_nocache 1-2 2439 _003269_hash NULL
87107 +_003271_hash ioremap_prot 1-2 51764 _003271_hash &_003102_hash
87108 +_003273_hash ioremap_wc 1-2 62695 _003273_hash NULL
87109 +_003274_hash acpi_os_ioremap 1-2 49523 _003274_hash NULL
87110 +_003276_hash ca91cx42_alloc_resource 2 10502 _003276_hash NULL
87111 +_003277_hash devm_ioremap_nocache 2-3 2036 _003277_hash NULL
87112 +_003279_hash __einj_error_trigger 1 17707 _003279_hash &_001577_hash
87113 +_003280_hash io_mapping_map_wc 2 19284 _003280_hash NULL
87114 +_003281_hash ioremap 1-2 23172 _003281_hash NULL
87115 +_003283_hash lguest_map 1-2 42008 _003283_hash NULL
87116 +_003285_hash msix_map_region 3 3411 _003285_hash NULL
87117 +_003286_hash pci_iomap 3 47575 _003286_hash NULL
87118 +_003287_hash sfi_map_memory 1-2 5183 _003287_hash NULL
87119 +_003289_hash tsi148_alloc_resource 2 24563 _003289_hash NULL
87120 +_003290_hash vb2_vmalloc_get_userptr 3 31374 _003290_hash NULL
87121 +_003291_hash xlate_dev_mem_ptr 1 15291 _003291_hash &_001167_hash
87122 +_003292_hash a4t_cs_init 3 27734 _003292_hash NULL
87123 +_003293_hash aac_nark_ioremap 2 50163 _003293_hash &_000314_hash
87124 +_003294_hash aac_rkt_ioremap 2 3333 _003294_hash NULL
87125 +_003295_hash aac_rx_ioremap 2 52410 _003295_hash NULL
87126 +_003296_hash aac_sa_ioremap 2 13596 _003296_hash &_000288_hash
87127 +_003297_hash aac_src_ioremap 2 41688 _003297_hash NULL
87128 +_003298_hash aac_srcv_ioremap 2 6659 _003298_hash NULL
87129 +_003299_hash acpi_map 1-2 58725 _003299_hash NULL
87130 +_003301_hash acpi_os_read_memory 1-3 54186 _003301_hash NULL
87131 +_003302_hash acpi_os_write_memory 1-3 56416 _003302_hash &_003262_hash
87132 +_003303_hash c101_run 2 37279 _003303_hash NULL
87133 +_003304_hash ca91cx42_master_set 4 23146 _003304_hash NULL
87134 +_003305_hash check586 2 29914 _003305_hash NULL
87135 +_003306_hash check_mirror 1-2 57342 _003306_hash &_001564_hash
87136 +_003308_hash cru_detect 1 11272 _003308_hash NULL
87137 +_003309_hash cs553x_init_one 3 58886 _003309_hash NULL
87138 +_003310_hash cycx_setup 4 47562 _003310_hash NULL
87139 +_003311_hash DepcaSignature 2 80 _003311_hash &_001321_hash
87140 +_003312_hash devm_ioremap 2-3 29235 _003312_hash NULL
87141 +_003314_hash divasa_remap_pci_bar 3-4 23485 _003314_hash &_000947_hash
87142 +_003316_hash dma_declare_coherent_memory 2-4 14244 _003316_hash NULL
87143 +_003318_hash doc_probe 1 23285 _003318_hash NULL
87144 +_003319_hash DoC_Probe 1 57534 _003319_hash NULL
87145 +_003320_hash ems_pcmcia_add_card 2 62627 _003320_hash NULL
87146 +_003321_hash gdth_init_isa 1 28091 _003321_hash NULL
87147 +_003322_hash gdth_search_isa 1 58595 _003322_hash NULL
87148 +_003323_hash isp1760_register 1-2 628 _003323_hash NULL
87149 +_003325_hash mthca_map_reg 2-3 5664 _003325_hash NULL
87150 +_003327_hash n2_run 3 53459 _003327_hash NULL
87151 +_003328_hash pcim_iomap 3 58334 _003328_hash NULL
87152 +_003329_hash probe_bios 1 17467 _003329_hash NULL
87153 +_003330_hash register_device 2-3 60015 _003330_hash NULL
87154 +_003332_hash remap_pci_mem 1-2 15966 _003332_hash NULL
87155 +_003334_hash rtl_port_map 1-2 2385 _003334_hash NULL
87156 +_003336_hash sfi_map_table 1 5462 _003336_hash NULL
87157 +_003337_hash sriov_enable_migration 2 14889 _003337_hash NULL
87158 +_003338_hash ssb_bus_scan 2 36578 _003338_hash NULL
87159 +_003339_hash ssb_ioremap 2 5228 _003339_hash NULL
87160 +_003340_hash tpm_tis_init 2-3 15304 _003340_hash NULL
87161 +_003342_hash tsi148_master_set 4 14685 _003342_hash NULL
87162 +_003343_hash acpi_os_map_memory 1-2 11161 _003343_hash NULL
87163 +_003345_hash com90xx_found 3 13974 _003345_hash NULL
87164 +_003346_hash dmam_declare_coherent_memory 2-4 43679 _003346_hash NULL
87165 +_003348_hash gdth_isa_probe_one 1 48925 _003348_hash NULL
87166 +_003349_hash sfi_check_table 1 6772 _003349_hash NULL
87167 +_003350_hash sfi_sysfs_install_table 1 51688 _003350_hash NULL
87168 +_003351_hash sriov_enable 2 59689 _003351_hash NULL
87169 +_003352_hash ssb_bus_register 3 65183 _003352_hash NULL
87170 +_003353_hash acpi_ex_system_memory_space_handler 2 31192 _003353_hash NULL
87171 +_003354_hash acpi_tb_check_xsdt 1 21862 _003354_hash NULL
87172 +_003355_hash acpi_tb_install_table 1 12988 _003355_hash NULL
87173 +_003356_hash acpi_tb_parse_root_table 1 53455 _003356_hash NULL
87174 +_003357_hash check_vendor_extension 1 3254 _003357_hash NULL
87175 +_003358_hash pci_enable_sriov 2 35745 _003358_hash NULL
87176 +_003359_hash ssb_bus_pcmciabus_register 3 56020 _003359_hash NULL
87177 +_003360_hash ssb_bus_ssbbus_register 2 2217 _003360_hash NULL
87178 +_003361_hash lpfc_sli_probe_sriov_nr_virtfn 2 26004 _003361_hash NULL
87179 +_003364_hash alloc_vm_area 1 15989 _003364_hash NULL
87180 +_003366_hash efi_ioremap 1-2 3492 _003366_hash &_001092_hash
87181 +_003368_hash init_chip_wc_pat 2 62768 _003368_hash NULL
87182 +_003369_hash io_mapping_create_wc 1-2 1354 _003369_hash NULL
87183 +_003371_hash iommu_map_mmio_space 1 30919 _003371_hash NULL
87184 +_003372_hash arch_gnttab_map_shared 3 41306 _003372_hash NULL
87185 +_003373_hash arch_gnttab_map_status 3 49812 _003373_hash NULL
87186 +_003374_hash intel_render_ring_init_dri 2-3 45446 _003374_hash NULL
87187 +_003376_hash persistent_ram_iomap 1-2 47156 _003376_hash NULL
87188 +_003378_hash sparse_early_usemaps_alloc_pgdat_section 2 62304 _003378_hash NULL
87189 +_003379_hash ttm_bo_ioremap 2-3 31082 _003379_hash NULL
87190 +_003381_hash ttm_bo_kmap_ttm 3 5922 _003381_hash NULL
87191 +_003382_hash atyfb_setup_generic 3 49151 _003382_hash NULL
87192 +_003383_hash do_test 1 15766 _003383_hash NULL
87193 +_003384_hash mga_ioremap 1-2 8571 _003384_hash NULL
87194 +_003386_hash mid_get_vbt_data_r0 2 10876 _003386_hash NULL
87195 +_003387_hash mid_get_vbt_data_r10 2 6308 _003387_hash NULL
87196 +_003388_hash mid_get_vbt_data_r1 2 26170 _003388_hash NULL
87197 +_003389_hash persistent_ram_buffer_map 1-2 11332 _003389_hash NULL
87198 +_003391_hash read_vbt_r0 1 503 _003391_hash NULL
87199 +_003392_hash read_vbt_r10 1 60679 _003392_hash NULL
87200 +_003393_hash tpci200_slot_map_space 2 3848 _003393_hash NULL
87201 +_003394_hash ttm_bo_kmap 2-3 60118 _003394_hash NULL
87202 +_003395_hash persistent_ram_new 1-2 14588 _003395_hash NULL
87203 +_003396_hash mpt_lan_receive_post_turbo 2 13592 _003396_hash NULL
87204 +_003397_hash v4l2_ctrl_new_int_menu 4 41151 _003397_hash NULL
87205 +_003398_hash v4l2_ctrl_new_std 5 45748 _003398_hash &_002699_hash
87206 +_003399_hash v4l2_ctrl_new_std_menu 4 6221 _003399_hash NULL
87207 +_003400_hash xhci_alloc_streams 5 37586 _003400_hash NULL
87208 +_003401_hash cx2341x_ctrl_new_menu 3 49700 _003401_hash NULL
87209 +_003402_hash cx2341x_ctrl_new_std 4 57061 _003402_hash NULL
87210 +_003405_hash _alloc_get_attr_desc 2 470 _003405_hash NULL
87211 +_003406_hash ath6kl_wmi_proc_events_vif 5 42549 _003406_hash &_003157_hash
87212 +_003407_hash bitmap_resize 2 33054 _003407_hash NULL
87213 +_003408_hash bitmap_storage_alloc 2 55077 _003408_hash NULL
87214 +_003411_hash bnx2fc_process_unsol_compl 2 15576 _003411_hash NULL
87215 +_003413_hash btmrvl_sdio_host_to_card 3 12152 _003413_hash NULL
87216 +_003415_hash btrfs_error_discard_extent 2 50444 _003415_hash NULL
87217 +_003416_hash btrfsic_cmp_log_and_dev_bytenr 2 49628 _003416_hash NULL
87218 +_003417_hash c4iw_id_table_alloc 3 48163 _003417_hash NULL
87219 +_003418_hash cache_read_pipefs 3 47615 _003418_hash NULL
87220 +_003419_hash cache_read_procfs 3 52882 _003419_hash NULL
87221 +_003420_hash cache_write_pipefs 3 48270 _003420_hash NULL
87222 +_003421_hash cache_write_procfs 3 22491 _003421_hash NULL
87223 +_003425_hash cfpkt_split 2 47541 _003425_hash NULL
87224 +_003426_hash cgroup_file_read 3 28804 _003426_hash NULL
87225 +_003427_hash cgroup_file_write 3 52417 _003427_hash NULL
87226 +_003428_hash cnic_init_id_tbl 2 41354 _003428_hash NULL
87227 +_003430_hash copy_nodes_to_user 2 63807 _003430_hash NULL
87228 +_003431_hash cp210x_get_config 4 56229 _003431_hash NULL
87229 +_003432_hash cp210x_set_config 4 46447 _003432_hash NULL
87230 +_003433_hash cx18_v4l2_read 3 21196 _003433_hash NULL
87231 +_003434_hash dccp_setsockopt 5 60367 _003434_hash NULL
87232 +_003435_hash ddp_ppod_write_idata 5 25610 _003435_hash NULL
87233 +_003436_hash dispatch_ioctl 2 32357 _003436_hash &_003179_hash
87234 +_003437_hash dn_setsockopt 5 314 _003437_hash &_001817_hash
87235 +_003438_hash dt3155_alloc_coherent 2 58073 _003438_hash NULL
87236 +_003439_hash dvb_ca_write 3 41171 _003439_hash NULL
87237 +_003440_hash dvb_demux_read 3 13981 _003440_hash NULL
87238 +_003441_hash dvb_dmxdev_read_sec 4 7892 _003441_hash NULL
87239 +_003442_hash dvb_dvr_read 3 17073 _003442_hash NULL
87240 +_003443_hash dvb_usercopy 2 14036 _003443_hash NULL
87241 +_003445_hash evdev_do_ioctl 2 24459 _003445_hash NULL
87242 +_003446_hash fc_host_post_vendor_event 3 30903 _003446_hash NULL
87243 +_003447_hash fix_unclean_leb 3 23188 _003447_hash NULL
87244 +_003448_hash fs_devrw_entry 3 11924 _003448_hash NULL
87245 +_003449_hash fuse_conn_congestion_threshold_read 3 51028 _003449_hash NULL
87246 +_003450_hash fuse_conn_congestion_threshold_write 3 43736 _003450_hash NULL
87247 +_003451_hash fuse_conn_max_background_read 3 10855 _003451_hash NULL
87248 +_003452_hash fuse_conn_max_background_write 3 50061 _003452_hash NULL
87249 +_003453_hash fuse_fill_write_pages 4 53682 _003453_hash NULL
87250 +_003454_hash generic_perform_write 3 54832 _003454_hash NULL
87251 +_003455_hash gen_pool_add_virt 4 39913 _003455_hash NULL
87252 +_003456_hash get_info 3 55681 _003456_hash NULL
87253 +_003457_hash get_nodes 3 39012 _003457_hash NULL
87254 +_003458_hash groups_alloc 1 7614 _003458_hash NULL
87255 +_003459_hash hiddev_ioctl 2 36816 _003459_hash NULL
87256 +_003460_hash hidraw_ioctl 2 63658 _003460_hash NULL
87257 +_003461_hash hidraw_write 3 31536 _003461_hash NULL
87258 +_003462_hash ide_core_cp_entry 3 22636 _003462_hash NULL
87259 +_003463_hash ieee80211_amsdu_to_8023s 5 15561 _003463_hash NULL
87260 +_003464_hash ieee80211_if_write_smps 3 35550 _003464_hash NULL
87261 +_003465_hash ieee80211_if_write_tkip_mic_test 3 58748 _003465_hash NULL
87262 +_003466_hash ieee80211_if_write_tsf 3 36077 _003466_hash NULL
87263 +_003467_hash ieee80211_if_write_uapsd_max_sp_len 3 14233 _003467_hash NULL
87264 +_003468_hash ieee80211_if_write_uapsd_queues 3 51526 _003468_hash NULL
87265 +_003469_hash if_spi_host_to_card 4 62890 _003469_hash NULL
87266 +_003470_hash intel_fake_agp_alloc_by_type 1 1 _003470_hash NULL
87267 +_003471_hash int_hardware_entry 3 36833 _003471_hash NULL
87268 +_003472_hash int_hw_irq_en 3 46776 _003472_hash NULL
87269 +_003473_hash int_tasklet_entry 3 52500 _003473_hash NULL
87270 +_003474_hash ip_append_data 5-6 16942 _003474_hash NULL
87271 +_003476_hash ip_make_skb 5-6 13129 _003476_hash NULL
87272 +_003478_hash ip_options_get_alloc 1 7448 _003478_hash NULL
87273 +_003479_hash ip_setsockopt 5 33487 _003479_hash NULL
87274 +_003480_hash ipv6_setsockopt 5 29871 _003480_hash NULL
87275 +_003481_hash iscsi_if_send_reply 7 52219 _003481_hash NULL
87276 +_003482_hash iscsi_offload_mesg 5 58425 _003482_hash NULL
87277 +_003483_hash iscsi_ping_comp_event 5 38263 _003483_hash NULL
87278 +_003484_hash iscsi_post_host_event 4 13473 _003484_hash NULL
87279 +_003485_hash iscsi_recv_pdu 4 16755 _003485_hash NULL
87280 +_003487_hash ivtv_v4l2_read 3 1964 _003487_hash NULL
87281 +_003488_hash joydev_ioctl_common 2 49359 _003488_hash NULL
87282 +_003489_hash lbs_bcnmiss_read 3 8678 _003489_hash NULL
87283 +_003490_hash lbs_failcount_read 3 31063 _003490_hash NULL
87284 +_003491_hash lbs_highrssi_read 3 64089 _003491_hash NULL
87285 +_003492_hash lbs_highsnr_read 3 5931 _003492_hash NULL
87286 +_003493_hash lbs_lowrssi_read 3 32242 _003493_hash NULL
87287 +_003494_hash lbs_lowsnr_read 3 29571 _003494_hash NULL
87288 +_003495_hash load_module 2 60056 _003495_hash &_002482_hash
87289 +_003496_hash logger_read 3 59607 _003496_hash NULL
87290 +_003497_hash mem_swapout_entry 3 32586 _003497_hash NULL
87291 +_003498_hash mlx4_init_icm_table 4-5 2151 _003498_hash NULL
87292 +_003501_hash mon_bin_ioctl 3 2771 _003501_hash NULL
87293 +_003502_hash mpi_set_buffer 3 65294 _003502_hash NULL
87294 +_003503_hash __mptctl_ioctl 2 15875 _003503_hash NULL
87295 +_003504_hash mthca_alloc_icm_table 3-4 38268 _003504_hash &_002129_hash
87296 +_003506_hash mthca_alloc_init 2 21754 _003506_hash NULL
87297 +_003507_hash mthca_array_init 2 39987 _003507_hash NULL
87298 +_003508_hash mthca_buf_alloc 2 35861 _003508_hash NULL
87299 +_003509_hash mthca_setup_cmd_doorbells 2 53954 _003509_hash NULL
87300 +_003510_hash __netlink_change_ngroups 2 46156 _003510_hash NULL
87301 +_003511_hash netlink_kernel_create 3 18110 _003511_hash NULL
87302 +_003512_hash netpoll_send_udp 3 58955 _003512_hash NULL
87303 +_003513_hash netxen_nic_map_indirect_address_128M 2 42257 _003513_hash NULL
87304 +_003514_hash nfs4_alloc_pages 1 48426 _003514_hash NULL
87305 +_003515_hash nfsd_read 5 19568 _003515_hash NULL
87306 +_003516_hash nfsd_read_file 6 62241 _003516_hash NULL
87307 +_003517_hash nfsd_write 6 54809 _003517_hash NULL
87308 +_003519_hash nvme_map_user_pages 3-4 41093 _003519_hash &_001486_hash
87309 +_003523_hash osd_req_read_sg_kern 5 6378 _003523_hash NULL
87310 +_003524_hash osd_req_write_sg_kern 5 10514 _003524_hash NULL
87311 +_003525_hash osst_read 3 40237 _003525_hash NULL
87312 +_003526_hash p54_parse_rssical 3 64493 _003526_hash NULL
87313 +_003527_hash p9_client_zc_rpc 7 14345 _003527_hash NULL
87314 +_003528_hash pcpu_alloc_alloc_info 1-2 45813 _003528_hash NULL
87315 +_003530_hash prism2_info_hostscanresults 3 39657 _003530_hash NULL
87316 +_003531_hash prism2_info_scanresults 3 59729 _003531_hash NULL
87317 +_003532_hash proc_file_read 3 53905 _003532_hash NULL
87318 +_003533_hash pskb_expand_head 2-3 42881 _003533_hash NULL
87319 +_003535_hash qla4xxx_post_aen_work 3 46953 _003535_hash NULL
87320 +_003536_hash qla4xxx_post_ping_evt_work 4 8074 _003536_hash &_001627_hash
87321 +_003537_hash rawv6_setsockopt 5 56165 _003537_hash NULL
87322 +_003538_hash rds_message_map_pages 2 31487 _003538_hash NULL
87323 +_003539_hash read_flush_pipefs 3 20171 _003539_hash NULL
87324 +_003540_hash read_flush_procfs 3 27642 _003540_hash NULL
87325 +_003541_hash receive_packet 2 12367 _003541_hash NULL
87326 +_003542_hash reiserfs_add_entry 4 23062 _003542_hash &_002307_hash
87327 +_003543_hash rsc_mgr_init 3 16299 _003543_hash NULL
87328 +_003544_hash rtsx_read_cfg_seq 3-5 48139 _003544_hash NULL
87329 +_003546_hash rtsx_write_cfg_seq 3-5 27485 _003546_hash NULL
87330 +_003548_hash rxrpc_client_sendmsg 5 23236 _003548_hash NULL
87331 +_003549_hash rxrpc_kernel_send_data 3 60083 _003549_hash NULL
87332 +_003550_hash rxrpc_server_sendmsg 4 37331 _003550_hash NULL
87333 +_003551_hash scsi_dispatch_cmd_entry 3 49848 _003551_hash NULL
87334 +_003552_hash scsi_nl_send_vendor_msg 5 16394 _003552_hash NULL
87335 +_003553_hash sctp_datamsg_from_user 4 55342 _003553_hash NULL
87336 +_003554_hash sctp_make_chunk 4 12986 _003554_hash NULL
87337 +_003555_hash sctp_tsnmap_grow 2 32784 _003555_hash NULL
87338 +_003556_hash sep_prepare_input_dma_table 2-3 2009 _003556_hash NULL
87339 +_003558_hash sep_prepare_input_output_dma_table 4-3-2 63429 _003558_hash NULL
87340 +_003559_hash set_fd_set 1 35249 _003559_hash NULL
87341 +_003563_hash sisusbcon_do_font_op 9 52271 _003563_hash NULL
87342 +_003564_hash sisusb_write_mem_bulk 4 29678 _003564_hash NULL
87343 +_003565_hash smk_write_access2 3 19170 _003565_hash NULL
87344 +_003566_hash smk_write_cipso2 3 1021 _003566_hash NULL
87345 +_003567_hash smk_write_load2 3 52155 _003567_hash NULL
87346 +_003568_hash smk_write_load 3 26829 _003568_hash NULL
87347 +_003569_hash smk_write_load_self2 3 591 _003569_hash NULL
87348 +_003570_hash smk_write_load_self 3 7958 _003570_hash NULL
87349 +_003571_hash snd_pcm_plugin_alloc 2 12580 _003571_hash NULL
87350 +_003572_hash snd_rawmidi_kernel_read 3 4328 _003572_hash NULL
87351 +_003573_hash snd_rawmidi_read 3 56337 _003573_hash NULL
87352 +_003576_hash spidev_ioctl 2 12846 _003576_hash NULL
87353 +_003577_hash squashfs_read_fragment_index_table 4 2506 _003577_hash NULL
87354 +_003578_hash squashfs_read_id_index_table 4 61961 _003578_hash NULL
87355 +_003579_hash squashfs_read_inode_lookup_table 4 64739 _003579_hash NULL
87356 +_003582_hash swap_cgroup_swapon 2 13614 _003582_hash NULL
87357 +_003583_hash timeradd_entry 3 49850 _003583_hash NULL
87358 +_003584_hash tipc_buf_acquire 1 60437 _003584_hash NULL
87359 +_003585_hash tty_buffer_find 2 2443 _003585_hash NULL
87360 +_003586_hash ubifs_wbuf_write_nolock 3 64946 _003586_hash NULL
87361 +_003588_hash usblp_ioctl 2 30203 _003588_hash NULL
87362 +_003589_hash vgacon_adjust_height 2 28124 _003589_hash NULL
87363 +_003590_hash vhci_read 3 47878 _003590_hash NULL
87364 +_003591_hash vhci_write 3 2224 _003591_hash NULL
87365 +_003592_hash __videobuf_copy_stream 4 44769 _003592_hash NULL
87366 +_003593_hash videobuf_read_one 3 31637 _003593_hash NULL
87367 +_003594_hash video_usercopy 2 62151 _003594_hash NULL
87368 +_003595_hash vme_user_read 3 55338 _003595_hash NULL
87369 +_003596_hash __vxge_hw_blockpool_malloc 2 5786 _003596_hash NULL
87370 +_003597_hash write_adapter_mem 3 3234 _003597_hash NULL
87371 +_003598_hash write_flush_pipefs 3 2021 _003598_hash NULL
87372 +_003599_hash write_flush_procfs 3 44011 _003599_hash NULL
87373 +_003600_hash xfs_buf_associate_memory 3 17915 _003600_hash NULL
87374 +_003601_hash xfs_dir2_leaf_getdents 3 23841 _003601_hash NULL
87375 +_003602_hash xfs_idata_realloc 2 26199 _003602_hash NULL
87376 +_003603_hash xfs_iformat_local 4 49472 _003603_hash NULL
87377 +_003604_hash xip_file_read 3 58592 _003604_hash NULL
87378 +_003605_hash afs_send_simple_reply 3 63940 _003605_hash NULL
87379 +_003606_hash audit_expand 2 2098 _003606_hash NULL
87380 +_003607_hash bnx2i_send_nl_mesg 4 53353 _003607_hash NULL
87381 +_003608_hash __btrfs_buffered_write 3 35311 _003608_hash NULL
87382 +_003609_hash bttv_read 3 11432 _003609_hash NULL
87383 +_003610_hash ceph_parse_server_name 2 60318 _003610_hash NULL
87384 +_003611_hash ddp_clear_map 4 46152 _003611_hash NULL
87385 +_003612_hash ddp_set_map 4 751 _003612_hash NULL
87386 +_003613_hash do_arpt_get_ctl 4 49526 _003613_hash NULL
87387 +_003614_hash do_ip6t_get_ctl 4 47808 _003614_hash NULL
87388 +_003615_hash do_ipt_get_ctl 4 33897 _003615_hash NULL
87389 +_003616_hash do_trimming 3 26952 _003616_hash &_002655_hash
87390 +_003617_hash dvb_ca_en50221_io_ioctl 2 26490 _003617_hash NULL
87391 +_003618_hash dvb_demux_ioctl 2 42733 _003618_hash NULL
87392 +_003619_hash dvb_dvr_ioctl 2 49182 _003619_hash NULL
87393 +_003620_hash dvb_generic_ioctl 2 21810 _003620_hash NULL
87394 +_003621_hash dvb_net_ioctl 2 61559 _003621_hash NULL
87395 +_003622_hash enlarge_skb 2 44248 _003622_hash NULL
87396 +_003623_hash evdev_ioctl_handler 2 21705 _003623_hash NULL
87397 +_003624_hash fuse_perform_write 4 18457 _003624_hash NULL
87398 +_003625_hash fw_device_op_ioctl 2 11595 _003625_hash NULL
87399 +_003626_hash generic_file_buffered_write 4 25464 _003626_hash NULL
87400 +_003627_hash gen_pool_add 3 21776 _003627_hash NULL
87401 +_003628_hash ieee80211_skb_resize 3 50211 _003628_hash NULL
87402 +_003629_hash ip_options_get 4 56538 _003629_hash NULL
87403 +_003630_hash ip_send_reply 5 19987 _003630_hash NULL
87404 +_003631_hash __iscsi_complete_pdu 4 10726 _003631_hash NULL
87405 +_003632_hash iscsi_nop_out_rsp 4 51117 _003632_hash NULL
87406 +_003633_hash joydev_ioctl 2 33343 _003633_hash NULL
87407 +_003634_hash mlx4_init_cmpt_table 3 11569 _003634_hash NULL
87408 +_003635_hash mptctl_ioctl 2 12355 _003635_hash NULL
87409 +_003636_hash mthca_alloc_cq_buf 3 46512 _003636_hash NULL
87410 +_003637_hash named_prepare_buf 2 24532 _003637_hash NULL
87411 +_003638_hash netlink_change_ngroups 2 16457 _003638_hash NULL
87412 +_003639_hash netxen_nic_hw_read_wx_128M 2 26858 _003639_hash NULL
87413 +_003640_hash netxen_nic_hw_write_wx_128M 2 33488 _003640_hash NULL
87414 +_003642_hash osd_req_add_get_attr_list 3 49278 _003642_hash NULL
87415 +_003643_hash pcpu_build_alloc_info 1-3-2 41443 _003643_hash NULL
87416 +_003646_hash ping_sendmsg 4 3782 _003646_hash NULL
87417 +_003647_hash __pskb_pull_tail 2 60287 _003647_hash NULL
87418 +_003648_hash raid5_resize 2 63306 _003648_hash NULL
87419 +_003649_hash rxrpc_sendmsg 4 29049 _003649_hash NULL
87420 +_003650_hash sctp_make_abort 3 34459 _003650_hash NULL
87421 +_003651_hash sctp_make_asconf 3 4078 _003651_hash NULL
87422 +_003652_hash sctp_make_asconf_ack 3 31726 _003652_hash NULL
87423 +_003653_hash sctp_make_datafrag_empty 3 34737 _003653_hash NULL
87424 +_003654_hash sctp_make_fwdtsn 3 53265 _003654_hash NULL
87425 +_003655_hash sctp_make_heartbeat_ack 4 34411 _003655_hash NULL
87426 +_003656_hash sctp_make_init 4 58401 _003656_hash NULL
87427 +_003657_hash sctp_make_init_ack 4 3335 _003657_hash NULL
87428 +_003658_hash sctp_make_op_error_space 3 5528 _003658_hash NULL
87429 +_003659_hash sctp_tsnmap_mark 2 35929 _003659_hash NULL
87430 +_003663_hash sisusb_clear_vram 2-3 57466 _003663_hash NULL
87431 +_003665_hash sisusb_copy_memory 4 35016 _003665_hash NULL
87432 +_003666_hash sisusb_write 3 44834 _003666_hash NULL
87433 +_003667_hash __skb_cow 2 39254 _003667_hash NULL
87434 +_003668_hash skb_pad 2 17302 _003668_hash NULL
87435 +_003669_hash skb_realloc_headroom 2 19516 _003669_hash NULL
87436 +_003670_hash snd_pcm_plug_alloc 2 42339 _003670_hash NULL
87437 +_003673_hash subdev_ioctl 2 28417 _003673_hash NULL
87438 +_003674_hash sys_get_mempolicy 3 30379 _003674_hash NULL
87439 +_003675_hash sys_init_module 2 36047 _003675_hash NULL
87440 +_003676_hash sys_mbind 5 7990 _003676_hash NULL
87441 +_003677_hash sys_migrate_pages 2 39825 _003677_hash NULL
87442 +_003678_hash sys_setgroups 1 48668 _003678_hash &_001127_hash
87443 +_003679_hash sys_setgroups16 1 48882 _003679_hash NULL
87444 +_003680_hash sys_set_mempolicy 3 32608 _003680_hash NULL
87445 +_003681_hash tipc_msg_build 4 12326 _003681_hash NULL
87446 +_003682_hash __tty_buffer_request_room 2 27700 _003682_hash NULL
87447 +_003683_hash ubifs_recover_leb 3 60639 _003683_hash NULL
87448 +_003684_hash udp_sendmsg 4 4492 _003684_hash NULL
87449 +_003685_hash udp_setsockopt 5 25985 _003685_hash NULL
87450 +_003686_hash udpv6_setsockopt 5 18487 _003686_hash NULL
87451 +_003687_hash uvc_v4l2_ioctl 2 8411 _003687_hash NULL
87452 +_003688_hash videobuf_read_stream 3 14956 _003688_hash NULL
87453 +_003689_hash video_ioctl2 2 21380 _003689_hash NULL
87454 +_003690_hash video_read 3 28148 _003690_hash NULL
87455 +_003691_hash write_head 4 30481 _003691_hash NULL
87456 +_003692_hash write_node 4 33121 _003692_hash NULL
87457 +_003693_hash write_pbl 4 59583 _003693_hash NULL
87458 +_003694_hash xfs_dir2_block_to_sf 3 37868 _003694_hash NULL
87459 +_003695_hash xfs_dir2_sf_addname_hard 3 54254 _003695_hash NULL
87460 +_003696_hash xfs_readdir 3 41200 _003696_hash NULL
87461 +_003697_hash xlog_bread_offset 3 60030 _003697_hash NULL
87462 +_003698_hash zr364xx_read 3 2354 _003698_hash NULL
87463 +_003699_hash au0828_v4l2_read 3 40220 _003699_hash NULL
87464 +_003700_hash audit_log_n_hex 3 45617 _003700_hash NULL
87465 +_003701_hash audit_log_n_string 3 31705 _003701_hash NULL
87466 +_003702_hash beiscsi_process_async_pdu 7 39834 _003702_hash NULL
87467 +_003703_hash __btrfs_direct_write 4 22273 _003703_hash NULL
87468 +_003704_hash btrfs_file_aio_write 4 21520 _003704_hash NULL
87469 +_003705_hash cx231xx_v4l2_read 3 55014 _003705_hash NULL
87470 +_003706_hash cx25821_video_ioctl 2 30188 _003706_hash NULL
87471 +_003707_hash em28xx_v4l2_read 3 16701 _003707_hash NULL
87472 +_003708_hash evdev_ioctl 2 22371 _003708_hash NULL
87473 +_003709_hash fuse_file_aio_write 4 46399 _003709_hash NULL
87474 +_003710_hash iscsi_complete_pdu 4 48372 _003710_hash NULL
87475 +_003711_hash isdn_ppp_skb_push 2 5236 _003711_hash NULL
87476 +_003712_hash ivtv_v4l2_ioctl 2 16915 _003712_hash NULL
87477 +_003713_hash mpeg_read 3 6708 _003713_hash NULL
87478 +_003714_hash mthca_alloc_resize_buf 3 60394 _003714_hash NULL
87479 +_003715_hash mthca_init_cq 2 60011 _003715_hash NULL
87480 +_003716_hash named_distribute 4 48544 _003716_hash NULL
87481 +_003717_hash __nf_nat_mangle_tcp_packet 5-7 8190 _003717_hash NULL
87482 +_003719_hash nf_nat_mangle_udp_packet 5-7 13321 _003719_hash NULL
87483 +_003722_hash pcpu_embed_first_chunk 1-3-2 24224 _003722_hash NULL
87484 +_003724_hash pcpu_page_first_chunk 1 20712 _003724_hash NULL
87485 +_003725_hash pd_video_read 3 24510 _003725_hash NULL
87486 +_003726_hash pskb_may_pull 2 22546 _003726_hash NULL
87487 +_003727_hash __pskb_pull 2 42602 _003727_hash NULL
87488 +_003728_hash pvr2_v4l2_ioctl 2 24398 _003728_hash &_000854_hash
87489 +_003729_hash sctp_abort_pkt_new 5 55218 _003729_hash NULL
87490 +_003730_hash sctp_make_abort_violation 4 27959 _003730_hash NULL
87491 +_003731_hash sctp_make_op_error 5-6 7057 _003731_hash NULL
87492 +_003734_hash sisusbcon_bmove 5-7-6 21873 _003734_hash NULL
87493 +_003737_hash sisusbcon_clear 3-5-4 64329 _003737_hash NULL
87494 +_003740_hash sisusbcon_putcs 3 57630 _003740_hash &_001003_hash
87495 +_003741_hash sisusbcon_scroll 5-3-2 31315 _003741_hash NULL
87496 +_003742_hash sisusbcon_scroll_area 3-4 25899 _003742_hash NULL
87497 +_003744_hash skb_cow 2 26138 _003744_hash NULL
87498 +_003745_hash skb_cow_head 2 52495 _003745_hash NULL
87499 +_003746_hash skb_make_writable 2 24783 _003746_hash NULL
87500 +_003747_hash skb_padto 2 50759 _003747_hash NULL
87501 +_003748_hash solo_enc_read 3 33553 _003748_hash NULL
87502 +_003749_hash solo_v4l2_read 3 59247 _003749_hash NULL
87503 +_003750_hash timblogiw_read 3 48305 _003750_hash NULL
87504 +_003751_hash tipc_multicast 5 49144 _003751_hash NULL
87505 +_003752_hash tipc_port_recv_sections 4 42890 _003752_hash NULL
87506 +_003753_hash tipc_port_reject_sections 5 55229 _003753_hash NULL
87507 +_003754_hash tm6000_read 3 4151 _003754_hash NULL
87508 +_003755_hash trim_bitmaps 3 24158 _003755_hash NULL
87509 +_003756_hash trim_no_bitmap 3 22524 _003756_hash NULL
87510 +_003757_hash tty_buffer_request_room 2 23228 _003757_hash NULL
87511 +_003758_hash tty_insert_flip_string_fixed_flag 4 37428 _003758_hash NULL
87512 +_003759_hash tty_insert_flip_string_flags 4 30969 _003759_hash NULL
87513 +_003760_hash tty_prepare_flip_string 3 39955 _003760_hash NULL
87514 +_003761_hash tty_prepare_flip_string_flags 4 59240 _003761_hash NULL
87515 +_003762_hash ubifs_recover_log_leb 3 12079 _003762_hash NULL
87516 +_003763_hash vbi_read 3 63673 _003763_hash NULL
87517 +_003764_hash xfs_file_buffered_aio_write 4 11492 _003764_hash NULL
87518 +_003765_hash xlog_do_recovery_pass 3 21618 _003765_hash NULL
87519 +_003766_hash zoran_ioctl 2 30465 _003766_hash NULL
87520 +_003767_hash audit_log_n_untrustedstring 3 9548 _003767_hash NULL
87521 +_003768_hash bla_is_backbone_gw 3 53001 _003768_hash NULL
87522 +_003769_hash btrfs_trim_block_group 3 28963 _003769_hash NULL
87523 +_003770_hash check_header 2 56930 _003770_hash NULL
87524 +_003771_hash check_management_packet 3 976 _003771_hash NULL
87525 +_003772_hash check_unicast_packet 2 62217 _003772_hash NULL
87526 +_003773_hash cx18_v4l2_ioctl 2 46647 _003773_hash NULL
87527 +_003774_hash dccp_manip_pkt 2 30229 _003774_hash NULL
87528 +_003775_hash dma_push_rx 2 39973 _003775_hash NULL
87529 +_003776_hash ftdi_process_packet 5 45005 _003776_hash NULL
87530 +_003777_hash gre_manip_pkt 2 38785 _003777_hash NULL
87531 +_003778_hash handle_response 5 55951 _003778_hash NULL
87532 +_003779_hash handle_response_icmp 7 39574 _003779_hash NULL
87533 +_003780_hash help 4 14971 _003780_hash NULL
87534 +_003781_hash icmp_manip_pkt 2 48801 _003781_hash NULL
87535 +_003782_hash interface_rx 4 20404 _003782_hash NULL
87536 +_003783_hash ip4ip6_err 5 36772 _003783_hash NULL
87537 +_003784_hash ip6ip6_err 5 18308 _003784_hash NULL
87538 +_003785_hash ip_vs_icmp_xmit 4 59624 _003785_hash NULL
87539 +_003786_hash ip_vs_icmp_xmit_v6 4 20464 _003786_hash NULL
87540 +_003787_hash iscsi_iser_recv 4 41948 _003787_hash NULL
87541 +_003788_hash l2tp_xmit_skb 3 42672 _003788_hash NULL
87542 +_003789_hash mangle_packet 6-8 27864 _003789_hash NULL
87543 +_003791_hash manip_pkt 3 7741 _003791_hash NULL
87544 +_003792_hash mthca_resize_cq 2 19333 _003792_hash NULL
87545 +_003793_hash my_skb_head_push 2 58297 _003793_hash NULL
87546 +_003794_hash nf_nat_mangle_tcp_packet 5-7 8643 _003794_hash NULL
87547 +_003797_hash pskb_network_may_pull 2 35336 _003797_hash NULL
87548 +_003798_hash pskb_pull 2 65005 _003798_hash NULL
87549 +_003799_hash replay_log_leb 3 18704 _003799_hash NULL
87550 +_003800_hash sctp_manip_pkt 2 40620 _003800_hash NULL
87551 +_003801_hash sctp_sf_abort_violation 6 38380 _003801_hash NULL
87552 +_003806_hash skb_gro_header_slow 2 34958 _003806_hash NULL
87553 +_003807_hash tcf_csum_skb_nextlayer 3 64025 _003807_hash NULL
87554 +_003808_hash tcp_manip_pkt 2 14202 _003808_hash NULL
87555 +_003809_hash tty_audit_log 8 47280 _003809_hash NULL
87556 +_003810_hash tty_insert_flip_string 3 34042 _003810_hash NULL
87557 +_003811_hash udplite_manip_pkt 2 62433 _003811_hash NULL
87558 +_003812_hash udp_manip_pkt 2 50770 _003812_hash NULL
87559 +_003813_hash xfs_file_aio_write 4 33234 _003813_hash NULL
87560 +_003814_hash xlog_do_log_recovery 3 17550 _003814_hash NULL
87561 +_003815_hash afs_extract_data 5 50261 _003815_hash NULL
87562 +_003816_hash aircable_process_packet 5 46639 _003816_hash NULL
87563 +_003817_hash edge_tty_recv 4 18667 _003817_hash &_002287_hash
87564 +_003818_hash gigaset_if_receive 3 4861 _003818_hash NULL
87565 +_003819_hash gsm_dlci_data 3 14155 _003819_hash NULL
87566 +_003820_hash ifx_spi_insert_flip_string 3 51752 _003820_hash NULL
87567 +_003821_hash ip_nat_sdp_port 6 52938 _003821_hash NULL
87568 +_003822_hash ip_nat_sip_expect 7 45693 _003822_hash NULL
87569 +_003823_hash ipwireless_tty_received 3 49154 _003823_hash NULL
87570 +_003824_hash iser_rcv_completion 2 8048 _003824_hash NULL
87571 +_003825_hash mangle_sdp_packet 9 36279 _003825_hash NULL
87572 +_003826_hash map_addr 6 4666 _003826_hash NULL
87573 +_003827_hash nf_nat_ftp 5 47948 _003827_hash NULL
87574 +_003828_hash pty_write 3 44757 _003828_hash &_001547_hash
87575 +_003829_hash push_rx 3 28939 _003829_hash NULL
87576 +_003830_hash put_data_to_circ_buf 3 24869 _003830_hash &_001419_hash
87577 +_003831_hash rds_tcp_data_recv 3 53476 _003831_hash NULL
87578 +_003832_hash send_to_tty 3 45141 _003832_hash NULL
87579 +_003834_hash tcf_csum_ipv4_icmp 3 9258 _003834_hash NULL
87580 +_003835_hash tcf_csum_ipv4_igmp 3 60446 _003835_hash NULL
87581 +_003836_hash tcf_csum_ipv4_tcp 4 39713 _003836_hash NULL
87582 +_003837_hash tcf_csum_ipv4_udp 4 30777 _003837_hash &_000218_hash
87583 +_003838_hash tcf_csum_ipv6_icmp 4 11738 _003838_hash NULL
87584 +_003839_hash tcf_csum_ipv6_tcp 4 54877 _003839_hash NULL
87585 +_003840_hash tcf_csum_ipv6_udp 4 25241 _003840_hash NULL
87586 +_003841_hash ti_recv 4 22027 _003841_hash NULL
87587 +_003842_hash xlog_do_recover 3 59789 _003842_hash NULL
87588 +_003843_hash ip_nat_sdp_media 8 23386 _003843_hash NULL
87589 +_003844_hash lock_loop 1 61681 _003844_hash NULL
87590 +_003845_hash max3107_handlerx 2 58978 _003845_hash NULL
87591 +_003846_hash process_rcvd_data 3 6679 _003846_hash NULL
87592 +_003847_hash alloc_mr 1 45935 _003847_hash NULL
87593 +_003848_hash compat_core_sys_select 1 65285 _003848_hash NULL
87594 +_003849_hash compat_dccp_setsockopt 5 51263 _003849_hash NULL
87595 +_003850_hash compat_ip_setsockopt 5 13870 _003850_hash &_003115_hash
87596 +_003851_hash compat_ipv6_setsockopt 5 20468 _003851_hash NULL
87597 +_003852_hash compat_mpctl_ioctl 2 45671 _003852_hash NULL
87598 +_003853_hash compat_raw_setsockopt 5 30634 _003853_hash NULL
87599 +_003854_hash compat_rawv6_setsockopt 5 4967 _003854_hash NULL
87600 +_003855_hash compat_sys_get_mempolicy 3 31109 _003855_hash NULL
87601 +_003856_hash compat_sys_mbind 5 36256 _003856_hash NULL
87602 +_003857_hash compat_sys_migrate_pages 2 3157 _003857_hash NULL
87603 +_003858_hash compat_sys_set_mempolicy 3 57742 _003858_hash &_002222_hash
87604 +_003859_hash evdev_ioctl_compat 2 13851 _003859_hash NULL
87605 +_003860_hash fw_device_op_compat_ioctl 2 42804 _003860_hash NULL
87606 +_003861_hash gnttab_expand 1 15817 _003861_hash NULL
87607 +_003862_hash hiddev_compat_ioctl 2 41255 _003862_hash NULL
87608 +_003863_hash joydev_compat_ioctl 2 8765 _003863_hash NULL
87609 +_003864_hash mon_bin_compat_ioctl 3 50234 _003864_hash NULL
87610 +_003865_hash spidev_compat_ioctl 2 63778 _003865_hash NULL
87611 +_003866_hash uvc_v4l2_compat_ioctl32 2 8375 _003866_hash NULL
87612 +_003867_hash xlbd_reserve_minors 1-2 18365 _003867_hash NULL
87613 +_003868_hash compat_sys_select 1 16131 _003868_hash NULL
87614 +_003869_hash compat_udp_setsockopt 5 38840 _003869_hash NULL
87615 +_003870_hash compat_udpv6_setsockopt 5 42981 _003870_hash NULL
87616 +_003871_hash do_compat_pselect 1 10398 _003871_hash NULL
87617 +_003872_hash get_free_entries 1 46030 _003872_hash NULL
87618 +_003873_hash ipath_reg_phys_mr 3 23918 _003873_hash &_000963_hash
87619 +_003874_hash qib_alloc_fast_reg_mr 2 12526 _003874_hash NULL
87620 +_003875_hash qib_reg_phys_mr 3 60202 _003875_hash &_000872_hash
87621 +_003876_hash compat_sys_pselect6 1 14105 _003876_hash NULL
87622 +_003877_hash gnttab_alloc_grant_references 1 18240 _003877_hash NULL
87623 +_003878_hash alc_auto_create_extra_outs 2 18975 _003878_hash NULL
87624 +_003879_hash _alloc_cdb_cont 2 23609 _003879_hash NULL
87625 +_003880_hash _alloc_set_attr_list 4 48991 _003880_hash NULL
87626 +_003881_hash __btrfs_free_reserved_extent 2 31207 _003881_hash NULL
87627 +_003882_hash btrfsic_create_link_to_next_block 4 58246 _003882_hash NULL
87628 +_003883_hash diva_alloc_dma_map 2 23798 _003883_hash NULL
87629 +_003884_hash diva_xdi_write 4 63975 _003884_hash NULL
87630 +_003885_hash gsm_control_reply 4 53333 _003885_hash NULL
87631 +_003886_hash iwm_ntf_rx_packet 3 60452 _003886_hash NULL
87632 +_003887_hash macvtap_recvmsg 4 63949 _003887_hash NULL
87633 +_003890_hash smp_send_cmd 3 512 _003890_hash NULL
87634 +_003891_hash tun_recvmsg 4 48463 _003891_hash NULL
87635 +_003892_hash um_idi_read 3 850 _003892_hash NULL
87636 +_003893_hash _add_sg_continuation_descriptor 3 54721 _003893_hash NULL
87637 +_003894_hash btrfs_free_and_pin_reserved_extent 2 53016 _003894_hash NULL
87638 +_003895_hash btrfs_free_reserved_extent 2 9867 _003895_hash NULL
87639 +_003896_hash diva_init_dma_map 3 58336 _003896_hash NULL
87640 +_003897_hash divas_write 3 63901 _003897_hash NULL
87641 +_003898_hash gsm_control_message 4 18209 _003898_hash NULL
87642 +_003899_hash gsm_control_modem 3 55303 _003899_hash NULL
87643 +_003900_hash gsm_control_rls 3 3353 _003900_hash NULL
87644 +_003901_hash osd_req_read_sg 5 47905 _003901_hash NULL
87645 +_003902_hash osd_req_write_sg 5 50908 _003902_hash NULL
87646 +_003903_hash agp_remap 2 30665 _003903_hash NULL
87647 +_003904_hash alloc_arraycache 2 47505 _003904_hash NULL
87648 +_003905_hash drm_buffer_alloc 2 44405 _003905_hash NULL
87649 +_003906_hash drm_ioctl 2 42813 _003906_hash NULL
87650 +_003907_hash fbcon_do_set_font 2-3 4079 _003907_hash NULL
87651 +_003909_hash slabinfo_write 3 18600 _003909_hash NULL
87652 +_003910_hash do_tune_cpucache 2 14828 _003910_hash NULL
87653 +_003911_hash drm_compat_ioctl 2 51717 _003911_hash NULL
87654 +_003912_hash i915_compat_ioctl 2 3656 _003912_hash NULL
87655 +_003913_hash ath6kl_usb_bmi_read 3 48745 _003913_hash NULL
87656 +_003914_hash ath6kl_usb_bmi_write 3 2454 _003914_hash &_000981_hash
87657 +_003915_hash ath6kl_usb_ctrl_msg_exchange 4 33327 _003915_hash NULL
87658 +_003916_hash mga_compat_ioctl 2 52170 _003916_hash NULL
87659 +_003918_hash netlink_send 5 38434 _003918_hash NULL
87660 +_003919_hash nouveau_compat_ioctl 2 28305 _003919_hash NULL
87661 +_003920_hash persistent_ram_vmap 1-2 709 _003920_hash NULL
87662 +_003922_hash psb_unlocked_ioctl 2 16926 _003922_hash &_002255_hash
87663 +_003923_hash r128_compat_ioctl 2 39250 _003923_hash NULL
87664 +_003924_hash radeon_compat_ioctl 2 59150 _003924_hash NULL
87665 +_003925_hash radeon_kms_compat_ioctl 2 51371 _003925_hash NULL
87666 +_003926_hash viacam_read 3 54526 _003926_hash NULL
87667 +_003927_hash vmw_framebuffer_dmabuf_dirty 6 37661 _003927_hash &_001074_hash
87668 +_003928_hash vmw_framebuffer_surface_dirty 6 48132 _003928_hash NULL
87669 +_003929_hash vmw_unlocked_ioctl 2 19212 _003929_hash NULL
87670 +_003930_hash wl1251_cmd_template_set 4 6172 _003930_hash NULL
87671 +_003931_hash cma_create_area 2 38642 _003931_hash NULL
87672 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
87673 new file mode 100644
87674 index 0000000..244559e
87675 --- /dev/null
87676 +++ b/tools/gcc/size_overflow_plugin.c
87677 @@ -0,0 +1,1879 @@
87678 +/*
87679 + * Copyright 2011, 2012 by Emese Revfy <re.emese@gmail.com>
87680 + * Licensed under the GPL v2, or (at your option) v3
87681 + *
87682 + * Homepage:
87683 + * http://www.grsecurity.net/~ephox/overflow_plugin/
87684 + *
87685 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
87686 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
87687 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
87688 + *
87689 + * Usage:
87690 + * $ 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
87691 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
87692 + */
87693 +
87694 +#include "gcc-plugin.h"
87695 +#include "config.h"
87696 +#include "system.h"
87697 +#include "coretypes.h"
87698 +#include "tree.h"
87699 +#include "tree-pass.h"
87700 +#include "intl.h"
87701 +#include "plugin-version.h"
87702 +#include "tm.h"
87703 +#include "toplev.h"
87704 +#include "function.h"
87705 +#include "tree-flow.h"
87706 +#include "plugin.h"
87707 +#include "gimple.h"
87708 +#include "c-common.h"
87709 +#include "diagnostic.h"
87710 +#include "cfgloop.h"
87711 +
87712 +#if BUILDING_GCC_VERSION >= 4007
87713 +#include "c-tree.h"
87714 +#else
87715 +#define C_DECL_IMPLICIT(EXP) DECL_LANG_FLAG_2 (EXP)
87716 +#endif
87717 +
87718 +struct size_overflow_hash {
87719 + const struct size_overflow_hash * const next;
87720 + const char * const name;
87721 + const unsigned int param;
87722 +};
87723 +
87724 +#include "size_overflow_hash.h"
87725 +
87726 +enum marked {
87727 + MARKED_NO, MARKED_YES, MARKED_NOT_INTENTIONAL
87728 +};
87729 +
87730 +#define __unused __attribute__((__unused__))
87731 +#define NAME(node) IDENTIFIER_POINTER(DECL_NAME(node))
87732 +#define NAME_LEN(node) IDENTIFIER_LENGTH(DECL_NAME(node))
87733 +#define BEFORE_STMT true
87734 +#define AFTER_STMT false
87735 +#define CREATE_NEW_VAR NULL_TREE
87736 +#define CODES_LIMIT 32
87737 +#define MAX_PARAM 32
87738 +#define MY_STMT GF_PLF_1
87739 +#define NO_CAST_CHECK GF_PLF_2
87740 +
87741 +#if BUILDING_GCC_VERSION == 4005
87742 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
87743 +#endif
87744 +
87745 +int plugin_is_GPL_compatible;
87746 +void debug_gimple_stmt(gimple gs);
87747 +
87748 +static tree expand(struct pointer_set_t *visited, tree lhs);
87749 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs);
87750 +static tree report_size_overflow_decl;
87751 +static const_tree const_char_ptr_type_node;
87752 +static unsigned int handle_function(void);
87753 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
87754 +static tree get_size_overflow_type(gimple stmt, const_tree node);
87755 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3);
87756 +
87757 +static struct plugin_info size_overflow_plugin_info = {
87758 + .version = "20120930beta",
87759 + .help = "no-size-overflow\tturn off size overflow checking\n",
87760 +};
87761 +
87762 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87763 +{
87764 + unsigned int arg_count;
87765 + enum tree_code code = TREE_CODE(*node);
87766 +
87767 + switch (code) {
87768 + case FUNCTION_DECL:
87769 + arg_count = type_num_arguments(TREE_TYPE(*node));
87770 + break;
87771 + case FUNCTION_TYPE:
87772 + case METHOD_TYPE:
87773 + arg_count = type_num_arguments(*node);
87774 + break;
87775 + default:
87776 + *no_add_attrs = true;
87777 + error("%s: %qE attribute only applies to functions", __func__, name);
87778 + return NULL_TREE;
87779 + }
87780 +
87781 + for (; args; args = TREE_CHAIN(args)) {
87782 + tree position = TREE_VALUE(args);
87783 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) < 1 || TREE_INT_CST_LOW(position) > arg_count ) {
87784 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87785 + *no_add_attrs = true;
87786 + }
87787 + }
87788 + return NULL_TREE;
87789 +}
87790 +
87791 +static const char* get_asm_name(tree node)
87792 +{
87793 + return IDENTIFIER_POINTER(DECL_ASSEMBLER_NAME(node));
87794 +}
87795 +
87796 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
87797 +{
87798 + unsigned int arg_count, arg_num;
87799 + enum tree_code code = TREE_CODE(*node);
87800 +
87801 + switch (code) {
87802 + case FUNCTION_DECL:
87803 + arg_count = type_num_arguments(TREE_TYPE(*node));
87804 + break;
87805 + case FUNCTION_TYPE:
87806 + case METHOD_TYPE:
87807 + arg_count = type_num_arguments(*node);
87808 + break;
87809 + case FIELD_DECL:
87810 + arg_num = TREE_INT_CST_LOW(TREE_VALUE(args));
87811 + if (arg_num != 0) {
87812 + *no_add_attrs = true;
87813 + error("%s: %qE attribute parameter can only be 0 in structure fields", __func__, name);
87814 + }
87815 + return NULL_TREE;
87816 + default:
87817 + *no_add_attrs = true;
87818 + error("%qE attribute only applies to functions", name);
87819 + return NULL_TREE;
87820 + }
87821 +
87822 + for (; args; args = TREE_CHAIN(args)) {
87823 + tree position = TREE_VALUE(args);
87824 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_HIGH(position) || TREE_INT_CST_LOW(position) > arg_count ) {
87825 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
87826 + *no_add_attrs = true;
87827 + }
87828 + }
87829 + return NULL_TREE;
87830 +}
87831 +
87832 +static struct attribute_spec size_overflow_attr = {
87833 + .name = "size_overflow",
87834 + .min_length = 1,
87835 + .max_length = -1,
87836 + .decl_required = true,
87837 + .type_required = false,
87838 + .function_type_required = false,
87839 + .handler = handle_size_overflow_attribute,
87840 +#if BUILDING_GCC_VERSION >= 4007
87841 + .affects_type_identity = false
87842 +#endif
87843 +};
87844 +
87845 +static struct attribute_spec intentional_overflow_attr = {
87846 + .name = "intentional_overflow",
87847 + .min_length = 1,
87848 + .max_length = -1,
87849 + .decl_required = true,
87850 + .type_required = false,
87851 + .function_type_required = false,
87852 + .handler = handle_intentional_overflow_attribute,
87853 +#if BUILDING_GCC_VERSION >= 4007
87854 + .affects_type_identity = false
87855 +#endif
87856 +};
87857 +
87858 +static void register_attributes(void __unused *event_data, void __unused *data)
87859 +{
87860 + register_attribute(&size_overflow_attr);
87861 + register_attribute(&intentional_overflow_attr);
87862 +}
87863 +
87864 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
87865 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
87866 +{
87867 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
87868 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
87869 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
87870 +
87871 + unsigned int m = 0x57559429;
87872 + unsigned int n = 0x5052acdb;
87873 + const unsigned int *key4 = (const unsigned int *)key;
87874 + unsigned int h = len;
87875 + unsigned int k = len + seed + n;
87876 + unsigned long long p;
87877 +
87878 + while (len >= 8) {
87879 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
87880 + len -= 8;
87881 + }
87882 + if (len >= 4) {
87883 + cwmixb(key4[0]) key4 += 1;
87884 + len -= 4;
87885 + }
87886 + if (len)
87887 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
87888 + cwmixb(h ^ (k + n));
87889 + return k ^ h;
87890 +
87891 +#undef cwfold
87892 +#undef cwmixa
87893 +#undef cwmixb
87894 +}
87895 +
87896 +static inline unsigned int get_hash_num(const char *fndecl, const char *tree_codes, unsigned int len, unsigned int seed)
87897 +{
87898 + unsigned int fn = CrapWow(fndecl, strlen(fndecl), seed) & 0xffff;
87899 + unsigned int codes = CrapWow(tree_codes, len, seed) & 0xffff;
87900 + return fn ^ codes;
87901 +}
87902 +
87903 +static inline tree get_original_function_decl(tree fndecl)
87904 +{
87905 + if (DECL_ABSTRACT_ORIGIN(fndecl))
87906 + return DECL_ABSTRACT_ORIGIN(fndecl);
87907 + return fndecl;
87908 +}
87909 +
87910 +static inline gimple get_def_stmt(const_tree node)
87911 +{
87912 + gcc_assert(node != NULL_TREE);
87913 + gcc_assert(TREE_CODE(node) == SSA_NAME);
87914 + return SSA_NAME_DEF_STMT(node);
87915 +}
87916 +
87917 +static unsigned char get_tree_code(const_tree type)
87918 +{
87919 + switch (TREE_CODE(type)) {
87920 + case ARRAY_TYPE:
87921 + return 0;
87922 + case BOOLEAN_TYPE:
87923 + return 1;
87924 + case ENUMERAL_TYPE:
87925 + return 2;
87926 + case FUNCTION_TYPE:
87927 + return 3;
87928 + case INTEGER_TYPE:
87929 + return 4;
87930 + case POINTER_TYPE:
87931 + return 5;
87932 + case RECORD_TYPE:
87933 + return 6;
87934 + case UNION_TYPE:
87935 + return 7;
87936 + case VOID_TYPE:
87937 + return 8;
87938 + case REAL_TYPE:
87939 + return 9;
87940 + case VECTOR_TYPE:
87941 + return 10;
87942 + case REFERENCE_TYPE:
87943 + return 11;
87944 + case OFFSET_TYPE:
87945 + return 12;
87946 + case COMPLEX_TYPE:
87947 + return 13;
87948 + default:
87949 + debug_tree((tree)type);
87950 + gcc_unreachable();
87951 + }
87952 +}
87953 +
87954 +static size_t add_type_codes(const_tree type, unsigned char *tree_codes, size_t len)
87955 +{
87956 + gcc_assert(type != NULL_TREE);
87957 +
87958 + while (type && len < CODES_LIMIT) {
87959 + tree_codes[len] = get_tree_code(type);
87960 + len++;
87961 + type = TREE_TYPE(type);
87962 + }
87963 + return len;
87964 +}
87965 +
87966 +static unsigned int get_function_decl(const_tree fndecl, unsigned char *tree_codes)
87967 +{
87968 + const_tree arg, result, arg_field, type = TREE_TYPE(fndecl);
87969 + enum tree_code code = TREE_CODE(type);
87970 + size_t len = 0;
87971 +
87972 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
87973 +
87974 + arg = TYPE_ARG_TYPES(type);
87975 + // skip builtins __builtin_constant_p
87976 + if (!arg && DECL_BUILT_IN(fndecl))
87977 + return 0;
87978 +
87979 + if (TREE_CODE_CLASS(code) == tcc_type)
87980 + result = type;
87981 + else
87982 + result = DECL_RESULT(fndecl);
87983 +
87984 + gcc_assert(result != NULL_TREE);
87985 + len = add_type_codes(TREE_TYPE(result), tree_codes, len);
87986 +
87987 + if (arg == NULL_TREE) {
87988 + gcc_assert(CODE_CONTAINS_STRUCT(TREE_CODE(fndecl), TS_DECL_NON_COMMON));
87989 + arg_field = DECL_ARGUMENT_FLD(fndecl);
87990 + if (arg_field == NULL_TREE)
87991 + return 0;
87992 + arg = TREE_TYPE(arg_field);
87993 + len = add_type_codes(arg, tree_codes, len);
87994 + gcc_assert(len != 0);
87995 + return len;
87996 + }
87997 +
87998 + gcc_assert(arg != NULL_TREE && TREE_CODE(arg) == TREE_LIST);
87999 + while (arg && len < CODES_LIMIT) {
88000 + len = add_type_codes(TREE_VALUE(arg), tree_codes, len);
88001 + arg = TREE_CHAIN(arg);
88002 + }
88003 +
88004 + gcc_assert(len != 0);
88005 + return len;
88006 +}
88007 +
88008 +static const struct size_overflow_hash *get_function_hash(tree fndecl)
88009 +{
88010 + unsigned int hash;
88011 + const struct size_overflow_hash *entry;
88012 + unsigned char tree_codes[CODES_LIMIT];
88013 + size_t len;
88014 + const char *func_name = get_asm_name(fndecl);
88015 +
88016 + len = get_function_decl(fndecl, tree_codes);
88017 + if (len == 0)
88018 + return NULL;
88019 +
88020 + hash = get_hash_num(func_name, (const char*) tree_codes, len, 0);
88021 +
88022 + entry = size_overflow_hash[hash];
88023 + while (entry) {
88024 + if (!strcmp(entry->name, func_name))
88025 + return entry;
88026 + entry = entry->next;
88027 + }
88028 +
88029 + return NULL;
88030 +}
88031 +
88032 +static void check_arg_type(const_tree arg)
88033 +{
88034 + const_tree type = TREE_TYPE(arg);
88035 + enum tree_code code = TREE_CODE(type);
88036 +
88037 + gcc_assert(code == INTEGER_TYPE || code == ENUMERAL_TYPE ||
88038 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == VOID_TYPE) ||
88039 + (code == POINTER_TYPE && TREE_CODE(TREE_TYPE(type)) == INTEGER_TYPE));
88040 +}
88041 +
88042 +static int find_arg_number(const_tree arg, tree func)
88043 +{
88044 + tree var;
88045 + unsigned int argnum = 1;
88046 +
88047 + if (TREE_CODE(arg) == SSA_NAME)
88048 + arg = SSA_NAME_VAR(arg);
88049 +
88050 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var)) {
88051 + if (strcmp(NAME(arg), NAME(var))) {
88052 + argnum++;
88053 + continue;
88054 + }
88055 + check_arg_type(var);
88056 + return argnum;
88057 + }
88058 + gcc_unreachable();
88059 +}
88060 +
88061 +static tree create_new_var(tree type)
88062 +{
88063 + tree new_var = create_tmp_var(type, "cicus");
88064 +
88065 + add_referenced_var(new_var);
88066 + mark_sym_for_renaming(new_var);
88067 + return new_var;
88068 +}
88069 +
88070 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
88071 +{
88072 + gimple assign;
88073 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88074 + tree type = TREE_TYPE(rhs1);
88075 + tree lhs = create_new_var(type);
88076 +
88077 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
88078 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88079 +
88080 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
88081 + update_stmt(assign);
88082 + gimple_set_plf(assign, MY_STMT, true);
88083 + return assign;
88084 +}
88085 +
88086 +static bool is_bool(const_tree node)
88087 +{
88088 + const_tree type;
88089 +
88090 + if (node == NULL_TREE)
88091 + return false;
88092 +
88093 + type = TREE_TYPE(node);
88094 + if (!INTEGRAL_TYPE_P(type))
88095 + return false;
88096 + if (TREE_CODE(type) == BOOLEAN_TYPE)
88097 + return true;
88098 + if (TYPE_PRECISION(type) == 1)
88099 + return true;
88100 + return false;
88101 +}
88102 +
88103 +static tree cast_a_tree(tree type, tree var)
88104 +{
88105 + gcc_assert(type != NULL_TREE);
88106 + gcc_assert(var != NULL_TREE);
88107 + gcc_assert(fold_convertible_p(type, var));
88108 +
88109 + return fold_convert(type, var);
88110 +}
88111 +
88112 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before)
88113 +{
88114 + gimple assign;
88115 +
88116 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
88117 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
88118 + gcc_unreachable();
88119 +
88120 + if (lhs == CREATE_NEW_VAR)
88121 + lhs = create_new_var(dst_type);
88122 +
88123 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
88124 +
88125 + if (!gsi_end_p(*gsi)) {
88126 + location_t loc = gimple_location(gsi_stmt(*gsi));
88127 + gimple_set_location(assign, loc);
88128 + }
88129 +
88130 + gimple_set_lhs(assign, make_ssa_name(lhs, assign));
88131 +
88132 + if (before)
88133 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
88134 + else
88135 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
88136 + update_stmt(assign);
88137 + gimple_set_plf(assign, MY_STMT, true);
88138 +
88139 + return assign;
88140 +}
88141 +
88142 +static tree cast_to_new_size_overflow_type(gimple stmt, tree new_rhs1, tree size_overflow_type, bool before)
88143 +{
88144 + const_gimple assign;
88145 + gimple_stmt_iterator gsi;
88146 +
88147 + if (new_rhs1 == NULL_TREE)
88148 + return NULL_TREE;
88149 +
88150 + if (!useless_type_conversion_p(TREE_TYPE(new_rhs1), size_overflow_type)) {
88151 + gsi = gsi_for_stmt(stmt);
88152 + assign = build_cast_stmt(size_overflow_type, new_rhs1, CREATE_NEW_VAR, &gsi, before);
88153 + return gimple_get_lhs(assign);
88154 + }
88155 + return new_rhs1;
88156 +}
88157 +
88158 +static tree follow_overflow_type_and_dup(struct pointer_set_t *visited, gimple stmt, const_tree node, tree new_rhs1, tree new_rhs2, tree new_rhs3)
88159 +{
88160 + tree size_overflow_type = get_size_overflow_type(stmt, node);
88161 +
88162 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88163 +
88164 + if (new_rhs2 != NULL_TREE)
88165 + new_rhs2 = cast_to_new_size_overflow_type(stmt, new_rhs2, size_overflow_type, BEFORE_STMT);
88166 +
88167 + if (new_rhs3 != NULL_TREE)
88168 + new_rhs3 = cast_to_new_size_overflow_type(stmt, new_rhs3, size_overflow_type, BEFORE_STMT);
88169 +
88170 + return dup_assign(visited, stmt, size_overflow_type, new_rhs1, new_rhs2, new_rhs3);
88171 +}
88172 +
88173 +
88174 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
88175 +{
88176 + tree size_overflow_type, lhs;
88177 + gimple stmt;
88178 + gimple_stmt_iterator gsi;
88179 +
88180 + if (rhs1 == NULL_TREE) {
88181 + debug_gimple_stmt(oldstmt);
88182 + error("%s: rhs1 is NULL_TREE", __func__);
88183 + gcc_unreachable();
88184 + }
88185 +
88186 + if (gimple_code(oldstmt) == GIMPLE_ASM)
88187 + lhs = rhs1;
88188 + else
88189 + lhs = gimple_get_lhs(oldstmt);
88190 +
88191 + gsi = gsi_for_stmt(oldstmt);
88192 + pointer_set_insert(visited, oldstmt);
88193 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
88194 + basic_block next_bb, cur_bb;
88195 + const_edge e;
88196 +
88197 + gcc_assert(before == false);
88198 + gcc_assert(stmt_can_throw_internal(oldstmt));
88199 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
88200 + gcc_assert(!gsi_end_p(gsi));
88201 +
88202 + cur_bb = gimple_bb(oldstmt);
88203 + next_bb = cur_bb->next_bb;
88204 + e = find_edge(cur_bb, next_bb);
88205 + gcc_assert(e != NULL);
88206 + gcc_assert(e->flags & EDGE_FALLTHRU);
88207 +
88208 + gsi = gsi_after_labels(next_bb);
88209 + gcc_assert(!gsi_end_p(gsi));
88210 +
88211 + before = true;
88212 + oldstmt = gsi_stmt(gsi);
88213 + }
88214 +
88215 + size_overflow_type = get_size_overflow_type(oldstmt, lhs);
88216 +
88217 + stmt = build_cast_stmt(size_overflow_type, rhs1, CREATE_NEW_VAR, &gsi, before);
88218 + gimple_set_plf(stmt, MY_STMT, true);
88219 + return gimple_get_lhs(stmt);
88220 +}
88221 +
88222 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, tree size_overflow_type, tree rhs1, tree rhs2, tree __unused rhs3)
88223 +{
88224 + gimple stmt;
88225 + gimple_stmt_iterator gsi;
88226 + tree new_var, lhs = gimple_get_lhs(oldstmt);
88227 +
88228 + if (gimple_plf(oldstmt, MY_STMT))
88229 + return lhs;
88230 +
88231 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
88232 + rhs1 = gimple_assign_rhs1(oldstmt);
88233 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
88234 + }
88235 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
88236 + rhs2 = gimple_assign_rhs2(oldstmt);
88237 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
88238 + }
88239 +
88240 + stmt = gimple_copy(oldstmt);
88241 + gimple_set_location(stmt, gimple_location(oldstmt));
88242 + gimple_set_plf(stmt, MY_STMT, true);
88243 +
88244 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
88245 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
88246 +
88247 + if (is_bool(lhs))
88248 + new_var = SSA_NAME_VAR(lhs);
88249 + else
88250 + new_var = create_new_var(size_overflow_type);
88251 + new_var = make_ssa_name(new_var, stmt);
88252 + gimple_set_lhs(stmt, new_var);
88253 +
88254 + if (rhs1 != NULL_TREE) {
88255 + if (!gimple_assign_cast_p(oldstmt))
88256 + rhs1 = cast_a_tree(size_overflow_type, rhs1);
88257 + gimple_assign_set_rhs1(stmt, rhs1);
88258 + }
88259 +
88260 + if (rhs2 != NULL_TREE)
88261 + gimple_assign_set_rhs2(stmt, rhs2);
88262 +#if BUILDING_GCC_VERSION >= 4007
88263 + if (rhs3 != NULL_TREE)
88264 + gimple_assign_set_rhs3(stmt, rhs3);
88265 +#endif
88266 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
88267 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
88268 +
88269 + gsi = gsi_for_stmt(oldstmt);
88270 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
88271 + update_stmt(stmt);
88272 + pointer_set_insert(visited, oldstmt);
88273 + return gimple_get_lhs(stmt);
88274 +}
88275 +
88276 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
88277 +{
88278 + basic_block bb;
88279 + gimple phi;
88280 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
88281 +
88282 + bb = gsi_bb(gsi);
88283 +
88284 + phi = create_phi_node(result, bb);
88285 + gsi = gsi_last(phi_nodes(bb));
88286 + gsi_remove(&gsi, false);
88287 +
88288 + gsi = gsi_for_stmt(oldstmt);
88289 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
88290 + gimple_set_bb(phi, bb);
88291 + gimple_set_plf(phi, MY_STMT, true);
88292 + return phi;
88293 +}
88294 +
88295 +static basic_block create_a_first_bb(void)
88296 +{
88297 + basic_block first_bb;
88298 +
88299 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
88300 + if (dom_info_available_p(CDI_DOMINATORS))
88301 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR);
88302 + return first_bb;
88303 +}
88304 +
88305 +static tree cast_old_phi_arg(gimple oldstmt, tree size_overflow_type, tree arg, tree new_var, unsigned int i)
88306 +{
88307 + basic_block bb;
88308 + const_gimple newstmt;
88309 + gimple_stmt_iterator gsi;
88310 + bool before = BEFORE_STMT;
88311 +
88312 + if (TREE_CODE(arg) == SSA_NAME && gimple_code(get_def_stmt(arg)) != GIMPLE_NOP) {
88313 + gsi = gsi_for_stmt(get_def_stmt(arg));
88314 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, AFTER_STMT);
88315 + return gimple_get_lhs(newstmt);
88316 + }
88317 +
88318 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
88319 + gsi = gsi_after_labels(bb);
88320 + if (bb->index == 0) {
88321 + bb = create_a_first_bb();
88322 + gsi = gsi_start_bb(bb);
88323 + }
88324 + newstmt = build_cast_stmt(size_overflow_type, arg, new_var, &gsi, before);
88325 + return gimple_get_lhs(newstmt);
88326 +}
88327 +
88328 +static const_gimple handle_new_phi_arg(const_tree arg, tree new_var, tree new_rhs)
88329 +{
88330 + gimple newstmt;
88331 + gimple_stmt_iterator gsi;
88332 + void (*gsi_insert)(gimple_stmt_iterator *, gimple, enum gsi_iterator_update);
88333 + gimple def_newstmt = get_def_stmt(new_rhs);
88334 +
88335 + gsi_insert = gsi_insert_after;
88336 + gsi = gsi_for_stmt(def_newstmt);
88337 +
88338 + switch (gimple_code(get_def_stmt(arg))) {
88339 + case GIMPLE_PHI:
88340 + newstmt = gimple_build_assign(new_var, new_rhs);
88341 + gsi = gsi_after_labels(gimple_bb(def_newstmt));
88342 + gsi_insert = gsi_insert_before;
88343 + break;
88344 + case GIMPLE_ASM:
88345 + case GIMPLE_CALL:
88346 + newstmt = gimple_build_assign(new_var, new_rhs);
88347 + break;
88348 + case GIMPLE_ASSIGN:
88349 + newstmt = gimple_build_assign(new_var, gimple_get_lhs(def_newstmt));
88350 + break;
88351 + default:
88352 + /* unknown gimple_code (handle_build_new_phi_arg) */
88353 + gcc_unreachable();
88354 + }
88355 +
88356 + gimple_set_lhs(newstmt, make_ssa_name(new_var, newstmt));
88357 + gsi_insert(&gsi, newstmt, GSI_NEW_STMT);
88358 + gimple_set_plf(newstmt, MY_STMT, true);
88359 + update_stmt(newstmt);
88360 + return newstmt;
88361 +}
88362 +
88363 +static tree build_new_phi_arg(struct pointer_set_t *visited, tree size_overflow_type, tree arg, tree new_var)
88364 +{
88365 + const_gimple newstmt;
88366 + gimple def_stmt;
88367 + tree new_rhs;
88368 +
88369 + new_rhs = expand(visited, arg);
88370 + if (new_rhs == NULL_TREE)
88371 + return NULL_TREE;
88372 +
88373 + def_stmt = get_def_stmt(new_rhs);
88374 + if (gimple_code(def_stmt) == GIMPLE_NOP)
88375 + return NULL_TREE;
88376 + new_rhs = cast_to_new_size_overflow_type(def_stmt, new_rhs, size_overflow_type, AFTER_STMT);
88377 +
88378 + newstmt = handle_new_phi_arg(arg, new_var, new_rhs);
88379 + return gimple_get_lhs(newstmt);
88380 +}
88381 +
88382 +static tree build_new_phi(struct pointer_set_t *visited, tree orig_result)
88383 +{
88384 + gimple phi, oldstmt = get_def_stmt(orig_result);
88385 + tree new_result, size_overflow_type;
88386 + unsigned int i;
88387 + unsigned int n = gimple_phi_num_args(oldstmt);
88388 +
88389 + size_overflow_type = get_size_overflow_type(oldstmt, orig_result);
88390 +
88391 + new_result = create_new_var(size_overflow_type);
88392 +
88393 + pointer_set_insert(visited, oldstmt);
88394 + phi = overflow_create_phi_node(oldstmt, new_result);
88395 + for (i = 0; i < n; i++) {
88396 + tree arg, lhs;
88397 +
88398 + arg = gimple_phi_arg_def(oldstmt, i);
88399 + if (is_gimple_constant(arg))
88400 + arg = cast_a_tree(size_overflow_type, arg);
88401 + lhs = build_new_phi_arg(visited, size_overflow_type, arg, new_result);
88402 + if (lhs == NULL_TREE)
88403 + lhs = cast_old_phi_arg(oldstmt, size_overflow_type, arg, new_result, i);
88404 + add_phi_arg(phi, lhs, gimple_phi_arg_edge(oldstmt, i), gimple_location(oldstmt));
88405 + }
88406 +
88407 + update_stmt(phi);
88408 + return gimple_phi_result(phi);
88409 +}
88410 +
88411 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
88412 +{
88413 + const_gimple assign;
88414 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88415 + tree origtype = TREE_TYPE(orig_rhs);
88416 +
88417 + gcc_assert(gimple_code(stmt) == GIMPLE_ASSIGN);
88418 +
88419 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88420 + return gimple_get_lhs(assign);
88421 +}
88422 +
88423 +static void change_rhs1(gimple stmt, tree new_rhs1)
88424 +{
88425 + tree assign_rhs;
88426 + const_tree rhs = gimple_assign_rhs1(stmt);
88427 +
88428 + assign_rhs = change_assign_rhs(stmt, rhs, new_rhs1);
88429 + gimple_assign_set_rhs1(stmt, assign_rhs);
88430 + update_stmt(stmt);
88431 +}
88432 +
88433 +static bool check_mode_type(const_gimple stmt)
88434 +{
88435 + const_tree lhs = gimple_get_lhs(stmt);
88436 + const_tree lhs_type = TREE_TYPE(lhs);
88437 + const_tree rhs_type = TREE_TYPE(gimple_assign_rhs1(stmt));
88438 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
88439 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
88440 +
88441 + if (rhs_mode == lhs_mode && TYPE_UNSIGNED(rhs_type) == TYPE_UNSIGNED(lhs_type))
88442 + return false;
88443 +
88444 + if (rhs_mode == SImode && lhs_mode == DImode && (TYPE_UNSIGNED(rhs_type) || !TYPE_UNSIGNED(lhs_type)))
88445 + return false;
88446 +
88447 + return true;
88448 +}
88449 +
88450 +static bool check_undefined_integer_operation(const_gimple stmt)
88451 +{
88452 + const_gimple def_stmt;
88453 + const_tree lhs = gimple_get_lhs(stmt);
88454 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88455 + const_tree rhs1_type = TREE_TYPE(rhs1);
88456 + const_tree lhs_type = TREE_TYPE(lhs);
88457 +
88458 + if (TYPE_MODE(rhs1_type) != TYPE_MODE(lhs_type) || TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
88459 + return false;
88460 +
88461 + def_stmt = get_def_stmt(rhs1);
88462 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN)
88463 + return false;
88464 +
88465 + if (gimple_assign_rhs_code(def_stmt) != MINUS_EXPR)
88466 + return false;
88467 + return true;
88468 +}
88469 +
88470 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
88471 +{
88472 + const_tree rhs1, lhs, rhs1_type, lhs_type;
88473 + enum machine_mode lhs_mode, rhs_mode;
88474 + gimple def_stmt = get_def_stmt(no_const_rhs);
88475 +
88476 + if (!gimple_assign_cast_p(def_stmt))
88477 + return false;
88478 +
88479 + rhs1 = gimple_assign_rhs1(def_stmt);
88480 + lhs = gimple_get_lhs(def_stmt);
88481 + rhs1_type = TREE_TYPE(rhs1);
88482 + lhs_type = TREE_TYPE(lhs);
88483 + rhs_mode = TYPE_MODE(rhs1_type);
88484 + lhs_mode = TYPE_MODE(lhs_type);
88485 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
88486 + return false;
88487 +
88488 + return true;
88489 +}
88490 +
88491 +static tree handle_unary_rhs(struct pointer_set_t *visited, gimple stmt)
88492 +{
88493 + tree size_overflow_type, lhs = gimple_get_lhs(stmt);
88494 + tree new_rhs1, rhs1 = gimple_assign_rhs1(stmt);
88495 + const_tree rhs1_type = TREE_TYPE(rhs1);
88496 + const_tree lhs_type = TREE_TYPE(lhs);
88497 +
88498 + new_rhs1 = expand(visited, rhs1);
88499 +
88500 + if (new_rhs1 == NULL_TREE || TREE_CODE(rhs1_type) == POINTER_TYPE)
88501 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88502 +
88503 + if (gimple_plf(stmt, MY_STMT))
88504 + return lhs;
88505 +
88506 + if (gimple_plf(stmt, NO_CAST_CHECK))
88507 + return follow_overflow_type_and_dup(visited, stmt, rhs1, new_rhs1, NULL_TREE, NULL_TREE);
88508 +
88509 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
88510 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88511 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88512 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88513 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88514 + }
88515 +
88516 + if (!gimple_assign_cast_p(stmt) || check_undefined_integer_operation(stmt))
88517 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
88518 +
88519 + size_overflow_type = get_size_overflow_type(stmt, rhs1);
88520 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88521 +
88522 + change_rhs1(stmt, new_rhs1);
88523 + check_size_overflow(stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
88524 +
88525 + rhs1 = gimple_assign_rhs1(stmt);
88526 + rhs1_type = TREE_TYPE(rhs1);
88527 + if (TYPE_UNSIGNED(rhs1_type) != TYPE_UNSIGNED(lhs_type))
88528 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
88529 +
88530 + if (!check_mode_type(stmt))
88531 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88532 +
88533 + size_overflow_type = get_size_overflow_type(stmt, lhs);
88534 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
88535 +
88536 + check_size_overflow(stmt, size_overflow_type, new_rhs1, lhs, BEFORE_STMT);
88537 +
88538 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88539 +}
88540 +
88541 +static tree handle_unary_ops(struct pointer_set_t *visited, tree lhs)
88542 +{
88543 + gimple def_stmt = get_def_stmt(lhs);
88544 + tree rhs1 = gimple_assign_rhs1(def_stmt);
88545 +
88546 + if (is_gimple_constant(rhs1))
88547 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88548 +
88549 + gcc_assert(TREE_CODE(rhs1) != COND_EXPR);
88550 + switch (TREE_CODE(rhs1)) {
88551 + case SSA_NAME:
88552 + return handle_unary_rhs(visited, def_stmt);
88553 + case ARRAY_REF:
88554 + case BIT_FIELD_REF:
88555 + case ADDR_EXPR:
88556 + case COMPONENT_REF:
88557 + case INDIRECT_REF:
88558 +#if BUILDING_GCC_VERSION >= 4006
88559 + case MEM_REF:
88560 +#endif
88561 + case PARM_DECL:
88562 + case TARGET_MEM_REF:
88563 + case VAR_DECL:
88564 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88565 +
88566 + default:
88567 + debug_gimple_stmt(def_stmt);
88568 + debug_tree(rhs1);
88569 + gcc_unreachable();
88570 + }
88571 +}
88572 +
88573 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
88574 +{
88575 + gimple cond_stmt;
88576 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
88577 +
88578 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
88579 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
88580 + update_stmt(cond_stmt);
88581 +}
88582 +
88583 +static tree create_string_param(tree string)
88584 +{
88585 + tree i_type, a_type;
88586 + const int length = TREE_STRING_LENGTH(string);
88587 +
88588 + gcc_assert(length > 0);
88589 +
88590 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
88591 + a_type = build_array_type(char_type_node, i_type);
88592 +
88593 + TREE_TYPE(string) = a_type;
88594 + TREE_CONSTANT(string) = 1;
88595 + TREE_READONLY(string) = 1;
88596 +
88597 + return build1(ADDR_EXPR, ptr_type_node, string);
88598 +}
88599 +
88600 +static void insert_cond_result(basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
88601 +{
88602 + gimple func_stmt;
88603 + const_gimple def_stmt;
88604 + const_tree loc_line;
88605 + tree loc_file, ssa_name, current_func;
88606 + expanded_location xloc;
88607 + char ssa_name_buf[256];
88608 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
88609 +
88610 + def_stmt = get_def_stmt(arg);
88611 + xloc = expand_location(gimple_location(def_stmt));
88612 +
88613 + if (!gimple_has_location(def_stmt)) {
88614 + xloc = expand_location(gimple_location(stmt));
88615 + if (!gimple_has_location(stmt))
88616 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
88617 + }
88618 +
88619 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
88620 +
88621 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
88622 + loc_file = create_string_param(loc_file);
88623 +
88624 + current_func = build_string(NAME_LEN(current_function_decl) + 1, NAME(current_function_decl));
88625 + current_func = create_string_param(current_func);
88626 +
88627 + snprintf(ssa_name_buf, 256, "%s_%u (%s)\n", NAME(SSA_NAME_VAR(arg)), SSA_NAME_VERSION(arg), min ? "min" : "max");
88628 + ssa_name = build_string(256, ssa_name_buf);
88629 + ssa_name = create_string_param(ssa_name);
88630 +
88631 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
88632 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
88633 +
88634 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
88635 +}
88636 +
88637 +static void __unused print_the_code_insertions(const_gimple stmt)
88638 +{
88639 + location_t loc = gimple_location(stmt);
88640 +
88641 + inform(loc, "Integer size_overflow check applied here.");
88642 +}
88643 +
88644 +static void insert_check_size_overflow(gimple stmt, enum tree_code cond_code, tree arg, tree type_value, bool before, bool min)
88645 +{
88646 + basic_block cond_bb, join_bb, bb_true;
88647 + edge e;
88648 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
88649 +
88650 + cond_bb = gimple_bb(stmt);
88651 + if (before)
88652 + gsi_prev(&gsi);
88653 + if (gsi_end_p(gsi))
88654 + e = split_block_after_labels(cond_bb);
88655 + else
88656 + e = split_block(cond_bb, gsi_stmt(gsi));
88657 + cond_bb = e->src;
88658 + join_bb = e->dest;
88659 + e->flags = EDGE_FALSE_VALUE;
88660 + e->probability = REG_BR_PROB_BASE;
88661 +
88662 + bb_true = create_empty_bb(cond_bb);
88663 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
88664 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
88665 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
88666 +
88667 + if (dom_info_available_p(CDI_DOMINATORS)) {
88668 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
88669 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
88670 + }
88671 +
88672 + if (current_loops != NULL) {
88673 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
88674 + add_bb_to_loop(bb_true, cond_bb->loop_father);
88675 + }
88676 +
88677 + insert_cond(cond_bb, arg, cond_code, type_value);
88678 + insert_cond_result(bb_true, stmt, arg, min);
88679 +
88680 +// print_the_code_insertions(stmt);
88681 +}
88682 +
88683 +static void check_size_overflow(gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
88684 +{
88685 + const_tree rhs_type = TREE_TYPE(rhs);
88686 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
88687 +
88688 + gcc_assert(rhs_type != NULL_TREE);
88689 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
88690 + return;
88691 +
88692 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == BOOLEAN_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
88693 +
88694 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
88695 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
88696 +
88697 + gcc_assert(!TREE_OVERFLOW(type_max));
88698 +
88699 + cast_rhs_type = TREE_TYPE(cast_rhs);
88700 + type_max_type = TREE_TYPE(type_max);
88701 + type_min_type = TREE_TYPE(type_min);
88702 + gcc_assert(useless_type_conversion_p(cast_rhs_type, type_max_type));
88703 + gcc_assert(useless_type_conversion_p(type_max_type, type_min_type));
88704 +
88705 + insert_check_size_overflow(stmt, GT_EXPR, cast_rhs, type_max, before, false);
88706 + insert_check_size_overflow(stmt, LT_EXPR, cast_rhs, type_min, before, true);
88707 +}
88708 +
88709 +static tree get_size_overflow_type_for_intentional_overflow(gimple def_stmt, tree change_rhs)
88710 +{
88711 + gimple change_rhs_def_stmt;
88712 + tree lhs = gimple_get_lhs(def_stmt);
88713 + tree lhs_type = TREE_TYPE(lhs);
88714 + tree rhs1_type = TREE_TYPE(gimple_assign_rhs1(def_stmt));
88715 + tree rhs2_type = TREE_TYPE(gimple_assign_rhs2(def_stmt));
88716 +
88717 + if (change_rhs == NULL_TREE)
88718 + return get_size_overflow_type(def_stmt, lhs);
88719 +
88720 + change_rhs_def_stmt = get_def_stmt(change_rhs);
88721 +
88722 + if (TREE_CODE_CLASS(gimple_assign_rhs_code(def_stmt)) == tcc_comparison)
88723 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88724 +
88725 + if (gimple_assign_rhs_code(def_stmt) == LSHIFT_EXPR)
88726 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88727 +
88728 + if (gimple_assign_rhs_code(def_stmt) == RSHIFT_EXPR)
88729 + return get_size_overflow_type(change_rhs_def_stmt, change_rhs);
88730 +
88731 + if (!useless_type_conversion_p(lhs_type, rhs1_type) || !useless_type_conversion_p(rhs1_type, rhs2_type)) {
88732 + debug_gimple_stmt(def_stmt);
88733 + gcc_unreachable();
88734 + }
88735 +
88736 + return get_size_overflow_type(def_stmt, lhs);
88737 +}
88738 +
88739 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
88740 +{
88741 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
88742 + return false;
88743 + if (!is_gimple_constant(rhs))
88744 + return false;
88745 + return true;
88746 +}
88747 +
88748 +static tree get_cast_def_stmt_rhs(const_tree new_rhs)
88749 +{
88750 + gimple def_stmt;
88751 +
88752 + def_stmt = get_def_stmt(new_rhs);
88753 + // get_size_overflow_type
88754 + if (LONG_TYPE_SIZE != GET_MODE_BITSIZE(SImode))
88755 + gcc_assert(gimple_assign_cast_p(def_stmt));
88756 + return gimple_assign_rhs1(def_stmt);
88757 +}
88758 +
88759 +static tree cast_to_int_TI_type_and_check(gimple stmt, tree new_rhs)
88760 +{
88761 + gimple_stmt_iterator gsi;
88762 + const_gimple cast_stmt;
88763 + gimple def_stmt;
88764 + enum machine_mode mode = TYPE_MODE(TREE_TYPE(new_rhs));
88765 +
88766 + if (mode != TImode && mode != DImode) {
88767 + def_stmt = get_def_stmt(new_rhs);
88768 + gcc_assert(gimple_assign_cast_p(def_stmt));
88769 + new_rhs = gimple_assign_rhs1(def_stmt);
88770 + mode = TYPE_MODE(TREE_TYPE(new_rhs));
88771 + }
88772 +
88773 + gcc_assert(mode == TImode || mode == DImode);
88774 +
88775 + if (mode == TYPE_MODE(intTI_type_node) && useless_type_conversion_p(TREE_TYPE(new_rhs), intTI_type_node))
88776 + return new_rhs;
88777 +
88778 + gsi = gsi_for_stmt(stmt);
88779 + cast_stmt = build_cast_stmt(intTI_type_node, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
88780 + new_rhs = gimple_get_lhs(cast_stmt);
88781 +
88782 + if (mode == DImode)
88783 + return new_rhs;
88784 +
88785 + check_size_overflow(stmt, intTI_type_node, new_rhs, new_rhs, BEFORE_STMT);
88786 +
88787 + return new_rhs;
88788 +}
88789 +
88790 +static bool is_an_integer_trunction(const_gimple stmt)
88791 +{
88792 + gimple rhs1_def_stmt, rhs2_def_stmt;
88793 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1;
88794 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode;
88795 + const_tree rhs1 = gimple_assign_rhs1(stmt);
88796 + const_tree rhs2 = gimple_assign_rhs2(stmt);
88797 + enum machine_mode rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1));
88798 + enum machine_mode rhs2_mode = TYPE_MODE(TREE_TYPE(rhs2));
88799 +
88800 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
88801 + return false;
88802 +
88803 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
88804 +
88805 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR || rhs1_mode != SImode || rhs2_mode != SImode)
88806 + return false;
88807 +
88808 + rhs1_def_stmt = get_def_stmt(rhs1);
88809 + rhs2_def_stmt = get_def_stmt(rhs2);
88810 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
88811 + return false;
88812 +
88813 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
88814 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
88815 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
88816 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
88817 + if (rhs1_def_stmt_rhs1_mode != DImode || rhs2_def_stmt_rhs1_mode != DImode)
88818 + return false;
88819 +
88820 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
88821 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
88822 + return true;
88823 +}
88824 +
88825 +static tree handle_integer_truncation(struct pointer_set_t *visited, const_tree lhs)
88826 +{
88827 + tree new_rhs1, new_rhs2;
88828 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
88829 + tree new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type;
88830 + gimple assign, stmt = get_def_stmt(lhs);
88831 + tree rhs1 = gimple_assign_rhs1(stmt);
88832 + tree rhs2 = gimple_assign_rhs2(stmt);
88833 +
88834 + if (!is_an_integer_trunction(stmt))
88835 + return NULL_TREE;
88836 +
88837 + new_rhs1 = expand(visited, rhs1);
88838 + new_rhs2 = expand(visited, rhs2);
88839 +
88840 + new_rhs1_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs1);
88841 + new_rhs2_def_stmt_rhs1 = get_cast_def_stmt_rhs(new_rhs2);
88842 +
88843 + new_rhs1_def_stmt_rhs1_type = TREE_TYPE(new_rhs1_def_stmt_rhs1);
88844 + new_rhs2_def_stmt_rhs1_type = TREE_TYPE(new_rhs2_def_stmt_rhs1);
88845 +
88846 + if (!useless_type_conversion_p(new_rhs1_def_stmt_rhs1_type, new_rhs2_def_stmt_rhs1_type)) {
88847 + new_rhs1_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs1_def_stmt_rhs1);
88848 + new_rhs2_def_stmt_rhs1 = cast_to_int_TI_type_and_check(stmt, new_rhs2_def_stmt_rhs1);
88849 + }
88850 +
88851 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
88852 + new_lhs = gimple_get_lhs(assign);
88853 + check_size_overflow(assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
88854 +
88855 + return follow_overflow_type_and_dup(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88856 +}
88857 +
88858 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
88859 +{
88860 + const_gimple def_stmt;
88861 +
88862 + if (TREE_CODE(rhs) != SSA_NAME)
88863 + return false;
88864 +
88865 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
88866 + return false;
88867 +
88868 + def_stmt = get_def_stmt(rhs);
88869 + if (gimple_code(def_stmt) != GIMPLE_ASSIGN || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
88870 + return false;
88871 +
88872 + return true;
88873 +}
88874 +
88875 +static tree handle_intentional_overflow(struct pointer_set_t *visited, bool check_overflow, gimple stmt, tree change_rhs, tree new_rhs1, tree new_rhs2)
88876 +{
88877 + tree new_rhs, size_overflow_type, orig_rhs;
88878 + void (*gimple_assign_set_rhs)(gimple, tree);
88879 + tree rhs1 = gimple_assign_rhs1(stmt);
88880 + tree rhs2 = gimple_assign_rhs2(stmt);
88881 + tree lhs = gimple_get_lhs(stmt);
88882 +
88883 + if (change_rhs == NULL_TREE)
88884 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88885 +
88886 + if (new_rhs2 == NULL_TREE) {
88887 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs1);
88888 + new_rhs2 = cast_a_tree(size_overflow_type, rhs2);
88889 + orig_rhs = rhs1;
88890 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
88891 + } else {
88892 + size_overflow_type = get_size_overflow_type_for_intentional_overflow(stmt, new_rhs2);
88893 + new_rhs1 = cast_a_tree(size_overflow_type, rhs1);
88894 + orig_rhs = rhs2;
88895 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
88896 + }
88897 +
88898 + change_rhs = cast_to_new_size_overflow_type(stmt, change_rhs, size_overflow_type, BEFORE_STMT);
88899 +
88900 + if (check_overflow)
88901 + check_size_overflow(stmt, size_overflow_type, change_rhs, orig_rhs, BEFORE_STMT);
88902 +
88903 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
88904 + gimple_assign_set_rhs(stmt, new_rhs);
88905 + update_stmt(stmt);
88906 +
88907 + return create_assign(visited, stmt, lhs, AFTER_STMT);
88908 +}
88909 +
88910 +static tree handle_binary_ops(struct pointer_set_t *visited, tree lhs)
88911 +{
88912 + tree rhs1, rhs2, new_lhs;
88913 + gimple def_stmt = get_def_stmt(lhs);
88914 + tree new_rhs1 = NULL_TREE;
88915 + tree new_rhs2 = NULL_TREE;
88916 +
88917 + rhs1 = gimple_assign_rhs1(def_stmt);
88918 + rhs2 = gimple_assign_rhs2(def_stmt);
88919 +
88920 + /* no DImode/TImode division in the 32/64 bit kernel */
88921 + switch (gimple_assign_rhs_code(def_stmt)) {
88922 + case RDIV_EXPR:
88923 + case TRUNC_DIV_EXPR:
88924 + case CEIL_DIV_EXPR:
88925 + case FLOOR_DIV_EXPR:
88926 + case ROUND_DIV_EXPR:
88927 + case TRUNC_MOD_EXPR:
88928 + case CEIL_MOD_EXPR:
88929 + case FLOOR_MOD_EXPR:
88930 + case ROUND_MOD_EXPR:
88931 + case EXACT_DIV_EXPR:
88932 + case POINTER_PLUS_EXPR:
88933 + case BIT_AND_EXPR:
88934 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
88935 + default:
88936 + break;
88937 + }
88938 +
88939 + new_lhs = handle_integer_truncation(visited, lhs);
88940 + if (new_lhs != NULL_TREE)
88941 + return new_lhs;
88942 +
88943 + if (TREE_CODE(rhs1) == SSA_NAME)
88944 + new_rhs1 = expand(visited, rhs1);
88945 + if (TREE_CODE(rhs2) == SSA_NAME)
88946 + new_rhs2 = expand(visited, rhs2);
88947 +
88948 + if (is_a_neg_overflow(def_stmt, rhs2))
88949 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88950 + if (is_a_neg_overflow(def_stmt, rhs1))
88951 + return handle_intentional_overflow(visited, true, def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88952 +
88953 + if (is_a_constant_overflow(def_stmt, rhs2))
88954 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, new_rhs1, NULL_TREE);
88955 + if (is_a_constant_overflow(def_stmt, rhs1))
88956 + return handle_intentional_overflow(visited, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, NULL_TREE, new_rhs2);
88957 +
88958 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
88959 +}
88960 +
88961 +#if BUILDING_GCC_VERSION >= 4007
88962 +static tree get_new_rhs(struct pointer_set_t *visited, tree size_overflow_type, tree rhs)
88963 +{
88964 + if (is_gimple_constant(rhs))
88965 + return cast_a_tree(size_overflow_type, rhs);
88966 + if (TREE_CODE(rhs) != SSA_NAME)
88967 + return NULL_TREE;
88968 + return expand(visited, rhs);
88969 +}
88970 +
88971 +static tree handle_ternary_ops(struct pointer_set_t *visited, tree lhs)
88972 +{
88973 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
88974 + gimple def_stmt = get_def_stmt(lhs);
88975 +
88976 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
88977 +
88978 + rhs1 = gimple_assign_rhs1(def_stmt);
88979 + rhs2 = gimple_assign_rhs2(def_stmt);
88980 + rhs3 = gimple_assign_rhs3(def_stmt);
88981 + new_rhs1 = get_new_rhs(visited, size_overflow_type, rhs1);
88982 + new_rhs2 = get_new_rhs(visited, size_overflow_type, rhs2);
88983 + new_rhs3 = get_new_rhs(visited, size_overflow_type, rhs3);
88984 +
88985 + return follow_overflow_type_and_dup(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
88986 +}
88987 +#endif
88988 +
88989 +static tree get_size_overflow_type(gimple stmt, const_tree node)
88990 +{
88991 + const_tree type;
88992 +
88993 + gcc_assert(node != NULL_TREE);
88994 +
88995 + type = TREE_TYPE(node);
88996 +
88997 + if (gimple_plf(stmt, MY_STMT))
88998 + return TREE_TYPE(node);
88999 +
89000 + switch (TYPE_MODE(type)) {
89001 + case QImode:
89002 + return (TYPE_UNSIGNED(type)) ? unsigned_intHI_type_node : intHI_type_node;
89003 + case HImode:
89004 + return (TYPE_UNSIGNED(type)) ? unsigned_intSI_type_node : intSI_type_node;
89005 + case SImode:
89006 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89007 + case DImode:
89008 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
89009 + return (TYPE_UNSIGNED(type)) ? unsigned_intDI_type_node : intDI_type_node;
89010 + return (TYPE_UNSIGNED(type)) ? unsigned_intTI_type_node : intTI_type_node;
89011 + default:
89012 + debug_tree((tree)node);
89013 + error("%s: unsupported gcc configuration.", __func__);
89014 + gcc_unreachable();
89015 + }
89016 +}
89017 +
89018 +static tree expand_visited(gimple def_stmt)
89019 +{
89020 + const_gimple next_stmt;
89021 + gimple_stmt_iterator gsi = gsi_for_stmt(def_stmt);
89022 +
89023 + gsi_next(&gsi);
89024 + next_stmt = gsi_stmt(gsi);
89025 +
89026 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
89027 +
89028 + switch (gimple_code(next_stmt)) {
89029 + case GIMPLE_ASSIGN:
89030 + return gimple_get_lhs(next_stmt);
89031 + case GIMPLE_PHI:
89032 + return gimple_phi_result(next_stmt);
89033 + case GIMPLE_CALL:
89034 + return gimple_call_lhs(next_stmt);
89035 + default:
89036 + return NULL_TREE;
89037 + }
89038 +}
89039 +
89040 +static tree expand(struct pointer_set_t *visited, tree lhs)
89041 +{
89042 + gimple def_stmt;
89043 + enum tree_code code = TREE_CODE(TREE_TYPE(lhs));
89044 +
89045 + if (is_gimple_constant(lhs))
89046 + return NULL_TREE;
89047 +
89048 + if (TREE_CODE(lhs) == ADDR_EXPR)
89049 + return NULL_TREE;
89050 +
89051 + if (code == REAL_TYPE)
89052 + return NULL_TREE;
89053 +
89054 + gcc_assert(code == INTEGER_TYPE || code == POINTER_TYPE || code == BOOLEAN_TYPE || code == ENUMERAL_TYPE);
89055 +
89056 +
89057 + def_stmt = get_def_stmt(lhs);
89058 +
89059 + if (!def_stmt)
89060 + return NULL_TREE;
89061 +
89062 + if (gimple_plf(def_stmt, MY_STMT))
89063 + return lhs;
89064 +
89065 + if (pointer_set_contains(visited, def_stmt))
89066 + return expand_visited(def_stmt);
89067 +
89068 + switch (gimple_code(def_stmt)) {
89069 + case GIMPLE_NOP:
89070 + return NULL_TREE;
89071 + case GIMPLE_PHI:
89072 + return build_new_phi(visited, lhs);
89073 + case GIMPLE_CALL:
89074 + case GIMPLE_ASM:
89075 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
89076 + case GIMPLE_ASSIGN:
89077 + switch (gimple_num_ops(def_stmt)) {
89078 + case 2:
89079 + return handle_unary_ops(visited, lhs);
89080 + case 3:
89081 + return handle_binary_ops(visited, lhs);
89082 +#if BUILDING_GCC_VERSION >= 4007
89083 + case 4:
89084 + return handle_ternary_ops(visited, lhs);
89085 +#endif
89086 + }
89087 + default:
89088 + debug_gimple_stmt(def_stmt);
89089 + error("%s: unknown gimple code", __func__);
89090 + gcc_unreachable();
89091 + }
89092 +}
89093 +
89094 +static void change_function_arg(gimple stmt, const_tree origarg, unsigned int argnum, tree newarg)
89095 +{
89096 + const_gimple assign;
89097 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
89098 + tree origtype = TREE_TYPE(origarg);
89099 +
89100 + gcc_assert(gimple_code(stmt) == GIMPLE_CALL);
89101 +
89102 + assign = build_cast_stmt(origtype, newarg, CREATE_NEW_VAR, &gsi, BEFORE_STMT);
89103 +
89104 + gimple_call_set_arg(stmt, argnum, gimple_get_lhs(assign));
89105 + update_stmt(stmt);
89106 +}
89107 +
89108 +static bool get_function_arg(unsigned int* argnum, const_tree fndecl)
89109 +{
89110 + const char *origid;
89111 + tree arg;
89112 + const_tree origarg;
89113 +
89114 + if (!DECL_ABSTRACT_ORIGIN(fndecl))
89115 + return true;
89116 +
89117 + origarg = DECL_ARGUMENTS(DECL_ABSTRACT_ORIGIN(fndecl));
89118 + while (origarg && *argnum) {
89119 + (*argnum)--;
89120 + origarg = TREE_CHAIN(origarg);
89121 + }
89122 +
89123 + gcc_assert(*argnum == 0);
89124 +
89125 + gcc_assert(origarg != NULL_TREE);
89126 + origid = NAME(origarg);
89127 + *argnum = 0;
89128 + for (arg = DECL_ARGUMENTS(fndecl); arg; arg = TREE_CHAIN(arg)) {
89129 + if (!strcmp(origid, NAME(arg)))
89130 + return true;
89131 + (*argnum)++;
89132 + }
89133 + return false;
89134 +}
89135 +
89136 +static bool skip_types(const_tree var)
89137 +{
89138 + switch (TREE_CODE(var)) {
89139 + case ADDR_EXPR:
89140 +#if BUILDING_GCC_VERSION >= 4006
89141 + case MEM_REF:
89142 +#endif
89143 + case ARRAY_REF:
89144 + case BIT_FIELD_REF:
89145 + case INDIRECT_REF:
89146 + case TARGET_MEM_REF:
89147 + case VAR_DECL:
89148 + return true;
89149 + default:
89150 + break;
89151 + }
89152 + return false;
89153 +}
89154 +
89155 +static bool walk_phi(struct pointer_set_t *visited, const_tree result)
89156 +{
89157 + gimple phi = get_def_stmt(result);
89158 + unsigned int i, n = gimple_phi_num_args(phi);
89159 +
89160 + if (!phi)
89161 + return false;
89162 +
89163 + pointer_set_insert(visited, phi);
89164 + for (i = 0; i < n; i++) {
89165 + const_tree arg = gimple_phi_arg_def(phi, i);
89166 + if (pre_expand(visited, arg))
89167 + return true;
89168 + }
89169 + return false;
89170 +}
89171 +
89172 +static bool walk_unary_ops(struct pointer_set_t *visited, const_tree lhs)
89173 +{
89174 + gimple def_stmt = get_def_stmt(lhs);
89175 + const_tree rhs;
89176 +
89177 + if (!def_stmt)
89178 + return false;
89179 +
89180 + rhs = gimple_assign_rhs1(def_stmt);
89181 + if (pre_expand(visited, rhs))
89182 + return true;
89183 + return false;
89184 +}
89185 +
89186 +static bool walk_binary_ops(struct pointer_set_t *visited, const_tree lhs)
89187 +{
89188 + bool rhs1_found, rhs2_found;
89189 + gimple def_stmt = get_def_stmt(lhs);
89190 + const_tree rhs1, rhs2;
89191 +
89192 + if (!def_stmt)
89193 + return false;
89194 +
89195 + rhs1 = gimple_assign_rhs1(def_stmt);
89196 + rhs2 = gimple_assign_rhs2(def_stmt);
89197 + rhs1_found = pre_expand(visited, rhs1);
89198 + rhs2_found = pre_expand(visited, rhs2);
89199 +
89200 + return rhs1_found || rhs2_found;
89201 +}
89202 +
89203 +static const_tree search_field_decl(const_tree comp_ref)
89204 +{
89205 + const_tree field = NULL_TREE;
89206 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
89207 +
89208 + for (i = 0; i < len; i++) {
89209 + field = TREE_OPERAND(comp_ref, i);
89210 + if (TREE_CODE(field) == FIELD_DECL)
89211 + break;
89212 + }
89213 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
89214 + return field;
89215 +}
89216 +
89217 +static enum marked mark_status(const_tree fndecl, unsigned int argnum)
89218 +{
89219 + const_tree attr, p;
89220 +
89221 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(fndecl));
89222 + if (!attr || !TREE_VALUE(attr))
89223 + return MARKED_NO;
89224 +
89225 + p = TREE_VALUE(attr);
89226 + if (!TREE_INT_CST_LOW(TREE_VALUE(p)))
89227 + return MARKED_NOT_INTENTIONAL;
89228 +
89229 + do {
89230 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(p)))
89231 + return MARKED_YES;
89232 + p = TREE_CHAIN(p);
89233 + } while (p);
89234 +
89235 + return MARKED_NO;
89236 +}
89237 +
89238 +static void print_missing_msg(tree func, unsigned int argnum)
89239 +{
89240 + unsigned int new_hash;
89241 + size_t len;
89242 + unsigned char tree_codes[CODES_LIMIT];
89243 + location_t loc = DECL_SOURCE_LOCATION(func);
89244 + const char *curfunc = get_asm_name(func);
89245 +
89246 + len = get_function_decl(func, tree_codes);
89247 + new_hash = get_hash_num(curfunc, (const char *) tree_codes, len, 0);
89248 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, new_hash);
89249 +}
89250 +
89251 +static unsigned int search_missing_attribute(const_tree arg)
89252 +{
89253 + const_tree type = TREE_TYPE(arg);
89254 + tree func = get_original_function_decl(current_function_decl);
89255 + unsigned int argnum;
89256 + const struct size_overflow_hash *hash;
89257 +
89258 + gcc_assert(TREE_CODE(arg) != COMPONENT_REF);
89259 +
89260 + if (TREE_CODE(type) == POINTER_TYPE)
89261 + return 0;
89262 +
89263 + argnum = find_arg_number(arg, func);
89264 + if (argnum == 0)
89265 + return 0;
89266 +
89267 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(func)))
89268 + return argnum;
89269 +
89270 + hash = get_function_hash(func);
89271 + if (!hash || !(hash->param & (1U << argnum))) {
89272 + print_missing_msg(func, argnum);
89273 + return 0;
89274 + }
89275 + return argnum;
89276 +}
89277 +
89278 +static bool is_already_marked(const_tree lhs)
89279 +{
89280 + unsigned int argnum;
89281 + const_tree fndecl;
89282 +
89283 + argnum = search_missing_attribute(lhs);
89284 + fndecl = get_original_function_decl(current_function_decl);
89285 + if (argnum && mark_status(fndecl, argnum) == MARKED_YES)
89286 + return true;
89287 + return false;
89288 +}
89289 +
89290 +static bool pre_expand(struct pointer_set_t *visited, const_tree lhs)
89291 +{
89292 + const_gimple def_stmt;
89293 +
89294 + if (is_gimple_constant(lhs))
89295 + return false;
89296 +
89297 + if (skip_types(lhs))
89298 + return false;
89299 +
89300 + if (TREE_CODE(lhs) == PARM_DECL)
89301 + return is_already_marked(lhs);
89302 +
89303 + if (TREE_CODE(lhs) == COMPONENT_REF) {
89304 + const_tree field, attr;
89305 +
89306 + field = search_field_decl(lhs);
89307 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(field));
89308 + if (!attr || !TREE_VALUE(attr))
89309 + return false;
89310 + return true;
89311 + }
89312 +
89313 + def_stmt = get_def_stmt(lhs);
89314 +
89315 + if (!def_stmt)
89316 + return false;
89317 +
89318 + if (pointer_set_contains(visited, def_stmt))
89319 + return false;
89320 +
89321 + switch (gimple_code(def_stmt)) {
89322 + case GIMPLE_NOP:
89323 + if (TREE_CODE(SSA_NAME_VAR(lhs)) == PARM_DECL)
89324 + return is_already_marked(lhs);
89325 + return false;
89326 + case GIMPLE_PHI:
89327 + return walk_phi(visited, lhs);
89328 + case GIMPLE_CALL:
89329 + case GIMPLE_ASM:
89330 + return false;
89331 + case GIMPLE_ASSIGN:
89332 + switch (gimple_num_ops(def_stmt)) {
89333 + case 2:
89334 + return walk_unary_ops(visited, lhs);
89335 + case 3:
89336 + return walk_binary_ops(visited, lhs);
89337 + }
89338 + default:
89339 + debug_gimple_stmt((gimple)def_stmt);
89340 + error("%s: unknown gimple code", __func__);
89341 + gcc_unreachable();
89342 + }
89343 +}
89344 +
89345 +static bool search_attributes(tree fndecl, const_tree arg, unsigned int argnum)
89346 +{
89347 + struct pointer_set_t *visited;
89348 + bool is_found;
89349 + enum marked is_marked;
89350 + location_t loc;
89351 +
89352 + visited = pointer_set_create();
89353 + is_found = pre_expand(visited, arg);
89354 + pointer_set_destroy(visited);
89355 +
89356 + is_marked = mark_status(fndecl, argnum + 1);
89357 + if ((is_found && is_marked == MARKED_YES) || is_marked == MARKED_NOT_INTENTIONAL)
89358 + return true;
89359 +
89360 + if (is_found) {
89361 + loc = DECL_SOURCE_LOCATION(fndecl);
89362 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", get_asm_name(fndecl), argnum + 1);
89363 + return true;
89364 + }
89365 + return false;
89366 +}
89367 +
89368 +static void handle_function_arg(gimple stmt, tree fndecl, unsigned int argnum)
89369 +{
89370 + struct pointer_set_t *visited;
89371 + tree arg, newarg;
89372 + bool match;
89373 +
89374 + match = get_function_arg(&argnum, fndecl);
89375 + if (!match)
89376 + return;
89377 + gcc_assert(gimple_call_num_args(stmt) > argnum);
89378 + arg = gimple_call_arg(stmt, argnum);
89379 + if (arg == NULL_TREE)
89380 + return;
89381 +
89382 + if (is_gimple_constant(arg))
89383 + return;
89384 +
89385 + if (search_attributes(fndecl, arg, argnum))
89386 + return;
89387 +
89388 + if (TREE_CODE(arg) != SSA_NAME)
89389 + return;
89390 +
89391 + check_arg_type(arg);
89392 +
89393 + visited = pointer_set_create();
89394 + newarg = expand(visited, arg);
89395 + pointer_set_destroy(visited);
89396 +
89397 + if (newarg == NULL_TREE)
89398 + return;
89399 +
89400 + change_function_arg(stmt, arg, argnum, newarg);
89401 +
89402 + check_size_overflow(stmt, TREE_TYPE(newarg), newarg, arg, BEFORE_STMT);
89403 +}
89404 +
89405 +static void handle_function_by_attribute(gimple stmt, const_tree attr, tree fndecl)
89406 +{
89407 + tree p = TREE_VALUE(attr);
89408 + do {
89409 + handle_function_arg(stmt, fndecl, TREE_INT_CST_LOW(TREE_VALUE(p))-1);
89410 + p = TREE_CHAIN(p);
89411 + } while (p);
89412 +}
89413 +
89414 +static void handle_function_by_hash(gimple stmt, tree fndecl)
89415 +{
89416 + tree orig_fndecl;
89417 + unsigned int num;
89418 + const struct size_overflow_hash *hash;
89419 +
89420 + orig_fndecl = get_original_function_decl(fndecl);
89421 + if (C_DECL_IMPLICIT(orig_fndecl))
89422 + return;
89423 + hash = get_function_hash(orig_fndecl);
89424 + if (!hash)
89425 + return;
89426 +
89427 + for (num = 1; num <= MAX_PARAM; num++)
89428 + if (hash->param & (1U << num))
89429 + handle_function_arg(stmt, fndecl, num - 1);
89430 +}
89431 +
89432 +static void set_plf_false(void)
89433 +{
89434 + basic_block bb;
89435 +
89436 + FOR_ALL_BB(bb) {
89437 + gimple_stmt_iterator si;
89438 +
89439 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
89440 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89441 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
89442 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
89443 + }
89444 +}
89445 +
89446 +static unsigned int handle_function(void)
89447 +{
89448 + basic_block next, bb = ENTRY_BLOCK_PTR->next_bb;
89449 +
89450 + set_plf_false();
89451 +
89452 + do {
89453 + gimple_stmt_iterator gsi;
89454 + next = bb->next_bb;
89455 +
89456 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89457 + tree fndecl, attr;
89458 + gimple stmt = gsi_stmt(gsi);
89459 +
89460 + if (!(is_gimple_call(stmt)))
89461 + continue;
89462 + fndecl = gimple_call_fndecl(stmt);
89463 + if (fndecl == NULL_TREE)
89464 + continue;
89465 + if (gimple_call_num_args(stmt) == 0)
89466 + continue;
89467 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
89468 + if (!attr || !TREE_VALUE(attr))
89469 + handle_function_by_hash(stmt, fndecl);
89470 + else
89471 + handle_function_by_attribute(stmt, attr, fndecl);
89472 + gsi = gsi_for_stmt(stmt);
89473 + next = gimple_bb(stmt)->next_bb;
89474 + }
89475 + bb = next;
89476 + } while (bb);
89477 + return 0;
89478 +}
89479 +
89480 +static struct gimple_opt_pass size_overflow_pass = {
89481 + .pass = {
89482 + .type = GIMPLE_PASS,
89483 + .name = "size_overflow",
89484 + .gate = NULL,
89485 + .execute = handle_function,
89486 + .sub = NULL,
89487 + .next = NULL,
89488 + .static_pass_number = 0,
89489 + .tv_id = TV_NONE,
89490 + .properties_required = PROP_cfg | PROP_referenced_vars,
89491 + .properties_provided = 0,
89492 + .properties_destroyed = 0,
89493 + .todo_flags_start = 0,
89494 + .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
89495 + }
89496 +};
89497 +
89498 +static void start_unit_callback(void __unused *gcc_data, void __unused *user_data)
89499 +{
89500 + tree fntype;
89501 +
89502 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
89503 +
89504 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
89505 + fntype = build_function_type_list(void_type_node,
89506 + const_char_ptr_type_node,
89507 + unsigned_type_node,
89508 + const_char_ptr_type_node,
89509 + const_char_ptr_type_node,
89510 + NULL_TREE);
89511 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
89512 +
89513 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
89514 + TREE_PUBLIC(report_size_overflow_decl) = 1;
89515 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
89516 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
89517 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
89518 +}
89519 +
89520 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89521 +{
89522 + int i;
89523 + const char * const plugin_name = plugin_info->base_name;
89524 + const int argc = plugin_info->argc;
89525 + const struct plugin_argument * const argv = plugin_info->argv;
89526 + bool enable = true;
89527 +
89528 + struct register_pass_info size_overflow_pass_info = {
89529 + .pass = &size_overflow_pass.pass,
89530 + .reference_pass_name = "ssa",
89531 + .ref_pass_instance_number = 1,
89532 + .pos_op = PASS_POS_INSERT_AFTER
89533 + };
89534 +
89535 + if (!plugin_default_version_check(version, &gcc_version)) {
89536 + error(G_("incompatible gcc/plugin versions"));
89537 + return 1;
89538 + }
89539 +
89540 + for (i = 0; i < argc; ++i) {
89541 + if (!strcmp(argv[i].key, "no-size-overflow")) {
89542 + enable = false;
89543 + continue;
89544 + }
89545 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89546 + }
89547 +
89548 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
89549 + if (enable) {
89550 + register_callback("start_unit", PLUGIN_START_UNIT, &start_unit_callback, NULL);
89551 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &size_overflow_pass_info);
89552 + }
89553 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
89554 +
89555 + return 0;
89556 +}
89557 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
89558 new file mode 100644
89559 index 0000000..38d2014
89560 --- /dev/null
89561 +++ b/tools/gcc/stackleak_plugin.c
89562 @@ -0,0 +1,313 @@
89563 +/*
89564 + * Copyright 2011 by the PaX Team <pageexec@freemail.hu>
89565 + * Licensed under the GPL v2
89566 + *
89567 + * Note: the choice of the license means that the compilation process is
89568 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
89569 + * but for the kernel it doesn't matter since it doesn't link against
89570 + * any of the gcc libraries
89571 + *
89572 + * gcc plugin to help implement various PaX features
89573 + *
89574 + * - track lowest stack pointer
89575 + *
89576 + * TODO:
89577 + * - initialize all local variables
89578 + *
89579 + * BUGS:
89580 + * - none known
89581 + */
89582 +#include "gcc-plugin.h"
89583 +#include "config.h"
89584 +#include "system.h"
89585 +#include "coretypes.h"
89586 +#include "tree.h"
89587 +#include "tree-pass.h"
89588 +#include "flags.h"
89589 +#include "intl.h"
89590 +#include "toplev.h"
89591 +#include "plugin.h"
89592 +//#include "expr.h" where are you...
89593 +#include "diagnostic.h"
89594 +#include "plugin-version.h"
89595 +#include "tm.h"
89596 +#include "function.h"
89597 +#include "basic-block.h"
89598 +#include "gimple.h"
89599 +#include "rtl.h"
89600 +#include "emit-rtl.h"
89601 +
89602 +extern void print_gimple_stmt(FILE *, gimple, int, int);
89603 +
89604 +int plugin_is_GPL_compatible;
89605 +
89606 +static int track_frame_size = -1;
89607 +static const char track_function[] = "pax_track_stack";
89608 +static const char check_function[] = "pax_check_alloca";
89609 +static bool init_locals;
89610 +
89611 +static struct plugin_info stackleak_plugin_info = {
89612 + .version = "201203140940",
89613 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
89614 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
89615 +};
89616 +
89617 +static bool gate_stackleak_track_stack(void);
89618 +static unsigned int execute_stackleak_tree_instrument(void);
89619 +static unsigned int execute_stackleak_final(void);
89620 +
89621 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
89622 + .pass = {
89623 + .type = GIMPLE_PASS,
89624 + .name = "stackleak_tree_instrument",
89625 + .gate = gate_stackleak_track_stack,
89626 + .execute = execute_stackleak_tree_instrument,
89627 + .sub = NULL,
89628 + .next = NULL,
89629 + .static_pass_number = 0,
89630 + .tv_id = TV_NONE,
89631 + .properties_required = PROP_gimple_leh | PROP_cfg,
89632 + .properties_provided = 0,
89633 + .properties_destroyed = 0,
89634 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
89635 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
89636 + }
89637 +};
89638 +
89639 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
89640 + .pass = {
89641 + .type = RTL_PASS,
89642 + .name = "stackleak_final",
89643 + .gate = gate_stackleak_track_stack,
89644 + .execute = execute_stackleak_final,
89645 + .sub = NULL,
89646 + .next = NULL,
89647 + .static_pass_number = 0,
89648 + .tv_id = TV_NONE,
89649 + .properties_required = 0,
89650 + .properties_provided = 0,
89651 + .properties_destroyed = 0,
89652 + .todo_flags_start = 0,
89653 + .todo_flags_finish = TODO_dump_func
89654 + }
89655 +};
89656 +
89657 +static bool gate_stackleak_track_stack(void)
89658 +{
89659 + return track_frame_size >= 0;
89660 +}
89661 +
89662 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
89663 +{
89664 + gimple check_alloca;
89665 + tree fntype, fndecl, alloca_size;
89666 +
89667 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
89668 + fndecl = build_fn_decl(check_function, fntype);
89669 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89670 +
89671 + // insert call to void pax_check_alloca(unsigned long size)
89672 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
89673 + check_alloca = gimple_build_call(fndecl, 1, alloca_size);
89674 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
89675 +}
89676 +
89677 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
89678 +{
89679 + gimple track_stack;
89680 + tree fntype, fndecl;
89681 +
89682 + fntype = build_function_type_list(void_type_node, NULL_TREE);
89683 + fndecl = build_fn_decl(track_function, fntype);
89684 + DECL_ASSEMBLER_NAME(fndecl); // for LTO
89685 +
89686 + // insert call to void pax_track_stack(void)
89687 + track_stack = gimple_build_call(fndecl, 0);
89688 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
89689 +}
89690 +
89691 +#if BUILDING_GCC_VERSION == 4005
89692 +static bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
89693 +{
89694 + tree fndecl;
89695 +
89696 + if (!is_gimple_call(stmt))
89697 + return false;
89698 + fndecl = gimple_call_fndecl(stmt);
89699 + if (!fndecl)
89700 + return false;
89701 + if (DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
89702 + return false;
89703 +// print_node(stderr, "pax", fndecl, 4);
89704 + return DECL_FUNCTION_CODE(fndecl) == code;
89705 +}
89706 +#endif
89707 +
89708 +static bool is_alloca(gimple stmt)
89709 +{
89710 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
89711 + return true;
89712 +
89713 +#if BUILDING_GCC_VERSION >= 4007
89714 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
89715 + return true;
89716 +#endif
89717 +
89718 + return false;
89719 +}
89720 +
89721 +static unsigned int execute_stackleak_tree_instrument(void)
89722 +{
89723 + basic_block bb, entry_bb;
89724 + bool prologue_instrumented = false, is_leaf = true;
89725 +
89726 + entry_bb = ENTRY_BLOCK_PTR_FOR_FUNCTION(cfun)->next_bb;
89727 +
89728 + // 1. loop through BBs and GIMPLE statements
89729 + FOR_EACH_BB(bb) {
89730 + gimple_stmt_iterator gsi;
89731 +
89732 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
89733 + gimple stmt;
89734 +
89735 + stmt = gsi_stmt(gsi);
89736 +
89737 + if (is_gimple_call(stmt))
89738 + is_leaf = false;
89739 +
89740 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
89741 + if (!is_alloca(stmt))
89742 + continue;
89743 +
89744 + // 2. insert stack overflow check before each __builtin_alloca call
89745 + stackleak_check_alloca(&gsi);
89746 +
89747 + // 3. insert track call after each __builtin_alloca call
89748 + stackleak_add_instrumentation(&gsi);
89749 + if (bb == entry_bb)
89750 + prologue_instrumented = true;
89751 + }
89752 + }
89753 +
89754 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
89755 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
89756 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
89757 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
89758 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
89759 + return 0;
89760 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
89761 + return 0;
89762 +
89763 + // 4. insert track call at the beginning
89764 + if (!prologue_instrumented) {
89765 + gimple_stmt_iterator gsi;
89766 +
89767 + bb = split_block_after_labels(ENTRY_BLOCK_PTR)->dest;
89768 + if (dom_info_available_p(CDI_DOMINATORS))
89769 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR);
89770 + gsi = gsi_start_bb(bb);
89771 + stackleak_add_instrumentation(&gsi);
89772 + }
89773 +
89774 + return 0;
89775 +}
89776 +
89777 +static unsigned int execute_stackleak_final(void)
89778 +{
89779 + rtx insn;
89780 +
89781 + if (cfun->calls_alloca)
89782 + return 0;
89783 +
89784 + // keep calls only if function frame is big enough
89785 + if (get_frame_size() >= track_frame_size)
89786 + return 0;
89787 +
89788 + // 1. find pax_track_stack calls
89789 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
89790 + // 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))
89791 + rtx body;
89792 +
89793 + if (!CALL_P(insn))
89794 + continue;
89795 + body = PATTERN(insn);
89796 + if (GET_CODE(body) != CALL)
89797 + continue;
89798 + body = XEXP(body, 0);
89799 + if (GET_CODE(body) != MEM)
89800 + continue;
89801 + body = XEXP(body, 0);
89802 + if (GET_CODE(body) != SYMBOL_REF)
89803 + continue;
89804 + if (strcmp(XSTR(body, 0), track_function))
89805 + continue;
89806 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89807 + // 2. delete call
89808 + insn = delete_insn_and_edges(insn);
89809 +#if BUILDING_GCC_VERSION >= 4007
89810 + if (GET_CODE(insn) == NOTE && NOTE_KIND(insn) == NOTE_INSN_CALL_ARG_LOCATION)
89811 + insn = delete_insn_and_edges(insn);
89812 +#endif
89813 + }
89814 +
89815 +// print_simple_rtl(stderr, get_insns());
89816 +// print_rtl(stderr, get_insns());
89817 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
89818 +
89819 + return 0;
89820 +}
89821 +
89822 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
89823 +{
89824 + const char * const plugin_name = plugin_info->base_name;
89825 + const int argc = plugin_info->argc;
89826 + const struct plugin_argument * const argv = plugin_info->argv;
89827 + int i;
89828 + struct register_pass_info stackleak_tree_instrument_pass_info = {
89829 + .pass = &stackleak_tree_instrument_pass.pass,
89830 +// .reference_pass_name = "tree_profile",
89831 + .reference_pass_name = "optimized",
89832 + .ref_pass_instance_number = 1,
89833 + .pos_op = PASS_POS_INSERT_BEFORE
89834 + };
89835 + struct register_pass_info stackleak_final_pass_info = {
89836 + .pass = &stackleak_final_rtl_opt_pass.pass,
89837 + .reference_pass_name = "final",
89838 + .ref_pass_instance_number = 1,
89839 + .pos_op = PASS_POS_INSERT_BEFORE
89840 + };
89841 +
89842 + if (!plugin_default_version_check(version, &gcc_version)) {
89843 + error(G_("incompatible gcc/plugin versions"));
89844 + return 1;
89845 + }
89846 +
89847 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
89848 +
89849 + for (i = 0; i < argc; ++i) {
89850 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
89851 + if (!argv[i].value) {
89852 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89853 + continue;
89854 + }
89855 + track_frame_size = atoi(argv[i].value);
89856 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
89857 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89858 + continue;
89859 + }
89860 + if (!strcmp(argv[i].key, "initialize-locals")) {
89861 + if (argv[i].value) {
89862 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
89863 + continue;
89864 + }
89865 + init_locals = true;
89866 + continue;
89867 + }
89868 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
89869 + }
89870 +
89871 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
89872 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
89873 +
89874 + return 0;
89875 +}
89876 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
89877 index 6789d78..4afd019e 100644
89878 --- a/tools/perf/util/include/asm/alternative-asm.h
89879 +++ b/tools/perf/util/include/asm/alternative-asm.h
89880 @@ -5,4 +5,7 @@
89881
89882 #define altinstruction_entry #
89883
89884 + .macro pax_force_retaddr rip=0, reload=0
89885 + .endm
89886 +
89887 #endif
89888 diff --git a/usr/gen_init_cpio.c b/usr/gen_init_cpio.c
89889 index af0f22f..9a7d479 100644
89890 --- a/usr/gen_init_cpio.c
89891 +++ b/usr/gen_init_cpio.c
89892 @@ -303,7 +303,7 @@ static int cpio_mkfile(const char *name, const char *location,
89893 int retval;
89894 int rc = -1;
89895 int namesize;
89896 - int i;
89897 + unsigned int i;
89898
89899 mode |= S_IFREG;
89900
89901 @@ -392,9 +392,10 @@ static char *cpio_replace_env(char *new_location)
89902 *env_var = *expanded = '\0';
89903 strncat(env_var, start + 2, end - start - 2);
89904 strncat(expanded, new_location, start - new_location);
89905 - strncat(expanded, getenv(env_var), PATH_MAX);
89906 - strncat(expanded, end + 1, PATH_MAX);
89907 + strncat(expanded, getenv(env_var), PATH_MAX - strlen(expanded));
89908 + strncat(expanded, end + 1, PATH_MAX - strlen(expanded));
89909 strncpy(new_location, expanded, PATH_MAX);
89910 + new_location[PATH_MAX] = 0;
89911 } else
89912 break;
89913 }
89914 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
89915 index 44ee712..a01c4b8 100644
89916 --- a/virt/kvm/kvm_main.c
89917 +++ b/virt/kvm/kvm_main.c
89918 @@ -75,7 +75,7 @@ LIST_HEAD(vm_list);
89919
89920 static cpumask_var_t cpus_hardware_enabled;
89921 static int kvm_usage_count = 0;
89922 -static atomic_t hardware_enable_failed;
89923 +static atomic_unchecked_t hardware_enable_failed;
89924
89925 struct kmem_cache *kvm_vcpu_cache;
89926 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
89927 @@ -703,7 +703,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
89928 /* We can read the guest memory with __xxx_user() later on. */
89929 if (user_alloc &&
89930 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
89931 - !access_ok(VERIFY_WRITE,
89932 + !__access_ok(VERIFY_WRITE,
89933 (void __user *)(unsigned long)mem->userspace_addr,
89934 mem->memory_size)))
89935 goto out;
89936 @@ -2291,7 +2291,7 @@ static void hardware_enable_nolock(void *junk)
89937
89938 if (r) {
89939 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
89940 - atomic_inc(&hardware_enable_failed);
89941 + atomic_inc_unchecked(&hardware_enable_failed);
89942 printk(KERN_INFO "kvm: enabling virtualization on "
89943 "CPU%d failed\n", cpu);
89944 }
89945 @@ -2345,10 +2345,10 @@ static int hardware_enable_all(void)
89946
89947 kvm_usage_count++;
89948 if (kvm_usage_count == 1) {
89949 - atomic_set(&hardware_enable_failed, 0);
89950 + atomic_set_unchecked(&hardware_enable_failed, 0);
89951 on_each_cpu(hardware_enable_nolock, NULL, 1);
89952
89953 - if (atomic_read(&hardware_enable_failed)) {
89954 + if (atomic_read_unchecked(&hardware_enable_failed)) {
89955 hardware_disable_all_nolock();
89956 r = -EBUSY;
89957 }
89958 @@ -2709,7 +2709,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
89959 kvm_arch_vcpu_put(vcpu);
89960 }
89961
89962 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89963 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89964 struct module *module)
89965 {
89966 int r;
89967 @@ -2772,7 +2772,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89968 if (!vcpu_align)
89969 vcpu_align = __alignof__(struct kvm_vcpu);
89970 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
89971 - 0, NULL);
89972 + SLAB_USERCOPY, NULL);
89973 if (!kvm_vcpu_cache) {
89974 r = -ENOMEM;
89975 goto out_free_3;
89976 @@ -2782,9 +2782,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
89977 if (r)
89978 goto out_free;
89979
89980 - kvm_chardev_ops.owner = module;
89981 - kvm_vm_fops.owner = module;
89982 - kvm_vcpu_fops.owner = module;
89983 + pax_open_kernel();
89984 + *(void **)&kvm_chardev_ops.owner = module;
89985 + *(void **)&kvm_vm_fops.owner = module;
89986 + *(void **)&kvm_vcpu_fops.owner = module;
89987 + pax_close_kernel();
89988
89989 r = misc_register(&kvm_dev);
89990 if (r) {